echarts-for-react 3.0.2 → 3.0.4

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,13 +1,13 @@
1
1
  # echarts-for-react
2
2
 
3
- The simplest, and the best React wrapper for [Apache ECharts](https://github.com/apache/incubator-echarts).
3
+ The simplest, and the best React wrapper for [Apache ECharts](https://github.com/apache/incubator-echarts). Using visualization with MCP Server [mcp-server-chart](https://github.com/antvis/mcp-server-chart).
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react)
6
- [![Build Status](https://github.com/hustcc/echarts-for-react/workflows/build/badge.svg?branch=master)](https://github.com/hustcc/echarts-for-react/actions?query=workflow%3Abuild)
6
+ [![build](https://github.com/hustcc/echarts-for-react/actions/workflows/build.yml/badge.svg)](https://github.com/hustcc/echarts-for-react/actions/workflows/build.yml)
7
7
  [![Coverage](https://img.shields.io/coveralls/hustcc/echarts-for-react/master.svg)](https://coveralls.io/github/hustcc/echarts-for-react)
8
8
  [![NPM downloads](https://img.shields.io/npm/dm/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react)
9
9
  [![License](https://img.shields.io/npm/l/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react)
10
- ![ECharts Ver](https://img.shields.io/badge/echarts-%5E3.0.0%20%7C%7C%20%5E4.0.0%20%7C%7C%20%5E5.0.0-blue.svg)
10
+ ![ECharts Ver](https://img.shields.io/badge/echarts-%5E3.0.0%20%7C%7C%20%5E4.0.0%20%7C%7C%20%5E5.0.0%20%5E6.0.0-blue.svg)
11
11
  ![React Ver](https://img.shields.io/badge/React-%20%5E15.0.0%20%7C%7C%20%20%5E16.0.0%20%7C%7C%20%20%5E17.0.0-blue.svg)
12
12
 
13
13
 
@@ -63,7 +63,7 @@ import ReactECharts from 'echarts-for-react'; // or var ReactECharts = require(
63
63
 
64
64
  Import ECharts.js modules manually to reduce bundle size
65
65
 
66
- **With Echarts.js v5:**
66
+ **With Echarts.js v5 or v6:**
67
67
 
68
68
  ```ts
69
69
  import React from 'react';
@@ -218,6 +218,29 @@ import 'echarts/lib/component/title';
218
218
  />
219
219
  ```
220
220
 
221
+ For **Next.js** user, code transpilation is needed. For Next.js 13.1 or higher, as all `next-transpile-modules` features are natively built-in and the package has been deprecated, so please add `transpilePackages: ['echarts', 'zrender']` into `nextConfig` object:
222
+
223
+ ```js
224
+ // next.config.js
225
+ /** @type {import('next').NextConfig} */
226
+
227
+ const nextConfig = {
228
+ // ...existing properties,
229
+ transpilePackages: ['echarts', 'zrender'],
230
+ }
231
+
232
+ module.exports = nextConfig
233
+ ```
234
+
235
+ For Next.js with version < 13.1:
236
+
237
+ ```js
238
+ // next.config.js
239
+ const withTM = require("next-transpile-modules")(["echarts", "zrender"]);
240
+
241
+ module.exports = withTM({})
242
+ ```
243
+
221
244
  ## Props of Component
222
245
 
223
246
  - **`option`** (required, object)
@@ -228,6 +251,10 @@ the echarts option config, can see [https://echarts.apache.org/option.html#title
228
251
 
229
252
  when `setOption`, not merge the data, default is `false`. See [https://echarts.apache.org/api.html#echartsInstance.setOption](https://echarts.apache.org/api.html#echartsInstance.setOption).
230
253
 
254
+ - **`replaceMerge`** (optional, string | string[])
255
+
256
+ when `setOption`, default is `null`. See [https://echarts.apache.org/api.html#echartsInstance.setOption](https://echarts.apache.org/api.html#echartsInstance.setOption).
257
+
231
258
  - **`lazyUpdate`** (optional, object)
232
259
 
233
260
  when `setOption`, lazy update the data, default is `false`. See [https://echarts.apache.org/api.html#echartsInstance.setOption](https://echarts.apache.org/api.html#echartsInstance.setOption).
@@ -303,6 +330,10 @@ the `opts` of echarts. `object`, will be used when initial echarts instance by `
303
330
  />
304
331
  ```
305
332
 
333
+ - **`autoResize`** (optional, boolean)
334
+
335
+ decide whether to trigger `this.resize` when window resize. default is `true`.
336
+
306
337
 
307
338
  ## Component API & Echarts API
308
339
 
@@ -326,6 +357,25 @@ const echartInstance = this.echartRef.getEchartsInstance();
326
357
  const base64 = echartInstance.getDataURL();
327
358
  ```
328
359
 
360
+ TypeScript and `useRef()` example:
361
+
362
+ ```ts
363
+ const getOption = () => {/** */};
364
+
365
+ export default function App() {
366
+ const echartsRef = useRef<InstanceType<typeof ReactEcharts>>(null);
367
+
368
+ useEffect(() => {
369
+ if (echartsRef.current) {
370
+ const echartsInstance = echartsRef.current.getEchartsInstance();
371
+ // do something
372
+ echartsInstance.resize();
373
+ }
374
+ }, []);
375
+ return <ReactEcharts ref={echartsRef} option={getOption()} />;
376
+ }
377
+ ```
378
+
329
379
  **About API of echarts, can see** [https://echarts.apache.org/api.html#echartsInstance](https://echarts.apache.org/api.html#echartsInstance).
330
380
 
331
381
  You can use the API to do:
package/esm/core.d.ts CHANGED
@@ -21,10 +21,9 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
21
21
  componentDidMount(): void;
22
22
  componentDidUpdate(prevProps: EChartsReactProps): void;
23
23
  componentWillUnmount(): void;
24
+ initEchartsInstance(): Promise<ECharts>;
24
25
  /**
25
- * return the echart object
26
- * 1. if exist, return the existed instance
27
- * 2. or new one instance
26
+ * return the existing echart object
28
27
  */
29
28
  getEchartsInstance(): ECharts;
30
29
  /**
@@ -36,6 +35,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
36
35
  */
37
36
  private renderNewEcharts;
38
37
  private bindEvents;
38
+ private offEvents;
39
39
  /**
40
40
  * render the echarts
41
41
  */
package/esm/core.js CHANGED
@@ -1,4 +1,4 @@
1
- import { __assign, __extends } from "tslib";
1
+ import { __assign, __awaiter, __extends, __generator } from "tslib";
2
2
  import React, { PureComponent } from 'react';
3
3
  import { bind, clear } from 'size-sensor';
4
4
  import { pick } from './helper/pick';
@@ -33,16 +33,20 @@ var EChartsReactCore = /** @class */ (function (_super) {
33
33
  // 以下属性修改的时候,需要 dispose 之后再新建
34
34
  // 1. 切换 theme 的时候
35
35
  // 2. 修改 opts 的时候
36
- // 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151
37
36
  if (!isEqual(prevProps.theme, this.props.theme) ||
38
- !isEqual(prevProps.opts, this.props.opts) ||
39
- !isEqual(prevProps.onEvents, this.props.onEvents)) {
37
+ !isEqual(prevProps.opts, this.props.opts)) {
40
38
  this.dispose();
41
39
  this.renderNewEcharts(); // 重建
42
40
  return;
43
41
  }
42
+ // 修改 onEvent 的时候先移除历史事件再添加
43
+ var echartsInstance = this.getEchartsInstance();
44
+ if (!isEqual(prevProps.onEvents, this.props.onEvents)) {
45
+ this.offEvents(echartsInstance, prevProps.onEvents);
46
+ this.bindEvents(echartsInstance, this.props.onEvents);
47
+ }
44
48
  // when these props are not isEqual, update echarts
45
- var pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
49
+ var pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
46
50
  if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
47
51
  this.updateEChartsOption();
48
52
  }
@@ -56,13 +60,37 @@ var EChartsReactCore = /** @class */ (function (_super) {
56
60
  EChartsReactCore.prototype.componentWillUnmount = function () {
57
61
  this.dispose();
58
62
  };
63
+ /*
64
+ * initialise an echarts instance
65
+ */
66
+ EChartsReactCore.prototype.initEchartsInstance = function () {
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ var _this = this;
69
+ return __generator(this, function (_a) {
70
+ return [2 /*return*/, new Promise(function (resolve) {
71
+ // create temporary echart instance
72
+ _this.echarts.init(_this.ele, _this.props.theme, _this.props.opts);
73
+ var echartsInstance = _this.getEchartsInstance();
74
+ echartsInstance.on('finished', function () {
75
+ // get final width and height
76
+ var width = _this.ele.clientWidth;
77
+ var height = _this.ele.clientHeight;
78
+ // dispose temporary echart instance
79
+ _this.echarts.dispose(_this.ele);
80
+ // recreate echart instance
81
+ // we use final width and height only if not originally provided as opts
82
+ var opts = __assign({ width: width, height: height }, _this.props.opts);
83
+ resolve(_this.echarts.init(_this.ele, _this.props.theme, opts));
84
+ });
85
+ })];
86
+ });
87
+ });
88
+ };
59
89
  /**
60
- * return the echart object
61
- * 1. if exist, return the existed instance
62
- * 2. or new one instance
90
+ * return the existing echart object
63
91
  */
64
92
  EChartsReactCore.prototype.getEchartsInstance = function () {
65
- return this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts);
93
+ return this.echarts.getInstanceByDom(this.ele);
66
94
  };
67
95
  /**
68
96
  * dispose echarts and clear size-sensor
@@ -83,21 +111,34 @@ var EChartsReactCore = /** @class */ (function (_super) {
83
111
  * render a new echarts instance
84
112
  */
85
113
  EChartsReactCore.prototype.renderNewEcharts = function () {
86
- var _this = this;
87
- var _a = this.props, onEvents = _a.onEvents, onChartReady = _a.onChartReady;
88
- // 1. new echarts instance
89
- var echartsInstance = this.updateEChartsOption();
90
- // 2. bind events
91
- this.bindEvents(echartsInstance, onEvents || {});
92
- // 3. on chart ready
93
- if (isFunction(onChartReady))
94
- onChartReady(echartsInstance);
95
- // 4. on resize
96
- if (this.ele) {
97
- bind(this.ele, function () {
98
- _this.resize();
114
+ return __awaiter(this, void 0, void 0, function () {
115
+ var _a, onEvents, onChartReady, _b, autoResize, echartsInstance;
116
+ var _this = this;
117
+ return __generator(this, function (_c) {
118
+ switch (_c.label) {
119
+ case 0:
120
+ _a = this.props, onEvents = _a.onEvents, onChartReady = _a.onChartReady, _b = _a.autoResize, autoResize = _b === void 0 ? true : _b;
121
+ // 1. init echarts instance
122
+ return [4 /*yield*/, this.initEchartsInstance()];
123
+ case 1:
124
+ // 1. init echarts instance
125
+ _c.sent();
126
+ echartsInstance = this.updateEChartsOption();
127
+ // 3. bind events
128
+ this.bindEvents(echartsInstance, onEvents || {});
129
+ // 4. on chart ready
130
+ if (isFunction(onChartReady))
131
+ onChartReady(echartsInstance);
132
+ // 5. on resize
133
+ if (this.ele && autoResize) {
134
+ bind(this.ele, function () {
135
+ _this.resize();
136
+ });
137
+ }
138
+ return [2 /*return*/];
139
+ }
99
140
  });
100
- }
141
+ });
101
142
  };
102
143
  // bind the events
103
144
  EChartsReactCore.prototype.bindEvents = function (instance, events) {
@@ -117,15 +158,26 @@ var EChartsReactCore = /** @class */ (function (_super) {
117
158
  }
118
159
  }
119
160
  };
161
+ // off the events
162
+ EChartsReactCore.prototype.offEvents = function (instance, events) {
163
+ if (!events)
164
+ return;
165
+ // loop and off
166
+ for (var eventName in events) {
167
+ if (isString(eventName)) {
168
+ instance.off(eventName);
169
+ }
170
+ }
171
+ };
120
172
  /**
121
173
  * render the echarts
122
174
  */
123
175
  EChartsReactCore.prototype.updateEChartsOption = function () {
124
- var _a = this.props, option = _a.option, _b = _a.notMerge, notMerge = _b === void 0 ? false : _b, _c = _a.lazyUpdate, lazyUpdate = _c === void 0 ? false : _c, showLoading = _a.showLoading, _d = _a.loadingOption, loadingOption = _d === void 0 ? null : _d;
176
+ var _a = this.props, option = _a.option, _b = _a.notMerge, notMerge = _b === void 0 ? false : _b, _c = _a.replaceMerge, replaceMerge = _c === void 0 ? null : _c, _d = _a.lazyUpdate, lazyUpdate = _d === void 0 ? false : _d, showLoading = _a.showLoading, _e = _a.loadingOption, loadingOption = _e === void 0 ? null : _e;
125
177
  // 1. get or initial the echarts object
126
178
  var echartInstance = this.getEchartsInstance();
127
179
  // 2. set the echarts option
128
- echartInstance.setOption(option, notMerge, lazyUpdate);
180
+ echartInstance.setOption(option, { notMerge: notMerge, replaceMerge: replaceMerge, lazyUpdate: lazyUpdate });
129
181
  // 3. set loading mask
130
182
  if (showLoading)
131
183
  echartInstance.showLoading(loadingOption);
@@ -143,7 +195,10 @@ var EChartsReactCore = /** @class */ (function (_super) {
143
195
  // resize should not happen on first render as it will cancel initial echarts animations
144
196
  if (!this.isInitialResize) {
145
197
  try {
146
- echartsInstance.resize();
198
+ echartsInstance.resize({
199
+ width: 'auto',
200
+ height: 'auto',
201
+ });
147
202
  }
148
203
  catch (e) {
149
204
  console.warn(e);
@@ -159,7 +214,7 @@ var EChartsReactCore = /** @class */ (function (_super) {
159
214
  var newStyle = __assign({ height: 300 }, style);
160
215
  return (React.createElement("div", { ref: function (e) {
161
216
  _this.ele = e;
162
- }, style: newStyle, className: "echarts-for-react " + className }));
217
+ }, style: newStyle, className: "echarts-for-react ".concat(className) }));
163
218
  };
164
219
  return EChartsReactCore;
165
220
  }(PureComponent));
package/esm/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C;;GAEG;AACH;IAA8C,oCAAgC;IAgB5E,0BAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAKb;QAHC,KAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,KAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAChB,KAAI,CAAC,eAAe,GAAG,IAAI,CAAC;;IAC9B,CAAC;IAED,4CAAiB,GAAjB;QACE,IAAI,CAAC,gBAAgB,EAAE,CAAC;IAC1B,CAAC;IAED,SAAS;IACT,6CAAkB,GAAlB,UAAmB,SAA4B;QAC7C;;;WAGG;QACK,IAAA,eAAe,GAAK,IAAI,CAAC,KAAK,gBAAf,CAAgB;QACvC,IAAI,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;YAC1E,OAAO;SACR;QAED,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;IAED,iCAAM,GAAN;QAAA,iBAcC;QAbO,IAAA,KAA4B,IAAI,CAAC,KAAK,EAApC,KAAK,WAAA,EAAE,iBAAc,EAAd,SAAS,mBAAG,EAAE,KAAe,CAAC;QAC7C,uBAAuB;QACvB,IAAM,QAAQ,cAAK,MAAM,EAAE,GAAG,IAAK,KAAK,CAAE,CAAC;QAE3C,OAAO,CACL,6BACE,GAAG,EAAE,UAAC,CAAc;gBAClB,KAAI,CAAC,GAAG,GAAG,CAAC,CAAC;YACf,CAAC,EACD,KAAK,EAAE,QAAQ,EACf,SAAS,EAAE,uBAAqB,SAAW,GAC3C,CACH,CAAC;IACJ,CAAC;IACH,uBAAC;AAAD,CAAC,AA/LD,CAA8C,aAAa,GA+L1D","sourcesContent":["import type { ECharts } from 'echarts';\nimport React, { PureComponent } from 'react';\nimport { bind, clear } from 'size-sensor';\nimport { pick } from './helper/pick';\nimport { isFunction } from './helper/is-function';\nimport { isString } from './helper/is-string';\nimport { isEqual } from './helper/is-equal';\nimport { EChartsReactProps, EChartsInstance } from './types';\n\n/**\n * core component for echarts binding\n */\nexport default class EChartsReactCore extends PureComponent<EChartsReactProps> {\n /**\n * echarts render container\n */\n public ele: HTMLElement;\n\n /**\n * if this is the first time we are resizing\n */\n private isInitialResize: boolean;\n\n /**\n * echarts library entry\n */\n protected echarts: any;\n\n constructor(props: EChartsReactProps) {\n super(props);\n\n this.echarts = props.echarts;\n this.ele = null;\n this.isInitialResize = true;\n }\n\n componentDidMount() {\n this.renderNewEcharts();\n }\n\n // update\n componentDidUpdate(prevProps: EChartsReactProps) {\n /**\n * if shouldSetOption return false, then return, not update echarts options\n * default is true\n */\n const { shouldSetOption } = this.props;\n if (isFunction(shouldSetOption) && !shouldSetOption(prevProps, this.props)) {\n return;\n }\n\n // 以下属性修改的时候,需要 dispose 之后再新建\n // 1. 切换 theme 的时候\n // 2. 修改 opts 的时候\n // 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151\n if (\n !isEqual(prevProps.theme, this.props.theme) ||\n !isEqual(prevProps.opts, this.props.opts) ||\n !isEqual(prevProps.onEvents, this.props.onEvents)\n ) {\n this.dispose();\n\n this.renderNewEcharts(); // 重建\n return;\n }\n\n // when these props are not isEqual, update echarts\n const pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];\n if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {\n this.updateEChartsOption();\n }\n\n /**\n * when style or class name updated, change size.\n */\n if (!isEqual(prevProps.style, this.props.style) || !isEqual(prevProps.className, this.props.className)) {\n this.resize();\n }\n }\n\n componentWillUnmount() {\n this.dispose();\n }\n\n /**\n * return the echart object\n * 1. if exist, return the existed instance\n * 2. or new one instance\n */\n public getEchartsInstance(): ECharts {\n return this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts);\n }\n\n /**\n * dispose echarts and clear size-sensor\n */\n private dispose() {\n if (this.ele) {\n try {\n clear(this.ele);\n } catch (e) {\n console.warn(e);\n }\n // dispose echarts instance\n this.echarts.dispose(this.ele);\n }\n }\n\n /**\n * render a new echarts instance\n */\n private renderNewEcharts() {\n const { onEvents, onChartReady } = this.props;\n\n // 1. new echarts instance\n const echartsInstance = this.updateEChartsOption();\n\n // 2. bind events\n this.bindEvents(echartsInstance, onEvents || {});\n\n // 3. on chart ready\n if (isFunction(onChartReady)) onChartReady(echartsInstance);\n\n // 4. on resize\n if (this.ele) {\n bind(this.ele, () => {\n this.resize();\n });\n }\n }\n\n // bind the events\n private bindEvents(instance, events: EChartsReactProps['onEvents']) {\n function _bindEvent(eventName: string, func: Function) {\n // ignore the event config which not satisfy\n if (isString(eventName) && isFunction(func)) {\n // binding event\n instance.on(eventName, (param) => {\n func(param, instance);\n });\n }\n }\n\n // loop and bind\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n _bindEvent(eventName, events[eventName]);\n }\n }\n }\n\n /**\n * render the echarts\n */\n private updateEChartsOption(): EChartsInstance {\n const { option, notMerge = false, lazyUpdate = false, showLoading, loadingOption = null } = this.props;\n // 1. get or initial the echarts object\n const echartInstance = this.getEchartsInstance();\n // 2. set the echarts option\n echartInstance.setOption(option, notMerge, lazyUpdate);\n // 3. set loading mask\n if (showLoading) echartInstance.showLoading(loadingOption);\n else echartInstance.hideLoading();\n\n return echartInstance;\n }\n\n /**\n * resize wrapper\n */\n private resize() {\n // 1. get the echarts object\n const echartsInstance = this.getEchartsInstance();\n\n // 2. call echarts instance resize if not the initial resize\n // resize should not happen on first render as it will cancel initial echarts animations\n if (!this.isInitialResize) {\n try {\n echartsInstance.resize();\n } catch (e) {\n console.warn(e);\n }\n }\n\n // 3. update variable for future calls\n this.isInitialResize = false;\n }\n\n render(): JSX.Element {\n const { style, className = '' } = this.props;\n // default height = 300\n const newStyle = { height: 300, ...style };\n\n return (\n <div\n ref={(e: HTMLElement) => {\n this.ele = e;\n }}\n style={newStyle}\n className={`echarts-for-react ${className}`}\n />\n );\n }\n}\n"]}
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAG5C;;GAEG;AACH;IAA8C,oCAAgC;IAgB5E,0BAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAKb;QAHC,KAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,KAAI,CAAC,GAAG,GAAG,IAAI,CAAC;QAChB,KAAI,CAAC,eAA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AM,EAAE,EAAE,QAAQ,UAAA,EAAE,YAAY,cAAA,EAAE,UAAU,YAAA,EAAE,CAAC,CAAC;QACzE,sBAAsB;QACtB,IAAI,WAAW;YAAE,cAAc,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;;YACtD,cAAc,CAAC,WAAW,EAAE,CAAC;QAElC,OAAO,cAAc,CAAC;IACxB,CAAC;IAED;;OAEG;IACK,iCAAM,GAAd;QACE,4BAA4B;QAC5B,IAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAElD,4DAA4D;QAC5D,wFAAwF;QACxF,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,IAAI;gBACF,eAAe,CAAC,MAAM,CAAC;oBACrB,KAAK,EAAE,MAAM;oBACb,MAAM,EAAE,MAAM;iBACf,CAAC,CAAC;aACJ;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;SACF;QAED,sCAAsC;QACtC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;IAC/B,CAAC;IAED,iCAAM,GAAN;QAAA,iBAcC;QAbO,IAAA,KAA4B,IAAI,CAAC,KAAK,EAApC,KAAK,WAAA,EAAE,iBAAc,EAAd,SAAS,mBAAG,EAAE,KAAe,CAAC;QAC7C,uBAAuB;QACvB,IAAM,QAAQ,cAAK,MAAM,EAAE,GAAG,IAAK,KAAK,CAAE,CAAC;QAE3C,OAAO,CACL,6BACE,GAAG,EAAE,UAAC,CAAc;gBAClB,KAAI,CAAC,GAAG,GAAG,CAAC,CAAC;YACf,CAAC,EACD,KAAK,EAAE,QAAQ,EACf,SAAS,EAAE,4BAAqB,SAAS,CAAE,GAC3C,CACH,CAAC;IACJ,CAAC;IACH,uBAAC;AAAD,CAAC,AAvPD,CAA8C,aAAa,GAuP1D","sourcesContent":["import type { ECharts } from 'echarts';\nimport React, { PureComponent } from 'react';\nimport { bind, clear } from 'size-sensor';\nimport { pick } from './helper/pick';\nimport { isFunction } from './helper/is-function';\nimport { isString } from './helper/is-string';\nimport { isEqual } from './helper/is-equal';\nimport { EChartsReactProps, EChartsInstance } from './types';\n\n/**\n * core component for echarts binding\n */\nexport default class EChartsReactCore extends PureComponent<EChartsReactProps> {\n /**\n * echarts render container\n */\n public ele: HTMLElement;\n\n /**\n * if this is the first time we are resizing\n */\n private isInitialResize: boolean;\n\n /**\n * echarts library entry\n */\n protected echarts: any;\n\n constructor(props: EChartsReactProps) {\n super(props);\n\n this.echarts = props.echarts;\n this.ele = null;\n this.isInitialResize = true;\n }\n\n componentDidMount() {\n this.renderNewEcharts();\n }\n\n // update\n componentDidUpdate(prevProps: EChartsReactProps) {\n /**\n * if shouldSetOption return false, then return, not update echarts options\n * default is true\n */\n const { shouldSetOption } = this.props;\n if (isFunction(shouldSetOption) && !shouldSetOption(prevProps, this.props)) {\n return;\n }\n\n // 以下属性修改的时候,需要 dispose 之后再新建\n // 1. 切换 theme 的时候\n // 2. 修改 opts 的时候\n if (\n !isEqual(prevProps.theme, this.props.theme) ||\n !isEqual(prevProps.opts, this.props.opts)\n ) {\n this.dispose();\n\n this.renderNewEcharts(); // 重建\n return;\n }\n\n // 修改 onEvent 的时候先移除历史事件再添加\n const echartsInstance = this.getEchartsInstance();\n if (!isEqual(prevProps.onEvents, this.props.onEvents)) {\n this.offEvents(echartsInstance, prevProps.onEvents);\n this.bindEvents(echartsInstance, this.props.onEvents);\n }\n\n // when these props are not isEqual, update echarts\n const pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];\n if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {\n this.updateEChartsOption();\n }\n\n /**\n * when style or class name updated, change size.\n */\n if (!isEqual(prevProps.style, this.props.style) || !isEqual(prevProps.className, this.props.className)) {\n this.resize();\n }\n }\n\n componentWillUnmount() {\n this.dispose();\n }\n\n /*\n * initialise an echarts instance\n */\n public async initEchartsInstance(): Promise<ECharts> {\n return new Promise((resolve) => {\n // create temporary echart instance\n this.echarts.init(this.ele, this.props.theme, this.props.opts);\n const echartsInstance = this.getEchartsInstance();\n\n echartsInstance.on('finished', () => {\n // get final width and height\n const width = this.ele.clientWidth;\n const height = this.ele.clientHeight;\n\n // dispose temporary echart instance\n this.echarts.dispose(this.ele);\n\n // recreate echart instance\n // we use final width and height only if not originally provided as opts\n const opts = {\n width,\n height,\n ...this.props.opts,\n };\n resolve(this.echarts.init(this.ele, this.props.theme, opts));\n });\n });\n }\n\n /**\n * return the existing echart object\n */\n public getEchartsInstance(): ECharts {\n return this.echarts.getInstanceByDom(this.ele);\n }\n\n /**\n * dispose echarts and clear size-sensor\n */\n private dispose() {\n if (this.ele) {\n try {\n clear(this.ele);\n } catch (e) {\n console.warn(e);\n }\n // dispose echarts instance\n this.echarts.dispose(this.ele);\n }\n }\n\n /**\n * render a new echarts instance\n */\n private async renderNewEcharts() {\n const { onEvents, onChartReady, autoResize = true } = this.props;\n\n // 1. init echarts instance\n await this.initEchartsInstance();\n\n // 2. update echarts instance\n const echartsInstance = this.updateEChartsOption();\n\n // 3. bind events\n this.bindEvents(echartsInstance, onEvents || {});\n\n // 4. on chart ready\n if (isFunction(onChartReady)) onChartReady(echartsInstance);\n\n // 5. on resize\n if (this.ele && autoResize) {\n bind(this.ele, () => {\n this.resize();\n });\n }\n }\n\n // bind the events\n private bindEvents(instance, events: EChartsReactProps['onEvents']) {\n function _bindEvent(eventName: string, func: Function) {\n // ignore the event config which not satisfy\n if (isString(eventName) && isFunction(func)) {\n // binding event\n instance.on(eventName, (param) => {\n func(param, instance);\n });\n }\n }\n\n // loop and bind\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n _bindEvent(eventName, events[eventName]);\n }\n }\n }\n\n // off the events\n private offEvents(instance, events: EChartsReactProps['onEvents']) {\n if (!events) return;\n // loop and off\n for (const eventName in events) {\n if (isString(eventName)) {\n instance.off(eventName);\n }\n }\n }\n\n /**\n * render the echarts\n */\n private updateEChartsOption(): EChartsInstance {\n const {\n option,\n notMerge = false,\n replaceMerge = null,\n lazyUpdate = false,\n showLoading,\n loadingOption = null,\n } = this.props;\n // 1. get or initial the echarts object\n const echartInstance = this.getEchartsInstance();\n // 2. set the echarts option\n echartInstance.setOption(option, { notMerge, replaceMerge, lazyUpdate });\n // 3. set loading mask\n if (showLoading) echartInstance.showLoading(loadingOption);\n else echartInstance.hideLoading();\n\n return echartInstance;\n }\n\n /**\n * resize wrapper\n */\n private resize() {\n // 1. get the echarts object\n const echartsInstance = this.getEchartsInstance();\n\n // 2. call echarts instance resize if not the initial resize\n // resize should not happen on first render as it will cancel initial echarts animations\n if (!this.isInitialResize) {\n try {\n echartsInstance.resize({\n width: 'auto',\n height: 'auto',\n });\n } catch (e) {\n console.warn(e);\n }\n }\n\n // 3. update variable for future calls\n this.isInitialResize = false;\n }\n\n render(): JSX.Element {\n const { style, className = '' } = this.props;\n // default height = 300\n const newStyle = { height: 300, ...style };\n\n return (\n <div\n ref={(e: HTMLElement) => {\n this.ele = e;\n }}\n style={newStyle}\n className={`echarts-for-react ${className}`}\n />\n );\n }\n}\n"]}
package/esm/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EChartsReactProps, EChartsOption, EChartsInstance } from './types';
2
2
  import EChartsReactCore from './core';
3
- export { EChartsReactProps, EChartsOption, EChartsInstance };
3
+ export type { EChartsReactProps, EChartsOption, EChartsInstance };
4
4
  export default class EChartsReact extends EChartsReactCore {
5
5
  constructor(props: EChartsReactProps);
6
6
  }
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,gBAAgB,MAAM,QAAQ,CAAC;AAItC,2CAA2C;AAC3C;IAA0C,gCAAgB;IACxD,sBAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAIb;QAFC,mBAAmB;QACnB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;;IACzB,CAAC;IACH,mBAAC;AAAD,CAAC,AAPD,CAA0C,gBAAgB,GAOzD","sourcesContent":["import * as echarts from 'echarts';\nimport { EChartsReactProps, EChartsOption, EChartsInstance } from './types';\nimport EChartsReactCore from './core';\n\nexport { EChartsReactProps, EChartsOption, EChartsInstance };\n\n// export the Component the echarts Object.\nexport default class EChartsReact extends EChartsReactCore {\n constructor(props: EChartsReactProps) {\n super(props);\n\n // 初始化为 echarts 整个包\n this.echarts = echarts;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,gBAAgB,MAAM,QAAQ,CAAC;AAItC,2CAA2C;AAC3C;IAA0C,gCAAgB;IACxD,sBAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAIb;QAFC,mBAAmB;QACnB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;;IACzB,CAAC;IACH,mBAAC;AAAD,CAAC,AAPD,CAA0C,gBAAgB,GAOzD","sourcesContent":["import * as echarts from 'echarts';\nimport { EChartsReactProps, EChartsOption, EChartsInstance } from './types';\nimport EChartsReactCore from './core';\n\nexport type { EChartsReactProps, EChartsOption, EChartsInstance };\n\n// export the Component the echarts Object.\nexport default class EChartsReact extends EChartsReactCore {\n constructor(props: EChartsReactProps) {\n super(props);\n\n // 初始化为 echarts 整个包\n this.echarts = echarts;\n }\n}\n"]}
package/esm/types.d.ts CHANGED
@@ -1,14 +1,18 @@
1
- import { CSSProperties } from 'react';
2
- export declare type EChartsOption = any;
3
- export declare type EChartsInstance = any;
4
- export declare type Opts = {
1
+ import type { CSSProperties } from 'react';
2
+ import type { EChartsType } from 'echarts';
3
+ /**
4
+ * Solve the type conflict caused by multiple type files
5
+ */
6
+ export type EChartsOption = any;
7
+ export type EChartsInstance = EChartsType;
8
+ export type Opts = {
5
9
  readonly devicePixelRatio?: number;
6
10
  readonly renderer?: 'canvas' | 'svg';
7
11
  readonly width?: number | null | undefined | 'auto';
8
12
  readonly height?: number | null | undefined | 'auto';
9
13
  readonly locale?: string;
10
14
  };
11
- export declare type EChartsReactProps = {
15
+ export type EChartsReactProps = {
12
16
  /**
13
17
  * echarts library entry, use it for import necessary.
14
18
  */
@@ -35,6 +39,10 @@ export declare type EChartsReactProps = {
35
39
  * notMerge config for echarts, default is `false`
36
40
  */
37
41
  readonly notMerge?: boolean;
42
+ /**
43
+ * replaceMerge config for echarts, default is `null`
44
+ */
45
+ readonly replaceMerge?: string | string[];
38
46
  /**
39
47
  * lazyUpdate config for echarts, default is `false`
40
48
  */
@@ -52,7 +60,7 @@ export declare type EChartsReactProps = {
52
60
  */
53
61
  readonly opts?: Opts;
54
62
  /**
55
- * when after chart reander, do the callback widht echarts instance
63
+ * when after chart render, do the callback with echarts instance
56
64
  */
57
65
  readonly onChartReady?: (instance: EChartsInstance) => void;
58
66
  /**
@@ -63,4 +71,8 @@ export declare type EChartsReactProps = {
63
71
  * should update echarts options
64
72
  */
65
73
  readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;
74
+ /**
75
+ * should trigger resize when window resize
76
+ */
77
+ readonly autoResize?: boolean;
66
78
  };
package/esm/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { CSSProperties } from 'react';\n\nexport type EChartsOption = any;\n\nexport type EChartsInstance = any;\n\nexport type Opts = {\n readonly devicePixelRatio?: number;\n readonly renderer?: 'canvas' | 'svg';\n readonly width?: number | null | undefined | 'auto';\n readonly height?: number | null | undefined | 'auto';\n readonly locale?: string;\n};\n\nexport type EChartsReactProps = {\n /**\n * echarts library entry, use it for import necessary.\n */\n readonly echarts?: any;\n /**\n * `className` for container\n */\n readonly className?: string;\n /**\n * `style` for container\n */\n readonly style?: CSSProperties;\n /**\n * echarts option\n */\n readonly option: EChartsOption;\n /**\n * echarts theme config, can be:\n * 1. theme name string\n * 2. theme object\n */\n readonly theme?: string | Record<string, any>;\n /**\n * notMerge config for echarts, default is `false`\n */\n readonly notMerge?: boolean;\n /**\n * lazyUpdate config for echarts, default is `false`\n */\n readonly lazyUpdate?: boolean;\n /**\n * showLoading config for echarts, default is `false`\n */\n readonly showLoading?: boolean;\n /**\n * loadingOption config for echarts, default is `null`\n */\n readonly loadingOption?: any;\n /**\n * echarts opts config, default is `{}`\n */\n readonly opts?: Opts;\n /**\n * when after chart reander, do the callback widht echarts instance\n */\n readonly onChartReady?: (instance: EChartsInstance) => void;\n /**\n * bind events, default is `{}`\n */\n readonly onEvents?: Record<string, Function>;\n /**\n * should update echarts options\n */\n readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CSSProperties } from 'react';\nimport type { EChartsType } from 'echarts';\n\n/**\n * Solve the type conflict caused by multiple type files\n */\nexport type EChartsOption = any;\n\nexport type EChartsInstance = EChartsType;\n\nexport type Opts = {\n readonly devicePixelRatio?: number;\n readonly renderer?: 'canvas' | 'svg';\n readonly width?: number | null | undefined | 'auto';\n readonly height?: number | null | undefined | 'auto';\n readonly locale?: string;\n};\n\nexport type EChartsReactProps = {\n /**\n * echarts library entry, use it for import necessary.\n */\n readonly echarts?: any;\n /**\n * `className` for container\n */\n readonly className?: string;\n /**\n * `style` for container\n */\n readonly style?: CSSProperties;\n /**\n * echarts option\n */\n readonly option: EChartsOption;\n /**\n * echarts theme config, can be:\n * 1. theme name string\n * 2. theme object\n */\n readonly theme?: string | Record<string, any>;\n /**\n * notMerge config for echarts, default is `false`\n */\n readonly notMerge?: boolean;\n /**\n * replaceMerge config for echarts, default is `null`\n */\n readonly replaceMerge?: string | string[];\n /**\n * lazyUpdate config for echarts, default is `false`\n */\n readonly lazyUpdate?: boolean;\n /**\n * showLoading config for echarts, default is `false`\n */\n readonly showLoading?: boolean;\n /**\n * loadingOption config for echarts, default is `null`\n */\n readonly loadingOption?: any;\n /**\n * echarts opts config, default is `{}`\n */\n readonly opts?: Opts;\n /**\n * when after chart render, do the callback with echarts instance\n */\n readonly onChartReady?: (instance: EChartsInstance) => void;\n /**\n * bind events, default is `{}`\n */\n readonly onEvents?: Record<string, Function>;\n /**\n * should update echarts options\n */\n readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;\n\n /**\n * should trigger resize when window resize\n */\n readonly autoResize?: boolean;\n};\n"]}
package/lib/core.d.ts CHANGED
@@ -21,10 +21,9 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
21
21
  componentDidMount(): void;
22
22
  componentDidUpdate(prevProps: EChartsReactProps): void;
23
23
  componentWillUnmount(): void;
24
+ initEchartsInstance(): Promise<ECharts>;
24
25
  /**
25
- * return the echart object
26
- * 1. if exist, return the existed instance
27
- * 2. or new one instance
26
+ * return the existing echart object
28
27
  */
29
28
  getEchartsInstance(): ECharts;
30
29
  /**
@@ -36,6 +35,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
36
35
  */
37
36
  private renderNewEcharts;
38
37
  private bindEvents;
38
+ private offEvents;
39
39
  /**
40
40
  * render the echarts
41
41
  */
package/lib/core.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
- var react_1 = (0, tslib_1.__importStar)(require("react"));
4
+ var react_1 = tslib_1.__importStar(require("react"));
5
5
  var size_sensor_1 = require("size-sensor");
6
6
  var pick_1 = require("./helper/pick");
7
7
  var is_function_1 = require("./helper/is-function");
@@ -11,7 +11,7 @@ var is_equal_1 = require("./helper/is-equal");
11
11
  * core component for echarts binding
12
12
  */
13
13
  var EChartsReactCore = /** @class */ (function (_super) {
14
- (0, tslib_1.__extends)(EChartsReactCore, _super);
14
+ tslib_1.__extends(EChartsReactCore, _super);
15
15
  function EChartsReactCore(props) {
16
16
  var _this = _super.call(this, props) || this;
17
17
  _this.echarts = props.echarts;
@@ -35,16 +35,20 @@ var EChartsReactCore = /** @class */ (function (_super) {
35
35
  // 以下属性修改的时候,需要 dispose 之后再新建
36
36
  // 1. 切换 theme 的时候
37
37
  // 2. 修改 opts 的时候
38
- // 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151
39
38
  if (!(0, is_equal_1.isEqual)(prevProps.theme, this.props.theme) ||
40
- !(0, is_equal_1.isEqual)(prevProps.opts, this.props.opts) ||
41
- !(0, is_equal_1.isEqual)(prevProps.onEvents, this.props.onEvents)) {
39
+ !(0, is_equal_1.isEqual)(prevProps.opts, this.props.opts)) {
42
40
  this.dispose();
43
41
  this.renderNewEcharts(); // 重建
44
42
  return;
45
43
  }
44
+ // 修改 onEvent 的时候先移除历史事件再添加
45
+ var echartsInstance = this.getEchartsInstance();
46
+ if (!(0, is_equal_1.isEqual)(prevProps.onEvents, this.props.onEvents)) {
47
+ this.offEvents(echartsInstance, prevProps.onEvents);
48
+ this.bindEvents(echartsInstance, this.props.onEvents);
49
+ }
46
50
  // when these props are not isEqual, update echarts
47
- var pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
51
+ var pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
48
52
  if (!(0, is_equal_1.isEqual)((0, pick_1.pick)(this.props, pickKeys), (0, pick_1.pick)(prevProps, pickKeys))) {
49
53
  this.updateEChartsOption();
50
54
  }
@@ -58,13 +62,37 @@ var EChartsReactCore = /** @class */ (function (_super) {
58
62
  EChartsReactCore.prototype.componentWillUnmount = function () {
59
63
  this.dispose();
60
64
  };
65
+ /*
66
+ * initialise an echarts instance
67
+ */
68
+ EChartsReactCore.prototype.initEchartsInstance = function () {
69
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
70
+ var _this = this;
71
+ return tslib_1.__generator(this, function (_a) {
72
+ return [2 /*return*/, new Promise(function (resolve) {
73
+ // create temporary echart instance
74
+ _this.echarts.init(_this.ele, _this.props.theme, _this.props.opts);
75
+ var echartsInstance = _this.getEchartsInstance();
76
+ echartsInstance.on('finished', function () {
77
+ // get final width and height
78
+ var width = _this.ele.clientWidth;
79
+ var height = _this.ele.clientHeight;
80
+ // dispose temporary echart instance
81
+ _this.echarts.dispose(_this.ele);
82
+ // recreate echart instance
83
+ // we use final width and height only if not originally provided as opts
84
+ var opts = tslib_1.__assign({ width: width, height: height }, _this.props.opts);
85
+ resolve(_this.echarts.init(_this.ele, _this.props.theme, opts));
86
+ });
87
+ })];
88
+ });
89
+ });
90
+ };
61
91
  /**
62
- * return the echart object
63
- * 1. if exist, return the existed instance
64
- * 2. or new one instance
92
+ * return the existing echart object
65
93
  */
66
94
  EChartsReactCore.prototype.getEchartsInstance = function () {
67
- return this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts);
95
+ return this.echarts.getInstanceByDom(this.ele);
68
96
  };
69
97
  /**
70
98
  * dispose echarts and clear size-sensor
@@ -85,21 +113,34 @@ var EChartsReactCore = /** @class */ (function (_super) {
85
113
  * render a new echarts instance
86
114
  */
87
115
  EChartsReactCore.prototype.renderNewEcharts = function () {
88
- var _this = this;
89
- var _a = this.props, onEvents = _a.onEvents, onChartReady = _a.onChartReady;
90
- // 1. new echarts instance
91
- var echartsInstance = this.updateEChartsOption();
92
- // 2. bind events
93
- this.bindEvents(echartsInstance, onEvents || {});
94
- // 3. on chart ready
95
- if ((0, is_function_1.isFunction)(onChartReady))
96
- onChartReady(echartsInstance);
97
- // 4. on resize
98
- if (this.ele) {
99
- (0, size_sensor_1.bind)(this.ele, function () {
100
- _this.resize();
116
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
117
+ var _a, onEvents, onChartReady, _b, autoResize, echartsInstance;
118
+ var _this = this;
119
+ return tslib_1.__generator(this, function (_c) {
120
+ switch (_c.label) {
121
+ case 0:
122
+ _a = this.props, onEvents = _a.onEvents, onChartReady = _a.onChartReady, _b = _a.autoResize, autoResize = _b === void 0 ? true : _b;
123
+ // 1. init echarts instance
124
+ return [4 /*yield*/, this.initEchartsInstance()];
125
+ case 1:
126
+ // 1. init echarts instance
127
+ _c.sent();
128
+ echartsInstance = this.updateEChartsOption();
129
+ // 3. bind events
130
+ this.bindEvents(echartsInstance, onEvents || {});
131
+ // 4. on chart ready
132
+ if ((0, is_function_1.isFunction)(onChartReady))
133
+ onChartReady(echartsInstance);
134
+ // 5. on resize
135
+ if (this.ele && autoResize) {
136
+ (0, size_sensor_1.bind)(this.ele, function () {
137
+ _this.resize();
138
+ });
139
+ }
140
+ return [2 /*return*/];
141
+ }
101
142
  });
102
- }
143
+ });
103
144
  };
104
145
  // bind the events
105
146
  EChartsReactCore.prototype.bindEvents = function (instance, events) {
@@ -119,15 +160,26 @@ var EChartsReactCore = /** @class */ (function (_super) {
119
160
  }
120
161
  }
121
162
  };
163
+ // off the events
164
+ EChartsReactCore.prototype.offEvents = function (instance, events) {
165
+ if (!events)
166
+ return;
167
+ // loop and off
168
+ for (var eventName in events) {
169
+ if ((0, is_string_1.isString)(eventName)) {
170
+ instance.off(eventName);
171
+ }
172
+ }
173
+ };
122
174
  /**
123
175
  * render the echarts
124
176
  */
125
177
  EChartsReactCore.prototype.updateEChartsOption = function () {
126
- var _a = this.props, option = _a.option, _b = _a.notMerge, notMerge = _b === void 0 ? false : _b, _c = _a.lazyUpdate, lazyUpdate = _c === void 0 ? false : _c, showLoading = _a.showLoading, _d = _a.loadingOption, loadingOption = _d === void 0 ? null : _d;
178
+ var _a = this.props, option = _a.option, _b = _a.notMerge, notMerge = _b === void 0 ? false : _b, _c = _a.replaceMerge, replaceMerge = _c === void 0 ? null : _c, _d = _a.lazyUpdate, lazyUpdate = _d === void 0 ? false : _d, showLoading = _a.showLoading, _e = _a.loadingOption, loadingOption = _e === void 0 ? null : _e;
127
179
  // 1. get or initial the echarts object
128
180
  var echartInstance = this.getEchartsInstance();
129
181
  // 2. set the echarts option
130
- echartInstance.setOption(option, notMerge, lazyUpdate);
182
+ echartInstance.setOption(option, { notMerge: notMerge, replaceMerge: replaceMerge, lazyUpdate: lazyUpdate });
131
183
  // 3. set loading mask
132
184
  if (showLoading)
133
185
  echartInstance.showLoading(loadingOption);
@@ -145,7 +197,10 @@ var EChartsReactCore = /** @class */ (function (_super) {
145
197
  // resize should not happen on first render as it will cancel initial echarts animations
146
198
  if (!this.isInitialResize) {
147
199
  try {
148
- echartsInstance.resize();
200
+ echartsInstance.resize({
201
+ width: 'auto',
202
+ height: 'auto',
203
+ });
149
204
  }
150
205
  catch (e) {
151
206
  console.warn(e);
@@ -158,10 +213,10 @@ var EChartsReactCore = /** @class */ (function (_super) {
158
213
  var _this = this;
159
214
  var _a = this.props, style = _a.style, _b = _a.className, className = _b === void 0 ? '' : _b;
160
215
  // default height = 300
161
- var newStyle = (0, tslib_1.__assign)({ height: 300 }, style);
216
+ var newStyle = tslib_1.__assign({ height: 300 }, style);
162
217
  return (react_1.default.createElement("div", { ref: function (e) {
163
218
  _this.ele = e;
164
- }, style: newStyle, className: "echarts-for-react " + className }));
219
+ }, style: newStyle, className: "echarts-for-react ".concat(className) }));
165
220
  };
166
221
  return EChartsReactCore;
167
222
  }(react_1.PureComponent));
package/lib/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";;;AACA,0DAA6C;AAC7C,2CAA0C;AAC1C,sCAAqC;AACrC,oDAAkD;AAClD,gDAA8C;AAC9C,8CAA4C;AAG5C;;GAEG;AACH;IAA8C,iDAAgC;IAgB5E,0BAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAKb;QAHC,KAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,KAAI,CAAC,GAAG,G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C,WAAW,CAAC,aAAa,CAAC,CAAC;;YACtD,cAAc,CAAC,WAAW,EAAE,CAAC;QAElC,OAAO,cAAc,CAAC;IACxB,CAAC;IAED;;OAEG;IACK,iCAAM,GAAd;QACE,4BAA4B;QAC5B,IAAM,eAAe,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAElD,4DAA4D;QAC5D,wFAAwF;QACxF,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE;YACzB,IAAI;gBACF,eAAe,CAAC,MAAM,EAAE,CAAC;aAC1B;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;SACF;QAED,sCAAsC;QACtC,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;IAC/B,CAAC;IAED,iCAAM,GAAN;QAAA,iBAcC;QAbO,IAAA,KAA4B,IAAI,CAAC,KAAK,EAApC,KAAK,WAAA,EAAE,iBAAc,EAAd,SAAS,mBAAG,EAAE,KAAe,CAAC;QAC7C,uBAAuB;QACvB,IAAM,QAAQ,2BAAK,MAAM,EAAE,GAAG,IAAK,KAAK,CAAE,CAAC;QAE3C,OAAO,CACL,uCACE,GAAG,EAAE,UAAC,CAAc;gBAClB,KAAI,CAAC,GAAG,GAAG,CAAC,CAAC;YACf,CAAC,EACD,KAAK,EAAE,QAAQ,EACf,SAAS,EAAE,uBAAqB,SAAW,GAC3C,CACH,CAAC;IACJ,CAAC;IACH,uBAAC;AAAD,CAAC,AA/LD,CAA8C,qBAAa,GA+L1D","sourcesContent":["import type { ECharts } from 'echarts';\nimport React, { PureComponent } from 'react';\nimport { bind, clear } from 'size-sensor';\nimport { pick } from './helper/pick';\nimport { isFunction } from './helper/is-function';\nimport { isString } from './helper/is-string';\nimport { isEqual } from './helper/is-equal';\nimport { EChartsReactProps, EChartsInstance } from './types';\n\n/**\n * core component for echarts binding\n */\nexport default class EChartsReactCore extends PureComponent<EChartsReactProps> {\n /**\n * echarts render container\n */\n public ele: HTMLElement;\n\n /**\n * if this is the first time we are resizing\n */\n private isInitialResize: boolean;\n\n /**\n * echarts library entry\n */\n protected echarts: any;\n\n constructor(props: EChartsReactProps) {\n super(props);\n\n this.echarts = props.echarts;\n this.ele = null;\n this.isInitialResize = true;\n }\n\n componentDidMount() {\n this.renderNewEcharts();\n }\n\n // update\n componentDidUpdate(prevProps: EChartsReactProps) {\n /**\n * if shouldSetOption return false, then return, not update echarts options\n * default is true\n */\n const { shouldSetOption } = this.props;\n if (isFunction(shouldSetOption) && !shouldSetOption(prevProps, this.props)) {\n return;\n }\n\n // 以下属性修改的时候,需要 dispose 之后再新建\n // 1. 切换 theme 的时候\n // 2. 修改 opts 的时候\n // 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151\n if (\n !isEqual(prevProps.theme, this.props.theme) ||\n !isEqual(prevProps.opts, this.props.opts) ||\n !isEqual(prevProps.onEvents, this.props.onEvents)\n ) {\n this.dispose();\n\n this.renderNewEcharts(); // 重建\n return;\n }\n\n // when these props are not isEqual, update echarts\n const pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];\n if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {\n this.updateEChartsOption();\n }\n\n /**\n * when style or class name updated, change size.\n */\n if (!isEqual(prevProps.style, this.props.style) || !isEqual(prevProps.className, this.props.className)) {\n this.resize();\n }\n }\n\n componentWillUnmount() {\n this.dispose();\n }\n\n /**\n * return the echart object\n * 1. if exist, return the existed instance\n * 2. or new one instance\n */\n public getEchartsInstance(): ECharts {\n return this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts);\n }\n\n /**\n * dispose echarts and clear size-sensor\n */\n private dispose() {\n if (this.ele) {\n try {\n clear(this.ele);\n } catch (e) {\n console.warn(e);\n }\n // dispose echarts instance\n this.echarts.dispose(this.ele);\n }\n }\n\n /**\n * render a new echarts instance\n */\n private renderNewEcharts() {\n const { onEvents, onChartReady } = this.props;\n\n // 1. new echarts instance\n const echartsInstance = this.updateEChartsOption();\n\n // 2. bind events\n this.bindEvents(echartsInstance, onEvents || {});\n\n // 3. on chart ready\n if (isFunction(onChartReady)) onChartReady(echartsInstance);\n\n // 4. on resize\n if (this.ele) {\n bind(this.ele, () => {\n this.resize();\n });\n }\n }\n\n // bind the events\n private bindEvents(instance, events: EChartsReactProps['onEvents']) {\n function _bindEvent(eventName: string, func: Function) {\n // ignore the event config which not satisfy\n if (isString(eventName) && isFunction(func)) {\n // binding event\n instance.on(eventName, (param) => {\n func(param, instance);\n });\n }\n }\n\n // loop and bind\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n _bindEvent(eventName, events[eventName]);\n }\n }\n }\n\n /**\n * render the echarts\n */\n private updateEChartsOption(): EChartsInstance {\n const { option, notMerge = false, lazyUpdate = false, showLoading, loadingOption = null } = this.props;\n // 1. get or initial the echarts object\n const echartInstance = this.getEchartsInstance();\n // 2. set the echarts option\n echartInstance.setOption(option, notMerge, lazyUpdate);\n // 3. set loading mask\n if (showLoading) echartInstance.showLoading(loadingOption);\n else echartInstance.hideLoading();\n\n return echartInstance;\n }\n\n /**\n * resize wrapper\n */\n private resize() {\n // 1. get the echarts object\n const echartsInstance = this.getEchartsInstance();\n\n // 2. call echarts instance resize if not the initial resize\n // resize should not happen on first render as it will cancel initial echarts animations\n if (!this.isInitialResize) {\n try {\n echartsInstance.resize();\n } catch (e) {\n console.warn(e);\n }\n }\n\n // 3. update variable for future calls\n this.isInitialResize = false;\n }\n\n render(): JSX.Element {\n const { style, className = '' } = this.props;\n // default height = 300\n const newStyle = { height: 300, ...style };\n\n return (\n <div\n ref={(e: HTMLElement) => {\n this.ele = e;\n }}\n style={newStyle}\n className={`echarts-for-react ${className}`}\n />\n );\n }\n}\n"]}
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";;;AACA,qDAA6C;AAC7C,2CAA0C;AAC1C,sCAAqC;AAC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AAG,IAAK,KAAK,CAAE,CAAC;QAE3C,OAAO,CACL,uCACE,GAAG,EAAE,UAAC,CAAc;gBAClB,KAAI,CAAC,GAAG,GAAG,CAAC,CAAC;YACf,CAAC,EACD,KAAK,EAAE,QAAQ,EACf,SAAS,EAAE,4BAAqB,SAAS,CAAE,GAC3C,CACH,CAAC;IACJ,CAAC;IACH,uBAAC;AAAD,CAAC,AAvPD,CAA8C,qBAAa,GAuP1D","sourcesContent":["import type { ECharts } from 'echarts';\nimport React, { PureComponent } from 'react';\nimport { bind, clear } from 'size-sensor';\nimport { pick } from './helper/pick';\nimport { isFunction } from './helper/is-function';\nimport { isString } from './helper/is-string';\nimport { isEqual } from './helper/is-equal';\nimport { EChartsReactProps, EChartsInstance } from './types';\n\n/**\n * core component for echarts binding\n */\nexport default class EChartsReactCore extends PureComponent<EChartsReactProps> {\n /**\n * echarts render container\n */\n public ele: HTMLElement;\n\n /**\n * if this is the first time we are resizing\n */\n private isInitialResize: boolean;\n\n /**\n * echarts library entry\n */\n protected echarts: any;\n\n constructor(props: EChartsReactProps) {\n super(props);\n\n this.echarts = props.echarts;\n this.ele = null;\n this.isInitialResize = true;\n }\n\n componentDidMount() {\n this.renderNewEcharts();\n }\n\n // update\n componentDidUpdate(prevProps: EChartsReactProps) {\n /**\n * if shouldSetOption return false, then return, not update echarts options\n * default is true\n */\n const { shouldSetOption } = this.props;\n if (isFunction(shouldSetOption) && !shouldSetOption(prevProps, this.props)) {\n return;\n }\n\n // 以下属性修改的时候,需要 dispose 之后再新建\n // 1. 切换 theme 的时候\n // 2. 修改 opts 的时候\n if (\n !isEqual(prevProps.theme, this.props.theme) ||\n !isEqual(prevProps.opts, this.props.opts)\n ) {\n this.dispose();\n\n this.renderNewEcharts(); // 重建\n return;\n }\n\n // 修改 onEvent 的时候先移除历史事件再添加\n const echartsInstance = this.getEchartsInstance();\n if (!isEqual(prevProps.onEvents, this.props.onEvents)) {\n this.offEvents(echartsInstance, prevProps.onEvents);\n this.bindEvents(echartsInstance, this.props.onEvents);\n }\n\n // when these props are not isEqual, update echarts\n const pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];\n if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {\n this.updateEChartsOption();\n }\n\n /**\n * when style or class name updated, change size.\n */\n if (!isEqual(prevProps.style, this.props.style) || !isEqual(prevProps.className, this.props.className)) {\n this.resize();\n }\n }\n\n componentWillUnmount() {\n this.dispose();\n }\n\n /*\n * initialise an echarts instance\n */\n public async initEchartsInstance(): Promise<ECharts> {\n return new Promise((resolve) => {\n // create temporary echart instance\n this.echarts.init(this.ele, this.props.theme, this.props.opts);\n const echartsInstance = this.getEchartsInstance();\n\n echartsInstance.on('finished', () => {\n // get final width and height\n const width = this.ele.clientWidth;\n const height = this.ele.clientHeight;\n\n // dispose temporary echart instance\n this.echarts.dispose(this.ele);\n\n // recreate echart instance\n // we use final width and height only if not originally provided as opts\n const opts = {\n width,\n height,\n ...this.props.opts,\n };\n resolve(this.echarts.init(this.ele, this.props.theme, opts));\n });\n });\n }\n\n /**\n * return the existing echart object\n */\n public getEchartsInstance(): ECharts {\n return this.echarts.getInstanceByDom(this.ele);\n }\n\n /**\n * dispose echarts and clear size-sensor\n */\n private dispose() {\n if (this.ele) {\n try {\n clear(this.ele);\n } catch (e) {\n console.warn(e);\n }\n // dispose echarts instance\n this.echarts.dispose(this.ele);\n }\n }\n\n /**\n * render a new echarts instance\n */\n private async renderNewEcharts() {\n const { onEvents, onChartReady, autoResize = true } = this.props;\n\n // 1. init echarts instance\n await this.initEchartsInstance();\n\n // 2. update echarts instance\n const echartsInstance = this.updateEChartsOption();\n\n // 3. bind events\n this.bindEvents(echartsInstance, onEvents || {});\n\n // 4. on chart ready\n if (isFunction(onChartReady)) onChartReady(echartsInstance);\n\n // 5. on resize\n if (this.ele && autoResize) {\n bind(this.ele, () => {\n this.resize();\n });\n }\n }\n\n // bind the events\n private bindEvents(instance, events: EChartsReactProps['onEvents']) {\n function _bindEvent(eventName: string, func: Function) {\n // ignore the event config which not satisfy\n if (isString(eventName) && isFunction(func)) {\n // binding event\n instance.on(eventName, (param) => {\n func(param, instance);\n });\n }\n }\n\n // loop and bind\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n _bindEvent(eventName, events[eventName]);\n }\n }\n }\n\n // off the events\n private offEvents(instance, events: EChartsReactProps['onEvents']) {\n if (!events) return;\n // loop and off\n for (const eventName in events) {\n if (isString(eventName)) {\n instance.off(eventName);\n }\n }\n }\n\n /**\n * render the echarts\n */\n private updateEChartsOption(): EChartsInstance {\n const {\n option,\n notMerge = false,\n replaceMerge = null,\n lazyUpdate = false,\n showLoading,\n loadingOption = null,\n } = this.props;\n // 1. get or initial the echarts object\n const echartInstance = this.getEchartsInstance();\n // 2. set the echarts option\n echartInstance.setOption(option, { notMerge, replaceMerge, lazyUpdate });\n // 3. set loading mask\n if (showLoading) echartInstance.showLoading(loadingOption);\n else echartInstance.hideLoading();\n\n return echartInstance;\n }\n\n /**\n * resize wrapper\n */\n private resize() {\n // 1. get the echarts object\n const echartsInstance = this.getEchartsInstance();\n\n // 2. call echarts instance resize if not the initial resize\n // resize should not happen on first render as it will cancel initial echarts animations\n if (!this.isInitialResize) {\n try {\n echartsInstance.resize({\n width: 'auto',\n height: 'auto',\n });\n } catch (e) {\n console.warn(e);\n }\n }\n\n // 3. update variable for future calls\n this.isInitialResize = false;\n }\n\n render(): JSX.Element {\n const { style, className = '' } = this.props;\n // default height = 300\n const newStyle = { height: 300, ...style };\n\n return (\n <div\n ref={(e: HTMLElement) => {\n this.ele = e;\n }}\n style={newStyle}\n className={`echarts-for-react ${className}`}\n />\n );\n }\n}\n"]}
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEqual = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var fast_deep_equal_1 = (0, tslib_1.__importDefault)(require("fast-deep-equal"));
5
+ var fast_deep_equal_1 = tslib_1.__importDefault(require("fast-deep-equal"));
6
6
  exports.isEqual = fast_deep_equal_1.default;
7
7
  //# sourceMappingURL=is-equal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-equal.js","sourceRoot":"","sources":["../../src/helper/is-equal.ts"],"names":[],"mappings":";;;;AAAA,iFAAsC;AAE7B,kBAFF,yBAAO,CAEE","sourcesContent":["import isEqual from 'fast-deep-equal';\n\nexport { isEqual };\n"]}
1
+ {"version":3,"file":"is-equal.js","sourceRoot":"","sources":["../../src/helper/is-equal.ts"],"names":[],"mappings":";;;;AAAA,4EAAsC;AAE7B,kBAFF,yBAAO,CAEE","sourcesContent":["import isEqual from 'fast-deep-equal';\n\nexport { isEqual };\n"]}
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EChartsReactProps, EChartsOption, EChartsInstance } from './types';
2
2
  import EChartsReactCore from './core';
3
- export { EChartsReactProps, EChartsOption, EChartsInstance };
3
+ export type { EChartsReactProps, EChartsOption, EChartsInstance };
4
4
  export default class EChartsReact extends EChartsReactCore {
5
5
  constructor(props: EChartsReactProps);
6
6
  }
package/lib/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  var tslib_1 = require("tslib");
4
- var echarts = (0, tslib_1.__importStar)(require("echarts"));
5
- var core_1 = (0, tslib_1.__importDefault)(require("./core"));
4
+ var echarts = tslib_1.__importStar(require("echarts"));
5
+ var core_1 = tslib_1.__importDefault(require("./core"));
6
6
  // export the Component the echarts Object.
7
7
  var EChartsReact = /** @class */ (function (_super) {
8
- (0, tslib_1.__extends)(EChartsReact, _super);
8
+ tslib_1.__extends(EChartsReact, _super);
9
9
  function EChartsReact(props) {
10
10
  var _this = _super.call(this, props) || this;
11
11
  // 初始化为 echarts 整个包
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAmC;AAEnC,6DAAsC;AAItC,2CAA2C;AAC3C;IAA0C,6CAAgB;IACxD,sBAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAIb;QAFC,mBAAmB;QACnB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;;IACzB,CAAC;IACH,mBAAC;AAAD,CAAC,AAPD,CAA0C,cAAgB,GAOzD","sourcesContent":["import * as echarts from 'echarts';\nimport { EChartsReactProps, EChartsOption, EChartsInstance } from './types';\nimport EChartsReactCore from './core';\n\nexport { EChartsReactProps, EChartsOption, EChartsInstance };\n\n// export the Component the echarts Object.\nexport default class EChartsReact extends EChartsReactCore {\n constructor(props: EChartsReactProps) {\n super(props);\n\n // 初始化为 echarts 整个包\n this.echarts = echarts;\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAmC;AAEnC,wDAAsC;AAItC,2CAA2C;AAC3C;IAA0C,wCAAgB;IACxD,sBAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAIb;QAFC,mBAAmB;QACnB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAC;;IACzB,CAAC;IACH,mBAAC;AAAD,CAAC,AAPD,CAA0C,cAAgB,GAOzD","sourcesContent":["import * as echarts from 'echarts';\nimport { EChartsReactProps, EChartsOption, EChartsInstance } from './types';\nimport EChartsReactCore from './core';\n\nexport type { EChartsReactProps, EChartsOption, EChartsInstance };\n\n// export the Component the echarts Object.\nexport default class EChartsReact extends EChartsReactCore {\n constructor(props: EChartsReactProps) {\n super(props);\n\n // 初始化为 echarts 整个包\n this.echarts = echarts;\n }\n}\n"]}
package/lib/types.d.ts CHANGED
@@ -1,14 +1,18 @@
1
- import { CSSProperties } from 'react';
2
- export declare type EChartsOption = any;
3
- export declare type EChartsInstance = any;
4
- export declare type Opts = {
1
+ import type { CSSProperties } from 'react';
2
+ import type { EChartsType } from 'echarts';
3
+ /**
4
+ * Solve the type conflict caused by multiple type files
5
+ */
6
+ export type EChartsOption = any;
7
+ export type EChartsInstance = EChartsType;
8
+ export type Opts = {
5
9
  readonly devicePixelRatio?: number;
6
10
  readonly renderer?: 'canvas' | 'svg';
7
11
  readonly width?: number | null | undefined | 'auto';
8
12
  readonly height?: number | null | undefined | 'auto';
9
13
  readonly locale?: string;
10
14
  };
11
- export declare type EChartsReactProps = {
15
+ export type EChartsReactProps = {
12
16
  /**
13
17
  * echarts library entry, use it for import necessary.
14
18
  */
@@ -35,6 +39,10 @@ export declare type EChartsReactProps = {
35
39
  * notMerge config for echarts, default is `false`
36
40
  */
37
41
  readonly notMerge?: boolean;
42
+ /**
43
+ * replaceMerge config for echarts, default is `null`
44
+ */
45
+ readonly replaceMerge?: string | string[];
38
46
  /**
39
47
  * lazyUpdate config for echarts, default is `false`
40
48
  */
@@ -52,7 +60,7 @@ export declare type EChartsReactProps = {
52
60
  */
53
61
  readonly opts?: Opts;
54
62
  /**
55
- * when after chart reander, do the callback widht echarts instance
63
+ * when after chart render, do the callback with echarts instance
56
64
  */
57
65
  readonly onChartReady?: (instance: EChartsInstance) => void;
58
66
  /**
@@ -63,4 +71,8 @@ export declare type EChartsReactProps = {
63
71
  * should update echarts options
64
72
  */
65
73
  readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;
74
+ /**
75
+ * should trigger resize when window resize
76
+ */
77
+ readonly autoResize?: boolean;
66
78
  };
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { CSSProperties } from 'react';\n\nexport type EChartsOption = any;\n\nexport type EChartsInstance = any;\n\nexport type Opts = {\n readonly devicePixelRatio?: number;\n readonly renderer?: 'canvas' | 'svg';\n readonly width?: number | null | undefined | 'auto';\n readonly height?: number | null | undefined | 'auto';\n readonly locale?: string;\n};\n\nexport type EChartsReactProps = {\n /**\n * echarts library entry, use it for import necessary.\n */\n readonly echarts?: any;\n /**\n * `className` for container\n */\n readonly className?: string;\n /**\n * `style` for container\n */\n readonly style?: CSSProperties;\n /**\n * echarts option\n */\n readonly option: EChartsOption;\n /**\n * echarts theme config, can be:\n * 1. theme name string\n * 2. theme object\n */\n readonly theme?: string | Record<string, any>;\n /**\n * notMerge config for echarts, default is `false`\n */\n readonly notMerge?: boolean;\n /**\n * lazyUpdate config for echarts, default is `false`\n */\n readonly lazyUpdate?: boolean;\n /**\n * showLoading config for echarts, default is `false`\n */\n readonly showLoading?: boolean;\n /**\n * loadingOption config for echarts, default is `null`\n */\n readonly loadingOption?: any;\n /**\n * echarts opts config, default is `{}`\n */\n readonly opts?: Opts;\n /**\n * when after chart reander, do the callback widht echarts instance\n */\n readonly onChartReady?: (instance: EChartsInstance) => void;\n /**\n * bind events, default is `{}`\n */\n readonly onEvents?: Record<string, Function>;\n /**\n * should update echarts options\n */\n readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CSSProperties } from 'react';\nimport type { EChartsType } from 'echarts';\n\n/**\n * Solve the type conflict caused by multiple type files\n */\nexport type EChartsOption = any;\n\nexport type EChartsInstance = EChartsType;\n\nexport type Opts = {\n readonly devicePixelRatio?: number;\n readonly renderer?: 'canvas' | 'svg';\n readonly width?: number | null | undefined | 'auto';\n readonly height?: number | null | undefined | 'auto';\n readonly locale?: string;\n};\n\nexport type EChartsReactProps = {\n /**\n * echarts library entry, use it for import necessary.\n */\n readonly echarts?: any;\n /**\n * `className` for container\n */\n readonly className?: string;\n /**\n * `style` for container\n */\n readonly style?: CSSProperties;\n /**\n * echarts option\n */\n readonly option: EChartsOption;\n /**\n * echarts theme config, can be:\n * 1. theme name string\n * 2. theme object\n */\n readonly theme?: string | Record<string, any>;\n /**\n * notMerge config for echarts, default is `false`\n */\n readonly notMerge?: boolean;\n /**\n * replaceMerge config for echarts, default is `null`\n */\n readonly replaceMerge?: string | string[];\n /**\n * lazyUpdate config for echarts, default is `false`\n */\n readonly lazyUpdate?: boolean;\n /**\n * showLoading config for echarts, default is `false`\n */\n readonly showLoading?: boolean;\n /**\n * loadingOption config for echarts, default is `null`\n */\n readonly loadingOption?: any;\n /**\n * echarts opts config, default is `{}`\n */\n readonly opts?: Opts;\n /**\n * when after chart render, do the callback with echarts instance\n */\n readonly onChartReady?: (instance: EChartsInstance) => void;\n /**\n * bind events, default is `{}`\n */\n readonly onEvents?: Record<string, Function>;\n /**\n * should update echarts options\n */\n readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;\n\n /**\n * should trigger resize when window resize\n */\n readonly autoResize?: boolean;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echarts-for-react",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": " Apache Echarts components for React.",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -48,7 +48,7 @@
48
48
  "devDependencies": {
49
49
  "@commitlint/cli": "^12.0.0",
50
50
  "@commitlint/config-angular": "^12.0.0",
51
- "@types/jest": "^26.0.20",
51
+ "@types/jest": "^24.0.0",
52
52
  "@types/node": "^14.14.31",
53
53
  "@types/react": "^17.0.2",
54
54
  "@typescript-eslint/eslint-plugin": "^4.15.2",
@@ -56,7 +56,7 @@
56
56
  "cross-env": "^7.0.3",
57
57
  "dumi": "^1.1.6",
58
58
  "dumi-theme-default": "^1.0.6",
59
- "echarts": "^5.0.2",
59
+ "echarts": "^6.0.0",
60
60
  "echarts-gl": "^2.0.2",
61
61
  "eslint": "^7.20.0",
62
62
  "eslint-config-prettier": "^8.1.0",
@@ -64,7 +64,7 @@
64
64
  "eslint-plugin-prettier": "^3.3.1",
65
65
  "gh-pages": "^3.1.0",
66
66
  "husky": "^5.1.1",
67
- "jest": "^26.6.3",
67
+ "jest": "^24.0.0",
68
68
  "jest-canvas-mock": "^2.3.1",
69
69
  "jest-electron": "^0.1.11",
70
70
  "lint-md-cli": "^0.1.2",
@@ -74,7 +74,7 @@
74
74
  "npm-run-all": "^4.1.5",
75
75
  "prettier": "^2.2.1",
76
76
  "rimraf": "^3.0.2",
77
- "ts-jest": "^26.5.2",
77
+ "ts-jest": "^24.0.2",
78
78
  "ts-loader": "^8.0.17",
79
79
  "typescript": "^4.2.2"
80
80
  },
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "peerDependencies": {
86
86
  "react": "^15.0.0 || >=16.0.0",
87
- "echarts": "^3.0.0 || ^4.0.0 || ^5.0.0"
87
+ "echarts": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0"
88
88
  },
89
89
  "jest": {
90
90
  "runner": "jest-electron/runner",
package/src/core.tsx CHANGED
@@ -52,11 +52,9 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
52
52
  // 以下属性修改的时候,需要 dispose 之后再新建
53
53
  // 1. 切换 theme 的时候
54
54
  // 2. 修改 opts 的时候
55
- // 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151
56
55
  if (
57
56
  !isEqual(prevProps.theme, this.props.theme) ||
58
- !isEqual(prevProps.opts, this.props.opts) ||
59
- !isEqual(prevProps.onEvents, this.props.onEvents)
57
+ !isEqual(prevProps.opts, this.props.opts)
60
58
  ) {
61
59
  this.dispose();
62
60
 
@@ -64,8 +62,15 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
64
62
  return;
65
63
  }
66
64
 
65
+ // 修改 onEvent 的时候先移除历史事件再添加
66
+ const echartsInstance = this.getEchartsInstance();
67
+ if (!isEqual(prevProps.onEvents, this.props.onEvents)) {
68
+ this.offEvents(echartsInstance, prevProps.onEvents);
69
+ this.bindEvents(echartsInstance, this.props.onEvents);
70
+ }
71
+
67
72
  // when these props are not isEqual, update echarts
68
- const pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
73
+ const pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
69
74
  if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
70
75
  this.updateEChartsOption();
71
76
  }
@@ -82,13 +87,40 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
82
87
  this.dispose();
83
88
  }
84
89
 
90
+ /*
91
+ * initialise an echarts instance
92
+ */
93
+ public async initEchartsInstance(): Promise<ECharts> {
94
+ return new Promise((resolve) => {
95
+ // create temporary echart instance
96
+ this.echarts.init(this.ele, this.props.theme, this.props.opts);
97
+ const echartsInstance = this.getEchartsInstance();
98
+
99
+ echartsInstance.on('finished', () => {
100
+ // get final width and height
101
+ const width = this.ele.clientWidth;
102
+ const height = this.ele.clientHeight;
103
+
104
+ // dispose temporary echart instance
105
+ this.echarts.dispose(this.ele);
106
+
107
+ // recreate echart instance
108
+ // we use final width and height only if not originally provided as opts
109
+ const opts = {
110
+ width,
111
+ height,
112
+ ...this.props.opts,
113
+ };
114
+ resolve(this.echarts.init(this.ele, this.props.theme, opts));
115
+ });
116
+ });
117
+ }
118
+
85
119
  /**
86
- * return the echart object
87
- * 1. if exist, return the existed instance
88
- * 2. or new one instance
120
+ * return the existing echart object
89
121
  */
90
122
  public getEchartsInstance(): ECharts {
91
- return this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts);
123
+ return this.echarts.getInstanceByDom(this.ele);
92
124
  }
93
125
 
94
126
  /**
@@ -109,20 +141,23 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
109
141
  /**
110
142
  * render a new echarts instance
111
143
  */
112
- private renderNewEcharts() {
113
- const { onEvents, onChartReady } = this.props;
144
+ private async renderNewEcharts() {
145
+ const { onEvents, onChartReady, autoResize = true } = this.props;
146
+
147
+ // 1. init echarts instance
148
+ await this.initEchartsInstance();
114
149
 
115
- // 1. new echarts instance
150
+ // 2. update echarts instance
116
151
  const echartsInstance = this.updateEChartsOption();
117
152
 
118
- // 2. bind events
153
+ // 3. bind events
119
154
  this.bindEvents(echartsInstance, onEvents || {});
120
155
 
121
- // 3. on chart ready
156
+ // 4. on chart ready
122
157
  if (isFunction(onChartReady)) onChartReady(echartsInstance);
123
158
 
124
- // 4. on resize
125
- if (this.ele) {
159
+ // 5. on resize
160
+ if (this.ele && autoResize) {
126
161
  bind(this.ele, () => {
127
162
  this.resize();
128
163
  });
@@ -149,15 +184,33 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
149
184
  }
150
185
  }
151
186
 
187
+ // off the events
188
+ private offEvents(instance, events: EChartsReactProps['onEvents']) {
189
+ if (!events) return;
190
+ // loop and off
191
+ for (const eventName in events) {
192
+ if (isString(eventName)) {
193
+ instance.off(eventName);
194
+ }
195
+ }
196
+ }
197
+
152
198
  /**
153
199
  * render the echarts
154
200
  */
155
201
  private updateEChartsOption(): EChartsInstance {
156
- const { option, notMerge = false, lazyUpdate = false, showLoading, loadingOption = null } = this.props;
202
+ const {
203
+ option,
204
+ notMerge = false,
205
+ replaceMerge = null,
206
+ lazyUpdate = false,
207
+ showLoading,
208
+ loadingOption = null,
209
+ } = this.props;
157
210
  // 1. get or initial the echarts object
158
211
  const echartInstance = this.getEchartsInstance();
159
212
  // 2. set the echarts option
160
- echartInstance.setOption(option, notMerge, lazyUpdate);
213
+ echartInstance.setOption(option, { notMerge, replaceMerge, lazyUpdate });
161
214
  // 3. set loading mask
162
215
  if (showLoading) echartInstance.showLoading(loadingOption);
163
216
  else echartInstance.hideLoading();
@@ -176,7 +229,10 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
176
229
  // resize should not happen on first render as it will cancel initial echarts animations
177
230
  if (!this.isInitialResize) {
178
231
  try {
179
- echartsInstance.resize();
232
+ echartsInstance.resize({
233
+ width: 'auto',
234
+ height: 'auto',
235
+ });
180
236
  } catch (e) {
181
237
  console.warn(e);
182
238
  }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import * as echarts from 'echarts';
2
2
  import { EChartsReactProps, EChartsOption, EChartsInstance } from './types';
3
3
  import EChartsReactCore from './core';
4
4
 
5
- export { EChartsReactProps, EChartsOption, EChartsInstance };
5
+ export type { EChartsReactProps, EChartsOption, EChartsInstance };
6
6
 
7
7
  // export the Component the echarts Object.
8
8
  export default class EChartsReact extends EChartsReactCore {
package/src/types.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { CSSProperties } from 'react';
1
+ import type { CSSProperties } from 'react';
2
+ import type { EChartsType } from 'echarts';
2
3
 
4
+ /**
5
+ * Solve the type conflict caused by multiple type files
6
+ */
3
7
  export type EChartsOption = any;
4
8
 
5
- export type EChartsInstance = any;
9
+ export type EChartsInstance = EChartsType;
6
10
 
7
11
  export type Opts = {
8
12
  readonly devicePixelRatio?: number;
@@ -39,6 +43,10 @@ export type EChartsReactProps = {
39
43
  * notMerge config for echarts, default is `false`
40
44
  */
41
45
  readonly notMerge?: boolean;
46
+ /**
47
+ * replaceMerge config for echarts, default is `null`
48
+ */
49
+ readonly replaceMerge?: string | string[];
42
50
  /**
43
51
  * lazyUpdate config for echarts, default is `false`
44
52
  */
@@ -56,7 +64,7 @@ export type EChartsReactProps = {
56
64
  */
57
65
  readonly opts?: Opts;
58
66
  /**
59
- * when after chart reander, do the callback widht echarts instance
67
+ * when after chart render, do the callback with echarts instance
60
68
  */
61
69
  readonly onChartReady?: (instance: EChartsInstance) => void;
62
70
  /**
@@ -67,4 +75,9 @@ export type EChartsReactProps = {
67
75
  * should update echarts options
68
76
  */
69
77
  readonly shouldSetOption?: (prevProps: EChartsReactProps, props: EChartsReactProps) => boolean;
78
+
79
+ /**
80
+ * should trigger resize when window resize
81
+ */
82
+ readonly autoResize?: boolean;
70
83
  };