Skip to content

Commit 78ab4c6

Browse files
committed
ignore invalid trace indices in restyle and update
1 parent 9899230 commit 78ab4c6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/plot_api/helpers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ exports.coerceTraceIndices = function(gd, traceIndices) {
490490
else if(!Array.isArray(traceIndices) || !traceIndices.length) {
491491
return gd.data.map(function(_, i) { return i; });
492492
}
493+
else if(Array.isArray(traceIndices)) {
494+
return traceIndices.filter(function(i) {return i < gd.data.length;});
495+
}
493496

494497
return traceIndices;
495498
};

test/jasmine/tests/plot_api_test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,18 @@ describe('Test plot api', function() {
921921
expect(gd._fullData[0].marker.color).toBe('blue');
922922
});
923923

924+
it('ignores invalid trace indices', function() {
925+
var gd = {
926+
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
927+
layout: {}
928+
};
929+
930+
mockDefaultsAndCalc(gd);
931+
932+
// Call restyle on an invalid trace indice
933+
Plotly.restyle(gd, {'type': 'scatter', 'marker.color': 'scatter'}, [1]);
934+
});
935+
924936
it('restores null values to defaults', function() {
925937
var gd = {
926938
data: [{x: [1, 2, 3], y: [1, 2, 3], type: 'scatter'}],
@@ -2580,6 +2592,11 @@ describe('Test plot api', function() {
25802592
.catch(failTest)
25812593
.then(done);
25822594
});
2595+
2596+
it('ignores invalid trace indices', function() {
2597+
// Call update on an invalid trace indice
2598+
Plotly.update(gd, {'type': 'scatter', 'marker.color': 'scatter'}, {}, [1]);
2599+
});
25832600
});
25842601

25852602
describe('@noCIdep Plotly.react', function() {

0 commit comments

Comments
 (0)