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

Include chart.js library while initializing to fix window reference n… #143

Open
wants to merge 1 commit into
base: chartjs-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 26 additions & 35 deletions dist/react-chartjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,51 +130,41 @@ return /******/ (function(modules) { // webpackBootstrap
classData.componentWillReceiveProps = function(nextProps) {
var chart = this.state.chart;

// // Reset the array of datasets
chart.data.datasets.forEach(function(set, setIndex) {
set.data.forEach(function(val, pointIndex) {
set.data = [];
});
});

// // Reset the array of labels
chart.data.labels = [];

// Adds the datapoints from nextProps
nextProps.data.datasets.forEach(function(set, setIndex) {
set.data.forEach(function(val, pointIndex) {
chart.data.datasets[setIndex].data[pointIndex] = nextProps.data.datasets[setIndex].data[pointIndex];
if (nextProps.redraw) {
chart.destroy(); // Reset the array of datasets
this.initializeChart(nextProps);
} else {
// assign all of the properites from the next datasets to the current chart
nextProps.data.datasets.forEach(function(set, setIndex) {

var chartDataset = {};

for (var property in set) {
if (set.hasOwnProperty(property)) {
chartDataset[property] = set[property];
}
}

chart.data.datasets[setIndex] = chartDataset;
});
});

// Sets the labels from nextProps
nextProps.data.labels.forEach(function(val, labelIndex) {
chart.data.labels[labelIndex] = nextProps.data.labels[labelIndex];
});
chart.data.labels = nextProps.data.labels;

// Updates Chart with new data
chart.update();
chart.update();
}
};

classData.initializeChart = function(nextProps) {
var Chart = __webpack_require__(5);
var el = ReactDOM.findDOMNode(this);
var ctx = el.getContext("2d");
var type = (chartType === 'PolarArea') ? 'polarArea':chartType.toLowerCase();

if (chartType === 'PolarArea'){
var chart = new Chart(ctx, {
type: 'polarArea',
data: nextProps.data,
options: nextProps.options
});
} else {
var chart = new Chart(ctx, {
type: chartType.toLowerCase(),
data: nextProps.data,
options: nextProps.options
});
}
this.state.chart = chart;
this.state.chart = new Chart(ctx, {
type: type,
data: nextProps.data,
options: nextProps.options
});
};


Expand Down Expand Up @@ -202,6 +192,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
};


/***/ },
/* 3 */
/***/ function(module, exports) {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-chartjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

var React = require('react');
var ReactDOM = require('react-dom');
var Chart = require('chart.js');

module.exports = {
createClass: function(chartType, methodNames, dataKey) {
Expand Down Expand Up @@ -74,6 +73,7 @@ module.exports = {
};

classData.initializeChart = function(nextProps) {
var Chart = require('chart.js');
var el = ReactDOM.findDOMNode(this);
var ctx = el.getContext("2d");
var type = (chartType === 'PolarArea') ? 'polarArea':chartType.toLowerCase();
Expand Down