Skip to content

Commit 4786b6e

Browse files
committed
simplify redundant title removal
1 parent 8804311 commit 4786b6e

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

Diff for: src/plots/cartesian/index.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -253,19 +253,29 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
253253
.remove();
254254
}
255255

256+
var oldSubplotList = oldFullLayout._subplots || {};
257+
var newSubplotList = newFullLayout._subplots || {xaxis: [], yaxis: []};
258+
259+
// delete any titles we don't need anymore
260+
// check if axis list has changed, and if so clear old titles
261+
if(oldSubplotList.xaxis && oldSubplotList.yaxis) {
262+
var oldAxIDs = oldSubplotList.xaxis.concat(oldSubplotList.yaxis);
263+
var newAxIDs = newSubplotList.xaxis.concat(newSubplotList.yaxis);
264+
265+
for(i = 0; i < oldAxIDs.length; i++) {
266+
if(newAxIDs.indexOf(oldAxIDs[i]) === -1) {
267+
oldFullLayout._infolayer.selectAll('.g-' + oldAxIDs[i] + 'title').remove();
268+
}
269+
}
270+
}
271+
272+
// if we've gotten rid of all cartesian traces, remove all the subplot svg items
256273
var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian'));
257274
var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian'));
258275

259276
if(hadCartesian && !hasCartesian) {
260-
var subplotLayers = oldFullLayout._cartesianlayer.selectAll('.subplot');
261-
var axIds = axisIds.listIds({ _fullLayout: oldFullLayout });
262-
263-
subplotLayers.call(purgeSubplotLayers, oldFullLayout);
277+
purgeSubplotLayers(oldFullLayout._cartesianlayer.selectAll('.subplot'), oldFullLayout);
264278
oldFullLayout._defs.selectAll('.axesclip').remove();
265-
266-
for(i = 0; i < axIds.length; i++) {
267-
oldFullLayout._infolayer.select('.' + axIds[i] + 'title').remove();
268-
}
269279
}
270280
};
271281

Diff for: src/plots/plots.js

-16
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,6 @@ plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayou
675675
plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
676676
var oldSubplots = oldFullLayout._plots || {};
677677
var newSubplots = newFullLayout._plots = {};
678-
var oldSubplotList = oldFullLayout._subplots || {};
679678
var newSubplotList = newFullLayout._subplots;
680679

681680
var mockGd = {
@@ -812,21 +811,6 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
812811
}
813812
ax._mainSubplot = mainSubplotID || nextBestMainSubplotID;
814813
}
815-
816-
// and lastly, delete any titles we don't need anymore
817-
// check if subplots have changed, and if so clear old titles
818-
if(oldSubplotList.xaxis && oldSubplotList.yaxis) {
819-
var oldAxIDs = oldSubplotList.xaxis.concat(oldSubplotList.yaxis);
820-
var newAxIDs = newSubplotList.xaxis.concat(newSubplotList.yaxis);
821-
822-
for(i = 0; i < oldAxIDs.length; i++) {
823-
if(newAxIDs.indexOf(oldAxIDs[i]) === -1) {
824-
oldFullLayout._infolayer.selectAll('.g-' + oldAxIDs[i] + 'title').remove();
825-
}
826-
}
827-
}
828-
829-
830814
};
831815

832816
// This function clears any trace attributes with valType: color and

0 commit comments

Comments
 (0)