Skip to content

Commit ef87937

Browse files
committed
relayout: merge all array container update into one block
- simply use p.set() to update - the recent relinkPrivateKeys modifs allow for gd.layout and gd._fullLayout array containers to not have the same length - set undo val to null when adding a new item, to remove when Queue.undo() is called.
1 parent ec0b0a4 commit ef87937

File tree

2 files changed

+15
-44
lines changed

2 files changed

+15
-44
lines changed

src/plot_api/plot_api.js

+10-36
Original file line numberDiff line numberDiff line change
@@ -1815,8 +1815,7 @@ function _relayout(gd, aobj) {
18151815
// trunk nodes (everything except the leaf)
18161816
ptrunk = p.parts.slice(0, pend).join('.'),
18171817
parentIn = Lib.nestedProperty(gd.layout, ptrunk).get(),
1818-
parentFull = Lib.nestedProperty(fullLayout, ptrunk).get(),
1819-
diff;
1818+
parentFull = Lib.nestedProperty(fullLayout, ptrunk).get();
18201819

18211820
if(vi === undefined) continue;
18221821

@@ -1950,42 +1949,17 @@ function _relayout(gd, aobj) {
19501949
drawOne(gd, objNum, p.parts.slice(2).join('.'), aobj[ai]);
19511950
delete aobj[ai];
19521951
}
1953-
else if(p.parts[0] === 'images') {
1954-
var update = Lib.objectFromPath(ai, vi);
1955-
Lib.extendDeepAll(gd.layout, update);
1952+
else if(
1953+
Plots.layoutArrayContainers.indexOf(p.parts[0]) !== -1 ||
1954+
(p.parts[0] === 'mapbox' && p.parts[1] === 'layers')
1955+
) {
19561956

1957-
Registry.getComponentMethod('images', 'supplyLayoutDefaults')(gd.layout, gd._fullLayout);
1958-
Registry.getComponentMethod('images', 'draw')(gd);
1959-
}
1960-
else if(p.parts[0] === 'mapbox' && p.parts[1] === 'layers') {
1961-
Lib.extendDeepAll(gd.layout, Lib.objectFromPath(ai, vi));
1962-
1963-
// append empty container to mapbox.layers
1964-
// so that relinkPrivateKeys does not complain
1965-
1966-
var fullLayers = (gd._fullLayout.mapbox || {}).layers || [];
1967-
diff = (p.parts[2] + 1) - fullLayers.length;
1968-
1969-
for(i = 0; i < diff; i++) fullLayers.push({});
1970-
1971-
flags.doplot = true;
1972-
}
1973-
else if(p.parts[0] === 'updatemenus') {
1974-
Lib.extendDeepAll(gd.layout, Lib.objectFromPath(ai, vi));
1975-
1976-
var menus = gd._fullLayout.updatemenus || [];
1977-
diff = (p.parts[2] + 1) - menus.length;
1978-
1979-
for(i = 0; i < diff; i++) menus.push({});
1980-
flags.doplot = true;
1981-
}
1982-
else if(p.parts[0] === 'sliders') {
1983-
Lib.extendDeepAll(gd.layout, Lib.objectFromPath(ai, vi));
1984-
1985-
var sliders = gd._fullLayout.sliders || [];
1986-
diff = (p.parts[2] + 1) - sliders.length;
1957+
// if adding a new item, make sure undo will remove it
1958+
if(isNumeric(p.parts[plen - 1]) && p.get() === undefined) {
1959+
undoit[ai] = null;
1960+
}
19871961

1988-
for(i = 0; i < diff; i++) sliders.push({});
1962+
p.set(vi);
19891963
flags.doplot = true;
19901964
}
19911965
// alter gd.layout

src/plots/plots.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,9 @@ plots.extendObjectWithContainers = function(dest, src, containerPaths) {
14241424
return dest;
14251425
};
14261426

1427+
plots.dataArrayContainers = ['transforms'];
1428+
plots.layoutArrayContainers = ['annotations', 'shapes', 'images', 'sliders', 'updatemenus'];
1429+
14271430
/*
14281431
* Extend a trace definition. This method:
14291432
*
@@ -1433,7 +1436,7 @@ plots.extendObjectWithContainers = function(dest, src, containerPaths) {
14331436
* The result is the original object reference with the new contents merged in.
14341437
*/
14351438
plots.extendTrace = function(destTrace, srcTrace) {
1436-
return plots.extendObjectWithContainers(destTrace, srcTrace, ['transforms']);
1439+
return plots.extendObjectWithContainers(destTrace, srcTrace, plots.dataArrayContainers);
14371440
};
14381441

14391442
/*
@@ -1446,13 +1449,7 @@ plots.extendTrace = function(destTrace, srcTrace) {
14461449
* The result is the original object reference with the new contents merged in.
14471450
*/
14481451
plots.extendLayout = function(destLayout, srcLayout) {
1449-
return plots.extendObjectWithContainers(destLayout, srcLayout, [
1450-
'annotations',
1451-
'shapes',
1452-
'images',
1453-
'sliders',
1454-
'updatemenus'
1455-
]);
1452+
return plots.extendObjectWithContainers(destLayout, srcLayout, plots.layoutArrayContainers);
14561453
};
14571454

14581455
/**

0 commit comments

Comments
 (0)