@@ -74,14 +74,11 @@ module.exports = function draw(gd) {
74
74
}
75
75
76
76
sliderGroups . each ( function ( sliderOpts ) {
77
- // If it has fewer than two options, it's not really a slider:
78
- if ( sliderOpts . steps . length < 2 ) return ;
79
-
80
77
var gSlider = d3 . select ( this ) ;
81
78
82
79
computeLabelSteps ( sliderOpts ) ;
83
80
84
- Plots . manageCommandObserver ( gd , sliderOpts , sliderOpts . steps , function ( data ) {
81
+ Plots . manageCommandObserver ( gd , sliderOpts , sliderOpts . _visibleSteps , function ( data ) {
85
82
// NB: Same as below. This is *not* always the same as sliderOpts since
86
83
// if a new set of steps comes in, the reference in this callback would
87
84
// be invalid. We need to refetch it from the slider group, which is
@@ -111,7 +108,7 @@ function makeSliderData(fullLayout, gd) {
111
108
112
109
for ( var i = 0 ; i < contOpts . length ; i ++ ) {
113
110
var item = contOpts [ i ] ;
114
- if ( ! item . visible || ! item . steps . length ) continue ;
111
+ if ( ! item . visible ) continue ;
115
112
item . _gd = gd ;
116
113
sliderData . push ( item ) ;
117
114
}
@@ -127,7 +124,7 @@ function keyFunction(opts) {
127
124
// Compute the dimensions (mutates sliderOpts):
128
125
function findDimensions ( gd , sliderOpts ) {
129
126
var sliderLabels = Drawing . tester . selectAll ( 'g.' + constants . labelGroupClass )
130
- . data ( sliderOpts . steps ) ;
127
+ . data ( sliderOpts . _visibleSteps ) ;
131
128
132
129
sliderLabels . enter ( ) . append ( 'g' )
133
130
. classed ( constants . labelGroupClass , true ) ;
@@ -176,7 +173,7 @@ function findDimensions(gd, sliderOpts) {
176
173
dims . inputAreaLength = Math . round ( dims . outerLength - sliderOpts . pad . l - sliderOpts . pad . r ) ;
177
174
178
175
var textableInputLength = dims . inputAreaLength - 2 * constants . stepInset ;
179
- var availableSpacePerLabel = textableInputLength / ( sliderOpts . steps . length - 1 ) ;
176
+ var availableSpacePerLabel = textableInputLength / ( sliderOpts . _stepCount - 1 ) ;
180
177
var computedSpacePerLabel = maxLabelWidth + constants . labelPadding ;
181
178
dims . labelStride = Math . max ( 1 , Math . ceil ( computedSpacePerLabel / availableSpacePerLabel ) ) ;
182
179
dims . labelHeight = labelHeight ;
@@ -260,8 +257,8 @@ function drawSlider(gd, sliderGroup, sliderOpts) {
260
257
// the *current* slider step is removed. The drawing functions will error out
261
258
// when they fail to find it, so the fix for now is that it will just draw the
262
259
// slider in the first position but will not execute the command.
263
- if ( sliderOpts . active >= sliderOpts . steps . length ) {
264
- sliderOpts . active = 0 ;
260
+ if ( ! ( ( sliderOpts . steps [ sliderOpts . active ] || { } ) . visible ) ) {
261
+ sliderOpts . active = sliderOpts . _visibleSteps [ 0 ] . _index ;
265
262
}
266
263
267
264
// These are carefully ordered for proper z-ordering:
@@ -278,7 +275,7 @@ function drawSlider(gd, sliderGroup, sliderOpts) {
278
275
// Position the rectangle:
279
276
Drawing . setTranslate ( sliderGroup , dims . lx + sliderOpts . pad . l , dims . ly + sliderOpts . pad . t ) ;
280
277
281
- sliderGroup . call ( setGripPosition , sliderOpts , sliderOpts . active / ( sliderOpts . steps . length - 1 ) , false ) ;
278
+ sliderGroup . call ( setGripPosition , sliderOpts , false ) ;
282
279
sliderGroup . call ( drawCurrentValue , sliderOpts ) ;
283
280
284
281
}
@@ -406,10 +403,11 @@ function drawLabelGroup(sliderGroup, sliderOpts) {
406
403
}
407
404
408
405
function handleInput ( gd , sliderGroup , sliderOpts , normalizedPosition , doTransition ) {
409
- var quantizedPosition = Math . round ( normalizedPosition * ( sliderOpts . steps . length - 1 ) ) ;
406
+ var quantizedPosition = Math . round ( normalizedPosition * ( sliderOpts . _stepCount - 1 ) ) ;
407
+ var quantizedIndex = sliderOpts . _visibleSteps [ quantizedPosition ] . _index ;
410
408
411
- if ( quantizedPosition !== sliderOpts . active ) {
412
- setActive ( gd , sliderGroup , sliderOpts , quantizedPosition , true , doTransition ) ;
409
+ if ( quantizedIndex !== sliderOpts . active ) {
410
+ setActive ( gd , sliderGroup , sliderOpts , quantizedIndex , true , doTransition ) ;
413
411
}
414
412
}
415
413
@@ -419,7 +417,7 @@ function setActive(gd, sliderGroup, sliderOpts, index, doCallback, doTransition)
419
417
420
418
var step = sliderOpts . steps [ sliderOpts . active ] ;
421
419
422
- sliderGroup . call ( setGripPosition , sliderOpts , sliderOpts . active / ( sliderOpts . steps . length - 1 ) , doTransition ) ;
420
+ sliderGroup . call ( setGripPosition , sliderOpts , doTransition ) ;
423
421
sliderGroup . call ( drawCurrentValue , sliderOpts ) ;
424
422
425
423
gd . emit ( 'plotly_sliderchange' , {
@@ -502,7 +500,7 @@ function attachGripEvents(item, gd, sliderGroup) {
502
500
503
501
function drawTicks ( sliderGroup , sliderOpts ) {
504
502
var tick = sliderGroup . selectAll ( 'rect.' + constants . tickRectClass )
505
- . data ( sliderOpts . steps ) ;
503
+ . data ( sliderOpts . _visibleSteps ) ;
506
504
var dims = sliderOpts . _dims ;
507
505
508
506
tick . enter ( ) . append ( 'rect' )
@@ -524,7 +522,7 @@ function drawTicks(sliderGroup, sliderOpts) {
524
522
. call ( Color . fill , isMajor ? sliderOpts . tickcolor : sliderOpts . tickcolor ) ;
525
523
526
524
Drawing . setTranslate ( item ,
527
- normalizedValueToPosition ( sliderOpts , i / ( sliderOpts . steps . length - 1 ) ) - 0.5 * sliderOpts . tickwidth ,
525
+ normalizedValueToPosition ( sliderOpts , i / ( sliderOpts . _stepCount - 1 ) ) - 0.5 * sliderOpts . tickwidth ,
528
526
( isMajor ? constants . tickOffset : constants . minorTickOffset ) + dims . currentValueTotalHeight
529
527
) ;
530
528
} ) ;
@@ -534,21 +532,28 @@ function drawTicks(sliderGroup, sliderOpts) {
534
532
function computeLabelSteps ( sliderOpts ) {
535
533
var dims = sliderOpts . _dims ;
536
534
dims . labelSteps = [ ] ;
537
- var i0 = 0 ;
538
- var nsteps = sliderOpts . steps . length ;
535
+ var nsteps = sliderOpts . _stepCount ;
539
536
540
- for ( var i = i0 ; i < nsteps ; i += dims . labelStride ) {
537
+ for ( var i = 0 ; i < nsteps ; i += dims . labelStride ) {
541
538
dims . labelSteps . push ( {
542
539
fraction : i / ( nsteps - 1 ) ,
543
- step : sliderOpts . steps [ i ]
540
+ step : sliderOpts . _visibleSteps [ i ]
544
541
} ) ;
545
542
}
546
543
}
547
544
548
- function setGripPosition ( sliderGroup , sliderOpts , position , doTransition ) {
545
+ function setGripPosition ( sliderGroup , sliderOpts , doTransition ) {
549
546
var grip = sliderGroup . select ( 'rect.' + constants . gripRectClass ) ;
550
547
551
- var x = normalizedValueToPosition ( sliderOpts , position ) ;
548
+ var quantizedIndex = 0 ;
549
+ for ( var i = 0 ; i < sliderOpts . _stepCount ; i ++ ) {
550
+ if ( sliderOpts . _visibleSteps [ i ] . _index === sliderOpts . active ) {
551
+ quantizedIndex = i ;
552
+ break ;
553
+ }
554
+ }
555
+
556
+ var x = normalizedValueToPosition ( sliderOpts , quantizedIndex / ( sliderOpts . _stepCount - 1 ) ) ;
552
557
553
558
// If this is true, then *this component* is already invoking its own command
554
559
// and has triggered its own animation.
0 commit comments