@damoqiongqiu/ice-chart 0.19.0 → 0.19.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 CHANGED
@@ -115,7 +115,7 @@ gray-100~900、`--bs-border-radius`、`--bs-body-font-family`),图表放进
115
115
  | 系列类型 | line / area / bar(含横向)/ scatter(含气泡)/ pie(含环形、玫瑰)/ radar / candlestick / heatmap / sankey / funnel / gauge / boxplot / waterfall / treemap / graph / function / parametric | 见下方「图表类型与写法」 |
116
116
  | 比例尺 | linear / category / time / log | time 轴按跨度自动切换毫秒~年粒度 |
117
117
  | 坐标系 | 直角坐标 / 极坐标(饼图) / 雷达 / 桑基图 | 按系列类型自动切换场景 |
118
- | 坐标轴 | x + **多 y 轴**(左右可配) | 刻度、网格、轴名、标签旋转与自动抽稀、自定义 formatter |
118
+ | 坐标轴 | x + **多 y 轴**(左右可配) | 刻度、网格、轴名、标签旋转与自动抽稀、自定义 formatter、**数据域留白 `padding`(默认 5%)** |
119
119
  | 图例 | top / bottom / left / right | **可点击切换系列 / 扇区显隐**并重算数据域 |
120
120
  | 提示框 | axis / item 触发器 | 画在画布内(小程序同样可用);K 线给 OHLC、桑基给流量 |
121
121
  | 十字准星 | x / y / xy | 带坐标轴数值标签;跟随时长按距离缩放(`crosshair.followDuration`,默认上限 90ms,`0` = 立即跟随) |
@@ -137,6 +137,8 @@ gray-100~900、`--bs-border-radius`、`--bs-body-font-family`),图表放进
137
137
  > 断行与文字方向(`direction` / `textAlign: 'start' | 'end'`)由引擎负责。
138
138
  > 边界契约见 ice-render 的 `docs/architecture/17-i18n-boundary.md`。
139
139
  | 序列化 | `toJSON` / `fromJSONString` | 配置 + 缩放窗口 + 图例显隐状态 |
140
+ | 自定义系列 | `registerSeriesType(type, factory)` | 任何 `SeriesBase` 子类接入成一等系列:命中 / 悬停 / 提示框 / 图例 / 序列化全部自动生效 |
141
+ | 数据坐标图元 | `addMark()` | 注释卡片 / 阈值线 / 目标线 / 预测带挂在**数据坐标**上,缩放平移与数据更新后不脱锚;组件就是引擎图元(带命中、事件、动画) |
140
142
 
141
143
  ## 事件
142
144
 
@@ -153,6 +155,8 @@ gray-100~900、`--bs-border-radius`、`--bs-body-font-family`),图表放进
153
155
  | `select:change` | `DataPointParams[]` | 选中集合变化 |
154
156
  | `brush:change` | `BrushRange \| null` | 框选拖动中(实时) |
155
157
  | `brush:end` | `BrushRange \| null` | 框选结束 |
158
+ | `mark:drag` | `ChartMarkData` | 数据坐标图元被拖动(阈值线 / 注释被拖时实时抛) |
159
+ | `mark:dragend` | `ChartMarkData` | 图元拖动结束(此时锚点已写回数据坐标) |
156
160
  | `zoom:change` | `ZoomRange` | 缩放 / 框选缩放的窗口变化 |
157
161
  | `pan:change` | `ZoomRange` | 拖拽平移 |
158
162
  | `legend:toggle` | `LegendToggleParams` | 图例切换系列 |
@@ -373,6 +377,57 @@ animation: {
373
377
  - **图例切换重排**:隐藏一个饼图扇区 / 漏斗阶段时,其余几何平滑挪位、被隐藏的那个收拢再消失;
374
378
  切换系列显隐时数值域与其它系列一起过渡。
375
379
 
380
+ ## 可编辑图表:数据坐标图元 + 自定义系列
381
+
382
+ 图表不是封闭渲染器 —— `chart.ice`(引擎实例)与 `chart.root`(组件树根)都是公开的,
383
+ 所以**任何引擎图元都能直接当图表的一部分**,并参与同一套命中测试、事件与动画。
384
+
385
+ ### 数据坐标图元(注释 / 阈值线 / 预测带)
386
+
387
+ ```ts
388
+ import { ICEStar } from 'ice-render';
389
+
390
+ // 钉在数据点上的注释卡片(组件是引擎图元:注意 style 的键名是 ctx 属性名)
391
+ chart.addMark({
392
+ type: 'point',
393
+ x: '7月', y: 210, dy: -34,
394
+ component: new ICEStar({ radius: 9, spikes: 5, fill: true, style: { fillStyle: '#dc3545' } }),
395
+ });
396
+
397
+ // 可拖的阈值线:拖完把新的数据值写回锚点,并抛 mark:drag
398
+ chart.addMark({
399
+ type: 'yLine', y: 150, draggable: true,
400
+ component: new ICERect({ width: 1, height: 3, fill: true, draggable: true, style: { fillStyle: '#dc3545' } }),
401
+ });
402
+
403
+ // 预测带 / 参考区间
404
+ chart.addMark({
405
+ type: 'yBand', y0: 150, y1: 200,
406
+ component: new ICERect({ width: 1, height: 1, fill: true, style: { fillStyle: 'rgba(13,110,253,0.10)' } }),
407
+ });
408
+
409
+ chart.on('mark:dragend', ({ id, yValue }) => console.log(id, yValue)); // 拖完拿到数据值
410
+ ```
411
+
412
+ - `type`:`point` / `xLine` / `yLine` / `xBand` / `yBand`
413
+ - 位置按**数据坐标**给(类目名 / 数值 / 时间戳都行),缩放、平移、数据更新后自动跟随;
414
+ - 数据点跑到可视区之外时自动隐藏(`hideWhenOutOfView: false` 可关);
415
+ - 因为组件是引擎图元,它同时拥有**命中测试**(`chart.ice.hitTest()` 能点到它)、
416
+ 关键帧动画与引擎级序列化 —— 而图表层的交互不会抢走它的拖拽(按在图元上不会触发框选 / 平移)。
417
+
418
+ ### 自定义系列类型
419
+
420
+ ```ts
421
+ registerSeriesType('sparkline', (series, props) => new SparkSeries(series, props));
422
+ chart.setOption({ series: [{ id: 's', type: 'sparkline', data: [3, 6, 2, 8] }] });
423
+ ```
424
+
425
+ 继承 `SeriesBase`、实现 `doRender()` 与 `hitTestIndex()` 即可:数据点由通用归一化给定
426
+ (支持数字数组 / `[x, y]` / 对象),悬停高亮、提示框、图例、无障碍与快照序列化全部自动生效。
427
+ 内置类型不允许覆盖(会让同一份 option 在不同环境画出不同的图),未注册的类型兜底按折线渲染。
428
+
429
+ 完整示例见 [examples/editable-chart.html](./examples/editable-chart.html)。
430
+
376
431
  ## 主要 API
377
432
 
378
433
  ```ts