Skip to content

Commit 887102d

Browse files
kingyue737Justineo
andauthored
add dataView slot
* chore: fix warnings and errors in demo (#839) * chore: suppress warning in demo * chore: prevent multiple intializations of esbuild-wasm in demo HMR * feat: dynamically update the theme (#841) Co-authored-by: GU Yiling <[email protected]> * feat: add dataView slot * vibe docs --------- Co-authored-by: GU Yiling <[email protected]>
1 parent 6aa8d6d commit 887102d

File tree

12 files changed

+196
-107
lines changed

12 files changed

+196
-107
lines changed

README.md

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Drop `<script>` inside your HTML file and access the component via `window.VueEC
120120

121121
```html
122122
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
123-
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1"></script>
123+
<script src="https://cdn.jsdelivr.net/npm/echarts@6.0.0-beta.1"></script>
124124
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
125125
```
126126

@@ -331,47 +331,69 @@ export default {
331331
- `clear` [](https://echarts.apache.org/en/api.html#echartsInstance.clear)
332332
- `dispose` [](https://echarts.apache.org/en/api.html#echartsInstance.dispose)
333333

334+
> [!NOTE]
335+
> The following ECharts instance methods aren't exposed because their functionality is already provided by component [props](#props):
336+
>
337+
> - [`showLoading`](https://echarts.apache.org/en/api.html#echartsInstance.showLoading) / [`hideLoading`](https://echarts.apache.org/en/api.html#echartsInstance.hideLoading): use the `loading` and `loading-options` props instead.
338+
> - `setTheme`: use the `theme` prop instead.
339+
334340
### Slots
335341

336-
Vue-ECharts allows you to define ECharts option's `tooltip.formatter` callbacks via Vue slots instead of defining them in your `option` object. This simplifies custom tooltip rendering using familiar Vue templating.
342+
Vue-ECharts allows you to define ECharts option's [`tooltip.formatter`](https://echarts.apache.org/en/option.html#tooltip.formatter) and [`toolbox.feature.dataView.optionToContent`](https://echarts.apache.org/en/option.html#toolbox.feature.dataView.optionToContent) callbacks via Vue slots instead of defining them in your `option` object. This simplifies custom HTMLElement rendering using familiar Vue templating.
337343

338344
**Slot Naming Convention**
339345

340-
- Slot names begin with `tooltip`, followed by hyphen-separated path segments to the target formatter.
346+
- Slot names begin with `tooltip`/`dataView`, followed by hyphen-separated path segments to the target.
341347
- Each segment corresponds to an `option` property name or an array index (for arrays, use the numeric index).
342-
- The constructed slot name maps directly to the nested `formatter` it overrides.
348+
- The constructed slot name maps directly to the nested callback it overrides.
343349

344350
**Example mappings**:
345351

346352
- `tooltip``option.tooltip.formatter`
347353
- `tooltip-baseOption``option.baseOption.tooltip.formatter`
348354
- `tooltip-xAxis-1``option.xAxis[1].tooltip.formatter`
349355
- `tooltip-series-2-data-4``option.series[2].data[4].tooltip.formatter`
356+
- `dataView``option.toolbox.feature.dataView.optionToContent`
357+
- `dataView-media[1]-option``option.media[1].option.toolbox.feature.dataView.optionToContent`
350358

351359
<details>
352360
<summary>Usage</summary>
353361

354362
```vue
355363
<template>
356364
<v-chart :option="chartOptions">
357-
<!-- Override global tooltip.formatter -->
365+
<!-- Global `tooltip.formatter` -->
358366
<template #tooltip="{ params }">
359-
<table>
360-
<tr>
361-
<th>Series</th>
362-
<th>Value</th>
363-
</tr>
364-
<tr v-for="(s, i) in params" :key="i">
365-
<td>{{ s.seriesName }}</td>
366-
<td>{{ s.data }}</td>
367-
</tr>
368-
</table>
367+
<div v-for="(param, i) in params" :key="i">
368+
<span v-html="param.marker" />
369+
<span>{{ param.seriesName }}</span>
370+
<span>{{ param.value[0] }}</span>
371+
</div>
369372
</template>
370373
371-
<!-- Override tooltip on xAxis -->
374+
<!-- Tooltip on xAxis -->
372375
<template #tooltip-xAxis="{ params }">
373376
<div>X-Axis : {{ params.value }}</div>
374377
</template>
378+
379+
<!-- Data View Content -->
380+
<template #dataView="{ option }">
381+
<table>
382+
<thead>
383+
<tr>
384+
<th v-for="(t, i) in option.dataset[0].source[0]" :key="i">
385+
{{ t }}
386+
</th>
387+
</tr>
388+
</thead>
389+
<tbody>
390+
<tr v-for="(row, i) in option.dataset[0].source.slice(1)" :key="i">
391+
<th>{{ row[0] }}</th>
392+
<td v-for="(v, i) in row.slice(1)" :key="i">{{ v }}</td>
393+
</tr>
394+
</tbody>
395+
</table>
396+
</template>
375397
</v-chart>
376398
</template>
377399
```
@@ -380,12 +402,8 @@ Vue-ECharts allows you to define ECharts option's `tooltip.formatter` callbacks
380402

381403
</details>
382404

383-
#### Slot Props
384-
385-
- `params`: The first argument passed to the original [`tooltip.formatter`](https://echarts.apache.org/en/option.html#tooltip.formatter) callback.
386-
387405
> [!NOTE]
388-
> Slots take precedence over any `tooltip.formatter` defined in `props.option`. If a matching slot is present, the slot's content will render instead of using `option`'s formatter.
406+
> Slots take precedence over the corresponding callback defined in `props.option`.
389407
390408
### Static Methods
391409

README.zh-Hans.md

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ import "echarts";
120120

121121
```html
122122
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
123-
<script src="https://cdn.jsdelivr.net/npm/echarts@5.5.1"></script>
123+
<script src="https://cdn.jsdelivr.net/npm/echarts@6.0.0-beta.1"></script>
124124
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
125125
```
126126

@@ -331,46 +331,68 @@ export default {
331331
- `clear` [](https://echarts.apache.org/zh/api.html#echartsInstance.clear)
332332
- `dispose` [](https://echarts.apache.org/zh/api.html#echartsInstance.dispose)
333333

334+
> [!NOTE]
335+
> 如下 ECharts 实例方法没有被暴露,因为它们的功能已经通过组件 [props](#props) 提供了:
336+
>
337+
> - [`showLoading`](https://echarts.apache.org/zh/api.html#echartsInstance.showLoading) / [`hideLoading`](https://echarts.apache.org/zh/api.html#echartsInstance.hideLoading):请使用 `loading``loading-options` prop。
338+
> - `setTheme`:请使用 `theme` prop。
339+
334340
### 插槽(Slots)
335341

336-
Vue-ECharts 允许你通过 Vue 插槽来定义 ECharts 配置中的 `tooltip.formatter` 回调,而无需在 `option` 对象中定义它们。这简化了自定义提示框的渲染,让你可以用熟悉的 Vue 模板语法来编写
342+
Vue-ECharts 允许你通过 Vue 插槽来定义 ECharts 配置中的 [`tooltip.formatter`](https://echarts.apache.org/zh/option.html#tooltip.formatter)[`toolbox.feature.dataView.optionToContent`](https://echarts.apache.org/zh/option.html#toolbox.feature.dataView.optionToContent) 回调,而无需在 `option` 对象中定义它们。你可以使用熟悉的 Vue 模板语法来编写自定义提示框或数据视图中的内容
337343

338344
**插槽命名约定**
339345

340-
- 插槽名称以 `tooltip` 开头,后面跟随用连字符分隔的路径片段,用于定位要覆盖的 `formatter`
341-
- 每个片段对应 `option` 对象的属性名或数组索引(数组索引使用数字形式)。
342-
- 拼接后的插槽名称直接映射到要覆盖的嵌套 `formatter`
346+
- 插槽名称以 `tooltip`/`dataView` 开头,后面跟随用连字符分隔的路径片段,用于定位目标
347+
- 每个路径片段对应 `option` 对象的属性名或数组索引(数组索引使用数字形式)。
348+
- 拼接后的插槽名称直接映射到要覆盖的嵌套回调函数
343349

344350
**示例映射**
345351

346352
- `tooltip``option.tooltip.formatter`
347353
- `tooltip-baseOption``option.baseOption.tooltip.formatter`
348354
- `tooltip-xAxis-1``option.xAxis[1].tooltip.formatter`
349355
- `tooltip-series-2-data-4``option.series[2].data[4].tooltip.formatter`
356+
- `dataView``option.toolbox.feature.dataView.optionToContent`
357+
- `dataView-media[1]-option``option.media[1].option.toolbox.feature.dataView.optionToContent`
350358

351359
<details>
352360
<summary>用法示例</summary>
353361

354362
```vue
355363
<template>
356364
<v-chart :option="chartOptions">
357-
<!-- 覆盖全局 tooltip.formatter -->
365+
<!-- 全局 `tooltip.formatter` -->
358366
<template #tooltip="{ params }">
359-
<table>
360-
<tr>
361-
<th>系列名称</th>
362-
<th>数值</th>
363-
</tr>
364-
<tr v-for="(item, idx) in params" :key="idx">
365-
<td>{{ item.seriesName }}</td>
366-
<td>{{ item.data }}</td>
367-
</tr>
368-
</table>
367+
<div v-for="(param, i) in params" :key="i">
368+
<span v-html="param.marker" />
369+
<span>{{ param.seriesName }}</span>
370+
<span>{{ param.value[0] }}</span>
371+
</div>
369372
</template>
370373
371-
<!-- 覆盖x轴 tooltip.formatter -->
374+
<!-- x轴 tooltip -->
372375
<template #tooltip-xAxis="{ params }">
373-
<div>X 轴: {{ params.value }}</div>
376+
<div>X轴: {{ params.value }}</div>
377+
</template>
378+
379+
<!-- 数据视图内容 -->
380+
<template #dataView="{ option }">
381+
<table>
382+
<thead>
383+
<tr>
384+
<th v-for="(t, i) in option.dataset[0].source[0]" :key="i">
385+
{{ t }}
386+
</th>
387+
</tr>
388+
</thead>
389+
<tbody>
390+
<tr v-for="(row, i) in option.dataset[0].source.slice(1)" :key="i">
391+
<th>{{ row[0] }}</th>
392+
<td v-for="(v, i) in row.slice(1)" :key="i">{{ v }}</td>
393+
</tr>
394+
</tbody>
395+
</table>
374396
</template>
375397
</v-chart>
376398
</template>
@@ -380,12 +402,8 @@ Vue-ECharts 允许你通过 Vue 插槽来定义 ECharts 配置中的 `tooltip.fo
380402

381403
</details>
382404

383-
#### 插槽Props
384-
385-
- `params`[`tooltip.formatter`](https://echarts.apache.org/zh/option.html#tooltip.formatter) 回调的第一个参数。
386-
387405
> [!NOTE]
388-
> 插槽内容会优先于 `props.option` 中对应的 `tooltip.formatter` 渲染,如果两者同时存在
406+
> 插槽会优先于 `props.option` 中对应的回调函数
389407
390408
### 静态方法
391409

demo/CodeGen.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ const transformedCode = ref("");
7878
const transformErrors = ref([]);
7979
8080
onMounted(async () => {
81-
await initialize({ wasmURL });
81+
// prevent multiple initializations during HMR
82+
if (!window.__esbuildInitialized) {
83+
await initialize({ wasmURL });
84+
window.__esbuildInitialized = true;
85+
}
8286
8387
initializing.value = false;
8488

demo/data/logo.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ export default {
2020
},
2121
shape: `path://${d}`,
2222
label: {
23-
normal: {
24-
formatter() {
25-
return "";
26-
},
23+
formatter() {
24+
return "";
2725
},
2826
},
2927
itemStyle: {

demo/data/radar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const useScoreStore = defineStore("store", () => {
2727
fontWeight: 300,
2828
},
2929
radar: {
30+
splitNumber: 4,
3031
indicator: scores.value.map(({ name, max }, index) => {
3132
if (index === activeIndex) {
3233
return { name, max, color: "goldenrod" };

demo/examples/LineChart.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
DatasetComponent,
77
LegendComponent,
88
TooltipComponent,
9+
ToolboxComponent,
910
} from "echarts/components";
1011
import { shallowRef } from "vue";
1112
import VChart from "../../src/ECharts";
@@ -18,6 +19,7 @@ use([
1819
LegendComponent,
1920
LineChart,
2021
TooltipComponent,
22+
ToolboxComponent,
2123
PieChart,
2224
]);
2325
@@ -56,7 +58,7 @@ function getPieOption(params) {
5658
<v-example
5759
id="line"
5860
title="Line chart"
59-
desc="(with component rendered tooltip)"
61+
desc="(with tooltip and dataView slots)"
6062
>
6163
<v-chart :option="option" autoresize>
6264
<template #tooltip="{ params }">
@@ -70,6 +72,23 @@ function getPieOption(params) {
7072
{{ axis === "xAxis" ? "Year" : "Value" }}:
7173
<b>{{ params.name }}</b>
7274
</template>
75+
<template #dataView="{ option }">
76+
<table style="margin: 20px auto">
77+
<thead>
78+
<tr>
79+
<th v-for="(t, i) in option.dataset[0].source[0]" :key="i">
80+
{{ t }}
81+
</th>
82+
</tr>
83+
</thead>
84+
<tbody>
85+
<tr v-for="(row, i) in option.dataset[0].source.slice(1)" :key="i">
86+
<th>{{ row[0] }}</th>
87+
<td v-for="(v, i) in row.slice(1)" :key="i">{{ v }}</td>
88+
</tr>
89+
</tbody>
90+
</table>
91+
</template>
7392
</v-chart>
7493
<template #extra>
7594
<p class="actions">
@@ -82,3 +101,10 @@ function getPieOption(params) {
82101
</template>
83102
</v-example>
84103
</template>
104+
105+
<style scoped>
106+
th,
107+
td {
108+
padding: 4px 8px;
109+
}
110+
</style>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"docs": "node ./scripts/docs.mjs",
2222
"prepublishOnly": "pnpm run typecheck && pnpm run dev:typecheck && pnpm run build && publint"
2323
},
24-
"packageManager": "[email protected].1",
24+
"packageManager": "[email protected].4",
2525
"type": "module",
2626
"main": "dist/index.js",
2727
"unpkg": "dist/index.min.js",
@@ -36,7 +36,7 @@
3636
"dist"
3737
],
3838
"peerDependencies": {
39-
"echarts": "^5.5.1",
39+
"echarts": "^6.0.0-beta.1",
4040
"vue": "^3.1.1"
4141
},
4242
"devDependencies": {
@@ -50,7 +50,7 @@
5050
"@vue/tsconfig": "^0.7.0",
5151
"@vueuse/core": "^13.1.0",
5252
"comment-mark": "^2.0.1",
53-
"echarts": "^5.6.0",
53+
"echarts": "^6.0.0-beta.1",
5454
"echarts-gl": "^2.0.9",
5555
"echarts-liquidfill": "^3.1.0",
5656
"esbuild-wasm": "^0.23.0",

0 commit comments

Comments
 (0)