* Gets the tooltip position nearest of the item nearest to the event position
(items, eventPosition)
| 90 | * Gets the tooltip position nearest of the item nearest to the event position |
| 91 | */ |
| 92 | nearest(items, eventPosition) { |
| 93 | if (!items.length) { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | const chartArea = getChartArea(this); |
| 98 | let x = eventPosition.x; |
| 99 | let y = eventPosition.y; |
| 100 | let minDistance = Number.POSITIVE_INFINITY; |
| 101 | let i, len, nearestElement; |
| 102 | |
| 103 | for (i = 0, len = items.length; i < len; ++i) { |
| 104 | const el = items[i].element; |
| 105 | if (el && el.hasValue()) { |
| 106 | const center = getMeasurePoint(el, chartArea); |
| 107 | const d = distanceBetweenPoints(eventPosition, center); |
| 108 | |
| 109 | if (d < minDistance) { |
| 110 | minDistance = d; |
| 111 | nearestElement = el; |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (nearestElement) { |
| 117 | const tp = getAnchorPosition(nearestElement, chartArea); |
| 118 | x = tp.x; |
| 119 | y = tp.y; |
| 120 | } |
| 121 | |
| 122 | return { |
| 123 | x, |
| 124 | y |
| 125 | }; |
| 126 | } |
| 127 | }; |
| 128 | |
| 129 | // Helper to push or concat based on if the 2nd parameter is an array or not |
nothing calls this directly
no test coverage detected