Skip to content

Commit 2bac6ef

Browse files
authored
Merge pull request #1639 from plotly/component-sort
numeric sort for component edits
2 parents ce970f1 + a0cca65 commit 2bac6ef

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/plot_api/manage_arrays.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var nestedProperty = require('../lib/nested_property');
1313
var isPlainObject = require('../lib/is_plain_object');
1414
var noop = require('../lib/noop');
1515
var Loggers = require('../lib/loggers');
16+
var sorterAsc = require('../lib/search').sorterAsc;
1617
var Registry = require('../registry');
1718

1819

@@ -101,7 +102,7 @@ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np,
101102
return true;
102103
}
103104

104-
var componentNums = Object.keys(edits).map(Number).sort(),
105+
var componentNums = Object.keys(edits).map(Number).sort(sorterAsc),
105106
componentArrayIn = np.get(),
106107
componentArray = componentArrayIn || [],
107108
// componentArrayFull is used just to keep splices in line between

test/jasmine/tests/annotations_test.js

+27
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)