Skip to content

Commit d87307c

Browse files
committed
numeric sort for component edits
1 parent 082bfc1 commit d87307c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/plot_api/manage_arrays.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np,
101101
return true;
102102
}
103103

104-
var componentNums = Object.keys(edits).map(Number).sort(),
104+
var componentNums = Object.keys(edits).map(Number).sort(function(a, b) { return a - b; }),
105105
componentArrayIn = np.get(),
106106
componentArray = componentArrayIn || [],
107107
// componentArrayFull is used just to keep splices in line between

test/jasmine/tests/annotations_test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,33 @@ describe('annotations relayout', function() {
223223
.then(done);
224224
});
225225

226+
it('should sort correctly when index>10', function(done) {
227+
var addall = {};
228+
var delall = {};
229+
230+
// leave the first one alone, but delete and re-add all the others
231+
for(var i = 1; i < gd.layout.annotations.length; i++) {
232+
addall['annotations[' + i + ']'] = {text: i, x: i / 10, y: 0};
233+
delall['annotations[' + i + ']'] = null;
234+
}
235+
236+
Plotly.relayout(gd, delall)
237+
.then(function() {
238+
expect(gd.layout.annotations).toEqual([mock.layout.annotations[0]]);
239+
240+
return Plotly.relayout(gd, addall);
241+
})
242+
.then(function() {
243+
var annotations = gd.layout.annotations;
244+
expect(annotations.length).toBe(mock.layout.annotations.length);
245+
for(var i = 1; i < annotations.length; i++) {
246+
expect(annotations[i].text).toBe(i);
247+
}
248+
})
249+
.catch(failTest)
250+
.then(done);
251+
});
252+
226253
it('should be able update annotations', function(done) {
227254
var updateObj = { 'annotations[0].text': 'hello' };
228255

0 commit comments

Comments
 (0)