Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 40fc7f9

Browse files
committed
plots: add linkSubplot method
- which handles fullLayout._plots creation and reference updates - rm block in Plots.transition that used to handle that
1 parent ff26691 commit 40fc7f9

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

src/plots/plots.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ plots.supplyDefaults = function(gd) {
414414
ax.setScale();
415415
}
416416

417+
// relink / initialize subplot axis objects
418+
plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout);
419+
417420
// update object references in calcdata
418421
if((gd.calcdata || []).length === newFullData.length) {
419422
for(i = 0; i < newFullData.length; i++) {
@@ -559,6 +562,41 @@ function relinkPrivateKeys(toContainer, fromContainer) {
559562
}
560563
}
561564

565+
plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
566+
var oldSubplots = oldFullLayout._plots || {},
567+
newSubplots = newFullLayout._plots = {};
568+
569+
var mockGd = {
570+
data: newFullData,
571+
_fullLayout: newFullLayout
572+
};
573+
574+
var ids = Plotly.Axes.getSubplots(mockGd);
575+
576+
function getAxisFunc(subplot, axLetter) {
577+
return function() { return Plotly.Axes.getFromId(mockGd, subplot, axLetter); };
578+
}
579+
580+
for(var i = 0; i < ids.length; i++) {
581+
var id = ids[i],
582+
oldSubplot = oldSubplots[id],
583+
plotinfo;
584+
585+
if(oldSubplot) {
586+
plotinfo = newSubplots[id] = oldSubplot;
587+
}
588+
else {
589+
plotinfo = newSubplots[id] = {};
590+
plotinfo.id = id;
591+
}
592+
593+
plotinfo.x = getAxisFunc(id, 'x');
594+
plotinfo.y = getAxisFunc(id, 'y');
595+
plotinfo.xaxis = plotinfo.x();
596+
plotinfo.yaxis = plotinfo.y();
597+
}
598+
};
599+
562600
plots.supplyDataDefaults = function(dataIn, dataOut, layout) {
563601
var modules = layout._modules = [],
564602
basePlotModules = layout._basePlotModules = [],
@@ -1363,7 +1401,8 @@ plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts)
13631401
var transitionedTraces = [];
13641402

13651403
function prepareTransitions() {
1366-
var plotinfo, i;
1404+
var i;
1405+
13671406
for(i = 0; i < traceIndices.length; i++) {
13681407
var traceIdx = traceIndices[i];
13691408
var trace = gd._fullData[traceIdx];
@@ -1410,19 +1449,6 @@ plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts)
14101449
// transitions:
14111450
plots.supplyDefaults(gd);
14121451

1413-
// This step fies the .xaxis and .yaxis references that otherwise
1414-
// aren't updated by the supplyDefaults step:
1415-
var subplots = Plotly.Axes.getSubplots(gd);
1416-
1417-
// Polar does not have _plots:
1418-
if(gd._fullLayout._plots) {
1419-
for(i = 0; i < subplots.length; i++) {
1420-
plotinfo = gd._fullLayout._plots[subplots[i]];
1421-
plotinfo.xaxis = plotinfo.x();
1422-
plotinfo.yaxis = plotinfo.y();
1423-
}
1424-
}
1425-
14261452
plots.doCalcdata(gd);
14271453

14281454
ErrorBars.calc(gd);

0 commit comments

Comments
 (0)