MCPcopy Create free account
hub / github.com/chartjs/Chart.js / _handleEvent

Method _handleEvent

src/core/core.controller.js:1200–1243  ·  view source on GitHub ↗

* Handle an event * @param {ChartEvent} e the event to handle * @param {boolean} [replay] - true if the event was replayed by `update` * @param {boolean} [inChartArea] - true if the event is inside chartArea * @return {boolean} true if the chart needs to re-render * @private

(e, replay, inChartArea)

Source from the content-addressed store, hash-verified

1198 * @private
1199 */
1200 _handleEvent(e, replay, inChartArea) {
1201 const {_active: lastActive = [], options} = this;
1202
1203 // If the event is replayed from `update`, we should evaluate with the final positions.
1204 //
1205 // The `replay`:
1206 // It's the last event (excluding click) that has occurred before `update`.
1207 // So mouse has not moved. It's also over the chart, because there is a `replay`.
1208 //
1209 // The why:
1210 // If animations are active, the elements haven't moved yet compared to state before update.
1211 // But if they will, we are activating the elements that would be active, if this check
1212 // was done after the animations have completed. => "final positions".
1213 // If there is no animations, the "final" and "current" positions are equal.
1214 // This is done so we do not have to evaluate the active elements each animation frame
1215 // - it would be expensive.
1216 const useFinalPosition = replay;
1217 const active = this._getActiveElements(e, lastActive, inChartArea, useFinalPosition);
1218 const isClick = _isClickEvent(e);
1219 const lastEvent = determineLastEvent(e, this._lastEvent, inChartArea, isClick);
1220
1221 if (inChartArea) {
1222 // Set _lastEvent to null while we are processing the event handlers.
1223 // This prevents recursion if the handler calls chart.update()
1224 this._lastEvent = null;
1225
1226 // Invoke onHover hook
1227 callCallback(options.onHover, [e, active, this], this);
1228
1229 if (isClick) {
1230 callCallback(options.onClick, [e, active, this], this);
1231 }
1232 }
1233
1234 const changed = !_elementsEqual(active, lastActive);
1235 if (changed || replay) {
1236 this._active = active;
1237 this._updateHoverStyles(active, lastActive, replay);
1238 }
1239
1240 this._lastEvent = lastEvent;
1241
1242 return changed;
1243 }
1244
1245 /**
1246 * @param {ChartEvent} e - The event

Callers 10

_eventHandlerMethod · 0.95
opacity.jsFile · 0.80
corner-radius.jsFile · 0.80
point-style.jsFile · 0.80
box-padding.jsFile · 0.80
positioning.jsFile · 0.80
caret-position.jsFile · 0.80

Calls 5

_getActiveElementsMethod · 0.95
_updateHoverStylesMethod · 0.95
_isClickEventFunction · 0.85
determineLastEventFunction · 0.85
_elementsEqualFunction · 0.85

Tested by

no test coverage detected