Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/plots/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ exports.manageCommandObserver = function(gd, container, commandList, onchange) {
* 3. the same property must be affected by all commands
*/
exports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue) {
var i;
var n = commandList.length;

var refBinding;

for(var i = 0; i < n; i++) {
for(i = 0; i < n; i++) {
var binding;
var command = commandList[i];
var method = command.method;
Expand Down Expand Up @@ -200,7 +201,11 @@ exports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue)
binding = bindings[0];
var value = binding.value;
if(Array.isArray(value)) {
value = value[0];
if(value.length === 1) {
value = value[0];
} else {
return false;
}
}
if(bindingsByValue) {
bindingsByValue[value] = i;
Expand Down
17 changes: 15 additions & 2 deletions test/jasmine/tests/command_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,17 @@ describe('Plots.hasSimpleAPICommandBindings', function() {
args: [{'marker.color': 20}, [2, 1]]
}]);

expect(isSimple).toEqual({
// See https://github.com/plotly/plotly.js/issues/1169 for an example of where
// this logic was a little too sophisticated. It's better to bail out and omit
// functionality than to get it wrong.
expect(isSimple).toEqual(false);

/* expect(isSimple).toEqual({
type: 'data',
prop: 'marker.color',
traces: [ 1, 2 ],
value: [ 10, 10 ]
});
});*/
});
});

Expand Down Expand Up @@ -508,6 +513,14 @@ describe('component bindings', function() {
}).catch(fail).then(done);
});

it('does not update the component if the value is not present', function(done) {
expect(gd.layout.sliders[0].active).toBe(0);

Plotly.restyle(gd, 'marker.color', 'black').then(function() {
expect(gd.layout.sliders[0].active).toBe(0);
}).catch(fail).then(done);
});

it('udpates bound components when the computed value changes', function(done) {
expect(gd.layout.sliders[0].active).toBe(0);

Expand Down
46 changes: 46 additions & 0 deletions test/jasmine/tests/updatemenus_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,52 @@ describe('update menus interactions', function() {
});
});

it('should update correctly on failed binding comparisons', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well, right @rreusser ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, a full end to end test of the specific failing case. Thanks! 👍

To elaborate, the specific difficulty is knowing when to dive into array contents. It's a little unpleasant since… do you do a deep comparison? Limit the deep comparison to when there aren't 1000 elements?

To limit the intelligence (which correlates with bugginess), my solution was to only compare arrays if they're length 1. I think that's a reasonable compromise since overall there are quite a few tests here (though this case was missed, obv 😞 )


// See https://github.com/plotly/plotly.js/issues/1169
// for more info.

var data = [{
y: [1, 2, 3],
visible: true
}, {
y: [2, 3, 1],
visible: false
}, {
y: [3, 1, 2],
visible: false
}];

var layout = {
updatemenus: [{
buttons: [{
label: 'a',
method: 'restyle',
args: ['visible', [true, false, false]]
}, {
label: 'b',
method: 'restyle',
args: ['visible', [false, true, false]]
}, {
label: 'c',
method: 'restyle',
args: ['visible', [false, false, true]]
}]
}]
};

Plotly.newPlot(gd, data, layout).then(function() {
return click(selectHeader(0));
})
.then(function() {
return click(selectButton(1));
})
.then(function() {
assertActive(gd, [1]);
})
.then(done);
});

it('should change color on mouse over', function(done) {
var INDEX_0 = 2,
INDEX_1 = gd.layout.updatemenus[1].active;
Expand Down