Skip to content

Commit dbc40dd

Browse files
authored
Merge pull request #11 from sghosh9/support/events
add fcevent- attribute in component to addeventlistener callback in parent
2 parents 4fc2bf2 + 8b204fe commit dbc40dd

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/ReactFC.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
3636

3737
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
3838

39+
var staticEvents = ['ready', 'beforeinitialize', 'initialized'];
40+
3941
var ReactFC = function (_React$Component) {
4042
_inherits(ReactFC, _React$Component);
4143

@@ -261,10 +263,25 @@ var ReactFC = function (_React$Component) {
261263
}, {
262264
key: 'renderChart',
263265
value: function renderChart() {
266+
var _this4 = this;
267+
264268
var currentOptions = this.resolveChartOptions(this.props);
265269
currentOptions.renderAt = this.containerId;
266270

267271
this.chartObj = new this.FusionCharts(currentOptions);
272+
Object.keys(this.props).forEach(function (value) {
273+
var event = value.match(/^fcEvent-.*/i);
274+
275+
if (event && typeof _this4.props[value] === 'function') {
276+
var eventName = value.replace(/^fcEvent-/i, '');
277+
278+
if (staticEvents.indexOf(eventName.toLowerCase()) > -1) {
279+
_this4.FusionCharts.addEventListener(eventName, _this4.props[value]);
280+
} else {
281+
_this4.chartObj.addEventListener(eventName, _this4.props[value]);
282+
}
283+
}
284+
});
268285
this.chartObj.render();
269286
this.oldOptions = currentOptions;
270287

src/ReactFC.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import uuid from 'uuid/v4';
44
import * as utils from './utils/utils';
55
import fusionChartsOptions from './utils/options';
66

7+
const staticEvents = ['ready', 'beforeinitialize', 'initialized'];
8+
79
class ReactFC extends React.Component {
810
static fcRoot(core, ...modules) {
911
modules.forEach((m) => {
@@ -209,6 +211,19 @@ class ReactFC extends React.Component {
209211
currentOptions.renderAt = this.containerId;
210212

211213
this.chartObj = new this.FusionCharts(currentOptions);
214+
Object.keys(this.props).forEach((value) => {
215+
const event = value.match(/^fcEvent-.*/i);
216+
217+
if (event && typeof this.props[value] === 'function') {
218+
const eventName = value.replace(/^fcEvent-/i, '');
219+
220+
if (staticEvents.indexOf(eventName.toLowerCase()) > -1) {
221+
this.FusionCharts.addEventListener(eventName, this.props[value]);
222+
} else {
223+
this.chartObj.addEventListener(eventName, this.props[value]);
224+
}
225+
}
226+
});
212227
this.chartObj.render();
213228
this.oldOptions = currentOptions;
214229

0 commit comments

Comments
 (0)