@x-cmd/draw 0.5.8 → 0.5.9
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.
|
@@ -68,6 +68,18 @@ export declare const HEAD_RULES: {
|
|
|
68
68
|
export declare function headLayout(option: Obj): void;
|
|
69
69
|
/** 把用户的 option 补齐缺省(皮肤色板/字体/轴/标题/图例)—— **浏览器端也用这一份** */
|
|
70
70
|
export declare function echartsOption(user: Obj, skin: Skin, width: number, height: number): EChartsOption;
|
|
71
|
+
/**
|
|
72
|
+
* 扇区/块**里面**的字:颜色跟**那一块的底色**走。
|
|
73
|
+
*
|
|
74
|
+
* 浅块用深字、深块用白字 —— 漏斗最下面那块深蓝上的字用深色就看不见了 ✗(#188)。
|
|
75
|
+
* 规则跟地图那一处一样(inkOf),只是这边算的是**色板**上的颜色。
|
|
76
|
+
*
|
|
77
|
+
* 只在用户没写颜色时落值(用户值恒优先)✓;
|
|
78
|
+
* 服务端与浏览器端**共用这一份** ⇒ 两端同图 ✓。
|
|
79
|
+
*/
|
|
80
|
+
export declare function applyInsideLabelInk(option: Obj, skin: Skin): void;
|
|
81
|
+
/** 一块底色上的字该是什么色:底色亮 ⇒ 墨字,底色暗 ⇒ 白字 */
|
|
82
|
+
export declare function inkOn(hex: string): string;
|
|
71
83
|
/**
|
|
72
84
|
* Render a parsed ECharts option object to a skinned SVG — shared by the HTTP
|
|
73
85
|
* layer (`?d=` urlencoded JSON) and the CLI (inline JSON / file / stdin, where
|
|
@@ -252,6 +252,8 @@ export function echartsOption(user, skin, width, height) {
|
|
|
252
252
|
fillDefaults(option.legend, { textStyle: { color: 'var(--d-muted)' } });
|
|
253
253
|
// 标题带/图例/绘图区排开:图例在顶部时不能压住标题(仓库硬规则:文字不得重叠)
|
|
254
254
|
headLayout(option);
|
|
255
|
+
// 块里面的字按那一块的底色取色(漏斗那块深蓝上的字原先是深色 ⇒ 看不见 ✗)
|
|
256
|
+
applyInsideLabelInk(option, skin);
|
|
255
257
|
// SSR 补轴:echarts SSR 不像浏览器那样为笛卡尔系列自动建坐标系,裸 option 会抛
|
|
256
258
|
// 'xAxis "0" not found'。按浏览器对等行为补空轴对象({} = 缺省 x=category/y=value),
|
|
257
259
|
// 仅在用户完全没写该轴时落;写了一根(多轴场景)也不动
|
|
@@ -301,6 +303,56 @@ export function echartsOption(user, skin, width, height) {
|
|
|
301
303
|
}
|
|
302
304
|
return option;
|
|
303
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* 扇区/块**里面**的字:颜色跟**那一块的底色**走。
|
|
308
|
+
*
|
|
309
|
+
* 浅块用深字、深块用白字 —— 漏斗最下面那块深蓝上的字用深色就看不见了 ✗(#188)。
|
|
310
|
+
* 规则跟地图那一处一样(inkOf),只是这边算的是**色板**上的颜色。
|
|
311
|
+
*
|
|
312
|
+
* 只在用户没写颜色时落值(用户值恒优先)✓;
|
|
313
|
+
* 服务端与浏览器端**共用这一份** ⇒ 两端同图 ✓。
|
|
314
|
+
*/
|
|
315
|
+
export function applyInsideLabelInk(option, skin) {
|
|
316
|
+
const series = Array.isArray(option.series) ? option.series : isObj(option.series) ? [option.series] : [];
|
|
317
|
+
for (const s of series) {
|
|
318
|
+
if (!isObj(s) || s.type !== 'funnel')
|
|
319
|
+
continue;
|
|
320
|
+
// 标签在块**里面**才需要跟着底色走(在外面的字压在页面上 ⇒ 用墨色 ✓)
|
|
321
|
+
if (!isObj(s.label) || s.label.position !== 'inside')
|
|
322
|
+
continue;
|
|
323
|
+
if (!Array.isArray(s.data))
|
|
324
|
+
continue;
|
|
325
|
+
s.data.forEach((it, i) => {
|
|
326
|
+
if (!isObj(it))
|
|
327
|
+
return;
|
|
328
|
+
const duo = skin.series[i];
|
|
329
|
+
const hex = pickHex(it, duo, skin.scheme);
|
|
330
|
+
if (!hex)
|
|
331
|
+
return;
|
|
332
|
+
const label = isObj(it.label) ? { ...it.label } : {};
|
|
333
|
+
if (label.color === undefined)
|
|
334
|
+
label.color = inkOn(hex);
|
|
335
|
+
it.label = label;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** 这一块的颜色:显式写的 ?? 色板上的第 i 号(按当前明暗取那一档) */
|
|
340
|
+
function pickHex(item, duo, scheme) {
|
|
341
|
+
const own = isObj(item.itemStyle) && typeof item.itemStyle.color === 'string' ? item.itemStyle.color : undefined;
|
|
342
|
+
if (own)
|
|
343
|
+
return own;
|
|
344
|
+
if (typeof item.color === 'string')
|
|
345
|
+
return item.color;
|
|
346
|
+
return duo ? duo[scheme === 'dark' ? 'dark' : 'light'] : undefined;
|
|
347
|
+
}
|
|
348
|
+
/** 一块底色上的字该是什么色:底色亮 ⇒ 墨字,底色暗 ⇒ 白字 */
|
|
349
|
+
export function inkOn(hex) {
|
|
350
|
+
const m = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex.trim());
|
|
351
|
+
if (!m)
|
|
352
|
+
return 'var(--d-text)';
|
|
353
|
+
const [r, g, b] = [m[1], m[2], m[3]].map((h) => parseInt(h, 16));
|
|
354
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b < 140 ? '#ffffff' : '#0f172a';
|
|
355
|
+
}
|
|
304
356
|
// 无障碍标签:取 title.text(与核心层 aria=标题 的约定一致)
|
|
305
357
|
function ariaOf(option) {
|
|
306
358
|
const t = option.title;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-cmd/draw",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
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",
|