* The point the tooltip anchors to. A bar cut off by the chart area points at the centre * of its visible part; a bar wholly inside, and any other element, at its `tooltipPosition`.
(el, chartArea)
| 36 | * of its visible part; a bar wholly inside, and any other element, at its `tooltipPosition`. |
| 37 | */ |
| 38 | function getAnchorPosition(el, chartArea) { |
| 39 | const position = el.tooltipPosition(); |
| 40 | const areaCenter = chartArea && el._getAreaCenter && el._getAreaCenter(chartArea); |
| 41 | if (!areaCenter) { |
| 42 | return position; |
| 43 | } |
| 44 | // A bar's tooltip position is its head, and its centre is midway to its base, |
| 45 | // so the base is the head mirrored through the centre. |
| 46 | const center = el.getCenterPoint(); |
| 47 | const base = {x: 2 * center.x - position.x, y: 2 * center.y - position.y}; |
| 48 | return _isPointInArea(position, chartArea) && _isPointInArea(base, chartArea) ? position : areaCenter; |
| 49 | } |
| 50 | |
| 51 | const positioners = { |
| 52 | /** |
no test coverage detected