Skip to content

Commit a22cb9a

Browse files
committed
bug fix
1 parent d1bc045 commit a22cb9a

File tree

6 files changed

+86
-22
lines changed

6 files changed

+86
-22
lines changed

example/graph/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export default class App extends Component {
2020
const options = {
2121
title : {
2222
text: '某站点用户访问来源',
23-
subtext: '纯属虚构',
2423
x:'center'
2524
},
2625
tooltip : {

lib/components/Chart.js

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,33 @@ var Charts = (function (_Component) {
7474
var onReady = this.props.onReady;
7575

7676
this.drawChart();
77-
if (onReady) onReady(this.chart);
77+
if (onReady) {
78+
onReady(this.chart);
79+
}
7880
};
7981

8082
Charts.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
8183
var _this = this;
8284

83-
var prevPropsArray = _react2['default'].Children.map(prevProps.children, function (preChild) {
84-
return preChild.props;
85-
});
86-
var propsArray = _react2['default'].Children.map(this.props.children, function (child) {
87-
return child.props;
88-
});
89-
propsArray.map(function (props, index) {
90-
if (props !== prevPropsArray[index]) {
91-
_this.drawChart();
85+
if (this.props.options) {
86+
if (prevProps.options !== this.props.options) {
87+
this.drawChart();
9288
}
93-
});
89+
} else {
90+
(function () {
91+
var prevPropsArray = _react2['default'].Children.map(prevProps.children, function (preChild) {
92+
return preChild.props;
93+
});
94+
var propsArray = _react2['default'].Children.map(_this.props.children, function (child) {
95+
return child.props;
96+
});
97+
propsArray.map(function (props, index) {
98+
if (props !== prevPropsArray[index]) {
99+
_this.drawChart();
100+
}
101+
});
102+
})();
103+
}
94104
};
95105

96106
Charts.prototype.componentWillUnmount = function componentWillUnmount() {
@@ -105,10 +115,14 @@ var Charts = (function (_Component) {
105115
};
106116

107117
Charts.prototype.drawChart = function drawChart() {
108-
console.log(2);
109118
var node = this.refs.chart;
110-
var options = _utilsFilterMap2['default'](['backgroundColor', 'animation', 'calculable', 'renderAsImage', 'timeline', 'title', 'toolbox', 'tooltip', 'legend', 'dataRange', 'dataZoom', 'roamController', 'grid', 'color', 'xAxis', 'yAxis', 'series'], this.props);
111-
this.getChartData(options);
119+
var options = undefined;
120+
if (this.props.options) {
121+
options = this.props.options;
122+
} else {
123+
options = _utilsFilterMap2['default'](['backgroundColor', 'animation', 'calculable', 'renderAsImage', 'timeline', 'title', 'toolbox', 'tooltip', 'legend', 'dataRange', 'dataZoom', 'roamController', 'grid', 'color', 'xAxis', 'yAxis', 'series'], this.props);
124+
this.getChartData(options);
125+
}
112126
this.chart = _echarts2['default'].init(node);
113127
this.chart.setOption(options, this.props.theme);
114128
};

lib/components/Graph.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
var _inherits = require('babel-runtime/helpers/inherits')['default'];
4+
5+
var _createClass = require('babel-runtime/helpers/create-class')['default'];
6+
7+
var _classCallCheck = require('babel-runtime/helpers/class-call-check')['default'];
8+
9+
var _interopRequireDefault = require('babel-runtime/helpers/interop-require-default')['default'];
10+
11+
exports.__esModule = true;
12+
13+
var _ChartBase2 = require('./ChartBase');
14+
15+
var _ChartBase3 = _interopRequireDefault(_ChartBase2);
16+
17+
var graph = (function (_ChartBase) {
18+
_inherits(graph, _ChartBase);
19+
20+
function graph() {
21+
_classCallCheck(this, graph);
22+
23+
_ChartBase.apply(this, arguments);
24+
}
25+
26+
_createClass(graph, null, [{
27+
key: 'defaultProps',
28+
value: {
29+
type: 'graph'
30+
},
31+
enumerable: true
32+
}]);
33+
34+
return graph;
35+
})(_ChartBase3['default']);
36+
37+
exports['default'] = graph;
38+
module.exports = exports['default'];

lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ var _componentsMap = require('./components/Map');
2828

2929
var _componentsMap2 = _interopRequireDefault(_componentsMap);
3030

31+
var _componentsGraph = require('./components/Graph');
32+
33+
var _componentsGraph2 = _interopRequireDefault(_componentsGraph);
34+
3135
var _componentsChart = require('./components/Chart');
3236

3337
var _componentsChart2 = _interopRequireDefault(_componentsChart);
@@ -38,6 +42,7 @@ _componentsChart2['default'].Pie = _componentsPie2['default'];
3842
_componentsChart2['default'].Bar = _componentsBar2['default'];
3943
_componentsChart2['default'].Cloud = _componentsCloud2['default'];
4044
_componentsChart2['default'].Map = _componentsMap2['default'];
45+
_componentsChart2['default'].Graph = _componentsGraph2['default'];
4146

4247
exports['default'] = _componentsChart2['default'];
4348
module.exports = exports['default'];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rc-echarts",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"description": "react echarts",
55
"keywords": [
66
"react",

src/components/Chart.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,25 @@ export default class Charts extends Component {
4545
componentDidMount() {
4646
const { onReady } = this.props;
4747
this.drawChart();
48-
if (onReady) onReady(this.chart);
48+
if (onReady) {
49+
onReady(this.chart);
50+
}
4951
}
5052

5153
componentDidUpdate(prevProps) {
52-
const prevPropsArray = React.Children.map(prevProps.children, (preChild) => preChild.props);
53-
const propsArray = React.Children.map(this.props.children, (child) => child.props);
54-
propsArray.map((props, index) => {
55-
if (props !== prevPropsArray[index]) {
54+
if (this.props.options) {
55+
if (prevProps.options !== this.props.options) {
5656
this.drawChart();
5757
}
58-
});
58+
} else {
59+
const prevPropsArray = React.Children.map(prevProps.children, (preChild) => preChild.props);
60+
const propsArray = React.Children.map(this.props.children, (child) => child.props);
61+
propsArray.map((props, index) => {
62+
if (props !== prevPropsArray[index]) {
63+
this.drawChart();
64+
}
65+
});
66+
}
5967
}
6068

6169
componentWillUnmount() {

0 commit comments

Comments
 (0)