Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions src/traces/bar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ module.exports = function(layoutIn, layoutOut, fullData) {
var gappedAnyway = false;
var usedSubplots = {};

var mode = coerce('barmode');

for(var i = 0; i < fullData.length; i++) {
var trace = fullData[i];
if(Registry.traceIs(trace, 'bar') && trace.visible) hasBars = true;
else continue;

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

if(!hasBars) return;
if(!hasBars) {
delete layoutOut.barmode;
Copy link
Contributor

Choose a reason for hiding this comment

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

++ a jasmine test in bar_test.js plz 😏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a jasmine test that checks _fullLayout doesn't have a barmode?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, that and the converse. Similar to

it('should not include alignementgroup/offsetgroup when barmode is not *group*', function() {
var gd = {
data: [{type: 'bar', y: [1], alignmentgroup: 'a', offsetgroup: '1'}],
layout: {barmode: 'group'}
};
supplyAllDefaults(gd);
expect(gd._fullData[0].alignmentgroup).toBe('a', 'alignementgroup');
expect(gd._fullData[0].offsetgroup).toBe('1', 'offsetgroup');
gd.layout.barmode = 'stack';
supplyAllDefaults(gd);
expect(gd._fullData[0].alignmentgroup).toBe(undefined, 'alignementgroup');
expect(gd._fullData[0].offsetgroup).toBe(undefined, 'offsetgroup');
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in bc3890b

return;
}

var mode = coerce('barmode');
if(mode !== 'overlay') coerce('barnorm');

coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions test/image/mocks/histogram_barmode_relative.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"data": [{
"type": "histogram",
"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]
}, {
"type": "histogram",
"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]
}],
"layout": {
"width": 600,
"barmode": "relative"
}
}
14 changes: 14 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ describe('Bar.supplyDefaults', function() {
expect(gd._fullData[0].alignmentgroup).toBe(undefined, 'alignementgroup');
expect(gd._fullData[0].offsetgroup).toBe(undefined, 'offsetgroup');
});

it('should have a barmode only if it contains bars', function() {
var gd = {
data: [{type: 'histogram', y: [1], visible: false}],
layout: {}
};

supplyAllDefaults(gd);
expect(gd._fullLayout.barmode).toBe(undefined, '`barmode` should be undefined');

gd.data[0].visible = true;
supplyAllDefaults(gd);
expect(gd._fullLayout.barmode).toBe('group', '`barmode` should be set to its default ');
});
});

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