Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6aa7adc

Browse files
committed
bar: fix normalised group bar plots
* Fixed bug computing the normalisation of bar plots in group mode. * The bug was caused by calling `sieve.put` with bar sizes that didn't take into account the bar base. * Bar plots in stack and relative mode weren't affected by this bug, because traces that set a bar base are excluded from the stack/relative mode.
1 parent c597b8c commit 6aa7adc

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/traces/bar/set_positions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,8 @@ function stackBars(gd, sa, sieve) {
485485
if(!isNumeric(bar.s)) continue;
486486

487487
// stack current bar and get previous sum
488-
var barBase = sieve.put(bar.p, bar.s),
489-
barTop = barBase + bar.s;
488+
var barBase = sieve.put(bar.p, bar.b + bar.s),
489+
barTop = barBase + bar.b + bar.s;
490490

491491
// store the bar base and top in each calcdata item
492492
bar.b = barBase;
@@ -524,7 +524,7 @@ function sieveBars(gd, sa, sieve) {
524524
for(var j = 0; j < trace.length; j++) {
525525
var bar = trace[j];
526526

527-
if(isNumeric(bar.s)) sieve.put(bar.p, bar.s);
527+
if(isNumeric(bar.s)) sieve.put(bar.p, bar.b + bar.s);
528528
}
529529
}
530530
}

test/jasmine/tests/bar_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,27 @@ describe('Bar.setPositions', function() {
453453
assertPointField(cd, 'y', [[0.75, 0.50, 0.25], [0.25, 0.50, 0.75]]);
454454
});
455455

456+
it('should honor barnorm (group+base case)', function() {
457+
var gd = mockBarPlot([{
458+
base: [3, 2, 1],
459+
y: [0, 0, 0]
460+
}, {
461+
y: [1, 2, 3]
462+
}], {
463+
bargap: 0,
464+
barmode: 'group',
465+
barnorm: 'fraction'
466+
});
467+
468+
expect(gd._fullLayout.barnorm).toBe('fraction');
469+
470+
var cd = gd.calcdata;
471+
assertPointField(cd, 'b', [[0.75, 0.50, 0.25], [0, 0, 0]]);
472+
assertPointField(cd, 's', [[0, 0, 0], [0.25, 0.50, 0.75]]);
473+
assertPointField(cd, 'x', [[-0.25, 0.75, 1.75], [0.25, 1.25, 2.25]]);
474+
assertPointField(cd, 'y', [[0.75, 0.50, 0.25], [0.25, 0.50, 0.75]]);
475+
});
476+
456477
it('should honor barnorm (stack case)', function() {
457478
var gd = mockBarPlot([{
458479
y: [3, 2, 1]

0 commit comments

Comments
 (0)