Skip to content

Commit 5270abb

Browse files
authored
Merge pull request #3652 from plotly/fix-3649
histogram: remove gap when `barmode` is relative
2 parents ef932cf + bc3890b commit 5270abb

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

src/traces/bar/layout_defaults.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ module.exports = function(layoutIn, layoutOut, fullData) {
2424
var gappedAnyway = false;
2525
var usedSubplots = {};
2626

27+
var mode = coerce('barmode');
28+
2729
for(var i = 0; i < fullData.length; i++) {
2830
var trace = fullData[i];
2931
if(Registry.traceIs(trace, 'bar') && trace.visible) hasBars = true;
3032
else continue;
3133

3234
// if we have at least 2 grouped bar traces on the same subplot,
3335
// we should default to a gap anyway, even if the data is histograms
34-
if(layoutIn.barmode !== 'overlay' && layoutIn.barmode !== 'stack') {
36+
if(mode === 'group') {
3537
var subploti = trace.xaxis + trace.yaxis;
3638
if(usedSubplots[subploti]) gappedAnyway = true;
3739
usedSubplots[subploti] = true;
@@ -44,9 +46,11 @@ module.exports = function(layoutIn, layoutOut, fullData) {
4446
}
4547
}
4648

47-
if(!hasBars) return;
49+
if(!hasBars) {
50+
delete layoutOut.barmode;
51+
return;
52+
}
4853

49-
var mode = coerce('barmode');
5054
if(mode !== 'overlay') coerce('barnorm');
5155

5256
coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"data": [{
3+
"type": "histogram",
4+
"x": [9, 9, 3, 2, 5, 1, 3, 0, 6, 8, 5, 7, 2, 9, 9, 8, 5, 4, 1, 9, 2, 8, 0, 7, 2, 3, 5, 0, 3, 8, 2, 1, 7, 7, 7, 3, 9, 7, 8, 1, 7, 9, 4, 6, 2, 4, 2, 9, 3, 1, 5, 1, 6, 7, 6, 1, 6, 8, 6, 7, 8, 3, 7, 3, 1, 0, 2, 6, 1, 2, 7, 2, 9, 6, 2, 8, 0, 0, 9, 8, 5, 5, 8, 3, 5, 7, 7, 8, 3, 9, 3, 1, 5, 3, 5, 0, 8, 9, 4, 3]
5+
}, {
6+
"type": "histogram",
7+
"x": [6, 7, 8, 0, 8, 1, 5, 4, 4, 3, 4, 7, 5, 3, 9, 5, 2, 5, 5, 4, 3, 5, 2, 6, 3, 9, 8, 5, 3, 8, 7, 2, 2, 7, 3, 7, 0, 1, 1, 1, 2, 1, 4, 9, 3, 5, 4, 1, 1, 2, 0, 2, 8, 1, 0, 3, 1, 2, 3, 5, 3, 8, 6, 1, 1, 0, 0, 0, 8, 6, 0, 8, 6, 8, 0, 9, 4, 4, 0, 7, 7, 9, 2, 8, 0, 9, 0, 5, 7, 2, 9, 6, 5, 0, 0, 4, 6, 0, 9, 8]
8+
}],
9+
"layout": {
10+
"width": 600,
11+
"barmode": "relative"
12+
}
13+
}

test/jasmine/tests/bar_test.js

+14
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ describe('Bar.supplyDefaults', function() {
226226
expect(gd._fullData[0].alignmentgroup).toBe(undefined, 'alignementgroup');
227227
expect(gd._fullData[0].offsetgroup).toBe(undefined, 'offsetgroup');
228228
});
229+
230+
it('should have a barmode only if it contains bars', function() {
231+
var gd = {
232+
data: [{type: 'histogram', y: [1], visible: false}],
233+
layout: {}
234+
};
235+
236+
supplyAllDefaults(gd);
237+
expect(gd._fullLayout.barmode).toBe(undefined, '`barmode` should be undefined');
238+
239+
gd.data[0].visible = true;
240+
supplyAllDefaults(gd);
241+
expect(gd._fullLayout.barmode).toBe('group', '`barmode` should be set to its default ');
242+
});
229243
});
230244

231245
describe('bar calc / crossTraceCalc (formerly known as setPositions)', function() {

0 commit comments

Comments
 (0)