Skip to content

numeric sort for component edits #1639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2017
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
3 changes: 2 additions & 1 deletion src/plot_api/manage_arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var nestedProperty = require('../lib/nested_property');
var isPlainObject = require('../lib/is_plain_object');
var noop = require('../lib/noop');
var Loggers = require('../lib/loggers');
var sorterAsc = require('../lib/search').sorterAsc;
var Registry = require('../registry');


Expand Down Expand Up @@ -101,7 +102,7 @@ exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np,
return true;
}

var componentNums = Object.keys(edits).map(Number).sort(),
var componentNums = Object.keys(edits).map(Number).sort(sorterAsc),
componentArrayIn = np.get(),
componentArray = componentArrayIn || [],
// componentArrayFull is used just to keep splices in line between
Expand Down
27 changes: 27 additions & 0 deletions test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,33 @@ describe('annotations relayout', function() {
.then(done);
});

it('should sort correctly when index>10', 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.

nice test!

var addall = {};
var delall = {};

// leave the first one alone, but delete and re-add all the others
for(var i = 1; i < gd.layout.annotations.length; i++) {
addall['annotations[' + i + ']'] = {text: i, x: i / 10, y: 0};
delall['annotations[' + i + ']'] = null;
}

Plotly.relayout(gd, delall)
.then(function() {
expect(gd.layout.annotations).toEqual([mock.layout.annotations[0]]);

return Plotly.relayout(gd, addall);
})
.then(function() {
var annotations = gd.layout.annotations;
expect(annotations.length).toBe(mock.layout.annotations.length);
for(var i = 1; i < annotations.length; i++) {
expect(annotations[i].text).toBe(i);
}
})
.catch(failTest)
.then(done);
});

it('should be able update annotations', function(done) {
var updateObj = { 'annotations[0].text': 'hello' };

Expand Down