Skip to content

Commit b0338bd

Browse files
committed
relayout: fix 'annotations[i].[key]': null bug
- previously all relayout calls with leading `annotations` or `shapes` and value `null` were replaced with value `'remove'` - now make sure that only `annotations/shapes[i]: null` are replaced with `'remove'`
1 parent de50756 commit b0338bd

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/plot_api/plot_api.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,13 +1917,14 @@ function _relayout(gd, aobj) {
19171917
objList = layout[objType] || [],
19181918
obji = objList[objNum] || {};
19191919

1920-
// new API, remove annotation / shape with `null`
1921-
if(vi === null) aobj[ai] = 'remove';
1922-
19231920
// if p.parts is just an annotation number, and val is either
19241921
// 'add' or an entire annotation to add, the undo is 'remove'
19251922
// if val is 'remove' then undo is the whole annotation object
19261923
if(p.parts.length === 2) {
1924+
1925+
// new API, remove annotation / shape with `null`
1926+
if(vi === null) aobj[ai] = 'remove';
1927+
19271928
if(aobj[ai] === 'add' || Lib.isPlainObject(aobj[ai])) {
19281929
undoit[ai] = 'remove';
19291930
}

test/jasmine/tests/annotations_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,27 @@ describe('annotations relayout', function() {
8686
done();
8787
});
8888
});
89+
90+
it('should be able update annotations', function(done) {
91+
92+
function assertText(index, expected) {
93+
var query = '.annotation[data-index="' + index + '"]',
94+
actual = d3.select(query).select('text').text();
95+
96+
expect(actual).toEqual(expected);
97+
}
98+
99+
assertText(0, 'left top');
100+
101+
Plotly.relayout(gd, 'annotations[0].text', 'hello').then(function() {
102+
assertText(0, 'hello');
103+
104+
return Plotly.relayout(gd, 'annotations[0].text', null);
105+
})
106+
.then(function() {
107+
assertText(0, 'new text');
108+
})
109+
.then(done);
110+
111+
});
89112
});

0 commit comments

Comments
 (0)