Skip to content

Commit

Permalink
Include dragging events and mapping event names containing periods
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanettephung committed Dec 6, 2021
1 parent 63304a7 commit 83cf649
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
16 changes: 13 additions & 3 deletions example/src/ModuleDrag.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,25 @@ class ModuleDrag extends Component {
}
}
this.chart = React.createRef();
this.log = this.log.bind(this);
}

log(result) {
console.log('event: ', result);
console.log('drag value: ', result['zingchart.plugins.dragging.update.value'])
}
render() {

render() {
return (
<div >
<ZingChart ref={this.chart} data={this.state.config} height='600px' modules='dragging' />
<ZingChart
ref={this.chart}
data={this.state.config}
height='600px'
modules='dragging'
zingchart_plugins_dragging_complete={this.log}/>
</div>
);

}

}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zingchart-react",
"version": "3.1.1",
"version": "3.1.2",
"description": "ZingChart React Component wrapper to allow native react syntax for javascript charts, chart events, chart methods and chart styling.",
"author": "ZingSoft Inc.",
"license": "MIT",
Expand Down
23 changes: 17 additions & 6 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,26 @@ class ZingChart extends Component {
);
}

bindEvent(eventName, originalEventName) {
if (EVENT_NAMES.includes(eventName)) {
// Filter through the provided events list, then register it to zingchart.
window.zingchart.bind(this.id, eventName, result => {
this.props[originalEventName || eventName](result);
});
return true;
} else {
return false;
};
}

componentDidMount() {
// Bind all events registered.
Object.keys(this.props).forEach(eventName => {
if (EVENT_NAMES.includes(eventName)) {
// Filter through the provided events list, then register it to zingchart.
window.zingchart.bind(this.id, eventName, result => {
this.props[eventName](result);
});
}
if (!this.bindEvent(eventName)) {
// Replace '_' with '.' and attempt again
let newEventName = eventName.replace(/\_/g, '.');
this.bindEvent(newEventName, eventName);
};
});

this.renderChart();
Expand Down

0 comments on commit 83cf649

Please sign in to comment.