Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
plots: add a cartesian subplot purge step
  • Loading branch information
etpinard committed Sep 16, 2016
commit 78faa3fe4399d13c37207499c451c82e7da701af
34 changes: 32 additions & 2 deletions src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
'use strict';

var d3 = require('d3');
var Lib = require('../../lib');
var Plots = require('../plots');
var Axes = require('./axes');

var constants = require('./constants');

exports.name = 'cartesian';
Expand Down Expand Up @@ -147,20 +147,33 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
}
}
}

var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian'));
var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian'));

if(hadCartesian && !hasCartesian) {
var subplotLayers = oldFullLayout._cartesianlayer.selectAll('.subplot');

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

exports.drawFramework = function(gd) {
var fullLayout = gd._fullLayout,
subplotData = makeSubplotData(gd);

var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot')
.data(subplotData, String);
.data(subplotData, Lib.identity);

subplotLayers.enter().append('g')
.classed('subplot', true);

subplotLayers.order();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See http://codepen.io/etpinard/pen/mAEBVz for example of this pattern


subplotLayers.exit()
.call(purgeSubplotLayers, fullLayout);

subplotLayers.each(function(subplot) {
var plotgroup = d3.select(this),
plotinfo = fullLayout._plots[subplot];
Expand Down Expand Up @@ -316,6 +329,23 @@ function makeSubplotLayer(plotgroup, gd, subplot) {
.classed('crisp', true);
}

function purgeSubplotLayers(layers, fullLayout) {
if(!layers) return;

layers.each(function(subplot) {
var plotgroup = d3.select(this),
clipId = 'clip' + fullLayout._uid + subplot + 'plot';

plotgroup.remove();
fullLayout._draggers.selectAll('g.' + subplot).remove();
fullLayout._defs.select('#' + clipId).remove();

// do not remove individual axis <clipPath>s here
// as other subplots may need them
});
}


function joinLayer(parent, nodeType, className) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good enough for Lib function ???

Copy link
Contributor

@rreusser rreusser Oct 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, def. We use this pattern all over the place, and it's invalid in d3 v4 without some minor modifications, so would be good to extract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll defer that to a future PR.

var layer = parent.selectAll('.' + className)
.data([0]);
Expand Down