Skip to content

Commit 5d4c84a

Browse files
committed
bar: fix expansion of position axis
1 parent 83168bd commit 5d4c84a

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

src/traces/bar/set_positions.js

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -407,28 +407,27 @@ function updatePositionAxis(gd, pa, sieve, allowMinDtick) {
407407
vpad = minDiff / 2;
408408

409409
Axes.minDtick(pa, minDiff, distinctPositions0, allowMinDtick);
410-
Axes.expand(pa, distinctPositions, {vpad: vpad});
411410

412411
// if user set bar width or offset,
413412
// then check whether axis needs expanding
414-
var minPos = Math.min.apply(Math, distinctPositions) - vpad,
415-
maxPos = Math.max.apply(Math, distinctPositions) + vpad,
416-
pMin, pMinOffset, pMinWidth,
417-
pMax, pMaxOffset, pMaxWidth;
413+
var pMin = Math.min.apply(Math, distinctPositions) - vpad,
414+
pMax = Math.max.apply(Math, distinctPositions) + vpad;
415+
418416
for(var i = 0; i < calcTraces.length; i++) {
419417
var calcTrace = calcTraces[i],
420418
calcTrace0 = calcTrace[0],
421-
fullTrace = calcTrace0.trace,
422-
t = calcTrace0.t,
423-
poffset = t.poffset,
424-
poffsetIsArray = Array.isArray(poffset),
425-
barwidth = t.barwidth,
426-
barwidthIsArray = Array.isArray(barwidth);
419+
fullTrace = calcTrace0.trace;
427420

428421
if(fullTrace.width === undefined && fullTrace.offset === undefined) {
429422
continue;
430423
}
431424

425+
var t = calcTrace0.t,
426+
poffset = t.poffset,
427+
barwidth = t.barwidth,
428+
poffsetIsArray = Array.isArray(poffset),
429+
barwidthIsArray = Array.isArray(barwidth);
430+
432431
for(var j = 0; j < calcTrace.length; j++) {
433432
var calcBar = calcTrace[j],
434433
calcBarOffset = (poffsetIsArray) ? poffset[j] : poffset,
@@ -437,29 +436,12 @@ function updatePositionAxis(gd, pa, sieve, allowMinDtick) {
437436
l = p + calcBarOffset,
438437
r = l + calcBarWidth;
439438

440-
if(r >= maxPos) {
441-
maxPos = r;
442-
pMax = p;
443-
pMaxOffset = calcBarOffset;
444-
pMaxWidth = calcBarWidth;
445-
}
446-
if(l <= minPos) {
447-
minPos = r;
448-
pMin = p;
449-
pMinOffset = calcBarOffset;
450-
pMinWidth = calcBarWidth;
451-
}
439+
pMin = Math.min(pMin, l);
440+
pMax = Math.max(pMax, r);
452441
}
453442
}
454443

455-
if(pMin) {
456-
vpad = pMinWidth / 2;
457-
Axes.expand(pa, [pMin + pMinOffset + vpad], {vpad: vpad});
458-
}
459-
if(pMax) {
460-
vpad = pMaxWidth / 2;
461-
Axes.expand(pa, [pMax + pMaxOffset + vpad], {vpad: vpad});
462-
}
444+
Axes.expand(pa, [pMin, pMax], {padded: false});
463445
}
464446

465447

0 commit comments

Comments
 (0)