MCPcopy
hub / github.com/chartjs/Chart.js / _handleEvent

Method _handleEvent

src/core/core.controller.js:1196–1239  ·  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

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