echarts-for-react 3.0.0-beta.1 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # echarts-for-react
2
2
 
3
- A very simple React wrapper for [Apache ECharts (incubating)](https://github.com/apache/incubator-echarts).
3
+ The simplest, and the best React wrapper for [Apache ECharts](https://github.com/apache/incubator-echarts).
4
4
 
5
5
  [![npm](https://img.shields.io/npm/v/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react)
6
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)
@@ -11,101 +11,154 @@ A very simple React wrapper for [Apache ECharts (incubating)](https://github.com
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
 
14
- # 1. install
14
+ ## Install
15
15
 
16
- ```sh
17
- npm install --save echarts-for-react
16
+ ```bach
17
+ $ npm install --save echarts-for-react
18
18
 
19
19
  # `echarts` is the peerDependence of `echarts-for-react`, you can install echarts with your own version.
20
- npm install --save echarts
20
+ $ npm install --save echarts
21
21
  ```
22
22
 
23
23
  Then use it.
24
24
 
25
- ```js
26
- import ReactEcharts from 'echarts-for-react';
25
+ ```ts
26
+ import ReactECharts from 'echarts-for-react';
27
27
 
28
28
  // render echarts option.
29
- <ReactEcharts option={this.getOption()} />
30
- ```
31
-
32
- You can run demo by:
33
-
34
- ```sh
35
- git clone git@github.com:hustcc/echarts-for-react.git
36
-
37
- npm install
38
-
39
- npm start
40
- ```
41
-
42
- then open [http://127.0.0.1:8080/](http://127.0.0.1:8080/) in your browser. or see [http://git.hust.cc/echarts-for-react/](http://git.hust.cc/echarts-for-react/)
43
-
44
- ## GL
45
-
46
- Install and import [`echarts-gl`](https://www.npmjs.com/package/echarts-gl) module when you want to create a [GL instance](https://www.echartsjs.com/examples/zh/index.html#chart-type-globe)
47
-
48
- - **`Install`**
49
-
50
- ```sh
51
- npm install --save echarts-gl
29
+ <ReactECharts option={this.getOption()} />
52
30
  ```
53
31
 
54
- - **`Import`**
32
+ You can run website.
55
33
 
56
- ```js
57
- import 'echarts-gl'
58
- import ReactEcharts from "echarts-for-react";
34
+ ```bash
35
+ $ git clone git@github.com:hustcc/echarts-for-react.git
59
36
 
60
- <ReactEcharts
61
- option={GL_OPTION}
62
- />
37
+ $ npm install
63
38
 
39
+ $ npm start
64
40
  ```
65
41
 
42
+ Then open [http://127.0.0.1:8081/](http://127.0.0.1:8081/) in your browser. or see [https://git.hust.cc/echarts-for-react/](https://git.hust.cc/echarts-for-react/) which is deploy on gh-pages.
66
43
 
67
- # 2. usage
68
44
 
69
- Code of a simple demo code showed below. For more example can see: [http://git.hust.cc/echarts-for-react/](http://git.hust.cc/echarts-for-react/)
45
+ ## Usage
70
46
 
71
- ### javascript
47
+ Code of a simple demo code showed below. For more example can see: [https://git.hust.cc/echarts-for-react/](https://git.hust.cc/echarts-for-react/)
72
48
 
73
- ```js
49
+ ```ts
74
50
  import React from 'react';
75
- import ReactEcharts from 'echarts-for-react'; // or var ReactEcharts = require('echarts-for-react');
51
+ import ReactECharts from 'echarts-for-react'; // or var ReactECharts = require('echarts-for-react');
76
52
 
77
- <ReactEcharts
53
+ <ReactECharts
78
54
  option={this.getOption()}
79
55
  notMerge={true}
80
56
  lazyUpdate={true}
81
57
  theme={"theme_name"}
82
58
  onChartReady={this.onChartReadyCallback}
83
59
  onEvents={EventsDict}
84
- opts={} />
60
+ opts={}
61
+ />
85
62
  ```
86
63
 
87
- ### typescript
64
+ Import ECharts.js modules manually to reduce bundle size
88
65
 
89
- ```js
90
- import * as React from "react";
91
- import ReactEcharts from "echarts-for-react";
66
+ **With Echarts.js v5:**
92
67
 
93
- <ReactEcharts
68
+ ```ts
69
+ import React from 'react';
70
+ // import the core library.
71
+ import ReactEChartsCore from 'echarts-for-react/lib/core';
72
+ // Import the echarts core module, which provides the necessary interfaces for using echarts.
73
+ import * as echarts from 'echarts/core';
74
+ // Import charts, all with Chart suffix
75
+ import {
76
+ // LineChart,
77
+ BarChart,
78
+ // PieChart,
79
+ // ScatterChart,
80
+ // RadarChart,
81
+ // MapChart,
82
+ // TreeChart,
83
+ // TreemapChart,
84
+ // GraphChart,
85
+ // GaugeChart,
86
+ // FunnelChart,
87
+ // ParallelChart,
88
+ // SankeyChart,
89
+ // BoxplotChart,
90
+ // CandlestickChart,
91
+ // EffectScatterChart,
92
+ // LinesChart,
93
+ // HeatmapChart,
94
+ // PictorialBarChart,
95
+ // ThemeRiverChart,
96
+ // SunburstChart,
97
+ // CustomChart,
98
+ } from 'echarts/charts';
99
+ // import components, all suffixed with Component
100
+ import {
101
+ // GridSimpleComponent,
102
+ GridComponent,
103
+ // PolarComponent,
104
+ // RadarComponent,
105
+ // GeoComponent,
106
+ // SingleAxisComponent,
107
+ // ParallelComponent,
108
+ // CalendarComponent,
109
+ // GraphicComponent,
110
+ // ToolboxComponent,
111
+ TooltipComponent,
112
+ // AxisPointerComponent,
113
+ // BrushComponent,
114
+ TitleComponent,
115
+ // TimelineComponent,
116
+ // MarkPointComponent,
117
+ // MarkLineComponent,
118
+ // MarkAreaComponent,
119
+ // LegendComponent,
120
+ // LegendScrollComponent,
121
+ // LegendPlainComponent,
122
+ // DataZoomComponent,
123
+ // DataZoomInsideComponent,
124
+ // DataZoomSliderComponent,
125
+ // VisualMapComponent,
126
+ // VisualMapContinuousComponent,
127
+ // VisualMapPiecewiseComponent,
128
+ // AriaComponent,
129
+ // TransformComponent,
130
+ DatasetComponent,
131
+ } from 'echarts/components';
132
+ // Import renderer, note that introducing the CanvasRenderer or SVGRenderer is a required step
133
+ import {
134
+ CanvasRenderer,
135
+ // SVGRenderer,
136
+ } from 'echarts/renderers';
137
+
138
+ // Register the required components
139
+ echarts.use(
140
+ [TitleComponent, TooltipComponent, GridComponent, BarChart, CanvasRenderer]
141
+ );
142
+
143
+ // The usage of ReactEChartsCore are same with above.
144
+ <ReactEChartsCore
145
+ echarts={echarts}
94
146
  option={this.getOption()}
95
147
  notMerge={true}
96
148
  lazyUpdate={true}
97
149
  theme={"theme_name"}
98
150
  onChartReady={this.onChartReadyCallback}
99
151
  onEvents={EventsDict}
100
- opts={} />
152
+ opts={}
153
+ />
101
154
  ```
102
155
 
103
- Import ECharts.js modules manually to reduce bundle size
156
+ **With Echarts.js v3 or v4:**
104
157
 
105
- ```js
158
+ ```ts
106
159
  import React from 'react';
107
160
  // import the core library.
108
- import ReactEchartsCore from 'echarts-for-react/lib/core';
161
+ import ReactEChartsCore from 'echarts-for-react/lib/core';
109
162
 
110
163
  // then import echarts modules those you have used manually.
111
164
  import echarts from 'echarts/lib/echarts';
@@ -152,8 +205,8 @@ import 'echarts/lib/component/title';
152
205
 
153
206
  // import 'zrender/lib/vml/vml';
154
207
 
155
- // The usage of ReactEchartsCore are same with above.
156
- <ReactEchartsCore
208
+ // The usage of ReactEChartsCore are same with above.
209
+ <ReactEChartsCore
157
210
  echarts={echarts}
158
211
  option={this.getOption()}
159
212
  notMerge={true}
@@ -161,10 +214,11 @@ import 'echarts/lib/component/title';
161
214
  theme={"theme_name"}
162
215
  onChartReady={this.onChartReadyCallback}
163
216
  onEvents={EventsDict}
164
- opts={} />
217
+ opts={}
218
+ />
165
219
  ```
166
220
 
167
- # 3. component props
221
+ ## Props of Component
168
222
 
169
223
  - **`option`** (required, object)
170
224
 
@@ -190,7 +244,7 @@ the `class` of echarts div. you can setting the css style of charts by class nam
190
244
 
191
245
  the `theme` of echarts. `string`, should `registerTheme` before use it (theme object format: [https://github.com/ecomfe/echarts/blob/master/theme/dark.js](https://github.com/ecomfe/echarts/blob/master/theme/dark.js)). e.g.
192
246
 
193
- ```js
247
+ ```ts
194
248
  // import echarts
195
249
  import echarts from 'echarts';
196
250
  ...
@@ -200,7 +254,7 @@ echarts.registerTheme('my_theme', {
200
254
  });
201
255
  ...
202
256
  // render the echarts use option `theme`
203
- <ReactEcharts
257
+ <ReactECharts
204
258
  option={this.getOption()}
205
259
  style={{height: '300px', width: '100%'}}
206
260
  className='echarts-for-echarts'
@@ -223,16 +277,17 @@ the echarts loading option config, can see [https://echarts.apache.org/api.html#
223
277
 
224
278
  binding the echarts event, will callback with the `echarts event object`, and `the echart object` as it's paramters. e.g:
225
279
 
226
- ```js
227
- let onEvents = {
280
+ ```ts
281
+ const onEvents = {
228
282
  'click': this.onChartClick,
229
283
  'legendselectchanged': this.onChartLegendselectchanged
230
284
  }
231
285
  ...
232
- <ReactEcharts
286
+ <ReactECharts
233
287
  option={this.getOption()}
234
- style={{height: '300px', width: '100%'}}
235
- onEvents={onEvents} />
288
+ style={{ height: '300px', width: '100%' }}
289
+ onEvents={onEvents}
290
+ />
236
291
  ```
237
292
  for more event key name, see: [https://echarts.apache.org/api.html#events](https://echarts.apache.org/api.html#events)
238
293
 
@@ -240,16 +295,16 @@ for more event key name, see: [https://echarts.apache.org/api.html#events](https
240
295
 
241
296
  the `opts` of echarts. `object`, will be used when initial echarts instance by `echarts.init`. Document [here](https://echarts.apache.org/api.html#echarts.init).
242
297
 
243
- ```js
244
- <ReactEcharts
298
+ ```ts
299
+ <ReactECharts
245
300
  option={this.getOption()}
246
- style={{height: '300px'}}
301
+ style={{ height: '300px' }}
247
302
  opts={{renderer: 'svg'}} // use svg to render the chart.
248
303
  />
249
304
  ```
250
305
 
251
306
 
252
- # 4. Component API & Echarts API
307
+ ## Component API & Echarts API
253
308
 
254
309
  the Component only has `one API` named `getEchartsInstance`.
255
310
 
@@ -257,16 +312,18 @@ the Component only has `one API` named `getEchartsInstance`.
257
312
 
258
313
  for example:
259
314
 
260
- ```js
315
+ ```ts
261
316
  // render the echarts component below with rel
262
- <ReactEcharts ref={(e) => { this.echarts_react = e; }}
263
- option={this.getOption()} />
317
+ <ReactECharts
318
+ ref={(e) => { this.echartRef = e; }}
319
+ option={this.getOption()}
320
+ />
264
321
 
265
- // then get the `ReactEcharts` use this.echarts_react
322
+ // then get the `ReactECharts` use this.echarts_react
266
323
 
267
- let echarts_instance = this.echarts_react.getEchartsInstance();
324
+ const echartInstance = this.echartRef.getEchartsInstance();
268
325
  // then you can use any API of echarts.
269
- let base64 = echarts_instance.getDataURL();
326
+ const base64 = echartInstance.getDataURL();
270
327
  ```
271
328
 
272
329
  **About API of echarts, can see** [https://echarts.apache.org/api.html#echartsInstance](https://echarts.apache.org/api.html#echartsInstance).
@@ -279,28 +336,39 @@ You can use the API to do:
279
336
  4. `release` the charts.
280
337
 
281
338
 
282
- # 5. Q & A
339
+ ## FAQ
283
340
 
284
- - How to render the chart with svg when using echarts 4.x
341
+ ### How to render the chart with svg when using echarts 4.x
285
342
 
286
343
  Use the props `opts` of component with `renderer = 'svg'`. For example:
287
344
 
288
345
 
289
- ```js
290
- <ReactEcharts
346
+ ```ts
347
+ <ReactECharts
291
348
  option={this.getOption()}
292
349
  style={{height: '300px'}}
293
350
  opts={{renderer: 'svg'}} // use svg to render the chart.
294
351
  />
295
352
  ```
296
353
 
297
- - How to resolve Error `Component series.scatter3D not exists. Load it first.`
354
+ ### How to resolve Error `Component series.scatter3D not exists. Load it first.`
298
355
 
299
- [Install and import `echarts-gl` first](#GL)
356
+ Install and import [`echarts-gl`](https://www.npmjs.com/package/echarts-gl) module when you want to create a [GL instance](https://www.echartsjs.com/examples/zh/index.html#chart-type-globe)
300
357
 
358
+ ```sh
359
+ npm install --save echarts-gl
360
+ ```
301
361
 
302
- # 6. LICENSE
362
+ ```ts
363
+ import 'echarts-gl'
364
+ import ReactECharts from "echarts-for-react";
303
365
 
304
- MIT@[hustcc](https://github.com/hustcc).
366
+ <ReactECharts
367
+ option={GL_OPTION}
368
+ />
369
+ ```
305
370
 
306
371
 
372
+ ## LICENSE
373
+
374
+ MIT@[hustcc](https://github.com/hustcc).
package/esm/core.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ECharts } from 'echarts';
1
2
  import { PureComponent } from 'react';
2
3
  import { EChartsReactProps } from './types';
3
4
  /**
@@ -8,6 +9,10 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
8
9
  * echarts render container
9
10
  */
10
11
  ele: HTMLElement;
12
+ /**
13
+ * if this is the first time we are resizing
14
+ */
15
+ private isInitialResize;
11
16
  /**
12
17
  * echarts library entry
13
18
  */
@@ -21,7 +26,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
21
26
  * 1. if exist, return the existed instance
22
27
  * 2. or new one instance
23
28
  */
24
- getEchartsInstance(): any;
29
+ getEchartsInstance(): ECharts;
25
30
  /**
26
31
  * dispose echarts and clear size-sensor
27
32
  */
@@ -35,5 +40,9 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
35
40
  * render the echarts
36
41
  */
37
42
  private updateEChartsOption;
43
+ /**
44
+ * resize wrapper
45
+ */
46
+ private resize;
38
47
  render(): JSX.Element;
39
48
  }
package/esm/core.js CHANGED
@@ -14,6 +14,7 @@ var EChartsReactCore = /** @class */ (function (_super) {
14
14
  var _this = _super.call(this, props) || this;
15
15
  _this.echarts = props.echarts;
16
16
  _this.ele = null;
17
+ _this.isInitialResize = true;
17
18
  return _this;
18
19
  }
19
20
  EChartsReactCore.prototype.componentDidMount = function () {
@@ -40,22 +41,16 @@ var EChartsReactCore = /** @class */ (function (_super) {
40
41
  this.renderNewEcharts(); // 重建
41
42
  return;
42
43
  }
43
- // when thoes props isEqual, do not update echarts
44
+ // when these props are not isEqual, update echarts
44
45
  var pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
45
- if (isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
46
- return;
46
+ if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
47
+ this.updateEChartsOption();
47
48
  }
48
- var echartsInstance = this.updateEChartsOption();
49
49
  /**
50
50
  * when style or class name updated, change size.
51
51
  */
52
52
  if (!isEqual(prevProps.style, this.props.style) || !isEqual(prevProps.className, this.props.className)) {
53
- try {
54
- echartsInstance.resize();
55
- }
56
- catch (e) {
57
- console.warn(e);
58
- }
53
+ this.resize();
59
54
  }
60
55
  };
61
56
  EChartsReactCore.prototype.componentWillUnmount = function () {
@@ -88,6 +83,7 @@ var EChartsReactCore = /** @class */ (function (_super) {
88
83
  * render a new echarts instance
89
84
  */
90
85
  EChartsReactCore.prototype.renderNewEcharts = function () {
86
+ var _this = this;
91
87
  var _a = this.props, onEvents = _a.onEvents, onChartReady = _a.onChartReady;
92
88
  // 1. new echarts instance
93
89
  var echartsInstance = this.updateEChartsOption();
@@ -99,12 +95,7 @@ var EChartsReactCore = /** @class */ (function (_super) {
99
95
  // 4. on resize
100
96
  if (this.ele) {
101
97
  bind(this.ele, function () {
102
- try {
103
- echartsInstance.resize();
104
- }
105
- catch (e) {
106
- console.warn(e);
107
- }
98
+ _this.resize();
108
99
  });
109
100
  }
110
101
  };
@@ -142,6 +133,25 @@ var EChartsReactCore = /** @class */ (function (_super) {
142
133
  echartInstance.hideLoading();
143
134
  return echartInstance;
144
135
  };
136
+ /**
137
+ * resize wrapper
138
+ */
139
+ EChartsReactCore.prototype.resize = function () {
140
+ // 1. get the echarts object
141
+ var echartsInstance = this.getEchartsInstance();
142
+ // 2. call echarts instance resize if not the initial resize
143
+ // resize should not happen on first render as it will cancel initial echarts animations
144
+ if (!this.isInitialResize) {
145
+ try {
146
+ echartsInstance.resize();
147
+ }
148
+ catch (e) {
149
+ console.warn(e);
150
+ }
151
+ }
152
+ // 3. update variable for future calls
153
+ this.isInitialResize = false;
154
+ };
145
155
  EChartsReactCore.prototype.render = function () {
146
156
  var _this = this;
147
157
  var _a = this.props, style = _a.style, _b = _a.className, className = _b === void 0 ? '' : _b;
package/esm/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE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M,CAAC,SAAS,CAAC,CAAC,CAAC;aAC1C;SACF;IACH,CAAC;IAED;;OAEG;IACK,8CAAmB,GAA3B;QACQ,IAAA,KAAsF,IAAI,CAAC,KAAK,EAA9F,MAAM,YAAA,EAAE,gBAAgB,EAAhB,QAAQ,mBAAG,KAAK,KAAA,EAAE,kBAAkB,EAAlB,UAAU,mBAAG,KAAK,KAAA,EAAE,WAAW,iBAAA,EAAE,qBAAoB,EAApB,aAAa,mBAAG,IAAI,KAAe,CAAC;QACvG,uCAAuC;QACvC,IAAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACjD,4BAA4B;QAC5B,cAAc,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QACvD,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,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,AA7KD,CAA8C,aAAa,GA6K1D","sourcesContent":["import 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 * 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 }\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 thoes props isEqual, do not update echarts\n const pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];\n if (isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {\n return;\n }\n\n const echartsInstance = this.updateEChartsOption();\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 try {\n echartsInstance.resize();\n } catch (e) {\n console.warn(e);\n }\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() {\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 try {\n echartsInstance.resize();\n } catch (e) {\n console.warn(e);\n }\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 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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import 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"]}
package/esm/types.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare type Opts = {
6
6
  readonly renderer?: 'canvas' | 'svg';
7
7
  readonly width?: number | null | undefined | 'auto';
8
8
  readonly height?: number | null | undefined | 'auto';
9
+ readonly locale?: string;
9
10
  };
10
11
  export declare type EChartsReactProps = {
11
12
  /**
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};\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 { 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"]}
package/lib/core.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ECharts } from 'echarts';
1
2
  import { PureComponent } from 'react';
2
3
  import { EChartsReactProps } from './types';
3
4
  /**
@@ -8,6 +9,10 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
8
9
  * echarts render container
9
10
  */
10
11
  ele: HTMLElement;
12
+ /**
13
+ * if this is the first time we are resizing
14
+ */
15
+ private isInitialResize;
11
16
  /**
12
17
  * echarts library entry
13
18
  */
@@ -21,7 +26,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
21
26
  * 1. if exist, return the existed instance
22
27
  * 2. or new one instance
23
28
  */
24
- getEchartsInstance(): any;
29
+ getEchartsInstance(): ECharts;
25
30
  /**
26
31
  * dispose echarts and clear size-sensor
27
32
  */
@@ -35,5 +40,9 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
35
40
  * render the echarts
36
41
  */
37
42
  private updateEChartsOption;
43
+ /**
44
+ * resize wrapper
45
+ */
46
+ private resize;
38
47
  render(): JSX.Element;
39
48
  }
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 = tslib_1.__importStar(require("react"));
4
+ var react_1 = (0, 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,11 +11,12 @@ 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
- tslib_1.__extends(EChartsReactCore, _super);
14
+ (0, 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;
18
18
  _this.ele = null;
19
+ _this.isInitialResize = true;
19
20
  return _this;
20
21
  }
21
22
  EChartsReactCore.prototype.componentDidMount = function () {
@@ -28,36 +29,30 @@ var EChartsReactCore = /** @class */ (function (_super) {
28
29
  * default is true
29
30
  */
30
31
  var shouldSetOption = this.props.shouldSetOption;
31
- if (is_function_1.isFunction(shouldSetOption) && !shouldSetOption(prevProps, this.props)) {
32
+ if ((0, is_function_1.isFunction)(shouldSetOption) && !shouldSetOption(prevProps, this.props)) {
32
33
  return;
33
34
  }
34
35
  // 以下属性修改的时候,需要 dispose 之后再新建
35
36
  // 1. 切换 theme 的时候
36
37
  // 2. 修改 opts 的时候
37
38
  // 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151
38
- if (!is_equal_1.isEqual(prevProps.theme, this.props.theme) ||
39
- !is_equal_1.isEqual(prevProps.opts, this.props.opts) ||
40
- !is_equal_1.isEqual(prevProps.onEvents, this.props.onEvents)) {
39
+ 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)) {
41
42
  this.dispose();
42
43
  this.renderNewEcharts(); // 重建
43
44
  return;
44
45
  }
45
- // when thoes props isEqual, do not update echarts
46
+ // when these props are not isEqual, update echarts
46
47
  var pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
47
- if (is_equal_1.isEqual(pick_1.pick(this.props, pickKeys), pick_1.pick(prevProps, pickKeys))) {
48
- return;
48
+ if (!(0, is_equal_1.isEqual)((0, pick_1.pick)(this.props, pickKeys), (0, pick_1.pick)(prevProps, pickKeys))) {
49
+ this.updateEChartsOption();
49
50
  }
50
- var echartsInstance = this.updateEChartsOption();
51
51
  /**
52
52
  * when style or class name updated, change size.
53
53
  */
54
- if (!is_equal_1.isEqual(prevProps.style, this.props.style) || !is_equal_1.isEqual(prevProps.className, this.props.className)) {
55
- try {
56
- echartsInstance.resize();
57
- }
58
- catch (e) {
59
- console.warn(e);
60
- }
54
+ if (!(0, is_equal_1.isEqual)(prevProps.style, this.props.style) || !(0, is_equal_1.isEqual)(prevProps.className, this.props.className)) {
55
+ this.resize();
61
56
  }
62
57
  };
63
58
  EChartsReactCore.prototype.componentWillUnmount = function () {
@@ -77,7 +72,7 @@ var EChartsReactCore = /** @class */ (function (_super) {
77
72
  EChartsReactCore.prototype.dispose = function () {
78
73
  if (this.ele) {
79
74
  try {
80
- size_sensor_1.clear(this.ele);
75
+ (0, size_sensor_1.clear)(this.ele);
81
76
  }
82
77
  catch (e) {
83
78
  console.warn(e);
@@ -90,23 +85,19 @@ var EChartsReactCore = /** @class */ (function (_super) {
90
85
  * render a new echarts instance
91
86
  */
92
87
  EChartsReactCore.prototype.renderNewEcharts = function () {
88
+ var _this = this;
93
89
  var _a = this.props, onEvents = _a.onEvents, onChartReady = _a.onChartReady;
94
90
  // 1. new echarts instance
95
91
  var echartsInstance = this.updateEChartsOption();
96
92
  // 2. bind events
97
93
  this.bindEvents(echartsInstance, onEvents || {});
98
94
  // 3. on chart ready
99
- if (is_function_1.isFunction(onChartReady))
95
+ if ((0, is_function_1.isFunction)(onChartReady))
100
96
  onChartReady(echartsInstance);
101
97
  // 4. on resize
102
98
  if (this.ele) {
103
- size_sensor_1.bind(this.ele, function () {
104
- try {
105
- echartsInstance.resize();
106
- }
107
- catch (e) {
108
- console.warn(e);
109
- }
99
+ (0, size_sensor_1.bind)(this.ele, function () {
100
+ _this.resize();
110
101
  });
111
102
  }
112
103
  };
@@ -114,7 +105,7 @@ var EChartsReactCore = /** @class */ (function (_super) {
114
105
  EChartsReactCore.prototype.bindEvents = function (instance, events) {
115
106
  function _bindEvent(eventName, func) {
116
107
  // ignore the event config which not satisfy
117
- if (is_string_1.isString(eventName) && is_function_1.isFunction(func)) {
108
+ if ((0, is_string_1.isString)(eventName) && (0, is_function_1.isFunction)(func)) {
118
109
  // binding event
119
110
  instance.on(eventName, function (param) {
120
111
  func(param, instance);
@@ -144,11 +135,30 @@ var EChartsReactCore = /** @class */ (function (_super) {
144
135
  echartInstance.hideLoading();
145
136
  return echartInstance;
146
137
  };
138
+ /**
139
+ * resize wrapper
140
+ */
141
+ EChartsReactCore.prototype.resize = function () {
142
+ // 1. get the echarts object
143
+ var echartsInstance = this.getEchartsInstance();
144
+ // 2. call echarts instance resize if not the initial resize
145
+ // resize should not happen on first render as it will cancel initial echarts animations
146
+ if (!this.isInitialResize) {
147
+ try {
148
+ echartsInstance.resize();
149
+ }
150
+ catch (e) {
151
+ console.warn(e);
152
+ }
153
+ }
154
+ // 3. update variable for future calls
155
+ this.isInitialResize = false;
156
+ };
147
157
  EChartsReactCore.prototype.render = function () {
148
158
  var _this = this;
149
159
  var _a = this.props, style = _a.style, _b = _a.className, className = _b === void 0 ? '' : _b;
150
160
  // default height = 300
151
- var newStyle = tslib_1.__assign({ height: 300 }, style);
161
+ var newStyle = (0, tslib_1.__assign)({ height: 300 }, style);
152
162
  return (react_1.default.createElement("div", { ref: function (e) {
153
163
  _this.ele = e;
154
164
  }, style: newStyle, className: "echarts-for-react " + className }));
package/lib/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";;;AAAA,qDAA6C;AAC7C,2CAA0C;AAC1C,sCAAqC;AACrC,oDAAkD;AAClD,gDAA8C;AAC9C,8CAA4C;AAG5C;;GAEG;AACH;IAA8C,4CAAgC;IAW5E,0BAAY,KAAwB;QAApC,YACE,kBAAM,KAAK,CAAC,SAIb;QAFC,KAAI,CAAC,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC7B,KAAI,CAAC,GAAG,GAAG,IAAI,CAAC;;IAClB,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,wBAAU,CAAC,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;YAC1E,OAAO;SACR;QAED,6BAA6B;QAC7B,kBAAkB;QAClB,iBAAiB;QACjB,gDAAgD;QAChD,IACE,CAAC,kBAAO,CAAC,SAAS,CAAC,KAA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C,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,AA7KD,CAA8C,qBAAa,GA6K1D","sourcesContent":["import 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 * 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 }\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 thoes props isEqual, do not update echarts\n const pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];\n if (isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {\n return;\n }\n\n const echartsInstance = this.updateEChartsOption();\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 try {\n echartsInstance.resize();\n } catch (e) {\n console.warn(e);\n }\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() {\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 try {\n echartsInstance.resize();\n } catch (e) {\n console.warn(e);\n }\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 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,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,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,IAAA,wBAAU,EAAC,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE;YAC1E,OAAO;SACR;QAED,6BAA6B;QAC7B,kBAAkB;QAClB,iBAAiB;QACjB,gDAAgD;QAChD,IACE,CAAC,IAAA,kBAAO,EAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;YAC3C,CAAC,IAAA,kBAAO,EAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YACzC,CAAC,IAAA,kBAAO,EAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,EACjD;YACA,IAAI,CAAC,OAAO,EAA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,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"]}
@@ -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 = tslib_1.__importDefault(require("fast-deep-equal"));
5
+ var fast_deep_equal_1 = (0, 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,4EAAsC;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,iFAAsC;AAE7B,kBAFF,yBAAO,CAEE","sourcesContent":["import isEqual from 'fast-deep-equal';\n\nexport { isEqual };\n"]}
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 = tslib_1.__importStar(require("echarts"));
5
- var core_1 = tslib_1.__importDefault(require("./core"));
4
+ var echarts = (0, tslib_1.__importStar)(require("echarts"));
5
+ var core_1 = (0, tslib_1.__importDefault)(require("./core"));
6
6
  // export the Component the echarts Object.
7
7
  var EChartsReact = /** @class */ (function (_super) {
8
- tslib_1.__extends(EChartsReact, _super);
8
+ (0, 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,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 { 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,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"]}
package/lib/types.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare type Opts = {
6
6
  readonly renderer?: 'canvas' | 'svg';
7
7
  readonly width?: number | null | undefined | 'auto';
8
8
  readonly height?: number | null | undefined | 'auto';
9
+ readonly locale?: string;
9
10
  };
10
11
  export declare type EChartsReactProps = {
11
12
  /**
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};\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 { 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"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "echarts-for-react",
3
- "version": "3.0.0-beta.1",
4
- "description": " Apache Echarts(v5) components for React.",
3
+ "version": "3.0.2",
4
+ "description": " Apache Echarts components for React.",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
7
7
  "types": "lib/index.d.ts",
@@ -11,10 +11,10 @@
11
11
  "src"
12
12
  ],
13
13
  "scripts": {
14
- "docs:dev": "dumi dev",
15
- "docs:build": "dumi build",
14
+ "docs:dev": "NODE_ENV=development dumi dev",
15
+ "docs:build": "NODE_ENV=production dumi build",
16
16
  "docs:deploy": "rimraf dist && npm run docs:build && gh-pages -d dist",
17
- "start": "webpack-dev-server --watch",
17
+ "start": "npm run docs:dev",
18
18
  "lint": "eslint src __tests__ && prettier src __tests__ --check",
19
19
  "fix": "eslint src __tests__ --fix && prettier src __tests__ --write",
20
20
  "clean": "rimraf lib esm dist",
@@ -46,45 +46,45 @@
46
46
  },
47
47
  "homepage": "https://github.com/hustcc/echarts-for-react",
48
48
  "devDependencies": {
49
- "@commitlint/cli": "^11.0.0",
50
- "@commitlint/config-angular": "^11.0.0",
49
+ "@commitlint/cli": "^12.0.0",
50
+ "@commitlint/config-angular": "^12.0.0",
51
51
  "@types/jest": "^26.0.20",
52
- "@types/node": "^14.14.14",
53
- "@types/react": "^17.0.1",
54
- "@typescript-eslint/eslint-plugin": "^4.14.2",
55
- "@typescript-eslint/parser": "^4.11.0",
56
- "cross-env": "^5.1.3",
57
- "dumi": "^1.1.4",
58
- "dumi-theme-default": "^1.0.4",
52
+ "@types/node": "^14.14.31",
53
+ "@types/react": "^17.0.2",
54
+ "@typescript-eslint/eslint-plugin": "^4.15.2",
55
+ "@typescript-eslint/parser": "^4.15.2",
56
+ "cross-env": "^7.0.3",
57
+ "dumi": "^1.1.6",
58
+ "dumi-theme-default": "^1.0.6",
59
59
  "echarts": "^5.0.2",
60
- "echarts-gl": "^2.0.1",
61
- "eslint": "^7.19.0",
62
- "eslint-config-prettier": "^7.1.0",
60
+ "echarts-gl": "^2.0.2",
61
+ "eslint": "^7.20.0",
62
+ "eslint-config-prettier": "^8.1.0",
63
63
  "eslint-plugin-import": "^2.22.1",
64
64
  "eslint-plugin-prettier": "^3.3.1",
65
65
  "gh-pages": "^3.1.0",
66
- "husky": "^4.3.8",
66
+ "husky": "^5.1.1",
67
67
  "jest": "^26.6.3",
68
- "jest-canvas-mock": "^2.3.0",
68
+ "jest-canvas-mock": "^2.3.1",
69
69
  "jest-electron": "^0.1.11",
70
70
  "lint-md-cli": "^0.1.2",
71
- "lint-staged": "^10.5.3",
71
+ "lint-staged": "^10.5.4",
72
72
  "lodash.clonedeep": "^4.5.0",
73
73
  "miz": "^1.0.1",
74
74
  "npm-run-all": "^4.1.5",
75
75
  "prettier": "^2.2.1",
76
- "rimraf": "^2.6.2",
77
- "ts-jest": "^26.5.0",
78
- "ts-loader": "^8.0.15",
79
- "typescript": "^4.1.3"
76
+ "rimraf": "^3.0.2",
77
+ "ts-jest": "^26.5.2",
78
+ "ts-loader": "^8.0.17",
79
+ "typescript": "^4.2.2"
80
80
  },
81
81
  "dependencies": {
82
- "size-sensor": "^1.0.0",
82
+ "size-sensor": "^1.0.1",
83
83
  "fast-deep-equal": "^3.1.3"
84
84
  },
85
85
  "peerDependencies": {
86
- "react": ">=16.8.0",
87
- "echarts": "^5.0.0"
86
+ "react": "^15.0.0 || >=16.0.0",
87
+ "echarts": "^3.0.0 || ^4.0.0 || ^5.0.0"
88
88
  },
89
89
  "jest": {
90
90
  "runner": "jest-electron/runner",
package/src/core.tsx CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ECharts } from 'echarts';
1
2
  import React, { PureComponent } from 'react';
2
3
  import { bind, clear } from 'size-sensor';
3
4
  import { pick } from './helper/pick';
@@ -15,6 +16,11 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
15
16
  */
16
17
  public ele: HTMLElement;
17
18
 
19
+ /**
20
+ * if this is the first time we are resizing
21
+ */
22
+ private isInitialResize: boolean;
23
+
18
24
  /**
19
25
  * echarts library entry
20
26
  */
@@ -25,6 +31,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
25
31
 
26
32
  this.echarts = props.echarts;
27
33
  this.ele = null;
34
+ this.isInitialResize = true;
28
35
  }
29
36
 
30
37
  componentDidMount() {
@@ -57,22 +64,17 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
57
64
  return;
58
65
  }
59
66
 
60
- // when thoes props isEqual, do not update echarts
67
+ // when these props are not isEqual, update echarts
61
68
  const pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
62
- if (isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
63
- return;
69
+ if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
70
+ this.updateEChartsOption();
64
71
  }
65
72
 
66
- const echartsInstance = this.updateEChartsOption();
67
73
  /**
68
74
  * when style or class name updated, change size.
69
75
  */
70
76
  if (!isEqual(prevProps.style, this.props.style) || !isEqual(prevProps.className, this.props.className)) {
71
- try {
72
- echartsInstance.resize();
73
- } catch (e) {
74
- console.warn(e);
75
- }
77
+ this.resize();
76
78
  }
77
79
  }
78
80
 
@@ -85,7 +87,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
85
87
  * 1. if exist, return the existed instance
86
88
  * 2. or new one instance
87
89
  */
88
- public getEchartsInstance() {
90
+ public getEchartsInstance(): ECharts {
89
91
  return this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts);
90
92
  }
91
93
 
@@ -122,11 +124,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
122
124
  // 4. on resize
123
125
  if (this.ele) {
124
126
  bind(this.ele, () => {
125
- try {
126
- echartsInstance.resize();
127
- } catch (e) {
128
- console.warn(e);
129
- }
127
+ this.resize();
130
128
  });
131
129
  }
132
130
  }
@@ -167,6 +165,27 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
167
165
  return echartInstance;
168
166
  }
169
167
 
168
+ /**
169
+ * resize wrapper
170
+ */
171
+ private resize() {
172
+ // 1. get the echarts object
173
+ const echartsInstance = this.getEchartsInstance();
174
+
175
+ // 2. call echarts instance resize if not the initial resize
176
+ // resize should not happen on first render as it will cancel initial echarts animations
177
+ if (!this.isInitialResize) {
178
+ try {
179
+ echartsInstance.resize();
180
+ } catch (e) {
181
+ console.warn(e);
182
+ }
183
+ }
184
+
185
+ // 3. update variable for future calls
186
+ this.isInitialResize = false;
187
+ }
188
+
170
189
  render(): JSX.Element {
171
190
  const { style, className = '' } = this.props;
172
191
  // default height = 300
package/src/types.ts CHANGED
@@ -9,6 +9,7 @@ export type Opts = {
9
9
  readonly renderer?: 'canvas' | 'svg';
10
10
  readonly width?: number | null | undefined | 'auto';
11
11
  readonly height?: number | null | undefined | 'auto';
12
+ readonly locale?: string;
12
13
  };
13
14
 
14
15
  export type EChartsReactProps = {