Skip to content
Snippets Groups Projects
Select Git revision
  • c2d830012435e24dae040f66f6cd7daede14a4ce
  • master default protected
  • csv_export
  • ndex
  • v1.1.18-rc2
  • v1.1.17
  • v1.1.16
  • v1.1.16-rc12
  • v1.1.16-rc11
  • v1.1.16-rc10
  • v1.1.16-rc9
  • v1.1.16-rc8
  • v1.1.16-rc7
  • v1.1.16-rc4
  • v1.1.16-rc3
  • v1.1.16-rc1
  • v1.1.6-rc1
  • v1.1.15
  • v1.1.15-rc7
  • v1.1.15-rc6
  • v1.1.15-rc3
  • v1.1.15-rc1
  • v1.1.14
  • v1.1.13
24 results

network-settings.ts

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    network-settings.ts 4.79 KiB
    import {getGradientColor} from './utils';
    import {
      Node,
    } from './interfaces';
    import { IConfig, defaultConfig} from './config';
    import * as merge from 'lodash/fp/merge'; 
    
    export class NetworkSettings {
    
      // colors
      private static Grey = '#A0A0A0'
      private static White = '#FFFFFF';
      private static Black = '#000000';
    
      // Node color
      private static hostColor = '#123456';
      private static approvedDrugColor = '#48C774';
      private static unapprovedDrugColor = '#F8981D';
      private static nonSeedHostColor = '#3070B3';
    
      // Edge color
      private static edgeHostDrugColor = '#686868';
      private static edgeHostDrugHighlightColor = '#686868';
      private static edgeGeneGeneColor = '#686868';
      private static edgeGeneGeneHighlightColor = '#686868';
    
      private static hostFontColor = NetworkSettings.White;
      private static drugFontColor = NetworkSettings.White;
    
      // Network Layout
      private static analysisLayout = {
        improvedLayout: true,
      };
      private static analysisEdges = {
        smooth: false,
      };
      private static analysisPhysics = {
        enabled: true,
        stabilization: {
          enabled: true,
        },
        repulsion: {
          centralGravity: 0,
        },
        solver: 'repulsion',
      };
      private static analysisBigPhysics = {
        enabled: false,
      };
    
      private static mainLayout = {
        improvedLayout: false,
      };
      private static mainEdges = {
        smooth: false,
        length: 250,
      };
      private static mainPhysics = {
        enabled: false,
      };
    
      // Node size
      private static hostSize = 20;
      private static drugSize = 15;
    
      // Node shape
      private static hostShape = 'ellipse';
      private static drugNotInTrialShape = 'box';
      private static drugInTrialShape = 'triangle';
    
      static getOptions(network: 'main' | 'analysis' | 'analysis-big') {
        if (network === 'main') {
          return {
            layout: this.mainLayout,
            edges: this.mainEdges,
            physics: this.mainPhysics,
          };
        } else if (network === 'analysis') {
          return {
            layout: this.analysisLayout,
            edges: this.analysisEdges,
            physics: this.analysisPhysics,
          };
        } else if (network === 'analysis-big') {
          return {
            layout: this.analysisLayout,
            edges: this.analysisEdges,
            physics: this.analysisBigPhysics,
          };
        }
      }
    
      static getColor(color: 'protein' | 'approvedDrug' | 'unapprovedDrug' | 'hostFont' | 'drugFont' |
        'nonSeedHost' | 'selectedForAnalysis' | 'selectedForAnalysisText' |
        'edgeHostDrug' | 'edgeHostDrugHighlight' | 'edgeGeneGene' | 'edgeGeneGeneHighlight') 
        /**
         * Collection of all colors per use-case
         */
        {
        if (color === 'protein') {
          return this.hostColor;
        } else if (color === 'approvedDrug') {
          return this.approvedDrugColor;
        } else if (color === 'unapprovedDrug') {
          return this.unapprovedDrugColor;
        } else if (color === 'hostFont') {
          return this.hostFontColor;
        } else if (color === 'drugFont') {
          return this.drugFontColor;
        } else if (color === 'nonSeedHost') {
          return this.nonSeedHostColor;
        } else if (color === 'edgeHostDrug') {
          return this.edgeHostDrugColor;
        } else if (color === 'edgeHostDrugHighlight') {
          return this.edgeHostDrugHighlightColor;
        } else if (color === 'edgeGeneGene') {
          return this.edgeGeneGeneColor;
        } else if (color === 'edgeGeneGeneHighlight') {
          return this.edgeGeneGeneHighlightColor;
        }
      }
    
      static getNodeStyle(
        node: Node,
        config: IConfig,
        isSeed: boolean,
        isSelected: boolean,
        gradient: number = 1): Node {
          // delete possible old styles
          Object.keys(config.nodeGroups.default).forEach(e => delete node[e]);
          // set group styles
          if (node.group === 'default') {
            node = merge(node, config.nodeGroups.default);
          } else {
            node = merge(node, config.nodeGroups[node.group]);
          }
          // note that seed and selected node style are applied after the node style is fetched. 
          // this allows to overwrite only attributes of interest, therefor in e.g. seedNode group
          // certain attributes like shape can remain undefined
          // use lodash merge to not lose deep attributes, e.g. "font.size"
          if (isSeed) {
            // apply seed node style to node
            node = merge(node, config.nodeGroups.seedNode);
          }
          // selection on purpose after seed style, so seed style will be combined with selection style
          if (isSelected) {
            // apply selected node style to node
            node = merge(node, config.nodeGroups.selectedNode);
          }
    
          // show image if image url is given. If seed nodes are highlighted, ignore image property
          if (node.image && !isSeed) {
            node.shape = 'image';
          }
    
          // use opactiy as gradient
          if (gradient === null) {
              node.opacity = 0
            } else {
              node.opacity = gradient
            }
          return node;
        }
    }