@x-cmd/draw 0.4.7 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/client.d.ts +44 -0
- package/dist/client.js +285 -0
- package/dist/core.d.ts +86 -0
- package/dist/core.js +132 -0
- package/dist/draw-client.iife.js +51 -0
- package/dist/draw-echarts.iife.js +1 -0
- package/dist/echarts-client.d.ts +34 -0
- package/dist/echarts-client.js +109 -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 +40 -2
- package/dist/render/echarts-ssr.js +80 -20
- 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 +103 -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 +44 -6
package/dist/render/compass.js
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
|
+
import { BASELINE } from '../styles/baseline.js';
|
|
1
2
|
import { card } from '../theme.js';
|
|
2
3
|
import { esc, r2, textW, trunc, svgDoc, titleBlock, sVar } from './svg.js';
|
|
4
|
+
/**
|
|
5
|
+
* 标签折行(按字宽折,最多 maxLines 行)——
|
|
6
|
+
* 方向标签比「胶囊」能装下的宽 ⇒ 宁可折成两行,不要截成「Invest …」:
|
|
7
|
+
* 截一半的标签等于给错信息(读者只能猜)。
|
|
8
|
+
*/
|
|
9
|
+
function wrapLabel(text, maxW, fs, maxLines = 2) {
|
|
10
|
+
if (!text)
|
|
11
|
+
return [];
|
|
12
|
+
const w = (ch) => (ch.charCodeAt(0) > 0x2e80 ? fs : fs * 0.55);
|
|
13
|
+
const chars = [...text];
|
|
14
|
+
if (chars.reduce((s, c) => s + w(c), 0) <= maxW)
|
|
15
|
+
return [text];
|
|
16
|
+
const lines = [];
|
|
17
|
+
let line = '';
|
|
18
|
+
let lw = 0;
|
|
19
|
+
for (const ch of chars) {
|
|
20
|
+
const cw = w(ch);
|
|
21
|
+
if (lw + cw > maxW && line !== '') {
|
|
22
|
+
lines.push(line);
|
|
23
|
+
line = ch;
|
|
24
|
+
lw = cw;
|
|
25
|
+
if (lines.length >= maxLines)
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
line += ch;
|
|
30
|
+
lw += cw;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (line && lines.length < maxLines)
|
|
34
|
+
lines.push(line);
|
|
35
|
+
return lines.length ? lines : [text];
|
|
36
|
+
}
|
|
3
37
|
const ARROW = 12; // 箭头长度
|
|
4
38
|
const BASE = 5.5; // 箭身根部半宽
|
|
5
39
|
// 字号偏大:看这图的人年长,字要看得清
|
|
6
|
-
const FS_LABEL =
|
|
7
|
-
const FS_NOTE =
|
|
40
|
+
const FS_LABEL = BASELINE.axisName; // 方向标签
|
|
41
|
+
const FS_NOTE = BASELINE.note; // 副说明
|
|
8
42
|
/**
|
|
9
43
|
* Compass chart: four labelled arrows radiating from a center point.
|
|
10
44
|
*/
|
|
11
45
|
export function renderCompass(spec, o) {
|
|
12
46
|
const { width, height, version, skin } = o;
|
|
13
|
-
const
|
|
47
|
+
const bg = card(width, height, skin.rules.canvas === 'plain');
|
|
48
|
+
const parts = [];
|
|
14
49
|
const titleH = spec.title ? 44 : 12;
|
|
15
50
|
const cx = width / 2;
|
|
16
51
|
const cy = titleH + (height - titleH) / 2;
|
|
@@ -37,21 +72,29 @@ export function renderCompass(spec, o) {
|
|
|
37
72
|
const by = cy + uy * (arm - ARROW);
|
|
38
73
|
parts.push(`<path d="M${r2(cx + px * BASE)} ${r2(cy + py * BASE)}L${r2(bx + px * BASE)} ${r2(by + py * BASE)}L${r2(x2)} ${r2(y2)}L${r2(bx - px * BASE)} ${r2(by - py * BASE)}L${r2(cx - px * BASE)} ${r2(cy - py * BASE)}Z" fill="${color}" fill-opacity="0.16" stroke="${color}" stroke-width="1.6" stroke-linejoin="round"/>`);
|
|
39
74
|
// 端点标签:胶囊(同色小圆点 + 文字),上下方向居中、左右方向顺排
|
|
40
|
-
|
|
75
|
+
// 标签折行而不是截断(见 wrapLabel 的说明)
|
|
76
|
+
const maxLabelW = ux === 0
|
|
77
|
+
? width - 48
|
|
78
|
+
: Math.max(70, (ux > 0 ? width - 16 - (x2 + 14) : (x2 - 14) - 16) - 34);
|
|
79
|
+
const labelLines = wrapLabel(a.label ?? '', maxLabelW, FS_LABEL);
|
|
80
|
+
const label = labelLines.join(' ');
|
|
41
81
|
const note = a.note ? trunc(a.note, 14) : '';
|
|
42
|
-
const tw = Math.max(textW(
|
|
82
|
+
const tw = Math.max(...labelLines.map((l) => textW(l, FS_LABEL)), textW(note, FS_NOTE));
|
|
83
|
+
const extraLines = Math.max(0, labelLines.length - 1);
|
|
43
84
|
const pillW = tw + 34;
|
|
44
|
-
const pillH = a.note ? 41 : 26;
|
|
85
|
+
const pillH = (a.note ? 41 : 26) + extraLines * (FS_LABEL + 4);
|
|
45
86
|
if (ux === 0) {
|
|
46
87
|
const py2 = y2 + (uy < 0 ? -pillH - 12 : 12);
|
|
47
88
|
// 圆点 + 文字作为一组居中(圆点占位,不然文字看着偏)
|
|
48
|
-
const tw2 = textW(
|
|
89
|
+
const tw2 = Math.max(...labelLines.map((l) => textW(l, FS_LABEL)));
|
|
49
90
|
const dotX = cx - (tw2 + 14) / 2;
|
|
50
|
-
parts.push(`<rect x="${r2(cx - pillW / 2)}" y="${r2(py2)}" width="${r2(pillW)}" height="${pillH}" rx="${pillH / 2}" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"/>`);
|
|
91
|
+
parts.push(`<rect x="${r2(cx - pillW / 2)}" y="${r2(py2)}" width="${r2(pillW)}" height="${pillH}" rx="${Math.min(pillH / 2, 13)}" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"/>`);
|
|
51
92
|
parts.push(`<circle cx="${r2(dotX)}" cy="${r2(py2 + (a.note ? 12 : 11))}" r="5" fill="${color}"/>`);
|
|
52
|
-
|
|
93
|
+
labelLines.forEach((ln, i) => {
|
|
94
|
+
parts.push(`<text x="${r2(dotX + 10)}" y="${r2(py2 + (a.note ? 17 : 16) + i * (FS_LABEL + 4))}" font-size="${FS_LABEL}" font-weight="600" fill="var(--d-ink)">${esc(ln)}</text>`);
|
|
95
|
+
});
|
|
53
96
|
if (a.note) {
|
|
54
|
-
parts.push(`<text x="${r2(cx)}" y="${r2(py2 + 34)}" font-size="${FS_NOTE}" text-anchor="middle" fill="var(--d-muted)">${esc(note)}</text>`);
|
|
97
|
+
parts.push(`<text x="${r2(cx)}" y="${r2(py2 + 34 + extraLines * (FS_LABEL + 4))}" font-size="${FS_NOTE}" text-anchor="middle" fill="var(--d-muted)">${esc(note)}</text>`);
|
|
55
98
|
}
|
|
56
99
|
}
|
|
57
100
|
else {
|
|
@@ -59,7 +102,9 @@ export function renderCompass(spec, o) {
|
|
|
59
102
|
parts.push(`<rect x="${r2(ux > 0 ? px2 : px2 - pillW)}" y="${r2(cy - pillH / 2)}" width="${r2(pillW)}" height="${pillH}" rx="${pillH / 2}" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1"/>`);
|
|
60
103
|
const lx = ux > 0 ? px2 + 8 : px2 - 8;
|
|
61
104
|
parts.push(`<circle cx="${r2(lx + (ux > 0 ? 4 : -4))}" cy="${r2(cy - (a.note ? 5 : 0))}" r="5" fill="${color}"/>`);
|
|
62
|
-
|
|
105
|
+
labelLines.forEach((ln, i) => {
|
|
106
|
+
parts.push(`<text x="${r2(lx + (ux > 0 ? 13 : -13))}" y="${r2(cy - (a.note ? 2 : 5) - (labelLines.length - 1) * (FS_LABEL + 4) / 2 + i * (FS_LABEL + 4))}" font-size="${FS_LABEL}" font-weight="600" text-anchor="${ux > 0 ? 'start' : 'end'}" fill="var(--d-ink)">${esc(ln)}</text>`);
|
|
107
|
+
});
|
|
63
108
|
if (a.note) {
|
|
64
109
|
// 说明对齐到**标签文字**的中线(不是整个胶囊)—— 圆点占了位,不然看着歪
|
|
65
110
|
const nc = ux > 0 ? lx + 13 + textW(label, FS_LABEL) / 2 : lx - 13 - textW(label, FS_LABEL) / 2;
|
|
@@ -71,7 +116,8 @@ export function renderCompass(spec, o) {
|
|
|
71
116
|
parts.push(`<circle cx="${r2(cx)}" cy="${r2(cy)}" r="13" fill="var(--d-card)" stroke="var(--d-border)" stroke-width="1.5"/>`);
|
|
72
117
|
parts.push(`<circle cx="${r2(cx)}" cy="${r2(cy)}" r="4.5" fill="var(--d-ink)"/>`);
|
|
73
118
|
if (spec.center) {
|
|
74
|
-
|
|
119
|
+
const centerLines = wrapLabel(spec.center, width - cx - 40, FS_LABEL, 1);
|
|
120
|
+
parts.push(`<text x="${r2(cx + 20)}" y="${r2(cy - 21)}" font-size="${FS_LABEL}" font-weight="600" fill="var(--d-ink)">${esc(centerLines[0] ?? spec.center)}</text>`);
|
|
75
121
|
}
|
|
76
|
-
return svgDoc(width, height, 'compass', version, spec.title ?? 'compass chart', spec, skin, titleBlock(spec.title) + parts.join(''));
|
|
122
|
+
return svgDoc(width, height, 'compass', version, spec.title ?? 'compass chart', spec, skin, bg + titleBlock(spec.title) + parts.join(''));
|
|
77
123
|
}
|
|
@@ -1,13 +1,49 @@
|
|
|
1
|
+
import type { Skin } from '../styles/index.js';
|
|
1
2
|
import { type DrawResult } from './query.js';
|
|
3
|
+
import type { EChartsOption } from 'echarts';
|
|
2
4
|
type Obj = Record<string, unknown>;
|
|
3
|
-
|
|
5
|
+
export declare const MAP_BANDS: {
|
|
6
|
+
/** 顶部标题带:24(顶)+18(字)+余量 */
|
|
7
|
+
readonly title: 52;
|
|
8
|
+
/** 底部图例带(横排时):色标 14 + 文字 + 余量 */
|
|
9
|
+
readonly legendBottom: 26;
|
|
10
|
+
/** 左侧图例带(竖排时):色标 12 + 文字 + 余量 */
|
|
11
|
+
readonly legendSide: 44;
|
|
12
|
+
/** 地图四周的余量(给边缘的标签) */
|
|
13
|
+
readonly margin: 10;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 地图布局缺省(服务端与浏览器端同一套规则 —— 浏览器端跑的是本函数的源码,
|
|
17
|
+
* 由 explore 页注入 ⇒ 两边不会走偏)。
|
|
18
|
+
*
|
|
19
|
+
* **自包含**:只依赖 MAP_BANDS(单独注入)与传进来的 aspect —— 不引用模块外的任何东西。
|
|
20
|
+
*/
|
|
4
21
|
export declare function mapLayout(o: {
|
|
5
|
-
|
|
22
|
+
/** 底图的纵横比(宽/高)—— 投影平面上外接框的比 */
|
|
23
|
+
aspect: number;
|
|
6
24
|
width: number;
|
|
7
25
|
height: number;
|
|
8
26
|
/** 图例是否横排在底部(横排才占底部那条带) */
|
|
9
27
|
legendAtBottom: boolean;
|
|
28
|
+
/** 画布上有没有标题(没有就不留顶带) */
|
|
29
|
+
hasTitle?: boolean;
|
|
10
30
|
}): Obj;
|
|
31
|
+
/**
|
|
32
|
+
* 地图的画布该多高(调用方只给了宽、没给高时):**按底图的形状给** ⇒ 地图填满宽度,
|
|
33
|
+
* 画布里不留空带(不给形状的话,竖长的地图在 16:9 的画布里只占三成宽 ✗)。
|
|
34
|
+
*
|
|
35
|
+
* 算的是「地图能占的那块」:宽度 = 画布宽 - 图例侧带 - 四周余量,
|
|
36
|
+
* 高度 = 宽度 / 底图纵横比;画布高 = 标题带 + 图例带 + 四周余量 + 地图高。
|
|
37
|
+
*/
|
|
38
|
+
export declare function mapCanvasHeight(o: {
|
|
39
|
+
/** 底图的纵横比(宽/高) */
|
|
40
|
+
aspect: number;
|
|
41
|
+
width: number;
|
|
42
|
+
/** 图例是否横排在底部 */
|
|
43
|
+
legendAtBottom: boolean;
|
|
44
|
+
/** 画布上有没有标题 */
|
|
45
|
+
hasTitle?: boolean;
|
|
46
|
+
}): number;
|
|
11
47
|
export declare const HEAD_RULES: {
|
|
12
48
|
readonly titleTop: 24;
|
|
13
49
|
readonly titleLeft: 19;
|
|
@@ -30,6 +66,8 @@ export declare const HEAD_RULES: {
|
|
|
30
66
|
* hub 那边用 `headLayout.toString()` 把源码塞进页面脚本。
|
|
31
67
|
*/
|
|
32
68
|
export declare function headLayout(option: Obj): void;
|
|
69
|
+
/** 把用户的 option 补齐缺省(皮肤色板/字体/轴/标题/图例)—— **浏览器端也用这一份** */
|
|
70
|
+
export declare function echartsOption(user: Obj, skin: Skin, width: number, height: number): EChartsOption;
|
|
33
71
|
/**
|
|
34
72
|
* Render a parsed ECharts option object to a skinned SVG — shared by the HTTP
|
|
35
73
|
* layer (`?d=` urlencoded JSON) and the CLI (inline JSON / file / stdin, where
|
|
@@ -12,7 +12,7 @@ import { resolveSkin } from '../styles/index.js';
|
|
|
12
12
|
import { FONT } from '../theme.js';
|
|
13
13
|
import { esc, metaTag, skinStyle, editTag } from './svg.js';
|
|
14
14
|
import { clampInt, schemeParam } from './query.js';
|
|
15
|
-
import { mapAspect, registerMaps, worldWrapLayout } from './maps.js';
|
|
15
|
+
import { mapAspect, mapNamesOf, registerMaps, worldWrapLayout } from './maps.js';
|
|
16
16
|
// ?d= 上限:再大就撞各端 URL 长度红线(Workers/代理 ~16KB);超限直接拒绝,
|
|
17
17
|
// 而不是静默截断(数据在 URL 上是产品第一性原则,不可悄悄丢)
|
|
18
18
|
const D_MAX = 16000;
|
|
@@ -43,29 +43,46 @@ const CARTESIAN = new Set(['bar', 'line', 'scatter', 'effectScatter', 'boxplot',
|
|
|
43
43
|
// 地图系列的布局缺省:
|
|
44
44
|
// aspectScale=1 —— echarts 默认 0.75(给经纬度 GeoJSON 用的经验值),会把投影过的
|
|
45
45
|
// 地图横向压扁 25%;地图数据本身已是等距投影的平面坐标,纵横比按数据来(aspect=1)
|
|
46
|
-
// 尺寸按画布算 ——
|
|
47
|
-
//
|
|
48
|
-
//
|
|
46
|
+
// 尺寸按画布算 —— 顶部留一条标题带(有标题才留)、图例横排(orient=horizontal)时
|
|
47
|
+
// 底部留一条、竖排(orient=vertical,靠左)则左侧留一条且地图右移,不跟图例叠在一起;
|
|
48
|
+
// 四周再留一点余量给州名标签(边缘的标签会溢出地图框)
|
|
49
49
|
// layoutSize 是 min(画布宽高) 的百分比:地图比画布宽时它给宽,比画布高时它给高
|
|
50
50
|
// (echarts 按地图自身纵横比决定),所以两条分支都要算。
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
//
|
|
52
|
+
// **带子的宽窄是有讲究的**:留得越多,地图能占的地方越少 ⇒ 地图在自己的画布里
|
|
53
|
+
// 显得越小(中国那张在 960×540 里只占 36% 的宽 ✗)。所以带子只按「真的有东西」
|
|
54
|
+
// 来留(没标题不留顶带、图例竖排就不留底带),数字也按实际字号收窄。
|
|
55
|
+
export const MAP_BANDS = {
|
|
56
|
+
/** 顶部标题带:24(顶)+18(字)+余量 */
|
|
57
|
+
title: 52,
|
|
58
|
+
/** 底部图例带(横排时):色标 14 + 文字 + 余量 */
|
|
59
|
+
legendBottom: 26,
|
|
60
|
+
/** 左侧图例带(竖排时):色标 12 + 文字 + 余量 */
|
|
61
|
+
legendSide: 44,
|
|
62
|
+
/** 地图四周的余量(给边缘的标签) */
|
|
63
|
+
margin: 10,
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* 地图布局缺省(服务端与浏览器端同一套规则 —— 浏览器端跑的是本函数的源码,
|
|
67
|
+
* 由 explore 页注入 ⇒ 两边不会走偏)。
|
|
68
|
+
*
|
|
69
|
+
* **自包含**:只依赖 MAP_BANDS(单独注入)与传进来的 aspect —— 不引用模块外的任何东西。
|
|
70
|
+
*/
|
|
56
71
|
export function mapLayout(o) {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
const
|
|
72
|
+
const B = MAP_BANDS;
|
|
73
|
+
const aspect = o.aspect > 0 ? o.aspect : 1.7;
|
|
74
|
+
const top = o.hasTitle === false ? 0 : B.title;
|
|
75
|
+
const left = o.legendAtBottom ? 0 : B.legendSide;
|
|
76
|
+
const bottom = o.legendAtBottom ? B.legendBottom : 0;
|
|
77
|
+
const availW = Math.max(40, o.width - left - B.margin * 2);
|
|
78
|
+
const availH = Math.max(40, o.height - top - bottom - B.margin * 2);
|
|
62
79
|
// echarts:layoutSize 给的是「短边」那个方向的尺寸 —— 地图比画布宽时给宽,否则给高
|
|
63
80
|
const size = aspect >= 1
|
|
64
81
|
? Math.min(availW, availH * aspect)
|
|
65
82
|
: Math.min(availH, availW / aspect);
|
|
66
83
|
const unit = Math.min(o.width, o.height);
|
|
67
|
-
const centerX = left +
|
|
68
|
-
const centerY =
|
|
84
|
+
const centerX = left + B.margin + availW / 2;
|
|
85
|
+
const centerY = top + B.margin + availH / 2;
|
|
69
86
|
return {
|
|
70
87
|
aspectScale: 1,
|
|
71
88
|
layoutSize: `${((size / unit) * 100).toFixed(2)}%`,
|
|
@@ -75,6 +92,22 @@ export function mapLayout(o) {
|
|
|
75
92
|
],
|
|
76
93
|
};
|
|
77
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* 地图的画布该多高(调用方只给了宽、没给高时):**按底图的形状给** ⇒ 地图填满宽度,
|
|
97
|
+
* 画布里不留空带(不给形状的话,竖长的地图在 16:9 的画布里只占三成宽 ✗)。
|
|
98
|
+
*
|
|
99
|
+
* 算的是「地图能占的那块」:宽度 = 画布宽 - 图例侧带 - 四周余量,
|
|
100
|
+
* 高度 = 宽度 / 底图纵横比;画布高 = 标题带 + 图例带 + 四周余量 + 地图高。
|
|
101
|
+
*/
|
|
102
|
+
export function mapCanvasHeight(o) {
|
|
103
|
+
const B = MAP_BANDS;
|
|
104
|
+
const aspect = o.aspect > 0 ? o.aspect : 1.7;
|
|
105
|
+
const top = o.hasTitle === false ? 0 : B.title;
|
|
106
|
+
const left = o.legendAtBottom ? 0 : B.legendSide;
|
|
107
|
+
const bottom = o.legendAtBottom ? B.legendBottom : 0;
|
|
108
|
+
const availW = Math.max(40, o.width - left - B.margin * 2);
|
|
109
|
+
return Math.round(top + bottom + B.margin * 2 + availW / aspect);
|
|
110
|
+
}
|
|
78
111
|
// 标题带 / 图例 / 绘图区 的排布(仓库硬规则:文字不得重叠)。
|
|
79
112
|
//
|
|
80
113
|
// echarts 6 的图例缺省在**底部**(bottom:15),但常见写法是放顶部(legend.top)。
|
|
@@ -197,7 +230,8 @@ export function headLayout(option) {
|
|
|
197
230
|
}
|
|
198
231
|
}
|
|
199
232
|
}
|
|
200
|
-
|
|
233
|
+
/** 把用户的 option 补齐缺省(皮肤色板/字体/轴/标题/图例)—— **浏览器端也用这一份** */
|
|
234
|
+
export function echartsOption(user, skin, width, height) {
|
|
201
235
|
const option = {
|
|
202
236
|
animation: false, // 静态 SVG:开动画只会输出第 0 帧
|
|
203
237
|
color: skin.series.map((_, i) => `var(--d-s${i + 1})`), // 皮肤系列色板(padSeries 已补足 10 色)
|
|
@@ -248,6 +282,10 @@ function withDrawDefaults(user, skin, width, height) {
|
|
|
248
282
|
// ECharts 6 label 内置默认 = 2px 白描边 + #333 字色(为白底设计):
|
|
249
283
|
// 暗色皮肤上黑字黑底且描边违反"无描边文字"约定 → 系列级缺省一次拨正,
|
|
250
284
|
// 数据项级 label 继承系列级,天然覆盖(用户显式写的不动)
|
|
285
|
+
const hasTitle = (() => {
|
|
286
|
+
const t = firstObj(option.title);
|
|
287
|
+
return !!t && typeof t.text === 'string' && t.text.trim() !== '';
|
|
288
|
+
})();
|
|
251
289
|
for (const s of seriesArr) {
|
|
252
290
|
if (isObj(s))
|
|
253
291
|
fillDefaults(s, { label: { textBorderWidth: 0, color: 'var(--d-text)' } });
|
|
@@ -255,7 +293,10 @@ function withDrawDefaults(user, skin, width, height) {
|
|
|
255
293
|
if (isObj(s) && s.type === 'map' && typeof s.map === 'string') {
|
|
256
294
|
const vm = user.visualMap;
|
|
257
295
|
const legendAtBottom = vm !== undefined && vm.orient !== 'vertical';
|
|
258
|
-
fillDefaults(s, mapLayout({
|
|
296
|
+
fillDefaults(s, mapLayout({
|
|
297
|
+
aspect: mapAspect(s.map) ?? 1.7,
|
|
298
|
+
width, height, legendAtBottom, hasTitle,
|
|
299
|
+
}));
|
|
259
300
|
}
|
|
260
301
|
}
|
|
261
302
|
return option;
|
|
@@ -450,13 +491,32 @@ export async function renderEchartsOption(user, params) {
|
|
|
450
491
|
const v = resolveVersion(params.get('v'));
|
|
451
492
|
const skin = resolveSkin('line', params.get('t'), schemeParam(params)); // echarts 无专属变体,借用 line 的家族注册表
|
|
452
493
|
const width = clampInt(params, 'w', 560, 200, 1600);
|
|
453
|
-
|
|
494
|
+
let height = clampInt(params, 'h', 320, 140, 1200);
|
|
454
495
|
// 动态加载:核心 /draw 路径(含 Worker 冷启动)不为 echarts 付 ~1MB 的加载成本
|
|
455
496
|
const echarts = await import('echarts');
|
|
456
497
|
// 地图数据(US 各州 GeoJSON)同样按需载入:option 没用 map/geo 就不碰它;
|
|
457
498
|
// 先注册再补缺省 —— 布局要按地图的真实纵横比算
|
|
458
499
|
await registerMaps(echarts, user);
|
|
459
|
-
|
|
500
|
+
// **地图的画布按底图的形状给**(调用方只给了宽、没给高时)⇒ 地图填满宽度,
|
|
501
|
+
// 画布里不留空带。不给形状的话,竖长的地图(中国/德国/日本)在 16:9 的画布里
|
|
502
|
+
// 只占三成宽 —— 看着像「图小了一圈」✗
|
|
503
|
+
if (!params.has('h')) {
|
|
504
|
+
const mapName = mapNamesOf(user)[0];
|
|
505
|
+
const aspect = mapName ? mapAspect(mapName) : undefined;
|
|
506
|
+
if (aspect) {
|
|
507
|
+
const vm = user.visualMap;
|
|
508
|
+
const t = firstObj(user.title);
|
|
509
|
+
const hasTitle = !!t && typeof t.text === 'string' && t.text.trim() !== '';
|
|
510
|
+
const h = mapCanvasHeight({
|
|
511
|
+
aspect,
|
|
512
|
+
width,
|
|
513
|
+
legendAtBottom: vm !== undefined && vm.orient !== 'vertical',
|
|
514
|
+
hasTitle,
|
|
515
|
+
});
|
|
516
|
+
height = Math.min(1200, Math.max(140, h));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const option = echartsOption(user, skin, width, height);
|
|
460
520
|
// 世界地图挪到某个经度时:底图绕一圈(registerMaps 已注册绕圈后的数据),
|
|
461
521
|
// 布局按份数放大 —— 两步都在 maps.ts,浏览器端跑同一份源码
|
|
462
522
|
worldWrapLayout(option);
|
package/dist/render/gauge.js
CHANGED
|
@@ -25,7 +25,7 @@ function pushLegendRow(parts, items, cx, ly0, width, advance, render) {
|
|
|
25
25
|
// 仪表盘:规范 gauge-1 半圆多环(默认)/ gauge-2 渐变整圆多环 / reliability 分区环。
|
|
26
26
|
import { ApiError } from '../specs/index.js';
|
|
27
27
|
import { TAB, card } from '../theme.js';
|
|
28
|
-
import { esc, fmtFull, fmtNum, r2,
|
|
28
|
+
import { esc, fmtFull, fmtNum, r2, subtitleBlock, sVar, svgDoc, textW, titleBlock, trunc } from './svg.js';
|
|
29
29
|
import { segPath, pol } from './pie.js';
|
|
30
30
|
import { C_gaugeGradient } from '../styles/common.js';
|
|
31
31
|
/**
|
|
@@ -75,7 +75,8 @@ function renderGaugeSemi(spec, o) {
|
|
|
75
75
|
// 半圆系的弧最多 180°,large 恒 0(>180° 才为 1,否则值弧会绕到底部走长弧)
|
|
76
76
|
return `M${r2(x0)} ${r2(y0)}A${r2(r)} ${r2(r)} 0 0 1 ${r2(x1)} ${r2(y1)}`;
|
|
77
77
|
};
|
|
78
|
-
const
|
|
78
|
+
const bg = card(width, height, true);
|
|
79
|
+
const parts = [];
|
|
79
80
|
rows.forEach((row, i) => {
|
|
80
81
|
const r = r0 + i * pitch;
|
|
81
82
|
parts.push(`<path d="${arc(r, 1)}" fill="none" stroke="var(--d-faint)" stroke-width="${r2(sw)}" stroke-linecap="round"/>`);
|
|
@@ -83,15 +84,21 @@ function renderGaugeSemi(spec, o) {
|
|
|
83
84
|
parts.push(`<path d="${arc(r, Math.min(row.pct, 100) / 100)}" fill="none" stroke="${sVar(i % skin.series.length)}" stroke-width="${r2(sw)}" stroke-linecap="round"/>`);
|
|
84
85
|
}
|
|
85
86
|
});
|
|
87
|
+
// 单值(没给 data 的那种):环心里写上**读数** ——
|
|
88
|
+
// 光一根弧,读者只能靠弧长猜数值(「87%」还是「80%」?)✗
|
|
89
|
+
if (!spec.data?.length && spec.value !== undefined) {
|
|
90
|
+
const fs = Math.max(22, Math.min(48, r0 * 0.62));
|
|
91
|
+
parts.push(`<text x="${r2(cx)}" y="${r2(cy - r0 * 0.34 + fs * 0.34)}" text-anchor="middle" font-size="${r2(fs)}" font-weight="600" letter-spacing="-0.03em" fill="var(--d-ink)" style="${TAB}">${esc(fmtFull(spec.value))}${spec.max ? `<tspan font-size="${r2(fs * 0.5)}" fill="var(--d-muted)"> / ${esc(fmtFull(spec.max))}</tspan>` : ''}</text>`);
|
|
92
|
+
}
|
|
86
93
|
// 底部图例(多环才显示):方块 + "标签 值%"
|
|
87
94
|
if (spec.data?.length) {
|
|
88
95
|
const items = spec.data.map((d, i) => ({ name: `${trunc(d.label, 12)} ${Math.round(d.value)}%`, color: sVar(i % skin.series.length) }));
|
|
89
96
|
pushLegendRow(parts, items, cx, height * 0.9375, width, (it) => 15 + textW(it.name, 12) + 26, (lx, ly, it) => {
|
|
90
97
|
parts.push(`<rect x="${r2(lx)}" y="${r2(ly - 10)}" width="10" height="10" rx="3" fill="${it.color}"/>`);
|
|
91
|
-
parts.push(`<text x="${r2(lx + 16)}" y="${r2(ly)}" font-size="
|
|
98
|
+
parts.push(`<text x="${r2(lx + 16)}" y="${r2(ly)}" font-size="13" fill="var(--d-muted)">${esc(it.name)}</text>`);
|
|
92
99
|
});
|
|
93
100
|
}
|
|
94
|
-
return svgDoc(width, height, 'gauge', version, spec.title ?? 'gauge', spec, skin, titleBlock(spec.title) + parts.join(''));
|
|
101
|
+
return svgDoc(width, height, 'gauge', version, spec.title ?? 'gauge', spec, skin, bg + titleBlock(spec.title) + subtitleBlock(spec.subtitle) + parts.join(''));
|
|
95
102
|
}
|
|
96
103
|
// 仪表盘 2 · 渐变多环(规范 gauge-2,860×480):
|
|
97
104
|
// 整圆环 pathLength=100 按百分比点亮,环环双色渐变,自顶顺时针
|
|
@@ -145,10 +152,10 @@ function renderGaugeRings(spec, o) {
|
|
|
145
152
|
const items = spec.data.map((d, i) => ({ name: `${trunc(d.label, 12)} ${Math.round(d.value)}%`, grad: i }));
|
|
146
153
|
pushLegendRow(parts, items, width / 2, height * 0.9438, width, (it) => 17 + textW(it.name, 12) + 26, (lx, ly, it) => {
|
|
147
154
|
parts.push(`<rect x="${r2(lx)}" y="${r2(ly - 10)}" width="12" height="10" rx="3" fill="url(#dgg-${it.grad})"/>`);
|
|
148
|
-
parts.push(`<text x="${r2(lx + 18)}" y="${r2(ly)}" font-size="
|
|
155
|
+
parts.push(`<text x="${r2(lx + 18)}" y="${r2(ly)}" font-size="13" fill="var(--d-muted)">${esc(it.name)}</text>`);
|
|
149
156
|
});
|
|
150
157
|
}
|
|
151
|
-
return svgDoc(width, height, 'gauge', version, spec.title ?? 'gauge', spec, skin, titleBlock(spec.title) + parts.join(''));
|
|
158
|
+
return svgDoc(width, height, 'gauge', version, spec.title ?? 'gauge', spec, skin, titleBlock(spec.title) + subtitleBlock(spec.subtitle) + parts.join(''));
|
|
152
159
|
}
|
|
153
160
|
// 分区仪表盘(reliability,规范 饼图 6):四分区圆环 + 中心分值 + 底部区刻度条
|
|
154
161
|
const ZONES = [
|
|
@@ -169,7 +176,7 @@ function renderZoneGauge(spec, o) {
|
|
|
169
176
|
let headSvg = '';
|
|
170
177
|
let headH = 0;
|
|
171
178
|
if (spec.title) {
|
|
172
|
-
headSvg = titleBlock(spec.title, pad);
|
|
179
|
+
headSvg = titleBlock(spec.title, pad) + subtitleBlock(spec.subtitle, pad, !!spec.title);
|
|
173
180
|
headH = 26;
|
|
174
181
|
}
|
|
175
182
|
const barH = 44;
|
|
@@ -178,7 +185,8 @@ function renderZoneGauge(spec, o) {
|
|
|
178
185
|
const R = Math.min(width / 2 - pad - 8, availH / 2 - 4, (168 / 520) * height); // 规范 pie-6:外径 168 封顶
|
|
179
186
|
const cy = pad + headH + availH / 2;
|
|
180
187
|
const r = R * (0.74 / 0.94); // 规范 pie-6:内径 132.3 / 外径 168
|
|
181
|
-
const
|
|
188
|
+
const bg = card(width, height, plain);
|
|
189
|
+
const parts = [];
|
|
182
190
|
// 四分区环:240° 仪表弧,-30° 起逆时针,区序倒排(规范 pie-6);分隔 = 底色描边
|
|
183
191
|
const START6 = -Math.PI / 6;
|
|
184
192
|
const SPAN6 = Math.PI * 2 * (240 / 360);
|
|
@@ -215,5 +223,5 @@ function renderZoneGauge(spec, o) {
|
|
|
215
223
|
prev = z.upto;
|
|
216
224
|
}
|
|
217
225
|
parts.push(`<text x="${r2(width - pad)}" y="${r2(barY - 8)}" text-anchor="end" font-size="11" fill="var(--d-muted)" style="${TAB}">${fmtNum(spec.max)}</text>`);
|
|
218
|
-
return svgDoc(width, height, 'gauge', version, spec.title ?? 'reliability', spec, skin, headSvg + parts.join(''));
|
|
226
|
+
return svgDoc(width, height, 'gauge', version, spec.title ?? 'reliability', spec, skin, bg + headSvg + parts.join(''));
|
|
219
227
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { resolveSkin } from '../styles/index.js';
|
|
2
|
+
import { type DrawResult } from './query.js';
|
|
3
|
+
/** 一个提交 */
|
|
4
|
+
export interface GitCommit {
|
|
5
|
+
id: string;
|
|
6
|
+
/** 所在分支(泳道)名 */
|
|
7
|
+
lane: string;
|
|
8
|
+
/** 提交信息 */
|
|
9
|
+
label?: string;
|
|
10
|
+
/** 父提交 id(第一个) */
|
|
11
|
+
parent?: string;
|
|
12
|
+
/** 第二父(合并提交才有) */
|
|
13
|
+
parent2?: string;
|
|
14
|
+
}
|
|
15
|
+
/** 提交图规格 */
|
|
16
|
+
export interface GitGraphSpec {
|
|
17
|
+
title?: string;
|
|
18
|
+
subtitle?: string;
|
|
19
|
+
/** 分支名(泳道),按顺序 */
|
|
20
|
+
branches: string[];
|
|
21
|
+
/** 提交(按时间顺序) */
|
|
22
|
+
commits: GitCommit[];
|
|
23
|
+
}
|
|
24
|
+
/** 从扁平 URL 参数造规格(参数已 decode) */
|
|
25
|
+
export declare function gitGraphSpecFromParams(params: URLSearchParams): GitGraphSpec;
|
|
26
|
+
/**
|
|
27
|
+
* 解析并校验提交图规格(JSON 形态,给 ?d= 用)。
|
|
28
|
+
*
|
|
29
|
+
* @throws ApiError(400) with a corrective example on bad input
|
|
30
|
+
*/
|
|
31
|
+
export declare function parseGitGraphSpec(raw: string | null): GitGraphSpec;
|
|
32
|
+
export interface GitGraphOpts {
|
|
33
|
+
spec: GitGraphSpec;
|
|
34
|
+
interactive: boolean;
|
|
35
|
+
version: number;
|
|
36
|
+
cacheControl: string;
|
|
37
|
+
skin: ReturnType<typeof resolveSkin>;
|
|
38
|
+
/** 画布宽度上限:?w= 给了就按它画(内容仍按自然尺寸排) */
|
|
39
|
+
width?: number;
|
|
40
|
+
/** 画布高度上限:?h= 给了就按它画 */
|
|
41
|
+
height?: number;
|
|
42
|
+
minW?: number;
|
|
43
|
+
minH?: number;
|
|
44
|
+
tagQuery?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 渲染提交图。
|
|
48
|
+
*/
|
|
49
|
+
export declare function renderGitGraph(spec: GitGraphSpec, o: GitGraphOpts): DrawResult;
|
|
50
|
+
/**
|
|
51
|
+
* `/draw/gitgraph` 入口:GET ?branch=…&commit=…&title=…
|
|
52
|
+
*/
|
|
53
|
+
export declare function renderGitGraphFromUrl(url: URL, interactive?: boolean): DrawResult;
|