@x-cmd/draw 0.4.7 → 0.5.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/README.md +3 -3
- package/dist/client.d.ts +42 -0
- package/dist/client.js +267 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +132 -0
- package/dist/globe.d.ts +4 -0
- package/dist/globe.js +6 -0
- package/dist/layout/cluster.d.ts +2 -0
- package/dist/layout/cluster.js +228 -0
- package/dist/layout/index.d.ts +2 -0
- package/dist/layout/index.js +6 -0
- package/dist/layout/layered.d.ts +51 -0
- package/dist/layout/layered.js +433 -0
- package/dist/layout/portsize.d.ts +18 -0
- package/dist/layout/portsize.js +34 -0
- package/dist/lib.d.ts +17 -4
- package/dist/lib.js +20 -4
- package/dist/node/cmd.d.ts +1 -0
- package/dist/node/cmd.js +3 -0
- package/dist/render/abc-parse.d.ts +75 -0
- package/dist/render/abc-parse.js +345 -0
- package/dist/render/abcjs.d.ts +10 -0
- package/dist/render/abcjs.js +90 -0
- package/dist/render/anno.d.ts +48 -2
- package/dist/render/anno.js +171 -17
- package/dist/render/ansi.d.ts +15 -0
- package/dist/render/ansi.js +142 -0
- package/dist/render/arch.js +8 -3
- package/dist/render/arch3d.d.ts +31 -0
- package/dist/render/arch3d.js +294 -0
- package/dist/render/archmap.js +2 -2
- package/dist/render/area.js +42 -11
- package/dist/render/bar-grid.js +1 -1
- package/dist/render/bar-grouped.js +25 -7
- package/dist/render/bar-stacked.js +22 -6
- package/dist/render/bar.js +27 -6
- package/dist/render/block.d.ts +56 -0
- package/dist/render/block.js +361 -0
- package/dist/render/butterfly.js +4 -1
- package/dist/render/calendar.js +49 -14
- package/dist/render/center.d.ts +26 -0
- package/dist/render/center.js +108 -0
- package/dist/render/chem.d.ts +22 -0
- package/dist/render/chem.js +205 -0
- package/dist/render/chord.d.ts +17 -0
- package/dist/render/chord.js +141 -0
- package/dist/render/combo.js +7 -7
- package/dist/render/compass.js +59 -13
- package/dist/render/echarts-ssr.d.ts +36 -2
- package/dist/render/echarts-ssr.js +77 -18
- package/dist/render/gauge.js +17 -9
- package/dist/render/gitgraph.d.ts +53 -0
- package/dist/render/gitgraph.js +324 -0
- package/dist/render/globe-areas.d.ts +21 -0
- package/dist/render/globe-areas.js +40 -0
- package/dist/render/globe-earth.d.ts +78 -0
- package/dist/render/globe-earth.js +464 -0
- package/dist/render/globe-keys.d.ts +34 -0
- package/dist/render/globe-keys.js +71 -0
- package/dist/render/globe-proj.d.ts +102 -0
- package/dist/render/globe-proj.js +332 -0
- package/dist/render/globe-regions.d.ts +23 -0
- package/dist/render/globe-regions.js +60 -0
- package/dist/render/globe.d.ts +15 -0
- package/dist/render/globe.js +306 -0
- package/dist/render/globe3d.d.ts +113 -0
- package/dist/render/globe3d.js +285 -0
- package/dist/render/hbar-spec.js +23 -10
- package/dist/render/hbar.js +30 -11
- package/dist/render/jianpu.d.ts +10 -0
- package/dist/render/jianpu.js +190 -0
- package/dist/render/journey.d.ts +54 -0
- package/dist/render/journey.js +277 -0
- package/dist/render/kanban.d.ts +50 -0
- package/dist/render/kanban.js +240 -0
- package/dist/render/kinds.js +19 -0
- package/dist/render/line-multi.js +27 -8
- package/dist/render/line.js +32 -14
- package/dist/render/maps.js +4 -2
- package/dist/render/mermaid/block.d.ts +2 -0
- package/dist/render/mermaid/block.js +256 -0
- package/dist/render/mermaid/c4.d.ts +3 -0
- package/dist/render/mermaid/c4.js +165 -0
- package/dist/render/mermaid/class.d.ts +2 -0
- package/dist/render/mermaid/class.js +185 -0
- package/dist/render/mermaid/common.d.ts +34 -0
- package/dist/render/mermaid/common.js +81 -0
- package/dist/render/mermaid/erd.d.ts +2 -0
- package/dist/render/mermaid/erd.js +103 -0
- package/dist/render/mermaid/gitgraph.d.ts +2 -0
- package/dist/render/mermaid/gitgraph.js +139 -0
- package/dist/render/mermaid/journey.d.ts +7 -0
- package/dist/render/mermaid/journey.js +68 -0
- package/dist/render/mermaid/kanban.d.ts +2 -0
- package/dist/render/mermaid/kanban.js +86 -0
- package/dist/render/mermaid/mindmap.d.ts +7 -0
- package/dist/render/mermaid/mindmap.js +74 -0
- package/dist/render/mermaid/packet.d.ts +2 -0
- package/dist/render/mermaid/packet.js +35 -0
- package/dist/render/mermaid/pie.d.ts +7 -0
- package/dist/render/mermaid/pie.js +58 -0
- package/dist/render/mermaid/quadrant.d.ts +8 -0
- package/dist/render/mermaid/quadrant.js +137 -0
- package/dist/render/mermaid/radar.d.ts +8 -0
- package/dist/render/mermaid/radar.js +69 -0
- package/dist/render/mermaid/requirement.d.ts +2 -0
- package/dist/render/mermaid/requirement.js +100 -0
- package/dist/render/mermaid/sankey.d.ts +7 -0
- package/dist/render/mermaid/sankey.js +54 -0
- package/dist/render/mermaid/seq.d.ts +2 -0
- package/dist/render/mermaid/seq.js +147 -0
- package/dist/render/mermaid/state.d.ts +2 -0
- package/dist/render/mermaid/state.js +168 -0
- package/dist/render/mermaid/timeline.d.ts +7 -0
- package/dist/render/mermaid/timeline.js +63 -0
- package/dist/render/mermaid/xychart.d.ts +7 -0
- package/dist/render/mermaid/xychart.js +94 -0
- package/dist/render/mermaid.d.ts +22 -4
- package/dist/render/mermaid.js +173 -7
- package/dist/render/mindmap.js +12 -2
- package/dist/render/nomnoml.d.ts +8 -0
- package/dist/render/nomnoml.js +47 -0
- package/dist/render/packet.d.ts +39 -0
- package/dist/render/packet.js +232 -0
- package/dist/render/params-dispatch.d.ts +20 -0
- package/dist/render/params-dispatch.js +192 -0
- package/dist/render/pie.js +29 -22
- package/dist/render/quadrant.js +38 -9
- package/dist/render/query.d.ts +11 -1
- package/dist/render/query.js +92 -16
- package/dist/render/radar.js +7 -6
- package/dist/render/requirement.d.ts +61 -0
- package/dist/render/requirement.js +355 -0
- package/dist/render/sankey.js +4 -4
- package/dist/render/scatter.js +25 -9
- package/dist/render/scene3d.d.ts +188 -0
- package/dist/render/scene3d.js +433 -0
- package/dist/render/seq.js +13 -8
- package/dist/render/simplify.d.ts +12 -0
- package/dist/render/simplify.js +105 -0
- package/dist/render/source-theme.d.ts +104 -0
- package/dist/render/source-theme.js +261 -0
- package/dist/render/svg.d.ts +81 -1
- package/dist/render/svg.js +259 -2
- package/dist/render/svgdom.d.ts +74 -0
- package/dist/render/svgdom.js +198 -0
- package/dist/render/timeline.d.ts +54 -0
- package/dist/render/timeline.js +290 -0
- package/dist/render/tty.d.ts +17 -0
- package/dist/render/tty.js +173 -0
- package/dist/render/ttycmd.d.ts +7 -0
- package/dist/render/ttycmd.js +152 -0
- package/dist/render/vendor/au.js +1 -1
- package/dist/render/vendor/br.js +1 -1
- package/dist/render/vendor/china-counties.d.ts +32 -0
- package/dist/render/vendor/china-counties.js +8 -0
- package/dist/render/vendor/china-provinces.d.ts +16 -0
- package/dist/render/vendor/china-provinces.js +8 -0
- package/dist/render/vendor/china.js +1 -1
- package/dist/render/vendor/country-aliases.d.ts +207 -0
- package/dist/render/vendor/country-aliases.js +7 -0
- package/dist/render/vendor/de.js +1 -1
- package/dist/render/vendor/eu.js +1 -1
- package/dist/render/vendor/japan.js +1 -1
- package/dist/render/vendor/kr.js +1 -1
- package/dist/render/vendor/world-geo.js +1 -1
- package/dist/render/vendor/world-ne.d.ts +18 -0
- package/dist/render/vendor/world-ne.js +8 -0
- package/dist/render/vendor/world.js +1 -1
- package/dist/render/vexflow.d.ts +10 -0
- package/dist/render/vexflow.js +189 -0
- package/dist/render/wavedrom.d.ts +14 -0
- package/dist/render/wavedrom.js +113 -0
- package/dist/source.d.ts +20 -0
- package/dist/source.js +27 -0
- package/dist/specs/base.js +9 -4
- package/dist/specs/combo.d.ts +1 -0
- package/dist/specs/combo.js +8 -1
- package/dist/specs/gauge.d.ts +1 -0
- package/dist/specs/gauge.js +14 -2
- package/dist/specs/multi.d.ts +3 -0
- package/dist/specs/multi.js +29 -3
- package/dist/specs/quadrant.js +5 -4
- package/dist/specs/scatter.d.ts +1 -0
- package/dist/specs/scatter.js +7 -0
- package/dist/styles/bar.js +3 -0
- package/dist/styles/baseline.d.ts +47 -0
- package/dist/styles/baseline.js +48 -0
- package/dist/styles/hbar.js +3 -0
- package/dist/styles/index.d.ts +1 -1
- package/dist/styles/index.js +16 -4
- package/dist/styles/line.js +9 -0
- package/dist/styles/pie.js +4 -0
- package/dist/styles/sankey.js +4 -0
- package/dist/styles/skins.d.ts +23 -0
- package/dist/styles/skins.js +349 -0
- package/dist/styles/types.d.ts +20 -0
- package/dist/styles/types.js +17 -1
- package/dist/world-data.d.ts +12 -0
- package/dist/world-data.js +192 -0
- package/package.json +38 -5
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type VersionInfo } from '../version.js';
|
|
2
|
+
import { type Skin } from '../styles/index.js';
|
|
3
|
+
import { type DrawResult } from './query.js';
|
|
4
|
+
/** 一个任务:名字 + 满意度分数(1–5)+ 参与者 */
|
|
5
|
+
export interface JourneyTask {
|
|
6
|
+
name: string;
|
|
7
|
+
/** 满意度分数 1–5 */
|
|
8
|
+
score: number;
|
|
9
|
+
/** 参与者 */
|
|
10
|
+
actors: string[];
|
|
11
|
+
}
|
|
12
|
+
/** 一个段:名字 + 属于它的任务 */
|
|
13
|
+
export interface JourneySection {
|
|
14
|
+
name: string;
|
|
15
|
+
tasks: JourneyTask[];
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Journey data: a title, ordered sections, and the tasks inside each.
|
|
19
|
+
*/
|
|
20
|
+
export interface JourneySpec {
|
|
21
|
+
title?: string;
|
|
22
|
+
subtitle?: string;
|
|
23
|
+
sections: JourneySection[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Build a journey spec from flat URL params.
|
|
27
|
+
*
|
|
28
|
+
* `section=` declares the segments; `task=` attaches a task to one of them
|
|
29
|
+
* with a satisfaction score of 1–5 and an optional actor list.
|
|
30
|
+
*
|
|
31
|
+
* @throws ApiError(400) with a corrective example on bad input
|
|
32
|
+
*/
|
|
33
|
+
export declare function journeySpecFromParams(params: URLSearchParams): JourneySpec;
|
|
34
|
+
/**
|
|
35
|
+
* Parse a journey spec from JSON.
|
|
36
|
+
*
|
|
37
|
+
* @throws ApiError(400) with a corrective example on bad input
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseJourneySpec(raw: string): JourneySpec;
|
|
40
|
+
/**
|
|
41
|
+
* Render a journey diagram.
|
|
42
|
+
*/
|
|
43
|
+
export declare function renderJourney(spec: JourneySpec, o: {
|
|
44
|
+
v: VersionInfo;
|
|
45
|
+
skin: Skin;
|
|
46
|
+
interactive: boolean;
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
tagQuery?: string;
|
|
50
|
+
}): DrawResult;
|
|
51
|
+
/**
|
|
52
|
+
* `/draw/journey` entry: GET ?title=…§ion=…&task=…
|
|
53
|
+
*/
|
|
54
|
+
export declare function renderJourneyFromUrl(url: URL, interactive?: boolean): DrawResult;
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// /draw/journey —— 用户旅程:section 分段,每段一排任务(卡片)。
|
|
2
|
+
//
|
|
3
|
+
// 参数语法(扁平,可重复):
|
|
4
|
+
// title=… 图题
|
|
5
|
+
// subtitle=… 副标题
|
|
6
|
+
// section=<段名> 一个段(按出现顺序);可重复
|
|
7
|
+
// task=<段>|<任务>|<分数>|<参与者,…> 一个任务;可重复。
|
|
8
|
+
// 分数是 1–5 的整数;参与者用逗号分隔(可省)。
|
|
9
|
+
// 竖线是分隔符,字段里不能再写竖线。
|
|
10
|
+
// w= / h= 画布尺寸;t= 皮肤家族;scheme= 明暗;v= 版本
|
|
11
|
+
//
|
|
12
|
+
// 画法:每个 section 一行(行首是段名),行里一排任务卡;卡上写任务名,
|
|
13
|
+
// 分数画成一个圆点 —— 圆点的大小随分数变大(1 分最小、5 分最大),颜色取皮肤色板;
|
|
14
|
+
// 参与者列在卡底(小字、弱色)。
|
|
15
|
+
import { ApiError } from '../specs/index.js';
|
|
16
|
+
import { resolveVersion } from '../version.js';
|
|
17
|
+
import { resolveSkin } from '../styles/index.js';
|
|
18
|
+
import { card } from '../theme.js';
|
|
19
|
+
import { esc, r2, sVar, svgDoc, textW, titleBlock, subtitleBlock } from './svg.js';
|
|
20
|
+
import { clampInt, schemeParam } from './query.js';
|
|
21
|
+
const PAD = 26;
|
|
22
|
+
const SEC_W = 96; // 行首段名列宽(下限;实际按内容加宽)
|
|
23
|
+
const SEC_W_MAX = 168; // 行首段名列宽上限(名字太长就截断)
|
|
24
|
+
const CARD_H = 92; // 任务卡高
|
|
25
|
+
const CARD_W = 176; // 任务卡宽(基准)
|
|
26
|
+
const CARD_GAP = 16;
|
|
27
|
+
const SEC_GAP = 22; // 段与段之间
|
|
28
|
+
const NAME_FS = 13;
|
|
29
|
+
const ACTOR_FS = 11;
|
|
30
|
+
const SEC_FS = 13;
|
|
31
|
+
const JR_EXAMPLE = 'section=Go to work&task=Go to work|Make tea|5|Me&task=Go to work|Go upstairs|3|Me&task=Go to work|Do work|1|Me,Cat';
|
|
32
|
+
function bad(detail) {
|
|
33
|
+
throw new ApiError(400, `journey: ${detail}. Example: /draw/journey?${JR_EXAMPLE}`);
|
|
34
|
+
}
|
|
35
|
+
/** task= 的一段拆成四段(段|任务|分数|参与者)。 */
|
|
36
|
+
const splitTask = (raw) => {
|
|
37
|
+
const f = raw.split('|');
|
|
38
|
+
if (f.length < 3 || f.length > 4) {
|
|
39
|
+
bad(`"task" must be "section|task|score[|actors]". Got: ${JSON.stringify(raw)}`);
|
|
40
|
+
}
|
|
41
|
+
return [f[0].trim(), f[1].trim(), f[2].trim(), (f[3] ?? '').trim()];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Build a journey spec from flat URL params.
|
|
45
|
+
*
|
|
46
|
+
* `section=` declares the segments; `task=` attaches a task to one of them
|
|
47
|
+
* with a satisfaction score of 1–5 and an optional actor list.
|
|
48
|
+
*
|
|
49
|
+
* @throws ApiError(400) with a corrective example on bad input
|
|
50
|
+
*/
|
|
51
|
+
export function journeySpecFromParams(params) {
|
|
52
|
+
const spec = { sections: [] };
|
|
53
|
+
const title = params.get('title')?.trim();
|
|
54
|
+
const subtitle = params.get('subtitle')?.trim();
|
|
55
|
+
if (title)
|
|
56
|
+
spec.title = title;
|
|
57
|
+
if (subtitle)
|
|
58
|
+
spec.subtitle = subtitle;
|
|
59
|
+
const byName = new Map();
|
|
60
|
+
for (const name of params.getAll('section').map((s) => s.trim()).filter(Boolean)) {
|
|
61
|
+
if (byName.has(name))
|
|
62
|
+
bad(`duplicate section ${JSON.stringify(name)}`);
|
|
63
|
+
const sec = { name, tasks: [] };
|
|
64
|
+
byName.set(name, sec);
|
|
65
|
+
spec.sections.push(sec);
|
|
66
|
+
}
|
|
67
|
+
for (const raw of params.getAll('task')) {
|
|
68
|
+
const [secName, name, scoreRaw, actorsRaw] = splitTask(raw);
|
|
69
|
+
if (!name)
|
|
70
|
+
bad(`"task" needs a name. Got: ${JSON.stringify(raw)}`);
|
|
71
|
+
const sec = byName.get(secName);
|
|
72
|
+
if (!sec)
|
|
73
|
+
bad(`"task" refers to unknown section ${JSON.stringify(secName)}`);
|
|
74
|
+
const score = Number(scoreRaw);
|
|
75
|
+
if (!Number.isInteger(score) || score < 1 || score > 5) {
|
|
76
|
+
bad(`"task" score must be an integer 1-5. Got: ${JSON.stringify(scoreRaw)}`);
|
|
77
|
+
}
|
|
78
|
+
const actors = actorsRaw.split(',').map((a) => a.trim()).filter(Boolean);
|
|
79
|
+
sec.tasks.push({ name, score, actors });
|
|
80
|
+
}
|
|
81
|
+
if (!spec.sections.length)
|
|
82
|
+
bad(`at least one "section=" is required`);
|
|
83
|
+
if (!spec.sections.some((s) => s.tasks.length))
|
|
84
|
+
bad(`at least one "task=" is required`);
|
|
85
|
+
return spec;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Parse a journey spec from JSON.
|
|
89
|
+
*
|
|
90
|
+
* @throws ApiError(400) with a corrective example on bad input
|
|
91
|
+
*/
|
|
92
|
+
export function parseJourneySpec(raw) {
|
|
93
|
+
if (!raw.trim())
|
|
94
|
+
bad(`empty spec`);
|
|
95
|
+
let obj;
|
|
96
|
+
try {
|
|
97
|
+
obj = JSON.parse(raw);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
bad(`"d" is not valid JSON`);
|
|
101
|
+
}
|
|
102
|
+
const o = obj;
|
|
103
|
+
const spec = { sections: [] };
|
|
104
|
+
if (o.title !== undefined) {
|
|
105
|
+
if (typeof o.title !== 'string')
|
|
106
|
+
bad(`"title" must be a string`);
|
|
107
|
+
spec.title = o.title;
|
|
108
|
+
}
|
|
109
|
+
if (o.subtitle !== undefined) {
|
|
110
|
+
if (typeof o.subtitle !== 'string')
|
|
111
|
+
bad(`"subtitle" must be a string`);
|
|
112
|
+
spec.subtitle = o.subtitle;
|
|
113
|
+
}
|
|
114
|
+
const secs = o.sections;
|
|
115
|
+
if (!Array.isArray(secs) || !secs.length)
|
|
116
|
+
bad(`"sections" must be a non-empty array`);
|
|
117
|
+
for (const s of secs) {
|
|
118
|
+
if (typeof s !== 'object' || s === null)
|
|
119
|
+
bad(`each section must be an object`);
|
|
120
|
+
const r = s;
|
|
121
|
+
if (typeof r.name !== 'string' || !r.name.trim())
|
|
122
|
+
bad(`each section needs a "name"`);
|
|
123
|
+
const tasks = [];
|
|
124
|
+
if (r.tasks !== undefined) {
|
|
125
|
+
if (!Array.isArray(r.tasks))
|
|
126
|
+
bad(`section "${r.name}": "tasks" must be an array`);
|
|
127
|
+
for (const t of r.tasks) {
|
|
128
|
+
if (typeof t !== 'object' || t === null)
|
|
129
|
+
bad(`section "${r.name}": each task must be an object`);
|
|
130
|
+
const tr = t;
|
|
131
|
+
if (typeof tr.name !== 'string' || !tr.name.trim())
|
|
132
|
+
bad(`section "${r.name}": each task needs a "name"`);
|
|
133
|
+
const score = Number(tr.score);
|
|
134
|
+
if (!Number.isInteger(score) || score < 1 || score > 5) {
|
|
135
|
+
bad(`section "${r.name}": task score must be an integer 1-5 (got ${JSON.stringify(tr.score)})`);
|
|
136
|
+
}
|
|
137
|
+
let actors = [];
|
|
138
|
+
if (tr.actors !== undefined) {
|
|
139
|
+
if (!Array.isArray(tr.actors))
|
|
140
|
+
bad(`section "${r.name}": task "actors" must be an array`);
|
|
141
|
+
actors = tr.actors.map((a) => String(a).trim()).filter(Boolean);
|
|
142
|
+
}
|
|
143
|
+
tasks.push({ name: tr.name, score, actors });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
spec.sections.push({ name: r.name.trim(), tasks });
|
|
147
|
+
}
|
|
148
|
+
if (!spec.sections.some((s) => s.tasks.length))
|
|
149
|
+
bad(`at least one task is required`);
|
|
150
|
+
return spec;
|
|
151
|
+
}
|
|
152
|
+
/** 分数 → 圆点半径(1 分最小、5 分最大) */
|
|
153
|
+
const scoreR = (score) => 5 + (score - 1) * 2.6;
|
|
154
|
+
/**
|
|
155
|
+
* Render a journey diagram.
|
|
156
|
+
*/
|
|
157
|
+
export function renderJourney(spec, o) {
|
|
158
|
+
const nSeries = Math.max(1, o.skin.series.length);
|
|
159
|
+
const hasTitle = !!spec.title;
|
|
160
|
+
// 无标题也留 30px 角标带(Edit 胶囊在右上 y≈25–45,不留带会压住第一行卡片)
|
|
161
|
+
const titleH = hasTitle ? 40 : 30;
|
|
162
|
+
const subH = spec.subtitle ? 22 : 0;
|
|
163
|
+
// 每段一行;行里的任务数最多是多少 → 卡宽按最挤的那行定
|
|
164
|
+
const maxTasks = Math.max(1, ...spec.sections.map((s) => s.tasks.length));
|
|
165
|
+
// 卡宽:至少装得下最宽的任务名(分两行)
|
|
166
|
+
let cardW = CARD_W;
|
|
167
|
+
for (const s of spec.sections) {
|
|
168
|
+
for (const t of s.tasks) {
|
|
169
|
+
const w = textW(t.name, NAME_FS);
|
|
170
|
+
cardW = Math.max(cardW, Math.min(260, w + 32));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// 段名列宽:按内容加宽,但封顶(名字太长就截断,不然卡片被挤到画布外)
|
|
174
|
+
const secW = Math.min(SEC_W_MAX, Math.max(SEC_W, ...spec.sections.map((s) => textW(s.name, SEC_FS) + 24)));
|
|
175
|
+
const needW = PAD * 2 + secW + cardW * maxTasks + CARD_GAP * (maxTasks - 1);
|
|
176
|
+
const width = o.width !== undefined ? Math.max(200, Math.min(2400, o.width)) : Math.min(Math.max(needW, 560), 2400);
|
|
177
|
+
const rows = spec.sections.length;
|
|
178
|
+
const needH = titleH + subH + PAD + rows * (CARD_H + SEC_GAP) + PAD;
|
|
179
|
+
const height = o.height !== undefined ? Math.max(140, Math.min(2000, o.height)) : Math.min(Math.max(needH, 220), 2000);
|
|
180
|
+
const parts = [];
|
|
181
|
+
let y = titleH + subH + PAD;
|
|
182
|
+
spec.sections.forEach((sec, si) => {
|
|
183
|
+
const color = sVar(si % nSeries);
|
|
184
|
+
// 段名:行首一列,竖直居中于这行任务
|
|
185
|
+
const rowH = CARD_H;
|
|
186
|
+
// 段名太长就截断(段名列宽是固定的,不能让字爬到卡片上去)
|
|
187
|
+
let secName = sec.name;
|
|
188
|
+
const maxSecW = secW - 20;
|
|
189
|
+
if (textW(secName, SEC_FS) > maxSecW) {
|
|
190
|
+
while (secName.length > 1 && textW(secName + '…', SEC_FS) > maxSecW)
|
|
191
|
+
secName = secName.slice(0, -1);
|
|
192
|
+
secName += '…';
|
|
193
|
+
}
|
|
194
|
+
// 段色的小竖条(在段名左边,不压字)
|
|
195
|
+
parts.push(`<rect x="${PAD}" y="${r2(y + rowH / 2 - 18)}" width="4" height="36" rx="2" fill="${color}"/>`, `<text x="${r2(PAD + 12)}" y="${r2(y + rowH / 2 + SEC_FS / 3)}" font-size="${SEC_FS}" font-weight="600" fill="var(--d-ink)">${esc(secName)}</text>`,
|
|
196
|
+
// 段行底下的一条细线(到这一行末尾),把段和卡片分开
|
|
197
|
+
`<line x1="${PAD}" y1="${r2(y + rowH + 8)}" x2="${r2(width - PAD)}" y2="${r2(y + rowH + 8)}" stroke="var(--d-grid)" stroke-width="1"/>`);
|
|
198
|
+
sec.tasks.forEach((t, ti) => {
|
|
199
|
+
const cx = PAD + secW + ti * (cardW + CARD_GAP);
|
|
200
|
+
const tip = [t.name, `score ${t.score}/5`, ...t.actors].filter(Boolean).join(' · ');
|
|
201
|
+
const ia = o.interactive ? ` data-node="${esc(t.name)}" data-tip="${esc(tip)}" tabindex="0"` : '';
|
|
202
|
+
// 卡:白底 + 细边(与 gantt 的条不同,这里是「卡片」)
|
|
203
|
+
parts.push(`<rect x="${r2(cx)}" y="${r2(y)}" width="${r2(cardW)}" height="${CARD_H}" rx="10" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"${ia}/>`);
|
|
204
|
+
// 任务名(左对齐,超宽就截断);右边给分数圆点留一格
|
|
205
|
+
const dotR = 13;
|
|
206
|
+
const maxNameW = cardW - 28 - dotR * 2 - 12;
|
|
207
|
+
let name = t.name;
|
|
208
|
+
if (textW(name, NAME_FS) > maxNameW) {
|
|
209
|
+
while (name.length > 1 && textW(name + '…', NAME_FS) > maxNameW)
|
|
210
|
+
name = name.slice(0, -1);
|
|
211
|
+
name += '…';
|
|
212
|
+
}
|
|
213
|
+
parts.push(`<text x="${r2(cx + 14)}" y="${r2(y + 26)}" font-size="${NAME_FS}" font-weight="600" fill="var(--d-ink)"${ia}>${esc(name)}</text>`);
|
|
214
|
+
// 分数圆点:大小随分数;颜色取皮肤色板(不硬编码红绿)
|
|
215
|
+
const r = scoreR(t.score);
|
|
216
|
+
const dotCx = cx + cardW - 14 - dotR;
|
|
217
|
+
const dotCy = y + 26;
|
|
218
|
+
// 底圈:把 1–5 的量程画出来(灰底),点落在量程上
|
|
219
|
+
parts.push(`<circle cx="${r2(dotCx)}" cy="${r2(dotCy)}" r="${dotR}" fill="none" stroke="var(--d-grid)" stroke-width="1"/>`);
|
|
220
|
+
parts.push(`<circle cx="${r2(dotCx)}" cy="${r2(dotCy)}" r="${r2(r)}" fill="${color}"${ia}/>`);
|
|
221
|
+
// 分数数字:圆点下面一行(贴着卡右边,不越出卡)
|
|
222
|
+
parts.push(`<text x="${r2(dotCx)}" y="${r2(y + 26 + dotR + 14)}" text-anchor="middle" font-size="11" fill="var(--d-muted)">${t.score}/5</text>`);
|
|
223
|
+
// 参与者:卡底一行(小字、弱色),多个用「·」隔开
|
|
224
|
+
if (t.actors.length) {
|
|
225
|
+
const actors = t.actors.join(' · ');
|
|
226
|
+
parts.push(`<text x="${r2(cx + 14)}" y="${r2(y + CARD_H - 16)}" font-size="${ACTOR_FS}" fill="var(--d-muted)">${esc(actors)}</text>`);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
y += CARD_H + SEC_GAP;
|
|
230
|
+
});
|
|
231
|
+
const titleSvg = titleBlock(spec.title, PAD) + subtitleBlock(spec.subtitle, PAD, hasTitle);
|
|
232
|
+
const canvas = card(width, height, o.skin.rules.canvas !== 'card');
|
|
233
|
+
let metaSvg = '';
|
|
234
|
+
if (o.interactive) {
|
|
235
|
+
const data = {
|
|
236
|
+
title: spec.title,
|
|
237
|
+
sections: spec.sections.map((s) => ({
|
|
238
|
+
name: s.name,
|
|
239
|
+
tasks: s.tasks.map((t) => ({ name: t.name, score: t.score, actors: t.actors })),
|
|
240
|
+
})),
|
|
241
|
+
};
|
|
242
|
+
metaSvg = `<metadata id="jtasks">${esc(JSON.stringify(data))}</metadata>`;
|
|
243
|
+
}
|
|
244
|
+
const iStyle = o.interactive
|
|
245
|
+
? `<style>#jr [data-node]{cursor:pointer;transition:filter .12s ease}` +
|
|
246
|
+
`#jr [data-node]:hover{filter:brightness(1.05)}</style>`
|
|
247
|
+
: '';
|
|
248
|
+
const specOut = {
|
|
249
|
+
type: 'journey',
|
|
250
|
+
...(spec.title ? { title: spec.title } : {}),
|
|
251
|
+
...(spec.subtitle ? { subtitle: spec.subtitle } : {}),
|
|
252
|
+
sections: spec.sections.map((s) => ({
|
|
253
|
+
name: s.name,
|
|
254
|
+
tasks: s.tasks.map((t) => ({ name: t.name, score: t.score, actors: t.actors })),
|
|
255
|
+
})),
|
|
256
|
+
};
|
|
257
|
+
const svg = svgDoc(width, height, 'journey', o.v.version, spec.title ?? `journey, ${spec.sections.reduce((a, s) => a + s.tasks.length, 0)} tasks`, specOut, o.skin, `${canvas}${metaSvg}${iStyle}<g id="jr">${titleSvg}${parts.join('')}</g>`, o.tagQuery, 'journey');
|
|
258
|
+
return { svg, version: o.v.version, cacheControl: o.v.cacheControl };
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* `/draw/journey` entry: GET ?title=…§ion=…&task=…
|
|
262
|
+
*/
|
|
263
|
+
export function renderJourneyFromUrl(url, interactive = false) {
|
|
264
|
+
const params = url.searchParams;
|
|
265
|
+
const d = params.get('d');
|
|
266
|
+
const spec = d !== null && d !== '' ? parseJourneySpec(d) : journeySpecFromParams(params);
|
|
267
|
+
const v = resolveVersion(params.get('v'));
|
|
268
|
+
const skin = resolveSkin('sankey', params.get('t'), schemeParam(params));
|
|
269
|
+
const width = clampInt(params, 'w', 0, 200, 2400);
|
|
270
|
+
const height = clampInt(params, 'h', 0, 140, 2000);
|
|
271
|
+
return renderJourney(spec, {
|
|
272
|
+
v, skin, interactive,
|
|
273
|
+
width: params.has('w') ? width : undefined,
|
|
274
|
+
height: params.has('h') ? height : undefined,
|
|
275
|
+
tagQuery: url.search,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { resolveSkin } from '../styles/index.js';
|
|
2
|
+
import { type DrawResult } from './query.js';
|
|
3
|
+
/** 一张任务卡 */
|
|
4
|
+
export interface KanbanTask {
|
|
5
|
+
/** 所属列名 */
|
|
6
|
+
column: string;
|
|
7
|
+
/** 卡片标题 */
|
|
8
|
+
title: string;
|
|
9
|
+
/** 可选的元信息(小字) */
|
|
10
|
+
meta?: string;
|
|
11
|
+
}
|
|
12
|
+
/** 看板规格 */
|
|
13
|
+
export interface KanbanSpec {
|
|
14
|
+
title?: string;
|
|
15
|
+
subtitle?: string;
|
|
16
|
+
/** 列名,按顺序 */
|
|
17
|
+
columns: string[];
|
|
18
|
+
/** 任务卡 */
|
|
19
|
+
tasks: KanbanTask[];
|
|
20
|
+
}
|
|
21
|
+
/** 从扁平 URL 参数造规格 */
|
|
22
|
+
export declare function kanbanSpecFromParams(params: URLSearchParams): KanbanSpec;
|
|
23
|
+
/**
|
|
24
|
+
* 解析并校验看板规格(JSON 形态,给 ?d= 用)。
|
|
25
|
+
*
|
|
26
|
+
* @throws ApiError(400) with a corrective example on bad input
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseKanbanSpec(raw: string | null): KanbanSpec;
|
|
29
|
+
export interface KanbanOpts {
|
|
30
|
+
spec: KanbanSpec;
|
|
31
|
+
interactive: boolean;
|
|
32
|
+
version: number;
|
|
33
|
+
cacheControl: string;
|
|
34
|
+
skin: ReturnType<typeof resolveSkin>;
|
|
35
|
+
/** 画布宽度:?w= 给了就按它画(内容仍按自然尺寸排) */
|
|
36
|
+
width?: number;
|
|
37
|
+
/** 画布高度:?h= 给了就按它画 */
|
|
38
|
+
height?: number;
|
|
39
|
+
minW?: number;
|
|
40
|
+
minH?: number;
|
|
41
|
+
tagQuery?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 渲染看板。
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderKanban(spec: KanbanSpec, o: KanbanOpts): DrawResult;
|
|
47
|
+
/**
|
|
48
|
+
* `/draw/kanban` 入口:GET ?column=…&task=…&title=…
|
|
49
|
+
*/
|
|
50
|
+
export declare function renderKanbanFromUrl(url: URL, interactive?: boolean): DrawResult;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// /draw/kanban —— 看板:列并排,列里是任务卡。
|
|
2
|
+
//
|
|
3
|
+
// 模型(扁平 URL 参数):
|
|
4
|
+
// column=<列名> 可重复 —— 列,按出现顺序从左往右排
|
|
5
|
+
// task=<列名>|<标题>[|<元信息>] 可重复 —— 一张任务卡
|
|
6
|
+
// title= / subtitle= 图题与副题
|
|
7
|
+
//
|
|
8
|
+
// 画法:每列一个淡底竖条(列名在顶上),任务卡是带边框的白卡片(卡面用皮肤的
|
|
9
|
+
// card/border 中性色),标题一行,元信息(如果有)一行小字。列的强调色走皮肤
|
|
10
|
+
// 的 var(--d-sN),所以换皮即换色。
|
|
11
|
+
import { ApiError } from '../specs/index.js';
|
|
12
|
+
import { BASELINE } from '../styles/baseline.js';
|
|
13
|
+
import { resolveSkin } from '../styles/index.js';
|
|
14
|
+
import { clampInt, schemeParam } from './query.js';
|
|
15
|
+
import { card } from '../theme.js';
|
|
16
|
+
import { esc, r2, subtitleBlock, svgDoc, textW, titleBlock } from './svg.js';
|
|
17
|
+
const PAD = 26;
|
|
18
|
+
const COL_GAP = 18; // 列间距
|
|
19
|
+
const COL_HEAD_H = 38; // 列名条高度
|
|
20
|
+
const CARD_H = 46; // 任务卡高(有元信息时高一点)
|
|
21
|
+
const CARD_GAP = 10; // 任务卡之间的间距
|
|
22
|
+
const CARD_PAD = 12; // 卡内边距
|
|
23
|
+
const COL_PAD = 10; // 列底板内边距
|
|
24
|
+
const COL_MIN_W = 170;
|
|
25
|
+
const CARD_MAX_W = 300;
|
|
26
|
+
const TITLE_FS = BASELINE.cellTitle;
|
|
27
|
+
const META_FS = 11;
|
|
28
|
+
const EXAMPLE = 'column=Todo&column=Doing&task=Todo|Implement the parser|high&task=Doing|Draw the chart|';
|
|
29
|
+
function bad(detail) {
|
|
30
|
+
throw new ApiError(400, `${detail}. Example: /draw/kanban?${EXAMPLE}`);
|
|
31
|
+
}
|
|
32
|
+
/** 从扁平 URL 参数造规格 */
|
|
33
|
+
export function kanbanSpecFromParams(params) {
|
|
34
|
+
const columns = params.getAll('column').map((c) => c.trim()).filter((c) => c !== '');
|
|
35
|
+
const tasks = [];
|
|
36
|
+
params.getAll('task').forEach((raw, i) => {
|
|
37
|
+
const f = raw.split('|').map((x) => x.trim());
|
|
38
|
+
if (f.length < 2 || !f[0] || !f[1]) {
|
|
39
|
+
bad(`"task" #${i + 1} must be "column|title[|meta]"`);
|
|
40
|
+
}
|
|
41
|
+
tasks.push({ column: f[0], title: f[1], ...(f[2] ? { meta: f[2] } : {}) });
|
|
42
|
+
});
|
|
43
|
+
const title = params.get('title')?.trim() || undefined;
|
|
44
|
+
const subtitle = params.get('subtitle')?.trim() || undefined;
|
|
45
|
+
return { ...(title ? { title } : {}), ...(subtitle ? { subtitle } : {}), columns, tasks };
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 解析并校验看板规格(JSON 形态,给 ?d= 用)。
|
|
49
|
+
*
|
|
50
|
+
* @throws ApiError(400) with a corrective example on bad input
|
|
51
|
+
*/
|
|
52
|
+
export function parseKanbanSpec(raw) {
|
|
53
|
+
if (raw === null || raw === '') {
|
|
54
|
+
bad(`missing data. Use /draw/kanban?${EXAMPLE}`);
|
|
55
|
+
}
|
|
56
|
+
let obj;
|
|
57
|
+
try {
|
|
58
|
+
obj = JSON.parse(raw);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
bad(`"d" is not valid JSON. Use {"columns":["Todo"],"tasks":[{"column":"Todo","title":"Write the parser"}]}`);
|
|
62
|
+
}
|
|
63
|
+
const o = obj;
|
|
64
|
+
if (!Array.isArray(o.columns) || o.columns.length === 0) {
|
|
65
|
+
bad(`"columns" must be a non-empty array of column names`);
|
|
66
|
+
}
|
|
67
|
+
const columns = [];
|
|
68
|
+
for (const c of o.columns) {
|
|
69
|
+
if (typeof c !== 'string' || c.trim() === '')
|
|
70
|
+
bad(`"columns" entries must be non-empty strings`);
|
|
71
|
+
columns.push(c.trim());
|
|
72
|
+
}
|
|
73
|
+
if (!Array.isArray(o.tasks) || o.tasks.length === 0) {
|
|
74
|
+
bad(`"tasks" must be a non-empty array of tasks`);
|
|
75
|
+
}
|
|
76
|
+
const tasks = o.tasks.map((t, i) => {
|
|
77
|
+
if (typeof t !== 'object' || t === null)
|
|
78
|
+
bad(`"tasks"[${i}] must be an object`);
|
|
79
|
+
const tt = t;
|
|
80
|
+
const column = typeof tt.column === 'string' ? tt.column : '';
|
|
81
|
+
if (!column)
|
|
82
|
+
bad(`"tasks"[${i}].column is required (a column name)`);
|
|
83
|
+
if (!columns.includes(column))
|
|
84
|
+
bad(`"tasks"[${i}].column "${column}" is not one of the columns`);
|
|
85
|
+
const title = typeof tt.title === 'string' ? tt.title : '';
|
|
86
|
+
if (!title)
|
|
87
|
+
bad(`"tasks"[${i}].title is required`);
|
|
88
|
+
const meta = typeof tt.meta === 'string' && tt.meta !== '' ? tt.meta : undefined;
|
|
89
|
+
return { column, title, ...(meta ? { meta } : {}) };
|
|
90
|
+
});
|
|
91
|
+
const title = typeof o.title === 'string' && o.title !== '' ? o.title : undefined;
|
|
92
|
+
const subtitle = typeof o.subtitle === 'string' && o.subtitle !== '' ? o.subtitle : undefined;
|
|
93
|
+
return { ...(title ? { title } : {}), ...(subtitle ? { subtitle } : {}), columns, tasks };
|
|
94
|
+
}
|
|
95
|
+
const COL_COLORS = ['var(--d-s1)', 'var(--d-s2)', 'var(--d-s3)', 'var(--d-s4)', 'var(--d-s5)', 'var(--d-s6)', 'var(--d-s7)', 'var(--d-s8)', 'var(--d-s9)', 'var(--d-s10)'];
|
|
96
|
+
/** 文字截到能放进 maxW(超了就加省略号)—— 卡面标题不许越出卡片 */
|
|
97
|
+
function fitText(s, fs, maxW) {
|
|
98
|
+
if (textW(s, fs) <= maxW)
|
|
99
|
+
return s;
|
|
100
|
+
let t = s;
|
|
101
|
+
while (t.length > 1 && textW(`${t}…`, fs) > maxW)
|
|
102
|
+
t = t.slice(0, -1);
|
|
103
|
+
return `${t}…`;
|
|
104
|
+
}
|
|
105
|
+
/** 同上,但吃 undefined(标题/副标题可能没有) */
|
|
106
|
+
function fitTextOr(s, fs, maxW) {
|
|
107
|
+
return s === undefined ? undefined : fitText(s, fs, maxW);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 右上角 Edit 角标占掉的宽度(照 svg.ts 里 editTag 的算法算)。
|
|
111
|
+
* 标题是左对齐的,只要不撞上角标就行 —— 不用留满 TAG_RESERVE 那 150px。
|
|
112
|
+
*/
|
|
113
|
+
function editTagReserve(width) {
|
|
114
|
+
const fs = Math.max(10, Math.min(18, Math.round(width / 55)));
|
|
115
|
+
const tw = textW('Edit @X-CMD', fs);
|
|
116
|
+
const padX = Math.max(6, Math.round(fs * 0.55));
|
|
117
|
+
return Math.round(tw + padX * 2 + 2) + 8 + PAD;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* 渲染看板。
|
|
121
|
+
*/
|
|
122
|
+
export function renderKanban(spec, o) {
|
|
123
|
+
if (!spec.columns.length)
|
|
124
|
+
bad('at least one column is required');
|
|
125
|
+
if (!spec.tasks.length)
|
|
126
|
+
bad('at least one task is required');
|
|
127
|
+
const colSet = new Set(spec.columns);
|
|
128
|
+
for (const t of spec.tasks) {
|
|
129
|
+
if (!colSet.has(t.column))
|
|
130
|
+
bad(`task "${t.title}" is in unknown column "${t.column}"`);
|
|
131
|
+
}
|
|
132
|
+
const perCol = new Map();
|
|
133
|
+
for (const c of spec.columns)
|
|
134
|
+
perCol.set(c, []);
|
|
135
|
+
for (const t of spec.tasks)
|
|
136
|
+
perCol.get(t.column).push(t);
|
|
137
|
+
const titleH = spec.title || spec.subtitle ? 44 : 30; // 没标题也留一条带:右上角那枚角标在那儿
|
|
138
|
+
const hasTitle = !!spec.title;
|
|
139
|
+
// 列宽:由该列最宽的一张卡决定(卡宽有上限,列也不无限宽)
|
|
140
|
+
const colW = spec.columns.map((c) => {
|
|
141
|
+
const tasks = perCol.get(c) ?? [];
|
|
142
|
+
let w = textW(c, 13) + 40; // 列名至少要放得下
|
|
143
|
+
for (const t of tasks) {
|
|
144
|
+
w = Math.max(w, textW(t.title, TITLE_FS) + CARD_PAD * 2 + 4);
|
|
145
|
+
if (t.meta)
|
|
146
|
+
w = Math.max(w, textW(t.meta, META_FS) + CARD_PAD * 2 + 4);
|
|
147
|
+
}
|
|
148
|
+
return Math.min(Math.max(w, COL_MIN_W), CARD_MAX_W);
|
|
149
|
+
});
|
|
150
|
+
const totalColsW = colW.reduce((a, b) => a + b, 0) + COL_GAP * (spec.columns.length - 1);
|
|
151
|
+
const naturalW = PAD * 2 + totalColsW;
|
|
152
|
+
// 列高:每列里最高的那摞决定列高(看板的列本来就一样高)
|
|
153
|
+
let maxStack = 0;
|
|
154
|
+
for (const c of spec.columns) {
|
|
155
|
+
const tasks = perCol.get(c) ?? [];
|
|
156
|
+
let h = 0;
|
|
157
|
+
for (const t of tasks)
|
|
158
|
+
h += (t.meta ? CARD_H + 8 : CARD_H) + CARD_GAP;
|
|
159
|
+
h = Math.max(0, h - CARD_GAP);
|
|
160
|
+
maxStack = Math.max(maxStack, h);
|
|
161
|
+
}
|
|
162
|
+
const naturalH = PAD * 2 + titleH + COL_HEAD_H + maxStack + COL_PAD;
|
|
163
|
+
// 画布:?w=/?h= 给了就按它画(内容仍是自然尺寸,摆在左上角);没给就用自然尺寸
|
|
164
|
+
let width = o.width !== undefined ? o.width : naturalW;
|
|
165
|
+
let height = o.height !== undefined ? o.height : naturalH;
|
|
166
|
+
width = Math.max(width, naturalW, o.minW ?? 0);
|
|
167
|
+
height = Math.max(height, naturalH, o.minH ?? 0);
|
|
168
|
+
const top = PAD + titleH;
|
|
169
|
+
const parts = [];
|
|
170
|
+
let x = PAD;
|
|
171
|
+
spec.columns.forEach((name, ci) => {
|
|
172
|
+
const w = colW[ci];
|
|
173
|
+
const color = COL_COLORS[ci % COL_COLORS.length];
|
|
174
|
+
const colH = COL_HEAD_H + maxStack + COL_PAD;
|
|
175
|
+
// 列底板
|
|
176
|
+
parts.push(`<g data-column="${esc(name)}">` +
|
|
177
|
+
`<rect x="${r2(x)}" y="${r2(top)}" width="${r2(w)}" height="${r2(colH)}" rx="12" fill="${color}" fill-opacity="0.05" stroke="${color}" stroke-opacity="0.38" stroke-width="1.2"/>` +
|
|
178
|
+
// 列名条:颜色块 + 名字
|
|
179
|
+
`<rect x="${r2(x + COL_PAD)}" y="${r2(top + 10)}" width="4" height="18" rx="2" fill="${color}"/>` +
|
|
180
|
+
`<text x="${r2(x + COL_PAD + 12)}" y="${r2(top + 24)}" font-size="13" font-weight="600" fill="var(--d-ink)">${esc(name)}</text>` +
|
|
181
|
+
// 任务数(角标:几件事,一眼可见)
|
|
182
|
+
`<text x="${r2(x + w - COL_PAD)}" y="${r2(top + 24)}" text-anchor="end" font-size="11" fill="var(--d-muted)">${(perCol.get(name) ?? []).length}</text>` +
|
|
183
|
+
`</g>`);
|
|
184
|
+
// 任务卡
|
|
185
|
+
let cy = top + COL_HEAD_H;
|
|
186
|
+
for (const t of perCol.get(name) ?? []) {
|
|
187
|
+
const ch = t.meta ? CARD_H + 8 : CARD_H;
|
|
188
|
+
const tip = [t.title, t.meta, name].filter(Boolean).join(' · ');
|
|
189
|
+
const ia = o.interactive ? ` data-node="${esc(t.title)}" data-tip="${esc(tip)}" tabindex="0" style="cursor:pointer"` : '';
|
|
190
|
+
parts.push(`<g${ia}>` +
|
|
191
|
+
`<rect x="${r2(x + COL_PAD)}" y="${r2(cy)}" width="${r2(w - COL_PAD * 2)}" height="${r2(ch)}" rx="9" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"/>` +
|
|
192
|
+
// 左侧强调条:列的颜色(极淡,只是提示归属)
|
|
193
|
+
`<rect x="${r2(x + COL_PAD)}" y="${r2(cy)}" width="3" height="${r2(ch)}" rx="1.5" fill="${color}" fill-opacity="0.75"/>` +
|
|
194
|
+
`</g>`);
|
|
195
|
+
// 卡面文字:标题一行(装不下就截到省略号),元信息一行小字
|
|
196
|
+
const innerW = w - COL_PAD * 2 - CARD_PAD - 6;
|
|
197
|
+
const titleText = fitText(t.title, TITLE_FS, innerW);
|
|
198
|
+
parts.push(`<text x="${r2(x + COL_PAD + CARD_PAD)}" y="${r2(cy + (t.meta ? 20 : ch / 2 + 4))}" font-size="${TITLE_FS}" fill="var(--d-ink)"${o.interactive ? ` data-node="${esc(t.title)}" style="cursor:pointer"` : ''}>${esc(titleText)}</text>`);
|
|
199
|
+
if (t.meta) {
|
|
200
|
+
parts.push(`<text x="${r2(x + COL_PAD + CARD_PAD)}" y="${r2(cy + 38)}" font-size="${META_FS}" fill="var(--d-muted)">${esc(fitText(t.meta, META_FS, innerW))}</text>`);
|
|
201
|
+
}
|
|
202
|
+
cy += ch + CARD_GAP;
|
|
203
|
+
}
|
|
204
|
+
x += w + COL_GAP;
|
|
205
|
+
});
|
|
206
|
+
const titleMax = Math.max(60, width - PAD - editTagReserve(width));
|
|
207
|
+
const head = titleBlock(fitTextOr(spec.title, 18, titleMax), PAD)
|
|
208
|
+
+ subtitleBlock(fitTextOr(spec.subtitle, 13, titleMax), PAD, hasTitle);
|
|
209
|
+
const meta = o.interactive
|
|
210
|
+
? `<metadata id="ktasks">${esc(JSON.stringify(spec.tasks))}</metadata>`
|
|
211
|
+
: '';
|
|
212
|
+
const bg = card(width, height, o.skin.rules.canvas === 'plain');
|
|
213
|
+
const svg = svgDoc(width, height, 'kanban', o.version, spec.title ?? `kanban board, ${spec.columns.length} columns, ${spec.tasks.length} tasks`, { type: 'kanban', ...spec }, o.skin, bg + meta + `<g id="kb">${head + parts.join('')}</g>`, o.tagQuery, 'kanban');
|
|
214
|
+
return { svg, version: o.version, cacheControl: o.cacheControl };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* `/draw/kanban` 入口:GET ?column=…&task=…&title=…
|
|
218
|
+
*/
|
|
219
|
+
export function renderKanbanFromUrl(url, interactive = false) {
|
|
220
|
+
const params = url.searchParams;
|
|
221
|
+
const d = params.get('d');
|
|
222
|
+
const spec = d !== null && d !== ''
|
|
223
|
+
? parseKanbanSpec(d)
|
|
224
|
+
: kanbanSpecFromParams(params);
|
|
225
|
+
const v = Number.parseInt(params.get('v') ?? '', 10);
|
|
226
|
+
const version = Number.isInteger(v) && v >= 1 ? v : 1;
|
|
227
|
+
const skin = resolveSkin('sankey', params.get('t'), schemeParam(params));
|
|
228
|
+
const hasW = params.get('w') !== null && params.get('w') !== '';
|
|
229
|
+
const hasH = params.get('h') !== null && params.get('h') !== '';
|
|
230
|
+
return renderKanban(spec, {
|
|
231
|
+
spec,
|
|
232
|
+
interactive,
|
|
233
|
+
version,
|
|
234
|
+
cacheControl: 'public, max-age=300',
|
|
235
|
+
skin,
|
|
236
|
+
...(hasW ? { width: clampInt(params, 'w', 0, 200, 2400) } : {}),
|
|
237
|
+
...(hasH ? { height: clampInt(params, 'h', 0, 140, 2400) } : {}),
|
|
238
|
+
tagQuery: url.search,
|
|
239
|
+
});
|
|
240
|
+
}
|
package/dist/render/kinds.js
CHANGED
|
@@ -97,6 +97,19 @@ function parseKindNodes(raw, allowed) {
|
|
|
97
97
|
return node;
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
+
// C4(上下文/容器/组件/部署):人、系统、容器、组件、外部系统 ——
|
|
101
|
+
// 边界 = System_Boundary/Container_Boundary,关系 = Rel(带技术标注)。
|
|
102
|
+
const C4 = {
|
|
103
|
+
meta: {
|
|
104
|
+
person: { name: 'Person', badge: 'P', color: 1 },
|
|
105
|
+
system: { name: 'System', badge: 'S', color: 2 },
|
|
106
|
+
container: { name: 'Container', badge: 'C', color: 3 },
|
|
107
|
+
component: { name: 'Component', badge: 'K', color: 4 },
|
|
108
|
+
external: { name: 'External', badge: 'X', color: -1 },
|
|
109
|
+
},
|
|
110
|
+
order: ['person', 'system', 'container', 'component', 'external'],
|
|
111
|
+
shape: { person: 'round', system: 'rect', container: 'rect', component: 'rect', external: 'rect' },
|
|
112
|
+
};
|
|
100
113
|
const KINDS = {
|
|
101
114
|
dataflow: {
|
|
102
115
|
name: 'Data flow',
|
|
@@ -116,6 +129,12 @@ const KINDS = {
|
|
|
116
129
|
allowed: ['table', 'view'],
|
|
117
130
|
example: 'n=users;table;users;id:int (pk)%0Aname:text%0Acreated_at:timestamp;r0c0&n=orders;table;orders;id:int (pk)%0Auser_id:int (fk)%0Atotal:int;r1c0&e=users;orders;1:N',
|
|
118
131
|
},
|
|
132
|
+
c4: {
|
|
133
|
+
name: 'C4',
|
|
134
|
+
types: C4,
|
|
135
|
+
allowed: ['person', 'system', 'container', 'component', 'external'],
|
|
136
|
+
example: 'n=cust;person;Banking Customer;;;&n=sys;system;Internet Banking;;;;&e=cust;sys;Uses&b=Bank;sys',
|
|
137
|
+
},
|
|
119
138
|
class: {
|
|
120
139
|
name: 'Class',
|
|
121
140
|
types: CLASS,
|