echarts-for-react 2.0.13 → 2.0.16
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 +27 -2
- package/lib/core.d.ts +11 -0
- package/lib/core.js +14 -10
- package/lib/index.d.ts +68 -6
- package/package.json +5 -3
- package/src/core.jsx +17 -10
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A very simple echarts(v3.0 & v4.0) wrapper for react.
|
|
4
4
|
|
|
5
|
-
[](https://travis-ci.org/hustcc/echarts-for-react) [](https://coveralls.io/github/hustcc/echarts-for-react?branch=master) [](https://www.npmjs.com/package/echarts-for-react) [](https://www.npmjs.com/package/echarts-for-react) [](https://www.npmjs.com/package/echarts-for-react)  ](https://travis-ci.org/hustcc/echarts-for-react) [](https://coveralls.io/github/hustcc/echarts-for-react?branch=master) [](https://www.npmjs.com/package/echarts-for-react) [](https://www.npmjs.com/package/echarts-for-react) [](https://www.npmjs.com/package/echarts-for-react)  
|
|
6
6
|
|
|
7
7
|
# 1. install
|
|
8
8
|
|
|
@@ -34,6 +34,28 @@ npm start
|
|
|
34
34
|
|
|
35
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
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
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- **`Import`**
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import 'echarts-gl'
|
|
51
|
+
import ReactEcharts from "echarts-for-react";
|
|
52
|
+
|
|
53
|
+
<ReactEcharts
|
|
54
|
+
option={GL_OPTION}
|
|
55
|
+
/>
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
|
|
37
59
|
|
|
38
60
|
# 2. usage
|
|
39
61
|
|
|
@@ -135,7 +157,6 @@ import 'echarts/lib/component/title';
|
|
|
135
157
|
opts={} />
|
|
136
158
|
```
|
|
137
159
|
|
|
138
|
-
|
|
139
160
|
# 3. component props
|
|
140
161
|
|
|
141
162
|
- **`option`** (required, object)
|
|
@@ -266,6 +287,10 @@ Use the props `opts` of component with `renderer = 'svg'`. For example:
|
|
|
266
287
|
/>
|
|
267
288
|
```
|
|
268
289
|
|
|
290
|
+
- How to resolve Error `Component series.scatter3D not exists. Load it first.`
|
|
291
|
+
|
|
292
|
+
[Install and import `echarts-gl` first](#GL)
|
|
293
|
+
|
|
269
294
|
|
|
270
295
|
# 6. LICENSE
|
|
271
296
|
|
package/lib/core.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import {ReactEchartsPropsTypes} from './index.d'
|
|
5
|
+
|
|
6
|
+
// Core
|
|
7
|
+
export interface ReactEchartsCorePropsTypes extends ReactEchartsPropsTypes{
|
|
8
|
+
echarts: object;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class ReactEchartsCore extends React.Component<ReactEchartsCorePropsTypes, any>{}
|
package/lib/core.js
CHANGED
|
@@ -71,7 +71,11 @@ var EchartsReactCore = function (_Component) {
|
|
|
71
71
|
// on resize
|
|
72
72
|
if (_this.echartsElement) {
|
|
73
73
|
(0, _sizeSensor.bind)(_this.echartsElement, function () {
|
|
74
|
-
|
|
74
|
+
try {
|
|
75
|
+
echartObj.resize();
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.warn(e);
|
|
78
|
+
}
|
|
75
79
|
});
|
|
76
80
|
}
|
|
77
81
|
};
|
|
@@ -107,7 +111,7 @@ var EchartsReactCore = function (_Component) {
|
|
|
107
111
|
return echartObj;
|
|
108
112
|
};
|
|
109
113
|
|
|
110
|
-
_this.echartsLib =
|
|
114
|
+
_this.echartsLib = props.echarts; // the echarts object.
|
|
111
115
|
_this.echartsElement = null; // echarts div element
|
|
112
116
|
return _this;
|
|
113
117
|
}
|
|
@@ -126,11 +130,16 @@ var EchartsReactCore = function (_Component) {
|
|
|
126
130
|
}, {
|
|
127
131
|
key: 'componentDidUpdate',
|
|
128
132
|
value: function componentDidUpdate(prevProps) {
|
|
133
|
+
// 判断是否需要 setOption,由开发者自己来确定。默认为 true
|
|
134
|
+
if (typeof this.props.shouldSetOption === 'function' && !this.props.shouldSetOption(prevProps, this.props)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
129
138
|
// 以下属性修改的时候,需要 dispose 之后再新建
|
|
130
139
|
// 1. 切换 theme 的时候
|
|
131
140
|
// 2. 修改 opts 的时候
|
|
132
|
-
// 3. 修改 onEvents
|
|
133
|
-
if (prevProps.theme
|
|
141
|
+
// 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151
|
|
142
|
+
if (!(0, _fastDeepEqual2['default'])(prevProps.theme, this.props.theme) || !(0, _fastDeepEqual2['default'])(prevProps.opts, this.props.opts) || !(0, _fastDeepEqual2['default'])(prevProps.onEvents, this.props.onEvents)) {
|
|
134
143
|
this.dispose();
|
|
135
144
|
|
|
136
145
|
this.rerender(); // 重建
|
|
@@ -143,11 +152,6 @@ var EchartsReactCore = function (_Component) {
|
|
|
143
152
|
return;
|
|
144
153
|
}
|
|
145
154
|
|
|
146
|
-
// 判断是否需要 setOption,由开发者自己来确定。默认为 true
|
|
147
|
-
if (typeof this.props.shouldSetOption === 'function' && !this.props.shouldSetOption(prevProps, this.props)) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
155
|
var echartObj = this.renderEchartDom();
|
|
152
156
|
// 样式修改的时候,可能会导致大小变化,所以触发一下 resize
|
|
153
157
|
if (!(0, _fastDeepEqual2['default'])(prevProps.style, this.props.style) || !(0, _fastDeepEqual2['default'])(prevProps.className, this.props.className)) {
|
|
@@ -214,7 +218,7 @@ EchartsReactCore.propTypes = {
|
|
|
214
218
|
lazyUpdate: _propTypes2['default'].bool,
|
|
215
219
|
style: _propTypes2['default'].object, // eslint-disable-line react/forbid-prop-types
|
|
216
220
|
className: _propTypes2['default'].string,
|
|
217
|
-
theme: _propTypes2['default'].string,
|
|
221
|
+
theme: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].object]),
|
|
218
222
|
onChartReady: _propTypes2['default'].func,
|
|
219
223
|
showLoading: _propTypes2['default'].bool,
|
|
220
224
|
loadingOption: _propTypes2['default'].object, // eslint-disable-line react/forbid-prop-types
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import { EChartOption, EChartsLoadingOption, ECharts } from 'echarts';
|
|
4
5
|
|
|
5
6
|
type Func = (...args: any[]) => any;
|
|
6
7
|
|
|
@@ -21,19 +22,80 @@ interface optsMap {
|
|
|
21
22
|
|
|
22
23
|
// Index
|
|
23
24
|
export interface ReactEchartsPropsTypes {
|
|
24
|
-
|
|
25
|
+
/**
|
|
26
|
+
* the echarts option config
|
|
27
|
+
* @see http://echarts.baidu.com/option.html#title
|
|
28
|
+
*/
|
|
29
|
+
option: EChartOption;
|
|
30
|
+
/**
|
|
31
|
+
* when `setOption`, not merge the data.
|
|
32
|
+
* @default false
|
|
33
|
+
* @see http://echarts.baidu.com/api.html#echartsInstance.setOption
|
|
34
|
+
*/
|
|
25
35
|
notMerge?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* when `setOption`, lazy update the data.
|
|
38
|
+
* @default false
|
|
39
|
+
* @see http://echarts.baidu.com/api.html#echartsInstance.setOption
|
|
40
|
+
*/
|
|
26
41
|
lazyUpdate?: boolean;
|
|
27
|
-
|
|
42
|
+
/**
|
|
43
|
+
* the `style` of echarts div.
|
|
44
|
+
* @default {height: '300px'}
|
|
45
|
+
*/
|
|
46
|
+
style?: React.CSSProperties;
|
|
47
|
+
/**
|
|
48
|
+
* the `class` of echarts div. you can setting the css style of charts by class name.
|
|
49
|
+
*/
|
|
28
50
|
className?: string;
|
|
29
|
-
|
|
51
|
+
/**
|
|
52
|
+
* the `theme` of echarts. should `registerTheme` before use it.
|
|
53
|
+
* @see https://github.com/ecomfe/echarts/blob/master/theme/dark.js)
|
|
54
|
+
* @example
|
|
55
|
+
* ```
|
|
56
|
+
// register theme object
|
|
57
|
+
echarts.registerTheme('my_theme', { backgroundColor: '#f4cccc' });
|
|
58
|
+
// render the echarts use option `theme`
|
|
59
|
+
<ReactEcharts option={this.getOption()} theme='my_theme' />
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
theme?: string | null | ObjectMap;
|
|
63
|
+
/**
|
|
64
|
+
* when the chart is ready, will callback the function with the `echarts object` as it's paramter.
|
|
65
|
+
*/
|
|
30
66
|
onChartReady?: Func;
|
|
67
|
+
/**
|
|
68
|
+
* when the chart is rendering, show the loading mask.
|
|
69
|
+
*/
|
|
31
70
|
showLoading?: boolean;
|
|
32
|
-
|
|
71
|
+
/**
|
|
72
|
+
* the echarts loading option config.
|
|
73
|
+
* @see http://echarts.baidu.com/api.html#echartsInstance.showLoading
|
|
74
|
+
*/
|
|
75
|
+
loadingOption?: EChartsLoadingOption;
|
|
76
|
+
/**
|
|
77
|
+
* binding the echarts event, will callback with the `echarts event object`, and the `echart object` as it's paramters.
|
|
78
|
+
* @example
|
|
79
|
+
* ```
|
|
80
|
+
let onEvents = {
|
|
81
|
+
'click': this.onChartClick,
|
|
82
|
+
'legendselectchanged': this.onChartLegendselectchanged
|
|
83
|
+
}
|
|
84
|
+
<ReactEcharts onEvents={onEvents} />
|
|
85
|
+
* ```
|
|
86
|
+
* @see: http://echarts.baidu.com/api.html#events
|
|
87
|
+
*/
|
|
33
88
|
onEvents?: EventMap;
|
|
34
|
-
|
|
89
|
+
/**
|
|
90
|
+
* the `opts` of echarts. will be used when initial echarts instance by `echarts.init`.
|
|
91
|
+
* @see http://echarts.baidu.com/api.html#echarts.init
|
|
92
|
+
*/
|
|
35
93
|
opts?: optsMap;
|
|
36
94
|
shouldSetOption?: Func;
|
|
37
95
|
}
|
|
38
96
|
|
|
39
|
-
|
|
97
|
+
declare class ReactEcharts extends React.Component<ReactEchartsPropsTypes, any>{
|
|
98
|
+
getEchartsInstance(): ECharts;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default ReactEcharts;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "echarts-for-react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "baidu Echarts(v3.x & v4.x) components for react.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -72,7 +72,8 @@
|
|
|
72
72
|
"eslint-plugin-react": "^7.5.1",
|
|
73
73
|
"file-loader": "^1.1.6",
|
|
74
74
|
"jest": "^22.4.2",
|
|
75
|
-
"jest-canvas-mock": "^
|
|
75
|
+
"jest-canvas-mock": "^2.0.0-alpha.0",
|
|
76
|
+
"jest-electron": "^0.1.7",
|
|
76
77
|
"jsx-loader": "^0.13.2",
|
|
77
78
|
"lodash.clonedeep": "^4.5.0",
|
|
78
79
|
"react": "^15.5.0",
|
|
@@ -87,7 +88,7 @@
|
|
|
87
88
|
},
|
|
88
89
|
"dependencies": {
|
|
89
90
|
"fast-deep-equal": "^2.0.1",
|
|
90
|
-
"size-sensor": "^0.0
|
|
91
|
+
"size-sensor": "^1.0.0"
|
|
91
92
|
},
|
|
92
93
|
"peerDependencies": {
|
|
93
94
|
"react": ">=0.13.2 || ^0.14 || ^15.0.0 || >=16.0.0",
|
|
@@ -96,6 +97,7 @@
|
|
|
96
97
|
},
|
|
97
98
|
"jest": {
|
|
98
99
|
"testRegex": "(/__tests__/.*\\.spec)\\.(js|jsx)$",
|
|
100
|
+
"testURL": "https://atool.vip/",
|
|
99
101
|
"moduleFileExtensions": [
|
|
100
102
|
"js",
|
|
101
103
|
"jsx",
|
package/src/core.jsx
CHANGED
|
@@ -7,7 +7,7 @@ import { pick } from './utils';
|
|
|
7
7
|
export default class EchartsReactCore extends Component {
|
|
8
8
|
constructor(props) {
|
|
9
9
|
super(props);
|
|
10
|
-
this.echartsLib =
|
|
10
|
+
this.echartsLib = props.echarts; // the echarts object.
|
|
11
11
|
this.echartsElement = null; // echarts div element
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -18,12 +18,17 @@ export default class EchartsReactCore extends Component {
|
|
|
18
18
|
|
|
19
19
|
// update
|
|
20
20
|
componentDidUpdate(prevProps) {
|
|
21
|
+
// 判断是否需要 setOption,由开发者自己来确定。默认为 true
|
|
22
|
+
if (typeof this.props.shouldSetOption === 'function' && !this.props.shouldSetOption(prevProps, this.props)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
// 以下属性修改的时候,需要 dispose 之后再新建
|
|
22
27
|
// 1. 切换 theme 的时候
|
|
23
28
|
// 2. 修改 opts 的时候
|
|
24
|
-
// 3. 修改 onEvents
|
|
29
|
+
// 3. 修改 onEvents 的时候,这样可以取消所有之前绑定的事件 issue #151
|
|
25
30
|
if (
|
|
26
|
-
prevProps.theme
|
|
31
|
+
!isEqual(prevProps.theme, this.props.theme) ||
|
|
27
32
|
!isEqual(prevProps.opts, this.props.opts) ||
|
|
28
33
|
!isEqual(prevProps.onEvents, this.props.onEvents)
|
|
29
34
|
) {
|
|
@@ -39,11 +44,6 @@ export default class EchartsReactCore extends Component {
|
|
|
39
44
|
return;
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
// 判断是否需要 setOption,由开发者自己来确定。默认为 true
|
|
43
|
-
if (typeof this.props.shouldSetOption === 'function' && !this.props.shouldSetOption(prevProps, this.props)) {
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
47
|
const echartObj = this.renderEchartDom();
|
|
48
48
|
// 样式修改的时候,可能会导致大小变化,所以触发一下 resize
|
|
49
49
|
if (!isEqual(prevProps.style, this.props.style) || !isEqual(prevProps.className, this.props.className)) {
|
|
@@ -88,7 +88,11 @@ export default class EchartsReactCore extends Component {
|
|
|
88
88
|
// on resize
|
|
89
89
|
if (this.echartsElement) {
|
|
90
90
|
bind(this.echartsElement, () => {
|
|
91
|
-
|
|
91
|
+
try {
|
|
92
|
+
echartObj.resize();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
console.warn(e);
|
|
95
|
+
}
|
|
92
96
|
});
|
|
93
97
|
}
|
|
94
98
|
};
|
|
@@ -151,7 +155,10 @@ EchartsReactCore.propTypes = {
|
|
|
151
155
|
lazyUpdate: PropTypes.bool,
|
|
152
156
|
style: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|
|
153
157
|
className: PropTypes.string,
|
|
154
|
-
theme: PropTypes.
|
|
158
|
+
theme: PropTypes.oneOfType([
|
|
159
|
+
PropTypes.string,
|
|
160
|
+
PropTypes.object
|
|
161
|
+
]),
|
|
155
162
|
onChartReady: PropTypes.func,
|
|
156
163
|
showLoading: PropTypes.bool,
|
|
157
164
|
loadingOption: PropTypes.object, // eslint-disable-line react/forbid-prop-types
|