Skip to content

Commit

Permalink
simplify redundant title removal
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcjohnson committed Dec 30, 2017
1 parent 8804311 commit 4786b6e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
26 changes: 18 additions & 8 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,29 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
.remove();
}

var oldSubplotList = oldFullLayout._subplots || {};
var newSubplotList = newFullLayout._subplots || {xaxis: [], yaxis: []};

// delete any titles we don't need anymore
// check if axis list has changed, and if so clear old titles
if(oldSubplotList.xaxis && oldSubplotList.yaxis) {
var oldAxIDs = oldSubplotList.xaxis.concat(oldSubplotList.yaxis);
var newAxIDs = newSubplotList.xaxis.concat(newSubplotList.yaxis);

for(i = 0; i < oldAxIDs.length; i++) {
if(newAxIDs.indexOf(oldAxIDs[i]) === -1) {
oldFullLayout._infolayer.selectAll('.g-' + oldAxIDs[i] + 'title').remove();
}
}
}

// if we've gotten rid of all cartesian traces, remove all the subplot svg items
var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian'));
var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian'));

if(hadCartesian && !hasCartesian) {
var subplotLayers = oldFullLayout._cartesianlayer.selectAll('.subplot');
var axIds = axisIds.listIds({ _fullLayout: oldFullLayout });

subplotLayers.call(purgeSubplotLayers, oldFullLayout);
purgeSubplotLayers(oldFullLayout._cartesianlayer.selectAll('.subplot'), oldFullLayout);
oldFullLayout._defs.selectAll('.axesclip').remove();

for(i = 0; i < axIds.length; i++) {
oldFullLayout._infolayer.select('.' + axIds[i] + 'title').remove();
}
}
};

Expand Down
16 changes: 0 additions & 16 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayou
plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
var oldSubplots = oldFullLayout._plots || {};
var newSubplots = newFullLayout._plots = {};
var oldSubplotList = oldFullLayout._subplots || {};
var newSubplotList = newFullLayout._subplots;

var mockGd = {
Expand Down Expand Up @@ -812,21 +811,6 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
}
ax._mainSubplot = mainSubplotID || nextBestMainSubplotID;
}

// and lastly, delete any titles we don't need anymore
// check if subplots have changed, and if so clear old titles
if(oldSubplotList.xaxis && oldSubplotList.yaxis) {
var oldAxIDs = oldSubplotList.xaxis.concat(oldSubplotList.yaxis);
var newAxIDs = newSubplotList.xaxis.concat(newSubplotList.yaxis);

for(i = 0; i < oldAxIDs.length; i++) {
if(newAxIDs.indexOf(oldAxIDs[i]) === -1) {
oldFullLayout._infolayer.selectAll('.g-' + oldAxIDs[i] + 'title').remove();
}
}
}


};

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

0 comments on commit 4786b6e

Please sign in to comment.