Skip to content

Commit 63f455d

Browse files
authored
Merge pull request #1176 from plotly/fix-command-api-bug
Add check for failed binding comparison
2 parents 125770b + 62c95f8 commit 63f455d

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed

src/plots/command.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ exports.manageCommandObserver = function(gd, container, commandList, onchange) {
145145
* 3. the same property must be affected by all commands
146146
*/
147147
exports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue) {
148+
var i;
148149
var n = commandList.length;
149150

150151
var refBinding;
151152

152-
for(var i = 0; i < n; i++) {
153+
for(i = 0; i < n; i++) {
153154
var binding;
154155
var command = commandList[i];
155156
var method = command.method;
@@ -200,7 +201,11 @@ exports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue)
200201
binding = bindings[0];
201202
var value = binding.value;
202203
if(Array.isArray(value)) {
203-
value = value[0];
204+
if(value.length === 1) {
205+
value = value[0];
206+
} else {
207+
return false;
208+
}
204209
}
205210
if(bindingsByValue) {
206211
bindingsByValue[value] = i;

test/jasmine/tests/command_test.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,17 @@ describe('Plots.hasSimpleAPICommandBindings', function() {
155155
args: [{'marker.color': 20}, [2, 1]]
156156
}]);
157157

158-
expect(isSimple).toEqual({
158+
// See https://github.com/plotly/plotly.js/issues/1169 for an example of where
159+
// this logic was a little too sophisticated. It's better to bail out and omit
160+
// functionality than to get it wrong.
161+
expect(isSimple).toEqual(false);
162+
163+
/* expect(isSimple).toEqual({
159164
type: 'data',
160165
prop: 'marker.color',
161166
traces: [ 1, 2 ],
162167
value: [ 10, 10 ]
163-
});
168+
});*/
164169
});
165170
});
166171

@@ -508,6 +513,14 @@ describe('component bindings', function() {
508513
}).catch(fail).then(done);
509514
});
510515

516+
it('does not update the component if the value is not present', function(done) {
517+
expect(gd.layout.sliders[0].active).toBe(0);
518+
519+
Plotly.restyle(gd, 'marker.color', 'black').then(function() {
520+
expect(gd.layout.sliders[0].active).toBe(0);
521+
}).catch(fail).then(done);
522+
});
523+
511524
it('udpates bound components when the computed value changes', function(done) {
512525
expect(gd.layout.sliders[0].active).toBe(0);
513526

test/jasmine/tests/updatemenus_test.js

+46
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,52 @@ describe('update menus interactions', function() {
462462
});
463463
});
464464

465+
it('should update correctly on failed binding comparisons', function(done) {
466+
467+
// See https://github.com/plotly/plotly.js/issues/1169
468+
// for more info.
469+
470+
var data = [{
471+
y: [1, 2, 3],
472+
visible: true
473+
}, {
474+
y: [2, 3, 1],
475+
visible: false
476+
}, {
477+
y: [3, 1, 2],
478+
visible: false
479+
}];
480+
481+
var layout = {
482+
updatemenus: [{
483+
buttons: [{
484+
label: 'a',
485+
method: 'restyle',
486+
args: ['visible', [true, false, false]]
487+
}, {
488+
label: 'b',
489+
method: 'restyle',
490+
args: ['visible', [false, true, false]]
491+
}, {
492+
label: 'c',
493+
method: 'restyle',
494+
args: ['visible', [false, false, true]]
495+
}]
496+
}]
497+
};
498+
499+
Plotly.newPlot(gd, data, layout).then(function() {
500+
return click(selectHeader(0));
501+
})
502+
.then(function() {
503+
return click(selectButton(1));
504+
})
505+
.then(function() {
506+
assertActive(gd, [1]);
507+
})
508+
.then(done);
509+
});
510+
465511
it('should change color on mouse over', function(done) {
466512
var INDEX_0 = 2,
467513
INDEX_1 = gd.layout.updatemenus[1].active;

0 commit comments

Comments
 (0)