@@ -15,6 +15,7 @@ var traceIs = require('../../registry').traceIs;
15
15
var handleGroupingDefaults = require ( '../bar/defaults' ) . handleGroupingDefaults ;
16
16
17
17
var nestedProperty = Lib . nestedProperty ;
18
+ var getAxisGroup = axisIds . getAxisGroup ;
18
19
19
20
var BINATTRS = [
20
21
{ aStr : { x : 'xbins.start' , y : 'ybins.start' } , name : 'start' } ,
@@ -28,8 +29,6 @@ var BINDIRECTIONS = ['x', 'y'];
28
29
// handle bin attrs and relink auto-determined values so fullData is complete
29
30
module . exports = function crossTraceDefaults ( fullData , fullLayout ) {
30
31
var allBinOpts = fullLayout . _histogramBinOpts = { } ;
31
- var isOverlay = fullLayout . barmode === 'overlay' ;
32
-
33
32
var histTraces = [ ] ;
34
33
var mustMatchTracesLookup = { } ;
35
34
var otherTracesList = [ ] ;
@@ -117,19 +116,40 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
117
116
}
118
117
}
119
118
119
+ var alignmentOpts = fullLayout . _alignmentOpts || { } ;
120
+
120
121
// Look for traces that "have to match", that is:
121
122
// - 1d histogram traces on the same subplot with same orientation under barmode:stack,
122
123
// - 1d histogram traces on the same subplot with same orientation under barmode:group
124
+ // - 1d histogram traces on the same position axis with the same orientation
125
+ // and the same *alignmentgroup* (coerced under barmode:group)
126
+ // - Once `stackgroup` gets implemented (see https://github.com/plotly/plotly.js/issues/3614),
127
+ // traces within the same stackgroup will also "have to match"
123
128
for ( i = 0 ; i < histTraces . length ; i ++ ) {
124
129
traceOut = histTraces [ i ] ;
130
+ groupName = '' ;
131
+
132
+ if ( ! traceIs ( traceOut , '2dMap' ) ) {
133
+ binDir = orientation2binDir ( traceOut ) ;
125
134
126
- if ( ! isOverlay && ! traceIs ( traceOut , '2dMap' ) ) {
127
- groupName = (
128
- axisIds . getAxisGroup ( fullLayout , traceOut . xaxis ) +
129
- axisIds . getAxisGroup ( fullLayout , traceOut . yaxis ) +
130
- orientation2binDir ( traceOut )
131
- ) ;
135
+ if ( fullLayout . barmode === 'group' && traceOut . alignmentgroup ) {
136
+ var pa = traceOut [ binDir + 'axis' ] ;
137
+ var aGroupId = getAxisGroup ( fullLayout , pa ) + traceOut . orientation ;
138
+ if ( ( alignmentOpts [ aGroupId ] || { } ) [ traceOut . alignmentgroup ] ) {
139
+ groupName = aGroupId ;
140
+ }
141
+ }
142
+
143
+ if ( ! groupName && fullLayout . barmode !== 'overlay' ) {
144
+ groupName = (
145
+ getAxisGroup ( fullLayout , traceOut . xaxis ) +
146
+ getAxisGroup ( fullLayout , traceOut . yaxis ) +
147
+ orientation2binDir ( traceOut )
148
+ ) ;
149
+ }
150
+ }
132
151
152
+ if ( groupName ) {
133
153
if ( ! mustMatchTracesLookup [ groupName ] ) {
134
154
mustMatchTracesLookup [ groupName ] = [ ] ;
135
155
}
0 commit comments