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) {

src/traces/scattergl/convert.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ var rgba = require('color-normalize');
1515
var Registry = require('../../registry');
1616
var Lib = require('../../lib');
1717
var Drawing = require('../../components/drawing');
18-
var Axes = require('../../plots/cartesian/axes');
1918
var AxisIDs = require('../../plots/cartesian/axis_ids');
2019

2120
var formatColor = require('../../lib/gl_format_color').formatColor;
@@ -511,11 +510,10 @@ function convertErrorBarPositions(gd, trace, positions, x, y) {
511510
}
512511
}
513512

514-
Axes.expand(ax, [minShoe, maxHat], {padded: true});
515-
516513
out[axLetter] = {
517514
positions: positions,
518-
errors: errors
515+
errors: errors,
516+
_bnds: [minShoe, maxHat]
519517
};
520518
}
521519
}

src/traces/scattergl/index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var Registry = require('../../registry');
1919
var Lib = require('../../lib');
2020
var prepareRegl = require('../../lib/prepare_regl');
2121
var AxisIDs = require('../../plots/cartesian/axis_ids');
22+
var findExtremes = require('../../plots/cartesian/autorange').findExtremes;
2223
var Color = require('../../components/color');
2324

2425
var subTypes = require('../scatter/subtypes');
@@ -85,18 +86,18 @@ function calc(gd, trace) {
8586
var opts = sceneOptions(gd, subplot, trace, positions, x, y);
8687
var scene = sceneUpdate(gd, subplot);
8788

88-
// Re-use SVG scatter axis expansion routine except
89-
// for graph with very large number of points where it
90-
// performs poorly.
91-
// In big data case, fake Axes.expand outputs with data bounds,
92-
// and an average size for array marker.size inputs.
89+
// Reuse SVG scatter axis expansion routine.
90+
// For graphs with very large number of points and array marker.size,
91+
// use average marker size instead to speed things up.
9392
var ppad;
9493
if(count < TOO_MANY_POINTS) {
9594
ppad = calcMarkerSize(trace, count);
9695
} else if(opts.marker) {
9796
ppad = 2 * (opts.marker.sizeAvg || Math.max(opts.marker.size, 3));
9897
}
9998
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
99+
if(opts.errorX) expandForErrorBars(trace, xa, opts.errorX);
100+
if(opts.errorY) expandForErrorBars(trace, ya, opts.errorY);
100101

101102
// set flags to create scene renderers
102103
if(opts.fill && !scene.fill2d) scene.fill2d = true;
@@ -137,6 +138,12 @@ function calc(gd, trace) {
137138
return [{x: false, y: false, t: stash, trace: trace}];
138139
}
139140

141+
function expandForErrorBars(trace, ax, opts) {
142+
var extremes = trace._extremes[ax._id];
143+
var errExt = findExtremes(ax, opts._bnds, {padded: true});
144+
extremes.min = extremes.min.concat(errExt.min);
145+
extremes.max = extremes.max.concat(errExt.max);
146+
}
140147

141148
// create scene options
142149
function sceneOptions(gd, subplot, trace, positions, x, y) {

src/traces/splom/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@ function calc(gd, trace) {
6666
var xa = AxisIDs.getFromId(gd, trace._diag[i][0]) || {};
6767
var ya = AxisIDs.getFromId(gd, trace._diag[i][1]) || {};
6868

69-
// Re-use SVG scatter axis expansion routine except
70-
// for graph with very large number of points where it
71-
// performs poorly.
72-
// In big data case, fake Axes.expand outputs with data bounds,
73-
// and an average size for array marker.size inputs.
69+
// Reuse SVG scatter axis expansion routine.
70+
// For graphs with very large number of points and array marker.size,
71+
// use average marker size instead to speed things up.
7472
var ppad;
7573
if(hasTooManyPoints) {
7674
ppad = 2 * (opts.sizeAvg || Math.max(opts.size, 3));

src/traces/violin/calc.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ module.exports = function calc(gd, trace) {
3535
};
3636
}
3737

38+
var spanMin = Infinity;
39+
var spanMax = -Infinity;
40+
3841
for(var i = 0; i < cd.length; i++) {
3942
var cdi = cd[i];
4043
var vals = cdi.pts.map(helpers.extractVal);
@@ -62,10 +65,15 @@ module.exports = function calc(gd, trace) {
6265
cdi.density[k] = {v: v, t: t};
6366
}
6467

65-
Axes.expand(valAxis, span, {padded: true});
6668
groupStats.maxCount = Math.max(groupStats.maxCount, vals.length);
69+
70+
spanMin = Math.min(spanMin, span[0]);
71+
spanMax = Math.max(spanMax, span[1]);
6772
}
6873

74+
var extremes = Axes.findExtremes(valAxis, [spanMin, spanMax], {padded: true});
75+
trace._extremes[valAxis._id] = extremes;
76+
6977
cd[0].t.labels.kde = Lib._(gd, 'kde:');
7078

7179
return cd;

0 commit comments

Comments
 (0)