@statewalker/fsm-charts 0.2.4 → 0.2.5
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/dist/{chunk-AZBRQNTU.js → chunk-2LFUT2C6.js} +1062 -1110
- package/dist/{chunk-SVKVQY7B.js → chunk-ARZYBFNA.js} +4 -4
- package/dist/{chunk-36ZLXJVD.js → chunk-CR2M4445.js} +35 -33
- package/dist/{chunk-TZHCBZVP.js → chunk-GW2Z65BN.js} +22 -15
- package/dist/chunk-PKBMQBKP.js +5 -0
- package/dist/{chunk-VILLJJJD.js → chunk-RZ4FP6JB.js} +11 -9
- package/dist/index-config.js +2 -1
- package/dist/index-dom.js +2 -1
- package/dist/{index-html-DgSCNHkR.d.ts → index-html-BBQqYoST.d.ts} +10 -10
- package/dist/index-html.d.ts +1 -1
- package/dist/index-html.js +2 -1
- package/dist/index-layout.d.ts +15 -15
- package/dist/index-layout.js +2 -1
- package/dist/index-runtime.js +2 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -5
- package/package.json +16 -18
- package/src/config/concatTransitionsToString.ts +2 -2
- package/src/config/index.ts +4 -4
- package/src/config/serializeProcessConfig.ts +3 -3
- package/src/config/splitTransitionString.ts +2 -2
- package/src/config/toFsmStateConfig.ts +3 -3
- 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 +16 -12
- package/src/dom/description-panels.ts +3 -3
- package/src/dom/getStatesDescriptions.ts +1 -1
- package/src/full/index.ts +1 -1
- package/src/full/toFsmStateCharts.ts +10 -10
- 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 +1 -1
- package/src/html/buildStatechartSvg.ts +7 -7
- package/src/html/buildStatechartsPanel.ts +2 -2
- 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 +5 -5
- package/src/layout/buildFlatCharts.ts +11 -13
- package/src/layout/getGraphParamsProvider.ts +5 -8
- 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 +12 -23
- package/src/runtime/StateChartIndex.ts +3 -3
- package/src/runtime/index.ts +2 -2
- package/src/types/FsmStateConfig.ts +1 -1
- package/src/types/GraphParamsProvider.ts +2 -2
- 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 +3 -3
- package/src/utils/domToText.ts +1 -1
- package/src/utils/getPadding.ts +1 -1
- package/src/utils/newRegistry.ts +1 -1
- package/src/utils/serializeAttrs.ts +6 -6
- package/src/utils/serializeCss.ts +3 -3
- package/src/utils/serializeStyle.ts +2 -2
- package/src/utils/toKebabCase.ts +1 -1
- package/CHANGELOG.md +0 -1
package/src/dagre/util.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Graph } from "../graphlib/index.js";
|
|
2
|
+
import { _ } from "../lodash-es/index.ts";
|
|
3
3
|
|
|
4
4
|
export {
|
|
5
5
|
addDummyNode,
|
|
@@ -38,10 +38,10 @@ function addDummyNode(g, type, attrs, name) {
|
|
|
38
38
|
*/
|
|
39
39
|
function simplify(g) {
|
|
40
40
|
var simplified = new Graph().setGraph(g.graph());
|
|
41
|
-
_.forEach(g.nodes(),
|
|
41
|
+
_.forEach(g.nodes(), (v) => {
|
|
42
42
|
simplified.setNode(v, g.node(v));
|
|
43
43
|
});
|
|
44
|
-
_.forEach(g.edges(),
|
|
44
|
+
_.forEach(g.edges(), (e) => {
|
|
45
45
|
var simpleLabel = simplified.edge(e.v, e.w) || { weight: 0, minlen: 1 };
|
|
46
46
|
var label = g.edge(e);
|
|
47
47
|
simplified.setEdge(e.v, e.w, {
|
|
@@ -53,22 +53,24 @@ function simplify(g) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function asNonCompoundGraph(g) {
|
|
56
|
-
var simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(
|
|
57
|
-
|
|
56
|
+
var simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(
|
|
57
|
+
g.graph(),
|
|
58
|
+
);
|
|
59
|
+
_.forEach(g.nodes(), (v) => {
|
|
58
60
|
if (!g.children(v).length) {
|
|
59
61
|
simplified.setNode(v, g.node(v));
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
|
-
_.forEach(g.edges(),
|
|
64
|
+
_.forEach(g.edges(), (e) => {
|
|
63
65
|
simplified.setEdge(e, g.edge(e));
|
|
64
66
|
});
|
|
65
67
|
return simplified;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
function successorWeights(g) {
|
|
69
|
-
var weightMap = _.map(g.nodes(),
|
|
71
|
+
var weightMap = _.map(g.nodes(), (v) => {
|
|
70
72
|
var sucs = {};
|
|
71
|
-
_.forEach(g.outEdges(v),
|
|
73
|
+
_.forEach(g.outEdges(v), (e) => {
|
|
72
74
|
sucs[e.w] = (sucs[e.w] || 0) + g.edge(e).weight;
|
|
73
75
|
});
|
|
74
76
|
return sucs;
|
|
@@ -77,9 +79,9 @@ function successorWeights(g) {
|
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
function predecessorWeights(g) {
|
|
80
|
-
var weightMap = _.map(g.nodes(),
|
|
82
|
+
var weightMap = _.map(g.nodes(), (v) => {
|
|
81
83
|
var preds = {};
|
|
82
|
-
_.forEach(g.inEdges(v),
|
|
84
|
+
_.forEach(g.inEdges(v), (e) => {
|
|
83
85
|
preds[e.v] = (preds[e.v] || 0) + g.edge(e).weight;
|
|
84
86
|
});
|
|
85
87
|
return preds;
|
|
@@ -103,7 +105,9 @@ function intersectRect(rect, point) {
|
|
|
103
105
|
var h = rect.height / 2;
|
|
104
106
|
|
|
105
107
|
if (!dx && !dy) {
|
|
106
|
-
throw new Error(
|
|
108
|
+
throw new Error(
|
|
109
|
+
"Not possible to find intersection inside of the rectangle",
|
|
110
|
+
);
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
var sx, sy;
|
|
@@ -131,10 +135,8 @@ function intersectRect(rect, point) {
|
|
|
131
135
|
* function will produce a matrix with the ids of each node.
|
|
132
136
|
*/
|
|
133
137
|
function buildLayerMatrix(g) {
|
|
134
|
-
var layering = _.map(_.range(maxRank(g) + 1),
|
|
135
|
-
|
|
136
|
-
});
|
|
137
|
-
_.forEach(g.nodes(), function (v) {
|
|
138
|
+
var layering = _.map(_.range(maxRank(g) + 1), () => []);
|
|
139
|
+
_.forEach(g.nodes(), (v) => {
|
|
138
140
|
var node = g.node(v);
|
|
139
141
|
var rank = node.rank;
|
|
140
142
|
if (!_.isUndefined(rank)) {
|
|
@@ -149,14 +151,10 @@ function buildLayerMatrix(g) {
|
|
|
149
151
|
* rank(v) >= 0 and at least one node w has rank(w) = 0.
|
|
150
152
|
*/
|
|
151
153
|
function normalizeRanks(g) {
|
|
152
|
-
var min = _.min(
|
|
153
|
-
|
|
154
|
-
return g.node(v).rank;
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
_.forEach(g.nodes(), function (v) {
|
|
154
|
+
var min = _.min(_.map(g.nodes(), (v) => g.node(v).rank));
|
|
155
|
+
_.forEach(g.nodes(), (v) => {
|
|
158
156
|
var node = g.node(v);
|
|
159
|
-
if (_.has(node,
|
|
157
|
+
if (_.has(node, "rank")) {
|
|
160
158
|
node.rank -= min;
|
|
161
159
|
}
|
|
162
160
|
});
|
|
@@ -164,14 +162,10 @@ function normalizeRanks(g) {
|
|
|
164
162
|
|
|
165
163
|
function removeEmptyRanks(g) {
|
|
166
164
|
// Ranks may not start at 0, so we need to offset them
|
|
167
|
-
var offset = _.min(
|
|
168
|
-
_.map(g.nodes(), function (v) {
|
|
169
|
-
return g.node(v).rank;
|
|
170
|
-
})
|
|
171
|
-
);
|
|
165
|
+
var offset = _.min(_.map(g.nodes(), (v) => g.node(v).rank));
|
|
172
166
|
|
|
173
167
|
var layers = [];
|
|
174
|
-
_.forEach(g.nodes(),
|
|
168
|
+
_.forEach(g.nodes(), (v) => {
|
|
175
169
|
var rank = g.node(v).rank - offset;
|
|
176
170
|
if (!layers[rank]) {
|
|
177
171
|
layers[rank] = [];
|
|
@@ -181,11 +175,11 @@ function removeEmptyRanks(g) {
|
|
|
181
175
|
|
|
182
176
|
var delta = 0;
|
|
183
177
|
var nodeRankFactor = g.graph().nodeRankFactor;
|
|
184
|
-
_.forEach(layers,
|
|
178
|
+
_.forEach(layers, (vs, i) => {
|
|
185
179
|
if (_.isUndefined(vs) && i % nodeRankFactor !== 0) {
|
|
186
180
|
--delta;
|
|
187
181
|
} else if (delta) {
|
|
188
|
-
_.forEach(vs,
|
|
182
|
+
_.forEach(vs, (v) => {
|
|
189
183
|
g.node(v).rank += delta;
|
|
190
184
|
});
|
|
191
185
|
}
|
|
@@ -201,17 +195,17 @@ function addBorderNode(g, prefix, rank, order) {
|
|
|
201
195
|
node.rank = rank;
|
|
202
196
|
node.order = order;
|
|
203
197
|
}
|
|
204
|
-
return addDummyNode(g,
|
|
198
|
+
return addDummyNode(g, "border", node, prefix);
|
|
205
199
|
}
|
|
206
200
|
|
|
207
201
|
function maxRank(g) {
|
|
208
202
|
return _.max(
|
|
209
|
-
_.map(g.nodes(),
|
|
203
|
+
_.map(g.nodes(), (v) => {
|
|
210
204
|
var rank = g.node(v).rank;
|
|
211
205
|
if (!_.isUndefined(rank)) {
|
|
212
206
|
return rank;
|
|
213
207
|
}
|
|
214
|
-
})
|
|
208
|
+
}),
|
|
215
209
|
);
|
|
216
210
|
}
|
|
217
211
|
|
|
@@ -222,7 +216,7 @@ function maxRank(g) {
|
|
|
222
216
|
*/
|
|
223
217
|
function partition(collection, fn) {
|
|
224
218
|
var result = { lhs: [], rhs: [] };
|
|
225
|
-
_.forEach(collection,
|
|
219
|
+
_.forEach(collection, (value) => {
|
|
226
220
|
if (fn(value)) {
|
|
227
221
|
result.lhs.push(value);
|
|
228
222
|
} else {
|
|
@@ -241,10 +235,10 @@ function time(name, fn) {
|
|
|
241
235
|
try {
|
|
242
236
|
return fn();
|
|
243
237
|
} finally {
|
|
244
|
-
console.log(name
|
|
238
|
+
console.log(`${name} time: ${_.now() - start}ms`);
|
|
245
239
|
}
|
|
246
240
|
}
|
|
247
241
|
|
|
248
|
-
function notime(
|
|
242
|
+
function notime(_name, fn) {
|
|
249
243
|
return fn();
|
|
250
244
|
}
|
package/src/dom/buildSections.ts
CHANGED
|
@@ -12,14 +12,14 @@ export function buildSections(root: HTMLElement | Iterable<Node>): DomSection {
|
|
|
12
12
|
let peek: DomSection = null!;
|
|
13
13
|
const stack: DomSection[] = [];
|
|
14
14
|
const aligner = newTreeBuilder<[HTMLElement?]>({
|
|
15
|
-
enter(
|
|
15
|
+
enter(_level, header) {
|
|
16
16
|
const section: DomSection = {
|
|
17
17
|
header,
|
|
18
18
|
content: [],
|
|
19
19
|
children: [],
|
|
20
20
|
};
|
|
21
21
|
top = top || section;
|
|
22
|
-
peek
|
|
22
|
+
peek?.children.push(section);
|
|
23
23
|
peek = section;
|
|
24
24
|
stack.push(section);
|
|
25
25
|
},
|
|
@@ -29,20 +29,23 @@ export function buildSections(root: HTMLElement | Iterable<Node>): DomSection {
|
|
|
29
29
|
},
|
|
30
30
|
});
|
|
31
31
|
aligner(0);
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
// Track the actual header magnitudes of the open ancestor sections. A header of
|
|
33
|
+
// level L closes every open header at its level or deeper, then opens at the
|
|
34
|
+
// resulting depth. Deriving depth from the real magnitudes (not a ±1 delta) keeps
|
|
35
|
+
// nesting correct for any header sequence and never goes negative.
|
|
36
|
+
const headerLevels: number[] = [];
|
|
34
37
|
for (const node of nodes) {
|
|
35
38
|
if (isDomElement(node)) {
|
|
36
39
|
if (/^H[1-6]$/i.test(node.tagName)) {
|
|
37
40
|
const headerLevel = +node.tagName.replace(/^H/, "");
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
aligner(
|
|
41
|
+
while (
|
|
42
|
+
headerLevels.length > 0 &&
|
|
43
|
+
headerLevels[headerLevels.length - 1] >= headerLevel
|
|
44
|
+
) {
|
|
45
|
+
headerLevels.pop();
|
|
46
|
+
}
|
|
47
|
+
headerLevels.push(headerLevel);
|
|
48
|
+
aligner(headerLevels.length, node);
|
|
46
49
|
} else {
|
|
47
50
|
peek.content.push(node);
|
|
48
51
|
}
|
|
@@ -80,6 +83,7 @@ export function findSection(
|
|
|
80
83
|
for (const s of vistSections(section)) {
|
|
81
84
|
if (accept(s) === true) return s;
|
|
82
85
|
}
|
|
86
|
+
return undefined;
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
// --------------------------------------------
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { DomSection } from "./buildSections.js";
|
|
2
2
|
import { getStatesDescriptions } from "./getStatesDescriptions.js";
|
|
3
3
|
|
|
4
4
|
export function getStateDescriptionRenderer(options: {
|
|
@@ -19,7 +19,7 @@ export function getStateDescriptionRenderer(options: {
|
|
|
19
19
|
|
|
20
20
|
const elm = renderSections({
|
|
21
21
|
section,
|
|
22
|
-
deep: (
|
|
22
|
+
deep: (_section) => false, // section.state !== options.rootStateKey, // ???
|
|
23
23
|
header: (section) => {
|
|
24
24
|
if (section.state === stateKey) {
|
|
25
25
|
return section.title || section.state;
|
|
@@ -35,7 +35,7 @@ export function getStateDescriptionRenderer(options: {
|
|
|
35
35
|
|
|
36
36
|
export function renderSections<T extends DomSection>({
|
|
37
37
|
section,
|
|
38
|
-
deep = (
|
|
38
|
+
deep = (_s) => true,
|
|
39
39
|
header = (section) => section.header?.cloneNode(true) as Node,
|
|
40
40
|
}: {
|
|
41
41
|
section: T;
|
package/src/full/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./toFsmStateCharts.
|
|
1
|
+
export * from "./toFsmStateCharts.js";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { newId } from "../utils/newId.ts";
|
|
2
|
-
import { newRegistry } from "../utils/newRegistry.ts";
|
|
3
|
-
import { RuntimeStatechartApi, StateChartIndex } from "../runtime/index.ts";
|
|
4
1
|
import {
|
|
5
2
|
buildStatechartCss,
|
|
6
3
|
buildStatechartsPanel,
|
|
7
|
-
FsmStateConfig,
|
|
8
|
-
StateChart,
|
|
9
|
-
StateGraphEdge,
|
|
10
|
-
} from "../index-html.
|
|
11
|
-
import { buildCharts, getGraphParamsProvider } from "../index-layout.
|
|
4
|
+
type FsmStateConfig,
|
|
5
|
+
type StateChart,
|
|
6
|
+
type StateGraphEdge,
|
|
7
|
+
} from "../index-html.js";
|
|
8
|
+
import { buildCharts, getGraphParamsProvider } from "../index-layout.js";
|
|
9
|
+
import { RuntimeStatechartApi, StateChartIndex } from "../runtime/index.js";
|
|
10
|
+
import { newId } from "../utils/newId.js";
|
|
11
|
+
import { newRegistry } from "../utils/newRegistry.js";
|
|
12
12
|
|
|
13
13
|
export type FsmStateCharts = {
|
|
14
14
|
api: RuntimeStatechartApi;
|
|
@@ -96,7 +96,7 @@ ${css}
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
// api.focusStates(...nodeIds);
|
|
99
|
-
})
|
|
99
|
+
}),
|
|
100
100
|
);
|
|
101
101
|
|
|
102
102
|
if (onTransitionClick) {
|
|
@@ -104,7 +104,7 @@ ${css}
|
|
|
104
104
|
api.onTransitionClick((transitionId) => {
|
|
105
105
|
const transition = index.getEdgeById(transitionId);
|
|
106
106
|
transition && onTransitionClick(transition);
|
|
107
|
-
})
|
|
107
|
+
}),
|
|
108
108
|
);
|
|
109
109
|
}
|
|
110
110
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
2
|
|
|
3
3
|
export { components };
|
|
4
4
|
|
|
@@ -15,7 +15,7 @@ function components(g) {
|
|
|
15
15
|
_.each(g.predecessors(v), dfs);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
_.each(g.nodes(),
|
|
18
|
+
_.each(g.nodes(), (v) => {
|
|
19
19
|
cmpt = [];
|
|
20
20
|
dfs(v);
|
|
21
21
|
if (cmpt.length) {
|
package/src/graphlib/alg/dfs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
2
|
|
|
3
3
|
export { dfs };
|
|
4
4
|
|
|
@@ -19,12 +19,12 @@ function dfs(g, vs, order) {
|
|
|
19
19
|
|
|
20
20
|
var acc = [];
|
|
21
21
|
var visited = {};
|
|
22
|
-
_.each(vs,
|
|
22
|
+
_.each(vs, (v) => {
|
|
23
23
|
if (!g.hasNode(v)) {
|
|
24
|
-
throw new Error(
|
|
24
|
+
throw new Error(`Graph does not have node: ${v}`);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
doDfs(g, v, order ===
|
|
27
|
+
doDfs(g, v, order === "post", visited, navigation, acc);
|
|
28
28
|
});
|
|
29
29
|
return acc;
|
|
30
30
|
}
|
|
@@ -36,7 +36,7 @@ function doDfs(g, v, postorder, visited, navigation, acc) {
|
|
|
36
36
|
if (!postorder) {
|
|
37
37
|
acc.push(v);
|
|
38
38
|
}
|
|
39
|
-
_.each(navigation(v),
|
|
39
|
+
_.each(navigation(v), (w) => {
|
|
40
40
|
doDfs(g, w, postorder, visited, navigation, acc);
|
|
41
41
|
});
|
|
42
42
|
if (postorder) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { _ } from
|
|
2
|
-
import { dijkstra } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
|
+
import { dijkstra } from "./dijkstra.js";
|
|
3
3
|
|
|
4
4
|
export { dijkstraAll };
|
|
5
5
|
|
|
6
6
|
function dijkstraAll(g, weightFunc, edgeFunc) {
|
|
7
7
|
return _.transform(
|
|
8
8
|
g.nodes(),
|
|
9
|
-
|
|
9
|
+
(acc, v) => {
|
|
10
10
|
acc[v] = dijkstra(g, v, weightFunc, edgeFunc);
|
|
11
11
|
},
|
|
12
|
-
{}
|
|
12
|
+
{},
|
|
13
13
|
);
|
|
14
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { _ } from
|
|
2
|
-
import { PriorityQueue } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
|
+
import { PriorityQueue } from "../data/priority-queue.js";
|
|
3
3
|
|
|
4
4
|
export { dijkstra };
|
|
5
5
|
|
|
@@ -10,10 +10,7 @@ function dijkstra(g, source, weightFn, edgeFn) {
|
|
|
10
10
|
g,
|
|
11
11
|
String(source),
|
|
12
12
|
weightFn || DEFAULT_WEIGHT_FUNC,
|
|
13
|
-
edgeFn ||
|
|
14
|
-
function (v) {
|
|
15
|
-
return g.outEdges(v);
|
|
16
|
-
}
|
|
13
|
+
edgeFn || ((v) => g.outEdges(v)),
|
|
17
14
|
);
|
|
18
15
|
}
|
|
19
16
|
|
|
@@ -22,7 +19,7 @@ function runDijkstra(g, source, weightFn, edgeFn) {
|
|
|
22
19
|
var pq = new PriorityQueue();
|
|
23
20
|
var v, vEntry;
|
|
24
21
|
|
|
25
|
-
var updateNeighbors =
|
|
22
|
+
var updateNeighbors = (edge) => {
|
|
26
23
|
var w = edge.v !== v ? edge.v : edge.w;
|
|
27
24
|
var wEntry = results[w];
|
|
28
25
|
var weight = weightFn(edge);
|
|
@@ -30,11 +27,11 @@ function runDijkstra(g, source, weightFn, edgeFn) {
|
|
|
30
27
|
|
|
31
28
|
if (weight < 0) {
|
|
32
29
|
throw new Error(
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
"dijkstra does not allow negative edge weights. " +
|
|
31
|
+
"Bad edge: " +
|
|
35
32
|
edge +
|
|
36
|
-
|
|
37
|
-
weight
|
|
33
|
+
" Weight: " +
|
|
34
|
+
weight,
|
|
38
35
|
);
|
|
39
36
|
}
|
|
40
37
|
|
|
@@ -45,7 +42,7 @@ function runDijkstra(g, source, weightFn, edgeFn) {
|
|
|
45
42
|
}
|
|
46
43
|
};
|
|
47
44
|
|
|
48
|
-
g.nodes().forEach(
|
|
45
|
+
g.nodes().forEach((v) => {
|
|
49
46
|
var distance = v === source ? 0 : Number.POSITIVE_INFINITY;
|
|
50
47
|
results[v] = { distance: distance };
|
|
51
48
|
pq.add(v, distance);
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { _ } from
|
|
2
|
-
import { tarjan } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
|
+
import { tarjan } from "./tarjan.js";
|
|
3
3
|
|
|
4
4
|
export { findCycles };
|
|
5
5
|
|
|
6
6
|
function findCycles(g) {
|
|
7
|
-
return _.filter(
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
return _.filter(
|
|
8
|
+
tarjan(g),
|
|
9
|
+
(cmpt) =>
|
|
10
|
+
cmpt.length > 1 || (cmpt.length === 1 && g.hasEdge(cmpt[0], cmpt[0])),
|
|
11
|
+
);
|
|
10
12
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
2
|
|
|
3
3
|
export { floydWarshall };
|
|
4
4
|
|
|
@@ -8,10 +8,7 @@ function floydWarshall(g, weightFn, edgeFn) {
|
|
|
8
8
|
return runFloydWarshall(
|
|
9
9
|
g,
|
|
10
10
|
weightFn || DEFAULT_WEIGHT_FUNC,
|
|
11
|
-
edgeFn ||
|
|
12
|
-
function (v) {
|
|
13
|
-
return g.outEdges(v);
|
|
14
|
-
}
|
|
11
|
+
edgeFn || ((v) => g.outEdges(v)),
|
|
15
12
|
);
|
|
16
13
|
}
|
|
17
14
|
|
|
@@ -19,26 +16,26 @@ function runFloydWarshall(g, weightFn, edgeFn) {
|
|
|
19
16
|
var results = {};
|
|
20
17
|
var nodes = g.nodes();
|
|
21
18
|
|
|
22
|
-
nodes.forEach(
|
|
19
|
+
nodes.forEach((v) => {
|
|
23
20
|
results[v] = {};
|
|
24
21
|
results[v][v] = { distance: 0 };
|
|
25
|
-
nodes.forEach(
|
|
22
|
+
nodes.forEach((w) => {
|
|
26
23
|
if (v !== w) {
|
|
27
24
|
results[v][w] = { distance: Number.POSITIVE_INFINITY };
|
|
28
25
|
}
|
|
29
26
|
});
|
|
30
|
-
edgeFn(v).forEach(
|
|
27
|
+
edgeFn(v).forEach((edge) => {
|
|
31
28
|
var w = edge.v === v ? edge.w : edge.v;
|
|
32
29
|
var d = weightFn(edge);
|
|
33
30
|
results[v][w] = { distance: d, predecessor: v };
|
|
34
31
|
});
|
|
35
32
|
});
|
|
36
33
|
|
|
37
|
-
nodes.forEach(
|
|
34
|
+
nodes.forEach((k) => {
|
|
38
35
|
var rowK = results[k];
|
|
39
|
-
nodes.forEach(
|
|
36
|
+
nodes.forEach((i) => {
|
|
40
37
|
var rowI = results[i];
|
|
41
|
-
nodes.forEach(
|
|
38
|
+
nodes.forEach((j) => {
|
|
42
39
|
var ik = rowI[k];
|
|
43
40
|
var kj = rowK[j];
|
|
44
41
|
var ij = rowI[j];
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { components } from
|
|
2
|
-
import { dijkstra } from
|
|
3
|
-
import { dijkstraAll } from
|
|
4
|
-
import { findCycles } from
|
|
5
|
-
import { floydWarshall } from
|
|
6
|
-
import { isAcyclic } from
|
|
7
|
-
import { postorder } from
|
|
8
|
-
import { preorder } from
|
|
9
|
-
import { prim } from
|
|
10
|
-
import { tarjan } from
|
|
11
|
-
import { topsort } from
|
|
1
|
+
import { components } from "./components.js";
|
|
2
|
+
import { dijkstra } from "./dijkstra.js";
|
|
3
|
+
import { dijkstraAll } from "./dijkstra-all.js";
|
|
4
|
+
import { findCycles } from "./find-cycles.js";
|
|
5
|
+
import { floydWarshall } from "./floyd-warshall.js";
|
|
6
|
+
import { isAcyclic } from "./is-acyclic.js";
|
|
7
|
+
import { postorder } from "./postorder.js";
|
|
8
|
+
import { preorder } from "./preorder.js";
|
|
9
|
+
import { prim } from "./prim.js";
|
|
10
|
+
import { tarjan } from "./tarjan.js";
|
|
11
|
+
import { topsort } from "./topsort.js";
|
|
12
12
|
export {
|
|
13
13
|
components,
|
|
14
14
|
dijkstra,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { components } from
|
|
2
|
-
import { dijkstra } from
|
|
3
|
-
import { dijkstraAll } from
|
|
4
|
-
import { findCycles } from
|
|
5
|
-
import { floydWarshall } from
|
|
6
|
-
import { isAcyclic } from
|
|
7
|
-
import { postorder } from
|
|
8
|
-
import { preorder } from
|
|
9
|
-
import { prim } from
|
|
10
|
-
import { tarjan } from
|
|
11
|
-
import { topsort } from
|
|
1
|
+
import { components } from "./components.js";
|
|
2
|
+
import { dijkstra } from "./dijkstra.js";
|
|
3
|
+
import { dijkstraAll } from "./dijkstra-all.js";
|
|
4
|
+
import { findCycles } from "./find-cycles.js";
|
|
5
|
+
import { floydWarshall } from "./floyd-warshall.js";
|
|
6
|
+
import { isAcyclic } from "./is-acyclic.js";
|
|
7
|
+
import { postorder } from "./postorder.js";
|
|
8
|
+
import { preorder } from "./preorder.js";
|
|
9
|
+
import { prim } from "./prim.js";
|
|
10
|
+
import { tarjan } from "./tarjan.js";
|
|
11
|
+
import { topsort } from "./topsort.js";
|
|
12
12
|
|
|
13
13
|
export {
|
|
14
14
|
components,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export function prim(g: any, weightFunc: any): Graph;
|
|
2
|
-
import { Graph } from
|
|
2
|
+
import { Graph } from "../graph.js";
|
package/src/graphlib/alg/prim.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ } from
|
|
2
|
-
import { PriorityQueue } from
|
|
3
|
-
import { Graph } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
|
+
import { PriorityQueue } from "../data/priority-queue.js";
|
|
3
|
+
import { Graph } from "../graph.js";
|
|
4
4
|
|
|
5
5
|
export { prim };
|
|
6
6
|
|
|
@@ -26,7 +26,7 @@ function prim(g, weightFunc) {
|
|
|
26
26
|
return result;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
_.each(g.nodes(),
|
|
29
|
+
_.each(g.nodes(), (v) => {
|
|
30
30
|
pq.add(v, Number.POSITIVE_INFINITY);
|
|
31
31
|
result.setNode(v);
|
|
32
32
|
});
|
|
@@ -40,7 +40,7 @@ function prim(g, weightFunc) {
|
|
|
40
40
|
if (_.has(parents, v)) {
|
|
41
41
|
result.setEdge(v, parents[v]);
|
|
42
42
|
} else if (init) {
|
|
43
|
-
throw new Error(
|
|
43
|
+
throw new Error(`Input graph is not connected: ${g}`);
|
|
44
44
|
} else {
|
|
45
45
|
init = true;
|
|
46
46
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ } from
|
|
1
|
+
import { _ } from "../../lodash-es/index.ts";
|
|
2
2
|
|
|
3
3
|
export { tarjan };
|
|
4
4
|
|
|
@@ -16,7 +16,7 @@ function tarjan(g) {
|
|
|
16
16
|
});
|
|
17
17
|
stack.push(v);
|
|
18
18
|
|
|
19
|
-
g.successors(v).forEach(
|
|
19
|
+
g.successors(v).forEach((w) => {
|
|
20
20
|
if (!_.has(visited, w)) {
|
|
21
21
|
dfs(w);
|
|
22
22
|
entry.lowlink = Math.min(entry.lowlink, visited[w].lowlink);
|
|
@@ -37,7 +37,7 @@ function tarjan(g) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
g.nodes().forEach(
|
|
40
|
+
g.nodes().forEach((v) => {
|
|
41
41
|
if (!_.has(visited, v)) {
|
|
42
42
|
dfs(v);
|
|
43
43
|
}
|