MCPcopy Create free account
hub / github.com/microsoft/SandDance / tryLabel

Function tryLabel

docs/app/js/sanddance-app.js:138819–138837  ·  view source on GitHub ↗
(_x, _y, maxSize, textWidth, textHeight)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 3

outOfBoundsFunction · 0.70
collisionFunction · 0.70
invertMethod · 0.45

Tested by

no test coverage detected