From 04677710be46881e9df30e6138098cbc8e3cf823 Mon Sep 17 00:00:00 2001 From: Andrew Chan Date: Tue, 11 Apr 2017 21:30:24 -0700 Subject: [PATCH 1/2] Added support for inline plugins (see chartjs@2.5.0) and modified mixed data example to include an example plugin --- example/src/components/mix.js | 8 ++++++++ src/index.js | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/example/src/components/mix.js b/example/src/components/mix.js index 41749a3e5..902d97d87 100644 --- a/example/src/components/mix.js +++ b/example/src/components/mix.js @@ -79,6 +79,13 @@ const options = { } }; +const plugins = [{ + afterDraw: (chartInstance, easing) => { + const ctx = chartInstance.chart.ctx; + ctx.fillText("This text drawn by a plugin", 100, 100); + } +}]; + export default React.createClass({ displayName: 'MixExample', @@ -89,6 +96,7 @@ export default React.createClass({ ); diff --git a/src/index.js b/src/index.js index aff59393d..8b7f244b3 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,7 @@ class ChartComponent extends React.Component { legend: PropTypes.object, onElementsClick: PropTypes.func, options: PropTypes.object, + plugins: PropTypes.arrayOf(PropTypes.object), redraw: PropTypes.bool, type: PropTypes.oneOf(['doughnut', 'pie', 'line', 'bar', 'horizontalBar', 'radar', 'polarArea', 'bubble']), width: PropTypes.number @@ -81,6 +82,10 @@ class ChartComponent extends React.Component { return true; } + if (!isEqual(plugins, nextProps.plugins)) { + return true; + } + const nextData = this.transformDataProp(nextProps) return !isEqual(this.shadowDataProp, nextData); } @@ -174,14 +179,15 @@ class ChartComponent extends React.Component { } renderChart() { - const {options, legend, type, redraw} = this.props; + const {options, legend, type, redraw, plugins} = this.props; const node = ReactDOM.findDOMNode(this); const data = this.memoizeDataProps(); this.chart_instance = new Chart(node, { type, data, - options + options, + plugins }); } From af13b90ee96636f390f9df522ef7a228c0dd40c0 Mon Sep 17 00:00:00 2001 From: Andrew Chan Date: Tue, 11 Apr 2017 21:39:31 -0700 Subject: [PATCH 2/2] missing ref in shouldComponentUpdate --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 8b7f244b3..93075a714 100644 --- a/src/index.js +++ b/src/index.js @@ -57,6 +57,7 @@ class ChartComponent extends React.Component { redraw, type, options, + plugins, legend, height, width