Skip to content

Per-trace axis extremes #2849

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

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
67db333
add axis.range under visible edits test
etpinard Jul 25, 2018
3e817f3
add findExtremes
etpinard Jul 25, 2018
1cd8482
add _extremes to all traces in calc
etpinard Jul 25, 2018
e9d3ca0
adapt getAutoRange and doAutoRange to trace _extremes
etpinard Jul 25, 2018
2966cf3
generalize concatExtremes for polar, splom and layout components
etpinard Jul 25, 2018
a9cf2e1
replace Axes.expand -> findExtremes in traces/
etpinard Jul 25, 2018
13cb0f0
replace Axex.expand -> findExtremes in annotations and shapes
etpinard Jul 25, 2018
d24eaef
replace Axes.expand -> findExtremes for ErrorBars
etpinard Jul 25, 2018
d9bb617
:hocho: ax._min / ax._max logic for rangeslider
etpinard Jul 25, 2018
9b02ac4
adapt enforceConstraints to new per trace/item _extremes
etpinard Jul 25, 2018
d407c90
adapt polar to new per trace/item _extremes
etpinard Jul 25, 2018
9ab0c2f
:hocho: obsolete comments about ax._min / ax._max
etpinard Jul 25, 2018
6e866c2
adapt gl2d to findExtremes
etpinard Jul 26, 2018
c45427b
:hocho: Axes.expand
etpinard Jul 26, 2018
e77cacc
adapt test for Axex.expand -> findExtremes change
etpinard Jul 26, 2018
ba3c903
adapt test to new getAutoRange API
etpinard Jul 26, 2018
424f4a6
sub fail -> failTest
etpinard Jul 26, 2018
4c250c3
setPositions even when recalc===false
etpinard Jul 26, 2018
5becba0
udpdate jsdoc for Axes.getAutoRange
etpinard Jul 26, 2018
66df51e
use ax.(_traceIndices, annIndices, shapeIndices)
etpinard Jul 27, 2018
d0699c0
fixups (from AJ's review)
etpinard Jul 27, 2018
f1cda60
add bar stack visible -> autorange test & move 'b' init to setPositions
etpinard Jul 27, 2018
9a78013
make annotations & shapes 'visible' -> 'plot' edit type
etpinard Jul 27, 2018
5cfee13
Revert "make annotations & shapes 'visible' -> 'plot' edit type"
etpinard Jul 30, 2018
62f1549
add fallback for _extremes during concat
etpinard Jul 30, 2018
aac11a2
collapse trace extremes before getAutorange
etpinard Jul 30, 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
87 changes: 58 additions & 29 deletions src/plots/cartesian/autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var isNumeric = require('fast-isnumeric');
Expand All @@ -24,6 +23,7 @@ module.exports = {

// Find the autorange for this axis
//
// TODO update!!
// assumes ax._min and ax._max have already been set by calling axes.expand
// using calcdata from all traces. These are arrays of objects:
// {
Expand All @@ -39,42 +39,50 @@ module.exports = {
// 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) {
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 +98,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 +140,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 +178,40 @@ function makePadFn(ax) {
return function getPad(pt) { return pt.pad + (pt.extrapad ? extrappad : 0); };
}

function doAutoRange(ax) {
function concatExtremes(gd, ax, k) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. Come to think of it, this thing will be a drag. Looping over all traces, annotations and shapes for every axis, doesn't scale very well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improvements in -> 66df51e

var i;
var out = [];

var fullData = gd._fullData;
var attr = ax._id.charAt(0) + 'axis';

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

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

if(trace.visible === true && (
trace[attr] === ax._id
)) {
out = out.concat(trace._extremes[attr][k]);
}
}

// - annotation
// - shapes
// - annotation3d
// - errorbars?

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