Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: danmolitor/react-chartjs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: malloc-fi/react-chartjs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Jun 12, 2016

  1. add support for redraw

    Nathan Dao committed Jun 12, 2016
    Copy the full SHA
    f465efc View commit details
Showing with 21 additions and 15 deletions.
  1. +21 −15 lib/core.js
36 changes: 21 additions & 15 deletions lib/core.js
Original file line number Diff line number Diff line change
@@ -48,25 +48,31 @@ module.exports = {
classData.componentWillReceiveProps = function(nextProps) {
var chart = this.state.chart;

// Adds the datapoints from nextProps
nextProps.data.datasets.forEach(function(set, setIndex) {
set.data.forEach(function(val, pointIndex) {
chart.data.datasets[setIndex].data[pointIndex] = val;
// Redraw chart if specified
if (nextProps.redraw) {
chart.destroy();
this.initializeChart(nextProps);
} else {
// Adds the datapoints from nextProps
nextProps.data.datasets.forEach(function(set, setIndex) {
set.data.forEach(function(val, pointIndex) {
chart.data.datasets[setIndex].data[pointIndex] = val;
});
});
});

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

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

// Initializing the chart is a bit different, because in Chart.js 2.0
// they now use lowercase letters for the names except for Polar-Area.
// This takes care of that issue.
// Initializing the chart is a bit different, because in Chart.js 2.0
// they now use lowercase letters for the names except for Polar-Area.
// This takes care of that issue.

classData.initializeChart = function(nextProps) {
var Chart = require('chart.js');
@@ -112,4 +118,4 @@ module.exports = {

return React.createClass(classData);
}
};
};