Skip to content

Commit 769c160

Browse files
committed
fill trace._extremes with findExtremes in calc
- replacing Axe.expand - for ErrorBars, we append the min/max arrays of the corresponding trace
1 parent ad1ac1f commit 769c160

File tree

14 files changed

+80
-48
lines changed

14 files changed

+80
-48
lines changed

src/components/errorbars/calc.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,15 @@ module.exports = function calc(gd) {
2121
var calcdata = gd.calcdata;
2222

2323
for(var i = 0; i < calcdata.length; i++) {
24-
var calcTrace = calcdata[i],
25-
trace = calcTrace[0].trace;
26-
27-
if(!Registry.traceIs(trace, 'errorBarsOK')) continue;
28-
29-
var xa = Axes.getFromId(gd, trace.xaxis),
30-
ya = Axes.getFromId(gd, trace.yaxis);
31-
32-
calcOneAxis(calcTrace, trace, xa, 'x');
33-
calcOneAxis(calcTrace, trace, ya, 'y');
24+
var calcTrace = calcdata[i];
25+
var trace = calcTrace[0].trace;
26+
27+
if(trace.visible === true && Registry.traceIs(trace, 'errorBarsOK')) {
28+
var xa = Axes.getFromId(gd, trace.xaxis);
29+
var ya = Axes.getFromId(gd, trace.yaxis);
30+
calcOneAxis(calcTrace, trace, xa, 'x');
31+
calcOneAxis(calcTrace, trace, ya, 'y');
32+
}
3433
}
3534
};
3635

@@ -57,5 +56,8 @@ function calcOneAxis(calcTrace, trace, axis, coord) {
5756
}
5857
}
5958

60-
Axes.expand(axis, vals, {padded: true});
59+
var extremes = Axes.findExtremes(axis, vals, {padded: true});
60+
var axId = axis._id;
61+
trace._extremes[axId].min = trace._extremes[axId].min.concat(extremes.min);
62+
trace._extremes[axId].max = trace._extremes[axId].max.concat(extremes.max);
6163
}

src/plots/cartesian/axes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ axes.getFromTrace = axisIds.getFromTrace;
5050
var autorange = require('./autorange');
5151
axes.expand = autorange.expand;
5252
axes.getAutoRange = autorange.getAutoRange;
53+
axes.findExtremes = autorange.findExtremes;
5354

5455
/*
5556
* find the list of possible axes to reference with an xref or yref attribute

src/plots/plots.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2455,10 +2455,13 @@ plots.doCalcdata = function(gd, traces) {
24552455
}
24562456
}
24572457

2458-
// find array attributes in trace
24592458
for(i = 0; i < fullData.length; i++) {
24602459
trace = fullData[i];
2460+
24612461
trace._arrayAttrs = PlotSchema.findArrayAttributes(trace);
2462+
2463+
// keep track of trace extremes (for autorange) in here
2464+
trace._extremes = {};
24622465
}
24632466

24642467
// add polar axes to axis list

src/traces/bar/set_positions.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ function updatePositionAxis(gd, pa, sieve, allowMinDtick) {
496496
}
497497
}
498498

499-
Axes.expand(pa, [pMin, pMax], {padded: false});
499+
var extremes = Axes.findExtremes(pa, [pMin, pMax], {padded: false});
500+
putExtremes(calcTraces, pa, extremes);
500501
}
501502

502503
function expandRange(range, newValue) {
@@ -530,7 +531,8 @@ function setBaseAndTop(gd, sa, sieve) {
530531
}
531532
}
532533

533-
Axes.expand(sa, sRange, {tozero: true, padded: true});
534+
var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: true});
535+
putExtremes(traces, sa, extremes);
534536
}
535537

536538

@@ -568,7 +570,10 @@ function stackBars(gd, sa, sieve) {
568570
}
569571

570572
// if barnorm is set, let normalizeBars update the axis range
571-
if(!barnorm) Axes.expand(sa, sRange, {tozero: true, padded: true});
573+
if(!barnorm) {
574+
var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: true});
575+
putExtremes(traces, sa, extremes);
576+
}
572577
}
573578

574579

@@ -633,14 +638,21 @@ function normalizeBars(gd, sa, sieve) {
633638
}
634639

635640
// update range of size axis
636-
Axes.expand(sa, sRange, {tozero: true, padded: padded});
641+
var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: padded});
642+
putExtremes(traces, sa, extremes);
637643
}
638644

639645

640646
function getAxisLetter(ax) {
641647
return ax._id.charAt(0);
642648
}
643649

650+
function putExtremes(cd, ax, extremes) {
651+
for(var i = 0; i < cd.length; i++) {
652+
cd[i][0].trace._extremes[ax._id] = extremes;
653+
}
654+
}
655+
644656
// find the full position span of bars at each position
645657
// for use by hover, to ensure labels move in if bars are
646658
// narrower than the space they're in.

src/traces/box/calc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ module.exports = function calc(gd, trace) {
122122
}
123123

124124
calcSelection(cd, trace);
125-
Axes.expand(valAxis, val, {padded: true});
125+
var extremes = Axes.findExtremes(valAxis, val, {padded: true});
126+
trace._extremes[valAxis._id] = extremes;
126127

127128
if(cd.length > 0) {
128129
cd[0].t = {

src/traces/box/set_positions.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,26 @@ function setPositionOffset(traceType, gd, boxList, posAxis, pad) {
8686
// check for forced minimum dtick
8787
Axes.minDtick(posAxis, boxdv.minDiff, boxdv.vals[0], true);
8888

89-
// set the width of all boxes
90-
for(i = 0; i < boxList.length; i++) {
91-
calcTrace = calcdata[boxList[i]];
92-
calcTrace[0].t.dPos = dPos;
93-
}
94-
9589
var gap = fullLayout[traceType + 'gap'];
9690
var groupgap = fullLayout[traceType + 'groupgap'];
9791
var padfactor = (1 - gap) * (1 - groupgap) * dPos / fullLayout[numKey];
9892

9993
// autoscale the x axis - including space for points if they're off the side
10094
// TODO: this will overdo it if the outermost boxes don't have
10195
// their points as far out as the other boxes
102-
Axes.expand(posAxis, boxdv.vals, {
96+
var extremes = Axes.findExtremes(posAxis, boxdv.vals, {
10397
vpadminus: dPos + pad[0] * padfactor,
10498
vpadplus: dPos + pad[1] * padfactor
10599
});
100+
101+
for(i = 0; i < boxList.length; i++) {
102+
calcTrace = calcdata[boxList[i]];
103+
// set the width of all boxes
104+
calcTrace[0].t.dPos = dPos;
105+
// link extremes to all boxes
106+
calcTrace[0].trace._extremes[posAxis._id] = extremes;
107+
}
108+
106109
}
107110

108111
module.exports = {

src/traces/carpet/calc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ module.exports = function calc(gd, trace) {
8282
xrange = [xc - dx * grow, xc + dx * grow];
8383
yrange = [yc - dy * grow, yc + dy * grow];
8484

85-
Axes.expand(xa, xrange, {padded: true});
86-
Axes.expand(ya, yrange, {padded: true});
85+
trace._extremes[xa._id] = Axes.findExtremes(xa, xrange, {padded: true});
86+
trace._extremes[ya._id] = Axes.findExtremes(ya, yrange, {padded: true});
8787

8888
// Enumerate the gridlines, both major and minor, and store them on the trace
8989
// object:

src/traces/heatmap/calc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ module.exports = function calc(gd, trace) {
124124

125125
// handled in gl2d convert step
126126
if(!isGL2D) {
127-
Axes.expand(xa, xArray);
128-
Axes.expand(ya, yArray);
127+
trace._extremes[xa._id] = Axes.findExtremes(xa, xArray);
128+
trace._extremes[ya._id] = Axes.findExtremes(ya, yArray);
129129
}
130130

131131
var cd0 = {

src/traces/ohlc/calc.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ function calc(gd, trace) {
2525

2626
var cd = calcCommon(gd, trace, x, ya, ptFunc);
2727

28-
Axes.expand(xa, x, {vpad: minDiff / 2});
29-
28+
trace._extremes[xa._id] = Axes.findExtremes(xa, x, {vpad: minDiff / 2});
3029
if(cd.length) {
3130
Lib.extendFlat(cd[0].t, {
3231
wHover: minDiff / 2,
@@ -93,7 +92,7 @@ function calcCommon(gd, trace, x, ya, ptFunc) {
9392
}
9493
}
9594

96-
Axes.expand(ya, l.concat(h), {padded: true});
95+
trace._extremes[ya._id] = Axes.findExtremes(ya, l.concat(h), {padded: true});
9796

9897
if(cd.length) {
9998
cd[0].t = {

src/traces/scatter/calc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ function calcAxisExpansion(gd, trace, xa, ya, x, y, ppad) {
9797
}
9898

9999
// N.B. asymmetric splom traces call this with blank {} xa or ya
100-
if(xa._id) Axes.expand(xa, x, xOptions);
101-
if(ya._id) Axes.expand(ya, y, yOptions);
100+
if(xa._id) trace._extremes[xa._id] = Axes.findExtremes(xa, x, xOptions);
101+
if(ya._id) trace._extremes[ya._id] = Axes.findExtremes(ya, y, yOptions);
102102
}
103103

104104
function calcMarkerSize(trace, serieslen) {

0 commit comments

Comments
 (0)