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

Method handleEvent

src/plugins/plugin.tooltip.js:1216–1255  ·  view source on GitHub ↗

* Handle an event * @param {ChartEvent} e - The event to handle * @param {boolean} [replay] - This is a replayed event (from update) * @param {boolean} [inChartArea] - The event is inside chartArea * @returns {boolean} true if the tooltip changed

(e, replay, inChartArea = true)

Source from the content-addressed store, hash-verified

1214 * @returns {boolean} true if the tooltip changed
1215 */
1216 handleEvent(e, replay, inChartArea = true) {
1217 if (replay && this._ignoreReplayEvents) {
1218 return false;
1219 }
1220 this._ignoreReplayEvents = false;
1221
1222 const options = this.options;
1223 const lastActive = this._active || [];
1224 const active = this._getActiveElements(e, lastActive, replay, inChartArea);
1225
1226 // When there are multiple items shown, but the tooltip position is nearest mode
1227 // an update may need to be made because our position may have changed even though
1228 // the items are the same as before.
1229 const positionChanged = this._positionChanged(active, e);
1230
1231 // Remember Last Actives
1232 const elementsChanged = !_elementsEqual(active, lastActive);
1233 const changed = replay || elementsChanged || positionChanged;
1234
1235 // A position change alone does not count: only the elements do, as in the chart.
1236 if (_pointerOwnsActive(inChartArea, replay, elementsChanged)) {
1237 this._activeSetByCode = false;
1238 }
1239
1240 // Only handle target event on tooltip change
1241 if (changed) {
1242 this._active = active;
1243
1244 if (options.enabled || options.external) {
1245 this._eventPosition = {
1246 x: e.x,
1247 y: e.y
1248 };
1249
1250 this.update(true, replay);
1251 }
1252 }
1253
1254 return changed;
1255 }
1256
1257 /**
1258 * Helper for determining the active elements for event

Callers 1

afterEventFunction · 0.45

Calls 5

_getActiveElementsMethod · 0.95
_positionChangedMethod · 0.95
updateMethod · 0.95
_elementsEqualFunction · 0.85
_pointerOwnsActiveFunction · 0.85

Tested by

no test coverage detected