@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
|
@@ -136,7 +136,7 @@ function parse(body, info) {
|
|
|
136
136
|
errors
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
function layout(model, { width, ctx, measure, renderOptions }) {
|
|
139
|
+
function layout(model, { width, ctx, measure, renderOptions, compact, embedHeading }) {
|
|
140
140
|
const { design: d } = ctx, { items, config, sections } = model;
|
|
141
141
|
const vertical = model.direction === "TD";
|
|
142
142
|
const finite = (value, fallback, floor) => Number.isFinite(Number(value)) ? Math.max(floor, Number(value)) : fallback;
|
|
@@ -150,15 +150,15 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
150
150
|
};
|
|
151
151
|
const lh = body.size + 5, iconSize = 16, iconGap = 6;
|
|
152
152
|
const occupied = sections.reduce((n, s) => n + (s.name || s.icon || s.items.length ? Math.max(1, s.items.length) : 0), 0);
|
|
153
|
-
const col = vertical ? Math.max(184, pad * 2 + 100) : Math.max(184, pad * 2 + 100, (width - left - 24) / occupied);
|
|
154
|
-
const eventW = vertical ? Math.max(204, width - left - col - 76, pad * 2 + 100) : col - 2 * pad - 14;
|
|
153
|
+
const col = vertical ? Math.max(184, pad * 2 + 100) : Math.max(184, pad * 2 + 100, compact ? 0 : (width - left - 24) / occupied);
|
|
154
|
+
const eventW = vertical ? Math.max(204, compact ? 0 : width - left - col - 76, pad * 2 + 100) : col - 2 * pad - 14;
|
|
155
155
|
const w = vertical ? left + col + eventW + 76 : left + col * occupied + 24;
|
|
156
156
|
const children = [], scene = {
|
|
157
157
|
width: w,
|
|
158
158
|
height: 0,
|
|
159
159
|
title: model.title,
|
|
160
160
|
children,
|
|
161
|
-
...renderOptions?.frame ? { heading: model.title || void 0 } : {}
|
|
161
|
+
...renderOptions?.frame || embedHeading ? { heading: model.title || void 0 } : {}
|
|
162
162
|
};
|
|
163
163
|
const add = (tag, attrs, meta) => children.push({
|
|
164
164
|
...ctx.el(tag, attrs),
|
|
@@ -209,7 +209,7 @@ function layout(model, { width, ctx, measure, renderOptions }) {
|
|
|
209
209
|
};
|
|
210
210
|
const boxColor = (status, fallback) => status && d[status] || fallback;
|
|
211
211
|
const titleSlot = model.titleIcon ? 22 : 0;
|
|
212
|
-
const title = !renderOptions?.frame && (model.title || model.titleIcon) ? wrap(model.title, w - 48 - titleSlot, FONT.title) : [];
|
|
212
|
+
const title = !renderOptions?.frame && !embedHeading && (model.title || model.titleIcon) ? wrap(model.title, w - 48 - titleSlot, FONT.title) : [];
|
|
213
213
|
if (title.length && model.titleIcon) children.push(drawIcon(model.titleIcon, 32, 24, d.fg1));
|
|
214
214
|
lines(title, 24 + titleSlot, 24, FONT.title, d.fg1, "start", 20);
|
|
215
215
|
const top = title.length ? 24 + title.length * 20 : 24;
|
|
@@ -149,7 +149,7 @@ function parse(body, { firstLine = 2, headerLine = 1, lang, params, config }) {
|
|
|
149
149
|
errors: [...errors, ...look.diagnostics()]
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
|
-
function layout(model, { width, measure, lang }) {
|
|
152
|
+
function layout(model, { width, measure, lang, embedHeading }) {
|
|
153
153
|
const available = Math.max(120, width - 48);
|
|
154
154
|
const { settings } = model;
|
|
155
155
|
const step = clamp(clamp(settings.rowIndent, 10, 4, 90) + clamp(settings.paddingX, 14, 4, 24), STEP, 12, 96);
|
|
@@ -187,7 +187,7 @@ function layout(model, { width, measure, lang }) {
|
|
|
187
187
|
}
|
|
188
188
|
const noteWidth = Math.max(0, ...rows.map((row) => maxWidthOf(row.notes, FONT.label, measure)));
|
|
189
189
|
const inline = !noteWidth || end + 16 + noteWidth + MARGIN <= width + 240;
|
|
190
|
-
const title = model.title ? wrapText(model.title, available, FONT.title, measure) : [];
|
|
190
|
+
const title = !embedHeading && model.title ? wrapText(model.title, available, FONT.title, measure) : [];
|
|
191
191
|
let y = MARGIN + (title.length ? title.length * 19 + 12 : 0);
|
|
192
192
|
let right = Math.max(end, MARGIN + maxWidthOf(title, FONT.title, measure));
|
|
193
193
|
for (const row of rows) {
|
|
@@ -206,6 +206,7 @@ function layout(model, { width, measure, lang }) {
|
|
|
206
206
|
return {
|
|
207
207
|
rows,
|
|
208
208
|
title,
|
|
209
|
+
...embedHeading ? { heading: model.title } : {},
|
|
209
210
|
width: naturalWidth,
|
|
210
211
|
height: y + MARGIN,
|
|
211
212
|
right,
|
|
@@ -279,7 +280,8 @@ function scene(plan, ctx) {
|
|
|
279
280
|
return {
|
|
280
281
|
width: plan.width,
|
|
281
282
|
height: plan.height,
|
|
282
|
-
children: [...edges, ...labels]
|
|
283
|
+
children: [...edges, ...labels],
|
|
284
|
+
...plan.heading ? { heading: plan.heading } : {}
|
|
283
285
|
};
|
|
284
286
|
}
|
|
285
287
|
var implementations = { "treeView-beta": {
|
package/dist/esm/diagram/venn.js
CHANGED
|
@@ -596,11 +596,17 @@ function layoutBlock(region) {
|
|
|
596
596
|
y: itemTop + (index + .5) * ITEM_LINE
|
|
597
597
|
}));
|
|
598
598
|
}
|
|
599
|
-
function planRings(model, { measure, width, lang }) {
|
|
600
|
-
const available = Math.max(240, width - 48);
|
|
599
|
+
function planRings(model, { measure, width, lang, compact, embedHeading }) {
|
|
600
|
+
const available = compact ? 560 : Math.max(240, width - 48);
|
|
601
601
|
const preferred = canonicalSpread(model.sets, 1);
|
|
602
602
|
const unit = boundsOf(ringsAt(model.sets, 1, preferred));
|
|
603
|
-
|
|
603
|
+
const maxLabel = Math.max(0, ...[
|
|
604
|
+
...model.sets.map((set) => set.label || set.id),
|
|
605
|
+
...model.unions.map((union) => union.label),
|
|
606
|
+
...model.texts.map((text) => text.label)
|
|
607
|
+
].map((label) => measure(label, SET_FONT)));
|
|
608
|
+
const preferredPlotWidth = Math.min(520, 260 + Math.min(100, (model.unions.length + model.texts.length) * 8) + Math.min(80, Math.max(0, model.sets.length - 2) * 30) + Math.min(80, maxLabel * .25));
|
|
609
|
+
let R = compact ? Math.max(56, Math.min(preferredPlotWidth / Math.max(1, unit.w), 320 / Math.max(1, unit.h))) : Math.max(56, Math.min(available / Math.max(1, unit.w), PLOT_H / Math.max(1, unit.h)));
|
|
604
610
|
const regions = regionList(ringsAt(model.sets, R, preferred), model);
|
|
605
611
|
let chosen = null;
|
|
606
612
|
for (let pass = 0; pass <= MAX_GROWTH; pass += 1) {
|
|
@@ -658,10 +664,12 @@ function planRings(model, { measure, width, lang }) {
|
|
|
658
664
|
notes
|
|
659
665
|
}, model, {
|
|
660
666
|
measure,
|
|
661
|
-
width
|
|
667
|
+
width,
|
|
668
|
+
compact,
|
|
669
|
+
embedHeading
|
|
662
670
|
});
|
|
663
671
|
}
|
|
664
|
-
function planGrid(model, { measure, width, lang }) {
|
|
672
|
+
function planGrid(model, { measure, width, lang, compact, embedHeading }) {
|
|
665
673
|
const groups = /* @__PURE__ */ new Map();
|
|
666
674
|
for (const text of model.texts) {
|
|
667
675
|
const list = groups.get(text.key) || [];
|
|
@@ -739,9 +747,9 @@ function planGrid(model, { measure, width, lang }) {
|
|
|
739
747
|
panel.h = 28 + panel.header.length * HEAD_LINE + (panel.captionLines.length ? 4 + panel.captionLines.length * ITEM_LINE : 0) + (panel.itemLines.length ? 6 + panel.itemLines.length * ITEM_LINE : 0);
|
|
740
748
|
}
|
|
741
749
|
const cellW = Math.max(...panels.map((panel) => panel.w));
|
|
742
|
-
const available = Math.max(240, width - 48);
|
|
750
|
+
const available = compact ? 520 : Math.max(240, width - 48);
|
|
743
751
|
let cols = Math.min(GRID_COLS, panels.length);
|
|
744
|
-
while (cols > 1 && cols * cellW + (cols - 1) * GRID_GAP > available * 2) cols -= 1;
|
|
752
|
+
if (!compact) while (cols > 1 && cols * cellW + (cols - 1) * GRID_GAP > available * 2) cols -= 1;
|
|
745
753
|
const rowCount = Math.ceil(panels.length / cols);
|
|
746
754
|
const rowHeights = [];
|
|
747
755
|
panels.forEach((panel, index) => {
|
|
@@ -811,12 +819,14 @@ function planGrid(model, { measure, width, lang }) {
|
|
|
811
819
|
notes
|
|
812
820
|
}, model, {
|
|
813
821
|
measure,
|
|
814
|
-
width
|
|
822
|
+
width,
|
|
823
|
+
compact,
|
|
824
|
+
embedHeading
|
|
815
825
|
});
|
|
816
826
|
}
|
|
817
|
-
function finish(plan, model, { measure, width }) {
|
|
818
|
-
const titleLines = model.title ? wrapText(model.title, Math.max(160, Math.min(width - 48, 480)), TITLE_FONT, (piece, spec) => measure(piece, spec)) : [];
|
|
819
|
-
const titleH = titleLines.length ? titleLines.length * TITLE_LINE + TITLE_GAP : 0;
|
|
827
|
+
function finish(plan, model, { measure, width, compact, embedHeading }) {
|
|
828
|
+
const titleLines = model.title ? wrapText(model.title, compact ? 480 : Math.max(160, Math.min(width - 48, 480)), TITLE_FONT, (piece, spec) => measure(piece, spec)) : [];
|
|
829
|
+
const titleH = !embedHeading && titleLines.length ? titleLines.length * TITLE_LINE + TITLE_GAP : 0;
|
|
820
830
|
const shelf = [];
|
|
821
831
|
let shelfRight = plan.plot.x + plan.plot.w;
|
|
822
832
|
let shelfBottom = plan.plot.y + plan.plot.h;
|
|
@@ -862,7 +872,7 @@ function finish(plan, model, { measure, width }) {
|
|
|
862
872
|
}
|
|
863
873
|
}
|
|
864
874
|
const spanW = Math.max(plan.plot.x + plan.plot.w, shelfRight) - plan.plot.x;
|
|
865
|
-
const contentW = Math.max(spanW, ...titleLines.map((row) => measure(row, TITLE_FONT)));
|
|
875
|
+
const contentW = Math.max(spanW, ...(embedHeading ? [] : titleLines).map((row) => measure(row, TITLE_FONT)));
|
|
866
876
|
const dx = MARGIN + (contentW - spanW) / 2 - plan.plot.x;
|
|
867
877
|
const dy = MARGIN + titleH - plan.plot.y;
|
|
868
878
|
const height = Math.ceil(shelfBottom - plan.plot.y + titleH + 48);
|
|
@@ -906,6 +916,10 @@ function finish(plan, model, { measure, width }) {
|
|
|
906
916
|
x: MARGIN + contentW / 2,
|
|
907
917
|
top: 34
|
|
908
918
|
} : null,
|
|
919
|
+
...embedHeading ? {
|
|
920
|
+
embedHeading,
|
|
921
|
+
heading: model.title
|
|
922
|
+
} : {},
|
|
909
923
|
rings: plan.rings || [],
|
|
910
924
|
regions: plan.regions || [],
|
|
911
925
|
panels: plan.panels || [],
|
|
@@ -922,6 +936,7 @@ function layout(model, options = {}) {
|
|
|
922
936
|
const measure = options.measure || fallbackMeasure;
|
|
923
937
|
const width = Math.max(1, Number(options.width) || 800);
|
|
924
938
|
const lang = options.lang || "zh";
|
|
939
|
+
const compact = options.compact === true, { embedHeading } = options;
|
|
925
940
|
if (!model.sets.length) return {
|
|
926
941
|
width,
|
|
927
942
|
height: 0,
|
|
@@ -930,11 +945,15 @@ function layout(model, options = {}) {
|
|
|
930
945
|
const plan = model.sets.length <= RING_MAX ? planRings(model, {
|
|
931
946
|
measure,
|
|
932
947
|
width,
|
|
933
|
-
lang
|
|
948
|
+
lang,
|
|
949
|
+
compact,
|
|
950
|
+
embedHeading
|
|
934
951
|
}) : planGrid(model, {
|
|
935
952
|
measure,
|
|
936
953
|
width,
|
|
937
|
-
lang
|
|
954
|
+
lang,
|
|
955
|
+
compact,
|
|
956
|
+
embedHeading
|
|
938
957
|
});
|
|
939
958
|
const errors = [...plan.notes];
|
|
940
959
|
const parts = model.sets.length + model.unions.length + model.texts.length;
|
|
@@ -1014,7 +1033,7 @@ function scene(plan, ctx) {
|
|
|
1014
1033
|
}));
|
|
1015
1034
|
for (const item of panel.rows) children.push(row(item));
|
|
1016
1035
|
}
|
|
1017
|
-
if (plan.title) plan.title.lines.forEach((line, index) => children.push(ctx.text(plan.title.x, plan.title.top + index * TITLE_LINE, line, {
|
|
1036
|
+
if (!plan.embedHeading && plan.title) plan.title.lines.forEach((line, index) => children.push(ctx.text(plan.title.x, plan.title.top + index * TITLE_LINE, line, {
|
|
1018
1037
|
anchor: "middle",
|
|
1019
1038
|
size: TITLE_FONT.size,
|
|
1020
1039
|
weight: TITLE_FONT.weight,
|
|
@@ -1025,6 +1044,7 @@ function scene(plan, ctx) {
|
|
|
1025
1044
|
width: plan.width,
|
|
1026
1045
|
height: plan.height,
|
|
1027
1046
|
title: plan.title ? plan.title.lines.join(" ") : void 0,
|
|
1047
|
+
...plan.embedHeading ? { heading: plan.heading } : {},
|
|
1028
1048
|
children,
|
|
1029
1049
|
anchor: plan.anchor
|
|
1030
1050
|
};
|
|
@@ -70,15 +70,15 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
70
70
|
const normalize = mapLabels(lang, (item) => errors.push(item));
|
|
71
71
|
const readLabel = (value, line) => normalize(readName(value), line);
|
|
72
72
|
if (title) ({text: model.title, icon: model.titleIcon} = normalize(title, headerLine));
|
|
73
|
-
const bad = (line, zh, en) => errors.push(error(lang, line, zh, en,
|
|
74
|
-
const hint = (key, line, zh, en) => {
|
|
73
|
+
const bad = (line, zh, en, fixZh, fixEn) => errors.push(error(lang, line, zh, en, fixZh, fixEn));
|
|
74
|
+
const hint = (key, line, zh, en, fixZh, fixEn) => {
|
|
75
75
|
if (hints.has(key)) return;
|
|
76
76
|
hints.add(key);
|
|
77
|
-
errors.push(warning("DIAGRAM_HINT", lang, line, zh, en));
|
|
77
|
+
errors.push(warning("DIAGRAM_HINT", lang, line, zh, en, fixZh, fixEn));
|
|
78
78
|
};
|
|
79
79
|
const percent = (raw, line) => {
|
|
80
80
|
const value = Number(raw);
|
|
81
|
-
if (value > 100) bad(line, "坐标超出 0–100 范围", "Coordinate is outside 0–100");
|
|
81
|
+
if (value > 100) bad(line, "坐标超出 0–100 范围", "Coordinate is outside 0–100", "使用 0.0–1.0 的比例或 0.0–100.0 的百分数,例如 0.3", "Use a decimal fraction from 0.0 to 1.0 or a percentage up to 100.0, such as 0.3");
|
|
82
82
|
return value <= 1 ? value * 100 : value;
|
|
83
83
|
};
|
|
84
84
|
const coords = (v, e, line) => ({
|
|
@@ -92,14 +92,14 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
92
92
|
const add = (node) => {
|
|
93
93
|
const previous = nodes.get(node.id);
|
|
94
94
|
if (previous) {
|
|
95
|
-
if (previous.visibility !== node.visibility || previous.evolution !== node.evolution) bad(node.line, `「${node.id}」有不同的坐标`, `Conflicting coordinates for "${node.id}"
|
|
95
|
+
if (previous.visibility !== node.visibility || previous.evolution !== node.evolution) bad(node.line, `「${node.id}」有不同的坐标`, `Conflicting coordinates for "${node.id}"`, "保留一处声明,或给不同的节点使用不同的名称", "Keep one declaration or give distinct nodes different names");
|
|
96
96
|
return;
|
|
97
97
|
}
|
|
98
98
|
nodes.set(node.id, node);
|
|
99
99
|
model.nodes.push(node);
|
|
100
100
|
};
|
|
101
101
|
if (body.length > 2e5) {
|
|
102
|
-
bad(firstLine, "地图源文本过长", "Map source exceeds 200,000 characters");
|
|
102
|
+
bad(firstLine, "地图源文本过长", "Map source exceeds 200,000 characters", "拆成多张地图,每张最多 200,000 个字符", "Split into maps of at most 200,000 characters each");
|
|
103
103
|
return {
|
|
104
104
|
model,
|
|
105
105
|
errors
|
|
@@ -114,7 +114,7 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
114
114
|
let m;
|
|
115
115
|
if (pipeline) {
|
|
116
116
|
if (text === "}") {
|
|
117
|
-
if (!pipeline.children.length) bad(line, "演进管道没有组件", "Pipeline needs at least one component");
|
|
117
|
+
if (!pipeline.children.length) bad(line, "演进管道没有组件", "Pipeline needs at least one component", "在 } 前添加组件,例如 component Child [0.4]", "Add a component before }, for example component Child [0.4]");
|
|
118
118
|
pipeline = null;
|
|
119
119
|
} else if (m = childPattern.exec(text)) {
|
|
120
120
|
const [, name, evo, dx, dy] = m, { text: label, icon } = readLabel(name, line);
|
|
@@ -129,7 +129,7 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
129
129
|
parent: pipeline.parent,
|
|
130
130
|
line
|
|
131
131
|
});
|
|
132
|
-
} else bad(line, "无效的演进管道组件", "Invalid pipeline component");
|
|
132
|
+
} else bad(line, "无效的演进管道组件", "Invalid pipeline component", "管道内只填写演进坐标,例如 component Child [0.4]", "Use one evolution coordinate inside a pipeline, as in component Child [0.4]");
|
|
133
133
|
continue;
|
|
134
134
|
}
|
|
135
135
|
if (accessibility) {
|
|
@@ -145,13 +145,13 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
145
145
|
width: Number(m[1]),
|
|
146
146
|
height: Number(m[2])
|
|
147
147
|
};
|
|
148
|
-
if (Object.values(model.size).some((n) => n > 16e3)) bad(line, "地图尺寸超过 16000 像素", "Map size exceeds 16,000 pixels");
|
|
148
|
+
if (Object.values(model.size).some((n) => n > 16e3)) bad(line, "地图尺寸超过 16000 像素", "Map size exceeds 16,000 pixels", "减小 size [宽, 高],两项均不得超过 16000", "Reduce both dimensions in size [width, height] to at most 16000");
|
|
149
149
|
} else if (text.startsWith("evolution ")) {
|
|
150
150
|
const parts = text.slice(10).match(/"(?:\\.|[^"\\])*"|->|[^"-]+|-/g) || [];
|
|
151
151
|
const stages = [""];
|
|
152
152
|
for (const part of parts) part === "->" ? stages.push("") : stages[stages.length - 1] += part;
|
|
153
153
|
const matches = stages.map((stage) => stagePattern.exec(stage.trim()));
|
|
154
|
-
if (matches.length < 2 || matches.some((match) => !match)) bad(line, "无效的演进阶段", "Invalid evolution stages");
|
|
154
|
+
if (matches.length < 2 || matches.some((match) => !match)) bad(line, "无效的演进阶段", "Invalid evolution stages", "用 -> 分隔至少两个阶段,例如 evolution Genesis -> Product", "Separate at least two stages with ->, as in evolution Genesis -> Product");
|
|
155
155
|
else {
|
|
156
156
|
model.stages = matches.map(([, name, end, second]) => {
|
|
157
157
|
const primary = readLabel(name, line), secondary = second ? readLabel(second, line) : null;
|
|
@@ -165,14 +165,14 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
165
165
|
});
|
|
166
166
|
const ends = model.stages.map((stage) => stage.boundary);
|
|
167
167
|
if (ends.some((end) => end !== null) && (ends.some((end, i) => end === null || end <= (ends[i - 1] ?? 0)) || ends.at(-1) !== 100)) {
|
|
168
|
-
hint("stages", line, "阶段边界不完整或未递增至 100;使用等宽阶段", "Incomplete or unordered stage boundaries; using equal bands");
|
|
168
|
+
hint("stages", line, "阶段边界不完整或未递增至 100;使用等宽阶段", "Incomplete or unordered stage boundaries; using equal bands", "为每个阶段写递增边界,例如 evolution Genesis @ 0.4 -> Product @ 1.0", "Give each stage an increasing boundary, as in evolution Genesis @ 0.4 -> Product @ 1.0");
|
|
169
169
|
for (const stage of model.stages) stage.boundary = null;
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
} else if (m = nodePattern.exec(text)) {
|
|
173
173
|
const [, kind, name, vis, evo, dx, dy, strategy, inertia] = m;
|
|
174
174
|
const { text: label, icon } = readLabel(name, line), point = coords(vis, evo, line);
|
|
175
|
-
if (kind !== "component" && (dx != null || strategy || inertia) || kind === "note" && !name.startsWith("\"")) bad(line, "无效的装饰或备注", "Invalid decorator or note");
|
|
175
|
+
if (kind !== "component" && (dx != null || strategy || inertia) || kind === "note" && !name.startsWith("\"")) bad(line, "无效的装饰或备注", "Invalid decorator or note", "只给 component 添加装饰;备注使用 note \"文字\" [0.3, 0.2]", "Apply decorators only to component; write notes as note \"Text\" [0.3, 0.2]");
|
|
176
176
|
else if (kind === "note") model.notes.push({
|
|
177
177
|
text: label,
|
|
178
178
|
icon,
|
|
@@ -216,7 +216,7 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
216
216
|
line
|
|
217
217
|
});
|
|
218
218
|
else if (m = boxPattern.exec(text)) {
|
|
219
|
-
if (model.annotationBox) hint("box", line, "只使用第一个注释框", "Only the first annotation box is used");
|
|
219
|
+
if (model.annotationBox) hint("box", line, "只使用第一个注释框", "Only the first annotation box is used", "只保留一条 annotations [x, y] 语句", "Keep only one annotations [x, y] statement");
|
|
220
220
|
else model.annotationBox = coords(m[1], m[2], line);
|
|
221
221
|
} else if ((m = linkPattern.exec(text)) && (m[2] || m[3] || m[7] || m[8] || m[1].startsWith("\"") || m[6].startsWith("\""))) {
|
|
222
222
|
const [, from, sourcePort, arrow, flowLabel, arrowPort, to, targetPort, label] = m;
|
|
@@ -240,10 +240,10 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
240
240
|
line
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
|
-
if (pipeline) bad(pipeline.line, "演进管道缺少结束括号", "Unclosed pipeline");
|
|
243
|
+
if (pipeline) bad(pipeline.line, "演进管道缺少结束括号", "Unclosed pipeline", "在管道的最后一个组件之后单独写一行 }", "Add } on its own line after the last pipeline component");
|
|
244
244
|
for (const group of model.pipelines) {
|
|
245
245
|
const parent = nodes.get(group.parent);
|
|
246
|
-
if (parent?.kind !== "component") bad(group.line, `管道父级「${group.parent}」不是组件`, `Pipeline parent "${group.parent}" is not a component
|
|
246
|
+
if (parent?.kind !== "component") bad(group.line, `管道父级「${group.parent}」不是组件`, `Pipeline parent "${group.parent}" is not a component`, "先声明同名 component,例如 component Parent [0.3, 0.2]", "Declare a component with the same name, as in component Parent [0.3, 0.2]");
|
|
247
247
|
else for (const child of group.children) add({
|
|
248
248
|
...child,
|
|
249
249
|
visibility: parent.visibility
|
|
@@ -269,19 +269,20 @@ function parse(body, { lang, firstLine = 2, title = "", headerLine = 1 } = {}) {
|
|
|
269
269
|
label: "",
|
|
270
270
|
line
|
|
271
271
|
});
|
|
272
|
-
else bad(line, "无法识别 Wardley 地图语句", "Unrecognized Wardley map statement");
|
|
272
|
+
else bad(line, "无法识别 Wardley 地图语句", "Unrecognized Wardley map statement", "用 component \"需求\" [0.3, 0.2] 声明组件;连线使用 \"需求\" --> \"网关\",名称外不要加方括号", "Declare components as component \"Demand\" [0.3, 0.2]; link them as \"Demand\" --> \"Gateway\" without square brackets around names");
|
|
273
273
|
}
|
|
274
274
|
model.links.sort((a, b) => a.line - b.line);
|
|
275
275
|
for (const link of model.links) {
|
|
276
276
|
link.from = resolve(link.from);
|
|
277
277
|
link.to = resolve(link.to);
|
|
278
|
-
|
|
278
|
+
const missing = [link.from, link.to].find((id) => !nodes.has(id));
|
|
279
|
+
if (missing !== void 0) bad(link.line, `依赖引用未定义的节点「${missing}」`, `Dependency references undefined node "${missing}"`, "声明同名组件,例如 component Gateway [0.4, 0.3],或更正连线端点名称", "Declare a matching component, as in component Gateway [0.4, 0.3], or correct the endpoint name");
|
|
279
280
|
}
|
|
280
281
|
for (const trend of model.trends) {
|
|
281
282
|
trend.nodeId = resolve(trend.nodeId);
|
|
282
|
-
if (!nodes.has(trend.nodeId)) hint("trend", trend.line, "演进引用未定义的组件", "Evolution references an undefined component");
|
|
283
|
+
if (!nodes.has(trend.nodeId)) hint("trend", trend.line, "演进引用未定义的组件", "Evolution references an undefined component", "将 evolve 后的名称改为已声明的组件,例如 evolve Gateway 0.7", "Use a declared component name after evolve, as in evolve Gateway 0.7");
|
|
283
284
|
}
|
|
284
|
-
if (model.nodes.length > 300 || model.links.length + model.trends.length > 600) bad(firstLine, "地图超过 300 个节点或 600 条连线,请拆分", "Split maps
|
|
285
|
+
if (model.nodes.length > 300 || model.links.length + model.trends.length > 600) bad(firstLine, "地图超过 300 个节点或 600 条连线,请拆分", "Map exceeds 300 nodes or 600 connections", "按主题拆分地图,每张最多 300 个节点、600 条连线", "Split the map by topic into maps of at most 300 nodes and 600 connections");
|
|
285
286
|
return {
|
|
286
287
|
model,
|
|
287
288
|
errors
|
|
@@ -344,8 +345,12 @@ var arrowhead = (ctx, a, b, fill) => {
|
|
|
344
345
|
const p = move(b, a, 7), dx = p.y - b.y, dy = b.x - p.x;
|
|
345
346
|
return ctx.path(`M${b.x} ${b.y} L${p.x + dx * .48} ${p.y + dy * .48} L${p.x - dx * .48} ${p.y - dy * .48} Z`, { fill });
|
|
346
347
|
};
|
|
347
|
-
function layout(model, { width, lang, ctx }, info = {}) {
|
|
348
|
+
function layout(model, { width, lang, ctx, compact = false, embedHeading }, info = {}) {
|
|
348
349
|
const t = appearance(ctx), edge = ctx.color("muted"), grid = ctx.color("grid"), axis = t.fg4;
|
|
350
|
+
const titleFont = compact ? {
|
|
351
|
+
...FONT.title,
|
|
352
|
+
size: 13
|
|
353
|
+
} : FONT.title;
|
|
349
354
|
const config = mapConfig(info.config, "wardley");
|
|
350
355
|
const pad = 48;
|
|
351
356
|
const stageParts = model.stages.map((stage) => [{
|
|
@@ -364,7 +369,8 @@ function layout(model, { width, lang, ctx }, info = {}) {
|
|
|
364
369
|
const bandFraction = (i) => fractions[i] - (fractions[i - 1] || 0);
|
|
365
370
|
const stageWidth = Math.max(...stageParts.map((rows, i) => (Math.max(...rows.map(stageInkWidth)) + 22) / bandFraction(i)));
|
|
366
371
|
const dimension = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, Math.min(16e3, value)) : fallback;
|
|
367
|
-
const
|
|
372
|
+
const compactWidth = Math.max(96 + stageWidth, Math.min(720, 540 + model.nodes.length * 4 + model.links.length * 2));
|
|
373
|
+
const W = compact ? compactWidth : Math.max(96 + stageWidth, 420, dimension(model.size?.width ?? mapConfig(config, "width"), 900));
|
|
368
374
|
const right = W - pad, plotW = right - pad;
|
|
369
375
|
const stages = stageParts.map((parts, i) => {
|
|
370
376
|
if (parts.length !== 2 || model.stages[i].secondName === null || [model.stages[i].name, model.stages[i].secondName].some((text) => text.includes("\n"))) return parts;
|
|
@@ -374,10 +380,11 @@ function layout(model, { width, lang, ctx }, info = {}) {
|
|
|
374
380
|
};
|
|
375
381
|
return stageInkWidth(together) + 22 <= plotW * bandFraction(i) ? [together] : parts;
|
|
376
382
|
});
|
|
377
|
-
const titleRows = model.title || model.titleIcon ? ctx.wrap(model.title, plotW - iconGap(model.titleIcon),
|
|
383
|
+
const titleRows = !embedHeading && (model.title || model.titleIcon) ? ctx.wrap(model.title, plotW - iconGap(model.titleIcon), titleFont.size, titleFont.weight) : [];
|
|
378
384
|
const top = 48 + Math.max(0, titleRows.length - 1) * 16;
|
|
379
385
|
const stagesExtra = Math.max(0, ...stages.map((rows) => rows.length - 2)) * 16;
|
|
380
|
-
const
|
|
386
|
+
const compactHeight = Math.max(top + 212 + stagesExtra, Math.min(540, 400 + model.nodes.length * 2 + model.links.length));
|
|
387
|
+
const H = compact ? compactHeight : Math.max(top + 212 + stagesExtra, dimension(model.size?.height ?? mapConfig(config, "height"), 600));
|
|
381
388
|
const bottom = H - 86 - stagesExtra, plotH = bottom - top;
|
|
382
389
|
const project = ({ evolution, visibility }) => ({
|
|
383
390
|
x: pad + plotW * evolution / 100,
|
|
@@ -547,7 +554,34 @@ function layout(model, { width, lang, ctx }, info = {}) {
|
|
|
547
554
|
const b = grow(centerBox(x, y, w, h), clearance);
|
|
548
555
|
return b.x > 31 && b.x + b.w < W - 8 && b.y > top - 20 && b.y + b.h < bottom + 9 && !obstacles.some((o) => collides(b, o)) && !occupied.some((o) => collides(b, o)) && !wires.some(([a, z]) => crosses(a, z, b));
|
|
549
556
|
};
|
|
550
|
-
let chosen = fixed
|
|
557
|
+
let chosen = fixed && compact && (() => {
|
|
558
|
+
const offsets = [
|
|
559
|
+
[0, 0],
|
|
560
|
+
[0, -1],
|
|
561
|
+
[1, 0],
|
|
562
|
+
[-1, 0],
|
|
563
|
+
[0, 1],
|
|
564
|
+
[1, -1],
|
|
565
|
+
[-1, -1],
|
|
566
|
+
[1, 1],
|
|
567
|
+
[-1, 1]
|
|
568
|
+
];
|
|
569
|
+
const alternatives = [fixed];
|
|
570
|
+
for (const distance of [
|
|
571
|
+
12,
|
|
572
|
+
24,
|
|
573
|
+
36,
|
|
574
|
+
52,
|
|
575
|
+
72
|
|
576
|
+
]) for (const [dx, dy] of offsets.slice(1)) alternatives.push({
|
|
577
|
+
x: fixed.x + dx * distance,
|
|
578
|
+
y: fixed.y + dy * distance
|
|
579
|
+
});
|
|
580
|
+
return alternatives.find(({ x, y }) => {
|
|
581
|
+
const b = grow(centerBox(x, y, w, h), clearance);
|
|
582
|
+
return b.x > 31 && b.x + b.w < W - 8 && b.y > top - 20 && b.y + b.h < bottom + 9 && !obstacles.some((o) => collides(b, o)) && !occupied.some((o) => collides(b, o));
|
|
583
|
+
});
|
|
584
|
+
})() || fixed || candidates.find(fits);
|
|
551
585
|
const leader = !fixed && chosen && leaderFor(chosen);
|
|
552
586
|
if (leader) addLeader(...leader);
|
|
553
587
|
if (!chosen) {
|
|
@@ -628,7 +662,7 @@ function layout(model, { width, lang, ctx }, info = {}) {
|
|
|
628
662
|
y: a.y
|
|
629
663
|
}, {}, true);
|
|
630
664
|
}
|
|
631
|
-
if (titleRows.length) guides.push(caption(W / 2, 23 + (titleRows.length - 1) * 8, titleRows, model.titleIcon,
|
|
665
|
+
if (titleRows.length) guides.push(caption(W / 2, 23 + (titleRows.length - 1) * 8, titleRows, model.titleIcon, titleFont));
|
|
632
666
|
guides.push(ctx.line(pad, top, pad, bottom, stroke(axis)), ctx.line(pad, bottom, right, bottom, stroke(axis)));
|
|
633
667
|
const axisMiddle = (top + bottom) / 2;
|
|
634
668
|
guides.push(ctx.el("g", { transform: `rotate(-90 18 ${axisMiddle})` }, [label(18, axisMiddle, [word(lang, "visibility")], bold, t.fg2)]));
|
|
@@ -812,12 +846,13 @@ function layout(model, { width, lang, ctx }, info = {}) {
|
|
|
812
846
|
labels.push(label(pad, footerY + rows.length * 8, rows, FONT.label, t.fg2, "start"));
|
|
813
847
|
footerY += rows.length * 16 + 8;
|
|
814
848
|
}
|
|
815
|
-
const errors = W > width * 2 || nodes.size > 60 ? [warning("LARGE_DIAGRAM", lang, info.headerLine || 1, "
|
|
849
|
+
const errors = W > width * 2 || nodes.size > 60 ? [warning("LARGE_DIAGRAM", lang, info.headerLine || 1, "地图较大,可在图框内滚动", "Large map; scroll inside the frame", "按主题拆分组件及其依赖", "Split components and their dependencies into maps by topic")] : [];
|
|
816
850
|
return {
|
|
817
851
|
scene: {
|
|
818
852
|
width: W,
|
|
819
853
|
height: footerY + 8,
|
|
820
854
|
title: model.title || void 0,
|
|
855
|
+
...embedHeading ? { heading: model.title } : {},
|
|
821
856
|
children: [
|
|
822
857
|
...guides,
|
|
823
858
|
...frames,
|