@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 +52 -86
- package/dist/bind.d.ts +1 -1
- package/dist/browser/executor.iife.d.ts +1 -1
- package/dist/browser-bundle.d.ts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/defaults.d.ts +1 -1
- package/dist/echarts.d.ts +1 -1
- package/dist/echarts.js +8 -8
- package/dist/executor.iife.global.d.ts +1 -1
- package/dist/executor.iife.global.js +14 -14
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/kinds.d.ts +1 -1
- package/dist/kit.cjs +1 -1
- package/dist/kit.d.ts +1 -1
- package/dist/kit.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/normalize.d.ts +1 -1
- package/dist/option-utils.d.ts +1 -1
- package/dist/plugin-Bf6QDbHO.cjs +1 -1
- package/dist/plugin-CUoE2jMs.js +1 -1
- package/dist/plugin.d.ts +1 -1
- package/dist/renderer.d.ts +1 -1
- package/dist/type-augmentation.d.ts +1 -1
- package/dist/ui.cjs +23 -28
- package/dist/ui.d.ts +1 -1
- package/dist/ui.js +23 -28
- package/dist/units.d.ts +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>@worm-print-platform/echarts</strong><br>
|
|
3
|
+
<em>打印模板 ECharts 图表元素可选包</em>
|
|
4
|
+
</p>
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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×
|
|
25
|
-
| `barHChart` | 条形图(横向) | 100×
|
|
26
|
-
| `lineChart` | 折线图 | 100×
|
|
27
|
-
| `areaChart` | 面积图 | 100×
|
|
28
|
-
| `pieChart` | 饼图 | 60×
|
|
29
|
-
| `doughnutChart` | 环形图 | 60×
|
|
30
|
-
| `scatterChart` | 散点图 | 80×
|
|
31
|
-
| `radarChart` | 雷达图 | 70×
|
|
32
|
-
| `funnelChart` | 漏斗图 | 60×
|
|
33
|
-
| `gaugeChart` | 仪表盘 | 60×
|
|
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
|
|
47
|
+
// 一行副作用 import:素材卡、画布、属性面板、校验、绑定、出图全部生效
|
|
45
48
|
import '@worm-print-platform/echarts'
|
|
46
49
|
```
|
|
47
50
|
|
|
48
51
|
### 服务端 PDF / Electron 主进程
|
|
49
52
|
|
|
50
53
|
```ts
|
|
51
|
-
// ① 部署白名单:显式 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
|
-
|
|
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,
|
|
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],
|
|
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` / `
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
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
|
-
|
|
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
|
-
|
|
111
|
+
## 相关链接
|
|
144
112
|
|
|
145
|
-
-
|
|
146
|
-
-
|
|
147
|
-
-
|
|
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
|
-
|
|
152
|
-
npm run build -w @worm-print-platform/echarts
|
|
153
|
-
```
|
|
119
|
+
[MIT](../../LICENSE)
|
package/dist/bind.d.ts
CHANGED
package/dist/browser-bundle.d.ts
CHANGED
package/dist/config.d.ts
CHANGED
package/dist/constants.d.ts
CHANGED
package/dist/defaults.d.ts
CHANGED
package/dist/echarts.d.ts
CHANGED