From eaa311783e0abc5f19a381757b2a6deb0254627f Mon Sep 17 00:00:00 2001 From: Arjun S Kumar Date: Tue, 23 Aug 2016 16:57:28 +0530 Subject: [PATCH] Include chart.js library while initializing to fix window reference not found bug --- dist/react-chartjs.js | 61 +++++++++++++++++---------------------- dist/react-chartjs.min.js | 2 +- lib/core.js | 2 +- 3 files changed, 28 insertions(+), 37 deletions(-) diff --git a/dist/react-chartjs.js b/dist/react-chartjs.js index ddee080..a2816a6 100644 --- a/dist/react-chartjs.js +++ b/dist/react-chartjs.js @@ -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 + }); }; @@ -202,6 +192,7 @@ return /******/ (function(modules) { // webpackBootstrap } }; + /***/ }, /* 3 */ /***/ function(module, exports) { diff --git a/dist/react-chartjs.min.js b/dist/react-chartjs.min.js index d45285f..7805565 100644 --- a/dist/react-chartjs.min.js +++ b/dist/react-chartjs.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("react-dom"),require("Chartjs")):"function"==typeof define&&define.amd?define(["react","react-dom","Chartjs"],e):"object"==typeof exports?exports["react-chartjs"]=e(require("react"),require("react-dom"),require("Chartjs")):t["react-chartjs"]=e(t.React,t.ReactDOM,t.Chart)}(this,function(t,e,a){return function(t){function e(r){if(a[r])return a[r].exports;var n=a[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var a={};return e.m=t,e.c=a,e.p="",e(0)}([function(t,e,a){t.exports={Bar:a(1),Bubble:a(6),Doughnut:a(7),Line:a(8),Pie:a(9),PolarArea:a(10),Radar:a(11),Scatter:a(12),createClass:a(2).createClass}},function(t,e,a){var r=a(2);t.exports=r.createClass("Bar",["getBarsAtEvent"])},function(t,e,a){var r=a(3),n=a(4),s=a(5);t.exports={createClass:function(t,e,a){function o(t){i[t]=function(){return this.state.chart[t].apply(this.state.chart,arguments)}}var i={displayName:t+"Chart",getInitialState:function(){return{}},render:function(){var t={ref:"canvass"};for(var e in this.props)this.props.hasOwnProperty(e)&&"data"!==e&&"options"!==e&&(t[e]=this.props[e]);return r.createElement("canvas",t)}},c=["clear","stop","resize","toBase64Image","generateLegend","update","addData","removeData"];i.componentDidMount=function(){this.initializeChart(this.props)},i.componentWillUnmount=function(){var t=this.state.chart;t.destroy()},i.componentWillReceiveProps=function(t){var e=this.state.chart;t.redraw?(e.destroy(),this.initializeChart(t)):(t.data.datasets.forEach(function(t,a){var r=e.data.datasets[a];for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n])}),e.data.labels=t.data.labels,e.update())},i.initializeChart=function(e){var a=n.findDOMNode(this),r=a.getContext("2d"),o="PolarArea"===t?"polarArea":t.toLowerCase();this.state.chart=new s(r,{type:o,data:e.data,options:e.options})},i.getChart=function(){return this.state.chart},i.getCanvass=function(){return this.refs.canvass},i.getCanvas=i.getCanvass;var u;for(u=0;u