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
2 changes: 1 addition & 1 deletion src/components/rangeslider/calc_autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function calcAutorange(gd) {

if(opts && opts.visible && opts.autorange && ax._min.length && ax._max.length) {
opts._input.autorange = true;
opts._input.range = opts.range = getAutoRange(ax);
opts._input.range = opts.range = getAutoRange(gd, ax);
}
}
};
2 changes: 1 addition & 1 deletion src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ exports.doAutoRangeAndConstraints = function(gd) {
for(var i = 0; i < axList.length; i++) {
var ax = axList[i];
cleanAxisConstraints(gd, ax);
doAutoRange(ax);
doAutoRange(gd, ax);
}

enforceAxisConstraints(gd);
Expand Down
160 changes: 114 additions & 46 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var isNumeric = require('fast-isnumeric');

var Lib = require('../../lib');
var FP_SAFE = require('../../constants/numerical').FP_SAFE;

var Registry = require('../../registry');

module.exports = {
getAutoRange: getAutoRange,
makePadFn: makePadFn,
Expand All @@ -22,59 +23,77 @@ module.exports = {
findExtremes: findExtremes
};

// Find the autorange for this axis
//
// assumes ax._min and ax._max have already been set by calling axes.expand
// using calcdata from all traces. These are arrays of objects:
// {
// val: calcdata value,
// pad: extra pixels beyond this value,
// extrapad: bool, does this point want 5% extra padding
// }
//
// Returns an array of [min, max]. These are calcdata for log and category axes
// and data for linear and date axes.
//
// TODO: we want to change log to data as well, but it's hard to do this
// maintaining backward compatibility. category will always have to use calcdata
// though, because otherwise values between categories (or outside all categories)
// would be impossible.
function getAutoRange(ax) {
/**
* getAutoRange
*
* Collects all _extremes values corresponding to a given axis
* and computes its auto range.
*
* getAutoRange uses return values from findExtremes where:
*
* {
* val: calcdata value,
* pad: extra pixels beyond this value,
* extrapad: bool, does this point want 5% extra padding
* }
*
* @param {object} gd:
* graph div object with filled in fullData and fullLayout,
* @param {object} ax:
* full axis object
* @return {array}
* an array of [min, max]. These are calcdata for log and category axes
* and data for linear and date axes.
*
* TODO: we want to change log to data as well, but it's hard to do this
* maintaining backward compatibility. category will always have to use calcdata
* though, because otherwise values between categories (or outside all categories)
* would be impossible.
*/
function getAutoRange(gd, ax) {
var i, j;
var newRange = [];
var minmin = ax._min[0].val;
var maxmax = ax._max[0].val;
var mbest = 0;
var axReverse = false;

var getPad = makePadFn(ax);
var minArray = concatExtremes(gd, ax, 'min');
var maxArray = concatExtremes(gd, ax, 'max');

var i, j, minpt, maxpt, minbest, maxbest, dp, dv;
if(minArray.length === 0 || maxArray.length === 0) {
return Lib.simpleMap(ax.range, ax.r2l);
}

for(i = 1; i < ax._min.length; i++) {
var minmin = minArray[0].val;
var maxmax = maxArray[0].val;

for(i = 1; i < minArray.length; i++) {
if(minmin !== maxmax) break;
minmin = Math.min(minmin, ax._min[i].val);
minmin = Math.min(minmin, minArray[i].val);
}
for(i = 1; i < ax._max.length; i++) {
for(i = 1; i < maxArray.length; i++) {
if(minmin !== maxmax) break;
maxmax = Math.max(maxmax, ax._max[i].val);
maxmax = Math.max(maxmax, maxArray[i].val);
}

var axReverse = false;

if(ax.range) {
var rng = Lib.simpleMap(ax.range, ax.r2l);
axReverse = rng[1] < rng[0];
}

// one-time setting to easily reverse the axis
// when plotting from code
if(ax.autorange === 'reversed') {
axReverse = true;
ax.autorange = true;
}

for(i = 0; i < ax._min.length; i++) {
minpt = ax._min[i];
for(j = 0; j < ax._max.length; j++) {
maxpt = ax._max[j];
var mbest = 0;
var minpt, maxpt, minbest, maxbest, dp, dv;

for(i = 0; i < minArray.length; i++) {
minpt = minArray[i];
for(j = 0; j < maxArray.length; j++) {
maxpt = maxArray[j];
dv = maxpt.val - minpt.val;
dp = ax._length - getPad(minpt) - getPad(maxpt);
if(dv > 0 && dp > 0 && dv / dp > mbest) {
Expand All @@ -90,11 +109,9 @@ function getAutoRange(ax) {
var upper = minmin + 1;
if(ax.rangemode === 'tozero') {
newRange = minmin < 0 ? [lower, 0] : [0, upper];
}
else if(ax.rangemode === 'nonnegative') {
} else if(ax.rangemode === 'nonnegative') {
newRange = [Math.max(0, lower), Math.max(0, upper)];
}
else {
} else {
newRange = [lower, upper];
}
}
Expand Down Expand Up @@ -134,11 +151,9 @@ function getAutoRange(ax) {
if(ax.rangemode === 'tozero') {
if(newRange[0] < 0) {
newRange = [newRange[0], 0];
}
else if(newRange[0] > 0) {
} else if(newRange[0] > 0) {
newRange = [0, newRange[0]];
}
else {
} else {
newRange = [0, 1];
}
}
Expand Down Expand Up @@ -174,15 +189,68 @@ function makePadFn(ax) {
return function getPad(pt) { return pt.pad + (pt.extrapad ? extrappad : 0); };
}

function doAutoRange(ax) {
function concatExtremes(gd, ax, ext) {
var i;
var out = [];

var fullData = gd._fullData;

// should be general enough for 3d, polar etc.

for(i = 0; i < fullData.length; i++) {
var trace = fullData[i];
var extremes = trace._extremes;

if(trace.visible === true) {
if(Registry.traceIs(trace, 'cartesian')) {
var axId = ax._id;
if(extremes[axId]) {
out = out.concat(extremes[axId][ext]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think my #2849 (comment) and #2849 (comment) still hold, and we should prune these the same way as in findExtremes to minimize O(min.length * max.length) in doAutoRange.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh sorry, you did that in a0bfaf3 🎉 and also 🌴 🏆 💯

Copy link
Contributor Author

@etpinard etpinard Aug 1, 2018

Choose a reason for hiding this comment

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

Yeah I tried to squash a0bfaf3 and 72f06a6 into ad1ac1f, but that was too much of a 🤕

}
} else if(Registry.traceIs(trace, 'polar')) {
if(trace.subplot === ax._subplot) {
out = out.concat(extremes[ax._name][ext]);
}
}
}
}

var fullLayout = gd._fullLayout;
var annotations = fullLayout.annotations;
var shapes = fullLayout.shapes;

if(Array.isArray(annotations)) {
out = out.concat(concatComponentExtremes(annotations, ax, ext));
}
if(Array.isArray(shapes)) {
out = out.concat(concatComponentExtremes(shapes, ax, ext));
}

return out;
}

function concatComponentExtremes(items, ax, ext) {
var out = [];
var axId = ax._id;
var letter = axId.charAt(0);

for(var i = 0; i < items.length; i++) {
var d = items[i];
var extremes = d._extremes;
if(d.visible && d[letter + 'ref'] === axId && extremes[axId]) {
out = out.concat(extremes[axId][ext]);
}
}
return out;
}

function doAutoRange(gd, ax) {
if(!ax._length) ax.setScale();

// TODO do we really need this?
var hasDeps = (ax._min && ax._max && ax._min.length && ax._max.length);
var axIn;

if(ax.autorange && hasDeps) {
ax.range = getAutoRange(ax);
if(ax.autorange) {
ax.range = getAutoRange(gd, ax);

ax._r = ax.range.slice();
ax._rl = Lib.simpleMap(ax._r, ax.r2l);
Expand Down
Loading