Skip to content

Commit 83cf649

Browse files
committed
Include dragging events and mapping event names containing periods
1 parent 63304a7 commit 83cf649

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

example/src/ModuleDrag.jsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,25 @@ class ModuleDrag extends Component {
6565
}
6666
}
6767
this.chart = React.createRef();
68+
this.log = this.log.bind(this);
69+
}
70+
71+
log(result) {
72+
console.log('event: ', result);
73+
console.log('drag value: ', result['zingchart.plugins.dragging.update.value'])
6874
}
69-
render() {
7075

76+
render() {
7177
return (
7278
<div >
73-
<ZingChart ref={this.chart} data={this.state.config} height='600px' modules='dragging' />
79+
<ZingChart
80+
ref={this.chart}
81+
data={this.state.config}
82+
height='600px'
83+
modules='dragging'
84+
zingchart_plugins_dragging_complete={this.log}/>
7485
</div>
7586
);
76-
7787
}
7888

7989
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zingchart-react",
3-
"version": "3.1.1",
3+
"version": "3.1.2",
44
"description": "ZingChart React Component wrapper to allow native react syntax for javascript charts, chart events, chart methods and chart styling.",
55
"author": "ZingSoft Inc.",
66
"license": "MIT",

src/index.jsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,26 @@ class ZingChart extends Component {
3535
);
3636
}
3737

38+
bindEvent(eventName, originalEventName) {
39+
if (EVENT_NAMES.includes(eventName)) {
40+
// Filter through the provided events list, then register it to zingchart.
41+
window.zingchart.bind(this.id, eventName, result => {
42+
this.props[originalEventName || eventName](result);
43+
});
44+
return true;
45+
} else {
46+
return false;
47+
};
48+
}
49+
3850
componentDidMount() {
3951
// Bind all events registered.
4052
Object.keys(this.props).forEach(eventName => {
41-
if (EVENT_NAMES.includes(eventName)) {
42-
// Filter through the provided events list, then register it to zingchart.
43-
window.zingchart.bind(this.id, eventName, result => {
44-
this.props[eventName](result);
45-
});
46-
}
53+
if (!this.bindEvent(eventName)) {
54+
// Replace '_' with '.' and attempt again
55+
let newEventName = eventName.replace(/\_/g, '.');
56+
this.bindEvent(newEventName, eventName);
57+
};
4758
});
4859

4960
this.renderChart();

0 commit comments

Comments
 (0)