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

Function findDimensions

src/components/sliders/draw.js:119–245  ·  view source on GitHub ↗
(gd, sliderOpts)

Source from the content-addressed store, hash-verified

117
118// Compute the dimensions (mutates sliderOpts):
119function findDimensions(gd, sliderOpts) {
120 var sliderLabels = Drawing.tester.selectAll('g.' + constants.labelGroupClass)
121 .data(sliderOpts._visibleSteps);
122
123 sliderLabels.enter().append('g')
124 .classed(constants.labelGroupClass, true);
125
126 // loop over fake buttons to find width / height
127 var maxLabelWidth = 0;
128 var labelHeight = 0;
129 sliderLabels.each(function(stepOpts) {
130 var labelGroup = d3.select(this);
131
132 var text = drawLabel(labelGroup, {step: stepOpts}, sliderOpts);
133
134 var textNode = text.node();
135 if(textNode) {
136 var bBox = Drawing.bBox(textNode);
137 labelHeight = Math.max(labelHeight, bBox.height);
138 maxLabelWidth = Math.max(maxLabelWidth, bBox.width);
139 }
140 });
141
142 sliderLabels.remove();
143
144 var dims = sliderOpts._dims = {};
145
146 dims.inputAreaWidth = Math.max(
147 constants.railWidth,
148 constants.gripHeight
149 );
150
151 // calculate some overall dimensions - some of these are needed for
152 // calculating the currentValue dimensions
153 var graphSize = gd._fullLayout._size;
154 dims.lx = graphSize.l + graphSize.w * sliderOpts.x;
155 dims.ly = graphSize.t + graphSize.h * (1 - sliderOpts.y);
156
157 if(sliderOpts.lenmode === 'fraction') {
158 // fraction:
159 dims.outerLength = Math.round(graphSize.w * sliderOpts.len);
160 } else {
161 // pixels:
162 dims.outerLength = sliderOpts.len;
163 }
164
165 // The length of the rail, *excluding* padding on either end:
166 dims.inputAreaStart = 0;
167 dims.inputAreaLength = Math.round(dims.outerLength - sliderOpts.pad.l - sliderOpts.pad.r);
168
169 var textableInputLength = dims.inputAreaLength - 2 * constants.stepInset;
170 var availableSpacePerLabel = textableInputLength / (sliderOpts._stepCount - 1);
171 var computedSpacePerLabel = maxLabelWidth + constants.labelPadding;
172 dims.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));
173 dims.labelHeight = labelHeight;
174
175 // loop over all possible values for currentValue to find the
176 // area we need for it

Callers 1

draw.jsFile · 0.70

Calls 3

drawLabelFunction · 0.85
drawCurrentValueFunction · 0.85
autoMarginIdFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…