($, bitmaps, avoidBaseMark, markIndex)
| 138814 | return bm0.outOfBounds(x1, y1, x2, y2) || bm0.getRange(x1, y1, x2, y2) || bm1 && bm1.getRange(x1, y1, x2, y2); |
| 138815 | } |
| 138816 | function placeAreaLabelReducedSearch($, bitmaps, avoidBaseMark, markIndex) { |
| 138817 | const width = $.width, height = $.height, bm0 = bitmaps[0], // where labels have been placed |
| 138818 | bm1 = bitmaps[1]; // area outlines |
| 138819 | function tryLabel(_x, _y, maxSize, textWidth, textHeight) { |
| 138820 | const x = $.invert(_x), y = $.invert(_y); |
| 138821 | let lo = maxSize, hi = height, mid; |
| 138822 | if (!outOfBounds(x, y, textWidth, textHeight, width, height) && !collision($, x, y, textHeight, textWidth, lo, bm0, bm1) && !collision($, x, y, textHeight, textWidth, textHeight, bm0, null)) { |
| 138823 | // if the label fits at the current sample point, |
| 138824 | // perform binary search to find the largest font size that fits |
| 138825 | while(hi - lo >= 1){ |
| 138826 | mid = (lo + hi) / 2; |
| 138827 | if (collision($, x, y, textHeight, textWidth, mid, bm0, bm1)) hi = mid; |
| 138828 | else lo = mid; |
| 138829 | } // place label if current lower bound exceeds prior max font size |
| 138830 | if (lo > maxSize) return [ |
| 138831 | x, |
| 138832 | y, |
| 138833 | lo, |
| 138834 | true |
| 138835 | ]; |
| 138836 | } |
| 138837 | } // try to place a label within an input area mark |
| 138838 | return function(d) { |
| 138839 | const items = d.datum.datum.items[markIndex].items, // area points |
| 138840 | n = items.length, // number of points |
| 138841 | textHeight = d.datum.fontSize, // label width |
| 138842 | textWidth = (0, _vegaScenegraph.textMetrics).width(d.datum, d.datum.text); // label height |
| 138843 | let maxSize = avoidBaseMark ? textHeight : 0, labelPlaced = false, labelPlaced2 = false, maxAreaWidth = 0, x1, x2, y1, y2, x, y, _x, _y, _x1, _xMid, _x2, _y1, _yMid, _y2, areaWidth, result, swapTmp; // for each area sample point |
| 138844 | for(let i5 = 0; i5 < n; ++i5){ |
| 138845 | x1 = items[i5].x; |
| 138846 | y1 = items[i5].y; |
| 138847 | x2 = items[i5].x2 === undefined ? x1 : items[i5].x2; |
| 138848 | y2 = items[i5].y2 === undefined ? y1 : items[i5].y2; |
| 138849 | if (x1 > x2) { |
| 138850 | swapTmp = x1; |
| 138851 | x1 = x2; |
| 138852 | x2 = swapTmp; |
| 138853 | } |
| 138854 | if (y1 > y2) { |
| 138855 | swapTmp = y1; |
| 138856 | y1 = y2; |
| 138857 | y2 = swapTmp; |
| 138858 | } |
| 138859 | _x1 = $(x1); |
| 138860 | _x2 = $(x2); |
| 138861 | _xMid = ~~((_x1 + _x2) / 2); |
| 138862 | _y1 = $(y1); |
| 138863 | _y2 = $(y2); |
| 138864 | _yMid = ~~((_y1 + _y2) / 2); // search along the line from mid point between the 2 border to lower border |
| 138865 | for(_x = _xMid; _x >= _x1; --_x)for(_y = _yMid; _y >= _y1; --_y){ |
| 138866 | result = tryLabel(_x, _y, maxSize, textWidth, textHeight); |
| 138867 | if (result) [d.x, d.y, maxSize, labelPlaced] = result; |
| 138868 | } |
| 138869 | // search along the line from mid point between the 2 border to upper border |
| 138870 | for(_x = _xMid; _x <= _x2; ++_x)for(_y = _yMid; _y <= _y2; ++_y){ |
| 138871 | result = tryLabel(_x, _y, maxSize, textWidth, textHeight); |
| 138872 | if (result) [d.x, d.y, maxSize, labelPlaced] = result; |
| 138873 | } |
nothing calls this directly
no test coverage detected