Skip to content

Commit b5daecc

Browse files
committed
Refactor Node.
1 parent 10212a8 commit b5daecc

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/model/Node.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,35 @@ export class Node {
2323
public attributes: Attribute[];
2424

2525
public toJsonString(): string {
26-
let nodeShapeAttr = '';
26+
const jsStringProperties: string[] = [];
27+
jsStringProperties.push(`id: "${this.id}"`);
28+
const label = this.config.maximumNodeLabelLength !== -1 && this.name.length > this.config.maximumNodeLabelLength ? this.name.substr(0, this.config.maximumNodeLabelLength) + '...' : this.name;
29+
jsStringProperties.push(`label: "${label}"`);
30+
jsStringProperties.push(`color: "${this.getNodeTypeColor(this.nodeType)}"`);
2731
switch (this.nodeType) {
2832
case NodeType.rootNode:
29-
nodeShapeAttr = `, shape: "${this.config.rootNodeShape}"`;
33+
jsStringProperties.push(`shape: "${this.config.rootNodeShape}"`);
3034
break;
3135
case NodeType.component:
32-
nodeShapeAttr = `, shape: "${this.config.componentNodeShape}"`;
36+
jsStringProperties.push(`shape: "${this.config.componentNodeShape}"`);
3337
break;
3438
case NodeType.module:
35-
nodeShapeAttr = `, shape: "${this.config.moduleNodeShape}"`;
39+
jsStringProperties.push(`shape: "${this.config.moduleNodeShape}"`);
3640
break;
3741
case NodeType.pipe:
38-
nodeShapeAttr = `, shape: "${this.config.pipeNodeShape}"`;
42+
jsStringProperties.push(`shape: "${this.config.pipeNodeShape}"`);
3943
break;
4044
case NodeType.directive:
41-
nodeShapeAttr = `, shape: "${this.config.directiveNodeShape}"`;
45+
jsStringProperties.push(`shape: "${this.config.directiveNodeShape}"`);
4246
break;
4347
case NodeType.injectable:
44-
nodeShapeAttr = `, shape: "${this.config.injectableNodeShape}"`;
48+
jsStringProperties.push(`shape: "${this.config.injectableNodeShape}"`);
4549
break;
4650
default:
47-
nodeShapeAttr = '';
4851
break;
4952
}
50-
const nodeColorAttr = `, color: "${this.getNodeTypeColor(this.nodeType)}"`;
51-
const label = this.config.maximumNodeLabelLength !== -1 && this.name.length > this.config.maximumNodeLabelLength ? this.name.substr(0, this.config.maximumNodeLabelLength) + '...' : this.name;
52-
return `{id: "${this.id}", label: "${label}"${nodeColorAttr}${nodeShapeAttr}}`;
53+
if (this.position !== undefined && this.position.x !== undefined && this.position.y !== undefined) { jsStringProperties.push(`x: ${this.position.x}, y: ${this.position.y}, fixed: { x: true, y: true}`); }
54+
return `{ ${jsStringProperties.join(', ')} }`;
5355
}
5456

5557
public toGraphViz(): string {

0 commit comments

Comments
 (0)