Skip to content

More optimization for cartesian subplots #2487

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

Merged
merged 6 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ exports.plot = function(gd, data, layout, config) {

// draw ticks, titles, and calculate axis scaling (._b, ._m)
function drawAxes() {
return Axes.doTicks(gd, 'redraw');
return Axes.doTicks(gd, graphWasEmpty ? '' : 'redraw');
Copy link
Collaborator

Choose a reason for hiding this comment

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

OK... this is the only caller using doTicks(gd, '') right? From the logic below it looks like there may have been one previously (or someone just calling doTicks(gd)) but I don't see it now. I'm a little reticent to add new branches inside doTicks when what we really need to do is unpack it into more digestible pieces - but that's probably a project for another time refactoring all of axes.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK... this is the only caller using doTicks(gd, '') right? From the logic below it looks like there may have been one previously (or someone just calling doTicks(gd)) but I don't see it now.

That's correct.

}

// Now plot the data
Expand Down
26 changes: 6 additions & 20 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,31 +124,17 @@ exports.lsInner = function(gd) {

var xDomain = plotinfo.xaxis.domain;
var yDomain = plotinfo.yaxis.domain;
var plotgroupBgData = [];
var plotgroup = plotinfo.plotgroup;

if(overlappingDomain(xDomain, yDomain, lowerDomains)) {
plotgroupBgData = [0];
}
else {
var pgNode = plotgroup.node();
var plotgroupBg = plotinfo.bg = Lib.ensureSingle(plotgroup, 'rect', 'bg');
pgNode.insertBefore(plotgroupBg.node(), pgNode.childNodes[0]);
} else {
plotgroup.select('rect.bg').remove();
lowerBackgroundIDs.push(subplot);
lowerDomains.push([xDomain, yDomain]);
}

// create the plot group backgrounds now, since
// they're all independent selections
var plotgroupBg = plotinfo.plotgroup.selectAll('.bg')
.data(plotgroupBgData);

plotgroupBg.enter().append('rect')
.classed('bg', true);

plotgroupBg.exit().remove();

plotgroupBg.each(function() {
plotinfo.bg = plotgroupBg;
var pgNode = plotinfo.plotgroup.node();
pgNode.insertBefore(this, pgNode.childNodes[0]);
});
});

// now create all the lower-layer backgrounds at once now that
Expand Down
53 changes: 26 additions & 27 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1539,10 +1539,8 @@ axes.doTicks = function(gd, axid, skipTitle) {
return function() {
if(!ax._id) return;
var axDone = axes.doTicks(gd, ax._id);
if(axid === 'redraw') {
ax._r = ax.range.slice();
ax._rl = Lib.simpleMap(ax._r, ax.r2l);
}
ax._r = ax.range.slice();
ax._rl = Lib.simpleMap(ax._r, ax.r2l);
return axDone;
};
}));
Expand All @@ -1552,21 +1550,22 @@ axes.doTicks = function(gd, axid, skipTitle) {
// set scaling to pixels
ax.setScale();

var axLetter = axid.charAt(0),
counterLetter = axes.counterLetter(axid),
vals = axes.calcTicks(ax),
datafn = function(d) { return [d.text, d.x, ax.mirror, d.font, d.fontSize, d.fontColor].join('_'); },
tcls = axid + 'tick',
gcls = axid + 'grid',
zcls = axid + 'zl',
pad = (ax.linewidth || 1) / 2,
labelStandoff = (ax.ticks === 'outside' ? ax.ticklen : 0),
labelShift = 0,
gridWidth = Drawing.crispRound(gd, ax.gridwidth, 1),
zeroLineWidth = Drawing.crispRound(gd, ax.zerolinewidth, gridWidth),
tickWidth = Drawing.crispRound(gd, ax.tickwidth, 1),
sides, transfn, tickpathfn, subplots,
i;
var axLetter = axid.charAt(0);
var counterLetter = axes.counterLetter(axid);
var vals = axes.calcTicks(ax);
var datafn = function(d) { return [d.text, d.x, ax.mirror, d.font, d.fontSize, d.fontColor].join('_'); };
var tcls = axid + 'tick';
var gcls = axid + 'grid';
var zcls = axid + 'zl';
var pad = (ax.linewidth || 1) / 2;
var labelStandoff = (ax.ticks === 'outside' ? ax.ticklen : 0);
var labelShift = 0;
var gridWidth = Drawing.crispRound(gd, ax.gridwidth, 1);
var zeroLineWidth = Drawing.crispRound(gd, ax.zerolinewidth, gridWidth);
var tickWidth = Drawing.crispRound(gd, ax.tickwidth, 1);
var sides, transfn, tickpathfn, subplots;
var tickLabels;
var i;

if(ax._counterangle && ax.ticks === 'outside') {
var caRad = ax._counterangle * Math.PI / 180;
Expand Down Expand Up @@ -1616,10 +1615,11 @@ axes.doTicks = function(gd, axid, skipTitle) {
Lib.warn('Unrecognized doTicks axis:', axid);
return;
}
var axside = ax.side || sides[0],

var axside = ax.side || sides[0];
// which direction do the side[0], side[1], and free ticks go?
// then we flip if outside XOR y axis
ticksign = [-1, 1, axside === sides[1] ? 1 : -1];
var ticksign = [-1, 1, axside === sides[1] ? 1 : -1];
if((ax.ticks !== 'inside') === (axLetter === 'x')) {
ticksign = ticksign.map(function(v) { return -v; });
}
Expand Down Expand Up @@ -1647,6 +1647,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
function drawTicks(container, tickpath) {
var ticks = container.selectAll('path.' + tcls)
.data(ax.ticks === 'inside' ? valsClipped : vals, datafn);

if(tickpath && ax.ticks) {
ticks.enter().append('path').classed(tcls, 1).classed('ticks', 1)
.classed('crisp', 1)
Expand All @@ -1662,7 +1663,7 @@ axes.doTicks = function(gd, axid, skipTitle) {
function drawLabels(container, position) {
// tick labels - for now just the main labels.
// TODO: mirror labels, esp for subplots
var tickLabels = container.selectAll('g.' + tcls).data(vals, datafn);
tickLabels = container.selectAll('g.' + tcls).data(vals, datafn);

if(!isNumeric(position)) {
tickLabels.remove();
Expand Down Expand Up @@ -2013,14 +2014,12 @@ axes.doTicks = function(gd, axid, skipTitle) {
// now this only applies to regular cartesian axes; colorbars and
// others ALWAYS call doTicks with skipTitle=true so they can
// configure their own titles.
var ax = axisIds.getFromId(gd, axid);

// rangeslider takes over a bottom title so drop it here
if(ax.rangeslider && ax.rangeslider.visible && ax._boundingBox && ax.side === 'bottom') return;

var avoidSelection = d3.select(gd).selectAll('g.' + axid + 'tick');
var avoid = {
selection: avoidSelection,
selection: tickLabels,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice find!

side: ax.side
};
var axLetter = axid.charAt(0);
Expand All @@ -2030,8 +2029,8 @@ axes.doTicks = function(gd, axid, skipTitle) {

var transform, counterAxis, x, y;

if(avoidSelection.size()) {
var translation = Drawing.getTranslate(avoidSelection.node().parentNode);
if(tickLabels.size()) {
var translation = Drawing.getTranslate(tickLabels.node().parentNode);
avoid.offsetLeft = translation.x;
avoid.offsetTop = translation.y;
}
Expand Down