@x-cmd/draw 0.4.4 → 0.4.5
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/dist/render/ladder.js +28 -11
- package/package.json +1 -1
package/dist/render/ladder.js
CHANGED
|
@@ -21,11 +21,19 @@ function tierGroups(tiers) {
|
|
|
21
21
|
}
|
|
22
22
|
/** 档位名列:组名竖排在组中间(组太矮就排在组首行上) */
|
|
23
23
|
/** 一根柱 */
|
|
24
|
-
function bar(x0, y, len, h, color, tip) {
|
|
24
|
+
function bar(x0, y, len, h, color, tip, row = -1) {
|
|
25
25
|
return [
|
|
26
|
-
`<rect x="${r2(x0)}" y="${r2(y)}" width="${r2(Math.max(len, 1))}" height="${r2(h)}" rx="4" fill="${color}"${tip ? ` data-tip="${esc(tip)}"` : ''}/>`,
|
|
26
|
+
`<rect${row >= 0 ? ` data-row="${row}"` : ''} x="${r2(x0)}" y="${r2(y)}" width="${r2(Math.max(len, 1))}" height="${r2(h)}" rx="4" fill="${color}"${tip ? ` data-tip="${esc(tip)}"` : ''}/>`,
|
|
27
27
|
];
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* 行底色:鼠标悬停时**整行**亮一下 ✓
|
|
31
|
+
* (垫色,不要描边 ✓ —— 描边会像选中框 ✗)
|
|
32
|
+
* 它同时是这一行的「悬停热区」✓ —— 悬在行里的空白处也能亮 ✓。
|
|
33
|
+
*/
|
|
34
|
+
function rowBand(x, y, w, h, row, tip) {
|
|
35
|
+
return `<rect class="row-band" data-row="${row}" x="${r2(x)}" y="${r2(y)}" width="${r2(w)}" height="${r2(h)}" fill="var(--d-ink)" fill-opacity="0"${tip ? ` ${tip}` : ''}/>`;
|
|
36
|
+
}
|
|
29
37
|
/**
|
|
30
38
|
* 天梯图(单边)。
|
|
31
39
|
*
|
|
@@ -122,11 +130,14 @@ export function renderLadder(spec, o) {
|
|
|
122
130
|
const tip = o.interactive
|
|
123
131
|
? ` data-tip="${esc(`${it.label ?? ''} · ${fmtFull(it.value)}${spec.unit ? ' ' + spec.unit : ''}`)}"`
|
|
124
132
|
: '';
|
|
125
|
-
|
|
133
|
+
const row = ` data-row="${i}"`;
|
|
134
|
+
// 行底色(悬停整行亮 ✓)—— 画在柱与字之前,垫在最下面 ✓
|
|
135
|
+
parts.push(rowBand(PAD, contentTop + i * pitch, right - PAD, pitch, i, tip));
|
|
136
|
+
parts.push(...bar(left, y, len, barH, color, tip, i));
|
|
126
137
|
if (it.label) {
|
|
127
|
-
parts.push(`<text x="${r2(PAD)}" y="${r2(y + barH / 2 + 4)}" text-anchor="start" font-size="12.5" fill="var(--d-text)">${esc(trunc(stripped(it.label, spec), cap))}</text>`);
|
|
138
|
+
parts.push(`<text${row}${tip} x="${r2(PAD)}" y="${r2(y + barH / 2 + 4)}" text-anchor="start" font-size="12.5" fill="var(--d-text)">${esc(trunc(stripped(it.label, spec), cap))}</text>`);
|
|
128
139
|
}
|
|
129
|
-
parts.push(`<text x="${r2(right + 8)}" y="${r2(y + barH / 2 + 4)}" font-size="12" font-weight="600" fill="var(--d-text)"${tip}>${fmtFull(it.value)}</text>`);
|
|
140
|
+
parts.push(`<text${row} x="${r2(right + 8)}" y="${r2(y + barH / 2 + 4)}" font-size="12" font-weight="600" fill="var(--d-text)"${tip}>${fmtFull(it.value)}</text>`);
|
|
130
141
|
});
|
|
131
142
|
const legend = legendItems.length
|
|
132
143
|
? `<g data-legend="types">${legendItems.map((l, i) => `<rect x="${r2(PAD + i * 130)}" y="${r2(contentTop - LEGEND_H + 5)}" width="15" height="15" rx="4" fill="${l.color}" fill-opacity="0.2" stroke="${l.color}" stroke-opacity="0.55"/><text x="${r2(PAD + i * 130 + 22)}" y="${r2(contentTop - LEGEND_H + 17)}" font-size="12" fill="var(--d-muted)">${esc(l.name)}</text>`).join('')}</g>`
|
|
@@ -206,30 +217,36 @@ export function renderButterflyLadder(spec, o) {
|
|
|
206
217
|
}
|
|
207
218
|
rows.forEach(([l, r], i) => {
|
|
208
219
|
const y = yOf(i);
|
|
220
|
+
const row = ` data-row="${i}"`;
|
|
221
|
+
// 行底色(悬停整行亮 ✓)—— 一行两翼一起亮 ✓
|
|
222
|
+
const bandTip = o.interactive
|
|
223
|
+
? ` data-tip="${esc(`${l?.label ?? ''}${r?.label ? ` · ${r.label}` : ''}`)}"`
|
|
224
|
+
: '';
|
|
225
|
+
parts.push(rowBand(PAD, contentTop + i * pitch, width - PAD * 2, pitch, i, bandTip));
|
|
209
226
|
if (l) {
|
|
210
227
|
const len = (l.value / (leftMax || 1)) * half;
|
|
211
228
|
const tip = o.interactive
|
|
212
229
|
? ` data-tip="${esc(`${l.label ?? ''} · ${fmtFull(l.value)}${spec.unit ? ' ' + spec.unit : ''}`)}"`
|
|
213
230
|
: '';
|
|
214
|
-
parts.push(...bar(centre - len, y, len, barH, itemColor(l, spec.left, sVar(0)), tip));
|
|
231
|
+
parts.push(...bar(centre - len, y, len, barH, itemColor(l, spec.left, sVar(0)), tip, i));
|
|
215
232
|
if (l.label) {
|
|
216
|
-
parts.push(`<text x="${r2(PAD)}" y="${r2(y + barH / 2 + 4)}" text-anchor="start" font-size="12.5" fill="var(--d-text)">${esc(trunc(stripped(l.label, spec), cap))}</text>`);
|
|
233
|
+
parts.push(`<text${row}${tip} x="${r2(PAD)}" y="${r2(y + barH / 2 + 4)}" text-anchor="start" font-size="12.5" fill="var(--d-text)">${esc(trunc(stripped(l.label, spec), cap))}</text>`);
|
|
217
234
|
}
|
|
218
235
|
// 数值:**一律画在 bar 外面** ✓(两边一致 ✓ —— 「左边的数据在 bar 里、右边在外面」看着别扭 ✓)
|
|
219
236
|
// 左边的柱往左长 ⇒ 数值在尾端的左边 ✓(紧挨着名字列 ✓)
|
|
220
|
-
parts.push(`<text x="${r2(centre - len - 8)}" y="${r2(y + barH / 2 + 4)}" text-anchor="end" font-size="12" font-weight="600" fill="var(--d-text)">${fmtFull(l.value)}</text>`);
|
|
237
|
+
parts.push(`<text${row} x="${r2(centre - len - 8)}" y="${r2(y + barH / 2 + 4)}" text-anchor="end" font-size="12" font-weight="600" fill="var(--d-text)"${tip}>${fmtFull(l.value)}</text>`);
|
|
221
238
|
}
|
|
222
239
|
if (r) {
|
|
223
240
|
const len = (r.value / (rightMax || 1)) * half;
|
|
224
241
|
const tip = o.interactive
|
|
225
242
|
? ` data-tip="${esc(`${r.label ?? ''} · ${fmtFull(r.value)}${spec.unit ? ' ' + spec.unit : ''}`)}"`
|
|
226
243
|
: '';
|
|
227
|
-
parts.push(...bar(centre, y, len, barH, itemColor(r, spec.right, sVar(1)), tip));
|
|
244
|
+
parts.push(...bar(centre, y, len, barH, itemColor(r, spec.right, sVar(1)), tip, i));
|
|
228
245
|
if (r.label) {
|
|
229
|
-
parts.push(`<text x="${r2(plotR + VALUE_W + 10)}" y="${r2(y + barH / 2 + 4)}" font-size="12.5" fill="var(--d-text)">${esc(trunc(stripped(r.label, spec), cap))}</text>`);
|
|
246
|
+
parts.push(`<text${row}${tip} x="${r2(plotR + VALUE_W + 10)}" y="${r2(y + barH / 2 + 4)}" font-size="12.5" fill="var(--d-text)">${esc(trunc(stripped(r.label, spec), cap))}</text>`);
|
|
230
247
|
}
|
|
231
248
|
// 右边同样:**一律画在 bar 外面** ✓
|
|
232
|
-
parts.push(`<text x="${r2(centre + len + 8)}" y="${r2(y + barH / 2 + 4)}" text-anchor="start" font-size="12" font-weight="600" fill="var(--d-text)">${fmtFull(r.value)}</text>`);
|
|
249
|
+
parts.push(`<text${row} x="${r2(centre + len + 8)}" y="${r2(y + barH / 2 + 4)}" text-anchor="start" font-size="12" font-weight="600" fill="var(--d-text)"${tip}>${fmtFull(r.value)}</text>`);
|
|
233
250
|
}
|
|
234
251
|
});
|
|
235
252
|
const legend = legendItems.length
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-cmd/draw",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "SVG chart rendering as a service, a library, and a CLI — pie/bar/hbar/line/area/radar/gauge/scatter/combo/sankey/qr, same params everywhere",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|