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

Function getAxisItems

src/core/core.interaction.js:228–246  ·  view source on GitHub ↗

* Helper function to get the items matching along the given X or Y axis * @param {Chart} chart - the chart to look at elements from * @param {Point} position - the point to be nearest to, in relative coordinates * @param {string} axis - the axis to match * @param {boolean} [intersect] - if true,

(chart, position, axis, intersect, useFinalPosition)

Source from the content-addressed store, hash-verified

226 * @return {InteractionItem[]} the nearest items
227 */
228function getAxisItems(chart, position, axis, intersect, useFinalPosition) {
229 const items = [];
230 const rangeMethod = axis === 'x' ? 'inXRange' : 'inYRange';
231 let intersectsItem = false;
232
233 evaluateInteractionItems(chart, axis, position, (element, datasetIndex, index) => {
234 if (element[rangeMethod] && element[rangeMethod](position[axis], useFinalPosition)) {
235 items.push({element, datasetIndex, index});
236 intersectsItem = intersectsItem || element.inRange(position.x, position.y, useFinalPosition);
237 }
238 });
239
240 // If we want to trigger on an intersect and we don't have any items
241 // that intersect the position, return nothing
242 if (intersect && !intersectsItem) {
243 return [];
244 }
245 return items;
246}
247
248/**
249 * Contains interaction related functions

Callers 2

xFunction · 0.85
yFunction · 0.85

Calls 2

evaluateInteractionItemsFunction · 0.85
inRangeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…