From a0ec7cabc7160e756b31aadbb8be1e0ec84d1579 Mon Sep 17 00:00:00 2001 From: Jer Date: Tue, 6 Dec 2016 19:40:05 -0600 Subject: [PATCH 1/2] made more of the datasets dynamic --- README.md | 1 + dist/react-chartjs-2.js | 7 ++++++ dist/react-chartjs-2.min.js | 2 +- lib/index.js | 7 ++++++ src/index.js | 45 ++++++++++++++++++++++--------------- 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index edf55408d..77ae9ef9a 100644 --- a/README.md +++ b/README.md @@ -177,3 +177,4 @@ MIT Licensed Copyright (c) 2016 Goran Udosic ## Contributors +Jeremy Ayerst [@jerairrest](https://github.com/jerairrest) diff --git a/dist/react-chartjs-2.js b/dist/react-chartjs-2.js index 26a272625..da31cb9cb 100644 --- a/dist/react-chartjs-2.js +++ b/dist/react-chartjs-2.js @@ -116,9 +116,16 @@ var ChartComponent = _react2.default.createClass({ nextData.forEach(function (dataset, sid) { if (currentData[sid] && currentData[sid].data) { currentData[sid].data.splice(nextData[sid].data.length); + dataset.data.forEach(function (point, pid) { currentData[sid].data[pid] = nextData[sid].data[pid]; }); + + delete dataset.data; + + currentData[sid] = _extends({ + data: currentData[sid].data + }, currentData[sid], dataset); } else { currentData[sid] = nextData[sid]; } diff --git a/dist/react-chartjs-2.min.js b/dist/react-chartjs-2.min.js index 1128d0c81..e6fc5f757 100644 --- a/dist/react-chartjs-2.min.js +++ b/dist/react-chartjs-2.min.js @@ -1 +1 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.index=t()}}(function(){return function t(e,n,r){function o(a,u){if(!n[a]){if(!e[a]){var c="function"==typeof require&&require;if(!u&&c)return c(a,!0);if(i)return i(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var f=n[a]={exports:{}};e[a][0].call(f.exports,function(t){var n=e[a][1][t];return o(n?n:t)},f,f.exports,t,e,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},shouldComponentUpdate:function(t,e){var n=["id","width","height","onElementsClick"],r=this._objectWithoutProperties(t,n),o=this._objectWithoutProperties(this.props,n);return!(0,_["default"])(r,o,{strict:!0})},componentWillUnmount:function(){this.chart_instance.destroy()},updateChart:function(){var t=this.props,e=t.data,n=t.options;if(this.chart_instance){n&&(this.chart_instance.options=h["default"].helpers.configMerge(this.chart_instance.options,n));var r=this.chart_instance.config.data.datasets,o=e.datasets;o.forEach(function(t,e){r[e]&&r[e].data?(r[e].data.splice(o[e].data.length),t.data.forEach(function(t,n){r[e].data[n]=o[e].data[n]})):r[e]=o[e]}),delete e.datasets,this.chart_instance.config.data=c({},this.chart_instance.config.data,e),this.chart_instance.update()}},renderChart:function(){var t=this.props,e=t.data,n=t.options,r=(t.legend,t.type),o=l["default"].findDOMNode(this);this.chart_instance=new h["default"](o,{type:r,data:e,options:n})},handleOnClick:function(t){var e=this.chart_instance,n=this.props,r=n.getDatasetAtEvent,o=n.getElementAtEvent,i=n.getElementsAtEvent,a=n.onElementsClick;r&&r(e.getDatasetAtEvent(t),t),o&&o(e.getElementAtEvent(t),t),i&&i(e.getElementsAtEvent(t),t),a&&a(e.getElementsAtEvent(t),t)},render:function(){var t=this.props,e=t.height,n=t.width;t.onElementsClick;return f["default"].createElement("canvas",{height:e,width:n,onClick:this.handleOnClick})}});n["default"]=b;n.Doughnut=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"doughnut"}))}}]),e}(f["default"].Component),n.Pie=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"pie"}))}}]),e}(f["default"].Component),n.Line=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"line"}))}}]),e}(f["default"].Component),n.Bar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bar"}))}}]),e}(f["default"].Component),n.HorizontalBar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"horizontalBar"}))}}]),e}(f["default"].Component),n.Radar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"radar"}))}}]),e}(f["default"].Component),n.Polar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"polarArea"}))}}]),e}(f["default"].Component),n.Bubble=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bubble"}))}}]),e}(f["default"].Component),n.defaults=h["default"].defaults;n.Chart=h["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils/deepEqual":2,"chart.js":void 0,"react-dom":void 0}],2:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=Object.prototype.hasOwnProperty,i=function(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e},a=function u(t,e){if(i(t,e))return!0;if("object"!==("undefined"==typeof t?"undefined":r(t))||null===t||"object"!==("undefined"==typeof e?"undefined":r(e))||null===e)return!1;for(var n=Object.keys(t),a=Object.keys(e),c=n.concat(a),s=0;s=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},shouldComponentUpdate:function(t,e){var n=["id","width","height","onElementsClick"],r=this._objectWithoutProperties(t,n),o=this._objectWithoutProperties(this.props,n);return!(0,_["default"])(r,o,{strict:!0})},componentWillUnmount:function(){this.chart_instance.destroy()},updateChart:function(){var t=this.props,e=t.data,n=t.options;if(this.chart_instance){n&&(this.chart_instance.options=h["default"].helpers.configMerge(this.chart_instance.options,n));var r=this.chart_instance.config.data.datasets,o=e.datasets;o.forEach(function(t,e){r[e]&&r[e].data?(r[e].data.splice(o[e].data.length),t.data.forEach(function(t,n){r[e].data[n]=o[e].data[n]}),delete t.data,r[e]=c({data:r[e].data},r[e],t)):r[e]=o[e]}),delete e.datasets,this.chart_instance.config.data=c({},this.chart_instance.config.data,e),this.chart_instance.update()}},renderChart:function(){var t=this.props,e=t.data,n=t.options,r=(t.legend,t.type),o=l["default"].findDOMNode(this);this.chart_instance=new h["default"](o,{type:r,data:e,options:n})},handleOnClick:function(t){var e=this.chart_instance,n=this.props,r=n.getDatasetAtEvent,o=n.getElementAtEvent,i=n.getElementsAtEvent,a=n.onElementsClick;r&&r(e.getDatasetAtEvent(t),t),o&&o(e.getElementAtEvent(t),t),i&&i(e.getElementsAtEvent(t),t),a&&a(e.getElementsAtEvent(t),t)},render:function(){var t=this.props,e=t.height,n=t.width;t.onElementsClick;return f["default"].createElement("canvas",{height:e,width:n,onClick:this.handleOnClick})}});n["default"]=b;n.Doughnut=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"doughnut"}))}}]),e}(f["default"].Component),n.Pie=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"pie"}))}}]),e}(f["default"].Component),n.Line=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"line"}))}}]),e}(f["default"].Component),n.Bar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bar"}))}}]),e}(f["default"].Component),n.HorizontalBar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"horizontalBar"}))}}]),e}(f["default"].Component),n.Radar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"radar"}))}}]),e}(f["default"].Component),n.Polar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"polarArea"}))}}]),e}(f["default"].Component),n.Bubble=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bubble"}))}}]),e}(f["default"].Component),n.defaults=h["default"].defaults;n.Chart=h["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils/deepEqual":2,"chart.js":void 0,"react-dom":void 0}],2:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=Object.prototype.hasOwnProperty,i=function(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e},a=function u(t,e){if(i(t,e))return!0;if("object"!==("undefined"==typeof t?"undefined":r(t))||null===t||"object"!==("undefined"==typeof e?"undefined":r(e))||null===e)return!1;for(var n=Object.keys(t),a=Object.keys(e),c=n.concat(a),s=0;s Date: Wed, 7 Dec 2016 08:07:27 -0600 Subject: [PATCH 2/2] got rid of the delete replaces with a spread --- dist/react-chartjs-2.js | 7 +++++-- dist/react-chartjs-2.min.js | 2 +- lib/index.js | 7 +++++-- src/index.js | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dist/react-chartjs-2.js b/dist/react-chartjs-2.js index da31cb9cb..31784b083 100644 --- a/dist/react-chartjs-2.js +++ b/dist/react-chartjs-2.js @@ -35,6 +35,8 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } +function _objectWithoutProperties2(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + var ChartComponent = _react2.default.createClass({ displayName: 'ChartComponent', @@ -121,11 +123,12 @@ var ChartComponent = _react2.default.createClass({ currentData[sid].data[pid] = nextData[sid].data[pid]; }); - delete dataset.data; + var _data = dataset.data, + otherProps = _objectWithoutProperties2(dataset, ['data']); currentData[sid] = _extends({ data: currentData[sid].data - }, currentData[sid], dataset); + }, currentData[sid], otherProps); } else { currentData[sid] = nextData[sid]; } diff --git a/dist/react-chartjs-2.min.js b/dist/react-chartjs-2.min.js index e6fc5f757..7ead8a9b3 100644 --- a/dist/react-chartjs-2.min.js +++ b/dist/react-chartjs-2.min.js @@ -1 +1 @@ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.index=t()}}(function(){return function t(e,n,r){function o(a,u){if(!n[a]){if(!e[a]){var c="function"==typeof require&&require;if(!u&&c)return c(a,!0);if(i)return i(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var f=n[a]={exports:{}};e[a][0].call(f.exports,function(t){var n=e[a][1][t];return o(n?n:t)},f,f.exports,t,e,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},shouldComponentUpdate:function(t,e){var n=["id","width","height","onElementsClick"],r=this._objectWithoutProperties(t,n),o=this._objectWithoutProperties(this.props,n);return!(0,_["default"])(r,o,{strict:!0})},componentWillUnmount:function(){this.chart_instance.destroy()},updateChart:function(){var t=this.props,e=t.data,n=t.options;if(this.chart_instance){n&&(this.chart_instance.options=h["default"].helpers.configMerge(this.chart_instance.options,n));var r=this.chart_instance.config.data.datasets,o=e.datasets;o.forEach(function(t,e){r[e]&&r[e].data?(r[e].data.splice(o[e].data.length),t.data.forEach(function(t,n){r[e].data[n]=o[e].data[n]}),delete t.data,r[e]=c({data:r[e].data},r[e],t)):r[e]=o[e]}),delete e.datasets,this.chart_instance.config.data=c({},this.chart_instance.config.data,e),this.chart_instance.update()}},renderChart:function(){var t=this.props,e=t.data,n=t.options,r=(t.legend,t.type),o=l["default"].findDOMNode(this);this.chart_instance=new h["default"](o,{type:r,data:e,options:n})},handleOnClick:function(t){var e=this.chart_instance,n=this.props,r=n.getDatasetAtEvent,o=n.getElementAtEvent,i=n.getElementsAtEvent,a=n.onElementsClick;r&&r(e.getDatasetAtEvent(t),t),o&&o(e.getElementAtEvent(t),t),i&&i(e.getElementsAtEvent(t),t),a&&a(e.getElementsAtEvent(t),t)},render:function(){var t=this.props,e=t.height,n=t.width;t.onElementsClick;return f["default"].createElement("canvas",{height:e,width:n,onClick:this.handleOnClick})}});n["default"]=b;n.Doughnut=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"doughnut"}))}}]),e}(f["default"].Component),n.Pie=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"pie"}))}}]),e}(f["default"].Component),n.Line=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"line"}))}}]),e}(f["default"].Component),n.Bar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bar"}))}}]),e}(f["default"].Component),n.HorizontalBar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"horizontalBar"}))}}]),e}(f["default"].Component),n.Radar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"radar"}))}}]),e}(f["default"].Component),n.Polar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"polarArea"}))}}]),e}(f["default"].Component),n.Bubble=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),u(e,[{key:"render",value:function(){var t=this;return f["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bubble"}))}}]),e}(f["default"].Component),n.defaults=h["default"].defaults;n.Chart=h["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils/deepEqual":2,"chart.js":void 0,"react-dom":void 0}],2:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=Object.prototype.hasOwnProperty,i=function(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e},a=function u(t,e){if(i(t,e))return!0;if("object"!==("undefined"==typeof t?"undefined":r(t))||null===t||"object"!==("undefined"==typeof e?"undefined":r(e))||null===e)return!1;for(var n=Object.keys(t),a=Object.keys(e),c=n.concat(a),s=0;s=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}Object.defineProperty(n,"__esModule",{value:!0}),n.Chart=n.defaults=n.Bubble=n.Polar=n.Radar=n.HorizontalBar=n.Bar=n.Line=n.Pie=n.Doughnut=void 0;var c=function(){function t(t,e){for(var n=0;n=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},shouldComponentUpdate:function(t,e){var n=["id","width","height","onElementsClick"],r=this._objectWithoutProperties(t,n),o=this._objectWithoutProperties(this.props,n);return!(0,b["default"])(r,o,{strict:!0})},componentWillUnmount:function(){this.chart_instance.destroy()},updateChart:function(){var t=this.props,e=t.data,n=t.options;if(this.chart_instance){n&&(this.chart_instance.options=y["default"].helpers.configMerge(this.chart_instance.options,n));var r=this.chart_instance.config.data.datasets,o=e.datasets;o.forEach(function(t,e){if(r[e]&&r[e].data){r[e].data.splice(o[e].data.length),t.data.forEach(function(t,n){r[e].data[n]=o[e].data[n]});var n=(t.data,u(t,["data"]));r[e]=f({data:r[e].data},r[e],n)}else r[e]=o[e]}),delete e.datasets,this.chart_instance.config.data=f({},this.chart_instance.config.data,e),this.chart_instance.update()}},renderChart:function(){var t=this.props,e=t.data,n=t.options,r=(t.legend,t.type),o=d["default"].findDOMNode(this);this.chart_instance=new y["default"](o,{type:r,data:e,options:n})},handleOnClick:function(t){var e=this.chart_instance,n=this.props,r=n.getDatasetAtEvent,o=n.getElementAtEvent,i=n.getElementsAtEvent,a=n.onElementsClick;r&&r(e.getDatasetAtEvent(t),t),o&&o(e.getElementAtEvent(t),t),i&&i(e.getElementsAtEvent(t),t),a&&a(e.getElementsAtEvent(t),t)},render:function(){var t=this.props,e=t.height,n=t.width;t.onElementsClick;return p["default"].createElement("canvas",{height:e,width:n,onClick:this.handleOnClick})}});n["default"]=v;n.Doughnut=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"doughnut"}))}}]),e}(p["default"].Component),n.Pie=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"pie"}))}}]),e}(p["default"].Component),n.Line=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"line"}))}}]),e}(p["default"].Component),n.Bar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bar"}))}}]),e}(p["default"].Component),n.HorizontalBar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"horizontalBar"}))}}]),e}(p["default"].Component),n.Radar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"radar"}))}}]),e}(p["default"].Component),n.Polar=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"polarArea"}))}}]),e}(p["default"].Component),n.Bubble=function(t){function e(){return o(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return a(e,t),c(e,[{key:"render",value:function(){var t=this;return p["default"].createElement(v,f({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bubble"}))}}]),e}(p["default"].Component),n.defaults=y["default"].defaults;n.Chart=y["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./utils/deepEqual":2,"chart.js":void 0,"react-dom":void 0}],2:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=Object.prototype.hasOwnProperty,i=function(t,e){return t===e?0!==t||1/t===1/e:t!==t&&e!==e},a=function u(t,e){if(i(t,e))return!0;if("object"!==("undefined"==typeof t?"undefined":r(t))||null===t||"object"!==("undefined"==typeof e?"undefined":r(e))||null===e)return!1;for(var n=Object.keys(t),a=Object.keys(e),c=n.concat(a),f=0;f= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + var ChartComponent = _react2.default.createClass({ displayName: 'ChartComponent', @@ -119,11 +121,12 @@ var ChartComponent = _react2.default.createClass({ currentData[sid].data[pid] = nextData[sid].data[pid]; }); - delete dataset.data; + var _data = dataset.data, + otherProps = _objectWithoutProperties2(dataset, ['data']); currentData[sid] = _extends({ data: currentData[sid].data - }, currentData[sid], dataset); + }, currentData[sid], otherProps); } else { currentData[sid] = nextData[sid]; } diff --git a/src/index.js b/src/index.js index 4b7068fc2..9dbc5756c 100644 --- a/src/index.js +++ b/src/index.js @@ -93,12 +93,12 @@ const ChartComponent = React.createClass({ currentData[sid].data[pid] = nextData[sid].data[pid]; }); - delete dataset.data; + const { data, ...otherProps } = dataset; currentData[sid] = { data: currentData[sid].data, ...currentData[sid], - ...dataset + ...otherProps } } else { currentData[sid] = nextData[sid];