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 1 commit
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
2 changes: 1 addition & 1 deletion src/plot_api/manage_arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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(function(a, b) { return a - b; }),
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to use Lib.sorterAsc to DRY it up 🌴

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ah thanks - should've guessed we'd have that already exposed somewhere!

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