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 19 commits
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
123 changes: 65 additions & 58 deletions src/components/annotations/calc_autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,63 +34,70 @@ function annAutorange(gd) {
Lib.filterVisible(fullLayout.annotations).forEach(function(ann) {
var xa = Axes.getFromId(gd, ann.xref);
var ya = Axes.getFromId(gd, ann.yref);
var headSize = 3 * ann.arrowsize * ann.arrowwidth || 0;
var startHeadSize = 3 * ann.startarrowsize * ann.arrowwidth || 0;

var headPlus, headMinus, startHeadPlus, startHeadMinus;

if(xa) {
headPlus = headSize + ann.xshift;
headMinus = headSize - ann.xshift;
startHeadPlus = startHeadSize + ann.xshift;
startHeadMinus = startHeadSize - ann.xshift;

if(ann.axref === ann.xref) {
// expand for the arrowhead (padded by arrowhead)
Axes.expand(xa, [xa.r2c(ann.x)], {
ppadplus: headPlus,
ppadminus: headMinus
});
// again for the textbox (padded by textbox)
Axes.expand(xa, [xa.r2c(ann.ax)], {
ppadplus: Math.max(ann._xpadplus, startHeadPlus),
ppadminus: Math.max(ann._xpadminus, startHeadMinus)
});
}
else {
startHeadPlus = ann.ax ? startHeadPlus + ann.ax : startHeadPlus;
startHeadMinus = ann.ax ? startHeadMinus - ann.ax : startHeadMinus;
Axes.expand(xa, [xa.r2c(ann.x)], {
ppadplus: Math.max(ann._xpadplus, headPlus, startHeadPlus),
ppadminus: Math.max(ann._xpadminus, headMinus, startHeadMinus)
});
}
}

if(ya) {
headPlus = headSize - ann.yshift;
headMinus = headSize + ann.yshift;
startHeadPlus = startHeadSize - ann.yshift;
startHeadMinus = startHeadSize + ann.yshift;

if(ann.ayref === ann.yref) {
Axes.expand(ya, [ya.r2c(ann.y)], {
ppadplus: headPlus,
ppadminus: headMinus
});
Axes.expand(ya, [ya.r2c(ann.ay)], {
ppadplus: Math.max(ann._ypadplus, startHeadPlus),
ppadminus: Math.max(ann._ypadminus, startHeadMinus)
});
}
else {
startHeadPlus = ann.ay ? startHeadPlus + ann.ay : startHeadPlus;
startHeadMinus = ann.ay ? startHeadMinus - ann.ay : startHeadMinus;
Axes.expand(ya, [ya.r2c(ann.y)], {
ppadplus: Math.max(ann._ypadplus, headPlus, startHeadPlus),
ppadminus: Math.max(ann._ypadminus, headMinus, startHeadMinus)
});
}
}

ann._extremes = {};
if(xa) calcAxisExpansion(ann, xa);
if(ya) calcAxisExpansion(ann, ya);
});
}

function calcAxisExpansion(ann, ax) {
var headSize = 3 * ann.arrowsize * ann.arrowwidth || 0;
var startHeadSize = 3 * ann.startarrowsize * ann.arrowwidth || 0;

var axId = ax._id;
var letter = axId.charAt(0);
var pos = ann[letter];
var apos = ann['a' + letter];
var ref = ann[letter + 'ref'];
var aref = ann['a' + letter + 'ref'];
var shift = ann[letter + 'shift'];
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you did * (letter === 'x' ? 1 : -1) the switch below would collapse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes -> d0699c0

var padplus = ann['_' + letter + 'padplus'];
var padminus = ann['_' + letter + 'padminus'];

var headPlus, headMinus;
var startHeadPlus, startHeadMinus;

switch(letter) {
case 'x':
headPlus = headSize + shift;
headMinus = headSize - shift;
startHeadPlus = startHeadSize + shift;
startHeadMinus = startHeadSize - shift;
break;
case 'y':
headPlus = headSize - shift;
headMinus = headSize + shift;
startHeadPlus = startHeadSize - shift;
startHeadMinus = startHeadSize + shift;
break;
}

var extremes;

if(aref === ref) {
// expand for the arrowhead (padded by arrowhead)
var extremeArrowHead = Axes.findExtremes(ax, [ax.r2c(pos)], {
ppadplus: headPlus,
ppadminus: headMinus
});
// again for the textbox (padded by textbox)
var extremeText = Axes.findExtremes(ax, [ax.r2c(apos)], {
ppadplus: Math.max(padplus, startHeadPlus),
ppadminus: Math.max(padminus, startHeadMinus)
});
extremes = {
min: [extremeArrowHead.min[0], extremeText.min[0]],
max: [extremeArrowHead.max[0], extremeText.max[0]]
};
} else {
startHeadPlus = apos ? startHeadPlus + apos : startHeadPlus;
startHeadMinus = apos ? startHeadMinus - apos : startHeadMinus;
extremes = Axes.findExtremes(ax, [ax.r2c(pos)], {
ppadplus: Math.max(padplus, headPlus, startHeadPlus),
ppadminus: Math.max(padminus, headMinus, startHeadMinus)
});
}

ann._extremes[axId] = extremes;
}
5 changes: 4 additions & 1 deletion src/components/errorbars/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,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);
}
11 changes: 4 additions & 7 deletions src/components/rangeslider/calc_autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ module.exports = function calcAutorange(gd) {
// this step in subsequent draw calls.

for(var i = 0; i < axes.length; i++) {
var ax = axes[i],
opts = ax[constants.name];
var ax = axes[i];
var opts = ax[constants.name];

// Don't try calling getAutoRange if _min and _max are filled in.
// This happens on updates where the calc step is skipped.

if(opts && opts.visible && opts.autorange && ax._min.length && ax._max.length) {
if(opts && opts.visible && opts.autorange) {
opts._input.autorange = true;
opts._input.range = opts.range = getAutoRange(ax);
opts._input.range = opts.range = getAutoRange(gd, ax);
}
}
};
10 changes: 7 additions & 3 deletions src/components/shapes/calc_autorange.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = function calcAutorange(gd) {

for(var i = 0; i < shapeList.length; i++) {
var shape = shapeList[i];
shape._extremes = {};

var ax, bounds;

Expand All @@ -33,8 +34,9 @@ module.exports = function calcAutorange(gd) {
ax = Axes.getFromId(gd, shape.xref);

bounds = shapeBounds(ax, vx0, vx1, shape.path, constants.paramIsX);

if(bounds) Axes.expand(ax, bounds, calcXPaddingOptions(shape));
if(bounds) {
shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcXPaddingOptions(shape));
}
}

if(shape.yref !== 'paper') {
Expand All @@ -43,7 +45,9 @@ module.exports = function calcAutorange(gd) {
ax = Axes.getFromId(gd, shape.yref);

bounds = shapeBounds(ax, vy0, vy1, shape.path, constants.paramIsY);
if(bounds) Axes.expand(ax, bounds, calcYPaddingOptions(shape));
if(bounds) {
shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcYPaddingOptions(shape));
}
}
}
};
Expand Down
1 change: 1 addition & 0 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ exports.plot = function(gd, data, layout, config) {

function positionAndAutorange() {
if(!recalc) {
Plots.doSetPositions(gd);
doAutoRangeAndConstraints();
return;
}
Expand Down
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
Loading