Skip to content

Commit 70c882b

Browse files
committed
keep _fullLayout container arrays in sync with splices in layout
1 parent c6378b1 commit 70c882b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/plot_api/manage_arrays.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
103103

104104
var componentNums = Object.keys(edits).map(Number).sort(),
105105
componentArrayIn = np.get(),
106-
componentArray = componentArrayIn || [];
106+
componentArray = componentArrayIn || [],
107+
// componentArrayFull is used just to keep splices in line between
108+
// full and input arrays, so private keys can be copied over after
109+
// redoing supplyDefaults
110+
// TODO: this assumes componentArray is in gd.layout - which will not be
111+
// true after we extend this to restyle
112+
componentArrayFull = nestedProperty(fullLayout, componentType).get();
107113

108114
var deletes = [],
109115
firstIndexChange = -1,
@@ -142,6 +148,7 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
142148
else if(adding) {
143149
if(objVal === 'add') objVal = {};
144150
componentArray.splice(componentNum, 0, objVal);
151+
if(componentArrayFull) componentArrayFull.splice(componentNum, 0, {});
145152
}
146153
else {
147154
Loggers.warn('Unrecognized full object edit value',
@@ -160,6 +167,9 @@ exports.editContainerArray = function editContainerArray(gd, np, edits, flags) {
160167
// now do deletes
161168
for(i = deletes.length - 1; i >= 0; i--) {
162169
componentArray.splice(deletes[i], 1);
170+
// TODO: this drops private keys that had been stored in componentArrayFull
171+
// does this have any ill effects?
172+
if(componentArrayFull) componentArrayFull.splice(deletes[i], 1);
163173
}
164174

165175
if(!componentArray.length) np.set(null);

test/jasmine/tests/annotations_test.js

+23
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ describe('annotations relayout', function() {
255255
anno1 = Lib.extendFlat(annos[1]),
256256
anno3 = Lib.extendFlat(annos[3]);
257257

258+
// store some (unused) private keys and make sure they are copied over
259+
// correctly during relayout
260+
var fullAnnos = gd._fullLayout.annotations;
261+
fullAnnos[0]._boo = 'hoo';
262+
fullAnnos[1]._foo = 'bar';
263+
fullAnnos[3]._cheese = ['gorgonzola', 'gouda', 'gloucester'];
264+
// this one gets lost
265+
fullAnnos[2]._splat = 'the cat';
266+
258267
Plotly.relayout(gd, {
259268
'annotations[0].text': 'tortilla',
260269
'annotations[0].x': 3.45,
@@ -266,21 +275,35 @@ describe('annotations relayout', function() {
266275
.then(function() {
267276
expect(countAnnotations()).toEqual(len);
268277

278+
var fullAnnosAfter = gd._fullLayout.annotations,
279+
fullStr = JSON.stringify(fullAnnosAfter);
280+
269281
assertText(0, 'tortilla');
270282
anno0.text = 'tortilla';
271283
expect(annos[0]).toEqual(anno0);
284+
expect(fullAnnosAfter[0]._boo).toBe('hoo');
285+
272286

273287
assertText(1, 'chips');
274288
expect(annos[1]).toEqual({text: 'chips', x: 1.1, y: 2.2});
289+
expect(fullAnnosAfter[1]._foo).toBeUndefined();
275290

276291
assertText(2, 'guacamole');
277292
anno1.text = 'guacamole';
278293
expect(annos[2]).toEqual(anno1);
294+
expect(fullAnnosAfter[2]._foo).toBe('bar');
295+
expect(fullAnnosAfter[2]._splat).toBeUndefined();
279296

280297
assertText(3, 'lime');
281298
anno3.text = 'lime';
282299
expect(annos[3]).toEqual(anno3);
300+
expect(fullAnnosAfter[3]._cheese).toEqual(['gorgonzola', 'gouda', 'gloucester']);
301+
302+
expect(fullStr.indexOf('_splat')).toBe(-1);
303+
expect(fullStr.indexOf('the cat')).toBe(-1);
304+
283305
expect(Loggers.warn).not.toHaveBeenCalled();
306+
284307
})
285308
.catch(failTest)
286309
.then(done);

0 commit comments

Comments
 (0)