Skip to content

Commit 0bb38e9

Browse files
committed
reorder sliders findDimensions so dummy calculations always succeed
1 parent c908ed4 commit 0bb38e9

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/components/sliders/draw.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,8 @@ function findDimensions(gd, sliderOpts) {
151151
constants.gripHeight
152152
);
153153

154-
sliderOpts.currentValueMaxWidth = 0;
155-
sliderOpts.currentValueHeight = 0;
156-
sliderOpts.currentValueTotalHeight = 0;
157-
sliderOpts.currentValueMaxLines = 1;
158-
159-
if(sliderOpts.currentvalue.visible) {
160-
// Get the dimensions of the current value label:
161-
var dummyGroup = Drawing.tester.append('g');
162-
163-
sliderLabels.each(function(stepOpts) {
164-
var curValPrefix = drawCurrentValue(dummyGroup, sliderOpts, stepOpts.label);
165-
var curValSize = (curValPrefix.node() && Drawing.bBox(curValPrefix.node())) || {width: 0, height: 0};
166-
var lines = svgTextUtils.lineCount(curValPrefix);
167-
sliderOpts.currentValueMaxWidth = Math.max(sliderOpts.currentValueMaxWidth, Math.ceil(curValSize.width));
168-
sliderOpts.currentValueHeight = Math.max(sliderOpts.currentValueHeight, Math.ceil(curValSize.height));
169-
sliderOpts.currentValueMaxLines = Math.max(sliderOpts.currentValueMaxLines, lines);
170-
});
171-
172-
sliderOpts.currentValueTotalHeight = sliderOpts.currentValueHeight + sliderOpts.currentvalue.offset;
173-
174-
dummyGroup.remove();
175-
}
176-
154+
// calculate some overall dimensions - some of these are needed for
155+
// calculating the currentValue dimensions
177156
var graphSize = gd._fullLayout._size;
178157
sliderOpts.lx = graphSize.l + graphSize.w * sliderOpts.x;
179158
sliderOpts.ly = graphSize.t + graphSize.h * (1 - sliderOpts.y);
@@ -200,6 +179,31 @@ function findDimensions(gd, sliderOpts) {
200179
sliderOpts.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));
201180
sliderOpts.labelHeight = labelHeight;
202181

182+
// loop over all possible values for currentValue to find the
183+
// area we need for it
184+
sliderOpts.currentValueMaxWidth = 0;
185+
sliderOpts.currentValueHeight = 0;
186+
sliderOpts.currentValueTotalHeight = 0;
187+
sliderOpts.currentValueMaxLines = 1;
188+
189+
if(sliderOpts.currentvalue.visible) {
190+
// Get the dimensions of the current value label:
191+
var dummyGroup = Drawing.tester.append('g');
192+
193+
sliderLabels.each(function(stepOpts) {
194+
var curValPrefix = drawCurrentValue(dummyGroup, sliderOpts, stepOpts.label);
195+
var curValSize = (curValPrefix.node() && Drawing.bBox(curValPrefix.node())) || {width: 0, height: 0};
196+
var lines = svgTextUtils.lineCount(curValPrefix);
197+
sliderOpts.currentValueMaxWidth = Math.max(sliderOpts.currentValueMaxWidth, Math.ceil(curValSize.width));
198+
sliderOpts.currentValueHeight = Math.max(sliderOpts.currentValueHeight, Math.ceil(curValSize.height));
199+
sliderOpts.currentValueMaxLines = Math.max(sliderOpts.currentValueMaxLines, lines);
200+
});
201+
202+
sliderOpts.currentValueTotalHeight = sliderOpts.currentValueHeight + sliderOpts.currentvalue.offset;
203+
204+
dummyGroup.remove();
205+
}
206+
203207
sliderOpts.height = sliderOpts.currentValueTotalHeight + constants.tickOffset + sliderOpts.ticklen + constants.labelOffset + sliderOpts.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;
204208

205209
var xanchor = 'left';

0 commit comments

Comments
 (0)