@worm-print-platform/echarts 1.5.0 → 1.5.2

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 CHANGED
@@ -1,12 +1,18 @@
1
- # @worm-print-platform/echarts
1
+ <p align="center">
2
+ <strong>@worm-print-platform/echarts</strong><br>
3
+ <em>打印模板 ECharts 图表元素可选包</em>
4
+ </p>
2
5
 
3
- 打印模板的 **ECharts 图表元素可选包**:一个插件注册十个图表元素,提供 SVG 渲染器(echarts SSR)、
4
- 页面执行器、设计器画布 / 图形化属性面板与共享数据契约。
5
- 主包 `@worm-print-platform/core` 与 `@worm-print-platform/canvas` 不依赖任何图表库,只有本包引入 `echarts`。
6
+ <p align="center">
7
+ <img src="https://img.shields.io/badge/npm-v1.5.2-384BFF" alt="npm">
8
+ <img src="https://img.shields.io/badge/license-MIT-9A9A9A" alt="license">
9
+ </p>
6
10
 
7
- **「import 即注册」**:宿主不需要写任何注册代码,也不需要手写渲染器传参。
11
+ > monorepo 根:[worm-print-platform](https://github.com/worm-longliu/worm-print-platform)
12
+
13
+ 一个插件注册十个图表元素:提供 ECharts SSR SVG 渲染器、页面执行器、设计器画布 / 图形化属性面板与共享数据契约。主包 `@worm-print-platform/core` 与 `@worm-print-platform/canvas` **不依赖任何图表库**,只有本包引入 `echarts`(Apache-2.0)。
8
14
 
9
- > 状态:本包随工作区主线开发,**尚未发布到 npm**;请以工作区依赖或源码方式引入。
15
+ **「import 即注册」**:宿主不需要写任何注册代码,也不需要手写渲染器传参。
10
16
 
11
17
  ## 安装
12
18
 
@@ -14,57 +20,48 @@
14
20
  npm i @worm-print-platform/echarts
15
21
  ```
16
22
 
17
- `echarts`(^6.1.0,Apache-2.0)由本包作为 dependency 安装;`@worm-print-platform/core`、
18
- `@worm-print-platform/plugin-kit` 同样以 dependency 引入。
23
+ 依赖:`echarts`(^6.1.0)、`@worm-print-platform/core`、`@worm-print-platform/plugin-kit`
19
24
 
20
25
  ## 十个元素
21
26
 
22
27
  | type | 元素 | 默认尺寸 | 数据映射要点 |
23
28
  | --- | --- | --- | --- |
24
- | `barChart` | 柱状图 | 100×60 | 类目 + 多数值字段(多值多系列) |
25
- | `barHChart` | 条形图(横向) | 100×60 | 类目写 yAxis,xAxis 为数值 |
26
- | `lineChart` | 折线图 | 100×60 | 同柱状图,series 为 line |
27
- | `areaChart` | 面积图 | 100×60 | 折线 + areaStyle |
28
- | `pieChart` | 饼图 | 60×60 | 类目 + 首数值 → `{ name, value }` |
29
- | `doughnutChart` | 环形图 | 60×60 | 饼图 + 可配内径 |
30
- | `scatterChart` | 散点图 | 80×60 | 类目作 x、首数值作 y;`chartBubble` 开启时第二数值作点大小 |
31
- | `radarChart` | 雷达图 | 70×60 | 数值字段=维度,每行一个系列 |
32
- | `funnelChart` | 漏斗图 | 60×60 | 类目 + 首数值,按数值降序 |
33
- | `gaugeChart` | 仪表盘 | 60×60 | 取首行首值;min/max 面板可配 |
34
-
35
- 所有元素共用同一份数据契约:`chartOption` + `chartDataSource` / `chartCategoryField` /
36
- `chartValueFields` / `chartSeriesField`(散点另有 `chartBubble`)。
37
- 模板只存 option 模板与字段映射,真实数据由 core 绑定阶段注入;`series[].data` 写 `$data` 占位即可。
29
+ | `barChart` | 柱状图 | 100×60mm | 类目 + 多数值字段(多值多系列) |
30
+ | `barHChart` | 条形图(横向) | 100×60mm | 类目写 yAxis,xAxis 为数值 |
31
+ | `lineChart` | 折线图 | 100×60mm | 同柱状图,series 为 line |
32
+ | `areaChart` | 面积图 | 100×60mm | 折线 + areaStyle |
33
+ | `pieChart` | 饼图 | 60×60mm | 类目 + 首数值 → `{ name, value }` |
34
+ | `doughnutChart` | 环形图 | 60×60mm | 饼图 + 可配内径 |
35
+ | `scatterChart` | 散点图 | 80×60mm | 类目作 x、首数值作 y;`chartBubble` 开启时第二数值作点大小 |
36
+ | `radarChart` | 雷达图 | 70×60mm | 数值字段 = 维度,每行一个系列 |
37
+ | `funnelChart` | 漏斗图 | 60×60mm | 类目 + 首数值,按数值降序 |
38
+ | `gaugeChart` | 仪表盘 | 60×60mm | 取首行首值;min/max 面板可配 |
39
+
40
+ 所有元素共用同一份数据契约:`chartOption` + `chartDataSource` / `chartCategoryField` / `chartValueFields` / `chartSeriesField`。模板只存 option 模板与字段映射,真实数据由 core 绑定阶段注入。
38
41
 
39
42
  ## 用法
40
43
 
41
44
  ### 设计器 / 浏览器宿主
42
45
 
43
46
  ```ts
44
- // 一行副作用 import:素材卡、画布组件、「自定义属性」tab、校验、绑定、出图全部生效
47
+ // 一行副作用 import:素材卡、画布、属性面板、校验、绑定、出图全部生效
45
48
  import '@worm-print-platform/echarts'
46
49
  ```
47
50
 
48
51
  ### 服务端 PDF / Electron 主进程
49
52
 
50
53
  ```ts
51
- // ① 部署白名单:显式 import 才允许该插件进入注册表(模板字符串无法触发 import())
54
+ // ① 部署白名单:显式 import 才允许该插件进入注册表
52
55
  import '@worm-print-platform/echarts/node'
53
56
 
54
- // ② runtime 装配:扩展元素执行器由注册表自动收集,新增插件无需改这行代码
57
+ // ② runtime 装配:执行器由注册表自动收集,新增插件无需改这行
55
58
  import { collectExecutorBundles, createDomHostRuntime } from '@worm-print-platform/core'
56
59
  createDomHostRuntime(factory, loadExecutorBundle(), collectExecutorBundles())
57
60
  ```
58
61
 
59
- `/node` 子路径会为描述符补上 `render.executorBundle()`(惰性读取 IIFE 产物),
60
- `collectExecutorBundles()` 因此能按注册态收集;插件同时提供 `createRenderer()`,
61
- 正常路径走**进程内 SSR 出图**,页面执行器只在宿主没有进程内能力时才需要。
62
- 执行器注入后挂在 `globalThis.__wormDom.renderAssets(specs)`(与 core 的 `renderAssets` 协议同名)。
63
-
64
62
  ### 零框架宿主 / 自建设计器 UI(`/kit`)
65
63
 
66
- `/kit` 是**框架无关的纯 TS 出口**:不包含任何 `.vue` 组件、不读磁盘,import 即把十个 kind 注册到
67
- core 插件注册表,但**不**注册设计器组件与执行器产物。零框架宿主用它自建画布与属性台:
64
+ `/kit` 是**框架无关的纯 TS 出口**:不包含任何 `.vue` 组件、不读磁盘,import 即把十个 kind 注册到 core 插件注册表,但**不**注册设计器组件与执行器产物。
68
65
 
69
66
  ```ts
70
67
  import {
@@ -73,81 +70,50 @@ import {
73
70
  } from '@worm-print-platform/echarts/kit'
74
71
  ```
75
72
 
76
- `/ui` 就是基于 `/kit` + `@worm-print-platform/plugin-kit` 的适配层(拆仓前旧名 `echarts-common`)
77
- (静态 SVG 画布 + 原生 DOM 属性面板);框架无关宿主不必重复实现面板读取/写回逻辑。
78
-
79
- ## 配置(`configureChartPlugin`)
80
-
81
- 配置是**惰性**的:可在注册前调用、按键合并,不需要注销重注册。
73
+ ## 配置
82
74
 
83
75
  ```ts
84
76
  import { configureChartPlugin } from '@worm-print-platform/echarts'
85
77
 
86
78
  configureChartPlugin({
87
- defaultWidth: 120, // 新建图表元素的全局默认尺寸(kind 自带默认值,配置优先)
79
+ defaultWidth: 120, // 新建图表元素的全局默认尺寸
88
80
  defaultHeight: 70,
89
81
  palettes: {
90
- default: { label: '企业蓝', colors: ['#165DFF', '#36B37E'] }, // 覆盖同名预设
91
- brand: { label: '品牌色', colors: ['#F2704E', '#F7A35C'] }, // 追加新配色
82
+ default: { label: '企业蓝', colors: ['#165DFF', '#36B37E'] },
83
+ brand: { label: '品牌色', colors: ['#F2704E', '#F7A35C'] },
92
84
  },
93
85
  sampleCategories: ['一季度', '二季度', '三季度'],
94
- components: [GaugeChart], // 追加 echarts.use 的图表/组件构造器
86
+ components: [GaugeChart], // 追加 echarts.use 的图表/组件构造器
95
87
  })
96
88
  ```
97
89
 
98
- | 键 | 作用 |
99
- | --- | --- |
100
- | `defaultWidth` / `defaultHeight` | 新建图表元素的默认 mm 尺寸(kind 默认尺寸可被覆盖) |
101
- | `palettes` | 覆盖同名预设配色或新增配色,属性台下拉即时可见 |
102
- | `sampleCategories` | 设计态无绑定数据时 `$data` 占位的示例类目 |
103
- | `components` | 追加 `echarts.use` 图表/组件;按引用去重,改配置后下次出图生效 |
90
+ 配置是**惰性**的:可在注册前调用、按键合并,不需要注销重注册。
104
91
 
105
92
  ## 导出
106
93
 
107
94
  | 子路径 | 内容 |
108
95
  | --- | --- |
109
- | `.` | `CHART_PLUGIN` / `CHART_PLUGIN_ID` / `CHART_KINDS` / `CHART_KIND_DEFINITIONS` / `getChartKindDefinition` / `resolveChartPanelFields` / `createDefaultChartOption` / `normalizeChartOption` / `bindChartData` / `renderChartToSvg` / `renderChartElement` / `fitSvgRoot` / `mmToChartPx` / `configureChartPlugin` / `getChartPluginConfig` / `getChartPalettes` / `getSampleCategories` / `chartFactoryDefaults` / `registerChartPlugin` / `uninstallChartPlugin` / `installChartDesigner` / `uninstallChartDesigner` |
110
- | `./kit` | 框架无关纯 TS 出口(无 Vue、无 `node:fs`):注册副作用 + 上表纯逻辑能力 + 常量(`CHART_PALETTES` / `FUNNEL_PADDING_DEFAULTS` / `RADAR_RADIUS_DEFAULT` 等)与面板读写工具(`previewChartOption` / `readPaletteKey` / `syncSeriesCount` / `readFunnelPadding` / `writeFunnelPadding` / `readRadarRadius` / `writeRadarRadius`) |
111
- | `./node` | 注册副作用 + `render.executorBundle()`(惰性读取 IIFE 产物,纯 TS、不含 Vue) |
112
- | `./browser/executor.iife` | 页面注入用 IIFE(echarts 已打入,自包含);带 `types` 条件 |
113
-
114
- `type-augmentation.ts` 用声明合并把十个图表类型与 `chartOption` 等专属字段注入 core 的类型扩展点,
115
- 并带编译期自校验——已装包宿主的 `Record<ElementType, T>` 穷尽映射无需改动。
96
+ | `.` | `CHART_PLUGIN` / `CHART_KIND_DEFINITIONS` / `createDefaultChartOption` / `renderChartToSvg` / `configureChartPlugin` 等(注册副作用 + 纯 TS 能力) |
97
+ | `/kit` | 框架无关纯 TS 出口(无 Vue、无 `node:fs`) |
98
+ | `/node` | 注册副作用 + `render.executorBundle()`(惰性读取 IIFE 产物,服务端装配用) |
99
+ | `/ui` | plugin-kit 设计器 UI(静态 SVG 画布 + 原生 DOM 属性面板) |
100
+ | `/browser` | UMD bundle(`dist/echarts.js`) |
116
101
 
117
- ## 设计器属性面板
102
+ `type-augmentation.ts` 用声明合并把十个图表类型与 `chartOption` 等专属字段注入 core 的类型扩展点。
118
103
 
119
- - **只提供图形化配置**:数据源 / 类目字段 / 数值字段 / 系列拆分 / 标题 / 图例 / 配色 /
120
- 堆叠 / 气泡 / 内径 / 仪表盘范围 / 漏斗内边距 / 雷达半径,按元素类型裁剪;不提供 JSON 编辑器。
121
- - 模板 JSON 仍允许手写 `chartOption`(开发者与 AI 的出口),面板只改自己掌管的字段。
122
- - 提交通道:`emit('change')`(记历史)、`emit('update:options', partial)`(受控合并)。
104
+ ## 开发
123
105
 
124
- ## 留白(内边距 / 半径)
125
-
126
- ECharts 的图表内边距是 option 自身的布局参数,插件负责给出适合打印小框的出厂值,并把这几个值放进属性台。
127
-
128
- | 元素 | 面板控件 | 落到 chartOption | 出厂默认 |
129
- | --- | --- | --- | --- |
130
- | `funnelChart` | 内边距 上/右/下/左 (%) | `series[].top/right/bottom/left` | `6% / 25% / 6% / 5%` |
131
- | `radarChart` | 半径 (%) | `radar.radius` | `75%` |
132
-
133
- - **漏斗图**不写内边距时会吃 ECharts 的 px 默认(左右 80、上 60、下 65),60×60mm 的元素框里图形只剩一半不到;
134
- 现阶段默认把四边压到 5~6%,右侧保留 25% 给**外置标签与引导线**(标签超出元素框会被 `overflow:hidden` 裁掉,
135
- 不要为了铺满把右边距调到 10% 以下;标签想更靠边可以手写 `series.label.position: 'inside'`)。
136
- - **雷达图**的 ECharts 6 默认 `radar.radius` 是 `50%`(5.x 是 `75%`),70×60mm 框里图形直径只有短边一半,
137
- 默认值已恢复为 `75%`;想更大可调到 `80%` 左右,再大轴名会顶到框边。
138
- - 面板显示统一为百分比:手写 `chartOption` 里的 px 数字会按当前元素框折算成百分比回读。
139
- - 出厂默认只作用于**新建元素**;存量模板的 `chartOption` 已落盘,出图不变,需要时在属性台或模板 JSON 里改。
140
-
141
- ## SVG 根节点处理
106
+ ```bash
107
+ npm run build # vite + tsc + tsup
108
+ npm test # vitest
109
+ ```
142
110
 
143
- echarts SSR 产出「固定 px 宽高 + viewBox」的独立 SVG。`renderChartToSvg` 归一为可内联铺满 mm 盒子的矢量图:
111
+ ## 相关链接
144
112
 
145
- - `width` / `height` → `100%`;
146
- - `viewBox="0 0 宽 高"`(96dpi:`px = mm * 96 / 25.4` 取整);
147
- - 根节点样式固定 `display:block;width:100%;height:100%`。
113
+ - [根 README](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md)
114
+ - [插件化自定义元素章节](https://github.com/worm-longliu/worm-print-platform/blob/main/README.md#插件化自定义元素)
115
+ - [plugin-kit 契约](../plugin-kit/README.md)
148
116
 
149
- ## 构建
117
+ ## License
150
118
 
151
- ```bash
152
- npm run build -w @worm-print-platform/echarts
153
- ```
119
+ [MIT](../../LICENSE)
package/dist/bind.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.0
2
+ * @worm-print-platform/echarts v1.5.2
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.0
2
+ * @worm-print-platform/echarts v1.5.2
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.0
2
+ * @worm-print-platform/echarts v1.5.2
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
package/dist/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.0
2
+ * @worm-print-platform/echarts v1.5.2
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.0
2
+ * @worm-print-platform/echarts v1.5.2
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.0
2
+ * @worm-print-platform/echarts v1.5.2
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT
package/dist/echarts.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @worm-print-platform/echarts v1.5.0
2
+ * @worm-print-platform/echarts v1.5.2
3
3
  * Copyright (c) 2026 worm <liu_long_qqcom@qq.com>
4
4
  * SPDX-FileCopyrightText: 2026 worm <liu_long_qqcom@qq.com>
5
5
  * SPDX-License-Identifier: MIT