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

Method setActiveElements

src/plugins/plugin.tooltip.js:1106–1130  ·  view source on GitHub ↗

* Set active elements in the tooltip * @param {array} activeElements Array of active datasetIndex/index pairs. * @param {object} eventPosition Synthetic event position used in positioning

(activeElements, eventPosition)

Source from the content-addressed store, hash-verified

1104 * @param {object} eventPosition Synthetic event position used in positioning
1105 */
1106 setActiveElements(activeElements, eventPosition) {
1107 const lastActive = this._active;
1108 const active = activeElements.map(({datasetIndex, index}) => {
1109 const meta = this.chart.getDatasetMeta(datasetIndex);
1110
1111 if (!meta) {
1112 throw new Error('Cannot find a dataset at index ' + datasetIndex);
1113 }
1114
1115 return {
1116 datasetIndex,
1117 element: meta.data[index],
1118 index,
1119 };
1120 });
1121 const changed = !_elementsEqual(lastActive, active);
1122 const positionChanged = this._positionChanged(active, eventPosition);
1123
1124 if (changed || positionChanged) {
1125 this._active = active;
1126 this._eventPosition = eventPosition;
1127 this._ignoreReplayEvents = true;
1128 this.update(true);
1129 }
1130 }
1131
1132 /**
1133 * Handle an event

Callers

nothing calls this directly

Calls 4

_positionChangedMethod · 0.95
updateMethod · 0.95
_elementsEqualFunction · 0.85
getDatasetMetaMethod · 0.80

Tested by

no test coverage detected