Skip to content

Bar & ErrorBar autorange fixes #3452

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 5 commits into from
Jan 22, 2019
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
make posAxis findExtremes calls per-trace
  • Loading branch information
etpinard committed Jan 21, 2019
commit c14ad6972b5b0537819002a1b504d254c4da28ee
60 changes: 26 additions & 34 deletions src/traces/bar/cross_trace_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,52 +420,44 @@ function setBarCenterAndWidth(gd, pa, sieve) {

function updatePositionAxis(gd, pa, sieve, allowMinDtick) {
var calcTraces = sieve.traces;
var distinctPositions = sieve.distinctPositions;
var distinctPositions0 = distinctPositions[0];
var minDiff = sieve.minDiff;
var vpad = minDiff / 2;

Axes.minDtick(pa, minDiff, distinctPositions0, allowMinDtick);

// If the user set the bar width or the offset,
// then bars can be shifted away from their positions
// and widths can be larger than minDiff.
//
// Here, we compute pMin and pMax to expand the position axis,
// so that all bars are fully within the axis range.
var pMin = Math.min.apply(Math, distinctPositions) - vpad;
var pMax = Math.max.apply(Math, distinctPositions) + vpad;
Axes.minDtick(pa, sieve.minDiff, sieve.distinctPositions[0], allowMinDtick);

for(var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var calcTrace0 = calcTrace[0];
var fullTrace = calcTrace0.trace;

if(fullTrace.width === undefined && fullTrace.offset === undefined) {
continue;
var pts = [];
var bar, l, r, j;

for(j = 0; j < calcTrace.length; j++) {
bar = calcTrace[j];
l = bar.p - vpad;
r = bar.p + vpad;
pts.push(l, r);
}

var t = calcTrace0.t;
var poffset = t.poffset;
var barwidth = t.barwidth;
var poffsetIsArray = Array.isArray(poffset);
var barwidthIsArray = Array.isArray(barwidth);

for(var j = 0; j < calcTrace.length; j++) {
var calcBar = calcTrace[j];
var calcBarOffset = (poffsetIsArray) ? poffset[j] : poffset;
var calcBarWidth = (barwidthIsArray) ? barwidth[j] : barwidth;
var p = calcBar.p;
var l = p + calcBarOffset;
var r = l + calcBarWidth;

pMin = Math.min(pMin, l);
pMax = Math.max(pMax, r);
if(fullTrace.width || fullTrace.offset) {
var t = calcTrace0.t;
var poffset = t.poffset;
var barwidth = t.barwidth;
var poffsetIsArray = Array.isArray(poffset);
var barwidthIsArray = Array.isArray(barwidth);

for(j = 0; j < calcTrace.length; j++) {
bar = calcTrace[j];
var calcBarOffset = poffsetIsArray ? poffset[j] : poffset;
var calcBarWidth = barwidthIsArray ? barwidth[j] : barwidth;
l = bar.p + calcBarOffset;
r = l + calcBarWidth;
pts.push(l, r);
}
}
}

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

function expandRange(range, newValue) {
Expand Down