@diagrammo/dgmo 0.15.0 → 0.15.1
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 +14 -1
- package/dist/advanced.cjs +53069 -0
- package/dist/advanced.d.cts +4691 -0
- package/dist/advanced.d.ts +4691 -0
- package/dist/advanced.js +52823 -0
- package/dist/auto.cjs +1495 -1288
- package/dist/auto.js +132 -109
- package/dist/auto.mjs +1491 -1284
- package/dist/cli.cjs +173 -150
- package/dist/index.cjs +1486 -1276
- package/dist/index.d.cts +45 -1
- package/dist/index.d.ts +45 -1
- package/dist/index.js +1481 -1272
- package/dist/internal.cjs +1497 -1289
- package/dist/internal.d.cts +80 -79
- package/dist/internal.d.ts +80 -79
- package/dist/internal.js +1492 -1285
- package/dist/pert.cjs +325 -0
- package/dist/pert.d.cts +542 -0
- package/dist/pert.d.ts +542 -0
- package/dist/pert.js +294 -0
- package/package.json +28 -3
- package/src/advanced.ts +731 -0
- package/src/auto/index.ts +14 -13
- package/src/boxes-and-lines/layout.ts +481 -445
- package/src/c4/parser.ts +7 -7
- package/src/chart-types.ts +0 -5
- package/src/class/parser.ts +1 -9
- package/src/cli.ts +9 -7
- package/src/completion-types.ts +28 -0
- package/src/completion.ts +15 -18
- package/src/cycle/layout.ts +2 -2
- package/src/d3.ts +1455 -1122
- package/src/echarts.ts +11 -11
- package/src/er/parser.ts +1 -9
- package/src/er/renderer.ts +1 -1
- package/src/gantt/calculator.ts +1 -11
- package/src/gantt/parser.ts +16 -16
- package/src/gantt/renderer.ts +2 -2
- package/src/graph/flowchart-parser.ts +1 -1
- package/src/graph/flowchart-renderer.ts +1 -1
- package/src/graph/state-renderer.ts +1 -1
- package/src/index.ts +17 -1
- package/src/infra/parser.ts +19 -19
- package/src/infra/renderer.ts +2 -2
- package/src/internal.ts +9 -721
- package/src/kanban/parser.ts +2 -2
- package/src/mindmap/layout.ts +1 -1
- package/src/mindmap/parser.ts +1 -1
- package/src/org/parser.ts +1 -1
- package/src/org/renderer.ts +1 -1
- package/src/pert/layout.ts +1 -1
- package/src/pert/monte-carlo.ts +2 -2
- package/src/pert/parser.ts +3 -3
- package/src/raci/parser.ts +4 -4
- package/src/raci/renderer.ts +1 -1
- package/src/sequence/renderer.ts +1 -4
- package/src/sitemap/parser.ts +1 -1
- package/src/tech-radar/interactive.ts +1 -1
- package/src/tech-radar/renderer.ts +1 -1
- package/src/utils/tag-groups.ts +11 -12
- package/src/wireframe/layout.ts +11 -7
- package/src/wireframe/parser.ts +2 -2
- package/src/wireframe/renderer.ts +5 -2
package/dist/pert.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// src/pert/internal.ts
|
|
2
|
+
var UNIT_TO_DAYS_LOCAL = {
|
|
3
|
+
min: 1 / (60 * 24),
|
|
4
|
+
h: 1 / 24,
|
|
5
|
+
d: 1,
|
|
6
|
+
bd: 1,
|
|
7
|
+
// PERT has no calendar; bd ≈ d for analytical purposes
|
|
8
|
+
w: 7,
|
|
9
|
+
m: 30,
|
|
10
|
+
q: 90,
|
|
11
|
+
y: 365,
|
|
12
|
+
s: 14
|
|
13
|
+
// sprint (14 calendar days) — not seconds
|
|
14
|
+
};
|
|
15
|
+
function unitToDays(unit) {
|
|
16
|
+
return UNIT_TO_DAYS_LOCAL[unit];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/pert/monte-carlo.ts
|
|
20
|
+
function lagDays(lag) {
|
|
21
|
+
return lag === null ? 0 : lag.amount * unitToDays(lag.unit);
|
|
22
|
+
}
|
|
23
|
+
function mulberry32(seed) {
|
|
24
|
+
let s = seed >>> 0;
|
|
25
|
+
return () => {
|
|
26
|
+
s = s + 1831565813 >>> 0;
|
|
27
|
+
let t = s;
|
|
28
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
29
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
30
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function standardNormal(rng) {
|
|
34
|
+
let u = 0;
|
|
35
|
+
let v = 0;
|
|
36
|
+
while (u === 0) u = rng();
|
|
37
|
+
while (v === 0) v = rng();
|
|
38
|
+
return Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
|
|
39
|
+
}
|
|
40
|
+
function gamma(shape, rng) {
|
|
41
|
+
if (shape < 1) {
|
|
42
|
+
const u = rng();
|
|
43
|
+
return gamma(shape + 1, rng) * Math.pow(u, 1 / shape);
|
|
44
|
+
}
|
|
45
|
+
const d = shape - 1 / 3;
|
|
46
|
+
const c = 1 / Math.sqrt(9 * d);
|
|
47
|
+
while (true) {
|
|
48
|
+
let x;
|
|
49
|
+
let v;
|
|
50
|
+
do {
|
|
51
|
+
x = standardNormal(rng);
|
|
52
|
+
v = 1 + c * x;
|
|
53
|
+
} while (v <= 0);
|
|
54
|
+
v = v * v * v;
|
|
55
|
+
const u = rng();
|
|
56
|
+
if (u < 1 - 0.0331 * x * x * x * x) return d * v;
|
|
57
|
+
if (Math.log(u) < x * x / 2 + d * (1 - v + Math.log(v))) return d * v;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function sampleBeta(alpha, beta, rng) {
|
|
61
|
+
const x = gamma(alpha, rng);
|
|
62
|
+
const y = gamma(beta, rng);
|
|
63
|
+
return x / (x + y);
|
|
64
|
+
}
|
|
65
|
+
function sampleBetaPert(o, m, p, rng) {
|
|
66
|
+
if (o === p) return m;
|
|
67
|
+
const range = p - o;
|
|
68
|
+
const alpha = 1 + 4 * (m - o) / range;
|
|
69
|
+
const beta = 1 + 4 * (p - m) / range;
|
|
70
|
+
return o + sampleBeta(alpha, beta, rng) * range;
|
|
71
|
+
}
|
|
72
|
+
function simulate(resolved, expanded, _predecessors, _successors, topo, terminals, poisoned, opts) {
|
|
73
|
+
const rng = mulberry32(opts.seed);
|
|
74
|
+
const expById = /* @__PURE__ */ new Map();
|
|
75
|
+
for (const e of expanded) expById.set(e.id, e);
|
|
76
|
+
const completionTimes = new Array(opts.trials);
|
|
77
|
+
const criticalityCount = /* @__PURE__ */ new Map();
|
|
78
|
+
for (const id of topo) criticalityCount.set(id, 0);
|
|
79
|
+
const pathCount = /* @__PURE__ */ new Map();
|
|
80
|
+
const pathById = /* @__PURE__ */ new Map();
|
|
81
|
+
const incomingEdges = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const id of topo) incomingEdges.set(id, []);
|
|
83
|
+
for (const e of resolved.edges) incomingEdges.get(e.target)?.push(e);
|
|
84
|
+
const es = /* @__PURE__ */ new Map();
|
|
85
|
+
const ef = /* @__PURE__ */ new Map();
|
|
86
|
+
const predOnLongestPath = /* @__PURE__ */ new Map();
|
|
87
|
+
for (let trial = 0; trial < opts.trials; trial++) {
|
|
88
|
+
for (const id of topo) {
|
|
89
|
+
const exp = expById.get(id);
|
|
90
|
+
let duration;
|
|
91
|
+
if (!exp || poisoned.has(id)) {
|
|
92
|
+
duration = 0;
|
|
93
|
+
} else if (exp.o === exp.p) {
|
|
94
|
+
duration = exp.m;
|
|
95
|
+
} else {
|
|
96
|
+
duration = sampleBetaPert(exp.o, exp.m, exp.p, rng);
|
|
97
|
+
}
|
|
98
|
+
let esLower = 0;
|
|
99
|
+
let efLower = -Infinity;
|
|
100
|
+
let bestPred = null;
|
|
101
|
+
let bestPredVal = -Infinity;
|
|
102
|
+
for (const edge of incomingEdges.get(id) ?? []) {
|
|
103
|
+
const aEs = es.get(edge.source) ?? 0;
|
|
104
|
+
const aEf = ef.get(edge.source) ?? 0;
|
|
105
|
+
const lag = lagDays(edge.lag);
|
|
106
|
+
let candES = -Infinity;
|
|
107
|
+
let candEF = -Infinity;
|
|
108
|
+
switch (edge.type) {
|
|
109
|
+
case "FS":
|
|
110
|
+
candES = aEf + lag;
|
|
111
|
+
break;
|
|
112
|
+
case "SS":
|
|
113
|
+
candES = aEs + lag;
|
|
114
|
+
break;
|
|
115
|
+
case "FF":
|
|
116
|
+
candEF = aEf + lag;
|
|
117
|
+
break;
|
|
118
|
+
case "SF":
|
|
119
|
+
candEF = aEs + lag;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (candES > esLower) esLower = candES;
|
|
123
|
+
if (candEF > efLower) efLower = candEF;
|
|
124
|
+
const contribution = Math.max(candES, candEF - duration);
|
|
125
|
+
if (contribution > bestPredVal) {
|
|
126
|
+
bestPredVal = contribution;
|
|
127
|
+
bestPred = edge.source;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let esVal = esLower;
|
|
131
|
+
let efVal = esVal + duration;
|
|
132
|
+
if (efLower > efVal) {
|
|
133
|
+
efVal = efLower;
|
|
134
|
+
esVal = efVal - duration;
|
|
135
|
+
}
|
|
136
|
+
es.set(id, esVal);
|
|
137
|
+
ef.set(id, efVal);
|
|
138
|
+
predOnLongestPath.set(id, bestPred);
|
|
139
|
+
}
|
|
140
|
+
let endEf = 0;
|
|
141
|
+
let endId = terminals[0] ?? null;
|
|
142
|
+
for (const id of topo) {
|
|
143
|
+
const e = ef.get(id) ?? 0;
|
|
144
|
+
if (e > endEf) {
|
|
145
|
+
endEf = e;
|
|
146
|
+
endId = id;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
completionTimes[trial] = endEf;
|
|
150
|
+
if (endId !== null) {
|
|
151
|
+
const path = [];
|
|
152
|
+
let cur = endId;
|
|
153
|
+
while (cur !== null) {
|
|
154
|
+
path.unshift(cur);
|
|
155
|
+
criticalityCount.set(cur, (criticalityCount.get(cur) ?? 0) + 1);
|
|
156
|
+
cur = predOnLongestPath.get(cur) ?? null;
|
|
157
|
+
}
|
|
158
|
+
const key = path.join("\0");
|
|
159
|
+
pathCount.set(key, (pathCount.get(key) ?? 0) + 1);
|
|
160
|
+
if (!pathById.has(key)) pathById.set(key, path);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
completionTimes.sort((a, b) => a - b);
|
|
164
|
+
const pct = (frac) => {
|
|
165
|
+
const idx = Math.min(
|
|
166
|
+
completionTimes.length - 1,
|
|
167
|
+
Math.max(0, Math.floor(frac * completionTimes.length))
|
|
168
|
+
);
|
|
169
|
+
return completionTimes[idx] ?? 0;
|
|
170
|
+
};
|
|
171
|
+
const minDurationDays = completionTimes[0] ?? 0;
|
|
172
|
+
const maxDurationDays = completionTimes[completionTimes.length - 1] ?? 0;
|
|
173
|
+
let modalKey = "";
|
|
174
|
+
let modalCount = -1;
|
|
175
|
+
for (const [key, count] of pathCount) {
|
|
176
|
+
if (count > modalCount) {
|
|
177
|
+
modalCount = count;
|
|
178
|
+
modalKey = key;
|
|
179
|
+
} else if (count === modalCount) {
|
|
180
|
+
const a = pathById.get(modalKey) ?? [];
|
|
181
|
+
const b = pathById.get(key) ?? [];
|
|
182
|
+
const va = pathVariance(a, expById);
|
|
183
|
+
const vb = pathVariance(b, expById);
|
|
184
|
+
if (vb > va) {
|
|
185
|
+
modalKey = key;
|
|
186
|
+
} else if (vb === va && key.localeCompare(modalKey) < 0) {
|
|
187
|
+
modalKey = key;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const criticalityByActivity = {};
|
|
192
|
+
for (const id of topo) {
|
|
193
|
+
criticalityByActivity[id] = (criticalityCount.get(id) ?? 0) / opts.trials;
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
trials: opts.trials,
|
|
197
|
+
seed: opts.seed,
|
|
198
|
+
p50: pct(0.5),
|
|
199
|
+
p80: pct(0.8),
|
|
200
|
+
p95: pct(0.95),
|
|
201
|
+
p16: pct(0.16),
|
|
202
|
+
p84: pct(0.84),
|
|
203
|
+
criticalityByActivity,
|
|
204
|
+
modalCriticalPath: pathById.get(modalKey) ?? [],
|
|
205
|
+
// Analyzer populates this after MC returns by running the
|
|
206
|
+
// deterministic per-activity tornado pass. Empty here so the
|
|
207
|
+
// type contract is satisfied even in scrubber/fast paths that
|
|
208
|
+
// never compute swings.
|
|
209
|
+
tornadoSwings: [],
|
|
210
|
+
minDurationDays,
|
|
211
|
+
maxDurationDays
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function pathVariance(path, expById) {
|
|
215
|
+
let sum = 0;
|
|
216
|
+
for (const id of path) {
|
|
217
|
+
const e = expById.get(id);
|
|
218
|
+
if (!e) continue;
|
|
219
|
+
const sigma = (e.p - e.o) / 6;
|
|
220
|
+
sum += sigma * sigma;
|
|
221
|
+
}
|
|
222
|
+
return sum;
|
|
223
|
+
}
|
|
224
|
+
function buildSimulationContext(resolved) {
|
|
225
|
+
const predecessors = /* @__PURE__ */ new Map();
|
|
226
|
+
const successors = /* @__PURE__ */ new Map();
|
|
227
|
+
for (const r of resolved.activities) {
|
|
228
|
+
predecessors.set(r.activity.id, []);
|
|
229
|
+
successors.set(r.activity.id, []);
|
|
230
|
+
}
|
|
231
|
+
for (const e of resolved.edges) {
|
|
232
|
+
successors.get(e.source)?.push(e.target);
|
|
233
|
+
predecessors.get(e.target)?.push(e.source);
|
|
234
|
+
}
|
|
235
|
+
const inDegree = /* @__PURE__ */ new Map();
|
|
236
|
+
for (const r of resolved.activities) {
|
|
237
|
+
inDegree.set(r.activity.id, predecessors.get(r.activity.id).length);
|
|
238
|
+
}
|
|
239
|
+
const queue = [];
|
|
240
|
+
for (const [id, deg] of inDegree) if (deg === 0) queue.push(id);
|
|
241
|
+
const topo = [];
|
|
242
|
+
while (queue.length > 0) {
|
|
243
|
+
const id = queue.shift();
|
|
244
|
+
topo.push(id);
|
|
245
|
+
for (const next of successors.get(id) ?? []) {
|
|
246
|
+
const deg = (inDegree.get(next) ?? 0) - 1;
|
|
247
|
+
inDegree.set(next, deg);
|
|
248
|
+
if (deg === 0) queue.push(next);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const terminals = [];
|
|
252
|
+
for (const r of resolved.activities) {
|
|
253
|
+
if ((successors.get(r.activity.id) ?? []).length === 0) {
|
|
254
|
+
terminals.push(r.activity.id);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const poisoned = /* @__PURE__ */ new Set();
|
|
258
|
+
for (const r of resolved.activities) {
|
|
259
|
+
if (r.activity.duration === null) {
|
|
260
|
+
const stack = [r.activity.id];
|
|
261
|
+
while (stack.length > 0) {
|
|
262
|
+
const id = stack.pop();
|
|
263
|
+
if (poisoned.has(id)) continue;
|
|
264
|
+
poisoned.add(id);
|
|
265
|
+
for (const next of successors.get(id) ?? []) stack.push(next);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return { predecessors, successors, topo, terminals, poisoned };
|
|
270
|
+
}
|
|
271
|
+
function simulateCanonical(resolved, expanded, opts) {
|
|
272
|
+
const ctx = buildSimulationContext(resolved);
|
|
273
|
+
return simulate(
|
|
274
|
+
resolved,
|
|
275
|
+
expanded,
|
|
276
|
+
ctx.predecessors,
|
|
277
|
+
ctx.successors,
|
|
278
|
+
ctx.topo,
|
|
279
|
+
ctx.terminals,
|
|
280
|
+
ctx.poisoned,
|
|
281
|
+
{ trials: opts.trials, seed: opts.seed }
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
function simulateFast(resolved, expanded, opts) {
|
|
285
|
+
return simulateCanonical(resolved, expanded, opts);
|
|
286
|
+
}
|
|
287
|
+
export {
|
|
288
|
+
buildSimulationContext,
|
|
289
|
+
mulberry32,
|
|
290
|
+
sampleBetaPert,
|
|
291
|
+
simulateCanonical,
|
|
292
|
+
simulateFast
|
|
293
|
+
};
|
|
294
|
+
//# sourceMappingURL=pert.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diagrammo/dgmo",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
4
4
|
"description": "DGMO diagram markup language — parser, renderer, and color system",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://github.com/diagrammo/dgmo#readme",
|
|
11
11
|
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20.6"
|
|
14
|
+
},
|
|
12
15
|
"bin": {
|
|
13
16
|
"dgmo": "dist/cli.cjs"
|
|
14
17
|
},
|
|
@@ -46,6 +49,16 @@
|
|
|
46
49
|
"default": "./dist/highlight.cjs"
|
|
47
50
|
}
|
|
48
51
|
},
|
|
52
|
+
"./advanced": {
|
|
53
|
+
"import": {
|
|
54
|
+
"types": "./dist/advanced.d.ts",
|
|
55
|
+
"default": "./dist/advanced.js"
|
|
56
|
+
},
|
|
57
|
+
"require": {
|
|
58
|
+
"types": "./dist/advanced.d.cts",
|
|
59
|
+
"default": "./dist/advanced.cjs"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
49
62
|
"./internal": {
|
|
50
63
|
"import": {
|
|
51
64
|
"types": "./dist/internal.d.ts",
|
|
@@ -56,6 +69,16 @@
|
|
|
56
69
|
"default": "./dist/internal.cjs"
|
|
57
70
|
}
|
|
58
71
|
},
|
|
72
|
+
"./pert": {
|
|
73
|
+
"import": {
|
|
74
|
+
"types": "./dist/pert.d.ts",
|
|
75
|
+
"default": "./dist/pert.js"
|
|
76
|
+
},
|
|
77
|
+
"require": {
|
|
78
|
+
"types": "./dist/pert.d.cts",
|
|
79
|
+
"default": "./dist/pert.cjs"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
59
82
|
"./auto": {
|
|
60
83
|
"import": {
|
|
61
84
|
"types": "./dist/auto.d.ts",
|
|
@@ -96,7 +119,7 @@
|
|
|
96
119
|
"typecheck": "tsc --noEmit",
|
|
97
120
|
"dev": "tsup --watch",
|
|
98
121
|
"pretest": "pnpm codegen",
|
|
99
|
-
"test": "vitest run",
|
|
122
|
+
"test": "vitest run --coverage",
|
|
100
123
|
"test:watch": "vitest",
|
|
101
124
|
"test:auto": "pnpm build && vitest run tests/auto.test.ts tests/safe-href.test.ts",
|
|
102
125
|
"sri": "node scripts/sri.mjs",
|
|
@@ -111,7 +134,7 @@
|
|
|
111
134
|
"check:deadcode": "knip",
|
|
112
135
|
"check:spelling": "cspell \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
113
136
|
"check:all": "pnpm check:deadcode && pnpm check:spelling && pnpm check:duplication && pnpm check:circular && pnpm check:deps && pnpm check:security && pnpm build && pnpm check:publish && pnpm check:types",
|
|
114
|
-
"check:circular": "madge --circular --extensions ts src/ --json | node -e \"const c=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')); const n=c.length; if(n>
|
|
137
|
+
"check:circular": "madge --circular --extensions ts src/ --json | node -e \"const c=JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')); const n=c.length; if(n>4){console.error('New circular deps found ('+n+' > 4 known type-only cycles)');process.exit(1)}else if(n>0){console.log(n+' known type-only/dynamic cycles (safe)')}else{console.log('No circular dependencies')}\"",
|
|
115
138
|
"check:deps": "depcheck --ignores='@codemirror/language,@lezer/*,husky,lint-staged,tsup,axe-core'",
|
|
116
139
|
"check:security": "pnpm audit --prod",
|
|
117
140
|
"check:publish": "publint",
|
|
@@ -130,6 +153,7 @@
|
|
|
130
153
|
"d3-selection": "^3.0.0",
|
|
131
154
|
"d3-shape": "^3.2.0",
|
|
132
155
|
"echarts": "^6.0.0",
|
|
156
|
+
"elkjs": "^0.11.1",
|
|
133
157
|
"jsdom": "^29.0.2",
|
|
134
158
|
"lz-string": "^1.5.0"
|
|
135
159
|
},
|
|
@@ -145,6 +169,7 @@
|
|
|
145
169
|
"@types/d3-selection": "^3.0.11",
|
|
146
170
|
"@types/d3-shape": "^3.1.8",
|
|
147
171
|
"@types/jsdom": "^28.0.1",
|
|
172
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
148
173
|
"axe-core": "^4.10.0",
|
|
149
174
|
"cspell": "^10.0.0",
|
|
150
175
|
"depcheck": "^1.4.7",
|