Skip to content

Commit 5bb9c06

Browse files
authored
Merge pull request #18 from ambit-tsai/dev
feat: deep watch prop "option"
2 parents 5a48637 + 794d48c commit 5bb9c06

14 files changed

+393
-1742
lines changed

README.md

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33

44
# ECharts For Vue  ![Version](https://img.shields.io/npm/v/echarts-for-vue.svg)
5-
📊📈 ECharts wrapper component for Vue 3 and 2
5+
📊📈 ECharts wrapper component for Vue 3, 2 and TypeScript
66

77

88
## Features
99
1. Support for Vue 3 and 2;
10+
1. Support auto resize;
1011
1. Conform to the habits of Vue and ECharts users;
1112
1. Provide pure function API, no side effects;
1213
1. Lightweight encapsulation, easy to use;
13-
1. Support auto resize;
1414

1515

1616
## Install
@@ -23,8 +23,8 @@ npm i -S echarts-for-vue
2323
1. Vue 3
2424
```javascript
2525
import { createApp, h } from 'vue';
26-
import * as echarts from 'echarts';
2726
import { plugin } from 'echarts-for-vue';
27+
import * as echarts from 'echarts';
2828

2929
const app = createApp({ /*...*/ });
3030
app.use(plugin, { echarts, h }); // use as a plugin
@@ -35,19 +35,17 @@ app.use(plugin, { echarts, h }); // use as a plugin
3535
</template>
3636

3737
<script>
38+
import { createComponent } from 'echarts-for-vue';
3839
import * as echarts from 'echarts';
3940
import { h } from 'vue';
40-
import { createComponent } from 'echarts-for-vue';
4141
4242
export default {
4343
components: {
4444
ECharts: createComponent({ echarts, h }), // use as a component
4545
},
46-
data() {
47-
return {
48-
option: { /*...*/ },
49-
};
50-
},
46+
data: () => ({
47+
option: { /*...*/ },
48+
}),
5149
methods: {
5250
doSomething() {
5351
this.$refs.chart.inst.getWidth(); // call the method of ECharts instance
@@ -60,8 +58,8 @@ app.use(plugin, { echarts, h }); // use as a plugin
6058
2. Vue 2
6159
```javascript
6260
import Vue from 'vue';
63-
import * as echarts from 'echarts';
6461
import { plugin } from 'echarts-for-vue';
62+
import * as echarts from 'echarts';
6563

6664
Vue.use(plugin, { echarts }); // use as a plugin
6765
```
@@ -71,18 +69,16 @@ Vue.use(plugin, { echarts }); // use as a plugin
7169
</template>
7270

7371
<script>
74-
import * as echarts from 'echarts';
7572
import { createComponent } from 'echarts-for-vue';
73+
import * as echarts from 'echarts';
7674
7775
export default {
7876
components: {
7977
ECharts: createComponent({ echarts }), // use as a component
8078
},
81-
data() {
82-
return {
83-
option: { /*...*/ },
84-
};
85-
},
79+
data: () => ({
80+
option: { /*...*/ },
81+
}),
8682
methods: {
8783
doSomething() {
8884
this.$refs.chart.inst.getWidth(); // call the method of ECharts instance
@@ -98,23 +94,24 @@ Vue.use(plugin, { echarts }); // use as a plugin
9894
## Global API
9995
|Definition|Return|Description|
10096
|-|-|-|
101-
|`createComponent`(*initialOptions*: object): object|Component definition object|Create a component|
102-
|`plugin`(*app*: Vue, *initialOptions*: object): void||The installation method of plugin|
97+
|`createComponent`(*options*: Options): object|Component definition object|Create a component|
98+
|`plugin`(*app*: Vue, *options*: Options): void||The installation method of plugin|
10399

104100

105-
## initialOptions
101+
## Options
106102
|Property|Type|Default|Optional|Description|
107103
|-|-|-|-|-|
108-
|echarts|object|||The global object of ECharts library|
109-
|h|function|||The method `createElement` of Vue (**Required** for Vue 3)|
110-
|ResizeObserver|function|window.ResizeObserver||When the global `ResizeObserver` doesn't exist, the <a href="https://github.com/que-etc/resize-observer-polyfill" target="_blank">polyfill</a> provides support|
104+
|echarts|typeof echarts|||The global object of ECharts library|
105+
|h|Function|||The method `createElement` of Vue (**Required** for Vue 3)|
106+
|ResizeObserver|typeof ResizeObserver|window.ResizeObserver||When the global `ResizeObserver` doesn't exist, the <a href="https://github.com/que-etc/resize-observer-polyfill" target="_blank">polyfill</a> provides support|
111107
|name|string|"ECharts"||The registered name of the component|
108+
|deepWatchOption|boolean|true||deep watch prop "option"|
112109

113110

114111
## Instance Properties
115112
|Name|Type|ReadOnly|Description|
116113
|-|-|-|-|
117-
|inst|object||ECharts instance|
114+
|inst|ECharts||ECharts instance|
118115

119116

120117
## props
@@ -124,25 +121,32 @@ Vue.use(plugin, { echarts }); // use as a plugin
124121
|initOpts|object|||The parameter `opts` of `echarts.init` method, <a href="https://echarts.apache.org/en/api.html#echarts.init" target="_blank">see</a>|
125122
|loading|boolean|false||Shows loading animation|
126123
|loadingType|string|"default"||The parameter `type` of ECharts instance method `showLoading`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.showLoading" target="_blank">see</a>|
127-
|loadingOpts|object|||The parameter `opts` of ECharts instance method `showLoading`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.showLoading" target="_blank">see</a>|
128-
|option|object|||The parameter `option` of ECharts instance method `setOption`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>|
129-
|setOptionOpts|object|||The parameter `opts` of ECharts instance method `setOption`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>|
124+
|loadingOpts|EChartsLoadingOption|||The parameter `opts` of ECharts instance method `showLoading`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.showLoading" target="_blank">see</a>|
125+
|option|EChartOption|||The parameter `option` of ECharts instance method `setOption`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>|
126+
|optionOpts|EChartsOptionConfig|||The parameter `opts` of ECharts instance method `setOption`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>|
130127
|events|Arguments[]|||An array element is the arguments of ECharts instance method `on`, <a href="https://echarts.apache.org/en/api.html#echartsInstance.on" target="_blank">see</a>|
131-
|autoResize|boolean|true||Auto resize (Based on `ResizeObserver`, forward compatibility via <a href="https://github.com/que-etc/resize-observer-polyfill" target="_blank">polyfill</a>)|
128+
|autoResize|boolean|true||Auto resize|
132129

133130
***Beyond the `props` above, the remaining properties are passed to the root element of the component, such as `style`, `class` or `onclick`***
134131

135132

133+
## Events
134+
|Name|Description|
135+
|-|-|
136+
|resize|Trigger when chart is resized|
137+
138+
136139
## methods
137140
|Definition|Description|
138141
|-|-|
139-
|`setOption`(*option*: object, *opts*: object): void|Call the method `setOption` of ECharts instance, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>|
142+
|`setOption`(*option*: EChartOption, *opts*?: EChartsOptionConfig): void|Call the method `setOption` of ECharts instance, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>|
140143
|`resize`(): void|Resize chart (Based on the size of root element)|
141144
|`addResizeListener`(): void|Add "resize" listener|
142145
|`removeResizeListener`(): void|Remove "resize" listener|
143146

144147

145148
## Contact
146-
1. *WeChat*: ambit_tsai
149+
1. *WeChat*: cai_fanwei
150+
1. *QQ*: 854521460
147151
1. *QQ Group*: 663286147
148152
1. *E-mail*: [email protected]

README.zh-CN.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33

44
# ECharts For Vue&nbsp;&nbsp;![Version](https://img.shields.io/npm/v/echarts-for-vue.svg)
5-
📊📈 适用于 Vue 3 和 2 的 ECharts 包装组件
5+
📊📈 适用于 Vue 3、2TypeScript 的 ECharts 包装组件
66

77

88
## 特点
99
1. 支持 Vue 3 和 2;
10+
1. 支持图表大小自适应;
1011
1. 符合 Vue 与 ECharts 用户的使用习惯;
1112
1. 提供纯函数 API,无副作用;
1213
1. 轻量级封装,简单易用;
13-
1. 支持图表大小自适应;
1414

1515

1616
## 安装
@@ -23,8 +23,8 @@ npm i -S echarts-for-vue
2323
1. Vue 3
2424
```javascript
2525
import { createApp, h } from 'vue';
26-
import * as echarts from 'echarts';
2726
import { plugin } from 'echarts-for-vue';
27+
import * as echarts from 'echarts';
2828

2929
const app = createApp({ /*...*/ });
3030
app.use(plugin, { echarts, h }); // 作为插件使用
@@ -35,19 +35,17 @@ app.use(plugin, { echarts, h }); // 作为插件使用
3535
</template>
3636

3737
<script>
38+
import { createComponent } from 'echarts-for-vue';
3839
import * as echarts from 'echarts';
3940
import { h } from 'vue';
40-
import { createComponent } from 'echarts-for-vue';
4141
4242
export default {
4343
components: {
4444
ECharts: createComponent({ echarts, h }), // 作为组件使用
4545
},
46-
data() {
47-
return {
48-
option: { /*...*/ },
49-
};
50-
},
46+
data: () => ({
47+
option: { /*...*/ },
48+
}),
5149
methods: {
5250
doSomething() {
5351
this.$refs.chart.inst.getWidth(); // 调用 ECharts 实例的方法
@@ -60,8 +58,8 @@ app.use(plugin, { echarts, h }); // 作为插件使用
6058
2. Vue 2
6159
```javascript
6260
import Vue from 'vue';
63-
import * as echarts from 'echarts';
6461
import { plugin } from 'echarts-for-vue';
62+
import * as echarts from 'echarts';
6563

6664
Vue.use(plugin, { echarts }); // 作为插件使用
6765
```
@@ -71,18 +69,16 @@ Vue.use(plugin, { echarts }); // 作为插件使用
7169
</template>
7270

7371
<script>
74-
import * as echarts from 'echarts';
7572
import { createComponent } from 'echarts-for-vue';
73+
import * as echarts from 'echarts';
7674
7775
export default {
7876
components: {
7977
ECharts: createComponent({ echarts }), // 作为组件使用
8078
},
81-
data() {
82-
return {
83-
option: { /*...*/ },
84-
};
85-
},
79+
data: () => ({
80+
option: { /*...*/ },
81+
}),
8682
methods: {
8783
doSomething() {
8884
this.$refs.chart.inst.getWidth(); // 调用 ECharts 实例的方法
@@ -98,23 +94,24 @@ Vue.use(plugin, { echarts }); // 作为插件使用
9894
## 全局 API
9995
|定义|返回值|说明|
10096
|-|-|-|
101-
|`createComponent`(*initialOptions*: object): object|组件定义对象|创建组件|
102-
|`plugin`(*app*: Vue, *initialOptions*: object): void||插件的安装方法|
97+
|`createComponent`(*options*: Options): object|组件定义对象|创建组件|
98+
|`plugin`(*app*: Vue, *options*: Options): void||插件的安装方法|
10399

104100

105-
## initialOptions
101+
## Options
106102
|属性|类型|默认值|可选|说明|
107103
|-|-|-|-|-|
108-
|echarts|object|||ECharts 库的全局对象|
109-
|h|function|||Vue 的 `createElement` 方法(使用 Vue 3 时,是**必选**的)|
110-
|ResizeObserver|function|window.ResizeObserver||全局 `ResizeObserver` 不存在时,可通过 <a href="https://github.com/que-etc/resize-observer-polyfill" target="_blank">polyfill</a> 提供支持|
104+
|echarts|typeof echarts|||ECharts 库的全局对象|
105+
|h|Function|||Vue 的 `createElement` 方法(使用 Vue 3 时,是**必选**的)|
106+
|ResizeObserver|typeof ResizeObserver|window.ResizeObserver||全局 `ResizeObserver` 不存在时,可通过 <a href="https://github.com/que-etc/resize-observer-polyfill" target="_blank">polyfill</a> 提供支持|
111107
|name|string|"ECharts"||组件的注册名称|
108+
|deepWatchOption|boolean|true||深度监听属性 “option”|
112109

113110

114111
## 实例属性
115112
|名称|类型|只读|说明|
116113
|-|-|-|-|
117-
|inst|object||ECharts 实例|
114+
|inst|ECharts||ECharts 实例|
118115

119116

120117
## props
@@ -124,19 +121,25 @@ Vue.use(plugin, { echarts }); // 作为插件使用
124121
|initOpts|object|||`echarts.init` 方法的入参 `opts`,<a href="https://echarts.apache.org/zh/api.html#echarts.init" target="_blank">详见</a>|
125122
|loading|boolean|false||显示加载动画效果|
126123
|loadingType|string|"default"||ECharts 实例 `showLoading` 方法的入参 `type`,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.showLoading" target="_blank">详见</a>|
127-
|loadingOpts|object|||ECharts 实例 `showLoading` 方法的入参 `opts`,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.showLoading" target="_blank">详见</a>|
128-
|option|object|||ECharts 实例 `setOption` 方法的入参 `option`,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.setOption" target="_blank">详见</a>|
129-
|setOptionOpts|object|||ECharts 实例 `setOption` 方法的入参 `opts`,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.setOption" target="_blank">详见</a>|
130-
|events|Arguments[]|||数组元素为ECharts 实例 `on` 方法的入参,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.on" target="_blank">详见</a>|
131-
|autoResize|boolean|true||自动调整大小(基于 `ResizeObserver` 实现,可通过 <a href="https://github.com/que-etc/resize-observer-polyfill" target="_blank">polyfill</a> 向前兼容)|
124+
|loadingOpts|EChartsLoadingOption |||ECharts 实例 `showLoading` 方法的入参 `opts`,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.showLoading" target="_blank">详见</a>|
125+
|option|EChartOption|||ECharts 实例 `setOption` 方法的入参 `option`,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.setOption" target="_blank">详见</a>|
126+
|optionOpts|EChartsOptionConfig|||ECharts 实例 `setOption` 方法的入参 `opts`,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.setOption" target="_blank">详见</a>|
127+
|events|Arguments[]|||数组元素为 ECharts 实例 `on` 方法的入参,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.on" target="_blank">详见</a>|
128+
|autoResize|boolean|true||自动调整大小|
132129

133130
***除了上述 `props`,其余属性将被传递给组件的根元素,如:`style``class``onclick`***
134131

135132

133+
## 事件
134+
|名称|说明|
135+
|-|-|
136+
|resize|图表大小调整时触发|
137+
138+
136139
## methods
137140
|定义|说明|
138141
|-|-|
139-
|`setOption`(*option*: object, *opts*: object): void|调用 ECharts 实例的 `setOption` 方法,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.setOption" target="_blank">详见</a>|
142+
|`setOption`(*option*: EChartOption, *opts*?: EChartsOptionConfig): void|调用 ECharts 实例的 `setOption` 方法,<a href="https://echarts.apache.org/zh/api.html#echartsInstance.setOption" target="_blank">详见</a>|
140143
|`resize`(): void|调整图表大小(以组件根元素大小为基准)|
141144
|`addResizeListener`(): void|添加 resize 监听器|
142145
|`removeResizeListener`(): void|移除 resize 监听器|

index.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import * as echarts from 'echarts'
22

33

4+
type EChartsNS = typeof echarts
5+
type ResizeObserverConstructor = typeof ResizeObserver
46
type Options = {
5-
echarts: typeof echarts
7+
echarts: EChartsNS
68
h?: Function
7-
ResizeObserver?: typeof ResizeObserver
9+
ResizeObserver?: ResizeObserverConstructor
810
name?: string
11+
deepWatchOption?: boolean
912
}
1013

1114

1215
declare module "echarts-for-vue" {
1316
export function createComponent(options: Options): object
14-
export function plugin(app: any, options: Options): void
17+
export function plugin(app: { component: Function }, options: Options): void
1518
}

0 commit comments

Comments
 (0)