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

Function getAnchorPosition

src/plugins/plugin.tooltip.js:38–49  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

36 * of its visible part; a bar wholly inside, and any other element, at its `tooltipPosition`.
37 */
38function 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
51const positioners = {
52 /**

Callers 2

averageFunction · 0.85
nearestFunction · 0.85

Calls 4

_isPointInAreaFunction · 0.85
_getAreaCenterMethod · 0.80
getCenterPointMethod · 0.65
tooltipPositionMethod · 0.45

Tested by

no test coverage detected