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

Function positionTitleOutside

src/traces/pie/plot.js:877–933  ·  view source on GitHub ↗
(cd0, plotSize)

Source from the content-addressed store, hash-verified

875}
876
877function positionTitleOutside(cd0, plotSize) {
878 var scaleX = 1;
879 var scaleY = 1;
880 var maxPull;
881
882 var trace = cd0.trace;
883 // position of the baseline point of the text box in the plot, before scaling.
884 // we anchored the text in the middle, so the baseline is on the bottom middle
885 // of the first line of text.
886 var topMiddle = {
887 x: cd0.cx,
888 y: cd0.cy
889 };
890 // relative translation of the text box after scaling
891 var translate = {
892 tx: 0,
893 ty: 0
894 };
895
896 // we reason below as if the baseline is the top middle point of the text box.
897 // so we must add the font size to approximate the y-coord. of the top.
898 // note that this correction must happen after scaling.
899 translate.ty += trace.title.font.size;
900 maxPull = getMaxPull(trace);
901
902 if (trace.title.position.indexOf('top') !== -1) {
903 topMiddle.y -= (1 + maxPull) * cd0.r;
904 translate.ty -= cd0.titleBox.height;
905 } else if (trace.title.position.indexOf('bottom') !== -1) {
906 topMiddle.y += (1 + maxPull) * cd0.r;
907 }
908
909 var rx = applyAspectRatio(cd0.r, cd0.trace.aspectratio);
910
911 var maxWidth = (plotSize.w * (trace.domain.x[1] - trace.domain.x[0])) / 2;
912 if (trace.title.position.indexOf('left') !== -1) {
913 // we start the text at the left edge of the pie
914 maxWidth = maxWidth + rx;
915 topMiddle.x -= (1 + maxPull) * rx;
916 translate.tx += cd0.titleBox.width / 2;
917 } else if (trace.title.position.indexOf('center') !== -1) {
918 maxWidth *= 2;
919 } else if (trace.title.position.indexOf('right') !== -1) {
920 maxWidth = maxWidth + rx;
921 topMiddle.x += (1 + maxPull) * rx;
922 translate.tx -= cd0.titleBox.width / 2;
923 }
924 scaleX = maxWidth / cd0.titleBox.width;
925 scaleY = getTitleSpace(cd0, plotSize) / cd0.titleBox.height;
926 return {
927 x: topMiddle.x,
928 y: topMiddle.y,
929 scale: Math.min(scaleX, scaleY),
930 tx: translate.tx,
931 ty: translate.ty
932 };
933}
934

Callers 2

plot.jsFile · 0.85
plotFunction · 0.85

Calls 3

getMaxPullFunction · 0.85
applyAspectRatioFunction · 0.85
getTitleSpaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…