Skip to content

Commit 0467771

Browse files
committed
Added support for inline plugins (see [email protected]) and modified mixed data example to include an example plugin
1 parent f87495e commit 0467771

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ChartComponent extends React.Component {
1616
legend: PropTypes.object,
1717
onElementsClick: PropTypes.func,
1818
options: PropTypes.object,
19+
plugins: PropTypes.arrayOf(PropTypes.object),
1920
redraw: PropTypes.bool,
2021
type: PropTypes.oneOf(['doughnut', 'pie', 'line', 'bar', 'horizontalBar', 'radar', 'polarArea', 'bubble']),
2122
width: PropTypes.number
@@ -81,6 +82,10 @@ class ChartComponent extends React.Component {
8182
return true;
8283
}
8384

85+
if (!isEqual(plugins, nextProps.plugins)) {
86+
return true;
87+
}
88+
8489
const nextData = this.transformDataProp(nextProps)
8590
return !isEqual(this.shadowDataProp, nextData);
8691
}
@@ -174,14 +179,15 @@ class ChartComponent extends React.Component {
174179
}
175180

176181
renderChart() {
177-
const {options, legend, type, redraw} = this.props;
182+
const {options, legend, type, redraw, plugins} = this.props;
178183
const node = ReactDOM.findDOMNode(this);
179184
const data = this.memoizeDataProps();
180185

181186
this.chart_instance = new Chart(node, {
182187
type,
183188
data,
184-
options
189+
options,
190+
plugins
185191
});
186192
}
187193

0 commit comments

Comments
 (0)