Skip to content

Commit 83e4240

Browse files
authored
Merge pull request #120 from theandrewchan/inlineplugins
Added support for inline plugins (see [email protected]) and modified mix…
2 parents f47d1ba + af13b90 commit 83e4240

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

example/src/components/mix.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ const options = {
7979
}
8080
};
8181

82+
const plugins = [{
83+
afterDraw: (chartInstance, easing) => {
84+
const ctx = chartInstance.chart.ctx;
85+
ctx.fillText("This text drawn by a plugin", 100, 100);
86+
}
87+
}];
88+
8289
export default React.createClass({
8390
displayName: 'MixExample',
8491

@@ -89,6 +96,7 @@ export default React.createClass({
8996
<Bar
9097
data={data}
9198
options={options}
99+
plugins={plugins}
92100
/>
93101
</div>
94102
);

src/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ChartComponent extends React.Component {
1818
legend: PropTypes.object,
1919
onElementsClick: PropTypes.func,
2020
options: PropTypes.object,
21+
plugins: PropTypes.arrayOf(PropTypes.object),
2122
redraw: PropTypes.bool,
2223
type: PropTypes.oneOf(['doughnut', 'pie', 'line', 'bar', 'horizontalBar', 'radar', 'polarArea', 'bubble']),
2324
width: PropTypes.number,
@@ -60,6 +61,7 @@ class ChartComponent extends React.Component {
6061
redraw,
6162
type,
6263
options,
64+
plugins,
6365
legend,
6466
height,
6567
width
@@ -85,6 +87,10 @@ class ChartComponent extends React.Component {
8587
return true;
8688
}
8789

90+
if (!isEqual(plugins, nextProps.plugins)) {
91+
return true;
92+
}
93+
8894
const nextData = this.transformDataProp(nextProps)
8995
return !isEqual(this.shadowDataProp, nextData);
9096
}
@@ -183,14 +189,15 @@ class ChartComponent extends React.Component {
183189
}
184190

185191
renderChart() {
186-
const {options, legend, type, redraw} = this.props;
192+
const {options, legend, type, redraw, plugins} = this.props;
187193
const node = ReactDOM.findDOMNode(this);
188194
const data = this.memoizeDataProps();
189195

190196
this.chart_instance = new Chart(node, {
191197
type,
192198
data,
193-
options
199+
options,
200+
plugins
194201
});
195202
}
196203

0 commit comments

Comments
 (0)