Skip to content

Commit 9ebbd57

Browse files
committed
replace ax._counterSpan with ax._counterDomain(Min|Max)
... which can be computed before ax.setScale() - This speeds up Axes.drawOne (e.g. for drag interactions) - rangeslider requires one less loop over the counter axes - make Fx.hover not have to depend on field computed in Axes.drawOne - ax._counterDomain(Min|Max) will also be used for mirror auto-margin computations
1 parent 2e7b3dd commit 9ebbd57

File tree

5 files changed

+40
-48
lines changed

5 files changed

+40
-48
lines changed

src/components/fx/hover.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -1443,8 +1443,14 @@ function createSpikelines(gd, closestPoints, opts) {
14431443
xEndSpike = hLinePointX;
14441444
}
14451445
if(yMode.indexOf('across') !== -1) {
1446-
xBase = ya._counterSpan[0];
1447-
xEndSpike = ya._counterSpan[1];
1446+
var xAcross0 = ya._counterDomainMin;
1447+
var xAcross1 = ya._counterDomainMax;
1448+
if(ya.anchor === 'free') {
1449+
xAcross0 = Math.min(xAcross0, ya.position);
1450+
xAcross1 = Math.max(xAcross1, ya.position);
1451+
}
1452+
xBase = gs.l + xAcross0 * gs.w;
1453+
xEndSpike = gs.l + xAcross1 * gs.w;
14481454
}
14491455

14501456
// Foreground horizontal line (to y-axis)
@@ -1516,8 +1522,14 @@ function createSpikelines(gd, closestPoints, opts) {
15161522
yEndSpike = vLinePointY;
15171523
}
15181524
if(xMode.indexOf('across') !== -1) {
1519-
yBase = xa._counterSpan[0];
1520-
yEndSpike = xa._counterSpan[1];
1525+
var yAcross0 = xa._counterDomainMin;
1526+
var yAcross1 = xa._counterDomainMax;
1527+
if(xa.anchor === 'free') {
1528+
yAcross0 = Math.min(yAcross0, xa.position);
1529+
yAcross1 = Math.max(yAcross1, xa.position);
1530+
}
1531+
yBase = gs.t + (1 - yAcross1) * gs.h;
1532+
yEndSpike = gs.t + (1 - yAcross0) * gs.h;
15211533
}
15221534

15231535
// Foreground vertical line (to x-axis)

src/components/rangeslider/draw.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,12 @@ module.exports = function(gd) {
110110
var domain = axisOpts.domain;
111111
var tickHeight = opts._tickHeight;
112112

113-
var oppBottom = opts._oppBottom;
114-
115113
opts._width = gs.w * (domain[1] - domain[0]);
116114

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

119117
var y = Math.round(
120-
gs.t + gs.h * (1 - oppBottom) +
118+
gs.t + gs.h * (1 - axisOpts._counterDomainMin) +
121119
tickHeight +
122120
opts._offsetShift + constants.extraPad
123121
);

src/components/rangeslider/helpers.js

-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ exports.makeData = function(fullLayout) {
4444
exports.autoMarginOpts = function(gd, ax) {
4545
var opts = ax[name];
4646

47-
var oppBottom = Infinity;
48-
var counterAxes = ax._counterAxes;
49-
for(var j = 0; j < counterAxes.length; j++) {
50-
var counterId = counterAxes[j];
51-
var oppAxis = axisIDs.getFromId(gd, counterId);
52-
oppBottom = Math.min(oppBottom, oppAxis.domain[0]);
53-
}
54-
opts._oppBottom = oppBottom;
55-
5647
var tickHeight = (ax.side === 'bottom' && ax._boundingBox.height) || 0;
5748
opts._tickHeight = tickHeight;
5849

src/plots/cartesian/axes.js

+3-32
Original file line numberDiff line numberDiff line change
@@ -1653,7 +1653,6 @@ axes.drawOne = function(gd, ax, opts) {
16531653
var mainMirrorPosition = ax._mainMirrorPosition;
16541654
var mainPlotinfo = fullLayout._plots[mainSubplot];
16551655
var mainAxLayer = mainPlotinfo[axLetter + 'axislayer'];
1656-
var subplotsWithAx = ax._subplotsWith;
16571656

16581657
var vals = ax._vals = axes.calcTicks(ax);
16591658

@@ -1691,7 +1690,9 @@ axes.drawOne = function(gd, ax, opts) {
16911690
var dividerVals = getDividerVals(ax, vals);
16921691

16931692
if(!fullLayout._hasOnlyLargeSploms) {
1694-
// keep track of which subplots (by main conteraxis) we've already
1693+
var subplotsWithAx = ax._subplotsWith;
1694+
1695+
// keep track of which subplots (by main counter axis) we've already
16951696
// drawn grids for, so we don't overdraw overlaying subplots
16961697
var finishedGrids = {};
16971698

@@ -1829,10 +1830,6 @@ axes.drawOne = function(gd, ax, opts) {
18291830
});
18301831
}
18311832

1832-
function extendRange(range, newRange) {
1833-
range[0] = Math.min(range[0], newRange[0]);
1834-
range[1] = Math.max(range[1], newRange[1]);
1835-
}
18361833

18371834
function calcBoundingBox() {
18381835
if(ax.showticklabels) {
@@ -1888,32 +1885,6 @@ axes.drawOne = function(gd, ax, opts) {
18881885
};
18891886
}
18901887
}
1891-
1892-
/*
1893-
* for spikelines: what's the full domain of positions in the
1894-
* opposite direction that are associated with this axis?
1895-
* This means any axes that we make a subplot with, plus the
1896-
* position of the axis itself if it's free.
1897-
*/
1898-
if(subplotsWithAx) {
1899-
var fullRange = ax._counterSpan = [Infinity, -Infinity];
1900-
1901-
for(var i = 0; i < subplotsWithAx.length; i++) {
1902-
var plotinfo = fullLayout._plots[subplotsWithAx[i]];
1903-
var counterAxis = plotinfo[(axLetter === 'x') ? 'yaxis' : 'xaxis'];
1904-
1905-
extendRange(fullRange, [
1906-
counterAxis._offset,
1907-
counterAxis._offset + counterAxis._length
1908-
]);
1909-
}
1910-
1911-
if(ax.anchor === 'free') {
1912-
extendRange(fullRange, (axLetter === 'x') ?
1913-
[ax._boundingBox.bottom, ax._boundingBox.top] :
1914-
[ax._boundingBox.right, ax._boundingBox.left]);
1915-
}
1916-
}
19171888
}
19181889

19191890
var hasRangeSlider = Registry.getComponentMethod('rangeslider', 'isVisible')(ax);

src/plots/plots.js

+20
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,26 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
920920
ax._counterAxes.sort(axisIDs.idSort);
921921
ax._subplotsWith.sort(Lib.subplotSort);
922922
ax._mainSubplot = findMainSubplot(ax, newFullLayout);
923+
924+
// find "full" domain span of counter axes,
925+
// this loop can be costly, so only compute it when required
926+
if(ax._counterAxes.length && (
927+
(ax.spikemode && ax.spikemode.indexOf('across') !== -1) ||
928+
(ax.automargin && ax.mirror) ||
929+
Registry.getComponentMethod('rangeslider', 'isVisible')(ax)
930+
)) {
931+
var min = 1;
932+
var max = 0;
933+
for(j = 0; j < ax._counterAxes.length; j++) {
934+
var ax2 = axisIDs.getFromId(mockGd, ax._counterAxes[j]);
935+
min = Math.min(min, ax2.domain[0]);
936+
max = Math.max(max, ax2.domain[1]);
937+
}
938+
if(min < max) {
939+
ax._counterDomainMin = min;
940+
ax._counterDomainMax = max;
941+
}
942+
}
923943
}
924944
};
925945

0 commit comments

Comments
 (0)