Skip to content

Commit cb67de8

Browse files
committed
Add subscribing to events
1 parent 8af7813 commit cb67de8

File tree

7 files changed

+54
-31
lines changed

7 files changed

+54
-31
lines changed

demos/demosources/ex7/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
fc-height="400"
44
fc-type="column2d",
55
fc-datasource="{{dataSource}}"
6-
fc-dataplot-click="onMyChartClick"
6+
fc-events="events"
77
></div>
88
<p>The value that you have selected is: {{ selectedValue }}</p>

demos/demosources/ex7/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@
3939
}]
4040
};
4141
$scope.selectedValue = "nothing";
42-
$scope.onMyChartClick = function (event, props) {
43-
$scope.selectedValue = props.displayValue;
44-
};
42+
43+
$scope.events = {
44+
dataplotclick: function (ev, props) {
45+
$scope.$apply(function () {
46+
$scope.selectedValue = props.displayValue;
47+
});
48+
}
49+
}
4550
});
4651

4752
}());

demos/demosources/ex7/src.ejs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@ $scope.dataSource = {
2828
}]
2929
};
3030
$scope.selectedValue = "nothing";
31-
$scope.onMyChartClick = function (event, props) {
32-
$scope.selectedValue = props.displayValue;
33-
};
31+
32+
$scope.events = {
33+
dataplotclick: function (ev, props) {
34+
$scope.$apply(function () {
35+
$scope.selectedValue = props.displayValue;
36+
});
37+
}
38+
}
3439
<% } else if(src==="html") { %>
3540
<div fc-chart
3641
fc-width="600"
3742
fc-height="400"
3843
fc-type="column2d",
3944
fc-datasource="{{dataSource}}"
40-
fc-dataplot-click="onMyChartClick"
45+
fc-events="events"
4146
></div>
4247
<p>The value that you have selected is: {{ selectedValue }}</p>
4348
<% } %>

demos/js/demos/ex7.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,14 @@
3939
}]
4040
};
4141
$scope.selectedValue = "nothing";
42-
$scope.onMyChartClick = function (event, props) {
43-
$scope.selectedValue = props.displayValue;
44-
};
42+
43+
$scope.events = {
44+
dataplotclick: function (ev, props) {
45+
$scope.$apply(function () {
46+
$scope.selectedValue = props.displayValue;
47+
});
48+
}
49+
}
4550
});
4651

4752
}());

demos/views/ex7.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fc-height="400"
44
fc-type="column2d",
55
fc-datasource="{{dataSource}}"
6-
fc-dataplot-click="onMyChartClick"
6+
fc-events="events"
77
></div>
88
<p>The value that you have selected is: {{ selectedValue }}</p><tabset>
99
<tab heading="HTML"><ng-prism class="language-markup">{{ html }}</ng-prism></tab>

dist/angular-fusioncharts.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/angular-fusioncharts.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,36 @@
3131
fcHeight: '@',
3232
fcDataset: '@',
3333
fcCategories: '@',
34-
fcChartAttrs: '@',
35-
fcDataplotClick: '@',
36-
fcChartClick: '@'
34+
fcChartAttrs: '@'
3735
},
3836
link: function (scope, element, attrs) {
39-
var chart = null,
37+
var eventsObj = {},
38+
attribs = Object.keys(attrs),
39+
chart = null,
4040
events = {
41-
dataplotClick: function (ev, props) {
42-
if(attrs.fcDataplotClick) {
43-
scope.$apply (function () {
44-
scope.$parent[attrs.fcDataplotClick](ev, props);
45-
});
46-
}
47-
},
48-
chartClick: function (ev, props) {
49-
if(attrs.fcChartClick) {
50-
scope.$apply (function () {
51-
scope.$parent[attrs.fcChartClick](ev, props);
52-
});
53-
}
41+
'*': function (ev, props) {
42+
if(eventsObj.hasOwnProperty(ev.eventType)) {
43+
eventsObj[ev.eventType](ev, props);
44+
}
5445
}
5546
};
47+
if(attrs.fcEvents) {
48+
if(scope.$parent[attrs.fcEvents]) {
49+
var _eobj = scope.$parent[attrs.fcEvents];
50+
for(var key in _eobj) {
51+
if(_eobj.hasOwnProperty(key)) {
52+
eventsObj[key.toLowerCase()] = _eobj[key];
53+
}
54+
}
55+
}
56+
}
57+
for(var i=0; i<attribs.length; i++) {
58+
var attr = attribs[i];
59+
if(attr.match(/^on/i)) {
60+
var key = attr.slice(2).toLowerCase ();
61+
eventsObj[key] = scope.$parent[attrs[attr]];
62+
}
63+
}
5664
if(attrs.fcConfig) {
5765
chart = new FusionCharts(scope[attrs.fcConfig]);
5866
scope[attrs.fcChartObject] = chart;

0 commit comments

Comments
 (0)