Skip to content

Commit

Permalink
Merge pull request #3053 from plotly/fixup-lib-warn-when-replacing-ar…
Browse files Browse the repository at this point in the history
…ray-cont

Do not to look for 'add' or 'remove' when replacing array containers
  • Loading branch information
etpinard authored Sep 26, 2018
2 parents a070a8d + 5491633 commit 67a05c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1979,9 +1979,10 @@ function _relayout(gd, aobj) {
var obji = (componentArray || [])[i] || {};
var updateValObject = valObject || {editType: 'calc'};

if(propStr === '') {
if(i !== '' && propStr === '') {
// special handling of undoit if we're adding or removing an element
// ie 'annotations[2]' which can be {...} (add) or null (remove)
// ie 'annotations[2]' which can be {...} (add) or null,
// does not work when replacing the entire array
if(manageArrays.isAddVal(vi)) {
undoit[ai] = null;
} else if(manageArrays.isRemoveVal(vi)) {
Expand All @@ -1990,7 +1991,6 @@ function _relayout(gd, aobj) {
Lib.warn('unrecognized full object value', aobj);
}
}

editTypes.update(flags, updateValObject);

// prepare the edits object we'll send to applyContainerArrayChanges
Expand Down
3 changes: 3 additions & 0 deletions test/jasmine/tests/shapes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ describe('Test shapes:', function() {
});

it('can replace the shapes array', function(done) {
spyOn(Lib, 'warn');

Plotly.relayout(gd, { shapes: [
getRandomShape(),
getRandomShape()
Expand All @@ -375,6 +377,7 @@ describe('Test shapes:', function() {
expect(countShapePathsInLowerLayer()).toEqual(0);
expect(countShapePathsInSubplots()).toEqual(0);
expect(gd.layout.shapes.length).toBe(2);
expect(Lib.warn).not.toHaveBeenCalled();
})
.catch(failTest)
.then(done);
Expand Down

0 comments on commit 67a05c7

Please sign in to comment.