From ba16e45d7701f85206559d7b4c783e083bed1e8a Mon Sep 17 00:00:00 2001 From: Ben Immanuel Date: Wed, 24 Feb 2016 19:53:17 +0000 Subject: [PATCH] add postUpdate callback --- examples/lineChart/index.js | 6 +++++- src/index.js | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/lineChart/index.js b/examples/lineChart/index.js index c40ae49..e1fd522 100644 --- a/examples/lineChart/index.js +++ b/examples/lineChart/index.js @@ -40,7 +40,11 @@ y: 'value', margin: { left: 200 - } + }, + ready: function() { console.log('ready'); }, + renderStart: function() { console.log('renderStart'); }, + renderEnd: function() { console.log('renderEnd'); }, + postUpdate: function() { console.log('postUpdate'); } }), document.getElementById('lineChart') ); diff --git a/src/index.js b/src/index.js index 35477dc..76ed686 100644 --- a/src/index.js +++ b/src/index.js @@ -43,6 +43,9 @@ export default class NVD3Chart extends React.Component { */ componentDidUpdate() { this.renderChart(); + if (this.props.postUpdate) { // trigger callback (as nvd3 chart.update does not do this) + this.props.postUpdate(this.chart); + } } /** @@ -86,7 +89,12 @@ export default class NVD3Chart extends React.Component { // Update the chart if the window size change. // Save resizeHandle to remove the resize listener later. if(!this.resizeHandler) - this.resizeHandler = nv.utils.windowResize(this.chart.update); + this.resizeHandler = nv.utils.windowResize(function() { + this.chart.update(); + if (this.props.postUpdate) { // trigger callback (as nvd3 chart.update does not do this) + this.props.postUpdate(this.chart); + } + }.bind(this)); // PieCharts are an special case. Their dispacher is the pie component inside the chart. // There are some charts do not feature the renderEnd event