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

Function transformInsideText

src/traces/pie/plot.js:679–794  ·  view source on GitHub ↗
(textBB, pt, cd0)

Source from the content-addressed store, hash-verified

677}
678
679function transformInsideText(textBB, pt, cd0) {
680 var r = cd0.r || pt.rpx1;
681 var rInscribed = pt.rInscribed;
682
683 var isEmpty = pt.startangle === pt.stopangle;
684 if (isEmpty) {
685 return {
686 rCenter: 1 - rInscribed,
687 scale: 0,
688 rotate: 0,
689 textPosAngle: 0
690 };
691 }
692
693 var ring = pt.ring;
694 var isCircle = ring === 1 && Math.abs(pt.startangle - pt.stopangle) === Math.PI * 2;
695
696 var halfAngle = pt.halfangle;
697 var midAngle = pt.midangle;
698
699 var orientation = cd0.trace.insidetextorientation;
700 var isHorizontal = orientation === 'horizontal';
701 var isTangential = orientation === 'tangential';
702 var isRadial = orientation === 'radial';
703 var isAuto = orientation === 'auto';
704
705 var allTransforms = [];
706 var newT;
707
708 if (!isAuto) {
709 // max size if text is placed (horizontally) at the top or bottom of the arc
710
711 var considerCrossing = function (angle, key) {
712 if (isCrossing(pt, angle)) {
713 var dStart = Math.abs(angle - pt.startangle);
714 var dStop = Math.abs(angle - pt.stopangle);
715
716 var closestEdge = dStart < dStop ? dStart : dStop;
717
718 if (key === 'tan') {
719 newT = calcTanTransform(textBB, r, ring, closestEdge, 0);
720 } else {
721 // case of 'rad'
722 newT = calcRadTransform(textBB, r, ring, closestEdge, Math.PI / 2);
723 }
724 newT.textPosAngle = angle;
725
726 allTransforms.push(newT);
727 }
728 };
729
730 // to cover all cases with trace.rotation added
731 var i;
732 if (isHorizontal || isTangential) {
733 // top
734 for (i = 4; i >= -4; i -= 2) considerCrossing(Math.PI * i, 'tan');
735 // bottom
736 for (i = 4; i >= -4; i -= 2) considerCrossing(Math.PI * (i + 1), 'tan');

Callers 2

plotOneFunction · 0.85
plotFunction · 0.85

Calls 3

considerCrossingFunction · 0.85
calcRadTransformFunction · 0.85
calcTanTransformFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…