Skip to content

Recycled commits from abandoned fast trace toggle PRs #2860

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 21 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
69dc0c4
DRY and small pref boost for scattergl
etpinard Jul 31, 2018
41ad08a
push trace module into fullLayout._modules even if visible:false
etpinard Jul 23, 2018
9c8ba02
fill in list of visible:true module in fullLayout._visibleModules
etpinard Jul 23, 2018
8ef5cb3
fix and :lock: splom trace visible toggling
etpinard Jul 23, 2018
cf0b19d
sub fail -> failTest
etpinard Jul 26, 2018
9cc5fbe
add scatter visibility restyles tests
etpinard Jul 25, 2018
dfada6a
add bar autorange tests & move 'b' init to setPositions
etpinard Jul 26, 2018
be44366
add findExtremes
etpinard Jul 25, 2018
ad1ac1f
adapt getAutoRange and doAutoRange to trace _extremes
etpinard Jul 25, 2018
769c160
fill trace._extremes with findExtremes in calc
etpinard Jul 25, 2018
736ab69
replace Axex.expand -> findExtremes in annotations and shapes
etpinard Jul 25, 2018
6194457
:hocho: ax._min / ax._max logic for rangeslider
etpinard Jul 25, 2018
8cd06ae
adapt enforceConstraints to new per trace/item _extremes
etpinard Jul 25, 2018
2a745de
adapt polar to new per trace/item _extremes
etpinard Jul 25, 2018
82d4bcc
adapt gl2d to findExtremes
etpinard Jul 26, 2018
29db388
:hocho: Axes.expand & adapt test for findExtremes
etpinard Jul 26, 2018
72f06a6
improve concatExtremes perf
etpinard Jul 27, 2018
a0bfaf3
collapse trace extremes before getAutorange
etpinard Jul 30, 2018
33b4085
mv repeat -> Lib.repeat
etpinard Aug 1, 2018
d233f3b
fix and :lock: _extremes in polar tranformed traces
etpinard Aug 1, 2018
89aebd1
fix typos in :books:
etpinard Aug 1, 2018
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
24 changes: 13 additions & 11 deletions src/components/errorbars/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@ module.exports = function calc(gd) {
var calcdata = gd.calcdata;

for(var i = 0; i < calcdata.length; i++) {
var calcTrace = calcdata[i],
trace = calcTrace[0].trace;

if(!Registry.traceIs(trace, 'errorBarsOK')) continue;

var xa = Axes.getFromId(gd, trace.xaxis),
ya = Axes.getFromId(gd, trace.yaxis);

calcOneAxis(calcTrace, trace, xa, 'x');
calcOneAxis(calcTrace, trace, ya, 'y');
var calcTrace = calcdata[i];
var trace = calcTrace[0].trace;

if(trace.visible === true && Registry.traceIs(trace, 'errorBarsOK')) {
var xa = Axes.getFromId(gd, trace.xaxis);
var ya = Axes.getFromId(gd, trace.yaxis);
calcOneAxis(calcTrace, trace, xa, 'x');
calcOneAxis(calcTrace, trace, ya, 'y');
}
}
};

Expand All @@ -57,5 +56,8 @@ function calcOneAxis(calcTrace, trace, axis, coord) {
}
}

Axes.expand(axis, vals, {padded: true});
var extremes = Axes.findExtremes(axis, vals, {padded: true});
var axId = axis._id;
trace._extremes[axId].min = trace._extremes[axId].min.concat(extremes.min);
trace._extremes[axId].max = trace._extremes[axId].max.concat(extremes.max);
}
1 change: 1 addition & 0 deletions src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ axes.getFromTrace = axisIds.getFromTrace;
var autorange = require('./autorange');
axes.expand = autorange.expand;
axes.getAutoRange = autorange.getAutoRange;
axes.findExtremes = autorange.findExtremes;

/*
* find the list of possible axes to reference with an xref or yref attribute
Expand Down
5 changes: 4 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2455,10 +2455,13 @@ plots.doCalcdata = function(gd, traces) {
}
}

// find array attributes in trace
for(i = 0; i < fullData.length; i++) {
trace = fullData[i];

trace._arrayAttrs = PlotSchema.findArrayAttributes(trace);

// keep track of trace extremes (for autorange) in here
trace._extremes = {};
}

// add polar axes to axis list
Expand Down
20 changes: 16 additions & 4 deletions src/traces/bar/set_positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ function updatePositionAxis(gd, pa, sieve, allowMinDtick) {
}
}

Axes.expand(pa, [pMin, pMax], {padded: false});
var extremes = Axes.findExtremes(pa, [pMin, pMax], {padded: false});
putExtremes(calcTraces, pa, extremes);
}

function expandRange(range, newValue) {
Expand Down Expand Up @@ -530,7 +531,8 @@ function setBaseAndTop(gd, sa, sieve) {
}
}

Axes.expand(sa, sRange, {tozero: true, padded: true});
var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: true});
putExtremes(traces, sa, extremes);
}


Expand Down Expand Up @@ -568,7 +570,10 @@ function stackBars(gd, sa, sieve) {
}

// if barnorm is set, let normalizeBars update the axis range
if(!barnorm) Axes.expand(sa, sRange, {tozero: true, padded: true});
if(!barnorm) {
var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: true});
putExtremes(traces, sa, extremes);
}
}


Expand Down Expand Up @@ -633,14 +638,21 @@ function normalizeBars(gd, sa, sieve) {
}

// update range of size axis
Axes.expand(sa, sRange, {tozero: true, padded: padded});
var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: padded});
putExtremes(traces, sa, extremes);
}


function getAxisLetter(ax) {
return ax._id.charAt(0);
}

function putExtremes(cd, ax, extremes) {
for(var i = 0; i < cd.length; i++) {
cd[i][0].trace._extremes[ax._id] = extremes;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we're not trying to make _extremes survive visibility changes, does it actually help to have the same thing repeated in all traces here? Seems like that will just waste time later on. Can we just put it in the first one and clear all the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, but turns out we still need to attach _extremes to all bar traces at the moment for error bars. Error bars concat their min/max extremes into the trace._extremes in which they are linked and assume that trace._extremes[ax._id] exists.

We could alternatively linked error bar _extremes in their trace.error_(x|y) containers and make getAutorange look for error_(x|y) in each trace. Or perhaps, making error bar create trace._extremes[ax._id] containers when needed would suffice.

But, I wouldn't worry too much about performance. I can't imagine getAutorange taking more than 1ms even in the worse of scenario.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah OK. I suppose the first one could have the actual values, then all the others could just get [] to give something for errorbars to append to... but yeah, no big deal, no block. These extras will get pruned quickly during your improved _concat that I hadn't noticed when I made that comment.


// find the full position span of bars at each position
// for use by hover, to ensure labels move in if bars are
// narrower than the space they're in.
Expand Down
3 changes: 2 additions & 1 deletion src/traces/box/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ module.exports = function calc(gd, trace) {
}

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

if(cd.length > 0) {
cd[0].t = {
Expand Down
17 changes: 10 additions & 7 deletions src/traces/box/set_positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,26 @@ function setPositionOffset(traceType, gd, boxList, posAxis, pad) {
// check for forced minimum dtick
Axes.minDtick(posAxis, boxdv.minDiff, boxdv.vals[0], true);

// set the width of all boxes
for(i = 0; i < boxList.length; i++) {
calcTrace = calcdata[boxList[i]];
calcTrace[0].t.dPos = dPos;
}

var gap = fullLayout[traceType + 'gap'];
var groupgap = fullLayout[traceType + 'groupgap'];
var padfactor = (1 - gap) * (1 - groupgap) * dPos / fullLayout[numKey];

// autoscale the x axis - including space for points if they're off the side
// TODO: this will overdo it if the outermost boxes don't have
// their points as far out as the other boxes
Axes.expand(posAxis, boxdv.vals, {
var extremes = Axes.findExtremes(posAxis, boxdv.vals, {
vpadminus: dPos + pad[0] * padfactor,
vpadplus: dPos + pad[1] * padfactor
});

for(i = 0; i < boxList.length; i++) {
calcTrace = calcdata[boxList[i]];
// set the width of all boxes
calcTrace[0].t.dPos = dPos;
// link extremes to all boxes
calcTrace[0].trace._extremes[posAxis._id] = extremes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

same question as for bars... can we just put these extremes in the first one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

... for consistency I'm leaning on voting for making all traces have an _extremes container. Like in my last comment, I can't imagine getAutorange ever being a performance drag.

}

}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions src/traces/carpet/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ module.exports = function calc(gd, trace) {
xrange = [xc - dx * grow, xc + dx * grow];
yrange = [yc - dy * grow, yc + dy * grow];

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

// Enumerate the gridlines, both major and minor, and store them on the trace
// object:
Expand Down
4 changes: 2 additions & 2 deletions src/traces/heatmap/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ module.exports = function calc(gd, trace) {

// handled in gl2d convert step
if(!isGL2D) {
Axes.expand(xa, xArray);
Axes.expand(ya, yArray);
trace._extremes[xa._id] = Axes.findExtremes(xa, xArray);
trace._extremes[ya._id] = Axes.findExtremes(ya, yArray);
}

var cd0 = {
Expand Down
5 changes: 2 additions & 3 deletions src/traces/ohlc/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ function calc(gd, trace) {

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

Axes.expand(xa, x, {vpad: minDiff / 2});

trace._extremes[xa._id] = Axes.findExtremes(xa, x, {vpad: minDiff / 2});
if(cd.length) {
Lib.extendFlat(cd[0].t, {
wHover: minDiff / 2,
Expand Down Expand Up @@ -93,7 +92,7 @@ function calcCommon(gd, trace, x, ya, ptFunc) {
}
}

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

if(cd.length) {
cd[0].t = {
Expand Down
4 changes: 2 additions & 2 deletions src/traces/scatter/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ function calcAxisExpansion(gd, trace, xa, ya, x, y, ppad) {
}

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

function calcMarkerSize(trace, serieslen) {
Expand Down
6 changes: 2 additions & 4 deletions src/traces/scattergl/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var rgba = require('color-normalize');
var Registry = require('../../registry');
var Lib = require('../../lib');
var Drawing = require('../../components/drawing');
var Axes = require('../../plots/cartesian/axes');
var AxisIDs = require('../../plots/cartesian/axis_ids');

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

Axes.expand(ax, [minShoe, maxHat], {padded: true});

out[axLetter] = {
positions: positions,
errors: errors
errors: errors,
_bnds: [minShoe, maxHat]
};
}
}
Expand Down
17 changes: 12 additions & 5 deletions src/traces/scattergl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var Registry = require('../../registry');
var Lib = require('../../lib');
var prepareRegl = require('../../lib/prepare_regl');
var AxisIDs = require('../../plots/cartesian/axis_ids');
var findExtremes = require('../../plots/cartesian/autorange').findExtremes;
var Color = require('../../components/color');

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

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

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

function expandForErrorBars(trace, ax, opts) {
var extremes = trace._extremes[ax._id];
var errExt = findExtremes(ax, opts._bnds, {padded: true});
extremes.min = extremes.min.concat(errExt.min);
extremes.max = extremes.max.concat(errExt.max);
}

// create scene options
function sceneOptions(gd, subplot, trace, positions, x, y) {
Expand Down
8 changes: 3 additions & 5 deletions src/traces/splom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ function calc(gd, trace) {
var xa = AxisIDs.getFromId(gd, trace._diag[i][0]) || {};
var ya = AxisIDs.getFromId(gd, trace._diag[i][1]) || {};

// Re-use SVG scatter axis expansion routine except
// for graph with very large number of points where it
// performs poorly.
// In big data case, fake Axes.expand outputs with data bounds,
// and an average size for array marker.size inputs.
// Reuse SVG scatter axis expansion routine.
// For graphs with very large number of points and array marker.size,
// use average marker size instead to speed things up.
var ppad;
if(hasTooManyPoints) {
ppad = 2 * (opts.sizeAvg || Math.max(opts.size, 3));
Expand Down
10 changes: 9 additions & 1 deletion src/traces/violin/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ module.exports = function calc(gd, trace) {
};
}

var spanMin = Infinity;
var spanMax = -Infinity;

for(var i = 0; i < cd.length; i++) {
var cdi = cd[i];
var vals = cdi.pts.map(helpers.extractVal);
Expand Down Expand Up @@ -62,10 +65,15 @@ module.exports = function calc(gd, trace) {
cdi.density[k] = {v: v, t: t};
}

Axes.expand(valAxis, span, {padded: true});
groupStats.maxCount = Math.max(groupStats.maxCount, vals.length);

spanMin = Math.min(spanMin, span[0]);
spanMax = Math.max(spanMax, span[1]);
}

var extremes = Axes.findExtremes(valAxis, [spanMin, spanMax], {padded: true});
trace._extremes[valAxis._id] = extremes;

cd[0].t.labels.kde = Lib._(gd, 'kde:');

return cd;
Expand Down