@statewalker/fsm-charts 0.1.11 → 0.1.12
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/{StateChart-DlcWaRml.d.ts → StateChart-CdOU9XAq.d.ts} +10 -3
- package/dist/{chunk-2OGGKHD6.js → chunk-AVTSJE25.js} +4 -1
- package/dist/{chunk-SURKRLPB.js → chunk-GCVBCAOL.js} +2 -2
- package/dist/{chunk-HQZXOJPG.js → chunk-GNTY7KMJ.js} +63 -32
- package/dist/index-config.d.ts +2 -2
- package/dist/index-dom.js +1 -1
- package/dist/{index-html-De8e33ol.d.ts → index-html-BKMwwc5Q.d.ts} +1 -1
- package/dist/index-html.d.ts +2 -2
- package/dist/index-html.js +1 -1
- package/dist/index-layout.d.ts +5 -3
- package/dist/index-layout.js +1 -1
- package/dist/index-runtime.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/package.json +1 -1
- package/src/dom/index.ts +4 -1
- package/src/html/buildStatechartSvg.ts +4 -4
- package/src/layout/buildCharts.ts +57 -29
- package/src/layout/getGraphParamsProvider.ts +18 -4
- package/src/types/GraphParamsProvider.ts +5 -5
- package/src/types/Label.ts +7 -0
- package/src/types/index.ts +1 -0
|
@@ -19,12 +19,19 @@ type FsmStateConfig = {
|
|
|
19
19
|
states?: FsmStateConfig[];
|
|
20
20
|
} & Record<string, any>;
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Human-readable label
|
|
24
|
+
*/
|
|
25
|
+
type Label = {
|
|
26
|
+
text: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
22
29
|
/**
|
|
23
30
|
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
24
31
|
*/
|
|
25
32
|
type GraphParamsProvider = {
|
|
26
|
-
getStateParams: (stateKey: string, state?: string) => Dimensions & Record<string, any>;
|
|
27
|
-
getTransitionParams: (fromStateKey: string, event: string, toStateKey: string) => Dimensions & Record<string, any>;
|
|
33
|
+
getStateParams: (stateKey: string, state?: string) => Dimensions & Label & Record<string, any>;
|
|
34
|
+
getTransitionParams: (fromStateKey: string, event: string, toStateKey: string) => Dimensions & Label & Record<string, any>;
|
|
28
35
|
};
|
|
29
36
|
|
|
30
37
|
/**
|
|
@@ -72,4 +79,4 @@ type StateChart = TransitionsGraph & StateGraphNode & {
|
|
|
72
79
|
children?: StateChart[];
|
|
73
80
|
} & Record<string, any>;
|
|
74
81
|
|
|
75
|
-
export type { Dimensions as D, FsmStateConfig as F, GraphParamsProvider as G, Padding as P, StateChart as S, Transition as T, Position as a, StateGraphEdge as b, StateGraphNode as c, TransitionsGraph as d };
|
|
82
|
+
export type { Dimensions as D, FsmStateConfig as F, GraphParamsProvider as G, Label as L, Padding as P, StateChart as S, Transition as T, Position as a, StateGraphEdge as b, StateGraphNode as c, TransitionsGraph as d };
|
|
@@ -57,9 +57,12 @@ function getStateDescriptionRenderer({
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
function* visitDom(elm) {
|
|
60
|
+
if (isDomElement(elm) && elm.tagName === "TEMPLATE") {
|
|
61
|
+
elm = elm.content;
|
|
62
|
+
}
|
|
60
63
|
for (let node = elm.firstChild; node; node = node.nextSibling) {
|
|
61
64
|
if (isDomElement(node)) {
|
|
62
|
-
if (node.tagName === "DIV") {
|
|
65
|
+
if (node.tagName === "DIV" || node.tagName === "TEMPLATE") {
|
|
63
66
|
yield* visitDom(node);
|
|
64
67
|
} else {
|
|
65
68
|
yield node;
|
|
@@ -422,7 +422,7 @@ function buildStatechartSvg({
|
|
|
422
422
|
fill: "currentColor"
|
|
423
423
|
});
|
|
424
424
|
for (const edge of edges) {
|
|
425
|
-
const { id, points,
|
|
425
|
+
const { id, points, text } = edge;
|
|
426
426
|
println(` <g class="transition" data-transition-id="${id}">`);
|
|
427
427
|
const markerId = newId("marker");
|
|
428
428
|
println(` <defs>`);
|
|
@@ -495,7 +495,7 @@ function buildStatechartSvg({
|
|
|
495
495
|
const finalStateRadius = initialStateRadius / 2;
|
|
496
496
|
println(`<g class="statechart__states">`);
|
|
497
497
|
for (const node of nodes) {
|
|
498
|
-
const { key, id,
|
|
498
|
+
const { key, id, text } = node;
|
|
499
499
|
const { x, y, width: width2, height: height2 } = getBoxParams({ ...node, padding: shift });
|
|
500
500
|
println(` <g class="state" data-state-id="${id}">`);
|
|
501
501
|
if (key === initialStateKey || key === finalStateKey) {
|
|
@@ -2579,37 +2579,62 @@ function buildCharts({
|
|
|
2579
2579
|
direction
|
|
2580
2580
|
}) {
|
|
2581
2581
|
return buildChart(config);
|
|
2582
|
-
function buildChart(config2, id = newId("s")) {
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2582
|
+
function buildChart(config2, id = newId("s"), stack = []) {
|
|
2583
|
+
stack.push(config2);
|
|
2584
|
+
try {
|
|
2585
|
+
const getStateLabel = (state, key = state) => {
|
|
2586
|
+
if (key === "<initial>" || key === "<final>") {
|
|
2587
|
+
return "";
|
|
2588
|
+
}
|
|
2589
|
+
let result;
|
|
2590
|
+
for (let i = stack.length - 1; result === void 0 && i >= 0; i--) {
|
|
2591
|
+
const conf = stack[i];
|
|
2592
|
+
console.log("WT", state, key, "=>", conf);
|
|
2593
|
+
if (conf.key !== state) continue;
|
|
2594
|
+
result = conf.label;
|
|
2595
|
+
}
|
|
2596
|
+
return result === void 0 ? state : result;
|
|
2597
|
+
};
|
|
2598
|
+
const graph = buildFlatCharts({
|
|
2599
|
+
lodash,
|
|
2600
|
+
transitions: config2.transitions || [],
|
|
2601
|
+
newId,
|
|
2602
|
+
getStateParams: (state, key) => {
|
|
2603
|
+
const params = getStateParams(state, key);
|
|
2604
|
+
params.text = getStateLabel(state, key);
|
|
2605
|
+
return params;
|
|
2606
|
+
},
|
|
2607
|
+
getTransitionParams,
|
|
2608
|
+
padding,
|
|
2609
|
+
initialStateKey,
|
|
2610
|
+
finalStateKey,
|
|
2611
|
+
vertical,
|
|
2612
|
+
direction
|
|
2613
|
+
});
|
|
2614
|
+
const index = graph.nodes.reduce(
|
|
2615
|
+
(index2, node) => {
|
|
2616
|
+
index2[node.key] = node.id;
|
|
2617
|
+
return index2;
|
|
2618
|
+
},
|
|
2619
|
+
{}
|
|
2620
|
+
);
|
|
2621
|
+
const children = [];
|
|
2622
|
+
if (config2.states) {
|
|
2623
|
+
for (const child of config2.states) {
|
|
2624
|
+
const childId = index[child.key];
|
|
2625
|
+
children.push(buildChart(child, childId));
|
|
2626
|
+
}
|
|
2604
2627
|
}
|
|
2628
|
+
return {
|
|
2629
|
+
id,
|
|
2630
|
+
key: config2.key,
|
|
2631
|
+
state: config2.key,
|
|
2632
|
+
...graph,
|
|
2633
|
+
children
|
|
2634
|
+
};
|
|
2635
|
+
} finally {
|
|
2636
|
+
stack.pop();
|
|
2605
2637
|
}
|
|
2606
|
-
return {
|
|
2607
|
-
id,
|
|
2608
|
-
key: config2.key,
|
|
2609
|
-
state: config2.key,
|
|
2610
|
-
...graph,
|
|
2611
|
-
children
|
|
2612
|
-
};
|
|
2613
2638
|
}
|
|
2614
2639
|
}
|
|
2615
2640
|
|
|
@@ -2664,18 +2689,22 @@ function getGraphParamsProvider({
|
|
|
2664
2689
|
stateFontSize = fontSize,
|
|
2665
2690
|
stateTextPadding = 0,
|
|
2666
2691
|
transitionsFontSize = fontSize,
|
|
2667
|
-
transitionsTextPadding = 0
|
|
2692
|
+
transitionsTextPadding = 0,
|
|
2693
|
+
getStateLabel = (state) => state,
|
|
2694
|
+
getTransitionLabel = (fromState, event, toState) => event
|
|
2668
2695
|
} = {}) {
|
|
2669
2696
|
return {
|
|
2670
2697
|
getStateParams: (stateKey, state = stateKey) => {
|
|
2671
2698
|
const padding = getPadding(stateTextPadding);
|
|
2672
2699
|
const fontSize2 = stateFontSize;
|
|
2700
|
+
const stateLabel = getStateLabel(state);
|
|
2673
2701
|
return {
|
|
2674
|
-
...getLabelDimensions(
|
|
2702
|
+
...getLabelDimensions(stateLabel, {
|
|
2675
2703
|
padding,
|
|
2676
2704
|
fontSize: fontSize2
|
|
2677
2705
|
}),
|
|
2678
2706
|
state,
|
|
2707
|
+
text: stateLabel,
|
|
2679
2708
|
key: stateKey,
|
|
2680
2709
|
padding,
|
|
2681
2710
|
fontSize: fontSize2
|
|
@@ -2684,14 +2713,16 @@ function getGraphParamsProvider({
|
|
|
2684
2713
|
getTransitionParams: (fromStateKey, event, toStateKey) => {
|
|
2685
2714
|
const padding = getPadding(transitionsTextPadding);
|
|
2686
2715
|
const fontSize2 = transitionsFontSize;
|
|
2716
|
+
const eventLabel = getTransitionLabel(fromStateKey, event, toStateKey);
|
|
2687
2717
|
return {
|
|
2688
|
-
...getLabelDimensions(
|
|
2718
|
+
...getLabelDimensions(eventLabel, {
|
|
2689
2719
|
padding,
|
|
2690
2720
|
fontSize: fontSize2
|
|
2691
2721
|
}),
|
|
2692
2722
|
from: fromStateKey,
|
|
2693
2723
|
event,
|
|
2694
2724
|
to: toStateKey,
|
|
2725
|
+
text: eventLabel,
|
|
2695
2726
|
padding,
|
|
2696
2727
|
fontSize: fontSize2
|
|
2697
2728
|
};
|
package/dist/index-config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as Transition, F as FsmStateConfig } from './StateChart-
|
|
2
|
-
export { D as Dimensions, G as GraphParamsProvider, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, d as TransitionsGraph } from './StateChart-
|
|
1
|
+
import { T as Transition, F as FsmStateConfig } from './StateChart-CdOU9XAq.js';
|
|
2
|
+
export { D as Dimensions, G as GraphParamsProvider, L as Label, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, d as TransitionsGraph } from './StateChart-CdOU9XAq.js';
|
|
3
3
|
|
|
4
4
|
declare function concatTransitionsToString(transitions: Transition[]): string[];
|
|
5
5
|
|
package/dist/index-dom.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { buildSections, findSection, getStateDescriptionRenderer, renderSections, visitDom, visitSectionNodes, vistSections } from './chunk-
|
|
1
|
+
export { buildSections, findSection, getStateDescriptionRenderer, renderSections, visitDom, visitSectionNodes, vistSections } from './chunk-AVTSJE25.js';
|
package/dist/index-html.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, T as Transition, d as TransitionsGraph } from './StateChart-
|
|
2
|
-
export { c as activeStatesStyle, d as activeTransitionsStyle, f as buildStateDetailsStyle, g as buildStateDetailsStyleWithModifier, b as buildStatechartCss, i as buildStatechartStyles, h as buildStatechartStylesWithModifier, j as buildStatechartSvg, a as buildStatechartsPanel, s as selectedStatesStyle, e as selectedTransitionsStyle } from './index-html-
|
|
1
|
+
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, L as Label, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, T as Transition, d as TransitionsGraph } from './StateChart-CdOU9XAq.js';
|
|
2
|
+
export { c as activeStatesStyle, d as activeTransitionsStyle, f as buildStateDetailsStyle, g as buildStateDetailsStyleWithModifier, b as buildStatechartCss, i as buildStatechartStyles, h as buildStatechartStylesWithModifier, j as buildStatechartSvg, a as buildStatechartsPanel, s as selectedStatesStyle, e as selectedTransitionsStyle } from './index-html-BKMwwc5Q.js';
|
package/dist/index-html.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { activeStatesStyle, activeTransitionsStyle, buildStateDetailsStyle, buildStateDetailsStyleWithModifier, buildStatechartCss, buildStatechartStyles, buildStatechartStylesWithModifier, buildStatechartSvg, buildStatechartsPanel, selectedStatesStyle, selectedTransitionsStyle } from './chunk-
|
|
1
|
+
export { activeStatesStyle, activeTransitionsStyle, buildStateDetailsStyle, buildStateDetailsStyleWithModifier, buildStatechartCss, buildStatechartStyles, buildStatechartStylesWithModifier, buildStatechartSvg, buildStatechartsPanel, selectedStatesStyle, selectedTransitionsStyle } from './chunk-GCVBCAOL.js';
|
|
2
2
|
import './chunk-FIQDLBWD.js';
|
package/dist/index-layout.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as Transition, P as Padding, G as GraphParamsProvider, d as TransitionsGraph, F as FsmStateConfig, S as StateChart } from './StateChart-
|
|
2
|
-
export { D as Dimensions, a as Position, b as StateGraphEdge, c as StateGraphNode } from './StateChart-
|
|
1
|
+
import { T as Transition, P as Padding, G as GraphParamsProvider, d as TransitionsGraph, F as FsmStateConfig, S as StateChart } from './StateChart-CdOU9XAq.js';
|
|
2
|
+
export { D as Dimensions, L as Label, a as Position, b as StateGraphEdge, c as StateGraphNode } from './StateChart-CdOU9XAq.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Build graphs corresponding to the specified transitions.
|
|
@@ -52,12 +52,14 @@ declare function buildCharts({ lodash, config, newId, getStateParams, getTransit
|
|
|
52
52
|
* @param transitionsFontSize - The font size for the transition labels.
|
|
53
53
|
* @param transitionsTextPadding - The padding around the transition labels.
|
|
54
54
|
*/
|
|
55
|
-
declare function getGraphParamsProvider({ fontSize, stateFontSize, stateTextPadding, transitionsFontSize, transitionsTextPadding, }?: {
|
|
55
|
+
declare function getGraphParamsProvider({ fontSize, stateFontSize, stateTextPadding, transitionsFontSize, transitionsTextPadding, getStateLabel, getTransitionLabel, }?: {
|
|
56
56
|
fontSize?: number;
|
|
57
57
|
stateFontSize?: number;
|
|
58
58
|
stateTextPadding?: Padding;
|
|
59
59
|
transitionsFontSize?: number;
|
|
60
60
|
transitionsTextPadding?: Padding;
|
|
61
|
+
getStateLabel?: (state: string) => string;
|
|
62
|
+
getTransitionLabel?: (fromState: string, event: string, toState: string) => string;
|
|
61
63
|
}): GraphParamsProvider;
|
|
62
64
|
|
|
63
65
|
declare function getLabelDimensions(label: string, { padding, fontSize, getCharWidth, // Golden ratio and all that jazz :-)
|
package/dist/index-layout.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-
|
|
1
|
+
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-GNTY7KMJ.js';
|
|
2
2
|
import './chunk-FIQDLBWD.js';
|
package/dist/index-runtime.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StateChart, c as StateGraphNode, b as StateGraphEdge } from './StateChart-
|
|
2
|
-
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, P as Padding, a as Position, T as Transition, d as TransitionsGraph } from './StateChart-
|
|
1
|
+
import { S as StateChart, c as StateGraphNode, b as StateGraphEdge } from './StateChart-CdOU9XAq.js';
|
|
2
|
+
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, L as Label, P as Padding, a as Position, T as Transition, d as TransitionsGraph } from './StateChart-CdOU9XAq.js';
|
|
3
3
|
|
|
4
4
|
type RuntimeListener = (id: string) => void;
|
|
5
5
|
declare class RuntimeStatechartApi {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, T as Transition, d as TransitionsGraph } from './StateChart-
|
|
1
|
+
export { D as Dimensions, F as FsmStateConfig, G as GraphParamsProvider, L as Label, P as Padding, a as Position, S as StateChart, b as StateGraphEdge, c as StateGraphNode, T as Transition, d as TransitionsGraph } from './StateChart-CdOU9XAq.js';
|
|
2
2
|
export { DomSection, buildSections, findSection, getStateDescriptionRenderer, renderSections, visitDom, visitSectionNodes, vistSections } from './index-dom.js';
|
|
3
3
|
export { concatTransitionsToString, serializeProcessConfig, splitTransitionString, toFsmStateConfig } from './index-config.js';
|
|
4
4
|
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './index-layout.js';
|
|
5
|
-
export { C as CssTree, c as activeStatesStyle, d as activeTransitionsStyle, f as buildStateDetailsStyle, g as buildStateDetailsStyleWithModifier, b as buildStatechartCss, i as buildStatechartStyles, h as buildStatechartStylesWithModifier, j as buildStatechartSvg, a as buildStatechartsPanel, s as selectedStatesStyle, e as selectedTransitionsStyle, k as serializeCss } from './index-html-
|
|
5
|
+
export { C as CssTree, c as activeStatesStyle, d as activeTransitionsStyle, f as buildStateDetailsStyle, g as buildStateDetailsStyleWithModifier, b as buildStatechartCss, i as buildStatechartStyles, h as buildStatechartStylesWithModifier, j as buildStatechartSvg, a as buildStatechartsPanel, s as selectedStatesStyle, e as selectedTransitionsStyle, k as serializeCss } from './index-html-BKMwwc5Q.js';
|
|
6
6
|
export { RuntimeListener, RuntimeStatechartApi, StateChartIndex } from './index-runtime.js';
|
|
7
7
|
|
|
8
8
|
declare function toKebabCase(str?: string): string;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { concatTransitionsToString, serializeProcessConfig, splitTransitionString, toFsmStateConfig } from './chunk-SVKVQY7B.js';
|
|
2
|
-
export { buildSections, findSection, getStateDescriptionRenderer, renderSections, visitDom, visitSectionNodes, vistSections } from './chunk-
|
|
3
|
-
export { activeStatesStyle, activeTransitionsStyle, buildStateDetailsStyle, buildStateDetailsStyleWithModifier, buildStatechartCss, buildStatechartStyles, buildStatechartStylesWithModifier, buildStatechartSvg, buildStatechartsPanel, selectedStatesStyle, selectedTransitionsStyle, serializeCss, toKebabCase } from './chunk-
|
|
4
|
-
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-
|
|
2
|
+
export { buildSections, findSection, getStateDescriptionRenderer, renderSections, visitDom, visitSectionNodes, vistSections } from './chunk-AVTSJE25.js';
|
|
3
|
+
export { activeStatesStyle, activeTransitionsStyle, buildStateDetailsStyle, buildStateDetailsStyleWithModifier, buildStatechartCss, buildStatechartStyles, buildStatechartStylesWithModifier, buildStatechartSvg, buildStatechartsPanel, selectedStatesStyle, selectedTransitionsStyle, serializeCss, toKebabCase } from './chunk-GCVBCAOL.js';
|
|
4
|
+
export { buildCharts, buildFlatCharts, getGraphParamsProvider, getLabelDimensions } from './chunk-GNTY7KMJ.js';
|
|
5
5
|
import './chunk-FIQDLBWD.js';
|
|
6
6
|
export { RuntimeStatechartApi, StateChartIndex } from './chunk-N77KKO5K.js';
|
package/package.json
CHANGED
package/src/dom/index.ts
CHANGED
|
@@ -90,9 +90,12 @@ export function getStateDescriptionRenderer({
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
export function* visitDom(elm: Node): Iterable<Node> {
|
|
93
|
+
if (isDomElement(elm) && elm.tagName === "TEMPLATE") {
|
|
94
|
+
elm = (elm as HTMLTemplateElement).content;
|
|
95
|
+
}
|
|
93
96
|
for (let node = elm.firstChild; node; node = node.nextSibling) {
|
|
94
97
|
if (isDomElement(node)) {
|
|
95
|
-
if (node.tagName === "DIV") {
|
|
98
|
+
if (node.tagName === "DIV" || node.tagName === "TEMPLATE") {
|
|
96
99
|
yield* visitDom(node);
|
|
97
100
|
} else {
|
|
98
101
|
yield node;
|
|
@@ -51,7 +51,7 @@ export function buildStatechartSvg({
|
|
|
51
51
|
height,
|
|
52
52
|
viewbox: `0 0 ${width} ${height}`,
|
|
53
53
|
xmlns: "http://www.w3.org/2000/svg",
|
|
54
|
-
})}
|
|
54
|
+
})}>`,
|
|
55
55
|
);
|
|
56
56
|
|
|
57
57
|
/*
|
|
@@ -79,7 +79,7 @@ export function buildStatechartSvg({
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
for (const edge of edges) {
|
|
82
|
-
const { id, points,
|
|
82
|
+
const { id, points, text } = edge;
|
|
83
83
|
println(` <g class="transition" data-transition-id="${id}">`);
|
|
84
84
|
const markerId = newId("marker");
|
|
85
85
|
|
|
@@ -98,7 +98,7 @@ export function buildStatechartSvg({
|
|
|
98
98
|
x1: number,
|
|
99
99
|
y1: number,
|
|
100
100
|
x2: number,
|
|
101
|
-
y2: number
|
|
101
|
+
y2: number,
|
|
102
102
|
) {
|
|
103
103
|
path.push("C" + round(x0, y0, x1, y1, x2, y2).join(","));
|
|
104
104
|
},
|
|
@@ -181,7 +181,7 @@ export function buildStatechartSvg({
|
|
|
181
181
|
|
|
182
182
|
println(`<g class="statechart__states">`);
|
|
183
183
|
for (const node of nodes) {
|
|
184
|
-
const { key, id,
|
|
184
|
+
const { key, id, text } = node;
|
|
185
185
|
const { x, y, width, height } = getBoxParams({ ...node, padding: shift });
|
|
186
186
|
|
|
187
187
|
println(` <g class="state" data-state-id="${id}">`);
|
|
@@ -39,38 +39,66 @@ export function buildCharts({
|
|
|
39
39
|
|
|
40
40
|
function buildChart(
|
|
41
41
|
config: FsmStateConfig,
|
|
42
|
-
id: string = newId("s")
|
|
42
|
+
id: string = newId("s"),
|
|
43
|
+
stack: Array<FsmStateConfig> = [],
|
|
43
44
|
): StateChart {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return index;
|
|
59
|
-
}, {} as Record<string, string>);
|
|
45
|
+
stack.push(config);
|
|
46
|
+
try {
|
|
47
|
+
const getStateLabel = (state: string, key: string = state) => {
|
|
48
|
+
if (key === "<initial>" || key === "<final>") {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
// TODO: search labels in sub-states of the current state.
|
|
52
|
+
let result: string | undefined;
|
|
53
|
+
for (let i = stack.length - 1; result === undefined && i >= 0; i--) {
|
|
54
|
+
const conf = stack[i];
|
|
55
|
+
console.log('WT', state, key, '=>', conf)
|
|
56
|
+
if (conf.key !== state) continue;
|
|
57
|
+
result = conf.label;
|
|
58
|
+
}
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
return result === undefined ? state : result;
|
|
61
|
+
};
|
|
62
|
+
const graph = buildFlatCharts({
|
|
63
|
+
lodash,
|
|
64
|
+
transitions: config.transitions || [],
|
|
65
|
+
newId,
|
|
66
|
+
getStateParams: (state: string, key?: string) => {
|
|
67
|
+
const params = getStateParams(state, key);
|
|
68
|
+
params.text = getStateLabel(state, key);
|
|
69
|
+
return params;
|
|
70
|
+
},
|
|
71
|
+
getTransitionParams,
|
|
72
|
+
padding,
|
|
73
|
+
initialStateKey,
|
|
74
|
+
finalStateKey,
|
|
75
|
+
vertical,
|
|
76
|
+
direction,
|
|
77
|
+
});
|
|
78
|
+
const index = graph.nodes.reduce(
|
|
79
|
+
(index, node) => {
|
|
80
|
+
index[node.key as string] = node.id as string;
|
|
81
|
+
return index;
|
|
82
|
+
},
|
|
83
|
+
{} as Record<string, string>,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const children: StateChart[] = [];
|
|
87
|
+
if (config.states) {
|
|
88
|
+
for (const child of config.states) {
|
|
89
|
+
const childId = index[child.key];
|
|
90
|
+
children.push(buildChart(child, childId));
|
|
91
|
+
}
|
|
66
92
|
}
|
|
93
|
+
return {
|
|
94
|
+
id,
|
|
95
|
+
key: config.key,
|
|
96
|
+
state: config.key,
|
|
97
|
+
...graph,
|
|
98
|
+
children,
|
|
99
|
+
};
|
|
100
|
+
} finally {
|
|
101
|
+
stack.pop();
|
|
67
102
|
}
|
|
68
|
-
return {
|
|
69
|
-
id,
|
|
70
|
-
key: config.key,
|
|
71
|
-
state: config.key,
|
|
72
|
-
...graph,
|
|
73
|
-
children,
|
|
74
|
-
};
|
|
75
103
|
}
|
|
76
104
|
}
|
|
@@ -4,6 +4,7 @@ import type { Padding } from "../types/Padding.ts";
|
|
|
4
4
|
|
|
5
5
|
import { getLabelDimensions } from "./getLabelDimensions.ts";
|
|
6
6
|
import { getPadding } from "../utils/getPadding.ts";
|
|
7
|
+
import { Label } from "../types/Label.ts";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
@@ -19,23 +20,34 @@ export function getGraphParamsProvider({
|
|
|
19
20
|
stateTextPadding = 0,
|
|
20
21
|
transitionsFontSize = fontSize,
|
|
21
22
|
transitionsTextPadding = 0,
|
|
23
|
+
getStateLabel = (state: string) => state,
|
|
24
|
+
getTransitionLabel = (fromState: string, event: string, toState: string) =>
|
|
25
|
+
event,
|
|
22
26
|
}: {
|
|
23
27
|
fontSize?: number;
|
|
24
28
|
stateFontSize?: number;
|
|
25
29
|
stateTextPadding?: Padding;
|
|
26
30
|
transitionsFontSize?: number;
|
|
27
31
|
transitionsTextPadding?: Padding;
|
|
32
|
+
getStateLabel?: (state: string) => string;
|
|
33
|
+
getTransitionLabel?: (
|
|
34
|
+
fromState: string,
|
|
35
|
+
event: string,
|
|
36
|
+
toState: string,
|
|
37
|
+
) => string;
|
|
28
38
|
} = {}): GraphParamsProvider {
|
|
29
39
|
return {
|
|
30
40
|
getStateParams: (stateKey: string, state: string = stateKey) => {
|
|
31
41
|
const padding = getPadding(stateTextPadding);
|
|
32
42
|
const fontSize = stateFontSize;
|
|
43
|
+
const stateLabel = getStateLabel(state);
|
|
33
44
|
return {
|
|
34
|
-
...getLabelDimensions(
|
|
45
|
+
...getLabelDimensions(stateLabel, {
|
|
35
46
|
padding,
|
|
36
47
|
fontSize,
|
|
37
48
|
}),
|
|
38
49
|
state,
|
|
50
|
+
text: stateLabel,
|
|
39
51
|
key: stateKey,
|
|
40
52
|
padding,
|
|
41
53
|
fontSize,
|
|
@@ -44,18 +56,20 @@ export function getGraphParamsProvider({
|
|
|
44
56
|
getTransitionParams: (
|
|
45
57
|
fromStateKey: string,
|
|
46
58
|
event: string,
|
|
47
|
-
toStateKey: string
|
|
48
|
-
)
|
|
59
|
+
toStateKey: string,
|
|
60
|
+
) => {
|
|
49
61
|
const padding = getPadding(transitionsTextPadding);
|
|
50
62
|
const fontSize = transitionsFontSize;
|
|
63
|
+
const eventLabel = getTransitionLabel(fromStateKey, event, toStateKey);
|
|
51
64
|
return {
|
|
52
|
-
...getLabelDimensions(
|
|
65
|
+
...getLabelDimensions(eventLabel, {
|
|
53
66
|
padding,
|
|
54
67
|
fontSize,
|
|
55
68
|
}),
|
|
56
69
|
from: fromStateKey,
|
|
57
70
|
event,
|
|
58
71
|
to: toStateKey,
|
|
72
|
+
text: eventLabel,
|
|
59
73
|
padding,
|
|
60
74
|
fontSize,
|
|
61
75
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Dimensions } from "./Dimensions.ts";
|
|
2
|
+
import { Label } from "./Label.ts";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Provides default functions measuring dimensions for state nodes and transition edges in the graph.
|
|
@@ -6,12 +7,11 @@ import type { Dimensions } from "./Dimensions.ts";
|
|
|
6
7
|
export type GraphParamsProvider = {
|
|
7
8
|
getStateParams: (
|
|
8
9
|
stateKey: string,
|
|
9
|
-
state?: string
|
|
10
|
-
) => Dimensions & Record<string, any>;
|
|
10
|
+
state?: string,
|
|
11
|
+
) => Dimensions & Label & Record<string, any>;
|
|
11
12
|
getTransitionParams: (
|
|
12
13
|
fromStateKey: string,
|
|
13
14
|
event: string,
|
|
14
|
-
toStateKey: string
|
|
15
|
-
) => Dimensions & Record<string, any>;
|
|
15
|
+
toStateKey: string,
|
|
16
|
+
) => Dimensions & Label & Record<string, any>;
|
|
16
17
|
};
|
|
17
|
-
|
package/src/types/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export type * from "./Dimensions.ts";
|
|
2
2
|
export type * from "./FsmStateConfig.ts";
|
|
3
3
|
export type * from "./GraphParamsProvider.ts";
|
|
4
|
+
export type * from "./Label.ts";
|
|
4
5
|
export type * from "./Padding.ts";
|
|
5
6
|
export type * from "./Position.ts";
|
|
6
7
|
export type * from "./StateChart.ts";
|