@fengwk/kchart 0.1.1 → 0.2.0
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/CHANGELOG.md +35 -0
- package/README.md +31 -2
- package/README.zh-CN.md +31 -2
- package/dist/esm/_virtual/_kchart-families.js +2 -1
- package/dist/esm/chart/composition.js +7 -5
- package/dist/esm/chart/maps.js +9 -7
- package/dist/esm/chart/mindmap.js +19 -5
- package/dist/esm/chart/multivariate.js +49 -14
- package/dist/esm/chart/relations.js +15 -7
- package/dist/esm/chart/spec.js +5 -2
- package/dist/esm/core/context.js +29 -10
- package/dist/esm/core/scene.js +238 -21
- package/dist/esm/core/text.js +1 -1
- package/dist/esm/diagram/block.js +287 -295
- package/dist/esm/diagram/blocks.js +541 -605
- package/dist/esm/diagram/board-paint.js +594 -0
- package/dist/esm/diagram/board-route.js +60 -0
- package/dist/esm/diagram/c4.js +75 -35
- package/dist/esm/diagram/class.js +3 -2
- package/dist/esm/diagram/cynefin.js +55 -9
- package/dist/esm/diagram/eventmodeling.js +4 -2
- package/dist/esm/diagram/gantt.js +37 -15
- package/dist/esm/diagram/gitgraph.js +26 -5
- package/dist/esm/diagram/graph-layout.js +39 -2
- package/dist/esm/diagram/graph-route.js +296 -38
- package/dist/esm/diagram/info.js +32 -0
- package/dist/esm/diagram/journey.js +5 -5
- package/dist/esm/diagram/kanban.js +3 -3
- package/dist/esm/diagram/layers.js +9 -7
- package/dist/esm/diagram/mindmap.js +5 -1
- package/dist/esm/diagram/numeric-composition.js +24 -4
- package/dist/esm/diagram/numeric-model.js +1 -1
- package/dist/esm/diagram/numeric-radar.js +25 -7
- package/dist/esm/diagram/numeric-sankey.js +4 -3
- package/dist/esm/diagram/numeric-xy.js +12 -2
- package/dist/esm/diagram/packet.js +4 -4
- package/dist/esm/diagram/quadrant.js +12 -5
- package/dist/esm/diagram/railroad-parse.js +20 -10
- package/dist/esm/diagram/railroad.js +1 -1
- package/dist/esm/diagram/registry.js +46 -8
- package/dist/esm/diagram/sequence.js +43 -6
- package/dist/esm/diagram/swimlane.js +2 -2
- package/dist/esm/diagram/time.js +3 -3
- package/dist/esm/diagram/timeline.js +5 -5
- package/dist/esm/diagram/treeview.js +5 -3
- package/dist/esm/diagram/venn.js +35 -15
- package/dist/esm/diagram/wardley.js +61 -26
- package/dist/esm/diagram/zenuml.js +338 -0
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/mermaid.d.ts +1 -1
- package/dist/esm/mermaid.js +2 -1
- package/dist/esm/node.js +8 -2
- package/dist/esm/src/families.js +6 -1
- package/dist/units/chart/composition.js +1 -1
- package/dist/units/chart/maps.js +1 -1
- package/dist/units/chart/mindmap.js +1 -1
- package/dist/units/chart/multivariate.js +1 -1
- package/dist/units/chart/relations.js +1 -1
- package/dist/units/chart/spec.js +1 -1
- package/dist/units/core/context.js +1 -1
- package/dist/units/core/scene.js +1 -1
- package/dist/units/core/text.js +1 -1
- package/dist/units/diagram/block.js +2 -2
- package/dist/units/diagram/blocks.js +2 -2
- package/dist/units/diagram/board-paint.js +1 -0
- package/dist/units/diagram/board-route.js +1 -0
- package/dist/units/diagram/c4.js +1 -1
- package/dist/units/diagram/class.js +2 -2
- package/dist/units/diagram/cynefin.js +2 -2
- package/dist/units/diagram/eventmodeling.js +1 -1
- package/dist/units/diagram/gantt.js +3 -3
- package/dist/units/diagram/gitgraph.js +2 -1
- package/dist/units/diagram/graph-layout.js +1 -1
- package/dist/units/diagram/graph-route.js +1 -1
- package/dist/units/diagram/info.js +2 -0
- package/dist/units/diagram/journey.js +3 -3
- package/dist/units/diagram/kanban.js +1 -1
- package/dist/units/diagram/layers.js +1 -1
- package/dist/units/diagram/mindmap.js +1 -1
- package/dist/units/diagram/numeric-composition.js +1 -1
- package/dist/units/diagram/numeric-model.js +1 -1
- package/dist/units/diagram/numeric-radar.js +2 -2
- package/dist/units/diagram/numeric-sankey.js +1 -1
- package/dist/units/diagram/numeric-xy.js +1 -1
- package/dist/units/diagram/packet.js +1 -1
- package/dist/units/diagram/quadrant.js +1 -1
- package/dist/units/diagram/railroad-parse.js +2 -2
- package/dist/units/diagram/railroad.js +1 -1
- package/dist/units/diagram/registry.js +2 -2
- package/dist/units/diagram/sequence.js +1 -1
- package/dist/units/diagram/swimlane.js +2 -2
- package/dist/units/diagram/time.js +1 -1
- package/dist/units/diagram/timeline.js +1 -1
- package/dist/units/diagram/treeview.js +1 -1
- package/dist/units/diagram/venn.js +1 -1
- package/dist/units/diagram/wardley.js +4 -4
- package/dist/units/diagram/zenuml.js +2 -0
- package/dist/units.json +79 -51
- package/package.json +1 -1
- package/dist/esm/diagram/relations.js +0 -966
- package/dist/units/diagram/relations.js +0 -3
package/dist/esm/diagram/c4.js
CHANGED
|
@@ -779,10 +779,10 @@ function drawBox(ctx, b) {
|
|
|
779
779
|
];
|
|
780
780
|
return b.link ? [ctx.link(b.link.href, shapes, b.link)] : shapes;
|
|
781
781
|
}
|
|
782
|
-
function layout(model, { width, ctx, lang }) {
|
|
782
|
+
function layout(model, { width, ctx, lang, compact }) {
|
|
783
783
|
const root = makeBoxes(model, ctx, lang), nodes = [], frames = [], byId = /* @__PURE__ */ new Map();
|
|
784
784
|
const margin = 38;
|
|
785
|
-
const sceneWidth = Math.max(width, root.w + 76);
|
|
785
|
+
const sceneWidth = Math.max(compact ? 0 : width, root.w + 76);
|
|
786
786
|
let height = root.h + 76;
|
|
787
787
|
function place(boxes, x, y) {
|
|
788
788
|
for (const box of boxes) {
|
|
@@ -877,6 +877,18 @@ function layout(model, { width, ctx, lang }) {
|
|
|
877
877
|
}
|
|
878
878
|
children.push(...nodes.flatMap((b) => drawBox(ctx, b)));
|
|
879
879
|
const leaders = [];
|
|
880
|
+
const coarse = [
|
|
881
|
+
.5,
|
|
882
|
+
.4,
|
|
883
|
+
.6,
|
|
884
|
+
.3,
|
|
885
|
+
.7,
|
|
886
|
+
.2,
|
|
887
|
+
.8,
|
|
888
|
+
.1,
|
|
889
|
+
.9
|
|
890
|
+
];
|
|
891
|
+
const fine = Array.from({ length: 19 }, (_, i) => i + 1).flatMap((i) => [(20 - i) / 40, (20 + i) / 40]).filter((t) => !coarse.includes(t));
|
|
880
892
|
for (const { path, rel, meta } of routes) {
|
|
881
893
|
const label = relLabel(rel, ctx);
|
|
882
894
|
if (!label) continue;
|
|
@@ -900,52 +912,80 @@ function layout(model, { width, ctx, lang }) {
|
|
|
900
912
|
h
|
|
901
913
|
});
|
|
902
914
|
const free = (box) => box.y >= 6 && box.y + h <= height - 6 && !occupied.some((b) => overlaps(inflate(box, 4), b)) && !arrowBoxes.some((b) => overlaps(box, b));
|
|
903
|
-
const candidates = [[preferred, mid]];
|
|
904
|
-
for (const t of [
|
|
905
|
-
.5,
|
|
906
|
-
.4,
|
|
907
|
-
.6,
|
|
908
|
-
.3,
|
|
909
|
-
.7,
|
|
910
|
-
.2,
|
|
911
|
-
.8,
|
|
912
|
-
.1,
|
|
913
|
-
.9
|
|
914
|
-
]) {
|
|
915
|
-
const p = along(t);
|
|
916
|
-
candidates.push([point(p.x, 6 + h / 2), p], [point(p.x, height - 6 - h / 2), p]);
|
|
917
|
-
for (const dx of [
|
|
918
|
-
0,
|
|
919
|
-
-w / 2 - 4,
|
|
920
|
-
w / 2 + 4
|
|
921
|
-
]) for (const dy of [
|
|
922
|
-
0,
|
|
923
|
-
-h / 2 - 4,
|
|
924
|
-
h / 2 + 4,
|
|
925
|
-
-h - 8,
|
|
926
|
-
h + 8
|
|
927
|
-
]) candidates.push([point(p.x + dx, p.y + dy), p]);
|
|
928
|
-
}
|
|
929
915
|
let box, leader, best = Infinity;
|
|
930
916
|
const other = used.filter((seg) => !path.includes(seg[0]) || !path.includes(seg[1])).concat(leaders);
|
|
931
|
-
|
|
917
|
+
const clear = (tie) => !occupied.some((b) => hits(tie, b));
|
|
918
|
+
const consider = (p, pOnEdge) => {
|
|
932
919
|
const candidate = plate(p);
|
|
933
|
-
if (!free(candidate))
|
|
920
|
+
if (!free(candidate)) return;
|
|
934
921
|
const end = point(Math.max(candidate.x, Math.min(candidate.x + w, pOnEdge.x)), Math.max(candidate.y, Math.min(candidate.y + h, pOnEdge.y)));
|
|
935
922
|
const tie = parts.some((seg) => hits(seg, candidate)) ? null : [pOnEdge, end];
|
|
936
|
-
if (tie &&
|
|
937
|
-
const
|
|
938
|
-
|
|
923
|
+
if (tie && !clear(tie)) return;
|
|
924
|
+
const padded = inflate(candidate, 2);
|
|
925
|
+
if (frames.some((frame) => overlaps(frame, padded) && !contains(frame, padded))) return;
|
|
926
|
+
const score = distance(point(cx(candidate), cy(candidate)), preferred) + (tie ? distance(...tie) * 2 : 0) + 240 * other.filter((seg) => hits(seg, candidate)).length;
|
|
939
927
|
if (score < best) {
|
|
940
928
|
best = score;
|
|
941
929
|
box = candidate;
|
|
942
930
|
leader = tie;
|
|
943
931
|
}
|
|
932
|
+
};
|
|
933
|
+
const search = (fractions) => {
|
|
934
|
+
for (const t of fractions) {
|
|
935
|
+
const p = along(t);
|
|
936
|
+
consider(point(p.x, 6 + h / 2), p);
|
|
937
|
+
consider(point(p.x, height - 6 - h / 2), p);
|
|
938
|
+
for (const dx of [
|
|
939
|
+
0,
|
|
940
|
+
-w / 2 - 4,
|
|
941
|
+
w / 2 + 4
|
|
942
|
+
]) for (const dy of [
|
|
943
|
+
0,
|
|
944
|
+
-h / 2 - 4,
|
|
945
|
+
h / 2 + 4,
|
|
946
|
+
-h - 8,
|
|
947
|
+
h + 8
|
|
948
|
+
]) consider(point(p.x + dx, p.y + dy), p);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
consider(preferred, mid);
|
|
952
|
+
search(coarse);
|
|
953
|
+
if (!box) search(fine);
|
|
954
|
+
if (!box) for (const t of coarse) {
|
|
955
|
+
const p = along(t);
|
|
956
|
+
for (const x of [6 + w / 2, sceneWidth - 6 - w / 2]) {
|
|
957
|
+
const candidate = plate(point(x, p.y));
|
|
958
|
+
const padded = inflate(candidate, 2);
|
|
959
|
+
if (!free(candidate) || frames.some((frame) => overlaps(frame, padded) && !contains(frame, padded))) continue;
|
|
960
|
+
const tie = [p, point(p.x < x ? candidate.x : candidate.x + w, p.y)];
|
|
961
|
+
if (!clear(tie)) continue;
|
|
962
|
+
const score = distance(...tie);
|
|
963
|
+
if (score < best) {
|
|
964
|
+
best = score;
|
|
965
|
+
box = candidate;
|
|
966
|
+
leader = tie;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
944
969
|
}
|
|
945
970
|
if (!box) {
|
|
946
|
-
|
|
971
|
+
const anchors = [
|
|
972
|
+
...path,
|
|
973
|
+
...coarse.map(along),
|
|
974
|
+
...fine.map(along)
|
|
975
|
+
].sort((a, b) => b.y - a.y);
|
|
976
|
+
for (const p of anchors) {
|
|
977
|
+
const candidate = plate(point(p.x, height + h / 2));
|
|
978
|
+
const tie = [p, point(p.x, candidate.y)];
|
|
979
|
+
if (p.x < candidate.x || p.x > candidate.x + w || !clear(tie)) continue;
|
|
980
|
+
box = candidate;
|
|
981
|
+
leader = tie;
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
if (!box) {
|
|
985
|
+
box = plate(point(mid.x, height + h / 2));
|
|
986
|
+
leader = [mid, point(cx(box), box.y)];
|
|
987
|
+
}
|
|
947
988
|
height += h + 14;
|
|
948
|
-
leader = [mid, point(cx(box), box.y)];
|
|
949
989
|
}
|
|
950
990
|
if (leader) {
|
|
951
991
|
leaders.push(leader);
|
|
@@ -824,6 +824,7 @@ function layoutCards(model, { ctx, width, lang, measure = (s, f) => ctx.measure(
|
|
|
824
824
|
if (w > 199) frameMin.set(card.id, Math.max(frameMin.get(card.id) || 0, w + 2));
|
|
825
825
|
}
|
|
826
826
|
}
|
|
827
|
+
const sectionGap = (rows, i, sections) => !requirements && rows.length && i < sections.length - 1 ? 5 : 0;
|
|
827
828
|
const nodes = cards.map((card, seq) => {
|
|
828
829
|
const wrap = (rows, members = false) => rows.flatMap((row) => (members ? wrapAtSeparators(row.text, 328, (s) => measure(s, FONT.label), /(?<=,)|(?<=[^\s:])(?=\s*:(?!:))/u) : ctx.wrap(row.text, 172, FONT.label.size, FONT.label.weight)).map((text) => ({
|
|
829
830
|
...row,
|
|
@@ -846,7 +847,7 @@ function layoutCards(model, { ctx, width, lang, measure = (s, f) => ctx.measure(
|
|
|
846
847
|
const detail = [...annotations, ...sections.flat()];
|
|
847
848
|
const w = Math.max(64, frameMin.get(card.id) || 0, 28 + Math.max(0, ...lines.map((s) => measure(s, FONT.title)), ...detail.map((row) => measure(row.text, FONT.body))));
|
|
848
849
|
const rowCount = annotations.length + Number(Boolean(card.icon)) + sections.reduce((sum, rows) => sum + Math.max(1, rows.length), 0);
|
|
849
|
-
const h = Math.max(40, 20 + lines.length * 19 + (rowCount ? 5 + rowCount * 17 : 0));
|
|
850
|
+
const h = Math.max(40, 20 + lines.length * 19 + (rowCount ? 5 + rowCount * 17 : 0) + sections.reduce((sum, rows, i) => sum + sectionGap(rows, i, sections), 0));
|
|
850
851
|
return {
|
|
851
852
|
id: card.id,
|
|
852
853
|
seq,
|
|
@@ -1100,7 +1101,7 @@ function layoutCards(model, { ctx, width, lang, measure = (s, f) => ctx.measure(
|
|
|
1100
1101
|
"stroke-width": .7
|
|
1101
1102
|
}));
|
|
1102
1103
|
for (const [j, row] of rows.entries()) drawRow(row, x + 14, cursor + 11 + j * 17, {});
|
|
1103
|
-
cursor += Math.max(1, rows.length) * 17;
|
|
1104
|
+
cursor += Math.max(1, rows.length) * 17 + sectionGap(rows, i, sections);
|
|
1104
1105
|
}
|
|
1105
1106
|
if (card.link) boxes.push(ctx.link(card.link.href, items, card.link));
|
|
1106
1107
|
else boxes.push(...items);
|
|
@@ -368,8 +368,9 @@ function layout(model, options = {}) {
|
|
|
368
368
|
const errors = [];
|
|
369
369
|
const ink = (value, font) => Math.max(0, measure(value, font.size, font.weight));
|
|
370
370
|
const wrap = (value, maxWidth, font) => wrapText(value, maxWidth, font, (piece, spec) => measure(piece, spec));
|
|
371
|
+
const compact = options.compact === true;
|
|
371
372
|
const nameFont = {
|
|
372
|
-
size: FONT.title.size,
|
|
373
|
+
size: compact ? 13 : FONT.title.size,
|
|
373
374
|
weight: FONT.title.weight
|
|
374
375
|
};
|
|
375
376
|
const bodyFont = {
|
|
@@ -378,8 +379,10 @@ function layout(model, options = {}) {
|
|
|
378
379
|
};
|
|
379
380
|
const widest = (lines, font) => Math.ceil(Math.max(0, ...lines.map((line) => ink(line, font))));
|
|
380
381
|
const titleLines = model.title ? wrap(model.title, Math.max(160, Math.min(640, width - 48)), nameFont) : [];
|
|
381
|
-
const titleHeight = titleLines.length ? titleLines.length * TITLE_LINE + TITLE_GAP : 0;
|
|
382
|
-
const
|
|
382
|
+
const titleHeight = !options.embedHeading && titleLines.length ? titleLines.length * TITLE_LINE + TITLE_GAP : 0;
|
|
383
|
+
const itemCount = DOMAINS.reduce((sum, name) => sum + model.domains[name].length, 0);
|
|
384
|
+
const transitionRoom = model.transitions.some((transition) => transition.label) ? 104 : 0;
|
|
385
|
+
const plotW = compact ? Math.min(MAX_PLOT, Math.max(480, 440 + itemCount * 14) + transitionRoom) : clamp(width - 48, MIN_PLOT, MAX_PLOT);
|
|
383
386
|
const chipCap = Math.max(96, Math.min(CHIP_CAP, plotW / 2 - 44 - 8));
|
|
384
387
|
const chipOf = (label, cap, icon) => {
|
|
385
388
|
const lines = wrap(label, cap, bodyFont);
|
|
@@ -426,7 +429,8 @@ function layout(model, options = {}) {
|
|
|
426
429
|
}));
|
|
427
430
|
const confusionChipsH = confusionChips.reduce((sum, chip) => sum + chip.h + CHIP_GAP, -4);
|
|
428
431
|
const confusionBlockH = 24 + (model.showDomainDescriptions ? SUB_PITCH : 0) + (confusionChips.length ? ITEM_GAP + confusionChipsH : 0);
|
|
429
|
-
const
|
|
432
|
+
const chipHalfWidth = Math.max(0, ...confusionChips.map((chip) => chip.w)) / 2;
|
|
433
|
+
const rx = Math.max(plotW * .15, Math.ceil(chipHalfWidth * (compact ? 1.5 : 1)) + 18);
|
|
430
434
|
const requiredRy = confusionBlockH * .68 + 12;
|
|
431
435
|
const plotH = Math.ceil(Math.max(clamp(plotW * .72, 380, 620), 2 * (PANEL_PAD + maxBlockH + CORRIDOR), 2 * (requiredRy + CORRIDOR)));
|
|
432
436
|
const ry = Math.max(plotH * .15, requiredRy);
|
|
@@ -447,7 +451,7 @@ function layout(model, options = {}) {
|
|
|
447
451
|
h: panelH
|
|
448
452
|
};
|
|
449
453
|
const block = blocks[name];
|
|
450
|
-
const blockX = panel.x + (panel.w - block.w) / 2;
|
|
454
|
+
const blockX = panel.x + (panel.w - block.w) / 2 + (compact && confusionChips.length ? col === 0 ? -12 : 12 : 0);
|
|
451
455
|
const blockY = row === 0 ? panel.y + PANEL_PAD : panel.y + panel.h - PANEL_PAD - bottomBlockH;
|
|
452
456
|
const texts = [];
|
|
453
457
|
let cursor = blockY;
|
|
@@ -536,13 +540,49 @@ function layout(model, options = {}) {
|
|
|
536
540
|
const lines = wrap(transition.label, Math.max(96, Math.min(LABEL_CAP, plotW - 80)), bodyFont);
|
|
537
541
|
const w = widest(lines, bodyFont) + 16;
|
|
538
542
|
const h = lines.length * LABEL_LINE + 6;
|
|
543
|
+
const x = clamp(arc.apex.x + arc.nx * arc.away * 16 - w / 2, 30, plotX + plotW - 6 - w);
|
|
544
|
+
const y = clamp(arc.apex.y + arc.ny * arc.away * 16 - h / 2, plotY + 6, plotY + plotH - 6 - h);
|
|
539
545
|
label = {
|
|
540
546
|
lines,
|
|
541
|
-
x
|
|
542
|
-
y
|
|
547
|
+
x,
|
|
548
|
+
y,
|
|
543
549
|
w,
|
|
544
550
|
h
|
|
545
551
|
};
|
|
552
|
+
if (compact) {
|
|
553
|
+
const blockers = [...QUADRANTS.map((name) => quadrants[name].content), ...arcs.map((item) => item.label).filter(Boolean)];
|
|
554
|
+
const clear = (px, py) => {
|
|
555
|
+
const dx = Math.max(px - centre.x, centre.x - px - w, 0);
|
|
556
|
+
const dy = Math.max(py - centre.y, centre.y - py - h, 0);
|
|
557
|
+
return (dx / rx) ** 2 + (dy / ry) ** 2 > 1 && !blockers.some((b) => px < b.x + b.w + 4 && px + w + 4 > b.x && py < b.y + b.h + 4 && py + h + 4 > b.y);
|
|
558
|
+
};
|
|
559
|
+
if (!clear(x, y)) outer: for (const step of [
|
|
560
|
+
12,
|
|
561
|
+
24,
|
|
562
|
+
36,
|
|
563
|
+
48
|
|
564
|
+
]) for (const [dx, dy] of [
|
|
565
|
+
[0, 1],
|
|
566
|
+
[0, -1],
|
|
567
|
+
[1, 0],
|
|
568
|
+
[-1, 0],
|
|
569
|
+
[1, 1],
|
|
570
|
+
[-1, 1],
|
|
571
|
+
[1, -1],
|
|
572
|
+
[-1, -1]
|
|
573
|
+
]) {
|
|
574
|
+
const px = clamp(x + dx * step, 30, plotX + plotW - 6 - w);
|
|
575
|
+
const py = clamp(y + dy * step, plotY + 6, plotY + plotH - 6 - h);
|
|
576
|
+
if (clear(px, py)) {
|
|
577
|
+
label = {
|
|
578
|
+
...label,
|
|
579
|
+
x: px,
|
|
580
|
+
y: py
|
|
581
|
+
};
|
|
582
|
+
break outer;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
546
586
|
}
|
|
547
587
|
arcs.push({
|
|
548
588
|
...transition,
|
|
@@ -563,11 +603,16 @@ function layout(model, options = {}) {
|
|
|
563
603
|
return {
|
|
564
604
|
width: planWidth,
|
|
565
605
|
height: planHeight,
|
|
606
|
+
compact,
|
|
566
607
|
title: titleLines.length ? {
|
|
567
608
|
lines: titleLines,
|
|
568
609
|
x: plotX + plotW / 2,
|
|
569
610
|
top: 34
|
|
570
611
|
} : null,
|
|
612
|
+
...options.embedHeading ? {
|
|
613
|
+
embedHeading: true,
|
|
614
|
+
heading: model.title
|
|
615
|
+
} : {},
|
|
571
616
|
plot: {
|
|
572
617
|
x: plotX,
|
|
573
618
|
y: plotY,
|
|
@@ -726,14 +771,15 @@ function scene(plan, ctx) {
|
|
|
726
771
|
}
|
|
727
772
|
});
|
|
728
773
|
}
|
|
729
|
-
if (plan.title) plan.title.lines.forEach((line, index) => children.push(label(line, {
|
|
730
|
-
size: FONT.title.size,
|
|
774
|
+
if (!plan.embedHeading && plan.title) plan.title.lines.forEach((line, index) => children.push(label(line, {
|
|
775
|
+
size: plan.compact ? 13 : FONT.title.size,
|
|
731
776
|
weight: FONT.title.weight
|
|
732
777
|
}, ink.fg1, plan.title.x, plan.title.top + index * TITLE_LINE)));
|
|
733
778
|
return {
|
|
734
779
|
width: plan.width,
|
|
735
780
|
height: plan.height,
|
|
736
781
|
title: plan.title ? plan.title.lines.join(" ") : void 0,
|
|
782
|
+
...plan.embedHeading ? { heading: plan.heading } : {},
|
|
737
783
|
children,
|
|
738
784
|
anchor: plan.anchor
|
|
739
785
|
};
|
|
@@ -680,7 +680,7 @@ function layout(model, options = {}, info = {}) {
|
|
|
680
680
|
return tracks.length ? LANE_GAP + depth * TRACK : gap < rows.length - 1 ? LANE_GAP : 0;
|
|
681
681
|
});
|
|
682
682
|
const { title, titleIcon } = model;
|
|
683
|
-
const titleLines = title || titleIcon ? wrapText(title, laneRightX - pad - (titleIcon ? 20 : 0), FONT.title, measure) : [];
|
|
683
|
+
const titleLines = !options.embedHeading && (title || titleIcon) ? wrapText(title, laneRightX - pad - (titleIcon ? 20 : 0), FONT.title, measure) : [];
|
|
684
684
|
let cursor = pad + titleLines.length * 20;
|
|
685
685
|
rows.forEach((lane, index) => {
|
|
686
686
|
lane.y = cursor;
|
|
@@ -812,7 +812,8 @@ function layout(model, options = {}, info = {}) {
|
|
|
812
812
|
title,
|
|
813
813
|
titleIcon,
|
|
814
814
|
titleLines,
|
|
815
|
-
pad
|
|
815
|
+
pad,
|
|
816
|
+
...options.embedHeading ? { heading: title } : {}
|
|
816
817
|
};
|
|
817
818
|
}
|
|
818
819
|
function scene(geometry, ctx) {
|
|
@@ -935,6 +936,7 @@ function scene(geometry, ctx) {
|
|
|
935
936
|
width: geometry.width,
|
|
936
937
|
height: geometry.height,
|
|
937
938
|
title: geometry.title,
|
|
939
|
+
...geometry.heading ? { heading: geometry.heading } : {},
|
|
938
940
|
children
|
|
939
941
|
};
|
|
940
942
|
}
|
|
@@ -66,6 +66,7 @@ function parse(body, info) {
|
|
|
66
66
|
};
|
|
67
67
|
const directives = /* @__PURE__ */ new Map(), excludes = /* @__PURE__ */ new Set(), includes = /* @__PURE__ */ new Set();
|
|
68
68
|
const issue = (line, zh, en, fixZh = "修正甘特图语句", fixEn = "Correct the Gantt statement") => errors.push(error(lang, line, zh, en, fixZh, fixEn));
|
|
69
|
+
const gluedTasks = (line) => issue(line, "此行看起来写了两个任务", "This looks like two tasks on one line", "每个任务各写一行", "Put each task on its own line");
|
|
69
70
|
const notice = (line, zh, en) => errors.push(warning("DIAGRAM_HINT", lang, line, zh, en));
|
|
70
71
|
if (info.params || Object.keys(info.options || {}).length) issue(info.headerLine, "gantt 标题行不接受选项", "The gantt header takes no options");
|
|
71
72
|
if (body.length > 2e5) {
|
|
@@ -124,7 +125,11 @@ function parse(body, info) {
|
|
|
124
125
|
const caption = label(stripClasses(text.slice(0, colon)).trim(), line);
|
|
125
126
|
const fields = text.slice(colon + 1).replace(/((?:\s*:::[\w-]+)+)\s*$/, stripClasses).trim().split(",").map((x) => x.trim()), tags = [];
|
|
126
127
|
while (Object.hasOwn(flags, fields[0]?.toLowerCase())) tags.push(fields.shift().toLowerCase());
|
|
127
|
-
if (fields.length > 3
|
|
128
|
+
if (fields.length > 3) {
|
|
129
|
+
gluedTasks(line);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (fields.some((x) => !x) || !fields.length) {
|
|
128
133
|
issue(line, "任务需要结束值,可在前面加起点和 ID", "Expected end, start/end, or ID/start/end");
|
|
129
134
|
continue;
|
|
130
135
|
}
|
|
@@ -191,6 +196,18 @@ function parse(body, info) {
|
|
|
191
196
|
model,
|
|
192
197
|
errors
|
|
193
198
|
};
|
|
199
|
+
for (const task of items) if ([
|
|
200
|
+
task.id,
|
|
201
|
+
task.startField,
|
|
202
|
+
task.endField
|
|
203
|
+
].some((field, i) => {
|
|
204
|
+
const value = field?.split("%%", 1)[0].trim();
|
|
205
|
+
return value?.includes(":") && (i === 0 || !valid(date.parse(value)));
|
|
206
|
+
})) gluedTasks(task.line);
|
|
207
|
+
if (errors.some(blocking)) return {
|
|
208
|
+
model,
|
|
209
|
+
errors
|
|
210
|
+
};
|
|
194
211
|
model.excluded = excludes.size ? excludedBy({
|
|
195
212
|
includes,
|
|
196
213
|
excludes,
|
|
@@ -313,16 +330,21 @@ function compactRows(items, { bounds, caption, markerXs, left, width }) {
|
|
|
313
330
|
}
|
|
314
331
|
return rows;
|
|
315
332
|
}
|
|
316
|
-
function layout(model, { width, ctx, measure, renderOptions }) {
|
|
333
|
+
function layout(model, { width, ctx, measure, renderOptions, compact: compactOption, embedHeading }) {
|
|
317
334
|
const { design: d, lang } = ctx, { items, sections, today } = model;
|
|
318
|
-
const
|
|
319
|
-
const
|
|
335
|
+
const compact = compactOption === true;
|
|
336
|
+
const compactRowsMode = model.compact || compact;
|
|
337
|
+
const errors = [], children = [], title = model.title, naked = !renderOptions?.frame && !embedHeading && title;
|
|
338
|
+
const body = FONT.body, small = FONT.label, titleFont = compact ? {
|
|
339
|
+
...FONT.title,
|
|
340
|
+
size: 13
|
|
341
|
+
} : FONT.title, bold = {
|
|
320
342
|
...body,
|
|
321
343
|
weight: 600
|
|
322
344
|
};
|
|
323
345
|
const texts = (value) => value.split("\n");
|
|
324
346
|
const states = (item) => item.flags.map((flag) => flags[flag][isEn(lang) ? 1 : 0]).join(" · ");
|
|
325
|
-
const labelW = Math.max(
|
|
347
|
+
const labelW = Math.max(compactRowsMode ? 32 : 120, ...compactRowsMode ? [] : items.flatMap((item) => [maxWidthOf(texts(item.name), body, measure) + iconSlot(item.icon), measure(states(item), small)]), ...sections.map((s) => maxWidthOf(texts(s.name), bold, measure) + iconSlot(s.icon)));
|
|
326
348
|
const addShape = (tag, attrs, meta, link) => {
|
|
327
349
|
const mark = {
|
|
328
350
|
...ctx.el(tag, attrs),
|
|
@@ -380,7 +402,7 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
380
402
|
});
|
|
381
403
|
}
|
|
382
404
|
});
|
|
383
|
-
let plot = Math.max(228, width - left - 60);
|
|
405
|
+
let plot = compact ? Math.max(220, Math.min(560, 220 + Math.ceil((end - min) / (30 * DAY)) * 14)) : Math.max(228, width - left - 60);
|
|
384
406
|
const ratio = (stamp) => (stamp - min) / (max - min);
|
|
385
407
|
for (let i = 1; i < tickList.length; i++) {
|
|
386
408
|
const a = tickList[i - 1], b = tickList[i];
|
|
@@ -393,14 +415,14 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
393
415
|
right: x(stamp) + w / 2
|
|
394
416
|
});
|
|
395
417
|
const right = Math.max(30, ...tickList.map((t) => t.w / 2 + 14));
|
|
396
|
-
let w = Math.max(width, Math.ceil(left + plot + right));
|
|
418
|
+
let w = compact ? Math.ceil(left + plot + right) : Math.max(width, Math.ceil(left + plot + right));
|
|
397
419
|
const markers = items.filter((item) => item.flags.includes("vert"));
|
|
398
420
|
const showToday = valid(today) && items.length && today >= min && today <= end;
|
|
399
421
|
const markerStamp = (marker) => marker.today ? today : marker.startTime + (marker.endTime - marker.startTime) / 2;
|
|
400
422
|
const markerXs = [...markers.map((marker) => x(markerStamp(marker))), ...showToday ? [x(today)] : []].sort((a, b) => a - b);
|
|
401
423
|
const markBounds = (item) => item.flags.includes("milestone") ? [x(markerStamp(item)) - 9, x(markerStamp(item)) + 9] : [x(item.startTime), Math.max(x(item.startTime) + 4, x(item.endTime))];
|
|
402
|
-
const
|
|
403
|
-
if (
|
|
424
|
+
const compactBySection = /* @__PURE__ */ new Map();
|
|
425
|
+
if (compactRowsMode) for (const section of sections) {
|
|
404
426
|
const rows = compactRows(section.items.filter((item) => !item.flags.includes("vert")), {
|
|
405
427
|
bounds: markBounds,
|
|
406
428
|
markerXs,
|
|
@@ -415,12 +437,12 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
415
437
|
};
|
|
416
438
|
}
|
|
417
439
|
});
|
|
418
|
-
|
|
440
|
+
compactBySection.set(section, rows);
|
|
419
441
|
for (const row of rows) for (const entry of row) w = Math.max(w, Math.ceil(entry.hi + 14));
|
|
420
442
|
}
|
|
421
|
-
const titleLines = naked ? wrapText(title, w - 48 - iconSlot(model.titleIcon),
|
|
443
|
+
const titleLines = naked ? wrapText(title, w - 48 - iconSlot(model.titleIcon), titleFont, measure) : [];
|
|
422
444
|
if (titleLines.length) drawIcon(model.titleIcon, 24, 24);
|
|
423
|
-
titleLines.forEach((value, i) => text(value, 24 + iconSlot(model.titleIcon), 24 + i * 20,
|
|
445
|
+
titleLines.forEach((value, i) => text(value, 24 + iconSlot(model.titleIcon), 24 + i * 20, titleFont));
|
|
424
446
|
let y = titleLines.length ? 24 + titleLines.length * 20 : 24;
|
|
425
447
|
if (model.topAxis) y += 22;
|
|
426
448
|
const markerY = y, markerInfo = [];
|
|
@@ -450,7 +472,7 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
450
472
|
if (!section.name && !section.icon && !section.items.length) continue;
|
|
451
473
|
const top = y, names = section.name || section.icon ? texts(section.name) : [];
|
|
452
474
|
if (names.length) y += 14 + 18 * names.length;
|
|
453
|
-
if (
|
|
475
|
+
if (compactRowsMode) for (const row of compactBySection.get(section)) {
|
|
454
476
|
const rowH = Math.max(48, ...row.map(({ label, inside }) => inside && label.state ? 58 : (label.names.length + Number(Boolean(label.state))) * 18 + 20));
|
|
455
477
|
for (const entry of row) {
|
|
456
478
|
const middle = y + rowH / 2;
|
|
@@ -534,7 +556,7 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
534
556
|
if (marker.link) children.push(ctx.link(marker.link.href, parts, marker.link));
|
|
535
557
|
else children.push(...parts);
|
|
536
558
|
const markerX = x(stamp);
|
|
537
|
-
if (!
|
|
559
|
+
if (!compactRowsMode) line(markerX, top, bottom, color, true);
|
|
538
560
|
else {
|
|
539
561
|
const gaps = bars.filter(({ caption }) => markerX > caption.x - 3 && markerX < caption.x + caption.label.w + 3);
|
|
540
562
|
let from = top;
|
|
@@ -631,7 +653,7 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
631
653
|
height,
|
|
632
654
|
title,
|
|
633
655
|
children,
|
|
634
|
-
...renderOptions?.frame ? { heading: title || void 0 } : {}
|
|
656
|
+
...renderOptions?.frame || embedHeading ? { heading: title || void 0 } : {}
|
|
635
657
|
};
|
|
636
658
|
return {
|
|
637
659
|
width: w,
|
|
@@ -241,21 +241,42 @@ function roundedRoute(points) {
|
|
|
241
241
|
}
|
|
242
242
|
return `${d} L${points.at(-1).join(" ")}`;
|
|
243
243
|
}
|
|
244
|
-
function layout(model, { ctx, width, renderOptions }, info = {}) {
|
|
244
|
+
function layout(model, { ctx, width, renderOptions, compact, embedHeading }, info = {}) {
|
|
245
245
|
const { title, commits, branches, direction, config } = model, t = appearance(ctx);
|
|
246
246
|
const vertical = direction !== "LR", reverse = direction === "BT";
|
|
247
247
|
const showBranches = config.showBranches !== false, showLabels = config.showCommitLabel !== false;
|
|
248
248
|
const pad = Math.max(12, Math.min(60, Number(config.diagramPadding) || 18));
|
|
249
|
-
const titleInline = title && !renderOptions?.frame, heading = titleInline ? Math.max(30, Math.min(100, Number(config.titleTopMargin) || 30)) : 0;
|
|
249
|
+
const titleInline = title && !renderOptions?.frame && !embedHeading, heading = titleInline ? Math.max(30, Math.min(100, Number(config.titleTopMargin) || 30)) : 0;
|
|
250
250
|
const W = (lines) => Math.max(0, ...lines.map((s) => ctx.measure(s, FONT.label.size)));
|
|
251
251
|
const laneOf = new Map(branches.map(({ name }, i) => [name, i]));
|
|
252
252
|
const branchNames = branches.map(({ label }) => ctx.wrap(label, 128, FONT.label.size));
|
|
253
253
|
const branchW = showBranches ? Math.max(...branchNames.map(W)) + 20 : 0;
|
|
254
254
|
const branchH = showBranches ? Math.max(...branchNames.map((lines) => lines.length)) * 16 + 10 : 0;
|
|
255
|
+
const wrapCommit = (text) => {
|
|
256
|
+
const limit = 130, size = FONT.label.size;
|
|
257
|
+
const fallback = () => ctx.wrap(text, limit, size);
|
|
258
|
+
if (!/\p{Script=Han}/u.test(text)) return fallback();
|
|
259
|
+
const lines = [];
|
|
260
|
+
for (const paragraph of text.split("\n")) {
|
|
261
|
+
let line = "";
|
|
262
|
+
for (const part of paragraph.split(/(?<=[,.:;!?,。;:!?、])|(?=\s)/u)) {
|
|
263
|
+
const word = part.trim();
|
|
264
|
+
if (!word) continue;
|
|
265
|
+
if (ctx.measure(word, size) > limit) return fallback();
|
|
266
|
+
const next = line + (line && /^\s/u.test(part) ? " " : "") + word;
|
|
267
|
+
if (ctx.measure(next, size) > limit) {
|
|
268
|
+
lines.push(line);
|
|
269
|
+
line = word;
|
|
270
|
+
} else line = next;
|
|
271
|
+
}
|
|
272
|
+
lines.push(line);
|
|
273
|
+
}
|
|
274
|
+
return lines;
|
|
275
|
+
};
|
|
255
276
|
const slots = [];
|
|
256
277
|
const nodes = commits.map((c) => {
|
|
257
|
-
const label = showLabels ?
|
|
258
|
-
const msg = c.msg ?
|
|
278
|
+
const label = showLabels ? wrapCommit(c.id ? c.label : !c.merge && c.cherryOf == null ? `${c.seq + 1}` : "").filter(Boolean) : [];
|
|
279
|
+
const msg = c.msg ? wrapCommit(c.msg) : [];
|
|
259
280
|
const tags = c.tags.map((tag) => ctx.wrap(tag, 130, FONT.label.size));
|
|
260
281
|
const slot = config.parallelCommits ? Math.max(-1, ...c.parents.map((p) => slots[p])) + 1 : c.seq;
|
|
261
282
|
slots.push(slot);
|
|
@@ -318,7 +339,7 @@ function layout(model, { ctx, width, renderOptions }, info = {}) {
|
|
|
318
339
|
});
|
|
319
340
|
}
|
|
320
341
|
const breadth = pos + (vertical ? pad : Math.max(0, pad - 12));
|
|
321
|
-
const w = Math.max(width, vertical ? breadth : timeline), height = heading + (vertical ? timeline : breadth);
|
|
342
|
+
const w = Math.max(compact ? 0 : width, vertical ? breadth : timeline), height = heading + (vertical ? timeline : breadth);
|
|
322
343
|
const offset = (w - (vertical ? breadth : timeline)) / 2;
|
|
323
344
|
const coords = (u, v) => vertical ? [offset + v, heading + (reverse ? timeline - u : u)] : [offset + u, heading + v];
|
|
324
345
|
const centered = {
|
|
@@ -149,7 +149,8 @@ function arrangeGraph(source, options, info, allowCompact = true, hints = null)
|
|
|
149
149
|
};
|
|
150
150
|
const all = [...nodes, ...model.subgraphs];
|
|
151
151
|
const occupied = new Set(all.map((item) => item.parent));
|
|
152
|
-
const
|
|
152
|
+
const mixedStages = model.variant !== "agentflow" && model.subgraphs.filter((frame) => !frame.parent).length >= 2 && !edges.some((edge) => edge.fromFrame || edge.toFrame);
|
|
153
|
+
const compact = allowCompact && model.type === "flowchart" && nodes.length > 0 && (mixedStages || nodes.every((item) => item.parent != null));
|
|
153
154
|
const flowConfig = Object.entries(info.config ?? {}).find(([key]) => key.toLowerCase() === "flowchart")?.[1];
|
|
154
155
|
const inheritDir = Object.entries(flowConfig ?? {}).some(([key, value]) => key.toLowerCase() === "inheritdir" && value === true);
|
|
155
156
|
const projected = /* @__PURE__ */ new Map();
|
|
@@ -253,6 +254,42 @@ function arrangeGraph(source, options, info, allowCompact = true, hints = null)
|
|
|
253
254
|
subgraphs: model.subgraphs.filter((frame) => !hidden.has(frame.id) && !proxy(frame.id)),
|
|
254
255
|
edges: outerEdges
|
|
255
256
|
}, options);
|
|
257
|
+
if (compact && mixedStages && outerEdges.length && outerEdges.every((edge) => redirects.has(edge.seq))) {
|
|
258
|
+
const axis = horizontal ? "y" : "x", span = horizontal ? "h" : "w";
|
|
259
|
+
const cross = horizontal ? "x" : "y", size = horizontal ? "w" : "h";
|
|
260
|
+
const ordered = [...outer.nodes].sort((a, b) => a[axis] - b[axis]);
|
|
261
|
+
const links = new Map(ordered.map((node) => [node.id, /* @__PURE__ */ new Set()]));
|
|
262
|
+
for (const edge of outerEdges) links.get(edge.from)?.add(edge.to);
|
|
263
|
+
const reverse = model.direction === "BT" || model.direction === "RL";
|
|
264
|
+
if (ordered.length > 1 && ordered.slice(1).every((node, i) => {
|
|
265
|
+
const before = ordered[i];
|
|
266
|
+
return node[axis] >= before[axis] + before[span] && (reverse ? links.get(node.id).has(before.id) : links.get(before.id).has(node.id));
|
|
267
|
+
})) {
|
|
268
|
+
const middle = (horizontal ? outer.width : outer.height) / 2;
|
|
269
|
+
for (const [i, node] of ordered.entries()) {
|
|
270
|
+
let center = middle;
|
|
271
|
+
if (!blocks.has(node.id) && (i === 0 || i === ordered.length - 1)) {
|
|
272
|
+
const incident = outerEdges.filter((edge) => edge.from === node.id || edge.to === node.id);
|
|
273
|
+
const block = blocks.get(ordered[i === 0 ? 1 : i - 1].id);
|
|
274
|
+
if (block && incident.length === 1) {
|
|
275
|
+
const original = redirects.get(incident[0].seq);
|
|
276
|
+
const member = block.inner.nodes.find((item) => item.id === (original.from === node.id ? original.to : original.from));
|
|
277
|
+
if (member) {
|
|
278
|
+
const aligned = middle - (horizontal ? block.inner.width / 2 : block.h / 2 - block.titleBand) + member[cross] + member[size] / 2;
|
|
279
|
+
const limit = MARGIN + node[size] / 2;
|
|
280
|
+
if (aligned >= limit && aligned <= 2 * middle - limit) center = aligned;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const at = center - node[size] / 2, delta = at - node[cross];
|
|
285
|
+
node[cross] = at;
|
|
286
|
+
if (!horizontal && !blocks.has(node.id)) {
|
|
287
|
+
node.titleY += delta;
|
|
288
|
+
if (node.descY != null) node.descY += delta;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
256
293
|
const retained = [];
|
|
257
294
|
for (const node of outer.nodes) {
|
|
258
295
|
const block = blocks.get(node.id);
|
|
@@ -643,7 +680,7 @@ function layoutCore(model, { measure = fallbackMeasure, lang, ctx, renderOptions
|
|
|
643
680
|
const rank = new Map(realItems.map((item) => [item, 0]));
|
|
644
681
|
for (const item of topo) for (const le of out.get(item)) rank.set(le.toItem, Math.max(rank.get(le.toItem), rank.get(item) + le.minlen));
|
|
645
682
|
const LABELLED_RANK_WEIGHT = 2;
|
|
646
|
-
const edgeRankWeight = (le) => le.edge.label ? LABELLED_RANK_WEIGHT : 1;
|
|
683
|
+
const edgeRankWeight = (le) => (le.edge.label ? LABELLED_RANK_WEIGHT : 1) * (model.type === "flowchart" && model.variant !== "agentflow" && le.fromItem.cluster !== root && le.fromItem.cluster === le.toItem.cluster ? 2 : 1);
|
|
647
684
|
/** 加权中位数;累计权重正好落在中点时取两侧值的平均,等权时即普通中位数;调用方再四舍五入为整数层号。 */
|
|
648
685
|
const weightedRankMedian = (entries) => {
|
|
649
686
|
if (!entries.length) return 0;
|