Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit ff15b2b

Browse files
committed
add chart.js to peer dependencies and require it in core
1 parent e740cb6 commit ff15b2b

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

lib/core.js

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,35 @@ module.exports = {
2323
};
2424
}
2525

26-
if (global.Chart) {
27-
classData.componentDidMount = function() {
28-
this.initializeChart(this.props);
29-
};
26+
classData.componentDidMount = function() {
27+
this.initializeChart(this.props);
28+
};
3029

31-
classData.componentWillUnmount = function() {
32-
var chart = this.state.chart;
33-
chart.destroy();
34-
};
30+
classData.componentWillUnmount = function() {
31+
var chart = this.state.chart;
32+
chart.destroy();
33+
};
3534

36-
classData.componentWillReceiveProps = function(nextProps) {
37-
var chart = this.state.chart;
38-
chart.destroy();
39-
this.initializeChart(nextProps);
40-
};
35+
classData.componentWillReceiveProps = function(nextProps) {
36+
var chart = this.state.chart;
37+
chart.destroy();
38+
this.initializeChart(nextProps);
39+
};
4140

42-
classData.initializeChart = function(nextProps) {
43-
var el = this.getDOMNode();
44-
var ctx = el.getContext("2d");
45-
var chart = new Chart(ctx)[chartType](nextProps.data, nextProps.options || {});
46-
this.state.chart = chart;
47-
};
41+
classData.initializeChart = function(nextProps) {
42+
var Chart = require('chart.js');
43+
var el = this.getDOMNode();
44+
var ctx = el.getContext("2d");
45+
var chart = new Chart(ctx)[chartType](nextProps.data, nextProps.options || {});
46+
this.state.chart = chart;
47+
};
4848

49-
var i;
50-
for (i=0; i<extras.length; i++) {
51-
extra(extras[i]);
52-
}
53-
for (i=0; i<methodNames.length; i++) {
54-
extra(methodNames[i]);
55-
}
49+
var i;
50+
for (i=0; i<extras.length; i++) {
51+
extra(extras[i]);
52+
}
53+
for (i=0; i<methodNames.length; i++) {
54+
extra(methodNames[i]);
5655
}
5756

5857
var React = require('react');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
},
2626
"homepage": "https://github.com/jhudson8/react-chartjs",
2727
"peerDependencies": {
28-
"react": "*"
28+
"react": "*",
29+
"chart.js": "*"
2930
},
3031
"devDependencies": {
3132
"uglify-js": "^2.4.16",

0 commit comments

Comments
 (0)