react-chartjs-2
Advanced tools
Comparing version 2.0.0 to 2.0.5
@@ -1,1 +0,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.reactChartjs2=t()}}(function(){return function t(e,n,r){function o(i,u){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!u&&c)return c(i,!0);if(a)return a(i,!0);var s=new Error("Cannot find module '"+i+"'");throw s.code="MODULE_NOT_FOUND",s}var f=n[i]={exports:{}};e[i][0].call(f.exports,function(t){var n=e[i][1][t];return o(n?n:t)},f,f.exports,t,e,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(t,e,n){(function(t){function r(t,e){for(var n=-1,r=t?t.length:0;++n<r;)if(e(t[n],n,t))return!0;return!1}function o(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}function a(t){return function(e){return t(e)}}function i(t,e){return null==t?void 0:t[e]}function u(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(n){}return e}function c(t){var e=-1,n=Array(t.size);return t.forEach(function(t,r){n[++e]=[r,t]}),n}function s(t,e){return function(n){return t(e(n))}}function f(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}function l(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function p(){this.__data__=je?je(null):{}}function h(t){return this.has(t)&&delete this.__data__[t]}function d(t){var e=this.__data__;if(je){var n=e[t];return n===ht?void 0:n}return se.call(e,t)?e[t]:void 0}function _(t){var e=this.__data__;return je?void 0!==e[t]:se.call(e,t)}function y(t,e){var n=this.__data__;return n[t]=je&&void 0===e?ht:e,this}function v(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function b(){this.__data__=[]}function g(t){var e=this.__data__,n=F(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():_e.call(e,n,1),!0}function w(t){var e=this.__data__,n=F(e,t);return n<0?void 0:e[n][1]}function m(t){return F(this.__data__,t)>-1}function j(t,e){var n=this.__data__,r=F(n,t);return r<0?n.push([t,e]):n[r][1]=e,this}function O(t){var e=-1,n=t?t.length:0;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function E(){this.__data__={hash:new l,map:new(be||v),string:new l}}function P(t){return K(this,t)["delete"](t)}function A(t){return K(this,t).get(t)}function k(t){return K(this,t).has(t)}function C(t,e){return K(this,t).set(t,e),this}function D(t){var e=-1,n=t?t.length:0;for(this.__data__=new O;++e<n;)this.add(t[e])}function T(t){return this.__data__.set(t,ht),this}function x(t){return this.__data__.has(t)}function M(t){this.__data__=new v(t)}function z(){this.__data__=new v}function B(t){return this.__data__["delete"](t)}function R(t){return this.__data__.get(t)}function S(t){return this.__data__.has(t)}function U(t,e){var n=this.__data__;if(n instanceof v){var r=n.__data__;if(!be||r.length<pt-1)return r.push([t,e]),this;n=this.__data__=new O(r)}return n.set(t,e),this}function q(t,e){var n=xe(t)||rt(t)?o(t.length,String):[],r=n.length,a=!!r;for(var i in t)!e&&!se.call(t,i)||a&&("length"==i||X(i,r))||n.push(i);return n}function F(t,e){for(var n=t.length;n--;)if(nt(t[n][0],e))return n;return-1}function L(t){return fe.call(t)}function $(t,e,n,r,o){return t===e||(null==t||null==e||!st(t)&&!ft(e)?t!==t&&e!==e:I(t,e,$,n,r,o))}function I(t,e,n,r,o,a){var i=xe(t),c=xe(e),s=bt,f=bt;i||(s=Te(t),s=s==vt?At:s),c||(f=Te(e),f=f==vt?At:f);var l=s==At&&!u(t),p=f==At&&!u(e),h=s==f;if(h&&!l)return a||(a=new M),i||Me(t)?V(t,e,n,r,o,a):G(t,e,s,n,r,o,a);if(!(o&_t)){var d=l&&se.call(t,"__wrapped__"),_=p&&se.call(e,"__wrapped__");if(d||_){var y=d?t.value():t,v=_?e.value():e;return a||(a=new M),n(y,v,r,o,a)}}return!!h&&(a||(a=new M),J(t,e,n,r,o,a))}function N(t){if(!st(t)||Z(t))return!1;var e=ut(t)||u(t)?le:Ht;return e.test(et(t))}function W(t){return ft(t)&&ct(t.length)&&!!Gt[fe.call(t)]}function H(t){if(!tt(t))return ye(t);var e=[];for(var n in Object(t))se.call(t,n)&&"constructor"!=n&&e.push(n);return e}function V(t,e,n,o,a,i){var u=a&_t,c=t.length,s=e.length;if(c!=s&&!(u&&s>c))return!1;var f=i.get(t);if(f&&i.get(e))return f==e;var l=-1,p=!0,h=a&dt?new D:void 0;for(i.set(t,e),i.set(e,t);++l<c;){var d=t[l],_=e[l];if(o)var y=u?o(_,d,l,e,t,i):o(d,_,l,t,e,i);if(void 0!==y){if(y)continue;p=!1;break}if(h){if(!r(e,function(t,e){if(!h.has(e)&&(d===t||n(d,t,o,a,i)))return h.add(e)})){p=!1;break}}else if(d!==_&&!n(d,_,o,a,i)){p=!1;break}}return i["delete"](t),i["delete"](e),p}function G(t,e,n,r,o,a,i){switch(n){case Bt:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case zt:return!(t.byteLength!=e.byteLength||!r(new he(t),new he(e)));case gt:case wt:case Pt:return nt(+t,+e);case mt:return t.name==e.name&&t.message==e.message;case Ct:case Tt:return t==e+"";case Et:var u=c;case Dt:var s=a&_t;if(u||(u=f),t.size!=e.size&&!s)return!1;var l=i.get(t);if(l)return l==e;a|=dt,i.set(t,e);var p=V(u(t),u(e),r,o,a,i);return i["delete"](t),p;case xt:if(De)return De.call(t)==De.call(e)}return!1}function J(t,e,n,r,o,a){var i=o&_t,u=lt(t),c=u.length,s=lt(e),f=s.length;if(c!=f&&!i)return!1;for(var l=c;l--;){var p=u[l];if(!(i?p in e:se.call(e,p)))return!1}var h=a.get(t);if(h&&a.get(e))return h==e;var d=!0;a.set(t,e),a.set(e,t);for(var _=i;++l<c;){p=u[l];var y=t[p],v=e[p];if(r)var b=i?r(v,y,p,e,t,a):r(y,v,p,t,e,a);if(!(void 0===b?y===v||n(y,v,r,o,a):b)){d=!1;break}_||(_="constructor"==p)}if(d&&!_){var g=t.constructor,w=e.constructor;g!=w&&"constructor"in t&&"constructor"in e&&!("function"==typeof g&&g instanceof g&&"function"==typeof w&&w instanceof w)&&(d=!1)}return a["delete"](t),a["delete"](e),d}function K(t,e){var n=t.__data__;return Y(e)?n["string"==typeof e?"string":"hash"]:n.map}function Q(t,e){var n=i(t,e);return N(n)?n:void 0}function X(t,e){return e=null==e?yt:e,!!e&&("number"==typeof t||Vt.test(t))&&t>-1&&t%1==0&&t<e}function Y(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}function Z(t){return!!ue&&ue in t}function tt(t){var e=t&&t.constructor,n="function"==typeof e&&e.prototype||ae;return t===n}function et(t){if(null!=t){try{return ce.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function nt(t,e){return t===e||t!==t&&e!==e}function rt(t){return at(t)&&se.call(t,"callee")&&(!de.call(t,"callee")||fe.call(t)==vt)}function ot(t){return null!=t&&ct(t.length)&&!ut(t)}function at(t){return ft(t)&&ot(t)}function it(t,e){return $(t,e)}function ut(t){var e=st(t)?fe.call(t):"";return e==jt||e==Ot}function ct(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=yt}function st(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function ft(t){return!!t&&"object"==typeof t}function lt(t){return ot(t)?q(t):H(t)}var pt=200,ht="__lodash_hash_undefined__",dt=1,_t=2,yt=9007199254740991,vt="[object Arguments]",bt="[object Array]",gt="[object Boolean]",wt="[object Date]",mt="[object Error]",jt="[object Function]",Ot="[object GeneratorFunction]",Et="[object Map]",Pt="[object Number]",At="[object Object]",kt="[object Promise]",Ct="[object RegExp]",Dt="[object Set]",Tt="[object String]",xt="[object Symbol]",Mt="[object WeakMap]",zt="[object ArrayBuffer]",Bt="[object DataView]",Rt="[object Float32Array]",St="[object Float64Array]",Ut="[object Int8Array]",qt="[object Int16Array]",Ft="[object Int32Array]",Lt="[object Uint8Array]",$t="[object Uint8ClampedArray]",It="[object Uint16Array]",Nt="[object Uint32Array]",Wt=/[\\^$.*+?()[\]{}|]/g,Ht=/^\[object .+?Constructor\]$/,Vt=/^(?:0|[1-9]\d*)$/,Gt={};Gt[Rt]=Gt[St]=Gt[Ut]=Gt[qt]=Gt[Ft]=Gt[Lt]=Gt[$t]=Gt[It]=Gt[Nt]=!0,Gt[vt]=Gt[bt]=Gt[zt]=Gt[gt]=Gt[Bt]=Gt[wt]=Gt[mt]=Gt[jt]=Gt[Et]=Gt[Pt]=Gt[At]=Gt[Ct]=Gt[Dt]=Gt[Tt]=Gt[Mt]=!1;var Jt="object"==typeof t&&t&&t.Object===Object&&t,Kt="object"==typeof self&&self&&self.Object===Object&&self,Qt=Jt||Kt||Function("return this")(),Xt="object"==typeof n&&n&&!n.nodeType&&n,Yt=Xt&&"object"==typeof e&&e&&!e.nodeType&&e,Zt=Yt&&Yt.exports===Xt,te=Zt&&Jt.process,ee=function(){try{return te&&te.binding("util")}catch(t){}}(),ne=ee&&ee.isTypedArray,re=Array.prototype,oe=Function.prototype,ae=Object.prototype,ie=Qt["__core-js_shared__"],ue=function(){var t=/[^.]+$/.exec(ie&&ie.keys&&ie.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),ce=oe.toString,se=ae.hasOwnProperty,fe=ae.toString,le=RegExp("^"+ce.call(se).replace(Wt,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),pe=Qt.Symbol,he=Qt.Uint8Array,de=ae.propertyIsEnumerable,_e=re.splice,ye=s(Object.keys,Object),ve=Q(Qt,"DataView"),be=Q(Qt,"Map"),ge=Q(Qt,"Promise"),we=Q(Qt,"Set"),me=Q(Qt,"WeakMap"),je=Q(Object,"create"),Oe=et(ve),Ee=et(be),Pe=et(ge),Ae=et(we),ke=et(me),Ce=pe?pe.prototype:void 0,De=Ce?Ce.valueOf:void 0;l.prototype.clear=p,l.prototype["delete"]=h,l.prototype.get=d,l.prototype.has=_,l.prototype.set=y,v.prototype.clear=b,v.prototype["delete"]=g,v.prototype.get=w,v.prototype.has=m,v.prototype.set=j,O.prototype.clear=E,O.prototype["delete"]=P,O.prototype.get=A,O.prototype.has=k,O.prototype.set=C,D.prototype.add=D.prototype.push=T,D.prototype.has=x,M.prototype.clear=z,M.prototype["delete"]=B,M.prototype.get=R,M.prototype.has=S,M.prototype.set=U;var Te=L;(ve&&Te(new ve(new ArrayBuffer(1)))!=Bt||be&&Te(new be)!=Et||ge&&Te(ge.resolve())!=kt||we&&Te(new we)!=Dt||me&&Te(new me)!=Mt)&&(Te=function(t){var e=fe.call(t),n=e==At?t.constructor:void 0,r=n?et(n):void 0;if(r)switch(r){case Oe:return Bt;case Ee:return Et;case Pe:return kt;case Ae:return Dt;case ke:return Mt}return e});var xe=Array.isArray,Me=ne?a(ne):W;e.exports=it}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(t,e,n){(function(e){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}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=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),f="undefined"!=typeof window?window.React:"undefined"!=typeof e?e.React:null,l=r(f),p="undefined"!=typeof window?window.ReactDOM:"undefined"!=typeof e?e.ReactDOM:null,h=r(p),d="undefined"!=typeof window?window.Chart:"undefined"!=typeof e?e.Chart:null,_=r(d),y=t("lodash.isequal"),v=r(y),b=function(t){function e(){var t,n,r,o;a(this,e);for(var u=arguments.length,c=Array(u),s=0;s<u;s++)c[s]=arguments[s];return n=r=i(this,(t=e.__proto__||Object.getPrototypeOf(e)).call.apply(t,[this].concat(c))),r.handleOnClick=function(t){var e=r.chart_instance,n=r.props,o=n.getDatasetAtEvent,a=n.getElementAtEvent,i=n.getElementsAtEvent,u=n.onElementsClick;o&&o(e.getDatasetAtEvent(t),t),a&&a(e.getElementAtEvent(t),t),i&&i(e.getElementsAtEvent(t),t),u&&u(e.getElementsAtEvent(t),t)},o=n,i(r,o)}return u(e,t),s(e,[{key:"componentWillMount",value:function(){this.chart_instance=void 0}},{key:"componentDidMount",value:function(){this.renderChart()}},{key:"componentDidUpdate",value:function(){return this.props.redraw?(this.chart_instance.destroy(),void this.renderChart()):void this.updateChart()}},{key:"shouldComponentUpdate",value:function(t){var e=this.props,n=(e.redraw,e.type),r=e.options,o=e.legend,a=e.height,i=e.width;return t.redraw===!0||(a!==t.height||i!==t.width||(n!==t.type||(!(0,v["default"])(o,t.legend)||(!(0,v["default"])(r,t.options)||!(0,v["default"])(this.shadowDataProp,t.data)))))}},{key:"componentWillUnmount",value:function(){this.chart_instance.destroy()}},{key:"memoizeDataProps",value:function(){var t=this.props.data;t&&(this.shadowDataProp=c({},t,{datasets:t.datasets&&t.datasets.map(function(t){return Object.assign({},t)})}))}},{key:"updateChart",value:function(){var t=this.props,e=t.data,n=t.options;if(this.memoizeDataProps(),this.chart_instance){n&&(this.chart_instance.options=_["default"].helpers.configMerge(this.chart_instance.options,n));var r=this.chart_instance.config.data&&this.chart_instance.config.data.datasets||[],a=e.datasets||[];a.forEach(function(t,e){if(r[e]&&r[e].data){r[e].data.splice(a[e].data.length),t.data.forEach(function(t,n){r[e].data[n]=a[e].data[n]});var n=(t.data,o(t,["data"]));r[e]=c({data:r[e].data},r[e],n)}else r[e]=a[e]});var i=(e.datasets,o(e,["datasets"]));this.chart_instance.config.data=c({},this.chart_instance.config.data,i),this.chart_instance.update()}}},{key:"renderChart",value:function(){var t=this.props,e=t.data,n=t.options,r=(t.legend,t.type),o=(t.redraw,h["default"].findDOMNode(this));this.memoizeDataProps(),this.chart_instance=new _["default"](o,{type:r,data:e,options:n})}},{key:"render",value:function(){var t=this.props,e=t.height,n=t.width;t.onElementsClick;return l["default"].createElement("canvas",{height:e,width:n,onClick:this.handleOnClick})}}]),e}(l["default"].Component);b.propTypes={data:f.PropTypes.object.isRequired,getDatasetAtEvent:f.PropTypes.func,getElementAtEvent:f.PropTypes.func,getElementsAtEvent:f.PropTypes.func,height:f.PropTypes.number,legend:f.PropTypes.object,onElementsClick:f.PropTypes.func,options:f.PropTypes.object,redraw:f.PropTypes.bool,type:f.PropTypes.oneOf(["doughnut","pie","line","bar","horizontalBar","radar","polarArea","bubble"]),width:f.PropTypes.number},b.defaultProps={legend:{display:!0,position:"bottom"},type:"doughnut",height:150,width:300,redraw:!1,options:{}},n["default"]=b;n.Doughnut=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"doughnut"}))}}]),e}(l["default"].Component),n.Pie=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"pie"}))}}]),e}(l["default"].Component),n.Line=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"line"}))}}]),e}(l["default"].Component),n.Bar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bar"}))}}]),e}(l["default"].Component),n.HorizontalBar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"horizontalBar"}))}}]),e}(l["default"].Component),n.Radar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"radar"}))}}]),e}(l["default"].Component),n.Polar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"polarArea"}))}}]),e}(l["default"].Component),n.Bubble=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bubble"}))}}]),e}(l["default"].Component),n.defaults=_["default"].defaults;n.Chart=_["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"lodash.isequal":1}]},{},[2])(2)}); | ||
!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.reactChartjs2=t()}}(function(){return function t(e,n,r){function o(i,u){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!u&&c)return c(i,!0);if(a)return a(i,!0);var s=new Error("Cannot find module '"+i+"'");throw s.code="MODULE_NOT_FOUND",s}var f=n[i]={exports:{}};e[i][0].call(f.exports,function(t){var n=e[i][1][t];return o(n?n:t)},f,f.exports,t,e,n,r)}return n[i].exports}for(var a="function"==typeof require&&require,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(t,e,n){(function(t){function r(t,e){for(var n=-1,r=null==t?0:t.length,o=0,a=[];++n<r;){var i=t[n];e(i,n,t)&&(a[o++]=i)}return a}function o(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}function a(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1}function i(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}function u(t){return function(e){return t(e)}}function c(t,e){return t.has(e)}function s(t,e){return null==t?void 0:t[e]}function f(t){var e=-1,n=Array(t.size);return t.forEach(function(t,r){n[++e]=[r,t]}),n}function l(t,e){return function(n){return t(e(n))}}function p(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}function h(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function d(){this.__data__=Ue?Ue(null):{},this.size=0}function y(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}function _(t){var e=this.__data__;if(Ue){var n=e[t];return n===wt?void 0:n}return ge.call(e,t)?e[t]:void 0}function v(t){var e=this.__data__;return Ue?void 0!==e[t]:ge.call(e,t)}function b(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=Ue&&void 0===e?wt:e,this}function g(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function w(){this.__data__=[],this.size=0}function j(t){var e=this.__data__,n=$(e,t);if(n<0)return!1;var r=e.length-1;return n==r?e.pop():ke.call(e,n,1),--this.size,!0}function m(t){var e=this.__data__,n=$(e,t);return n<0?void 0:e[n][1]}function O(t){return $(this.__data__,t)>-1}function P(t,e){var n=this.__data__,r=$(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this}function E(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function A(){this.size=0,this.__data__={hash:new h,map:new(Me||g),string:new h}}function k(t){var e=tt(this,t)["delete"](t);return this.size-=e?1:0,e}function z(t){return tt(this,t).get(t)}function C(t){return tt(this,t).has(t)}function D(t,e){var n=tt(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this}function T(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new E;++e<n;)this.add(t[e])}function x(t){return this.__data__.set(t,wt),this}function M(t){return this.__data__.has(t)}function B(t){var e=this.__data__=new g(t);this.size=e.size}function S(){this.__data__=new g,this.size=0}function R(t){var e=this.__data__,n=e["delete"](t);return this.size=e.size,n}function U(t){return this.__data__.get(t)}function F(t){return this.__data__.has(t)}function L(t,e){var n=this.__data__;if(n instanceof g){var r=n.__data__;if(!Me||r.length<gt-1)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new E(r)}return n.set(t,e),this.size=n.size,this}function q(t,e){var n=Je(t),r=!n&&Ge(t),o=!n&&!r&&Ke(t),a=!n&&!r&&!o&&Qe(t),u=n||r||o||a,c=u?i(t.length,String):[],s=c.length;for(var f in t)!e&&!ge.call(t,f)||u&&("length"==f||o&&("offset"==f||"parent"==f)||a&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||rt(f,s))||c.push(f);return c}function $(t,e){for(var n=t.length;n--;)if(st(t[n][0],e))return n;return-1}function N(t,e,n){var r=e(t);return Je(t)?r:o(r,n(t))}function I(t){return null==t?void 0===t?Nt:Bt:ze&&ze in Object(t)?nt(t):ut(t)}function W(t){return yt(t)&&I(t)==Pt}function H(t,e,n,r,o){return t===e||(null==t||null==e||!yt(t)&&!yt(e)?t!==t&&e!==e:V(t,e,n,r,H,o))}function V(t,e,n,r,o,a){var i=Je(t),u=Je(e),c=i?Et:Ve(t),s=u?Et:Ve(e);c=c==Pt?St:c,s=s==Pt?St:s;var f=c==St,l=s==St,p=c==s;if(p&&Ke(t)){if(!Ke(e))return!1;i=!0,f=!1}if(p&&!f)return a||(a=new B),i||Qe(t)?Q(t,e,n,r,o,a):X(t,e,c,n,r,o,a);if(!(n&jt)){var h=f&&ge.call(t,"__wrapped__"),d=l&&ge.call(e,"__wrapped__");if(h||d){var y=h?t.value():t,_=d?e.value():e;return a||(a=new B),o(y,_,n,r,a)}}return!!p&&(a||(a=new B),Y(t,e,n,r,o,a))}function G(t){if(!dt(t)||at(t))return!1;var e=pt(t)?me:ne;return e.test(ct(t))}function J(t){return yt(t)&&ht(t.length)&&!!oe[I(t)]}function K(t){if(!it(t))return Te(t);var e=[];for(var n in Object(t))ge.call(t,n)&&"constructor"!=n&&e.push(n);return e}function Q(t,e,n,r,o,i){var u=n&jt,s=t.length,f=e.length;if(s!=f&&!(u&&f>s))return!1;var l=i.get(t);if(l&&i.get(e))return l==e;var p=-1,h=!0,d=n&mt?new T:void 0;for(i.set(t,e),i.set(e,t);++p<s;){var y=t[p],_=e[p];if(r)var v=u?r(_,y,p,e,t,i):r(y,_,p,t,e,i);if(void 0!==v){if(v)continue;h=!1;break}if(d){if(!a(e,function(t,e){if(!c(d,e)&&(y===t||o(y,t,n,r,i)))return d.push(e)})){h=!1;break}}else if(y!==_&&!o(y,_,n,r,i)){h=!1;break}}return i["delete"](t),i["delete"](e),h}function X(t,e,n,r,o,a,i){switch(n){case Ht:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Wt:return!(t.byteLength!=e.byteLength||!a(new Ee(t),new Ee(e)));case kt:case zt:case Mt:return st(+t,+e);case Ct:return t.name==e.name&&t.message==e.message;case Ft:case qt:return t==e+"";case xt:var u=f;case Lt:var c=r&jt;if(u||(u=p),t.size!=e.size&&!c)return!1;var s=i.get(t);if(s)return s==e;r|=mt,i.set(t,e);var l=Q(u(t),u(e),r,o,a,i);return i["delete"](t),l;case $t:if(We)return We.call(t)==We.call(e)}return!1}function Y(t,e,n,r,o,a){var i=n&jt,u=Z(t),c=u.length,s=Z(e),f=s.length;if(c!=f&&!i)return!1;for(var l=c;l--;){var p=u[l];if(!(i?p in e:ge.call(e,p)))return!1}var h=a.get(t);if(h&&a.get(e))return h==e;var d=!0;a.set(t,e),a.set(e,t);for(var y=i;++l<c;){p=u[l];var _=t[p],v=e[p];if(r)var b=i?r(v,_,p,e,t,a):r(_,v,p,t,e,a);if(!(void 0===b?_===v||o(_,v,n,r,a):b)){d=!1;break}y||(y="constructor"==p)}if(d&&!y){var g=t.constructor,w=e.constructor;g!=w&&"constructor"in t&&"constructor"in e&&!("function"==typeof g&&g instanceof g&&"function"==typeof w&&w instanceof w)&&(d=!1)}return a["delete"](t),a["delete"](e),d}function Z(t){return N(t,_t,He)}function tt(t,e){var n=t.__data__;return ot(e)?n["string"==typeof e?"string":"hash"]:n.map}function et(t,e){var n=s(t,e);return G(n)?n:void 0}function nt(t){var e=ge.call(t,ze),n=t[ze];try{t[ze]=void 0;var r=!0}catch(o){}var a=je.call(t);return r&&(e?t[ze]=n:delete t[ze]),a}function rt(t,e){return e=null==e?Ot:e,!!e&&("number"==typeof t||re.test(t))&&t>-1&&t%1==0&&t<e}function ot(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t}function at(t){return!!we&&we in t}function it(t){var e=t&&t.constructor,n="function"==typeof e&&e.prototype||_e;return t===n}function ut(t){return je.call(t)}function ct(t){if(null!=t){try{return be.call(t)}catch(e){}try{return t+""}catch(e){}}return""}function st(t,e){return t===e||t!==t&&e!==e}function ft(t){return null!=t&&ht(t.length)&&!pt(t)}function lt(t,e){return H(t,e)}function pt(t){if(!dt(t))return!1;var e=I(t);return e==Dt||e==Tt||e==At||e==Ut}function ht(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=Ot}function dt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function yt(t){return null!=t&&"object"==typeof t}function _t(t){return ft(t)?q(t):K(t)}function vt(){return[]}function bt(){return!1}var gt=200,wt="__lodash_hash_undefined__",jt=1,mt=2,Ot=9007199254740991,Pt="[object Arguments]",Et="[object Array]",At="[object AsyncFunction]",kt="[object Boolean]",zt="[object Date]",Ct="[object Error]",Dt="[object Function]",Tt="[object GeneratorFunction]",xt="[object Map]",Mt="[object Number]",Bt="[object Null]",St="[object Object]",Rt="[object Promise]",Ut="[object Proxy]",Ft="[object RegExp]",Lt="[object Set]",qt="[object String]",$t="[object Symbol]",Nt="[object Undefined]",It="[object WeakMap]",Wt="[object ArrayBuffer]",Ht="[object DataView]",Vt="[object Float32Array]",Gt="[object Float64Array]",Jt="[object Int8Array]",Kt="[object Int16Array]",Qt="[object Int32Array]",Xt="[object Uint8Array]",Yt="[object Uint8ClampedArray]",Zt="[object Uint16Array]",te="[object Uint32Array]",ee=/[\\^$.*+?()[\]{}|]/g,ne=/^\[object .+?Constructor\]$/,re=/^(?:0|[1-9]\d*)$/,oe={};oe[Vt]=oe[Gt]=oe[Jt]=oe[Kt]=oe[Qt]=oe[Xt]=oe[Yt]=oe[Zt]=oe[te]=!0,oe[Pt]=oe[Et]=oe[Wt]=oe[kt]=oe[Ht]=oe[zt]=oe[Ct]=oe[Dt]=oe[xt]=oe[Mt]=oe[St]=oe[Ft]=oe[Lt]=oe[qt]=oe[It]=!1;var ae="object"==typeof t&&t&&t.Object===Object&&t,ie="object"==typeof self&&self&&self.Object===Object&&self,ue=ae||ie||Function("return this")(),ce="object"==typeof n&&n&&!n.nodeType&&n,se=ce&&"object"==typeof e&&e&&!e.nodeType&&e,fe=se&&se.exports===ce,le=fe&&ae.process,pe=function(){try{return le&&le.binding&&le.binding("util")}catch(t){}}(),he=pe&&pe.isTypedArray,de=Array.prototype,ye=Function.prototype,_e=Object.prototype,ve=ue["__core-js_shared__"],be=ye.toString,ge=_e.hasOwnProperty,we=function(){var t=/[^.]+$/.exec(ve&&ve.keys&&ve.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),je=_e.toString,me=RegExp("^"+be.call(ge).replace(ee,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Oe=fe?ue.Buffer:void 0,Pe=ue.Symbol,Ee=ue.Uint8Array,Ae=_e.propertyIsEnumerable,ke=de.splice,ze=Pe?Pe.toStringTag:void 0,Ce=Object.getOwnPropertySymbols,De=Oe?Oe.isBuffer:void 0,Te=l(Object.keys,Object),xe=et(ue,"DataView"),Me=et(ue,"Map"),Be=et(ue,"Promise"),Se=et(ue,"Set"),Re=et(ue,"WeakMap"),Ue=et(Object,"create"),Fe=ct(xe),Le=ct(Me),qe=ct(Be),$e=ct(Se),Ne=ct(Re),Ie=Pe?Pe.prototype:void 0,We=Ie?Ie.valueOf:void 0;h.prototype.clear=d,h.prototype["delete"]=y,h.prototype.get=_,h.prototype.has=v,h.prototype.set=b,g.prototype.clear=w,g.prototype["delete"]=j,g.prototype.get=m,g.prototype.has=O,g.prototype.set=P,E.prototype.clear=A,E.prototype["delete"]=k,E.prototype.get=z,E.prototype.has=C,E.prototype.set=D,T.prototype.add=T.prototype.push=x,T.prototype.has=M,B.prototype.clear=S,B.prototype["delete"]=R,B.prototype.get=U,B.prototype.has=F,B.prototype.set=L;var He=Ce?function(t){return null==t?[]:(t=Object(t),r(Ce(t),function(e){return Ae.call(t,e)}))}:vt,Ve=I;(xe&&Ve(new xe(new ArrayBuffer(1)))!=Ht||Me&&Ve(new Me)!=xt||Be&&Ve(Be.resolve())!=Rt||Se&&Ve(new Se)!=Lt||Re&&Ve(new Re)!=It)&&(Ve=function(t){var e=I(t),n=e==St?t.constructor:void 0,r=n?ct(n):"";if(r)switch(r){case Fe:return Ht;case Le:return xt;case qe:return Rt;case $e:return Lt;case Ne:return It}return e});var Ge=W(function(){return arguments}())?W:function(t){return yt(t)&&ge.call(t,"callee")&&!Ae.call(t,"callee")},Je=Array.isArray,Ke=De||bt,Qe=he?u(he):J;e.exports=lt}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(t,e,n){(function(e){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function u(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}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=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}(),f="undefined"!=typeof window?window.React:"undefined"!=typeof e?e.React:null,l=r(f),p="undefined"!=typeof window?window.ReactDOM:"undefined"!=typeof e?e.ReactDOM:null,h=r(p),d="undefined"!=typeof window?window.Chart:"undefined"!=typeof e?e.Chart:null,y=r(d),_=t("lodash.isequal"),v=r(_),b=function(t){function e(){var t,n,r,o;a(this,e);for(var u=arguments.length,c=Array(u),s=0;s<u;s++)c[s]=arguments[s];return n=r=i(this,(t=e.__proto__||Object.getPrototypeOf(e)).call.apply(t,[this].concat(c))),r.handleOnClick=function(t){var e=r.chart_instance,n=r.props,o=n.getDatasetAtEvent,a=n.getElementAtEvent,i=n.getElementsAtEvent,u=n.onElementsClick;o&&o(e.getDatasetAtEvent(t),t),a&&a(e.getElementAtEvent(t),t),i&&i(e.getElementsAtEvent(t),t),u&&u(e.getElementsAtEvent(t),t)},o=n,i(r,o)}return u(e,t),s(e,[{key:"componentWillMount",value:function(){this.chart_instance=void 0}},{key:"componentDidMount",value:function(){this.renderChart()}},{key:"componentDidUpdate",value:function(){return this.props.redraw?(this.chart_instance.destroy(),void this.renderChart()):void this.updateChart()}},{key:"shouldComponentUpdate",value:function(t){var e=this.props,n=(e.redraw,e.type),r=e.options,o=e.legend,a=e.height,i=e.width;if(t.redraw===!0)return!0;if(a!==t.height||i!==t.width)return!0;if(n!==t.type)return!0;if(!(0,v["default"])(o,t.legend))return!0;if(!(0,v["default"])(r,t.options))return!0;var u=this.transformDataProp(t);return!(0,v["default"])(this.shadowDataProp,u)}},{key:"componentWillUnmount",value:function(){this.chart_instance.destroy()}},{key:"transformDataProp",value:function(t){var e=t.data;if("function"==typeof e){var n=h["default"].findDOMNode(this);return e(n)}return e}},{key:"memoizeDataProps",value:function(){if(this.props.data){var t=this.transformDataProp(this.props);return this.shadowDataProp=c({},t,{datasets:t.datasets&&t.datasets.map(function(t){return c({},t)})}),t}}},{key:"updateChart",value:function(){var t=this.props.options,e=this.memoizeDataProps(this.props);if(this.chart_instance){t&&(this.chart_instance.options=y["default"].helpers.configMerge(this.chart_instance.options,t));for(var n=this.chart_instance.config.data&&this.chart_instance.config.data.datasets||[],r=e.datasets||[];n.length>r.length;)n.pop();r.forEach(function(t,e){if(n[e]&&n[e].data){n[e].data.splice(r[e].data.length),t.data.forEach(function(t,o){n[e].data[o]=r[e].data[o]});var a=(t.data,o(t,["data"]));n[e]=c({data:n[e].data},n[e],a)}else n[e]=r[e]});var a=(e.datasets,o(e,["datasets"]));this.chart_instance.config.data=c({},this.chart_instance.config.data,a),this.chart_instance.update()}}},{key:"renderChart",value:function(){var t=this.props,e=t.options,n=(t.legend,t.type),r=(t.redraw,h["default"].findDOMNode(this)),o=this.memoizeDataProps();this.chart_instance=new y["default"](r,{type:n,data:o,options:e})}},{key:"render",value:function(){var t=this.props,e=t.height,n=t.width;t.onElementsClick;return l["default"].createElement("canvas",{height:e,width:n,onClick:this.handleOnClick})}}]),e}(l["default"].Component);b.propTypes={data:f.PropTypes.oneOfType([f.PropTypes.object,f.PropTypes.func]).isRequired,getDatasetAtEvent:f.PropTypes.func,getElementAtEvent:f.PropTypes.func,getElementsAtEvent:f.PropTypes.func,height:f.PropTypes.number,legend:f.PropTypes.object,onElementsClick:f.PropTypes.func,options:f.PropTypes.object,redraw:f.PropTypes.bool,type:f.PropTypes.oneOf(["doughnut","pie","line","bar","horizontalBar","radar","polarArea","bubble"]),width:f.PropTypes.number},b.defaultProps={legend:{display:!0,position:"bottom"},type:"doughnut",height:150,width:300,redraw:!1,options:{}},n["default"]=b;n.Doughnut=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"doughnut"}))}}]),e}(l["default"].Component),n.Pie=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"pie"}))}}]),e}(l["default"].Component),n.Line=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"line"}))}}]),e}(l["default"].Component),n.Bar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bar"}))}}]),e}(l["default"].Component),n.HorizontalBar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"horizontalBar"}))}}]),e}(l["default"].Component),n.Radar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"radar"}))}}]),e}(l["default"].Component),n.Polar=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"polarArea"}))}}]),e}(l["default"].Component),n.Bubble=function(t){function e(){return a(this,e),i(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return u(e,t),s(e,[{key:"render",value:function(){var t=this;return l["default"].createElement(b,c({},this.props,{ref:function(e){return t.chart_instance=e&&e.chart_instance},type:"bubble"}))}}]),e}(l["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:{})},{"lodash.isequal":1}]},{},[2])(2)}); |
@@ -1776,3 +1776,4 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
return !(0, _lodash2.default)(this.shadowDataProp, nextProps.data); | ||
var nextData = this.transformDataProp(nextProps); | ||
return !(0, _lodash2.default)(this.shadowDataProp, nextData); | ||
} | ||
@@ -1784,3 +1785,15 @@ }, { | ||
} | ||
}, { | ||
key: 'transformDataProp', | ||
value: function transformDataProp(props) { | ||
var data = props.data; | ||
if (typeof data == "function") { | ||
var node = _reactDom2.default.findDOMNode(this); | ||
return data(node); | ||
} else { | ||
return data; | ||
} | ||
} | ||
// Chart.js directly mutates the data.dataset objects by adding _meta proprerty | ||
@@ -1794,14 +1807,15 @@ // this makes impossible to compare the current and next data changes | ||
value: function memoizeDataProps() { | ||
var data = this.props.data; | ||
if (!data) { | ||
if (!this.props.data) { | ||
return; | ||
} | ||
var data = this.transformDataProp(this.props); | ||
this.shadowDataProp = _extends({}, data, { | ||
datasets: data.datasets && data.datasets.map(function (set) { | ||
return Object.assign({}, set); | ||
return _extends({}, set); | ||
}) | ||
}); | ||
return data; | ||
} | ||
@@ -1811,8 +1825,6 @@ }, { | ||
value: function updateChart() { | ||
var _props2 = this.props, | ||
data = _props2.data, | ||
options = _props2.options; | ||
var options = this.props.options; | ||
this.memoizeDataProps(); | ||
var data = this.memoizeDataProps(this.props); | ||
@@ -1830,2 +1842,7 @@ if (!this.chart_instance) return; | ||
// Prevent charting of legend items that no longer exist | ||
while (currentDatasets.length > nextDatasets.length) { | ||
currentDatasets.pop(); | ||
} | ||
nextDatasets.forEach(function (dataset, sid) { | ||
@@ -1860,13 +1877,11 @@ if (currentDatasets[sid] && currentDatasets[sid].data) { | ||
value: function renderChart() { | ||
var _props3 = this.props, | ||
data = _props3.data, | ||
options = _props3.options, | ||
legend = _props3.legend, | ||
type = _props3.type, | ||
redraw = _props3.redraw; | ||
var _props2 = this.props, | ||
options = _props2.options, | ||
legend = _props2.legend, | ||
type = _props2.type, | ||
redraw = _props2.redraw; | ||
var node = _reactDom2.default.findDOMNode(this); | ||
var data = this.memoizeDataProps(); | ||
this.memoizeDataProps(); | ||
this.chart_instance = new _chart2.default(node, { | ||
@@ -1881,6 +1896,6 @@ type: type, | ||
value: function render() { | ||
var _props4 = this.props, | ||
height = _props4.height, | ||
width = _props4.width, | ||
onElementsClick = _props4.onElementsClick; | ||
var _props3 = this.props, | ||
height = _props3.height, | ||
width = _props3.width, | ||
onElementsClick = _props3.onElementsClick; | ||
@@ -1900,3 +1915,3 @@ | ||
ChartComponent.propTypes = { | ||
data: _react.PropTypes.object.isRequired, | ||
data: _react.PropTypes.oneOfType([_react.PropTypes.object, _react.PropTypes.func]).isRequired, | ||
getDatasetAtEvent: _react.PropTypes.func, | ||
@@ -1903,0 +1918,0 @@ getElementAtEvent: _react.PropTypes.func, |
@@ -562,2 +562,4 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _react = require('react'); | ||
@@ -613,3 +615,4 @@ | ||
var newDataSet = Object.assign({}, oldDataSet); | ||
var newDataSet = _extends({}, oldDataSet); | ||
newDataSet.data = newData; | ||
@@ -616,0 +619,0 @@ |
@@ -122,3 +122,4 @@ 'use strict'; | ||
return !(0, _lodash2.default)(this.shadowDataProp, nextProps.data); | ||
var nextData = this.transformDataProp(nextProps); | ||
return !(0, _lodash2.default)(this.shadowDataProp, nextData); | ||
} | ||
@@ -130,3 +131,15 @@ }, { | ||
} | ||
}, { | ||
key: 'transformDataProp', | ||
value: function transformDataProp(props) { | ||
var data = props.data; | ||
if (typeof data == "function") { | ||
var node = _reactDom2.default.findDOMNode(this); | ||
return data(node); | ||
} else { | ||
return data; | ||
} | ||
} | ||
// Chart.js directly mutates the data.dataset objects by adding _meta proprerty | ||
@@ -140,14 +153,15 @@ // this makes impossible to compare the current and next data changes | ||
value: function memoizeDataProps() { | ||
var data = this.props.data; | ||
if (!data) { | ||
if (!this.props.data) { | ||
return; | ||
} | ||
var data = this.transformDataProp(this.props); | ||
this.shadowDataProp = _extends({}, data, { | ||
datasets: data.datasets && data.datasets.map(function (set) { | ||
return Object.assign({}, set); | ||
return _extends({}, set); | ||
}) | ||
}); | ||
return data; | ||
} | ||
@@ -157,8 +171,6 @@ }, { | ||
value: function updateChart() { | ||
var _props2 = this.props, | ||
data = _props2.data, | ||
options = _props2.options; | ||
var options = this.props.options; | ||
this.memoizeDataProps(); | ||
var data = this.memoizeDataProps(this.props); | ||
@@ -176,2 +188,7 @@ if (!this.chart_instance) return; | ||
// Prevent charting of legend items that no longer exist | ||
while (currentDatasets.length > nextDatasets.length) { | ||
currentDatasets.pop(); | ||
} | ||
nextDatasets.forEach(function (dataset, sid) { | ||
@@ -206,13 +223,11 @@ if (currentDatasets[sid] && currentDatasets[sid].data) { | ||
value: function renderChart() { | ||
var _props3 = this.props, | ||
data = _props3.data, | ||
options = _props3.options, | ||
legend = _props3.legend, | ||
type = _props3.type, | ||
redraw = _props3.redraw; | ||
var _props2 = this.props, | ||
options = _props2.options, | ||
legend = _props2.legend, | ||
type = _props2.type, | ||
redraw = _props2.redraw; | ||
var node = _reactDom2.default.findDOMNode(this); | ||
var data = this.memoizeDataProps(); | ||
this.memoizeDataProps(); | ||
this.chart_instance = new _chart2.default(node, { | ||
@@ -227,6 +242,6 @@ type: type, | ||
value: function render() { | ||
var _props4 = this.props, | ||
height = _props4.height, | ||
width = _props4.width, | ||
onElementsClick = _props4.onElementsClick; | ||
var _props3 = this.props, | ||
height = _props3.height, | ||
width = _props3.width, | ||
onElementsClick = _props3.onElementsClick; | ||
@@ -246,3 +261,3 @@ | ||
ChartComponent.propTypes = { | ||
data: _react.PropTypes.object.isRequired, | ||
data: _react.PropTypes.oneOfType([_react.PropTypes.object, _react.PropTypes.func]).isRequired, | ||
getDatasetAtEvent: _react.PropTypes.func, | ||
@@ -249,0 +264,0 @@ getElementAtEvent: _react.PropTypes.func, |
{ | ||
"name": "react-chartjs-2", | ||
"version": "2.0.0", | ||
"version": "2.0.5", | ||
"description": "react-chartjs-2", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -51,3 +51,3 @@ [![build status]( https://img.shields.io/travis/gor181/react-chartjs-2.svg?branch=master&style=flat-square)](https://travis-ci.org/gor181/react-chartjs-2) | ||
* data: PropTypes.object.isRequired, | ||
* data: (PropTypes.object | PropTypes.func).isRequired, | ||
* width: PropTypes.number, | ||
@@ -91,2 +91,27 @@ * height: PropTypes.number, | ||
### Getting context for data generation | ||
Canvas node and hence context, that can be used to create CanvasGradient background, | ||
is passed as argument to data if given as function: | ||
This approach is useful when you want to keep your components pure. | ||
```js | ||
render() { | ||
const data = (canvas) => { | ||
const ctx = canvas.getContext("2d") | ||
const gradient = ctx.createLinearGradient(0,0,100,0); | ||
... | ||
return { | ||
... | ||
backgroundColor: gradient | ||
... | ||
} | ||
} | ||
return ( | ||
<Line data={data} /> | ||
) | ||
} | ||
``` | ||
### Chart.js Defaults | ||
@@ -93,0 +118,0 @@ Chart.js defaults can be set by importing the `defaults` object: |
@@ -212,2 +212,15 @@ import React from 'react'; | ||
}); | ||
describe('props.data function', () => { | ||
it('calls data func with canvas node', () => { | ||
const resultData = { test: 1 } | ||
const dataFn = sinon.spy((canvas) => resultData); | ||
const wrapper = mountComponent({ data: dataFn }); | ||
const canvas = wrapper.find('canvas').at(0).node; | ||
expect(dataFn.callCount).to.equal(1); | ||
expect(dataFn.calledWith(canvas)).to.equal(true); | ||
}); | ||
}) | ||
}); |
Sorry, the diff of this file is too big to display
2615797
69947
212