Skip to content
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

histogram: remove gap when barmode is relative #3652

Merged
merged 3 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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"
}
}