Skip to content

Commit e8bd5db

Browse files
committed
Track alignmentgroups in fullLayout._alignmentOpts by trace type
Previously, all offsetgroups of different trace types were listed together, leading to undesired grouping interaction between different trace types. Fixes failing baseline test "legendgroup".
1 parent 68fae33 commit e8bd5db

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

src/traces/bar/cross_trace_calc.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,9 @@ function setOffsetAndWidth(gd, pa, sieve, opts) {
322322
barWidth = barWidthPlusGap * (1 - (opts.groupgap || 0));
323323
offsetFromCenter = -barWidth / 2;
324324
} else { // collect groups and calculate values in loop below
325-
var groupId = getAxisGroup(fullLayout, pa._id) + calcTraces[0][0].trace.orientation;
326-
alignmentGroups = fullLayout._alignmentOpts[groupId] || {};
325+
var firstTrace = calcTraces[0][0].trace;
326+
var groupId = getAxisGroup(fullLayout, pa._id) + firstTrace.orientation;
327+
alignmentGroups = fullLayout._alignmentOpts[firstTrace.type][groupId] || {};
327328
}
328329

329330
for(var i = 0; i < nTraces; i++) {

src/traces/box/cross_trace_calc.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,14 @@ function setPositionOffset(traceType, gd, boxList, posAxis) {
100100
} else {
101101
dPos = dPos0;
102102

103+
var groupId = getAxisGroup(fullLayout, posAxis._id) + trace.orientation;
104+
if(fullLayout._alignmentOpts[traceType] === undefined) {
105+
fullLayout._alignmentOpts[traceType] = {};
106+
}
107+
var alignmentGroups = fullLayout._alignmentOpts[traceType][groupId] || {};
108+
var alignmentGroupOpts = alignmentGroups[trace.alignmentgroup] || {};
109+
var nOffsetGroups = Object.keys(alignmentGroupOpts.offsetGroups || {}).length;
103110
if(group) {
104-
var groupId = getAxisGroup(fullLayout, posAxis._id) + trace.orientation;
105-
var alignmentGroups = fullLayout._alignmentOpts[groupId] || {};
106-
var alignmentGroupOpts = alignmentGroups[trace.alignmentgroup] || {};
107-
var nOffsetGroups = Object.keys(alignmentGroupOpts.offsetGroups || {}).length;
108111
var num = nOffsetGroups || numTotal;
109112
var shift = nOffsetGroups ? trace._offsetIndex : t.num;
110113

src/traces/histogram/cross_trace_defaults.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,10 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
116116
}
117117
}
118118
}
119-
120-
var alignmentOpts = fullLayout._alignmentOpts || {};
119+
var alignmentOpts = {};
120+
if(fullLayout._alignmentOpts.histogram !== undefined) {
121+
alignmentOpts = fullLayout._alignmentOpts.histogram || {};
122+
}
121123

122124
// Look for traces that "have to match", that is:
123125
// - 1d histogram traces on the same subplot with same orientation under barmode:stack,
@@ -136,7 +138,7 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
136138
if(fullLayout.barmode === 'group' && traceOut.alignmentgroup) {
137139
var pa = traceOut[binDir + 'axis'];
138140
var aGroupId = getAxisGroup(fullLayout, pa) + traceOut.orientation;
139-
if((alignmentOpts[aGroupId] || {})[traceOut.alignmentgroup]) {
141+
if((alignmentOpts.histogram[aGroupId] || {})[traceOut.alignmentgroup]) {
140142
groupName = aGroupId;
141143
}
142144
}

src/traces/scatter/grouping_defaults.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ module.exports = function handleGroupingDefaults(traceIn, traceOut, fullLayout,
88
var posAxId = traceOut[{v: 'x', h: 'y'}[orientation] + 'axis'];
99
var groupId = getAxisGroup(fullLayout, posAxId) + orientation;
1010

11-
var alignmentOpts = fullLayout._alignmentOpts || {};
11+
var allAlignmentOpts = fullLayout._alignmentOpts || {};
12+
if(allAlignmentOpts[traceOut.type] === undefined) {
13+
allAlignmentOpts[traceOut.type] = {};
14+
}
15+
var alignmentOpts = allAlignmentOpts[traceOut.type];
16+
1217
var alignmentgroup = coerce('alignmentgroup');
1318

1419
var alignmentGroups = alignmentOpts[groupId];

0 commit comments

Comments
 (0)