-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Even better cartesian trace updates and removal #2579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
400bfe6
284c206
da63ed4
a1c76bc
fa38ca5
48ee0d8
362da1f
3bef9a9
d47276f
83422f7
8c9a7bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,13 @@ | |
'use strict'; | ||
|
||
var d3 = require('d3'); | ||
|
||
var Registry = require('../../registry'); | ||
var Lib = require('../../lib'); | ||
var Plots = require('../plots'); | ||
var getModuleCalcData = require('../get_data').getModuleCalcData; | ||
var Drawing = require('../../components/drawing'); | ||
|
||
var getModuleCalcData = require('../get_data').getModuleCalcData; | ||
var axisIds = require('./axis_ids'); | ||
var constants = require('./constants'); | ||
var xmlnsNamespaces = require('../../constants/xmlns_namespaces'); | ||
|
@@ -179,40 +182,75 @@ exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) { | |
}; | ||
|
||
function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback) { | ||
var traceLayerClasses = constants.traceLayerClasses; | ||
var fullLayout = gd._fullLayout; | ||
var modules = fullLayout._modules; | ||
// list of plot methods to call (this list includes plot methods of 'gone' modules) | ||
var plotMethodsToCall = plotinfo.plotMethods || []; | ||
// list of plot methods of visible module on this subplot | ||
var plotMethods = []; | ||
var i, plotMethod; | ||
|
||
for(i = 0; i < modules.length; i++) { | ||
var _module = modules[i]; | ||
|
||
if(_module.basePlotModule.name === 'cartesian') { | ||
plotMethod = _module.plot; | ||
Lib.pushUnique(plotMethodsToCall, plotMethod); | ||
Lib.pushUnique(plotMethods, plotMethod); | ||
var _module, cdModuleAndOthers, cdModule; | ||
|
||
var layerData = []; | ||
|
||
for(var i = 0; i < traceLayerClasses.length; i++) { | ||
var className = traceLayerClasses[i]; | ||
|
||
for(var j = 0; j < modules.length; j++) { | ||
_module = modules[j]; | ||
|
||
if(_module.basePlotModule.name === 'cartesian' && | ||
(_module.layerName || _module.name + 'layer') === className | ||
) { | ||
var plotMethod = _module.plot; | ||
|
||
// plot all traces of this type on this subplot at once | ||
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod); | ||
cdModule = cdModuleAndOthers[0]; | ||
// don't need to search the found traces again - in fact we need to NOT | ||
// so that if two modules share the same plotter we don't double-plot | ||
cdSubplot = cdModuleAndOthers[1]; | ||
|
||
if(cdModule.length) { | ||
layerData.push({ | ||
className: className, | ||
plotMethod: plotMethod, | ||
cdModule: cdModule | ||
}); | ||
} | ||
break; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be a 2D loop? Could we just loop over modules, include the layer index in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to avoid sorting for 🐎 but you're probably right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in d47276f |
||
} | ||
} | ||
} | ||
|
||
for(i = 0; i < plotMethodsToCall.length; i++) { | ||
plotMethod = plotMethodsToCall[i]; | ||
var layers = plotinfo.plot.selectAll('g.mlayer') | ||
.data(layerData, function(d) { return d.className; }); | ||
|
||
// plot all traces of this type on this subplot at once | ||
var cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod); | ||
var cdModule = cdModuleAndOthers[0]; | ||
// don't need to search the found traces again - in fact we need to NOT | ||
// so that if two modules share the same plotter we don't double-plot | ||
cdSubplot = cdModuleAndOthers[1]; | ||
layers.enter().append('g') | ||
.attr('class', function(d) { return d.className; }) | ||
.classed('mlayer', true); | ||
|
||
plotMethod(gd, plotinfo, cdModule, transitionOpts, makeOnCompleteCallback); | ||
} | ||
layers.exit().remove(); | ||
|
||
layers.order(); | ||
|
||
layers.each(function(d) { | ||
var sel = d3.select(this); | ||
var className = d.className; | ||
|
||
// save list of plot methods on subplot for later, | ||
// so that they can be called to clear traces of 'gone' modules | ||
plotinfo.plotMethods = plotMethods; | ||
d.plotMethod( | ||
gd, plotinfo, d.cdModule, sel, | ||
transitionOpts, makeOnCompleteCallback | ||
); | ||
|
||
// layers that allow `cliponaxis: false` | ||
if(className !== 'scatterlayer' && className !== 'barlayer') { | ||
Drawing.setClipUrl(sel, plotinfo.layerClipId); | ||
} | ||
}); | ||
|
||
// call Scattergl.plot separately | ||
if(fullLayout._has('scattergl')) { | ||
_module = Registry.getModule('scattergl'); | ||
cdModule = getModuleCalcData(cdSubplot, _module)[0]; | ||
_module.plot(gd, plotinfo, cdModule); | ||
} | ||
} | ||
|
||
exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) { | ||
|
@@ -441,10 +479,6 @@ function makeSubplotLayer(gd, plotinfo) { | |
ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.xaxis._id); | ||
ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.yaxis._id); | ||
plotinfo.gridlayer.selectAll('g').sort(axisIds.idSort); | ||
|
||
for(var i = 0; i < constants.traceLayerClasses.length; i++) { | ||
ensureSingle(plotinfo.plot, 'g', constants.traceLayerClasses[i]); | ||
} | ||
} | ||
|
||
plotinfo.xlines | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,19 +18,24 @@ var svgTextUtils = require('../../lib/svg_text_utils'); | |
var Lib = require('../../lib'); | ||
var alignmentConstants = require('../../constants/alignment'); | ||
|
||
module.exports = function plot(gd, plotinfo, cdcarpet) { | ||
if(!cdcarpet.length) { | ||
plotinfo.plot.select('.carpetlayer') | ||
.selectAll('g.trace') | ||
.remove(); | ||
} | ||
module.exports = function plot(gd, plotinfo, cdcarpet, carpetLayer) { | ||
var i; | ||
|
||
carpetLayer.selectAll('g.trace').each(function() { | ||
var classString = d3.select(this).attr('class'); | ||
var oldUid = classString.split('carpet')[1].split(/\s/)[0]; | ||
for(i = 0; i < cdcarpet.length; i++) { | ||
if(oldUid === cdcarpet[i][0].trace.uid) return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🌴 🐎 perhaps make a common helper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in d47276f |
||
d3.select(this).remove(); | ||
}); | ||
|
||
for(var i = 0; i < cdcarpet.length; i++) { | ||
plotOne(gd, plotinfo, cdcarpet[i]); | ||
for(i = 0; i < cdcarpet.length; i++) { | ||
plotOne(gd, plotinfo, cdcarpet[i], carpetLayer); | ||
} | ||
}; | ||
|
||
function plotOne(gd, plotinfo, cd) { | ||
function plotOne(gd, plotinfo, cd, carpetLayer) { | ||
var t = cd[0]; | ||
var trace = cd[0].trace, | ||
xa = plotinfo.xaxis, | ||
|
@@ -39,10 +44,9 @@ function plotOne(gd, plotinfo, cd) { | |
bax = trace.baxis, | ||
fullLayout = gd._fullLayout; | ||
|
||
var gridLayer = plotinfo.plot.select('.carpetlayer'); | ||
var clipLayer = fullLayout._clips; | ||
|
||
var axisLayer = Lib.ensureSingle(gridLayer, 'g', 'carpet' + trace.uid).classed('trace', true); | ||
var axisLayer = Lib.ensureSingle(carpetLayer, 'g', 'carpet' + trace.uid).classed('trace', true); | ||
var minorLayer = Lib.ensureSingle(axisLayer, 'g', 'minorlayer'); | ||
var majorLayer = Lib.ensureSingle(axisLayer, 'g', 'majorlayer'); | ||
var boundaryLayer = Lib.ensureSingle(axisLayer, 'g', 'boundarylayer'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N.B. On the other hand, trace modules (e.g.
scattercarpet
) that only wrap another plot method need a separate layer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason some of the new ones share lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put modules that almost have the same
plot
method on the same line. I thought that would make it easier to track. I can change that of course.