echarts-for-react 2.0.16 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +165 -90
  3. package/esm/core.d.ts +39 -0
  4. package/esm/core.js +157 -0
  5. package/esm/core.js.map +1 -0
  6. package/esm/helper/is-equal.d.ts +2 -0
  7. package/esm/helper/is-equal.js +3 -0
  8. package/esm/helper/is-equal.js.map +1 -0
  9. package/esm/helper/is-function.d.ts +1 -0
  10. package/esm/helper/is-function.js +4 -0
  11. package/esm/helper/is-function.js.map +1 -0
  12. package/esm/helper/is-string.d.ts +1 -0
  13. package/esm/helper/is-string.js +4 -0
  14. package/esm/helper/is-string.js.map +1 -0
  15. package/esm/helper/pick.d.ts +6 -0
  16. package/esm/helper/pick.js +13 -0
  17. package/esm/helper/pick.js.map +1 -0
  18. package/esm/index.d.ts +6 -0
  19. package/esm/index.js +16 -0
  20. package/esm/index.js.map +1 -0
  21. package/esm/types.d.ts +66 -0
  22. package/esm/types.js +2 -0
  23. package/esm/types.js.map +1 -0
  24. package/lib/core.d.ts +38 -10
  25. package/lib/core.js +151 -242
  26. package/lib/core.js.map +1 -0
  27. package/lib/helper/is-equal.d.ts +2 -0
  28. package/lib/helper/is-equal.js +7 -0
  29. package/lib/helper/is-equal.js.map +1 -0
  30. package/lib/helper/is-function.d.ts +1 -0
  31. package/lib/helper/is-function.js +8 -0
  32. package/lib/helper/is-function.js.map +1 -0
  33. package/lib/helper/is-string.d.ts +1 -0
  34. package/lib/helper/is-string.js +8 -0
  35. package/lib/helper/is-string.js.map +1 -0
  36. package/lib/helper/pick.d.ts +6 -0
  37. package/lib/helper/pick.js +17 -0
  38. package/lib/helper/pick.js.map +1 -0
  39. package/lib/index.d.ts +5 -100
  40. package/lib/index.js +17 -39
  41. package/lib/index.js.map +1 -0
  42. package/lib/types.d.ts +66 -0
  43. package/lib/types.js +3 -0
  44. package/lib/types.js.map +1 -0
  45. package/package.json +72 -77
  46. package/src/core.tsx +185 -0
  47. package/src/helper/is-equal.ts +3 -0
  48. package/src/helper/is-function.ts +3 -0
  49. package/src/helper/is-string.ts +3 -0
  50. package/src/helper/pick.ts +12 -0
  51. package/src/index.ts +15 -0
  52. package/src/types.ts +70 -0
  53. package/lib/.DS_Store +0 -0
  54. package/lib/utils.js +0 -14
  55. package/src/core.jsx +0 -194
  56. package/src/index.js +0 -10
  57. package/src/utils.js +0 -10
package/LICENSE CHANGED
@@ -1,13 +1,13 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) hustcc
3
+ Copyright (c) 2018 AntV team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
7
7
  in the Software without restriction, including without limitation the rights
8
8
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
10
+ furnished to do { so, subject } to the following conditions:
11
11
 
12
12
  The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
package/README.md CHANGED
@@ -1,104 +1,164 @@
1
1
  # echarts-for-react
2
2
 
3
- A very simple echarts(v3.0 & v4.0) wrapper for react.
3
+ The simplest, and the best React wrapper for [Apache ECharts](https://github.com/apache/incubator-echarts).
4
4
 
5
- [![Build Status](https://travis-ci.org/hustcc/echarts-for-react.svg?branch=master)](https://travis-ci.org/hustcc/echarts-for-react) [![Coverage Status](https://coveralls.io/repos/github/hustcc/echarts-for-react/badge.svg?branch=master)](https://coveralls.io/github/hustcc/echarts-for-react?branch=master) [![npm](https://img.shields.io/npm/v/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) [![npm](https://img.shields.io/npm/dm/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) [![npm](https://img.shields.io/npm/l/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react) ![echarts supported](https://img.shields.io/badge/echarts-%5E3.0.0%20%7C%7C%20%5E4.0.0-blue.svg) ![react supported](https://img.shields.io/badge/React-%20%5E15.0.0%20%7C%7C%20%20%5E16.0.0-blue.svg)
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)
7
+ [![Coverage](https://img.shields.io/coveralls/hustcc/echarts-for-react/master.svg)](https://coveralls.io/github/hustcc/echarts-for-react)
8
+ [![NPM downloads](https://img.shields.io/npm/dm/echarts-for-react.svg)](https://www.npmjs.com/package/echarts-for-react)
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)
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)
6
12
 
7
- # 1. install
8
13
 
9
- ```sh
10
- npm install --save echarts-for-react
14
+ ## Install
15
+
16
+ ```bach
17
+ $ npm install --save echarts-for-react
11
18
 
12
19
  # `echarts` is the peerDependence of `echarts-for-react`, you can install echarts with your own version.
13
- npm install --save echarts
20
+ $ npm install --save echarts
14
21
  ```
15
22
 
16
23
  Then use it.
17
24
 
18
- ```js
19
- import ReactEcharts from 'echarts-for-react';
25
+ ```ts
26
+ import ReactECharts from 'echarts-for-react';
20
27
 
21
28
  // render echarts option.
22
- <ReactEcharts option={this.getOption()} />
23
- ```
24
-
25
- You can run demo by:
26
-
27
- ```sh
28
- git clone git@github.com:hustcc/echarts-for-react.git
29
-
30
- npm install
31
-
32
- npm start
33
- ```
34
-
35
- 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/)
36
-
37
- ## GL
38
-
39
- 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)
40
-
41
- - **`Install`**
42
-
43
- ```sh
44
- npm install --save echarts-gl
29
+ <ReactECharts option={this.getOption()} />
45
30
  ```
46
31
 
47
- - **`Import`**
32
+ You can run website.
48
33
 
49
- ```js
50
- import 'echarts-gl'
51
- import ReactEcharts from "echarts-for-react";
34
+ ```bash
35
+ $ git clone git@github.com:hustcc/echarts-for-react.git
52
36
 
53
- <ReactEcharts
54
- option={GL_OPTION}
55
- />
37
+ $ npm install
56
38
 
39
+ $ npm start
57
40
  ```
58
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.
59
43
 
60
- # 2. usage
61
44
 
62
- 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
63
46
 
64
- ### 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/)
65
48
 
66
- ```js
49
+ ```ts
67
50
  import React from 'react';
68
- 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');
69
52
 
70
- <ReactEcharts
53
+ <ReactECharts
71
54
  option={this.getOption()}
72
55
  notMerge={true}
73
56
  lazyUpdate={true}
74
57
  theme={"theme_name"}
75
58
  onChartReady={this.onChartReadyCallback}
76
59
  onEvents={EventsDict}
77
- opts={} />
60
+ opts={}
61
+ />
78
62
  ```
79
63
 
80
- ### typescript
64
+ Import ECharts.js modules manually to reduce bundle size
81
65
 
82
- ```js
83
- import * as React from "react";
84
- import ReactEcharts from "echarts-for-react";
66
+ **With Echarts.js v5:**
85
67
 
86
- <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}
87
146
  option={this.getOption()}
88
147
  notMerge={true}
89
148
  lazyUpdate={true}
90
149
  theme={"theme_name"}
91
150
  onChartReady={this.onChartReadyCallback}
92
151
  onEvents={EventsDict}
93
- opts={} />
152
+ opts={}
153
+ />
94
154
  ```
95
155
 
96
- Import ECharts.js modules manually to reduce bundle size
156
+ **With Echarts.js v3 or v4:**
97
157
 
98
- ```js
158
+ ```ts
99
159
  import React from 'react';
100
160
  // import the core library.
101
- import ReactEchartsCore from 'echarts-for-react/lib/core';
161
+ import ReactEChartsCore from 'echarts-for-react/lib/core';
102
162
 
103
163
  // then import echarts modules those you have used manually.
104
164
  import echarts from 'echarts/lib/echarts';
@@ -145,8 +205,8 @@ import 'echarts/lib/component/title';
145
205
 
146
206
  // import 'zrender/lib/vml/vml';
147
207
 
148
- // The usage of ReactEchartsCore are same with above.
149
- <ReactEchartsCore
208
+ // The usage of ReactEChartsCore are same with above.
209
+ <ReactEChartsCore
150
210
  echarts={echarts}
151
211
  option={this.getOption()}
152
212
  notMerge={true}
@@ -154,22 +214,23 @@ import 'echarts/lib/component/title';
154
214
  theme={"theme_name"}
155
215
  onChartReady={this.onChartReadyCallback}
156
216
  onEvents={EventsDict}
157
- opts={} />
217
+ opts={}
218
+ />
158
219
  ```
159
220
 
160
- # 3. component props
221
+ ## Props of Component
161
222
 
162
223
  - **`option`** (required, object)
163
224
 
164
- the echarts option config, can see [http://echarts.baidu.com/option.html#title](http://echarts.baidu.com/option.html#title).
225
+ the echarts option config, can see [https://echarts.apache.org/option.html#title](https://echarts.apache.org/option.html#title).
165
226
 
166
227
  - **`notMerge`** (optional, object)
167
228
 
168
- when `setOption`, not merge the data, default is `false`. See [http://echarts.baidu.com/api.html#echartsInstance.setOption](http://echarts.baidu.com/api.html#echartsInstance.setOption).
229
+ 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).
169
230
 
170
231
  - **`lazyUpdate`** (optional, object)
171
232
 
172
- when `setOption`, lazy update the data, default is `false`. See [http://echarts.baidu.com/api.html#echartsInstance.setOption](http://echarts.baidu.com/api.html#echartsInstance.setOption).
233
+ 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).
173
234
 
174
235
  - **`style`** (optional, object)
175
236
 
@@ -183,7 +244,7 @@ the `class` of echarts div. you can setting the css style of charts by class nam
183
244
 
184
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.
185
246
 
186
- ```js
247
+ ```ts
187
248
  // import echarts
188
249
  import echarts from 'echarts';
189
250
  ...
@@ -193,7 +254,7 @@ echarts.registerTheme('my_theme', {
193
254
  });
194
255
  ...
195
256
  // render the echarts use option `theme`
196
- <ReactEcharts
257
+ <ReactECharts
197
258
  option={this.getOption()}
198
259
  style={{height: '300px', width: '100%'}}
199
260
  className='echarts-for-echarts'
@@ -206,7 +267,7 @@ when the chart is ready, will callback the function with the `echarts object` as
206
267
 
207
268
  - **`loadingOption`** (optional, object)
208
269
 
209
- the echarts loading option config, can see [http://echarts.baidu.com/api.html#echartsInstance.showLoading](http://echarts.baidu.com/api.html#echartsInstance.showLoading).
270
+ the echarts loading option config, can see [https://echarts.apache.org/api.html#echartsInstance.showLoading](https://echarts.apache.org/api.html#echartsInstance.showLoading).
210
271
 
211
272
  - **`showLoading`** (optional, bool, default: false)
212
273
 
@@ -216,33 +277,34 @@ the echarts loading option config, can see [http://echarts.baidu.com/api.html#ec
216
277
 
217
278
  binding the echarts event, will callback with the `echarts event object`, and `the echart object` as it's paramters. e.g:
218
279
 
219
- ```js
220
- let onEvents = {
280
+ ```ts
281
+ const onEvents = {
221
282
  'click': this.onChartClick,
222
283
  'legendselectchanged': this.onChartLegendselectchanged
223
284
  }
224
285
  ...
225
- <ReactEcharts
286
+ <ReactECharts
226
287
  option={this.getOption()}
227
- style={{height: '300px', width: '100%'}}
228
- onEvents={onEvents} />
288
+ style={{ height: '300px', width: '100%' }}
289
+ onEvents={onEvents}
290
+ />
229
291
  ```
230
- for more event key name, see: [http://echarts.baidu.com/api.html#events](http://echarts.baidu.com/api.html#events)
292
+ for more event key name, see: [https://echarts.apache.org/api.html#events](https://echarts.apache.org/api.html#events)
231
293
 
232
294
  - **`opts`** (optional, object)
233
295
 
234
- the `opts` of echarts. `object`, will be used when initial echarts instance by `echarts.init`. Document [here](http://echarts.baidu.com/api.html#echarts.init).
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).
235
297
 
236
- ```js
237
- <ReactEcharts
298
+ ```ts
299
+ <ReactECharts
238
300
  option={this.getOption()}
239
- style={{height: '300px'}}
301
+ style={{ height: '300px' }}
240
302
  opts={{renderer: 'svg'}} // use svg to render the chart.
241
303
  />
242
304
  ```
243
305
 
244
306
 
245
- # 4. Component API & Echarts API
307
+ ## Component API & Echarts API
246
308
 
247
309
  the Component only has `one API` named `getEchartsInstance`.
248
310
 
@@ -250,19 +312,21 @@ the Component only has `one API` named `getEchartsInstance`.
250
312
 
251
313
  for example:
252
314
 
253
- ```js
315
+ ```ts
254
316
  // render the echarts component below with rel
255
- <ReactEcharts ref={(e) => { this.echarts_react = e; }}
256
- option={this.getOption()} />
317
+ <ReactECharts
318
+ ref={(e) => { this.echartRef = e; }}
319
+ option={this.getOption()}
320
+ />
257
321
 
258
- // then get the `ReactEcharts` use this.echarts_react
322
+ // then get the `ReactECharts` use this.echarts_react
259
323
 
260
- let echarts_instance = this.echarts_react.getEchartsInstance();
324
+ const echartInstance = this.echartRef.getEchartsInstance();
261
325
  // then you can use any API of echarts.
262
- let base64 = echarts_instance.getDataURL();
326
+ const base64 = echartInstance.getDataURL();
263
327
  ```
264
328
 
265
- **About API of echarts, can see** [http://echarts.baidu.com/api.html#echartsInstance](http://echarts.baidu.com/api.html#echartsInstance).
329
+ **About API of echarts, can see** [https://echarts.apache.org/api.html#echartsInstance](https://echarts.apache.org/api.html#echartsInstance).
266
330
 
267
331
  You can use the API to do:
268
332
 
@@ -272,28 +336,39 @@ You can use the API to do:
272
336
  4. `release` the charts.
273
337
 
274
338
 
275
- # 5. Q & A
339
+ ## FAQ
276
340
 
277
- - 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
278
342
 
279
343
  Use the props `opts` of component with `renderer = 'svg'`. For example:
280
344
 
281
345
 
282
- ```js
283
- <ReactEcharts
346
+ ```ts
347
+ <ReactECharts
284
348
  option={this.getOption()}
285
349
  style={{height: '300px'}}
286
350
  opts={{renderer: 'svg'}} // use svg to render the chart.
287
351
  />
288
352
  ```
289
353
 
290
- - 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.`
291
355
 
292
- [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)
293
357
 
358
+ ```sh
359
+ npm install --save echarts-gl
360
+ ```
294
361
 
295
- # 6. LICENSE
362
+ ```ts
363
+ import 'echarts-gl'
364
+ import ReactECharts from "echarts-for-react";
296
365
 
297
- MIT@[hustcc](https://github.com/hustcc).
366
+ <ReactECharts
367
+ option={GL_OPTION}
368
+ />
369
+ ```
298
370
 
299
371
 
372
+ ## LICENSE
373
+
374
+ MIT@[hustcc](https://github.com/hustcc).
package/esm/core.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { PureComponent } from 'react';
2
+ import { EChartsReactProps } from './types';
3
+ /**
4
+ * core component for echarts binding
5
+ */
6
+ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
7
+ /**
8
+ * echarts render container
9
+ */
10
+ ele: HTMLElement;
11
+ /**
12
+ * echarts library entry
13
+ */
14
+ protected echarts: any;
15
+ constructor(props: EChartsReactProps);
16
+ componentDidMount(): void;
17
+ componentDidUpdate(prevProps: EChartsReactProps): void;
18
+ componentWillUnmount(): void;
19
+ /**
20
+ * return the echart object
21
+ * 1. if exist, return the existed instance
22
+ * 2. or new one instance
23
+ */
24
+ getEchartsInstance(): any;
25
+ /**
26
+ * dispose echarts and clear size-sensor
27
+ */
28
+ private dispose;
29
+ /**
30
+ * render a new echarts instance
31
+ */
32
+ private renderNewEcharts;
33
+ private bindEvents;
34
+ /**
35
+ * render the echarts
36
+ */
37
+ private updateEChartsOption;
38
+ render(): JSX.Element;
39
+ }
package/esm/core.js ADDED
@@ -0,0 +1,157 @@
1
+ import { __assign, __extends } from "tslib";
2
+ import React, { PureComponent } from 'react';
3
+ import { bind, clear } from 'size-sensor';
4
+ import { pick } from './helper/pick';
5
+ import { isFunction } from './helper/is-function';
6
+ import { isString } from './helper/is-string';
7
+ import { isEqual } from './helper/is-equal';
8
+ /**
9
+ * core component for echarts binding
10
+ */
11
+ var EChartsReactCore = /** @class */ (function (_super) {
12
+ __extends(EChartsReactCore, _super);
13
+ function EChartsReactCore(props) {
14
+ var _this = _super.call(this, props) || this;
15
+ _this.echarts = props.echarts;
16
+ _this.ele = null;
17
+ return _this;
18
+ }
19
+ EChartsReactCore.prototype.componentDidMount = function () {
20
+ this.renderNewEcharts();
21
+ };
22
+ // update
23
+ EChartsReactCore.prototype.componentDidUpdate = function (prevProps) {
24
+ /**
25
+ * if shouldSetOption return false, then return, not update echarts options
26
+ * default is true
27
+ */
28
+ var shouldSetOption = this.props.shouldSetOption;
29
+ if (isFunction(shouldSetOption) && !shouldSetOption(prevProps, this.props)) {
30
+ return;
31
+ }
32
+ // 以下属性修改的时候,需要 dispose 之后再新建
33
+ // 1. 切换 theme 的时候
34
+ // 2. 修改 opts 的时候
35
+ // 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151
36
+ if (!isEqual(prevProps.theme, this.props.theme) ||
37
+ !isEqual(prevProps.opts, this.props.opts) ||
38
+ !isEqual(prevProps.onEvents, this.props.onEvents)) {
39
+ this.dispose();
40
+ this.renderNewEcharts(); // 重建
41
+ return;
42
+ }
43
+ // when thoes props isEqual, do not update echarts
44
+ var pickKeys = ['option', 'notMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
45
+ if (isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
46
+ return;
47
+ }
48
+ var echartsInstance = this.updateEChartsOption();
49
+ /**
50
+ * when style or class name updated, change size.
51
+ */
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
+ }
59
+ }
60
+ };
61
+ EChartsReactCore.prototype.componentWillUnmount = function () {
62
+ this.dispose();
63
+ };
64
+ /**
65
+ * return the echart object
66
+ * 1. if exist, return the existed instance
67
+ * 2. or new one instance
68
+ */
69
+ EChartsReactCore.prototype.getEchartsInstance = function () {
70
+ return this.echarts.getInstanceByDom(this.ele) || this.echarts.init(this.ele, this.props.theme, this.props.opts);
71
+ };
72
+ /**
73
+ * dispose echarts and clear size-sensor
74
+ */
75
+ EChartsReactCore.prototype.dispose = function () {
76
+ if (this.ele) {
77
+ try {
78
+ clear(this.ele);
79
+ }
80
+ catch (e) {
81
+ console.warn(e);
82
+ }
83
+ // dispose echarts instance
84
+ this.echarts.dispose(this.ele);
85
+ }
86
+ };
87
+ /**
88
+ * render a new echarts instance
89
+ */
90
+ EChartsReactCore.prototype.renderNewEcharts = function () {
91
+ var _a = this.props, onEvents = _a.onEvents, onChartReady = _a.onChartReady;
92
+ // 1. new echarts instance
93
+ var echartsInstance = this.updateEChartsOption();
94
+ // 2. bind events
95
+ this.bindEvents(echartsInstance, onEvents || {});
96
+ // 3. on chart ready
97
+ if (isFunction(onChartReady))
98
+ onChartReady(echartsInstance);
99
+ // 4. on resize
100
+ if (this.ele) {
101
+ bind(this.ele, function () {
102
+ try {
103
+ echartsInstance.resize();
104
+ }
105
+ catch (e) {
106
+ console.warn(e);
107
+ }
108
+ });
109
+ }
110
+ };
111
+ // bind the events
112
+ EChartsReactCore.prototype.bindEvents = function (instance, events) {
113
+ function _bindEvent(eventName, func) {
114
+ // ignore the event config which not satisfy
115
+ if (isString(eventName) && isFunction(func)) {
116
+ // binding event
117
+ instance.on(eventName, function (param) {
118
+ func(param, instance);
119
+ });
120
+ }
121
+ }
122
+ // loop and bind
123
+ for (var eventName in events) {
124
+ if (Object.prototype.hasOwnProperty.call(events, eventName)) {
125
+ _bindEvent(eventName, events[eventName]);
126
+ }
127
+ }
128
+ };
129
+ /**
130
+ * render the echarts
131
+ */
132
+ EChartsReactCore.prototype.updateEChartsOption = function () {
133
+ 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;
134
+ // 1. get or initial the echarts object
135
+ var echartInstance = this.getEchartsInstance();
136
+ // 2. set the echarts option
137
+ echartInstance.setOption(option, notMerge, lazyUpdate);
138
+ // 3. set loading mask
139
+ if (showLoading)
140
+ echartInstance.showLoading(loadingOption);
141
+ else
142
+ echartInstance.hideLoading();
143
+ return echartInstance;
144
+ };
145
+ EChartsReactCore.prototype.render = function () {
146
+ var _this = this;
147
+ var _a = this.props, style = _a.style, _b = _a.className, className = _b === void 0 ? '' : _b;
148
+ // default height = 300
149
+ var newStyle = __assign({ height: 300 }, style);
150
+ return (React.createElement("div", { ref: function (e) {
151
+ _this.ele = e;
152
+ }, style: newStyle, className: "echarts-for-react " + className }));
153
+ };
154
+ return EChartsReactCore;
155
+ }(PureComponent));
156
+ export default EChartsReactCore;
157
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.tsx"],"names":[],"mappings":";AAAA,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;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,UAAU,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,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;YAC3C,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC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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"]}
@@ -0,0 +1,2 @@
1
+ import isEqual from 'fast-deep-equal';
2
+ export { isEqual };
@@ -0,0 +1,3 @@
1
+ import isEqual from 'fast-deep-equal';
2
+ export { isEqual };
3
+ //# sourceMappingURL=is-equal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-equal.js","sourceRoot":"","sources":["../../src/helper/is-equal.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,iBAAiB,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,CAAC","sourcesContent":["import isEqual from 'fast-deep-equal';\n\nexport { isEqual };\n"]}
@@ -0,0 +1 @@
1
+ export declare function isFunction(v: any): boolean;
@@ -0,0 +1,4 @@
1
+ export function isFunction(v) {
2
+ return typeof v === 'function';
3
+ }
4
+ //# sourceMappingURL=is-function.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-function.js","sourceRoot":"","sources":["../../src/helper/is-function.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,CAAM;IAC/B,OAAO,OAAO,CAAC,KAAK,UAAU,CAAC;AACjC,CAAC","sourcesContent":["export function isFunction(v: any): boolean {\n return typeof v === 'function';\n}\n"]}