Skip to content

Commit a554cad

Browse files
committed
Add equivalent command API test for udpatemenus
1 parent d35ee35 commit a554cad

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

src/components/sliders/draw.js

-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ function handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, doTransiti
359359
var quantizedPosition = Math.round(normalizedPosition * (sliderOpts.steps.length - 1));
360360

361361
if(quantizedPosition !== sliderOpts.active) {
362-
363362
setActive(gd, sliderGroup, sliderOpts, quantizedPosition, true, doTransition);
364363
}
365364
}

src/components/updatemenus/defaults.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ module.exports = function updateMenusDefaults(layoutIn, layoutOut) {
3333
// used to determine object constancy
3434
menuOut._index = i;
3535

36+
menuOut._input.active = menuOut.active;
37+
3638
contOut.push(menuOut);
3739
}
3840
};
@@ -48,7 +50,9 @@ function menuDefaults(menuIn, menuOut, layoutOut) {
4850
var visible = coerce('visible', buttons.length > 0);
4951
if(!visible) return;
5052

51-
coerce('active');
53+
// Default to zero since active must be *something*:
54+
coerce('active', 0);
55+
5256
coerce('direction');
5357
coerce('type');
5458
coerce('showactive');

test/jasmine/tests/command_test.js

+56-3
Original file line numberDiff line numberDiff line change
@@ -525,21 +525,21 @@ describe('attaching component bindings', function() {
525525
destroyGraphDiv(gd);
526526
});
527527

528-
it('attaches bindings when events are added', function(done) {
528+
it('attaches and updates bindings for sliders', function(done) {
529529
expect(gd._internalEv._events.plotly_animatingframe).toBeUndefined();
530530

531531
Plotly.relayout(gd, {
532532
sliders: [{
533533
// This one gets bindings:
534534
steps: [
535535
{label: 'first', method: 'restyle', args: ['marker.color', 'red']},
536-
{label: 'first', method: 'restyle', args: ['marker.color', 'blue']},
536+
{label: 'second', method: 'restyle', args: ['marker.color', 'blue']},
537537
]
538538
}, {
539539
// This one does *not*:
540540
steps: [
541541
{label: 'first', method: 'restyle', args: ['line.color', 'red']},
542-
{label: 'first', method: 'restyle', args: ['marker.color', 'blue']},
542+
{label: 'second', method: 'restyle', args: ['marker.color', 'blue']},
543543
]
544544
}]
545545
}).then(function() {
@@ -577,4 +577,57 @@ describe('attaching component bindings', function() {
577577
expect(gd._internalEv._events.plotly_animatingframe).toBeUndefined();
578578
}).catch(fail).then(done);
579579
});
580+
581+
it('attaches and updates bindings for updatemenus', function(done) {
582+
expect(gd._internalEv._events.plotly_animatingframe).toBeUndefined();
583+
584+
Plotly.relayout(gd, {
585+
updatemenus: [{
586+
// This one gets bindings:
587+
buttons: [
588+
{label: 'first', method: 'restyle', args: ['marker.color', 'red']},
589+
{label: 'second', method: 'restyle', args: ['marker.color', 'blue']},
590+
]
591+
}, {
592+
// This one does *not*:
593+
buttons: [
594+
{label: 'first', method: 'restyle', args: ['line.color', 'red']},
595+
{label: 'second', method: 'restyle', args: ['marker.color', 'blue']},
596+
]
597+
}]
598+
}).then(function() {
599+
// Check that it has attached a listener:
600+
expect(typeof gd._internalEv._events.plotly_animatingframe).toBe('function');
601+
602+
// Confirm the first position is selected:
603+
expect(gd.layout.updatemenus[0].active).toBe(0);
604+
605+
// Modify the plot
606+
return Plotly.restyle(gd, {'marker.color': 'blue'});
607+
}).then(function() {
608+
// Confirm that this has changed the slider position:
609+
expect(gd.layout.updatemenus[0].active).toBe(1);
610+
611+
// Swap the values of the components:
612+
return Plotly.relayout(gd, {
613+
'updatemenus[0].buttons[0].args[1]': 'green',
614+
'updatemenus[0].buttons[1].args[1]': 'red'
615+
});
616+
}).then(function() {
617+
return Plotly.restyle(gd, {'marker.color': 'green'});
618+
}).then(function() {
619+
// Confirm that the lookup table has been updated:
620+
expect(gd.layout.updatemenus[0].active).toBe(0);
621+
622+
// Check that it still has one attached listener:
623+
expect(typeof gd._internalEv._events.plotly_animatingframe).toBe('function');
624+
625+
// Change this to a non-simple binding:
626+
return Plotly.relayout(gd, {'updatemenus[0].buttons[0].args[0]': 'line.color'});
627+
}).then(function() {
628+
// Bindings are no longer simple, so check to ensure they have
629+
// been removed
630+
expect(gd._internalEv._events.plotly_animatingframe).toBeUndefined();
631+
}).catch(fail).then(done);
632+
});
580633
});

0 commit comments

Comments
 (0)