MCPcopy Index your code
hub / github.com/plotly/plotly.js / alignHoverText

Function alignHoverText

src/components/fx/hover.js:2050–2158  ·  view source on GitHub ↗
(hoverLabels, rotateLabels, scaleX, scaleY)

Source from the content-addressed store, hash-verified

2048}
2049
2050function alignHoverText(hoverLabels, rotateLabels, scaleX, scaleY) {
2051 var pX = function (x) {
2052 return x * scaleX;
2053 };
2054 var pY = function (y) {
2055 return y * scaleY;
2056 };
2057
2058 // finally set the text positioning relative to the data and draw the
2059 // box around it
2060 hoverLabels.each(function (d) {
2061 var g = d3.select(this);
2062 if (d.del) return g.remove();
2063
2064 var tx = g.select('text.nums');
2065 var anchor = d.anchor;
2066 var horzSign = anchor === 'end' ? -1 : 1;
2067 var shiftX = getTextShiftX(d);
2068 var offsets = getHoverLabelOffsets(d, rotateLabels);
2069 var offsetX = offsets.x;
2070 var offsetY = offsets.y;
2071
2072 var isMiddle = anchor === 'middle';
2073 // Get 'showarrow' attribute value from trace hoverlabel settings;
2074 // if trace has no hoverlabel settings, we should show the arrow by default
2075 var showArrow = 'hoverlabel' in d.trace ? d.trace.hoverlabel.showarrow : true;
2076
2077 var pathStr;
2078 if (isMiddle) {
2079 // middle aligned: rect centered on data
2080 pathStr =
2081 'M-' +
2082 pX(d.bx / 2 + d.tx2width / 2) +
2083 ',' +
2084 pY(offsetY - d.by / 2) +
2085 'h' +
2086 pX(d.bx) +
2087 'v' +
2088 pY(d.by) +
2089 'h-' +
2090 pX(d.bx) +
2091 'Z';
2092 } else if (showArrow) {
2093 // left or right aligned: side rect with arrow to data
2094 pathStr =
2095 'M0,0L' +
2096 pX(horzSign * HOVERARROWSIZE + offsetX) +
2097 ',' +
2098 pY(HOVERARROWSIZE + offsetY) +
2099 'v' +
2100 pY(d.by / 2 - HOVERARROWSIZE) +
2101 'h' +
2102 pX(horzSign * d.bx) +
2103 'v-' +
2104 pY(d.by) +
2105 'H' +
2106 pX(horzSign * HOVERARROWSIZE + offsetX) +
2107 'V' +

Callers 2

hover.jsFile · 0.85
_hoverFunction · 0.85

Calls 4

getTextShiftXFunction · 0.85
getHoverLabelOffsetsFunction · 0.85
pXFunction · 0.85
pYFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…