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

Function computeLegendDimensions

src/components/legend/draw.js:861–1087  ·  view source on GitHub ↗
(gd, groups, traces, legendObj, scrollBox)

Source from the content-addressed store, hash-verified

859 * - _maxWidth (for orientation:h only): maximum width before starting new row
860 */
861function computeLegendDimensions(gd, groups, traces, legendObj, scrollBox) {
862 var fullLayout = gd._fullLayout;
863 var legendId = helpers.getId(legendObj);
864 if(!legendObj) {
865 legendObj = fullLayout[legendId];
866 }
867 var gs = fullLayout._size;
868
869 var isVertical = helpers.isVertical(legendObj);
870 var isGrouped = helpers.isGrouped(legendObj);
871 var isFraction = legendObj.entrywidthmode === 'fraction';
872
873 var bw = legendObj.borderwidth;
874 var bw2 = 2 * bw;
875 var itemGap = constants.itemGap;
876 var textGap = legendObj.indentation + legendObj.itemwidth + itemGap * 2;
877 var endPad = 2 * (bw + itemGap);
878
879 var yanchor = getYanchor(legendObj);
880 var isBelowPlotArea = legendObj.y < 0 || (legendObj.y === 0 && yanchor === 'top');
881 var isAbovePlotArea = legendObj.y > 1 || (legendObj.y === 1 && yanchor === 'bottom');
882
883 var traceGroupGap = legendObj.tracegroupgap;
884 var legendGroupWidths = {};
885
886 const { orientation, yref } = legendObj;
887 let { maxheight } = legendObj;
888 const useFullLayoutHeight = isBelowPlotArea || isAbovePlotArea || orientation !== "v" || yref !== "paper"
889 // Set default maxheight here since it depends on values passed in by user
890 maxheight ||= useFullLayoutHeight ? 0.5 : 1;
891 const heightToBeScaled = useFullLayoutHeight ? fullLayout.height : gs.h;
892 legendObj._maxHeight = Math.max(maxheight > 1 ? maxheight : maxheight * heightToBeScaled, 30);
893
894 var toggleRectWidth = 0;
895 legendObj._width = 0;
896 legendObj._height = 0;
897 var titleSize = getTitleSize(legendObj);
898
899 if(isVertical) {
900 traces.each(function(d) {
901 var h = d[0].height;
902 Drawing.setTranslate(this,
903 bw + titleSize[0],
904 bw + titleSize[1] + legendObj._height + h / 2 + itemGap
905 );
906 legendObj._height += h;
907 legendObj._width = Math.max(legendObj._width, d[0].width);
908 });
909
910 toggleRectWidth = textGap + legendObj._width;
911 legendObj._width += itemGap + textGap + bw2;
912 legendObj._height += endPad;
913
914 if(isGrouped) {
915 groups.each(function(d, i) {
916 Drawing.setTranslate(this, 0, i * legendObj.tracegroupgap);
917 });
918 legendObj._height += (legendObj._lgroupsLength - 1) * legendObj.tracegroupgap;

Callers 1

drawOneFunction · 0.85

Calls 5

getYanchorFunction · 0.85
getTitleSizeFunction · 0.85
getXanchorFunction · 0.85
getTraceWidthFunction · 0.85
horizontalAlignTitleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…