Skip to content

Commit

Permalink
rm alignmentgroup/offsetgroup from bar/box/violin when mode!=group
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Feb 8, 2019
1 parent a853521 commit 1c1ca3a
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 9 deletions.
21 changes: 17 additions & 4 deletions src/traces/bar/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* LICENSE file in the root directory of this source tree.
*/


'use strict';

var Registry = require('../../registry');
Expand All @@ -15,8 +14,9 @@ var Lib = require('../../lib');

var layoutAttributes = require('./layout_attributes');


module.exports = function(layoutIn, layoutOut, fullData) {
var i, trace;

function coerce(attr, dflt) {
return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
}
Expand All @@ -25,9 +25,10 @@ module.exports = function(layoutIn, layoutOut, fullData) {
var shouldBeGapless = false;
var gappedAnyway = false;
var usedSubplots = {};
var tracesWithGroupAttrs = [];

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

Expand All @@ -44,6 +45,10 @@ module.exports = function(layoutIn, layoutOut, fullData) {
trace[trace.orientation === 'v' ? 'xaxis' : 'yaxis']);
if(pa.type !== 'category') shouldBeGapless = true;
}

if(trace.alignmentgroup || trace.offsetgroup) {
tracesWithGroupAttrs.push(trace);
}
}

if(!hasBars) return;
Expand All @@ -53,4 +58,12 @@ module.exports = function(layoutIn, layoutOut, fullData) {

coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
coerce('bargroupgap');

if(mode !== 'group') {
for(i = 0; i < tracesWithGroupAttrs.length; i++) {
trace = tracesWithGroupAttrs[i];
delete trace.alignmentgroup;
delete trace.offsetgroup;
}
}
};
27 changes: 22 additions & 5 deletions src/traces/box/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,36 @@ var Lib = require('../../lib');
var layoutAttributes = require('./layout_attributes');

function _supply(layoutIn, layoutOut, fullData, coerce, traceType) {
var hasTraceType;
var i, trace;

var category = traceType + 'Layout';
for(var i = 0; i < fullData.length; i++) {
if(Registry.traceIs(fullData[i], category)) {
var hasTraceType = false;
var tracesWithGroupAttrs = [];

for(i = 0; i < fullData.length; i++) {
trace = fullData[i];

if(Registry.traceIs(trace, category)) {
hasTraceType = true;
break;

if(trace.alignmentgroup || trace.offsetgroup) {
tracesWithGroupAttrs.push(trace);
}
}
}
if(!hasTraceType) return;

coerce(traceType + 'mode');
var mode = coerce(traceType + 'mode');
coerce(traceType + 'gap');
coerce(traceType + 'groupgap');

if(mode !== 'group') {
for(i = 0; i < tracesWithGroupAttrs.length; i++) {
trace = tracesWithGroupAttrs[i];
delete trace.alignmentgroup;
delete trace.offsetgroup;
}
}
}

function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
Expand Down
16 changes: 16 additions & 0 deletions test/jasmine/tests/bar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ describe('Bar.supplyDefaults', function() {
expect(traceOut.xcalendar).toBe('coptic');
expect(traceOut.ycalendar).toBe('ethiopian');
});

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');
});
});

describe('bar calc / crossTraceCalc (formerly known as setPositions)', function() {
Expand Down
17 changes: 17 additions & 0 deletions test/jasmine/tests/box_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var failTest = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var supplyAllDefaults = require('../assets/supply_defaults');

var customAssertions = require('../assets/custom_assertions');
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
Expand Down Expand Up @@ -150,6 +151,22 @@ describe('Test boxes supplyDefaults', function() {
expect(traceOut.marker).toBeDefined();
expect(traceOut.text).toBeDefined();
});

it('should not include alignementgroup/offsetgroup when boxmode is not *group*', function() {
var gd = {
data: [{type: 'box', y: [1], alignmentgroup: 'a', offsetgroup: '1'}],
layout: {boxmode: 'group'}
};

supplyAllDefaults(gd);
expect(gd._fullData[0].alignmentgroup).toBe('a', 'alignementgroup');
expect(gd._fullData[0].offsetgroup).toBe('1', 'offsetgroup');

gd.layout.boxmode = 'overlay';
supplyAllDefaults(gd);
expect(gd._fullData[0].alignmentgroup).toBe(undefined, 'alignementgroup');
expect(gd._fullData[0].offsetgroup).toBe(undefined, 'offsetgroup');
});
});

describe('Test box hover:', function() {
Expand Down
16 changes: 16 additions & 0 deletions test/jasmine/tests/violin_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ describe('Test violin defaults', function() {
expect(traceOut.scalemode).toBe('width');
expect(traceOut.scalegroup).toBe('');
});

it('should not include alignementgroup/offsetgroup when violinmode is not *group*', function() {
var gd = {
data: [{type: 'violin', y: [1], alignmentgroup: 'a', offsetgroup: '1'}],
layout: {violinmode: 'group'}
};

supplyAllDefaults(gd);
expect(gd._fullData[0].alignmentgroup).toBe('a', 'alignementgroup');
expect(gd._fullData[0].offsetgroup).toBe('1', 'offsetgroup');

gd.layout.violinmode = 'overlay';
supplyAllDefaults(gd);
expect(gd._fullData[0].alignmentgroup).toBe(undefined, 'alignementgroup');
expect(gd._fullData[0].offsetgroup).toBe(undefined, 'offsetgroup');
});
});

describe('Test violin calc:', function() {
Expand Down

0 comments on commit 1c1ca3a

Please sign in to comment.