@widgetic/workflows 0.2.3 → 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.
@@ -0,0 +1,93 @@
1
+ import type { RunsFlow, RunsFlowLink, RunsFlowStep } from './runsFlow.js';
2
+ /**
3
+ * Where everything of the Runs chart goes: the pixels of its bars, its labels and its bands, from the model
4
+ * (`runsFlow.ts`) and the width the screen has. Plain numbers in and out, so it is tested without a screen.
5
+ *
6
+ * The chart reads from left to right in every language (as the canvas of the editor does): the columns are the steps a
7
+ * visitor takes, and a band always runs to the right. Every bar has a label above it, and the label can be as wide as the
8
+ * column; the last column has the room that is left.
9
+ *
10
+ * One scale makes the chart honest: a visitor is the same number of pixels of height in every bar and every band, so the
11
+ * width of a band can be compared with any other. A bar or a band that would be too thin to see is given a least thickness
12
+ * (the scale is not bent for it), and a bar is never thinner than the bands it holds.
13
+ *
14
+ * A band that skips a column (a visitor who goes from the first composition to the third) runs through that column in a
15
+ * lane of its own, between the bars, so that it never goes behind a bar or under a label. A lane is a place in the column,
16
+ * ordered and spaced like a bar, and the band is one curve through all its lanes.
17
+ */
18
+ /** The measures of the chart, in pixels of the drawing. */
19
+ export declare const RUNS_FLOW_METRICS: {
20
+ /** How wide a bar is (and a lane, which a band runs straight through). */
21
+ readonly barWidth: 12;
22
+ /** The margin around the chart. */
23
+ readonly paddingX: 16;
24
+ readonly paddingY: 16;
25
+ /** The space between the bottom of a bar and the label of the bar below it. */
26
+ readonly stepGap: 20;
27
+ /** The space between a lane and what is above it (a lane has no label to make room for). */
28
+ readonly laneGap: 8;
29
+ /** The height of the line a composition's name is on, and of each line of numbers under it. */
30
+ readonly nameLineHeight: 20;
31
+ readonly detailLineHeight: 16;
32
+ /** The space between the label and its bar. */
33
+ readonly labelMargin: 6;
34
+ /** A bar and a band are never thinner than this (a few visitors among thousands stay visible). */
35
+ readonly minBarHeight: 6;
36
+ readonly minLinkThickness: 1.5;
37
+ /** When nobody was counted at all, every band is this thick, so that the shape of the workflow shows. */
38
+ readonly emptyLinkThickness: 32;
39
+ /** The part of a bar that did not go on is never thinner than this, so that it can be seen. */
40
+ readonly minStayedHeight: 3;
41
+ /** What the bars of the busiest column add up to, when the workflow is small. */
42
+ readonly barsBudget: 240;
43
+ readonly minHeight: 280;
44
+ /** The least distance between two columns, and the room the last column's labels have. */
45
+ readonly minColumnPitch: 190;
46
+ readonly lastLabelRoom: 170;
47
+ /** The space kept between a label and the next column's bars. */
48
+ readonly labelGutter: 16;
49
+ };
50
+ /** How many lines of words a step's label has: its name, how many entered, and the two that are only there when they apply. */
51
+ export declare function countLabelLines(step: Pick<RunsFlowStep, 'stayed' | 'failed'>): number;
52
+ /** A bar, with the place of its label. */
53
+ export interface PlacedStep extends RunsFlowStep {
54
+ /** The left edge of the bar and of its label. */
55
+ x: number;
56
+ /** The top of the label, and of the bar under it. */
57
+ labelY: number;
58
+ barY: number;
59
+ barHeight: number;
60
+ labelHeight: number;
61
+ labelWidth: number;
62
+ /** The part of the bar that did not go on, at the bottom of it (0 high when all of them did, or there is no way on). */
63
+ stayedY: number;
64
+ stayedHeight: number;
65
+ }
66
+ /** The place where a band runs through a column it skips: as wide as a bar, `x` is its left edge and `y` its middle. */
67
+ export interface PlacedLane {
68
+ x: number;
69
+ y: number;
70
+ }
71
+ /** A band, as the curve its middle follows and how thick it is. */
72
+ export interface PlacedLink extends RunsFlowLink {
73
+ /** An SVG path: a curve from the right edge of the source bar to the left edge of the target bar, through its lanes. */
74
+ path: string;
75
+ thickness: number;
76
+ /** The columns the band skips, left to right, and where it runs through each one. Empty for a band to the next column. */
77
+ lanes: PlacedLane[];
78
+ }
79
+ export interface PlacedRunsFlow {
80
+ width: number;
81
+ height: number;
82
+ steps: PlacedStep[];
83
+ links: PlacedLink[];
84
+ }
85
+ /** The least width the chart can be drawn in for a number of columns. */
86
+ export declare function measureMinimumWidth(columnCount: number): number;
87
+ /**
88
+ * Lays the chart out in `width` pixels. The chart is wider than `width` only when its columns cannot be drawn in it (the
89
+ * screen scrolls then), and as tall as the busiest column needs.
90
+ */
91
+ export declare function layoutRunsFlow(flow: RunsFlow, options: {
92
+ width: number;
93
+ }): PlacedRunsFlow;
@@ -0,0 +1,305 @@
1
+ /**
2
+ * Where everything of the Runs chart goes: the pixels of its bars, its labels and its bands, from the model
3
+ * (`runsFlow.ts`) and the width the screen has. Plain numbers in and out, so it is tested without a screen.
4
+ *
5
+ * The chart reads from left to right in every language (as the canvas of the editor does): the columns are the steps a
6
+ * visitor takes, and a band always runs to the right. Every bar has a label above it, and the label can be as wide as the
7
+ * column; the last column has the room that is left.
8
+ *
9
+ * One scale makes the chart honest: a visitor is the same number of pixels of height in every bar and every band, so the
10
+ * width of a band can be compared with any other. A bar or a band that would be too thin to see is given a least thickness
11
+ * (the scale is not bent for it), and a bar is never thinner than the bands it holds.
12
+ *
13
+ * A band that skips a column (a visitor who goes from the first composition to the third) runs through that column in a
14
+ * lane of its own, between the bars, so that it never goes behind a bar or under a label. A lane is a place in the column,
15
+ * ordered and spaced like a bar, and the band is one curve through all its lanes.
16
+ */
17
+ /** The measures of the chart, in pixels of the drawing. */
18
+ export const RUNS_FLOW_METRICS = {
19
+ /** How wide a bar is (and a lane, which a band runs straight through). */
20
+ barWidth: 12,
21
+ /** The margin around the chart. */
22
+ paddingX: 16,
23
+ paddingY: 16,
24
+ /** The space between the bottom of a bar and the label of the bar below it. */
25
+ stepGap: 20,
26
+ /** The space between a lane and what is above it (a lane has no label to make room for). */
27
+ laneGap: 8,
28
+ /** The height of the line a composition's name is on, and of each line of numbers under it. */
29
+ nameLineHeight: 20,
30
+ detailLineHeight: 16,
31
+ /** The space between the label and its bar. */
32
+ labelMargin: 6,
33
+ /** A bar and a band are never thinner than this (a few visitors among thousands stay visible). */
34
+ minBarHeight: 6,
35
+ minLinkThickness: 1.5,
36
+ /** When nobody was counted at all, every band is this thick, so that the shape of the workflow shows. */
37
+ emptyLinkThickness: 32,
38
+ /** The part of a bar that did not go on is never thinner than this, so that it can be seen. */
39
+ minStayedHeight: 3,
40
+ /** What the bars of the busiest column add up to, when the workflow is small. */
41
+ barsBudget: 240,
42
+ minHeight: 280,
43
+ /** The least distance between two columns, and the room the last column's labels have. */
44
+ minColumnPitch: 190,
45
+ lastLabelRoom: 170,
46
+ /** The space kept between a label and the next column's bars. */
47
+ labelGutter: 16
48
+ };
49
+ /** How many lines of words a step's label has: its name, how many entered, and the two that are only there when they apply. */
50
+ export function countLabelLines(step) {
51
+ return 2 + (step.stayed > 0 ? 1 : 0) + (step.failed > 0 ? 1 : 0);
52
+ }
53
+ const EMPTY_CHART = { width: 0, height: 0, steps: [], links: [] };
54
+ /** Pixel values are kept to two places, so the same chart is always the same text. */
55
+ const round = (value) => Math.round(value * 100) / 100;
56
+ /** The least width the chart can be drawn in for a number of columns. */
57
+ export function measureMinimumWidth(columnCount) {
58
+ const metrics = RUNS_FLOW_METRICS;
59
+ return (2 * metrics.paddingX +
60
+ metrics.lastLabelRoom +
61
+ Math.max(0, columnCount - 1) * metrics.minColumnPitch);
62
+ }
63
+ const appendTo = (map, key, piece) => {
64
+ const pieces = map.get(key);
65
+ if (pieces)
66
+ pieces.push(piece);
67
+ else
68
+ map.set(key, [piece]);
69
+ };
70
+ /**
71
+ * Puts the items of each column in the order that crosses the fewest bands: each column is ordered by where the pieces
72
+ * that reach it come from (the middle of the places of the items they leave), going right and then going back, a few times.
73
+ * An item with no piece on the side that is looked at keeps its place. Ties keep the order the workflow lists its blocks in.
74
+ */
75
+ function orderColumns(columns, pieces) {
76
+ const placeOf = new Map();
77
+ const writePlaces = (column) => {
78
+ column.forEach((item, position) => placeOf.set(item, (position + 0.5) / column.length));
79
+ };
80
+ columns.forEach(writePlaces);
81
+ const piecesInto = new Map();
82
+ const piecesOutOf = new Map();
83
+ for (const piece of pieces) {
84
+ appendTo(piecesInto, piece.to, piece);
85
+ appendTo(piecesOutOf, piece.from, piece);
86
+ }
87
+ const sortByNeighbours = (column, piecesOf, neighbourOf) => {
88
+ const keyOf = new Map();
89
+ for (const item of column) {
90
+ const own = piecesOf.get(item) ?? [];
91
+ // A band with nobody in it still counts a little, so that the shape of the workflow orders an empty chart too.
92
+ const weight = own.reduce((total, piece) => total + piece.band.value + 0.01, 0);
93
+ const middle = own.reduce((total, piece) => total + (placeOf.get(neighbourOf(piece)) ?? 0.5) * (piece.band.value + 0.01), 0);
94
+ keyOf.set(item, own.length > 0 ? middle / weight : (placeOf.get(item) ?? 0.5));
95
+ }
96
+ // `sort` is stable: items with the same key stay in the order they were in.
97
+ column.sort((first, second) => (keyOf.get(first) ?? 0) - (keyOf.get(second) ?? 0));
98
+ writePlaces(column);
99
+ };
100
+ for (let sweep = 0; sweep < 4; sweep += 1) {
101
+ for (let columnNumber = 1; columnNumber < columns.length; columnNumber += 1) {
102
+ sortByNeighbours(columns[columnNumber], piecesInto, (piece) => piece.from);
103
+ }
104
+ for (let columnNumber = columns.length - 2; columnNumber >= 0; columnNumber -= 1) {
105
+ sortByNeighbours(columns[columnNumber], piecesOutOf, (piece) => piece.to);
106
+ }
107
+ }
108
+ }
109
+ /**
110
+ * Lays the chart out in `width` pixels. The chart is wider than `width` only when its columns cannot be drawn in it (the
111
+ * screen scrolls then), and as tall as the busiest column needs.
112
+ */
113
+ export function layoutRunsFlow(flow, options) {
114
+ const metrics = RUNS_FLOW_METRICS;
115
+ if (flow.steps.length === 0)
116
+ return EMPTY_CHART;
117
+ // ---- the columns, with the lanes of the bands that skip some ------------------------------------------------------
118
+ const columns = Array.from({ length: flow.columnCount }, () => []);
119
+ const itemOfStep = new Map();
120
+ const columnNumberOf = new Map();
121
+ for (const step of flow.steps) {
122
+ const item = { kind: 'bar', step };
123
+ const columnNumber = Math.min(step.column, flow.columnCount - 1);
124
+ columns[columnNumber].push(item);
125
+ itemOfStep.set(step.nodeId, item);
126
+ columnNumberOf.set(item, columnNumber);
127
+ }
128
+ const routes = new Map();
129
+ const pieces = [];
130
+ for (const band of flow.links) {
131
+ const source = itemOfStep.get(band.sourceId);
132
+ const target = itemOfStep.get(band.targetId);
133
+ if (!source || !target)
134
+ continue;
135
+ const lanes = [];
136
+ // A band that goes back, or to the same column, has nothing to skip: it is one piece, as it is drawn.
137
+ for (let columnNumber = (columnNumberOf.get(source) ?? 0) + 1; columnNumber < (columnNumberOf.get(target) ?? 0); columnNumber += 1) {
138
+ const lane = { kind: 'lane', band };
139
+ columns[columnNumber].push(lane);
140
+ lanes.push(lane);
141
+ }
142
+ const way = [source, ...lanes, target];
143
+ const own = [];
144
+ for (let position = 1; position < way.length; position += 1) {
145
+ own.push({ band, from: way[position - 1], to: way[position] });
146
+ }
147
+ routes.set(band, { pieces: own, lanes });
148
+ pieces.push(...own);
149
+ }
150
+ orderColumns(columns, pieces);
151
+ // ---- across -------------------------------------------------------------------------------------------------------
152
+ const width = Math.max(Number.isFinite(options.width) ? options.width : 0, measureMinimumWidth(flow.columnCount));
153
+ const pitch = flow.columnCount > 1
154
+ ? (width - 2 * metrics.paddingX - metrics.lastLabelRoom) / (flow.columnCount - 1)
155
+ : 0;
156
+ const columnX = (columnNumber) => metrics.paddingX + columnNumber * pitch;
157
+ const labelWidthOf = (columnNumber) => columnNumber < flow.columnCount - 1
158
+ ? pitch - metrics.labelGutter
159
+ : width - columnX(columnNumber) - metrics.paddingX;
160
+ // ---- the scale ----------------------------------------------------------------------------------------------------
161
+ const labelHeightOf = (item) => item.kind === 'bar'
162
+ ? metrics.nameLineHeight +
163
+ metrics.detailLineHeight * (countLabelLines(item.step) - 1) +
164
+ metrics.labelMargin
165
+ : 0;
166
+ /** The space an item has above it: room for the label of the bar it is (the label is in `labelHeightOf`) or the gap of a lane. */
167
+ const gapBefore = (item) => item.kind === 'bar' ? metrics.stepGap : metrics.laneGap;
168
+ /** What a column needs for its labels and the gaps between its items, whatever the bars come to. */
169
+ const overheadOf = (column) => column.reduce((total, item, position) => total + labelHeightOf(item) + (position > 0 ? gapBefore(item) : 0), 0);
170
+ /** What an item stands for, in visitors: a bar's size, and the value of the band a lane carries. */
171
+ const visitorsOf = (item) => item.kind === 'bar' ? item.step.size : item.band.value;
172
+ const tallestOverhead = Math.max(...columns.map(overheadOf));
173
+ const wantedHeight = Math.max(metrics.minHeight, 2 * metrics.paddingY + tallestOverhead + metrics.barsBudget);
174
+ // Pixels of height for one visitor: the busiest column, the one that fills its height first, sets it for every column.
175
+ let pixelsPerVisitor = Number.POSITIVE_INFINITY;
176
+ for (const column of columns) {
177
+ const visitors = column.reduce((total, item) => total + visitorsOf(item), 0);
178
+ if (visitors > 0) {
179
+ pixelsPerVisitor = Math.min(pixelsPerVisitor, (wantedHeight - 2 * metrics.paddingY - overheadOf(column)) / visitors);
180
+ }
181
+ }
182
+ if (!Number.isFinite(pixelsPerVisitor) || pixelsPerVisitor < 0)
183
+ pixelsPerVisitor = 0;
184
+ // With nobody counted there is no scale to keep: the bands are all alike, and the bars are as tall as the bands they hold.
185
+ const thicknessOf = (band) => flow.hasVisitors
186
+ ? Math.max(metrics.minLinkThickness, band.value * pixelsPerVisitor)
187
+ : metrics.emptyLinkThickness;
188
+ const thicknessSum = (list) => list.reduce((total, piece) => total + thicknessOf(piece.band), 0);
189
+ const piecesOutOf = new Map();
190
+ const piecesInto = new Map();
191
+ for (const piece of pieces) {
192
+ appendTo(piecesOutOf, piece.from, piece);
193
+ appendTo(piecesInto, piece.to, piece);
194
+ }
195
+ /** A bar is as tall as the visitors it stands for, and never thinner than the bands that leave or reach it; a lane is as thick as its band. */
196
+ const barHeightOf = (item) => item.kind === 'bar'
197
+ ? Math.max(metrics.minBarHeight, item.step.size * pixelsPerVisitor, thicknessSum(piecesOutOf.get(item) ?? []), thicknessSum(piecesInto.get(item) ?? []))
198
+ : thicknessOf(item.band);
199
+ // ---- down ---------------------------------------------------------------------------------------------------------
200
+ const contentHeightOf = (column) => overheadOf(column) + column.reduce((total, item) => total + barHeightOf(item), 0);
201
+ const height = Math.max(metrics.minHeight, 2 * metrics.paddingY + Math.max(...columns.map(contentHeightOf)));
202
+ /** Where an item is: the left edge, and the top and height of the bar or lane. */
203
+ const seatOf = new Map();
204
+ const placedSteps = [];
205
+ columns.forEach((column, columnNumber) => {
206
+ // A column with less in it than the busiest one is centred in the height, so that the bands leave and arrive evenly.
207
+ let cursor = metrics.paddingY + (height - 2 * metrics.paddingY - contentHeightOf(column)) / 2;
208
+ column.forEach((item, position) => {
209
+ if (position > 0)
210
+ cursor += gapBefore(item);
211
+ const labelHeight = labelHeightOf(item);
212
+ const barHeight = barHeightOf(item);
213
+ const barY = cursor + labelHeight;
214
+ seatOf.set(item, { x: round(columnX(columnNumber)), barY, barHeight });
215
+ cursor = barY + barHeight;
216
+ if (item.kind !== 'bar')
217
+ return;
218
+ const leavingThickness = thicknessSum(piecesOutOf.get(item) ?? []);
219
+ // The part that did not go on is at the bottom of the bar, under where the bands leave from.
220
+ const roomUnderBands = Math.max(0, barHeight - leavingThickness);
221
+ const stayedHeight = item.step.stayed > 0 && item.step.hasWayOn
222
+ ? Math.min(roomUnderBands, Math.max(metrics.minStayedHeight, item.step.stayed * pixelsPerVisitor))
223
+ : 0;
224
+ placedSteps.push({
225
+ ...item.step,
226
+ x: round(columnX(columnNumber)),
227
+ labelY: round(barY - labelHeight),
228
+ barY: round(barY),
229
+ barHeight: round(barHeight),
230
+ labelHeight,
231
+ labelWidth: round(Math.max(60, labelWidthOf(columnNumber))),
232
+ stayedY: round(barY + barHeight - stayedHeight),
233
+ stayedHeight: round(stayedHeight)
234
+ });
235
+ });
236
+ });
237
+ // ---- the bands ----------------------------------------------------------------------------------------------------
238
+ // Where a piece leaves an item and arrives at one: the pieces that leave an item are stacked from its top in the order of
239
+ // the items they go to (top to bottom), and the ones that arrive in the order of the items they come from, so that none
240
+ // crosses another for no reason.
241
+ const slotOfLeaving = new Map();
242
+ const slotOfArriving = new Map();
243
+ /** Writes, for each piece of one item's side, how far from the top of the item it starts. */
244
+ const stackFromTop = (list, otherEnd, slots) => {
245
+ const barYOfOtherEnd = (piece) => seatOf.get(otherEnd(piece))?.barY ?? 0;
246
+ let offset = 0;
247
+ for (const piece of [...list].sort((first, second) => barYOfOtherEnd(first) - barYOfOtherEnd(second))) {
248
+ slots.set(piece, offset);
249
+ offset += thicknessOf(piece.band);
250
+ }
251
+ };
252
+ for (const column of columns) {
253
+ for (const item of column) {
254
+ stackFromTop(piecesOutOf.get(item) ?? [], (piece) => piece.to, slotOfLeaving);
255
+ stackFromTop(piecesInto.get(item) ?? [], (piece) => piece.from, slotOfArriving);
256
+ }
257
+ }
258
+ const placedLinks = [];
259
+ for (const band of flow.links) {
260
+ const route = routes.get(band);
261
+ const firstPiece = route?.pieces[0];
262
+ const lastPiece = route?.pieces[route.pieces.length - 1];
263
+ if (!route || !firstPiece || !lastPiece)
264
+ continue;
265
+ const source = seatOf.get(firstPiece.from);
266
+ const target = seatOf.get(lastPiece.to);
267
+ if (!source || !target)
268
+ continue;
269
+ const thickness = thicknessOf(band);
270
+ const startX = source.x + metrics.barWidth;
271
+ const startY = source.barY + (slotOfLeaving.get(firstPiece) ?? 0) + thickness / 2;
272
+ const endY = target.barY + (slotOfArriving.get(lastPiece) ?? 0) + thickness / 2;
273
+ /** The places the curve goes through, from the source to the target: where it comes in, where it goes out, how high. */
274
+ const stations = [
275
+ { xIn: startX, xOut: startX, y: startY },
276
+ ...route.lanes.map((lane) => {
277
+ const seat = seatOf.get(lane) ?? { x: startX, barY: startY, barHeight: 0 };
278
+ return { xIn: seat.x, xOut: seat.x + metrics.barWidth, y: seat.barY + seat.barHeight / 2 };
279
+ }),
280
+ { xIn: target.x, xOut: target.x, y: endY }
281
+ ];
282
+ // Each stretch leaves and arrives level, so the curve is smooth through a lane, which it crosses straight.
283
+ let path = `M${round(startX)} ${round(startY)}`;
284
+ for (let position = 1; position < stations.length; position += 1) {
285
+ const from = stations[position - 1];
286
+ const to = stations[position];
287
+ const middleX = (from.xOut + to.xIn) / 2;
288
+ path += `C${round(middleX)} ${round(from.y)} ${round(middleX)} ${round(to.y)} ${round(to.xIn)} ${round(to.y)}`;
289
+ if (to.xOut > to.xIn)
290
+ path += `H${round(to.xOut)}`;
291
+ }
292
+ placedLinks.push({
293
+ ...band,
294
+ path,
295
+ thickness: round(thickness),
296
+ lanes: route.lanes.map((lane) => {
297
+ const seat = seatOf.get(lane);
298
+ return seat
299
+ ? { x: seat.x, y: round(seat.barY + seat.barHeight / 2) }
300
+ : { x: round(startX), y: round(startY) };
301
+ })
302
+ });
303
+ }
304
+ return { width: round(width), height: round(height), steps: placedSteps, links: placedLinks };
305
+ }
@@ -0,0 +1,24 @@
1
+ import type { TranslateWorkflowsMessage } from './blockLabels.js';
2
+ import type { CanvasWords } from './canvasContext.js';
3
+ import type { RunsFlowLink } from './runsFlow.js';
4
+ /**
5
+ * The words of the Runs chart that are names: what a bar is called, what a band is called, and how a visitor gets along it.
6
+ * The names a person wrote (a composition, a rule) go in as they are, and the words around them are messages, so the
7
+ * chart speaks the page's language. It reads the same words the blocks of the canvas read (`CanvasWords`), so a composition
8
+ * is called the same thing on the canvas, in the problems of the editor and here.
9
+ */
10
+ export interface RunsFlowWords {
11
+ /** What a composition is called: its own name, numbered when two are called the same. */
12
+ nameStep(nodeId: string): string;
13
+ /** A band as a phrase: `Welcome to Thanks`. */
14
+ namePath(link: RunsFlowLink): string;
15
+ /**
16
+ * How a visitor gets along a band, in order: what its trigger waits for, then the rule (or the Default path) of each
17
+ * condition on the way. Nothing in the list is empty.
18
+ */
19
+ describeRoute(link: RunsFlowLink): string[];
20
+ }
21
+ export declare function makeRunsFlowWords(input: {
22
+ words: CanvasWords;
23
+ t: TranslateWorkflowsMessage;
24
+ }): RunsFlowWords;
@@ -0,0 +1,50 @@
1
+ import { DEFAULT_PORT } from '@widgetic/workflows-engine';
2
+ import { nameRule } from './blockLabels.js';
3
+ export function makeRunsFlowWords(input) {
4
+ const { words, t } = input;
5
+ // Looked up the first time a way is described, not when the words are made: a workflow the chart cannot read is drawn as
6
+ // nothing and asks for no names, and making its words must not be what takes the screen down.
7
+ let loadedNodes = null;
8
+ const readNodes = () => {
9
+ if (loadedNodes)
10
+ return loadedNodes;
11
+ const nodesById = new Map();
12
+ for (const node of Array.isArray(words.graph.nodes) ? words.graph.nodes : []) {
13
+ if (!nodesById.has(node.id))
14
+ nodesById.set(node.id, node);
15
+ }
16
+ loadedNodes = nodesById;
17
+ return nodesById;
18
+ };
19
+ return {
20
+ nameStep: (nodeId) => words.describeBlock(nodeId),
21
+ namePath: (link) => t('workflows.runs.pathLabel', {
22
+ from: words.describeBlock(link.sourceId),
23
+ to: words.describeBlock(link.targetId)
24
+ }),
25
+ describeRoute: (link) => {
26
+ const parts = [];
27
+ const nodesById = readNodes();
28
+ const trigger = nodesById.get(link.triggerId);
29
+ if (trigger?.type === 'trigger') {
30
+ const line = words.summarizeTrigger(trigger.trigger);
31
+ if (line)
32
+ parts.push(line);
33
+ }
34
+ for (const rule of link.rules) {
35
+ const condition = nodesById.get(rule.conditionId);
36
+ if (condition?.type !== 'condition')
37
+ continue;
38
+ if (rule.port === DEFAULT_PORT) {
39
+ parts.push(t('workflows.condition.defaultName'));
40
+ continue;
41
+ }
42
+ const position = condition.cases.findIndex((conditionCase) => conditionCase.id === rule.port);
43
+ const conditionCase = condition.cases[position];
44
+ if (conditionCase)
45
+ parts.push(nameRule(conditionCase, position, t));
46
+ }
47
+ return parts;
48
+ }
49
+ };
50
+ }
@@ -12,7 +12,7 @@ export declare function makeStatsRange(days: number, now?: Date): {
12
12
  from: string;
13
13
  to: string;
14
14
  };
15
- /** What the Runs canvas shows: a number for every block and line by its id. A block nobody entered is 0, not missing. */
15
+ /** What the Runs chart shows: a number for every block and line by its id. A block nobody entered is 0, not missing. */
16
16
  export interface RunCounts {
17
17
  /** Visitors who started the workflow in the range, or `null` when the counts cover every version. */
18
18
  started: number | null;