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

Function toMoveInsideBar

src/traces/bar/plot.js:759–857  ·  view source on GitHub ↗
(x0, x1, y0, y1, textBB, opts)

Source from the content-addressed store, hash-verified

757}
758
759function toMoveInsideBar(x0, x1, y0, y1, textBB, opts) {
760 var isHorizontal = !!opts.isHorizontal;
761 var constrained = !!opts.constrained;
762 var angle = opts.angle || 0;
763 var anchor = opts.anchor;
764 var isEnd = anchor === 'end';
765 var isStart = anchor === 'start';
766 var leftToRight = opts.leftToRight || 0; // left: -1, center: 0, right: 1
767 var toRight = (leftToRight + 1) / 2;
768 var toLeft = 1 - toRight;
769 var hasB = opts.hasB;
770 var r = opts.r;
771 var overhead = opts.overhead;
772
773 var textWidth = textBB.width;
774 var textHeight = textBB.height;
775
776 var lx = Math.abs(x1 - x0);
777 var ly = Math.abs(y1 - y0);
778
779 // compute remaining space
780 var textpad = lx > 2 * TEXTPAD && ly > 2 * TEXTPAD ? TEXTPAD : 0;
781
782 lx -= 2 * textpad;
783 ly -= 2 * textpad;
784
785 var rotate = getRotateFromAngle(angle);
786 if (
787 angle === 'auto' &&
788 !(textWidth <= lx && textHeight <= ly) &&
789 (textWidth > lx || textHeight > ly) &&
790 (!(textWidth > ly || textHeight > lx) || textWidth < textHeight !== lx < ly)
791 ) {
792 rotate += 90;
793 }
794
795 var t = getRotatedTextSize(textBB, rotate);
796
797 var scale, padForRounding;
798 // Scale text for rounded bars
799 if (r && r - overhead > TEXTPAD) {
800 var scaleAndPad = scaleTextForRoundedBar(x0, x1, y0, y1, t, r, overhead, isHorizontal, hasB);
801 scale = scaleAndPad.scale;
802 padForRounding = scaleAndPad.pad;
803 // Scale text for non-rounded bars
804 } else {
805 scale = 1;
806 if (constrained) {
807 scale = Math.min(1, lx / t.x, ly / t.y);
808 }
809 padForRounding = 0;
810 }
811
812 // compute text and target positions
813 var textX = textBB.left * toLeft + textBB.right * toRight;
814 var textY = (textBB.top + textBB.bottom) / 2;
815 var targetX = (x0 + TEXTPAD) * toLeft + (x1 - TEXTPAD) * toRight;
816 var targetY = (y0 + y1) / 2;

Callers 3

plot.jsFile · 0.85
appendBarTextFunction · 0.85
toMoveInsideSliceFunction · 0.85

Calls 4

getRotateFromAngleFunction · 0.85
getRotatedTextSizeFunction · 0.85
scaleTextForRoundedBarFunction · 0.85
dirSignFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…