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

Function hoverAvoidOverlaps

src/components/fx/hover.js:1768–2012  ·  view source on GitHub ↗
(hoverLabels, rotateLabels, fullLayout, commonLabelBoundingBox)

Source from the content-addressed store, hash-verified

1766// the other, though it hardly matters - there's just too much
1767// information then.
1768function hoverAvoidOverlaps(hoverLabels, rotateLabels, fullLayout, commonLabelBoundingBox) {
1769 var axKey = rotateLabels ? 'xa' : 'ya';
1770 var crossAxKey = rotateLabels ? 'ya' : 'xa';
1771 var nummoves = 0;
1772 var axSign = 1;
1773 var nLabels = hoverLabels.size();
1774
1775 // make groups of touching points
1776 var pointgroups = new Array(nLabels);
1777 var k = 0;
1778
1779 // get extent of axis hover label
1780 var axisLabelMinX = commonLabelBoundingBox.minX;
1781 var axisLabelMaxX = commonLabelBoundingBox.maxX;
1782 var axisLabelMinY = commonLabelBoundingBox.minY;
1783 var axisLabelMaxY = commonLabelBoundingBox.maxY;
1784
1785 var pX = function (x) {
1786 return x * fullLayout._invScaleX;
1787 };
1788 var pY = function (y) {
1789 return y * fullLayout._invScaleY;
1790 };
1791
1792 hoverLabels.each(function (d) {
1793 var ax = d[axKey];
1794 var crossAx = d[crossAxKey];
1795 var axIsX = ax._id.charAt(0) === 'x';
1796 var rng = ax.range;
1797
1798 if (k === 0 && rng && rng[0] > rng[1] !== axIsX) {
1799 axSign = -1;
1800 }
1801 var pmin = 0;
1802 var pmax = axIsX ? fullLayout.width : fullLayout.height;
1803 // in hovermode avoid overlap between hover labels and axis label
1804 if (fullLayout.hovermode === 'x' || fullLayout.hovermode === 'y') {
1805 // extent of rect behind hover label on cross axis:
1806 var offsets = getHoverLabelOffsets(d, rotateLabels);
1807 var anchor = d.anchor;
1808 var horzSign = anchor === 'end' ? -1 : 1;
1809 var labelMin;
1810 var labelMax;
1811 if (anchor === 'middle') {
1812 // use extent of centered rect either on x or y axis depending on current axis
1813 labelMin = d.crossPos + (axIsX ? pY(offsets.y - d.by / 2) : pX(d.bx / 2 + d.tx2width / 2));
1814 labelMax = labelMin + (axIsX ? pY(d.by) : pX(d.bx));
1815 } else {
1816 // use extend of path (see alignHoverText function) without arrow
1817 if (axIsX) {
1818 labelMin = d.crossPos + pY(HOVERARROWSIZE + offsets.y) - pY(d.by / 2 - HOVERARROWSIZE);
1819 labelMax = labelMin + pY(d.by);
1820 } else {
1821 var startX = pX(horzSign * HOVERARROWSIZE + offsets.x);
1822 var endX = startX + pX(horzSign * d.bx);
1823 labelMin = d.crossPos + Math.min(startX, endX);
1824 labelMax = d.crossPos + Math.max(startX, endX);
1825 }

Callers 1

_hoverFunction · 0.85

Calls 3

getHoverLabelOffsetsFunction · 0.85
pYFunction · 0.85
pXFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…