@statewalker/fsm-charts 0.2.4 → 0.2.6
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/README.md +206 -1
- package/dist/StateChart-cXyVRcs-.d.ts +94 -0
- package/dist/StateChart-cXyVRcs-.d.ts.map +1 -0
- package/dist/StateChartIndex-BK2315qj.d.ts +142 -0
- package/dist/StateChartIndex-BK2315qj.d.ts.map +1 -0
- package/dist/StateChartIndex-BOIrc_nq.js +355 -0
- package/dist/StateChartIndex-BOIrc_nq.js.map +1 -0
- package/dist/buildStatechartsPanel-CxQlIwTh.js +494 -0
- package/dist/buildStatechartsPanel-CxQlIwTh.js.map +1 -0
- package/dist/buildStatechartsPanel-hCtZbdiF.d.ts +79 -0
- package/dist/buildStatechartsPanel-hCtZbdiF.d.ts.map +1 -0
- package/dist/defineProperty-C0rC37pP.js +39 -0
- package/dist/description-panels-DI2MNlbK.js +184 -0
- package/dist/description-panels-DI2MNlbK.js.map +1 -0
- package/dist/getLabelDimensions-BY0q7j3D.d.ts +79 -0
- package/dist/getLabelDimensions-BY0q7j3D.d.ts.map +1 -0
- package/dist/getPadding-Cw0e7G2v.js +25 -0
- package/dist/getPadding-Cw0e7G2v.js.map +1 -0
- package/dist/index-config.d.ts +3 -12
- package/dist/index-config.js +2 -1
- package/dist/index-dom.d.ts +2 -49
- package/dist/index-dom.js +2 -1
- package/dist/index-html.d.ts +3 -2
- package/dist/index-html.js +2 -2
- package/dist/index-layout.d.ts +3 -77
- package/dist/index-layout.js +2 -2
- package/dist/index-runtime.d.ts +3 -141
- package/dist/index-runtime.js +2 -1
- package/dist/index.d.ts +11 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -6
- package/dist/layout-Dp671N6q.js +2465 -0
- package/dist/layout-Dp671N6q.js.map +1 -0
- package/dist/newTreeBuilder-CvtLDjGj.d.ts +54 -0
- package/dist/newTreeBuilder-CvtLDjGj.d.ts.map +1 -0
- package/dist/toFsmStateConfig-DlJkyZni.js +135 -0
- package/dist/toFsmStateConfig-DlJkyZni.js.map +1 -0
- package/dist/toFsmStateConfig-DmOlTRjv.d.ts +15 -0
- package/dist/toFsmStateConfig-DmOlTRjv.d.ts.map +1 -0
- package/package.json +54 -28
- package/src/config/concatTransitionsToString.ts +4 -4
- package/src/config/index.ts +4 -4
- package/src/config/serializeProcessConfig.ts +3 -3
- package/src/config/splitTransitionString.ts +2 -4
- package/src/config/toFsmStateConfig.ts +5 -12
- package/src/dagre/acyclic.js +9 -10
- package/src/dagre/add-border-segments.js +11 -7
- package/src/dagre/coordinate-system.js +12 -12
- package/src/dagre/data/list.js +2 -2
- package/src/dagre/debug.d.ts +1 -1
- package/src/dagre/debug.js +11 -11
- package/src/dagre/greedy-fas.js +17 -21
- package/src/dagre/index.d.ts +4 -4
- package/src/dagre/index.js +4 -4
- package/src/dagre/layout.js +107 -96
- package/src/dagre/nesting-graph.js +13 -19
- package/src/dagre/normalize.js +7 -7
- package/src/dagre/order/add-subgraph-constraints.js +2 -2
- package/src/dagre/order/barycenter.d.ts +1 -1
- package/src/dagre/order/barycenter.js +4 -4
- package/src/dagre/order/build-layer-graph.d.ts +1 -1
- package/src/dagre/order/build-layer-graph.js +7 -9
- package/src/dagre/order/cross-count.js +14 -17
- package/src/dagre/order/index.js +19 -17
- package/src/dagre/order/init-order.js +5 -15
- package/src/dagre/order/resolve-conflicts.js +10 -14
- package/src/dagre/order/sort-subgraph.d.ts +1 -1
- package/src/dagre/order/sort-subgraph.js +13 -14
- package/src/dagre/order/sort.d.ts +1 -1
- package/src/dagre/order/sort.js +6 -10
- package/src/dagre/parent-dummy-chains.js +10 -4
- package/src/dagre/position/bk.d.ts +3 -3
- package/src/dagre/position/bk.js +84 -65
- package/src/dagre/position/index.js +7 -11
- package/src/dagre/rank/feasible-tree.d.ts +1 -1
- package/src/dagre/rank/feasible-tree.js +6 -6
- package/src/dagre/rank/index.js +6 -6
- package/src/dagre/rank/network-simplex.d.ts +0 -1
- package/src/dagre/rank/network-simplex.js +20 -25
- package/src/dagre/rank/util.js +2 -6
- package/src/dagre/util.d.ts +12 -6
- package/src/dagre/util.js +31 -37
- package/src/dom/buildSections.ts +15 -19
- package/src/dom/description-panels.ts +5 -7
- package/src/dom/getStatesDescriptions.ts +4 -10
- package/src/full/index.ts +1 -1
- package/src/full/toFsmStateCharts.ts +11 -11
- package/src/graphlib/alg/components.js +2 -2
- package/src/graphlib/alg/dfs.js +5 -5
- package/src/graphlib/alg/dijkstra-all.js +4 -4
- package/src/graphlib/alg/dijkstra.js +9 -12
- package/src/graphlib/alg/find-cycles.js +7 -5
- package/src/graphlib/alg/floyd-warshall.js +8 -11
- package/src/graphlib/alg/index.d.ts +11 -11
- package/src/graphlib/alg/index.js +11 -11
- package/src/graphlib/alg/is-acyclic.js +1 -1
- package/src/graphlib/alg/postorder.js +2 -2
- package/src/graphlib/alg/preorder.js +2 -2
- package/src/graphlib/alg/prim.d.ts +1 -1
- package/src/graphlib/alg/prim.js +5 -5
- package/src/graphlib/alg/tarjan.js +3 -3
- package/src/graphlib/alg/topsort.js +1 -1
- package/src/graphlib/data/priority-queue.js +8 -10
- package/src/graphlib/graph.js +53 -52
- package/src/graphlib/index.d.ts +2 -2
- package/src/graphlib/index.js +2 -2
- package/src/graphlib/json.d.ts +1 -1
- package/src/graphlib/json.js +6 -6
- package/src/html/buildStatechartCss.ts +2 -2
- package/src/html/buildStatechartStyles.ts +5 -15
- package/src/html/buildStatechartSvg.ts +8 -20
- package/src/html/buildStatechartsPanel.ts +3 -5
- package/src/html/index.ts +4 -4
- package/src/index-config.ts +2 -2
- package/src/index-dom.ts +1 -1
- package/src/index-html.ts +2 -2
- package/src/index-layout.ts +2 -2
- package/src/index-runtime.ts +2 -2
- package/src/index.ts +8 -8
- package/src/layout/buildCharts.ts +6 -7
- package/src/layout/buildFlatCharts.ts +17 -21
- package/src/layout/getGraphParamsProvider.ts +7 -19
- package/src/layout/getLabelDimensions.ts +5 -5
- package/src/layout/index.ts +5 -4
- package/src/lodash-es/index.ts +2 -2
- package/src/lodash-es/types.ts +37 -35
- package/src/runtime/RuntimeStatechartApi.ts +13 -46
- package/src/runtime/StateChartIndex.ts +7 -24
- package/src/runtime/index.ts +2 -2
- package/src/types/FsmStateConfig.ts +1 -1
- package/src/types/GraphParamsProvider.ts +3 -6
- package/src/types/Position.ts +1 -1
- package/src/types/StateChart.ts +2 -2
- package/src/types/StateGraphEdge.ts +2 -2
- package/src/types/StateGraphNode.ts +2 -2
- package/src/types/TransitionsGraph.ts +4 -4
- package/src/types/index.ts +11 -11
- package/src/utils/BasisCurve.ts +6 -15
- package/src/utils/domToText.ts +3 -7
- package/src/utils/getPadding.ts +2 -3
- package/src/utils/newId.ts +2 -1
- package/src/utils/newRegistry.ts +13 -13
- package/src/utils/serializeAttrs.ts +6 -14
- package/src/utils/serializeCss.ts +3 -7
- package/src/utils/serializeStyle.ts +2 -5
- package/src/utils/toKebabCase.ts +1 -4
- package/CHANGELOG.md +0 -1
- package/dist/StateChart-BYBjTmC2.d.ts +0 -82
- package/dist/chunk-36ZLXJVD.js +0 -606
- package/dist/chunk-AZBRQNTU.js +0 -2739
- package/dist/chunk-FIQDLBWD.js +0 -9
- package/dist/chunk-SVKVQY7B.js +0 -133
- package/dist/chunk-TZHCBZVP.js +0 -422
- package/dist/chunk-VILLJJJD.js +0 -231
- package/dist/index-html-DgSCNHkR.d.ts +0 -75
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { l as FsmStateConfig, u as Transition } from "./StateChart-cXyVRcs-.js";
|
|
2
|
+
//#region src/config/concatTransitionsToString.d.ts
|
|
3
|
+
declare function concatTransitionsToString(transitions: Transition[]): string[];
|
|
4
|
+
//#endregion
|
|
5
|
+
//#region src/config/serializeProcessConfig.d.ts
|
|
6
|
+
declare function serializeProcessConfig(config: FsmStateConfig | undefined): string;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/config/splitTransitionString.d.ts
|
|
9
|
+
declare function splitTransitionString(str: string): Transition[];
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/config/toFsmStateConfig.d.ts
|
|
12
|
+
declare function toFsmStateConfig(json: any): FsmStateConfig | undefined;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { concatTransitionsToString as i, splitTransitionString as n, serializeProcessConfig as r, toFsmStateConfig as t };
|
|
15
|
+
//# sourceMappingURL=toFsmStateConfig-DmOlTRjv.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toFsmStateConfig-DmOlTRjv.d.ts","names":[],"sources":["../src/config/concatTransitionsToString.ts","../src/config/serializeProcessConfig.ts","../src/config/splitTransitionString.ts","../src/config/toFsmStateConfig.ts"],"mappings":";;iBAEgB,0BAA0B,aAAa;;;iBCAvC,uBAAuB,QAAQ;;;iBCA/B,sBAAsB,cAAc;;;iBCCpC,iBAAiB,YAAY"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statewalker/fsm-charts",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.6",
|
|
4
|
+
"description": "Statechart layout, SVG rendering and runtime binding for hierarchical finite state machines",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://github.com/statewalker/statewalker-fsm/issues"
|
|
7
|
+
},
|
|
5
8
|
"keywords": [],
|
|
6
|
-
"homepage": "https://github.com/statewalker/statewalker-fsm-charts",
|
|
9
|
+
"homepage": "https://github.com/statewalker/statewalker-fsm/tree/main/packages/fsm-charts#readme",
|
|
7
10
|
"author": {
|
|
8
11
|
"name": "Mikhail Kotelnikov",
|
|
9
12
|
"email": "mikhail.kotelnikov@gmail.com"
|
|
@@ -26,42 +29,65 @@
|
|
|
26
29
|
"types": "./dist/index.d.ts",
|
|
27
30
|
"import": "./dist/index.js",
|
|
28
31
|
"default": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./config": {
|
|
34
|
+
"source": "./src/index-config.ts",
|
|
35
|
+
"types": "./dist/index-config.d.ts",
|
|
36
|
+
"import": "./dist/index-config.js",
|
|
37
|
+
"default": "./dist/index-config.js"
|
|
38
|
+
},
|
|
39
|
+
"./dom": {
|
|
40
|
+
"source": "./src/index-dom.ts",
|
|
41
|
+
"types": "./dist/index-dom.d.ts",
|
|
42
|
+
"import": "./dist/index-dom.js",
|
|
43
|
+
"default": "./dist/index-dom.js"
|
|
44
|
+
},
|
|
45
|
+
"./html": {
|
|
46
|
+
"source": "./src/index-html.ts",
|
|
47
|
+
"types": "./dist/index-html.d.ts",
|
|
48
|
+
"import": "./dist/index-html.js",
|
|
49
|
+
"default": "./dist/index-html.js"
|
|
50
|
+
},
|
|
51
|
+
"./layout": {
|
|
52
|
+
"source": "./src/index-layout.ts",
|
|
53
|
+
"types": "./dist/index-layout.d.ts",
|
|
54
|
+
"import": "./dist/index-layout.js",
|
|
55
|
+
"default": "./dist/index-layout.js"
|
|
56
|
+
},
|
|
57
|
+
"./runtime": {
|
|
58
|
+
"source": "./src/index-runtime.ts",
|
|
59
|
+
"types": "./dist/index-runtime.d.ts",
|
|
60
|
+
"import": "./dist/index-runtime.js",
|
|
61
|
+
"default": "./dist/index-runtime.js"
|
|
29
62
|
}
|
|
30
63
|
},
|
|
31
64
|
"devDependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"@types/jsdom": "^21.1.7",
|
|
65
|
+
"@types/jsdom": "^30.0.0",
|
|
34
66
|
"@types/lodash-es": "^4.17.12",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"lodash": "^4.17.21",
|
|
43
|
-
"lodash-es": "^4.17.21",
|
|
44
|
-
"tsup": "^8.0.2",
|
|
45
|
-
"typescript": "*",
|
|
46
|
-
"vitest": "^1.6.0"
|
|
67
|
+
"eslint": "^10.12.0",
|
|
68
|
+
"jsdom": "^30.1.1",
|
|
69
|
+
"lodash": "^4.18.1",
|
|
70
|
+
"lodash-es": "^4.18.1",
|
|
71
|
+
"tsdown": "^0.23.0",
|
|
72
|
+
"typescript": "^7.0.2",
|
|
73
|
+
"vitest": "^5.0.3"
|
|
47
74
|
},
|
|
48
75
|
"repository": {
|
|
49
76
|
"type": "git",
|
|
50
|
-
"url": "git
|
|
77
|
+
"url": "git+https://github.com/statewalker/statewalker-fsm.git",
|
|
78
|
+
"directory": "packages/fsm-charts"
|
|
79
|
+
},
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public"
|
|
51
82
|
},
|
|
52
83
|
"scripts": {
|
|
53
|
-
"build": "rm -fr ./dist &&
|
|
54
|
-
"
|
|
55
|
-
"watch": "tsup --watch",
|
|
56
|
-
"watch-for-viewer": "tsup --watch --outDir=../statewalker-fsm-viewer/src/.observablehq/cache/_node/@statewalker/fsm-charts@0.2.1",
|
|
84
|
+
"build": "rm -fr ./dist && pnpm test && tsdown",
|
|
85
|
+
"watch": "tsdown --watch",
|
|
57
86
|
"clean": "rm -rf dist",
|
|
58
87
|
"lint": "eslint",
|
|
59
|
-
"lint:fix": "
|
|
88
|
+
"lint:fix": "pnpm lint --fix",
|
|
60
89
|
"test": "vitest --run",
|
|
61
90
|
"test:watch": "vitest",
|
|
62
|
-
"prepublish": "
|
|
63
|
-
},
|
|
64
|
-
"publishConfig": {
|
|
65
|
-
"access": "public"
|
|
91
|
+
"prepublish": "pnpm build"
|
|
66
92
|
}
|
|
67
|
-
}
|
|
93
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Transition } from "../types/index.js";
|
|
2
2
|
|
|
3
3
|
export function concatTransitionsToString(transitions: Transition[]) {
|
|
4
|
-
|
|
4
|
+
const list: string[] = [];
|
|
5
5
|
let str: string = "";
|
|
6
6
|
let prev: undefined | string;
|
|
7
7
|
for (const [from, event, to] of transitions) {
|
|
@@ -9,13 +9,13 @@ export function concatTransitionsToString(transitions: Transition[]) {
|
|
|
9
9
|
if (str) list.push(str);
|
|
10
10
|
str = from;
|
|
11
11
|
}
|
|
12
|
-
str += ` -${
|
|
12
|
+
str += ` -${escapeLabel(event)}-> ${escapeLabel(to)}`;
|
|
13
13
|
prev = to;
|
|
14
14
|
}
|
|
15
15
|
if (str) list.push(str);
|
|
16
16
|
return list;
|
|
17
17
|
|
|
18
|
-
function
|
|
18
|
+
function escapeLabel(str: string): string {
|
|
19
19
|
return str;
|
|
20
20
|
}
|
|
21
21
|
}
|
package/src/config/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./concatTransitionsToString.
|
|
2
|
-
export * from "./serializeProcessConfig.
|
|
3
|
-
export * from "./splitTransitionString.
|
|
4
|
-
export * from "./toFsmStateConfig.
|
|
1
|
+
export * from "./concatTransitionsToString.js";
|
|
2
|
+
export * from "./serializeProcessConfig.js";
|
|
3
|
+
export * from "./splitTransitionString.js";
|
|
4
|
+
export * from "./toFsmStateConfig.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { FsmStateConfig } from "../types/index.
|
|
1
|
+
import type { FsmStateConfig } from "../types/index.js";
|
|
2
2
|
|
|
3
3
|
export function serializeProcessConfig(config: FsmStateConfig | undefined) {
|
|
4
4
|
if (!config) return "";
|
|
5
|
-
|
|
5
|
+
const lines: string[] = [];
|
|
6
6
|
visit(config, lines);
|
|
7
7
|
return lines.join("\n");
|
|
8
8
|
|
|
@@ -29,7 +29,7 @@ export function serializeProcessConfig(config: FsmStateConfig | undefined) {
|
|
|
29
29
|
if (i > 0) {
|
|
30
30
|
lines[lines.length - 1] += ",";
|
|
31
31
|
}
|
|
32
|
-
visit(states[i], lines, shift
|
|
32
|
+
visit(states[i], lines, `${shift} `);
|
|
33
33
|
}
|
|
34
34
|
lines.push(`${shift} ]`);
|
|
35
35
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Transition } from "../types/index.js";
|
|
2
2
|
|
|
3
3
|
export function splitTransitionString(str: string): Transition[] {
|
|
4
4
|
let list: string[] = [];
|
|
5
5
|
let pos = 0;
|
|
6
|
-
const matches = Array.from(
|
|
7
|
-
str.matchAll(/-\s*("[^"]*?"|'[^']*?'|[^-]*?)\s*->/g)
|
|
8
|
-
);
|
|
6
|
+
const matches = Array.from(str.matchAll(/-\s*("[^"]*?"|'[^']*?'|[^-]*?)\s*->/g));
|
|
9
7
|
for (const match of matches) {
|
|
10
8
|
list.push(str.substring(pos, match.index));
|
|
11
9
|
list.push(match[1]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { FsmStateConfig, Transition } from "../types/index.js";
|
|
2
|
+
import { splitTransitionString } from "./splitTransitionString.js";
|
|
3
3
|
|
|
4
4
|
export function toFsmStateConfig(json: any): FsmStateConfig | undefined {
|
|
5
5
|
if (!json || typeof json !== "object") return;
|
|
@@ -20,11 +20,9 @@ export function toFsmStateConfig(json: any): FsmStateConfig | undefined {
|
|
|
20
20
|
const transitions: Transition[] = [];
|
|
21
21
|
const index: Record<string, boolean> = {};
|
|
22
22
|
const array = toArray(json);
|
|
23
|
-
for (
|
|
23
|
+
for (const line of array) {
|
|
24
24
|
const lineTransitions =
|
|
25
|
-
typeof line === "string"
|
|
26
|
-
? splitTransitionString(line)
|
|
27
|
-
: [toArray(line)];
|
|
25
|
+
typeof line === "string" ? splitTransitionString(line) : [toArray(line)];
|
|
28
26
|
for (const transition of lineTransitions.map(validateTransition)) {
|
|
29
27
|
if (!transition) continue;
|
|
30
28
|
const key = transition.join("|");
|
|
@@ -40,12 +38,7 @@ export function toFsmStateConfig(json: any): FsmStateConfig | undefined {
|
|
|
40
38
|
const array = toArray(value);
|
|
41
39
|
if (array.length !== 3) return;
|
|
42
40
|
const [from, event, to] = array;
|
|
43
|
-
if (
|
|
44
|
-
typeof from !== "string" ||
|
|
45
|
-
typeof event !== "string" ||
|
|
46
|
-
typeof to !== "string"
|
|
47
|
-
)
|
|
48
|
-
return;
|
|
41
|
+
if (typeof from !== "string" || typeof event !== "string" || typeof to !== "string") return;
|
|
49
42
|
return [from, event, to];
|
|
50
43
|
}
|
|
51
44
|
|
package/src/dagre/acyclic.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { _ } from
|
|
2
|
-
import { greedyFAS } from
|
|
1
|
+
import { _ } from "../lodash-es/index.ts";
|
|
2
|
+
import { greedyFAS } from "./greedy-fas.js";
|
|
3
3
|
|
|
4
4
|
export { run, undo };
|
|
5
5
|
|
|
6
6
|
function run(g) {
|
|
7
|
-
var fas =
|
|
8
|
-
|
|
7
|
+
var fas =
|
|
8
|
+
g.graph().acyclicer === "greedy" ? greedyFAS(g, weightFn(g)) : dfsFAS(g);
|
|
9
|
+
_.forEach(fas, (e) => {
|
|
9
10
|
var label = g.edge(e);
|
|
10
11
|
g.removeEdge(e);
|
|
11
12
|
label.forwardName = e.name;
|
|
12
13
|
label.reversed = true;
|
|
13
|
-
g.setEdge(e.w, e.v, label, _.uniqueId(
|
|
14
|
+
g.setEdge(e.w, e.v, label, _.uniqueId("rev"));
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
function weightFn(g) {
|
|
17
|
-
return
|
|
18
|
-
return g.edge(e).weight;
|
|
19
|
-
};
|
|
18
|
+
return (e) => g.edge(e).weight;
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
|
|
@@ -31,7 +30,7 @@ function dfsFAS(g) {
|
|
|
31
30
|
}
|
|
32
31
|
visited[v] = true;
|
|
33
32
|
stack[v] = true;
|
|
34
|
-
_.forEach(g.outEdges(v),
|
|
33
|
+
_.forEach(g.outEdges(v), (e) => {
|
|
35
34
|
if (_.has(stack, e.w)) {
|
|
36
35
|
fas.push(e);
|
|
37
36
|
} else {
|
|
@@ -46,7 +45,7 @@ function dfsFAS(g) {
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
function undo(g) {
|
|
49
|
-
_.forEach(g.edges(),
|
|
48
|
+
_.forEach(g.edges(), (e) => {
|
|
50
49
|
var label = g.edge(e);
|
|
51
50
|
if (label.reversed) {
|
|
52
51
|
g.removeEdge(e);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ } from
|
|
2
|
-
import * as util from
|
|
1
|
+
import { _ } from "../lodash-es/index.ts";
|
|
2
|
+
import * as util from "./util.js";
|
|
3
3
|
|
|
4
4
|
export { addBorderSegments };
|
|
5
5
|
|
|
@@ -11,12 +11,16 @@ function addBorderSegments(g) {
|
|
|
11
11
|
_.forEach(children, dfs);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
if (_.has(node,
|
|
14
|
+
if (_.has(node, "minRank")) {
|
|
15
15
|
node.borderLeft = [];
|
|
16
16
|
node.borderRight = [];
|
|
17
|
-
for (
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
for (
|
|
18
|
+
var rank = node.minRank, maxRank = node.maxRank + 1;
|
|
19
|
+
rank < maxRank;
|
|
20
|
+
++rank
|
|
21
|
+
) {
|
|
22
|
+
addBorderNode(g, "borderLeft", "_bl", v, node, rank);
|
|
23
|
+
addBorderNode(g, "borderRight", "_br", v, node, rank);
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
}
|
|
@@ -27,7 +31,7 @@ function addBorderSegments(g) {
|
|
|
27
31
|
function addBorderNode(g, prop, prefix, sg, sgNode, rank) {
|
|
28
32
|
var label = { width: 0, height: 0, rank: rank, borderType: prop };
|
|
29
33
|
var prev = sgNode[prop][rank - 1];
|
|
30
|
-
var curr = util.addDummyNode(g,
|
|
34
|
+
var curr = util.addDummyNode(g, "border", label, prefix);
|
|
31
35
|
sgNode[prop][rank] = curr;
|
|
32
36
|
g.setParent(curr, sg);
|
|
33
37
|
if (prev) {
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { _ } from
|
|
1
|
+
import { _ } from "../lodash-es/index.ts";
|
|
2
2
|
|
|
3
3
|
export { adjust, undo };
|
|
4
4
|
|
|
5
5
|
function adjust(g) {
|
|
6
6
|
var rankDir = g.graph().rankdir.toLowerCase();
|
|
7
|
-
if (rankDir ===
|
|
7
|
+
if (rankDir === "lr" || rankDir === "rl") {
|
|
8
8
|
swapWidthHeight(g);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
function undo(g) {
|
|
13
13
|
var rankDir = g.graph().rankdir.toLowerCase();
|
|
14
|
-
if (rankDir ===
|
|
14
|
+
if (rankDir === "bt" || rankDir === "rl") {
|
|
15
15
|
reverseY(g);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
if (rankDir ===
|
|
18
|
+
if (rankDir === "lr" || rankDir === "rl") {
|
|
19
19
|
swapXY(g);
|
|
20
20
|
swapWidthHeight(g);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function swapWidthHeight(g) {
|
|
25
|
-
_.forEach(g.nodes(),
|
|
25
|
+
_.forEach(g.nodes(), (v) => {
|
|
26
26
|
swapWidthHeightOne(g.node(v));
|
|
27
27
|
});
|
|
28
|
-
_.forEach(g.edges(),
|
|
28
|
+
_.forEach(g.edges(), (e) => {
|
|
29
29
|
swapWidthHeightOne(g.edge(e));
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -37,14 +37,14 @@ function swapWidthHeightOne(attrs) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function reverseY(g) {
|
|
40
|
-
_.forEach(g.nodes(),
|
|
40
|
+
_.forEach(g.nodes(), (v) => {
|
|
41
41
|
reverseYOne(g.node(v));
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
_.forEach(g.edges(),
|
|
44
|
+
_.forEach(g.edges(), (e) => {
|
|
45
45
|
var edge = g.edge(e);
|
|
46
46
|
_.forEach(edge.points, reverseYOne);
|
|
47
|
-
if (_.has(edge,
|
|
47
|
+
if (_.has(edge, "y")) {
|
|
48
48
|
reverseYOne(edge);
|
|
49
49
|
}
|
|
50
50
|
});
|
|
@@ -55,14 +55,14 @@ function reverseYOne(attrs) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function swapXY(g) {
|
|
58
|
-
_.forEach(g.nodes(),
|
|
58
|
+
_.forEach(g.nodes(), (v) => {
|
|
59
59
|
swapXYOne(g.node(v));
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
_.forEach(g.edges(),
|
|
62
|
+
_.forEach(g.edges(), (e) => {
|
|
63
63
|
var edge = g.edge(e);
|
|
64
64
|
_.forEach(edge.points, swapXYOne);
|
|
65
|
-
if (_.has(edge,
|
|
65
|
+
if (_.has(edge, "x")) {
|
|
66
66
|
swapXYOne(edge);
|
|
67
67
|
}
|
|
68
68
|
});
|
package/src/dagre/data/list.js
CHANGED
|
@@ -37,7 +37,7 @@ class List {
|
|
|
37
37
|
strs.push(JSON.stringify(curr, filterOutLinks));
|
|
38
38
|
curr = curr._prev;
|
|
39
39
|
}
|
|
40
|
-
return
|
|
40
|
+
return `[${strs.join(", ")}]`;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -49,7 +49,7 @@ function unlink(entry) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
function filterOutLinks(k, v) {
|
|
52
|
-
if (k !==
|
|
52
|
+
if (k !== "_next" && k !== "_prev") {
|
|
53
53
|
return v;
|
|
54
54
|
}
|
|
55
55
|
}
|
package/src/dagre/debug.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export function debugOrdering(g: any): Graph;
|
|
2
|
-
import { Graph } from
|
|
2
|
+
import { Graph } from "../graphlib/index.js";
|
package/src/dagre/debug.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import * as util from
|
|
1
|
+
import { Graph } from "../graphlib/index.js";
|
|
2
|
+
import { _ } from "../lodash-es/index.ts";
|
|
3
|
+
import * as util from "./util.js";
|
|
4
4
|
|
|
5
5
|
export { debugOrdering };
|
|
6
6
|
|
|
@@ -10,20 +10,20 @@ function debugOrdering(g) {
|
|
|
10
10
|
|
|
11
11
|
var h = new Graph({ compound: true, multigraph: true }).setGraph({});
|
|
12
12
|
|
|
13
|
-
_.forEach(g.nodes(),
|
|
13
|
+
_.forEach(g.nodes(), (v) => {
|
|
14
14
|
h.setNode(v, { label: v });
|
|
15
|
-
h.setParent(v,
|
|
15
|
+
h.setParent(v, `layer${g.node(v).rank}`);
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
_.forEach(g.edges(),
|
|
18
|
+
_.forEach(g.edges(), (e) => {
|
|
19
19
|
h.setEdge(e.v, e.w, {}, e.name);
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
_.forEach(layerMatrix,
|
|
23
|
-
var layerV =
|
|
24
|
-
h.setNode(layerV, { rank:
|
|
25
|
-
_.reduce(layer,
|
|
26
|
-
h.setEdge(u, v, { style:
|
|
22
|
+
_.forEach(layerMatrix, (layer, i) => {
|
|
23
|
+
var layerV = `layer${i}`;
|
|
24
|
+
h.setNode(layerV, { rank: "same" });
|
|
25
|
+
_.reduce(layer, (u, v) => {
|
|
26
|
+
h.setEdge(u, v, { style: "invis" });
|
|
27
27
|
return v;
|
|
28
28
|
});
|
|
29
29
|
});
|
package/src/dagre/greedy-fas.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { List } from
|
|
1
|
+
import { Graph } from "../graphlib/index.js";
|
|
2
|
+
import { _ } from "../lodash-es/index.ts";
|
|
3
|
+
import { List } from "./data/list.js";
|
|
4
4
|
|
|
5
5
|
/*
|
|
6
6
|
* A greedy heuristic for finding a feedback arc set for a graph. A feedback
|
|
@@ -21,11 +21,7 @@ function greedyFAS(g, weightFn) {
|
|
|
21
21
|
var results = doGreedyFAS(state.graph, state.buckets, state.zeroIdx);
|
|
22
22
|
|
|
23
23
|
// Expand multi-edges
|
|
24
|
-
return _.flatten(
|
|
25
|
-
_.map(results, function (e) {
|
|
26
|
-
return g.outEdges(e.v, e.w);
|
|
27
|
-
})
|
|
28
|
-
);
|
|
24
|
+
return _.flatten(_.map(results, (e) => g.outEdges(e.v, e.w)));
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
function doGreedyFAS(g, buckets, zeroIdx) {
|
|
@@ -45,7 +41,9 @@ function doGreedyFAS(g, buckets, zeroIdx) {
|
|
|
45
41
|
for (var i = buckets.length - 2; i > 0; --i) {
|
|
46
42
|
entry = buckets[i].dequeue();
|
|
47
43
|
if (entry) {
|
|
48
|
-
results = results.concat(
|
|
44
|
+
results = results.concat(
|
|
45
|
+
removeNode(g, buckets, zeroIdx, entry, true),
|
|
46
|
+
);
|
|
49
47
|
break;
|
|
50
48
|
}
|
|
51
49
|
}
|
|
@@ -58,7 +56,7 @@ function doGreedyFAS(g, buckets, zeroIdx) {
|
|
|
58
56
|
function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
|
|
59
57
|
var results = collectPredecessors ? [] : undefined;
|
|
60
58
|
|
|
61
|
-
_.forEach(g.inEdges(entry.v),
|
|
59
|
+
_.forEach(g.inEdges(entry.v), (edge) => {
|
|
62
60
|
var weight = g.edge(edge);
|
|
63
61
|
var uEntry = g.node(edge.v);
|
|
64
62
|
|
|
@@ -70,11 +68,11 @@ function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
|
|
|
70
68
|
assignBucket(buckets, zeroIdx, uEntry);
|
|
71
69
|
});
|
|
72
70
|
|
|
73
|
-
_.forEach(g.outEdges(entry.v),
|
|
71
|
+
_.forEach(g.outEdges(entry.v), (edge) => {
|
|
74
72
|
var weight = g.edge(edge);
|
|
75
73
|
var w = edge.w;
|
|
76
74
|
var wEntry = g.node(w);
|
|
77
|
-
wEntry
|
|
75
|
+
wEntry.in -= weight;
|
|
78
76
|
assignBucket(buckets, zeroIdx, wEntry);
|
|
79
77
|
});
|
|
80
78
|
|
|
@@ -88,27 +86,25 @@ function buildState(g, weightFn) {
|
|
|
88
86
|
var maxIn = 0;
|
|
89
87
|
var maxOut = 0;
|
|
90
88
|
|
|
91
|
-
_.forEach(g.nodes(),
|
|
89
|
+
_.forEach(g.nodes(), (v) => {
|
|
92
90
|
fasGraph.setNode(v, { v: v, in: 0, out: 0 });
|
|
93
91
|
});
|
|
94
92
|
|
|
95
93
|
// Aggregate weights on nodes, but also sum the weights across multi-edges
|
|
96
94
|
// into a single edge for the fasGraph.
|
|
97
|
-
_.forEach(g.edges(),
|
|
95
|
+
_.forEach(g.edges(), (e) => {
|
|
98
96
|
var prevWeight = fasGraph.edge(e.v, e.w) || 0;
|
|
99
97
|
var weight = weightFn(e);
|
|
100
98
|
var edgeWeight = prevWeight + weight;
|
|
101
99
|
fasGraph.setEdge(e.v, e.w, edgeWeight);
|
|
102
100
|
maxOut = Math.max(maxOut, (fasGraph.node(e.v).out += weight));
|
|
103
|
-
maxIn = Math.max(maxIn, (fasGraph.node(e.w)
|
|
101
|
+
maxIn = Math.max(maxIn, (fasGraph.node(e.w).in += weight));
|
|
104
102
|
});
|
|
105
103
|
|
|
106
|
-
var buckets = _.range(maxOut + maxIn + 3).map(
|
|
107
|
-
return new List();
|
|
108
|
-
});
|
|
104
|
+
var buckets = _.range(maxOut + maxIn + 3).map(() => new List());
|
|
109
105
|
var zeroIdx = maxIn + 1;
|
|
110
106
|
|
|
111
|
-
_.forEach(fasGraph.nodes(),
|
|
107
|
+
_.forEach(fasGraph.nodes(), (v) => {
|
|
112
108
|
assignBucket(buckets, zeroIdx, fasGraph.node(v));
|
|
113
109
|
});
|
|
114
110
|
|
|
@@ -118,9 +114,9 @@ function buildState(g, weightFn) {
|
|
|
118
114
|
function assignBucket(buckets, zeroIdx, entry) {
|
|
119
115
|
if (!entry.out) {
|
|
120
116
|
buckets[0].enqueue(entry);
|
|
121
|
-
} else if (!entry
|
|
117
|
+
} else if (!entry.in) {
|
|
122
118
|
buckets[buckets.length - 1].enqueue(entry);
|
|
123
119
|
} else {
|
|
124
|
-
buckets[entry.out - entry
|
|
120
|
+
buckets[entry.out - entry.in + zeroIdx].enqueue(entry);
|
|
125
121
|
}
|
|
126
122
|
}
|
package/src/dagre/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as acyclic from
|
|
2
|
-
import * as normalize from
|
|
3
|
-
import { rank } from
|
|
4
|
-
import { layout } from
|
|
1
|
+
import * as acyclic from "./acyclic.js";
|
|
2
|
+
import * as normalize from "./normalize.js";
|
|
3
|
+
import { rank } from "./rank/index.js";
|
|
4
|
+
import { layout } from "./layout.js";
|
|
5
5
|
export { acyclic, normalize, rank, layout };
|
package/src/dagre/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as acyclic from
|
|
2
|
-
import { layout } from
|
|
3
|
-
import * as normalize from
|
|
4
|
-
import { rank } from
|
|
1
|
+
import * as acyclic from "./acyclic.js";
|
|
2
|
+
import { layout } from "./layout.js";
|
|
3
|
+
import * as normalize from "./normalize.js";
|
|
4
|
+
import { rank } from "./rank/index.js";
|
|
5
5
|
|
|
6
6
|
export { acyclic, normalize, rank, layout };
|