@pega/cosmos-react-build 2.0.0-dev.20.0 → 2.0.0-dev.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppShell/AppShell.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.js +41 -44
- package/lib/components/AppShell/AppShell.js.map +1 -1
- package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.styles.js +22 -17
- package/lib/components/AppShell/AppShell.styles.js.map +1 -1
- package/lib/components/AppShell/AppShell.types.d.ts +14 -9
- package/lib/components/AppShell/AppShell.types.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.types.js.map +1 -1
- package/lib/components/AppShell/AppShellContext.d.ts.map +1 -1
- package/lib/components/AppShell/AppShellContext.js +5 -3
- package/lib/components/AppShell/AppShellContext.js.map +1 -1
- package/lib/components/FlowModeller/FlowModeller.d.ts +6 -5
- package/lib/components/FlowModeller/FlowModeller.d.ts.map +1 -1
- package/lib/components/FlowModeller/FlowModeller.js +184 -61
- package/lib/components/FlowModeller/FlowModeller.js.map +1 -1
- package/lib/components/FlowModeller/Node/Node.types.d.ts +26 -16
- package/lib/components/FlowModeller/Node/Node.types.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/Node.types.js +27 -1
- package/lib/components/FlowModeller/Node/Node.types.js.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts +10 -5
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.js +38 -31
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.js.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplates.d.ts +1 -4
- package/lib/components/FlowModeller/Node/NodeTemplates.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplates.js +25 -19
- package/lib/components/FlowModeller/Node/NodeTemplates.js.map +1 -1
- package/lib/components/FlowModeller/NodeLibrary.d.ts +12 -0
- package/lib/components/FlowModeller/NodeLibrary.d.ts.map +1 -0
- package/lib/components/FlowModeller/NodeLibrary.js +49 -0
- package/lib/components/FlowModeller/NodeLibrary.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/AddNode.d.ts +10 -0
- package/lib/components/FlowModeller/Renderer/AddNode.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/AddNode.js +42 -0
- package/lib/components/FlowModeller/Renderer/AddNode.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Connector.d.ts +5 -0
- package/lib/components/FlowModeller/Renderer/Connector.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Connector.js +50 -0
- package/lib/components/FlowModeller/Renderer/Connector.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.d.ts +12 -0
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.js +15 -0
- package/lib/components/FlowModeller/Renderer/ConnectorsContainer.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Node.d.ts +5 -0
- package/lib/components/FlowModeller/Renderer/Node.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Node.js +18 -0
- package/lib/components/FlowModeller/Renderer/Node.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/NodesContainer.d.ts +8 -0
- package/lib/components/FlowModeller/Renderer/NodesContainer.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/NodesContainer.js +15 -0
- package/lib/components/FlowModeller/Renderer/NodesContainer.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Renderer.d.ts +5 -0
- package/lib/components/FlowModeller/Renderer/Renderer.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Renderer.js +17 -0
- package/lib/components/FlowModeller/Renderer/Renderer.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts +18 -0
- package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Renderer.types.js +2 -0
- package/lib/components/FlowModeller/Renderer/Renderer.types.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts +51 -0
- package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Utils/Graph.js +247 -0
- package/lib/components/FlowModeller/Renderer/Utils/Graph.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.d.ts +35 -0
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.d.ts.map +1 -0
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js +104 -0
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js.map +1 -0
- package/lib/components/FlowModeller/helper.d.ts +22 -0
- package/lib/components/FlowModeller/helper.d.ts.map +1 -0
- package/lib/components/FlowModeller/helper.js +97 -0
- package/lib/components/FlowModeller/helper.js.map +1 -0
- package/lib/components/LifeCycle/Stage.d.ts +3 -1
- package/lib/components/LifeCycle/Stage.d.ts.map +1 -1
- package/lib/components/LifeCycle/Stage.js +9 -2
- package/lib/components/LifeCycle/Stage.js.map +1 -1
- package/lib/components/LifeCycle/Step.d.ts +4 -1
- package/lib/components/LifeCycle/Step.d.ts.map +1 -1
- package/lib/components/LifeCycle/Step.js +12 -2
- package/lib/components/LifeCycle/Step.js.map +1 -1
- package/lib/components/LifeCycle/Task.d.ts +3 -1
- package/lib/components/LifeCycle/Task.d.ts.map +1 -1
- package/lib/components/LifeCycle/Task.js +11 -2
- package/lib/components/LifeCycle/Task.js.map +1 -1
- package/lib/components/SummaryCard/SummaryCard.d.ts.map +1 -1
- package/lib/components/SummaryCard/SummaryCard.js +2 -1
- package/lib/components/SummaryCard/SummaryCard.js.map +1 -1
- package/package.json +4 -3
- package/lib/components/FlowModeller/Connector.d.ts +0 -30
- package/lib/components/FlowModeller/Connector.d.ts.map +0 -1
- package/lib/components/FlowModeller/Connector.js +0 -89
- package/lib/components/FlowModeller/Connector.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export interface ConnectorProps<T = unknown> {
|
|
2
|
+
id: string;
|
|
3
|
+
fromNodeId: string;
|
|
4
|
+
toNodeId: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
data?: T;
|
|
7
|
+
}
|
|
8
|
+
export interface Node<T = unknown> {
|
|
9
|
+
id: string;
|
|
10
|
+
data?: T;
|
|
11
|
+
}
|
|
12
|
+
export interface GraphData<T extends Node, U extends ConnectorProps> {
|
|
13
|
+
nodes: T[];
|
|
14
|
+
connectors: U[];
|
|
15
|
+
}
|
|
16
|
+
export declare class DirectedGraph<T extends Node = Node, U extends ConnectorProps = ConnectorProps, D1 = unknown, // Can be any here.. because nodeData is optional and each node may need to carry its own Data type.
|
|
17
|
+
D2 = unknown> {
|
|
18
|
+
private nodes;
|
|
19
|
+
private connectors;
|
|
20
|
+
private nodeData;
|
|
21
|
+
private connectorData;
|
|
22
|
+
private inConnectors;
|
|
23
|
+
private prevNodesCount;
|
|
24
|
+
private outConnectors;
|
|
25
|
+
private nextNodesCount;
|
|
26
|
+
private nodeCount;
|
|
27
|
+
private connectorsCount;
|
|
28
|
+
constructor(graphData?: GraphData<T, U>);
|
|
29
|
+
getGraphData(): GraphData<T, U>;
|
|
30
|
+
getNodeCount(): number;
|
|
31
|
+
getNodes(): T[];
|
|
32
|
+
addNode(node: T, data?: D1): DirectedGraph;
|
|
33
|
+
getNode(nodeId: string): T;
|
|
34
|
+
hasNode(nodeId: string): boolean;
|
|
35
|
+
deleteNode(nodeId: string, ignoreConnectors?: boolean): DirectedGraph<T, U>;
|
|
36
|
+
getPrevNodes(nodeId: string): T[];
|
|
37
|
+
getNextNodes(nodeId: string): T[];
|
|
38
|
+
getPrevNodesCount(nodeId: string): number;
|
|
39
|
+
getNextNodesCount(nodeId: string): number;
|
|
40
|
+
isLeaf(nodeId: string): boolean;
|
|
41
|
+
getConnectorsCount(): number;
|
|
42
|
+
getConnectors(): U[];
|
|
43
|
+
addConnector(connector: U, data?: D2): DirectedGraph<T, U>;
|
|
44
|
+
hasConnector(id: string): boolean;
|
|
45
|
+
getConnector(id: string): U;
|
|
46
|
+
removeConnector(id: string): DirectedGraph<T, U>;
|
|
47
|
+
getInConnectors(toNodeId: string, fromNodeId?: string): ConnectorProps[];
|
|
48
|
+
getOutConnectors(fromNodeId: string, toNodeId?: string): ConnectorProps[];
|
|
49
|
+
getAllNodeConnectors(nodeId: string): ConnectorProps<unknown>[] | undefined;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=Graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Graph.d.ts","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/Graph.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,IAAI,CAAC,CAAC,GAAG,OAAO;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,SAAS,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,cAAc;IACjE,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,UAAU,EAAE,CAAC,EAAE,CAAC;CACjB;AAED,qBAAa,aAAa,CACxB,CAAC,SAAS,IAAI,GAAG,IAAI,EACrB,CAAC,SAAS,cAAc,GAAG,cAAc,EACzC,EAAE,GAAG,OAAO,EAAE,oGAAoG;AAClH,EAAE,GAAG,OAAO;IAEZ,OAAO,CAAC,KAAK,CAAyB;IACtC,OAAO,CAAC,UAAU,CAAyB;IAG3C,OAAO,C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Aa,CAAC,CAAC,EAAE,CAAC,CAAC;IA+BhD,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,cAAc,EAAE;IAkBxE,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,cAAc,EAAE;IAkBzE,oBAAoB,CAAC,MAAM,EAAE,MAAM;CAOpC"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
export class DirectedGraph {
|
|
2
|
+
constructor(graphData = { nodes: [], connectors: [] }) {
|
|
3
|
+
Object.defineProperty(this, "nodes", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: {}
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "connectors", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: {}
|
|
14
|
+
});
|
|
15
|
+
// additional way to maintain related data - for cases where Graph is used for indirect purposes
|
|
16
|
+
Object.defineProperty(this, "nodeData", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: {}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "connectorData", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: {}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "inConnectors", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: {}
|
|
33
|
+
}); // we are maintaining connector reference instead of id, to avoid iterations later on.
|
|
34
|
+
Object.defineProperty(this, "prevNodesCount", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: {}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(this, "outConnectors", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
writable: true,
|
|
44
|
+
value: {}
|
|
45
|
+
}); // we are maintaining connector reference instead of id, to avoid iterations later on
|
|
46
|
+
Object.defineProperty(this, "nextNodesCount", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
configurable: true,
|
|
49
|
+
writable: true,
|
|
50
|
+
value: {}
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(this, "nodeCount", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
value: 0
|
|
57
|
+
});
|
|
58
|
+
Object.defineProperty(this, "connectorsCount", {
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true,
|
|
62
|
+
value: 0
|
|
63
|
+
});
|
|
64
|
+
// Not necessary to clone, as this class never modifies any nodes
|
|
65
|
+
graphData.nodes.forEach(item => this.addNode(item));
|
|
66
|
+
// copy/clone, connectors properties 'fromNodeId' and 'toNodeId' values may get modified by this class
|
|
67
|
+
graphData.connectors.forEach(item => this.addConnector(JSON.parse(JSON.stringify(item))));
|
|
68
|
+
}
|
|
69
|
+
getGraphData() {
|
|
70
|
+
return {
|
|
71
|
+
nodes: this.getNodes(),
|
|
72
|
+
connectors: this.getConnectors()
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
getNodeCount() {
|
|
76
|
+
return this.nodeCount;
|
|
77
|
+
}
|
|
78
|
+
getNodes() {
|
|
79
|
+
return Object.values(this.nodes);
|
|
80
|
+
}
|
|
81
|
+
addNode(node, data) {
|
|
82
|
+
if (this.nodes[node.id] !== undefined) {
|
|
83
|
+
this.nodes[node.id] = node;
|
|
84
|
+
this.nodeData[node.id] = data;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.nodes[node.id] = node;
|
|
88
|
+
this.nodeData[node.id] = data;
|
|
89
|
+
this.inConnectors[node.id] = {};
|
|
90
|
+
this.prevNodesCount[node.id] = {};
|
|
91
|
+
this.outConnectors[node.id] = {};
|
|
92
|
+
this.nextNodesCount[node.id] = {};
|
|
93
|
+
this.nodeCount += 1;
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
getNode(nodeId) {
|
|
98
|
+
return this.nodes[nodeId];
|
|
99
|
+
}
|
|
100
|
+
hasNode(nodeId) {
|
|
101
|
+
return this.nodes[nodeId] !== undefined;
|
|
102
|
+
}
|
|
103
|
+
deleteNode(nodeId, ignoreConnectors = false) {
|
|
104
|
+
if (this.hasNode(nodeId)) {
|
|
105
|
+
delete this.nodes[nodeId];
|
|
106
|
+
delete this.nodeData[nodeId];
|
|
107
|
+
if (ignoreConnectors !== true) {
|
|
108
|
+
const removeConnector = (id) => this.removeConnector(id);
|
|
109
|
+
// IMP NOTE its the responsibility of the callee to make sure that the connectors are cleanly reassigned, or else all attached connectors will be deleted
|
|
110
|
+
Object.keys(this.inConnectors[nodeId]).forEach(removeConnector);
|
|
111
|
+
delete this.inConnectors[nodeId];
|
|
112
|
+
delete this.prevNodesCount[nodeId];
|
|
113
|
+
Object.keys(this.outConnectors[nodeId]).forEach(removeConnector);
|
|
114
|
+
delete this.outConnectors[nodeId];
|
|
115
|
+
delete this.nextNodesCount[nodeId];
|
|
116
|
+
}
|
|
117
|
+
this.nodeCount += 1;
|
|
118
|
+
}
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
getPrevNodes(nodeId) {
|
|
122
|
+
return this.prevNodesCount[nodeId]
|
|
123
|
+
? Object.keys(this.prevNodesCount[nodeId]).map(id => this.getNode(id))
|
|
124
|
+
: [];
|
|
125
|
+
}
|
|
126
|
+
getNextNodes(nodeId) {
|
|
127
|
+
return this.nextNodesCount[nodeId]
|
|
128
|
+
? Object.keys(this.nextNodesCount[nodeId]).map(id => this.getNode(id))
|
|
129
|
+
: [];
|
|
130
|
+
}
|
|
131
|
+
getPrevNodesCount(nodeId) {
|
|
132
|
+
return (this.prevNodesCount[nodeId] ? Object.values(this.prevNodesCount[nodeId]) : []).reduce((prev, current) => prev + current, 0);
|
|
133
|
+
}
|
|
134
|
+
getNextNodesCount(nodeId) {
|
|
135
|
+
return (this.nextNodesCount[nodeId] ? Object.values(this.nextNodesCount[nodeId]) : []).reduce((prev, current) => prev + current, 0);
|
|
136
|
+
}
|
|
137
|
+
isLeaf(nodeId) {
|
|
138
|
+
return this.getNextNodes(nodeId).length === 0;
|
|
139
|
+
}
|
|
140
|
+
// -- Connectors
|
|
141
|
+
getConnectorsCount() {
|
|
142
|
+
return this.connectorsCount;
|
|
143
|
+
}
|
|
144
|
+
getConnectors() {
|
|
145
|
+
return Object.values(this.connectors);
|
|
146
|
+
}
|
|
147
|
+
addConnector(connector, data) {
|
|
148
|
+
if (this.connectors[connector.id] !== undefined) {
|
|
149
|
+
// update the map
|
|
150
|
+
this.connectors[connector.id] = connector;
|
|
151
|
+
this.connectorData[connector.id] = data;
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
const id = connector.id;
|
|
155
|
+
const fromNodeId = connector.fromNodeId;
|
|
156
|
+
const toNodeId = connector.toNodeId;
|
|
157
|
+
// check if nodes with given ids exist
|
|
158
|
+
if (this.nodes[fromNodeId] === undefined || this.nodes[toNodeId] === undefined) {
|
|
159
|
+
throw new Error(`One or more nodes does not exist, cannot add connector ${fromNodeId}-${toNodeId}`);
|
|
160
|
+
}
|
|
161
|
+
// add it to the map
|
|
162
|
+
this.connectors[id] = connector;
|
|
163
|
+
this.connectorData[id] = data;
|
|
164
|
+
// update prev nodes count
|
|
165
|
+
if (this.prevNodesCount[toNodeId][fromNodeId]) {
|
|
166
|
+
this.prevNodesCount[toNodeId][fromNodeId] += 1;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
this.prevNodesCount[toNodeId][fromNodeId] = 1;
|
|
170
|
+
}
|
|
171
|
+
// update next nodes count
|
|
172
|
+
if (this.nextNodesCount[fromNodeId][toNodeId]) {
|
|
173
|
+
this.nextNodesCount[fromNodeId][toNodeId] += 1;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.nextNodesCount[fromNodeId][toNodeId] = 1;
|
|
177
|
+
}
|
|
178
|
+
// update in and out connectors for both the nodes
|
|
179
|
+
this.inConnectors[toNodeId][id] = connector;
|
|
180
|
+
this.outConnectors[fromNodeId][id] = connector;
|
|
181
|
+
// increment total connectors count
|
|
182
|
+
this.connectorsCount += 1;
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
hasConnector(id) {
|
|
186
|
+
return this.connectors[id] !== undefined;
|
|
187
|
+
}
|
|
188
|
+
getConnector(id) {
|
|
189
|
+
return this.connectors[id];
|
|
190
|
+
}
|
|
191
|
+
removeConnector(id) {
|
|
192
|
+
const connector = this.connectors[id];
|
|
193
|
+
if (connector !== undefined) {
|
|
194
|
+
const fromNodeId = connector.fromNodeId;
|
|
195
|
+
const toNodeId = connector.toNodeId;
|
|
196
|
+
delete this.connectors[id];
|
|
197
|
+
delete this.connectorData[id];
|
|
198
|
+
// update prev nodes count
|
|
199
|
+
this.prevNodesCount[toNodeId][fromNodeId] -= 1;
|
|
200
|
+
if (this.prevNodesCount[toNodeId][fromNodeId] === 0) {
|
|
201
|
+
delete this.prevNodesCount[toNodeId][fromNodeId];
|
|
202
|
+
}
|
|
203
|
+
// update next nodes count
|
|
204
|
+
this.nextNodesCount[fromNodeId][toNodeId] -= 1;
|
|
205
|
+
if (this.nextNodesCount[fromNodeId][toNodeId] === 0) {
|
|
206
|
+
delete this.nextNodesCount[fromNodeId][toNodeId];
|
|
207
|
+
}
|
|
208
|
+
delete this.inConnectors[toNodeId][id];
|
|
209
|
+
delete this.outConnectors[fromNodeId][id];
|
|
210
|
+
this.connectorsCount -= 1;
|
|
211
|
+
}
|
|
212
|
+
return this;
|
|
213
|
+
}
|
|
214
|
+
getInConnectors(toNodeId, fromNodeId) {
|
|
215
|
+
const allInConnectors = this.inConnectors[toNodeId];
|
|
216
|
+
if (allInConnectors) {
|
|
217
|
+
const connectorValues = Object.values(allInConnectors);
|
|
218
|
+
if (fromNodeId === undefined) {
|
|
219
|
+
return connectorValues;
|
|
220
|
+
}
|
|
221
|
+
return connectorValues.filter(connector => {
|
|
222
|
+
return connector.fromNodeId === fromNodeId;
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
getOutConnectors(fromNodeId, toNodeId) {
|
|
228
|
+
const allOutConnectors = this.outConnectors[fromNodeId];
|
|
229
|
+
if (allOutConnectors) {
|
|
230
|
+
const connectorValues = Object.values(allOutConnectors);
|
|
231
|
+
if (toNodeId === undefined) {
|
|
232
|
+
return connectorValues;
|
|
233
|
+
}
|
|
234
|
+
return connectorValues.filter(connector => {
|
|
235
|
+
return connector.toNodeId === toNodeId;
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
getAllNodeConnectors(nodeId) {
|
|
241
|
+
const inConnectors = this.getInConnectors(nodeId);
|
|
242
|
+
if (inConnectors) {
|
|
243
|
+
return inConnectors.concat(this.getOutConnectors(nodeId));
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=Graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Graph.js","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/Graph.ts"],"names":[],"mappings":"AAkBA,MAAM,OAAO,aAAa;IAsBxB,YAAY,YAA6B,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE;QAhBtE;;;;mBAAmC,EAAE;WAAC;QACtC;;;;mBAAwC,EAAE;WAAC;QAE3C,gGAAgG;QAChG;;;;mBAAiD,EAAE;WAAC;QACpD;;;;mBAAsD,EAAE;WAAC;QAEzD;;;;mBAA0D,EAAE;WAAC,CAAC,sFAAsF;QACpJ;;;;mB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,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,gBAAgB,CAAC,UAAkB,EAAE,QAAiB;QACpD,MAAM,gBAAgB,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;QAExD,IAAI,gBAAgB,EAAE;YACpB,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YAExD,IAAI,QAAQ,KAAK,SAAS,EAAE;gBAC1B,OAAO,eAAe,CAAC;aACxB;YAED,OAAO,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE;gBACxC,OAAO,SAAS,CAAC,QAAQ,KAAK,QAAQ,CAAC;YACzC,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,oBAAoB,CAAC,MAAc;QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QAElD,IAAI,YAAY,EAAE;YAChB,OAAO,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;SAC3D;IACH,CAAC;CACF","sourcesContent":["export interface ConnectorProps<T = unknown> {\n id: string;\n fromNodeId: string;\n toNodeId: string;\n label?: string;\n data?: T;\n}\n\nexport interface Node<T = unknown> {\n id: string;\n data?: T;\n}\n\nexport interface GraphData<T extends Node, U extends ConnectorProps> {\n nodes: T[];\n connectors: U[];\n}\n\nexport class DirectedGraph<\n T extends Node = Node,\n U extends ConnectorProps = ConnectorProps,\n D1 = unknown, // Can be any here.. because nodeData is optional and each node may need to carry its own Data type.\n D2 = unknown // Can be any here.. because connectorData is optional and each connector may need to carry its own Data type.\n> {\n private nodes: Record<string, T> = {};\n private connectors: Record<string, U> = {};\n\n // additional way to maintain related data - for cases where Graph is used for indirect purposes\n private nodeData: Record<string, D1 | unknown> = {};\n private connectorData: Record<string, D2 | unknown> = {};\n\n private inConnectors: Record<string, Record<string, U>> = {}; // we are maintaining connector reference instead of id, to avoid iterations later on.\n private prevNodesCount: Record<string, Record<string, number>> = {};\n\n private outConnectors: Record<string, Record<string, U>> = {}; // we are maintaining connector reference instead of id, to avoid iterations later on\n private nextNodesCount: Record<string, Record<string, number>> = {};\n\n private nodeCount = 0;\n private connectorsCount = 0;\n\n constructor(graphData: GraphData<T, U> = { nodes: [], connectors: [] }) {\n // Not necessary to clone, as this class never modifies any nodes\n graphData.nodes.forEach(item => this.addNode(item));\n // copy/clone, connectors properties 'fromNodeId' and 'toNodeId' values may get modified by this class\n graphData.connectors.forEach(item => this.addConnector(JSON.parse(JSON.stringify(item))));\n }\n\n getGraphData(): GraphData<T, U> {\n return {\n nodes: this.getNodes(),\n connectors: this.getConnectors()\n };\n }\n\n getNodeCount(): number {\n return this.nodeCount;\n }\n\n getNodes() {\n return Object.values(this.nodes);\n }\n\n addNode(node: T, data?: D1): DirectedGraph {\n if (this.nodes[node.id] !== undefined) {\n this.nodes[node.id] = node;\n this.nodeData[node.id] = data;\n } else {\n this.nodes[node.id] = node;\n this.nodeData[node.id] = data;\n\n this.inConnectors[node.id] = {};\n this.prevNodesCount[node.id] = {};\n\n this.outConnectors[node.id] = {};\n this.nextNodesCount[node.id] = {};\n\n this.nodeCount += 1;\n }\n\n return this;\n }\n\n getNode(nodeId: string): T {\n return this.nodes[nodeId];\n }\n\n hasNode(nodeId: string): boolean {\n return this.nodes[nodeId] !== undefined;\n }\n\n deleteNode(nodeId: string, ignoreConnectors = false): DirectedGraph<T, U> {\n if (this.hasNode(nodeId)) {\n delete this.nodes[nodeId];\n delete this.nodeData[nodeId];\n\n if (ignoreConnectors !== true) {\n const removeConnector = (id: string) => this.removeConnector(id);\n\n // IMP NOTE its the responsibility of the callee to make sure that the connectors are cleanly reassigned, or else all attached connectors will be deleted\n\n Object.keys(this.inConnectors[nodeId]).forEach(removeConnector);\n delete this.inConnectors[nodeId];\n delete this.prevNodesCount[nodeId];\n\n Object.keys(this.outConnectors[nodeId]).forEach(removeConnector);\n delete this.outConnectors[nodeId];\n delete this.nextNodesCount[nodeId];\n }\n\n this.nodeCount += 1;\n }\n\n return this;\n }\n\n getPrevNodes(nodeId: string): T[] {\n return this.prevNodesCount[nodeId]\n ? Object.keys(this.prevNodesCount[nodeId]).map(id => this.getNode(id))\n : [];\n }\n\n getNextNodes(nodeId: string): T[] {\n return this.nextNodesCount[nodeId]\n ? Object.keys(this.nextNodesCount[nodeId]).map(id => this.getNode(id))\n : [];\n }\n\n getPrevNodesCount(nodeId: string): number {\n return (this.prevNodesCount[nodeId] ? Object.values(this.prevNodesCount[nodeId]) : []).reduce(\n (prev, current) => prev + current,\n 0\n );\n }\n\n getNextNodesCount(nodeId: string): number {\n return (this.nextNodesCount[nodeId] ? Object.values(this.nextNodesCount[nodeId]) : []).reduce(\n (prev, current) => prev + current,\n 0\n );\n }\n\n isLeaf(nodeId: string): boolean {\n return this.getNextNodes(nodeId).length === 0;\n }\n\n // -- Connectors\n getConnectorsCount(): number {\n return this.connectorsCount;\n }\n\n getConnectors() {\n return Object.values(this.connectors);\n }\n\n addConnector(connector: U, data?: D2): DirectedGraph<T, U> {\n if (this.connectors[connector.id] !== undefined) {\n // update the map\n this.connectors[connector.id] = connector;\n this.connectorData[connector.id] = data;\n\n return this;\n }\n\n const id = connector.id;\n const fromNodeId = connector.fromNodeId;\n const toNodeId = connector.toNodeId;\n\n // check if nodes with given ids exist\n if (this.nodes[fromNodeId] === undefined || this.nodes[toNodeId] === undefined) {\n throw new Error(\n `One or more nodes does not exist, cannot add connector ${fromNodeId}-${toNodeId}`\n );\n }\n\n // add it to the map\n this.connectors[id] = connector;\n this.connectorData[id] = data;\n\n // update prev nodes count\n if (this.prevNodesCount[toNodeId][fromNodeId]) {\n this.prevNodesCount[toNodeId][fromNodeId] += 1;\n } else {\n this.prevNodesCount[toNodeId][fromNodeId] = 1;\n }\n\n // update next nodes count\n if (this.nextNodesCount[fromNodeId][toNodeId]) {\n this.nextNodesCount[fromNodeId][toNodeId] += 1;\n } else {\n this.nextNodesCount[fromNodeId][toNodeId] = 1;\n }\n\n // update in and out connectors for both the nodes\n this.inConnectors[toNodeId][id] = connector;\n this.outConnectors[fromNodeId][id] = connector;\n\n // increment total connectors count\n this.connectorsCount += 1;\n\n return this;\n }\n\n hasConnector(id: string): boolean {\n return this.connectors[id] !== undefined;\n }\n\n getConnector(id: string): U {\n return this.connectors[id];\n }\n\n removeConnector(id: string): DirectedGraph<T, U> {\n const connector = this.connectors[id];\n\n if (connector !== undefined) {\n const fromNodeId = connector.fromNodeId;\n const toNodeId = connector.toNodeId;\n\n delete this.connectors[id];\n delete this.connectorData[id];\n\n // update prev nodes count\n this.prevNodesCount[toNodeId][fromNodeId] -= 1;\n if (this.prevNodesCount[toNodeId][fromNodeId] === 0) {\n delete this.prevNodesCount[toNodeId][fromNodeId];\n }\n\n // update next nodes count\n this.nextNodesCount[fromNodeId][toNodeId] -= 1;\n if (this.nextNodesCount[fromNodeId][toNodeId] === 0) {\n delete this.nextNodesCount[fromNodeId][toNodeId];\n }\n\n delete this.inConnectors[toNodeId][id];\n delete this.outConnectors[fromNodeId][id];\n\n this.connectorsCount -= 1;\n }\n\n return this;\n }\n\n getInConnectors(toNodeId: string, fromNodeId?: string): ConnectorProps[] {\n const allInConnectors = this.inConnectors[toNodeId];\n\n if (allInConnectors) {\n const connectorValues = Object.values(allInConnectors);\n\n if (fromNodeId === undefined) {\n return connectorValues;\n }\n\n return connectorValues.filter(connector => {\n return connector.fromNodeId === fromNodeId;\n });\n }\n\n return [];\n }\n\n getOutConnectors(fromNodeId: string, toNodeId?: string): ConnectorProps[] {\n const allOutConnectors = this.outConnectors[fromNodeId];\n\n if (allOutConnectors) {\n const connectorValues = Object.values(allOutConnectors);\n\n if (toNodeId === undefined) {\n return connectorValues;\n }\n\n return connectorValues.filter(connector => {\n return connector.toNodeId === toNodeId;\n });\n }\n\n return [];\n }\n\n getAllNodeConnectors(nodeId: string) {\n const inConnectors = this.getInConnectors(nodeId);\n\n if (inConnectors) {\n return inConnectors.concat(this.getOutConnectors(nodeId));\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ConnectorProps, GraphData, Node } from './Graph';
|
|
2
|
+
export interface PlottedGraphNode<T = any> extends Node<T> {
|
|
3
|
+
dimensions: {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
};
|
|
7
|
+
position: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export interface PlottedGraphConnector<T = any> extends ConnectorProps<T> {
|
|
13
|
+
points: {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
}[];
|
|
17
|
+
labelLayout?: {
|
|
18
|
+
value: any;
|
|
19
|
+
width: number;
|
|
20
|
+
height: number;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare enum GraphLayoutDirection {
|
|
26
|
+
LeftToRight = "LR",
|
|
27
|
+
TopToBottom = "TB"
|
|
28
|
+
}
|
|
29
|
+
export default class GraphLayout {
|
|
30
|
+
static plot<T extends GraphData<PlottedGraphNode, PlottedGraphConnector>>(graphData: T, direction?: GraphLayoutDirection): {
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=GraphLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphLayout.d.ts","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/GraphLayout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE1D,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,IAAI,CAAC,CAAC,CAAC;IACxD,UAAU,EAAE;QACV,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,QAAQ,EAAE;QACR,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;CACH;AAED,MAAM,WAAW,qBAAqB,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,cAAc,CAAC,CAAC,CAAC;IACvE,MAAM,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACnC,WAAW,CAAC,EAAE;QACZ,KAAK,EAAE,GAAG,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;CACH;AAED,oBAAY,oBAAoB;IAC9B,WAAW,OAAO;IAClB,WAAW,OAAO;CACnB;AAKD,MAAM,CAAC,OAAO,OAAO,WAAW;IAE9B,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,SAAS,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,EACtE,SAAS,EAAE,CAAC,EACZ,SAAS,GAAE,oBAAuD;;;;CA8GrE"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import dagre from 'dagre';
|
|
2
|
+
export var GraphLayoutDirection;
|
|
3
|
+
(function (GraphLayoutDirection) {
|
|
4
|
+
GraphLayoutDirection["LeftToRight"] = "LR";
|
|
5
|
+
GraphLayoutDirection["TopToBottom"] = "TB";
|
|
6
|
+
})(GraphLayoutDirection || (GraphLayoutDirection = {}));
|
|
7
|
+
const DEFAULT_GRAPH_WIDTH = 2000;
|
|
8
|
+
const DEFAULT_GRAPH_HEIGHT = 2000;
|
|
9
|
+
export default class GraphLayout {
|
|
10
|
+
// Using Dagre layouting
|
|
11
|
+
static plot(graphData, direction = GraphLayoutDirection.TopToBottom) {
|
|
12
|
+
const dagreGraph = new dagre.graphlib.Graph();
|
|
13
|
+
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
|
14
|
+
const defaultNodeWidth = 280;
|
|
15
|
+
const defaultNodeHeight = 112;
|
|
16
|
+
dagreGraph.setGraph({
|
|
17
|
+
rankdir: direction,
|
|
18
|
+
ranksep: 10,
|
|
19
|
+
edgesep: defaultNodeWidth / 2,
|
|
20
|
+
nodesep: 40,
|
|
21
|
+
// cspell:disable-next
|
|
22
|
+
marginx: 200,
|
|
23
|
+
// cspell:disable-next
|
|
24
|
+
marginy: 50
|
|
25
|
+
});
|
|
26
|
+
graphData.nodes.forEach(node => {
|
|
27
|
+
dagreGraph.setNode(node.id, {
|
|
28
|
+
width: node.dimensions.width ? node.dimensions.width : defaultNodeWidth,
|
|
29
|
+
height: node.dimensions.height ? node.dimensions.height : defaultNodeHeight
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
graphData.connectors.forEach(con => {
|
|
33
|
+
dagreGraph.setEdge(con.fromNodeId, con.toNodeId, {
|
|
34
|
+
weight: 1,
|
|
35
|
+
minlen: 1,
|
|
36
|
+
label: con.data?.label,
|
|
37
|
+
width: 200,
|
|
38
|
+
height: 60,
|
|
39
|
+
// cspell:disable-next
|
|
40
|
+
lablepos: 'c',
|
|
41
|
+
labeloffset: 0
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
dagre.layout(dagreGraph, {});
|
|
45
|
+
graphData.nodes.forEach(el => {
|
|
46
|
+
const node = dagreGraph.node(el.id);
|
|
47
|
+
el.position.x = node.x - el.dimensions.width / 2;
|
|
48
|
+
el.position.y = node.y - el.dimensions.height / 2;
|
|
49
|
+
});
|
|
50
|
+
graphData.connectors.forEach(con => {
|
|
51
|
+
const edge = dagreGraph.edge(con.fromNodeId, con.toNodeId);
|
|
52
|
+
con.labelLayout = {
|
|
53
|
+
value: edge.label,
|
|
54
|
+
x: edge.x,
|
|
55
|
+
y: edge.y - 10,
|
|
56
|
+
width: edge.width,
|
|
57
|
+
height: edge.height
|
|
58
|
+
};
|
|
59
|
+
const lastIndex = edge.points.length - 1;
|
|
60
|
+
let firstPoint = edge.points[0];
|
|
61
|
+
const secondPoint = edge.points[1];
|
|
62
|
+
let lastPoint = edge.points[lastIndex];
|
|
63
|
+
const secondLastPoint = edge.points[lastIndex - 1];
|
|
64
|
+
const fromNode = dagreGraph.node(con.fromNodeId);
|
|
65
|
+
const toNode = dagreGraph.node(con.toNodeId);
|
|
66
|
+
firstPoint =
|
|
67
|
+
firstPoint.x !== secondPoint.x
|
|
68
|
+
? {
|
|
69
|
+
...edge.points[0],
|
|
70
|
+
x: fromNode.x,
|
|
71
|
+
y: edge.points[1].y
|
|
72
|
+
}
|
|
73
|
+
: firstPoint;
|
|
74
|
+
lastPoint =
|
|
75
|
+
lastPoint.x !== secondLastPoint.x
|
|
76
|
+
? {
|
|
77
|
+
...edge.points[lastIndex],
|
|
78
|
+
x: toNode.x,
|
|
79
|
+
y: edge.points[lastIndex - 1].y
|
|
80
|
+
}
|
|
81
|
+
: lastPoint;
|
|
82
|
+
con.points = [
|
|
83
|
+
{ x: fromNode.x, y: fromNode.y + fromNode.height / 2 },
|
|
84
|
+
firstPoint,
|
|
85
|
+
...edge.points.slice(1, lastIndex),
|
|
86
|
+
lastPoint,
|
|
87
|
+
{ x: toNode.x, y: toNode.y }
|
|
88
|
+
];
|
|
89
|
+
});
|
|
90
|
+
const width = dagreGraph.graph().width;
|
|
91
|
+
const height = dagreGraph.graph().height;
|
|
92
|
+
if (width !== undefined && height !== undefined) {
|
|
93
|
+
return {
|
|
94
|
+
width: Number.isFinite(width) ? width : DEFAULT_GRAPH_WIDTH,
|
|
95
|
+
height: Number.isFinite(height) ? height : DEFAULT_GRAPH_HEIGHT
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
width: DEFAULT_GRAPH_WIDTH,
|
|
100
|
+
height: DEFAULT_GRAPH_HEIGHT
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=GraphLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GraphLayout.js","sourceRoot":"","sources":["../../../../../src/components/FlowModeller/Renderer/Utils/GraphLayout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AA0B1B,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,0CAAkB,CAAA;IAClB,0CAAkB,CAAA;AACpB,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AAED,MAAM,mBAAmB,GAAG,IAAI,CAAC;AACjC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B,wBAAwB;IACxB,MAAM,CAAC,IAAI,CACT,SAAY,EACZ,YAAkC,oBAAoB,CAAC,WAAW;QAElE,MAAM,UAAU,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAE9C,UAAU,CAAC,mBAAmB,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAE3C,MAAM,gBAAgB,GAAG,GAAG,CAAC;QAC7B,MAAM,iBAAiB,GAAG,GAAG,CAAC;QAE9B,UAAU,CAAC,QAAQ,CAAC;YAClB,OAAO,EAAE,SAAS;YAClB,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,gBAAgB,GAAG,CAAC;YAC7B,OAAO,EAAE,EAAE;YACX,sBAAsB;YACtB,OAAO,EAAE,GAAG;YACZ,sBAAsB;YACtB,OAAO,EAAE,EAAE;SACZ,CAAC,CAAC;QAEH,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YAC7B,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE;gBAC1B,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB;g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AC,SAAS,CAAC;YAEhB,GAAG,CAAC,MAAM,GAAG;gBACX,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;gBACtD,UAAU;gBACV,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC;gBAClC,SAAS;gBACT,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE;aAC7B,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC;QACvC,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC;QAEzC,IAAI,KAAK,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE;YAC/C,OAAO;gBACL,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,mBAAmB;gBAC3D,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB;aAChE,CAAC;SACH;QAED,OAAO;YACL,KAAK,EAAE,mBAAmB;YAC1B,MAAM,EAAE,oBAAoB;SAC7B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import dagre from 'dagre';\n\nimport { ConnectorProps, GraphData, Node } from './Graph';\n\nexport interface PlottedGraphNode<T = any> extends Node<T> {\n dimensions: {\n width: number;\n height: number;\n };\n position: {\n x: number;\n y: number;\n };\n}\n\nexport interface PlottedGraphConnector<T = any> extends ConnectorProps<T> {\n points: { x: number; y: number }[];\n labelLayout?: {\n value: any;\n width: number;\n height: number;\n x: number;\n y: number;\n };\n}\n\nexport enum GraphLayoutDirection {\n LeftToRight = 'LR',\n TopToBottom = 'TB'\n}\n\nconst DEFAULT_GRAPH_WIDTH = 2000;\nconst DEFAULT_GRAPH_HEIGHT = 2000;\n\nexport default class GraphLayout {\n // Using Dagre layouting\n static plot<T extends GraphData<PlottedGraphNode, PlottedGraphConnector>>(\n graphData: T,\n direction: GraphLayoutDirection = GraphLayoutDirection.TopToBottom\n ) {\n const dagreGraph = new dagre.graphlib.Graph();\n\n dagreGraph.setDefaultEdgeLabel(() => ({}));\n\n const defaultNodeWidth = 280;\n const defaultNodeHeight = 112;\n\n dagreGraph.setGraph({\n rankdir: direction,\n ranksep: 10,\n edgesep: defaultNodeWidth / 2,\n nodesep: 40,\n // cspell:disable-next\n marginx: 200,\n // cspell:disable-next\n marginy: 50\n });\n\n graphData.nodes.forEach(node => {\n dagreGraph.setNode(node.id, {\n width: node.dimensions.width ? node.dimensions.width : defaultNodeWidth,\n height: node.dimensions.height ? node.dimensions.height : defaultNodeHeight\n });\n });\n\n graphData.connectors.forEach(con => {\n dagreGraph.setEdge(con.fromNodeId, con.toNodeId, {\n weight: 1,\n minlen: 1,\n label: con.data?.label,\n width: 200,\n height: 60,\n // cspell:disable-next\n lablepos: 'c',\n labeloffset: 0\n });\n });\n\n dagre.layout(dagreGraph, {});\n\n graphData.nodes.forEach(el => {\n const node = dagreGraph.node(el.id);\n el.position.x = node.x - el.dimensions.width / 2;\n el.position.y = node.y - el.dimensions.height / 2;\n });\n\n graphData.connectors.forEach(con => {\n const edge = dagreGraph.edge(con.fromNodeId, con.toNodeId);\n\n con.labelLayout = {\n value: edge.label,\n x: edge.x,\n y: edge.y - 10,\n width: edge.width,\n height: edge.height\n };\n\n const lastIndex = edge.points.length - 1;\n let firstPoint = edge.points[0];\n const secondPoint = edge.points[1];\n let lastPoint = edge.points[lastIndex];\n const secondLastPoint = edge.points[lastIndex - 1];\n\n const fromNode = dagreGraph.node(con.fromNodeId);\n const toNode = dagreGraph.node(con.toNodeId);\n\n firstPoint =\n firstPoint.x !== secondPoint.x\n ? {\n ...edge.points[0],\n x: fromNode.x,\n y: edge.points[1].y\n }\n : firstPoint;\n\n lastPoint =\n lastPoint.x !== secondLastPoint.x\n ? {\n ...edge.points[lastIndex],\n x: toNode.x,\n y: edge.points[lastIndex - 1].y\n }\n : lastPoint;\n\n con.points = [\n { x: fromNode.x, y: fromNode.y + fromNode.height / 2 },\n firstPoint,\n ...edge.points.slice(1, lastIndex),\n lastPoint,\n { x: toNode.x, y: toNode.y }\n ];\n });\n\n const width = dagreGraph.graph().width;\n const height = dagreGraph.graph().height;\n\n if (width !== undefined && height !== undefined) {\n return {\n width: Number.isFinite(width) ? width : DEFAULT_GRAPH_WIDTH,\n height: Number.isFinite(height) ? height : DEFAULT_GRAPH_HEIGHT\n };\n }\n\n return {\n width: DEFAULT_GRAPH_WIDTH,\n height: DEFAULT_GRAPH_HEIGHT\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { GraphData, ConnectorProps } from './Renderer/Utils/Graph';
|
|
2
|
+
import { AddNodeHandlerParams } from './Renderer/Renderer.types';
|
|
3
|
+
import { NodeProps, NodeType } from './Node/Node.types';
|
|
4
|
+
interface NodeDataType {
|
|
5
|
+
nodes: NodeProps[];
|
|
6
|
+
connectors: ConnectorProps[];
|
|
7
|
+
}
|
|
8
|
+
export interface AddHelperParams {
|
|
9
|
+
nodeType: NodeType;
|
|
10
|
+
graphData: GraphData<NodeProps, ConnectorProps>;
|
|
11
|
+
metaData: AddNodeHandlerParams;
|
|
12
|
+
connectorsCount?: number;
|
|
13
|
+
getNewNode?: () => NodeProps;
|
|
14
|
+
getNewConnector?: (fromNodeId: string, toNodeId: string) => ConnectorProps;
|
|
15
|
+
}
|
|
16
|
+
declare const helpers: {
|
|
17
|
+
deleteNode(graphData: NodeDataType, nodeId: string): GraphData<NodeProps, ConnectorProps<unknown>> | null;
|
|
18
|
+
deleteConnector: (graphData: NodeDataType, connector: ConnectorProps) => GraphData<NodeProps, ConnectorProps<unknown>> | null;
|
|
19
|
+
addNode: ({ graphData, nodeType, metaData, getNewNode, getNewConnector, connectorsCount }: AddHelperParams) => GraphData<NodeProps, ConnectorProps<unknown>>;
|
|
20
|
+
};
|
|
21
|
+
export default helpers;
|
|
22
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../src/components/FlowModeller/helper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,SAAS,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAiB,MAAM,mBAAmB,CAAC;AAEvE,UAAU,YAAY;IACpB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,UAAU,EAAE,cAAc,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAChD,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,SAAS,CAAC;IAC7B,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,cAAc,CAAC;CAC5E;AAED,QAAA,MAAM,OAAO;0BACW,YAAY,UAAU,MAAM;iCAmBrB,YAAY,aAAa,cAAc;+FAqCjE,eAAe;CAqDnB,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createUID } from '@pega/cosmos-react-core';
|
|
2
|
+
import { DirectedGraph } from './Renderer/Utils/Graph';
|
|
3
|
+
import { STOP_NODETYPE } from './Node/Node.types';
|
|
4
|
+
const helpers = {
|
|
5
|
+
deleteNode(graphData, nodeId) {
|
|
6
|
+
const graph = new DirectedGraph(graphData);
|
|
7
|
+
const outConnectors = graph.getOutConnectors(nodeId);
|
|
8
|
+
if (outConnectors.length > 1) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const inConnectors = graph.getInConnectors(nodeId);
|
|
12
|
+
inConnectors.forEach(con => {
|
|
13
|
+
con.toNodeId = outConnectors[0].toNodeId;
|
|
14
|
+
});
|
|
15
|
+
graph.removeConnector(outConnectors[0].id);
|
|
16
|
+
graph.deleteNode(nodeId, true);
|
|
17
|
+
return graph.getGraphData();
|
|
18
|
+
},
|
|
19
|
+
deleteConnector: (graphData, connector) => {
|
|
20
|
+
const graph = new DirectedGraph(graphData);
|
|
21
|
+
const nodeId = connector.fromNodeId;
|
|
22
|
+
const outConnectors = graph.getOutConnectors(nodeId);
|
|
23
|
+
const toNode = graph.getNode(connector.toNodeId);
|
|
24
|
+
const inConnectors = graph.getInConnectors(connector.toNodeId);
|
|
25
|
+
let isRemoved = false;
|
|
26
|
+
if (inConnectors.length >= 2) {
|
|
27
|
+
graph.removeConnector(connector.id);
|
|
28
|
+
isRemoved = true;
|
|
29
|
+
}
|
|
30
|
+
if (toNode.type.id === STOP_NODETYPE.id && outConnectors.length > 1 && !isRemoved) {
|
|
31
|
+
graph.removeConnector(connector.id);
|
|
32
|
+
isRemoved = true;
|
|
33
|
+
}
|
|
34
|
+
if (outConnectors.length > 1 && !isRemoved) {
|
|
35
|
+
outConnectors.forEach(item => {
|
|
36
|
+
if (connector.toNodeId === item.toNodeId && item.id !== connector.id) {
|
|
37
|
+
// Connector without any node
|
|
38
|
+
graph.removeConnector(connector.id);
|
|
39
|
+
isRemoved = true;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (isRemoved) {
|
|
44
|
+
return graph.getGraphData();
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
},
|
|
48
|
+
addNode: ({ graphData, nodeType, metaData, getNewNode, getNewConnector, connectorsCount }) => {
|
|
49
|
+
const graph = new DirectedGraph(graphData);
|
|
50
|
+
const newNode = getNewNode
|
|
51
|
+
? getNewNode()
|
|
52
|
+
: {
|
|
53
|
+
...nodeType.defaults.node,
|
|
54
|
+
id: createUID(),
|
|
55
|
+
type: nodeType
|
|
56
|
+
};
|
|
57
|
+
// add new node
|
|
58
|
+
graph.addNode(newNode);
|
|
59
|
+
let toNodeId = '';
|
|
60
|
+
if (metaData.refType === 'connector') {
|
|
61
|
+
const refConnector = graph.getConnector(metaData.refId);
|
|
62
|
+
// backup current connectors toNodeId
|
|
63
|
+
toNodeId = refConnector.toNodeId;
|
|
64
|
+
// update the actual connector
|
|
65
|
+
refConnector.toNodeId = newNode.id;
|
|
66
|
+
}
|
|
67
|
+
else if (metaData.refType === 'node') {
|
|
68
|
+
toNodeId = metaData.refId;
|
|
69
|
+
// iterate and update all in-connectors to point to the new node
|
|
70
|
+
graph.getInConnectors(metaData.refId).forEach(con => {
|
|
71
|
+
con.toNodeId = newNode.id;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
let minConnectors = 1;
|
|
75
|
+
if (connectorsCount !== undefined) {
|
|
76
|
+
minConnectors = connectorsCount;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
minConnectors = nodeType.minConnectors !== undefined ? nodeType.minConnectors : 1;
|
|
80
|
+
}
|
|
81
|
+
for (let i = 0; i < minConnectors; i += 1) {
|
|
82
|
+
const newConnector = getNewConnector
|
|
83
|
+
? getNewConnector(newNode.id, toNodeId)
|
|
84
|
+
: {
|
|
85
|
+
id: createUID(),
|
|
86
|
+
fromNodeId: newNode.id,
|
|
87
|
+
toNodeId,
|
|
88
|
+
label: nodeType.defaults?.connector[i].label
|
|
89
|
+
};
|
|
90
|
+
graph.addConnector(newConnector);
|
|
91
|
+
}
|
|
92
|
+
// return the updated graphData
|
|
93
|
+
return graph.getGraphData();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
export default helpers;
|
|
97
|
+
//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EAAE,EAAE,SAAS,EAAE;oBACf,UAAU,EAAE,OAAO,CAAC,EAAE;oBACtB,QAAQ;oBACR,KAAK,EAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK;iBAC7C,CAAC;YACN,KAAK,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;SAClC;QACD,+BAA+B;QAC/B,OAAO,KAAK,CAAC,YAAY,EAAE,CAAC;IAC9B,CAAC;CACF,CAAC;AAEF,eAAe,OAAO,CAAC","sourcesContent":["import { createUID } from '@pega/cosmos-react-core';\n\nimport { DirectedGraph, GraphData, ConnectorProps } from './Renderer/Utils/Graph';\nimport { AddNodeHandlerParams } from './Renderer/Renderer.types';\nimport { NodeProps, NodeType, STOP_NODETYPE } from './Node/Node.types';\n\ninterface NodeDataType {\n nodes: NodeProps[];\n connectors: ConnectorProps[];\n}\n\nexport interface AddHelperParams {\n nodeType: NodeType;\n graphData: GraphData<NodeProps, ConnectorProps>;\n metaData: AddNodeHandlerParams;\n connectorsCount?: number;\n getNewNode?: () => NodeProps;\n getNewConnector?: (fromNodeId: string, toNodeId: string) => ConnectorProps;\n}\n\nconst helpers = {\n deleteNode(graphData: NodeDataType, nodeId: string) {\n const graph = new DirectedGraph<NodeProps, ConnectorProps>(graphData);\n const outConnectors = graph.getOutConnectors(nodeId);\n\n if (outConnectors.length > 1) {\n return null;\n }\n const inConnectors = graph.getInConnectors(nodeId);\n\n inConnectors.forEach(con => {\n con.toNodeId = outConnectors[0].toNodeId;\n });\n\n graph.removeConnector(outConnectors[0].id);\n\n graph.deleteNode(nodeId, true);\n\n return graph.getGraphData();\n },\n deleteConnector: (graphData: NodeDataType, connector: ConnectorProps) => {\n const graph = new DirectedGraph<NodeProps, ConnectorProps>(graphData);\n const nodeId = connector.fromNodeId;\n const outConnectors = graph.getOutConnectors(nodeId);\n const toNode = graph.getNode(connector.toNodeId);\n const inConnectors = graph.getInConnectors(connector.toNodeId);\n let isRemoved = false;\n if (inConnectors.length >= 2) {\n graph.removeConnector(connector.id);\n isRemoved = true;\n }\n if (toNode.type.id === STOP_NODETYPE.id && outConnectors.length > 1 && !isRemoved) {\n graph.removeConnector(connector.id);\n isRemoved = true;\n }\n\n if (outConnectors.length > 1 && !isRemoved) {\n outConnectors.forEach(item => {\n if (connector.toNodeId === item.toNodeId && item.id !== connector.id) {\n // Connector without any node\n graph.removeConnector(connector.id);\n isRemoved = true;\n }\n });\n }\n if (isRemoved) {\n return graph.getGraphData();\n }\n return null;\n },\n addNode: ({\n graphData,\n nodeType,\n metaData,\n getNewNode,\n getNewConnector,\n connectorsCount\n }: AddHelperParams) => {\n const graph = new DirectedGraph(graphData);\n\n const newNode = getNewNode\n ? getNewNode()\n : {\n ...nodeType.defaults.node,\n id: createUID(),\n type: nodeType\n };\n\n // add new node\n graph.addNode(newNode);\n\n let toNodeId = '';\n if (metaData.refType === 'connector') {\n const refConnector = graph.getConnector(metaData.refId);\n\n // backup current connectors toNodeId\n toNodeId = refConnector.toNodeId;\n\n // update the actual connector\n refConnector.toNodeId = newNode.id;\n } else if (metaData.refType === 'node') {\n toNodeId = metaData.refId;\n\n // iterate and update all in-connectors to point to the new node\n graph.getInConnectors(metaData.refId).forEach(con => {\n con.toNodeId = newNode.id;\n });\n }\n\n let minConnectors = 1;\n if (connectorsCount !== undefined) {\n minConnectors = connectorsCount;\n } else {\n minConnectors = nodeType.minConnectors !== undefined ? nodeType.minConnectors : 1;\n }\n\n for (let i = 0; i < minConnectors; i += 1) {\n const newConnector = getNewConnector\n ? getNewConnector(newNode.id, toNodeId)\n : {\n id: createUID(),\n fromNodeId: newNode.id,\n toNodeId,\n label: nodeType.defaults?.connector[i].label\n };\n graph.addConnector(newConnector);\n }\n // return the updated graphData\n return graph.getGraphData();\n }\n};\n\nexport default helpers;\n"]}
|