Newer
Older
import {getGradientColor} from './utils';
import {
Node,
} from './interfaces';
import {IConfig, defaultConfig} from './config';
private static Grey = '#A0A0A0';
private static White = '#FFFFFF';
private static Black = '#000000';
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,
enabled: true,
stabilization: true
static getOptions(network: 'main' | 'analysis' | 'analysis-big', config) {
const physicsOn = config.physicsOn;
const groups = config.nodeGroups;
if (network === 'main') {
return {
layout: this.mainLayout,
edges: this.mainEdges,
physics: physicsOn || this.mainPhysics,
};
} else if (network === 'analysis') {
return {
layout: this.analysisLayout,
edges: this.analysisEdges,
physics: physicsOn || this.analysisPhysics,
} else if (network === 'analysis-big') {
return {
layout: this.analysisLayout,
edges: this.analysisEdges,
physics: physicsOn || this.analysisBigPhysics,
static getNodeStyle(
node: Node,
config: IConfig,
isSeed: boolean,
isSelected: boolean,

Hartung, Michael
committed
gradient: number = 1,
renderer = null): Node {
// delete possible old styles
Object.keys(config.nodeGroups.default).forEach(e => delete node[e]);

Hartung, Michael
committed
// note that seed and selected node style are applied after the node style is fetched.

Hartung, Michael
committed
// this allows to overwrite only attributes of interest, therefore in e.g. seedNode group
// certain attributes like shape can remain undefined
// use lodash merge to not lose deep attributes, e.g. "font.size"
// @ts-ignore
// @ts-ignore
AndiMajore
committed
node.group = node._group;
}
AndiMajore
committed
node.shadow = node._shadow;
} else {
AndiMajore
committed
node.shadow = {enabled: config.nodeGroups[node.group].shadow};
node.shadow.color = 'rgba(0,0,0,0.5)';
AndiMajore
committed
node.shadow = {color: 'rgba(0,0,0,0.5)'};
if (isSeed) {
// apply seed node style to node
// @ts-ignore
AndiMajore
committed
node._group = node.group;
node.group = 'seedNode';
}
// selection on purpose after seed style, so seed style will be combined with selection style
if (isSelected) {
// @ts-ignore
AndiMajore
committed
node._group = node.group;
// apply selected node style to node
AndiMajore
committed
node.group = 'selectedNode';
AndiMajore
committed
node.shadow = {enabled: config.nodeGroups[node.group].shadow};
node.shadow.color = '#000000';
AndiMajore
committed
node.shadow = {color: '#000000'};
// show image if image url is given. If seed nodes are highlighted, ignore image property
if (node.image && !isSeed) {
node.shape = 'image';
}

Hartung, Michael
committed
// custom ctx renderer for e.g. pie chart
if (renderer !== null) {
// @ts-ignore

Hartung, Michael
committed
node.shape = 'custom';
AndiMajore
committed
node.color = {opacity: gradient};
node.opacity = gradient;
if (isSeed) {
// apply seed node style to node
// @ts-ignore
AndiMajore
committed
node.color = config.nodeGroups[node.group].color;
} else {
delete node.color;
// @ts-ignore
AndiMajore
committed
node._shadow = node.shadow;
if (config.nodeGroups[node.group].shadow) {
AndiMajore
committed
node.shadow = {enabled: config.nodeGroups[node.group].shadow};
node.shadow.color = 'rgba(0,0,0,0.5)';
AndiMajore
committed
node.shadow = {color: 'rgba(0,0,0,0.5)'};

Hartung, Michael
committed
node.ctxRenderer = renderer;
AndiMajore
committed
node.opacity = undefined;

Hartung, Michael
committed
}