Skip to content

Commit fdc6b5d

Browse files
mathbenjtblin
authored andcommitted
Add selected point/element in eventHandler for onClick and onHover (#536)
1 parent 3891fbb commit fdc6b5d

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

angular-chart.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,23 @@
201201
function getEventHandler (scope, action, triggerOnlyOnChange) {
202202
var lastState = null;
203203
return function (evt) {
204-
var atEvent = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
205-
if (atEvent) {
206-
var activePoints = atEvent.call(scope.chart, evt);
207-
if (triggerOnlyOnChange === false || angular.equals(lastState, activePoints) === false) {
208-
lastState = activePoints;
209-
scope[action](activePoints, evt);
204+
var atEvent = scope.chart.getElementAtEvent || scope.chart.getPointAtEvent;
205+
var atEvents = scope.chart.getElementsAtEvent || scope.chart.getPointsAtEvent;
206+
if (atEvents) {
207+
// get all point
208+
var points = atEvents.call(scope.chart, evt);
209+
var activePoint;
210+
// get active point
211+
if (atEvent) {
212+
var arrayActivePoint = atEvent.call(scope.chart, evt); // return array of 0 or 1 point
213+
if (arrayActivePoint.length) {
214+
activePoint = arrayActivePoint[0];
215+
}
216+
}
217+
218+
if (triggerOnlyOnChange === false || angular.equals(lastState, points) === false) {
219+
lastState = points;
220+
scope[action](points, evt, activePoint);
210221
}
211222
}
212223
};

0 commit comments

Comments
 (0)