Skip to content
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

Axes.draw w/o getBoundingClientRect + many axis automargin fixes #4165

Merged
merged 15 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 11 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
33 changes: 22 additions & 11 deletions src/components/fx/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,15 @@ function _hover(gd, evt, subplot, noHoverEvent) {
var result = dragElement.unhoverRaw(gd, evt);
if(hasCartesian && ((spikePoints.hLinePoint !== null) || (spikePoints.vLinePoint !== null))) {
if(spikesChanged(oldspikepoints)) {
createSpikelines(spikePoints, spikelineOpts);
createSpikelines(gd, spikePoints, spikelineOpts);
}
}
return result;
}

if(hasCartesian) {
if(spikesChanged(oldspikepoints)) {
createSpikelines(spikePoints, spikelineOpts);
createSpikelines(gd, spikePoints, spikelineOpts);
}
}

Expand Down Expand Up @@ -1396,9 +1396,10 @@ function cleanPoint(d, hovermode) {
return d;
}

function createSpikelines(closestPoints, opts) {
function createSpikelines(gd, closestPoints, opts) {
var container = opts.container;
var fullLayout = opts.fullLayout;
var gs = fullLayout._size;
var evt = opts.event;
var showY = !!closestPoints.hLinePoint;
var showX = !!closestPoints.vLinePoint;
Expand Down Expand Up @@ -1433,8 +1434,7 @@ function createSpikelines(closestPoints, opts) {
var yMode = ya.spikemode;
var yThickness = ya.spikethickness;
var yColor = ya.spikecolor || dfltHLineColor;
var yBB = ya._boundingBox;
var xEdge = ((yBB.left + yBB.right) / 2) < hLinePointX ? yBB.right : yBB.left;
var xEdge = Axes.getPxPosition(gd, ya);
var xBase, xEndSpike;

if(yMode.indexOf('toaxis') !== -1 || yMode.indexOf('across') !== -1) {
Expand All @@ -1443,8 +1443,14 @@ function createSpikelines(closestPoints, opts) {
xEndSpike = hLinePointX;
}
if(yMode.indexOf('across') !== -1) {
xBase = ya._counterSpan[0];
xEndSpike = ya._counterSpan[1];
var xAcross0 = ya._counterDomainMin;
var xAcross1 = ya._counterDomainMax;
if(ya.anchor === 'free') {
xAcross0 = Math.min(xAcross0, ya.position);
xAcross1 = Math.max(xAcross1, ya.position);
}
xBase = gs.l + xAcross0 * gs.w;
xEndSpike = gs.l + xAcross1 * gs.w;
}

// Foreground horizontal line (to y-axis)
Expand Down Expand Up @@ -1507,8 +1513,7 @@ function createSpikelines(closestPoints, opts) {
var xMode = xa.spikemode;
var xThickness = xa.spikethickness;
var xColor = xa.spikecolor || dfltVLineColor;
var xBB = xa._boundingBox;
var yEdge = ((xBB.top + xBB.bottom) / 2) < vLinePointY ? xBB.bottom : xBB.top;
var yEdge = Axes.getPxPosition(gd, xa);
var yBase, yEndSpike;

if(xMode.indexOf('toaxis') !== -1 || xMode.indexOf('across') !== -1) {
Expand All @@ -1517,8 +1522,14 @@ function createSpikelines(closestPoints, opts) {
yEndSpike = vLinePointY;
}
if(xMode.indexOf('across') !== -1) {
yBase = xa._counterSpan[0];
yEndSpike = xa._counterSpan[1];
var yAcross0 = xa._counterDomainMin;
var yAcross1 = xa._counterDomainMax;
if(xa.anchor === 'free') {
yAcross0 = Math.min(yAcross0, xa.position);
yAcross1 = Math.max(yAcross1, xa.position);
}
yBase = gs.t + (1 - yAcross1) * gs.h;
yEndSpike = gs.t + (1 - yAcross0) * gs.h;
}

// Foreground vertical line (to x-axis)
Expand Down
7 changes: 2 additions & 5 deletions src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,14 @@ module.exports = function(gd) {

var gs = fullLayout._size;
var domain = axisOpts.domain;
var tickHeight = opts._tickHeight;

var oppBottom = opts._oppBottom;

opts._width = gs.w * (domain[1] - domain[0]);

var x = Math.round(gs.l + (gs.w * domain[0]));

var y = Math.round(
gs.t + gs.h * (1 - oppBottom) +
tickHeight +
gs.t + gs.h * (1 - axisOpts._counterDomainMin) +
(axisOpts.side === 'bottom' ? axisOpts._depth : 0) +
opts._offsetShift + constants.extraPad
);

Expand Down
18 changes: 3 additions & 15 deletions src/components/rangeslider/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,14 @@ exports.makeData = function(fullLayout) {

exports.autoMarginOpts = function(gd, ax) {
var opts = ax[name];

var oppBottom = Infinity;
var counterAxes = ax._counterAxes;
for(var j = 0; j < counterAxes.length; j++) {
var counterId = counterAxes[j];
var oppAxis = axisIDs.getFromId(gd, counterId);
oppBottom = Math.min(oppBottom, oppAxis.domain[0]);
}
opts._oppBottom = oppBottom;

var tickHeight = (ax.side === 'bottom' && ax._boundingBox.height) || 0;
opts._tickHeight = tickHeight;

var bottomDepth = ax.side === 'bottom' ? ax._depth : 0;
return {
x: 0,
y: oppBottom,
y: ax._counterDomainMin,
l: 0,
r: 0,
t: 0,
b: opts._height + gd._fullLayout.margin.b + tickHeight,
b: opts._height + gd._fullLayout.margin.b + bottomDepth,
pad: constants.extraPad + opts._offsetShift * 2
};
};
11 changes: 5 additions & 6 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function lsInner(gd) {
// can still get here because it makes some of the SVG structure
// for shared features like selections.
if(!fullLayout._has('cartesian')) {
return gd._promises.length && Promise.all(gd._promises);
return Plots.previousPromises(gd);
}

function getLinePosition(ax, counterAx, side) {
Expand Down Expand Up @@ -347,7 +347,7 @@ function lsInner(gd) {

Axes.makeClipPaths(gd);

return gd._promises.length && Promise.all(gd._promises);
return Plots.previousPromises(gd);
}

function shouldShowLinesOrTicks(ax, subplot) {
Expand Down Expand Up @@ -599,9 +599,11 @@ exports.drawData = function(gd) {
// styling separate from drawing
Plots.style(gd);

// show annotations and shapes
// draw components that can be drawn on axes,
// and that do not push the margins
Registry.getComponentMethod('shapes', 'draw')(gd);
Registry.getComponentMethod('annotations', 'draw')(gd);
Registry.getComponentMethod('images', 'draw')(gd);

// Mark the first render as complete
fullLayout._replotting = false;
Expand Down Expand Up @@ -717,9 +719,6 @@ exports.doAutoRangeAndConstraints = function(gd) {
// correctly sized and the whole plot re-margined. fullLayout._replotting must
// be set to false before these will work properly.
exports.finalDraw = function(gd) {
Registry.getComponentMethod('shapes', 'draw')(gd);
Registry.getComponentMethod('images', 'draw')(gd);
Registry.getComponentMethod('annotations', 'draw')(gd);
// TODO: rangesliders really belong in marginPushers but they need to be
// drawn after data - can we at least get the margin pushing part separated
// out and done earlier?
Expand Down
Loading