|
1 | 1 | import { CommandBase } from '@commands';
|
2 | 2 | import { Config, FileSystemUtils } from '@src';
|
| 3 | +import { Edge, Node } from '@model'; |
3 | 4 | import { Base64 } from 'js-base64';
|
4 | 5 | import * as fs from 'fs';
|
5 | 6 | import * as path from 'path';
|
6 | 7 | import * as vscode from 'vscode';
|
7 |
| -import { Project } from '@model'; |
8 | 8 |
|
9 |
| -export enum NodeType { |
10 |
| - none, |
11 |
| - component, |
12 |
| - directive, |
13 |
| - injectable, |
14 |
| - module, |
15 |
| - pipe, |
16 |
| - rootNode |
17 |
| -} |
18 |
| -export class Node { |
19 |
| - private config: Config = new Config(); |
20 |
| - constructor(id: string, name: string, isRoot: boolean, nodeType: NodeType = NodeType.none) { |
21 |
| - this.id = id; |
22 |
| - this.name = name; |
23 |
| - this.isRoot = isRoot; |
24 |
| - this.nodeType = nodeType; |
25 |
| - } |
26 |
| - public id: string; |
27 |
| - public name: string; |
28 |
| - public isRoot: boolean; |
29 |
| - public nodeType: NodeType; |
30 |
| - |
31 |
| - public toJsonString(): string { |
32 |
| - let nodeColorAttr = ''; |
33 |
| - switch (this.nodeType) { |
34 |
| - case NodeType.rootNode: |
35 |
| - nodeColorAttr = `, color: "${this.config.rootNodeBackgroundColor}", shape: "${this.config.visNodeShape}"`; |
36 |
| - break; |
37 |
| - case NodeType.component: |
38 |
| - nodeColorAttr = `, color: "${this.config.componentNodeBackgroundColor}", shape: "${this.config.componentNodeShape}"`; |
39 |
| - break; |
40 |
| - case NodeType.module: |
41 |
| - nodeColorAttr = `, color: "${this.config.moduleNodeBackgroundColor}", shape: "${this.config.moduleNodeShape}"`; |
42 |
| - break; |
43 |
| - case NodeType.pipe: |
44 |
| - nodeColorAttr = `, color: "${this.config.pipeNodeBackgroundColor}", shape: "${this.config.pipeNodeShape}"`; |
45 |
| - break; |
46 |
| - case NodeType.directive: |
47 |
| - nodeColorAttr = `, color: "${this.config.directiveNodeBackgroundColor}", shape: "${this.config.directiveNodeShape}"`; |
48 |
| - break; |
49 |
| - default: |
50 |
| - nodeColorAttr = ''; |
51 |
| - break; |
52 |
| - } |
53 |
| - const label = this.config.maximumNodeLabelLength !== -1 && this.name.length > this.config.maximumNodeLabelLength ? this.name.substr(0, this.config.maximumNodeLabelLength) + '...' : this.name; |
54 |
| - return `{id: "${this.id}", label: "${label}" ${nodeColorAttr}}`; |
55 |
| - } |
56 |
| - |
57 |
| - public static getNodeType(project: Project, className: string) { |
58 |
| - let nodeType = NodeType.none; |
59 |
| - if (project.moduleNames.has(className) || className.endsWith('Module') || className.includes("Module.")) { |
60 |
| - nodeType = NodeType.module; |
61 |
| - } |
62 |
| - else if (project.components.has(className) || className.endsWith('Component')) { |
63 |
| - nodeType = NodeType.component; |
64 |
| - } |
65 |
| - else if (project.directives.has(className) || className.endsWith('Directive')) { |
66 |
| - nodeType = NodeType.directive; |
67 |
| - } |
68 |
| - else if (project.pipes.has(className) || className.endsWith('Pipe')) { |
69 |
| - nodeType = NodeType.pipe; |
70 |
| - } |
71 |
| - else if (project.injectables.has(className)) { |
72 |
| - nodeType = NodeType.injectable; |
73 |
| - } |
74 |
| - return nodeType; |
75 |
| - } |
76 |
| -} |
77 |
| - |
78 |
| -export enum ArrowType { |
79 |
| - none = 0, |
80 |
| - import = 1, |
81 |
| - export = 2, |
82 |
| - injectable = 3 |
83 |
| -} |
84 |
| - |
85 |
| -export class Edge { |
86 |
| - private config: Config = new Config(); |
87 |
| - constructor(id: string, source: string, target: string, arrowType: ArrowType = ArrowType.none) { |
88 |
| - this.id = id; |
89 |
| - this.source = source; |
90 |
| - this.target = target; |
91 |
| - this.arrowType = arrowType; |
92 |
| - } |
93 |
| - public id: string; |
94 |
| - public source: string; |
95 |
| - public target: string; |
96 |
| - public arrowType: ArrowType; |
97 |
| - |
98 |
| - public toJsonString(): string { |
99 |
| - let arrowColorAttr = ''; |
100 |
| - switch (this.arrowType) { |
101 |
| - case ArrowType.import: |
102 |
| - arrowColorAttr = `, color: "${this.config.importEdgeColor}"`; |
103 |
| - break; |
104 |
| - case ArrowType.export: |
105 |
| - arrowColorAttr = `, color: "${this.config.exportEdgeColor}"`; |
106 |
| - break; |
107 |
| - default: |
108 |
| - arrowColorAttr = ''; |
109 |
| - break; |
110 |
| - } |
111 |
| - return `{from: "${this.source}", to: "${this.target}", arrows: arrowAttr ${arrowColorAttr} }`; |
112 |
| - } |
113 |
| -} |
114 | 9 |
|
115 | 10 | export class ShowHierarchyBase extends CommandBase {
|
116 | 11 | protected fsUtils: FileSystemUtils = new FileSystemUtils();
|
@@ -166,7 +61,7 @@ export class ShowHierarchyBase extends CommandBase {
|
166 | 61 | }
|
167 | 62 |
|
168 | 63 | protected saveAsDgml(dgmlGraphFilename: string, messageText: string) {
|
169 |
| - |
| 64 | + |
170 | 65 | }
|
171 | 66 |
|
172 | 67 | protected generateHtmlContent(webview: vscode.Webview, outputJsFilename: string): string {
|
|
0 commit comments