@@ -15,6 +15,7 @@ var traceIs = require('../../registry').traceIs;
1515var handleGroupingDefaults = require ( '../bar/defaults' ) . handleGroupingDefaults ;
1616
1717var nestedProperty = Lib . nestedProperty ;
18+ var getAxisGroup = axisIds . getAxisGroup ;
1819
1920var BINATTRS = [
2021 { aStr : { x : 'xbins.start' , y : 'ybins.start' } , name : 'start' } ,
@@ -28,8 +29,6 @@ var BINDIRECTIONS = ['x', 'y'];
2829// handle bin attrs and relink auto-determined values so fullData is complete
2930module . exports = function crossTraceDefaults ( fullData , fullLayout ) {
3031 var allBinOpts = fullLayout . _histogramBinOpts = { } ;
31- var isOverlay = fullLayout . barmode === 'overlay' ;
32-
3332 var histTraces = [ ] ;
3433 var mustMatchTracesLookup = { } ;
3534 var otherTracesList = [ ] ;
@@ -117,19 +116,40 @@ module.exports = function crossTraceDefaults(fullData, fullLayout) {
117116 }
118117 }
119118
119+ var alignmentOpts = fullLayout . _alignmentOpts || { } ;
120+
120121 // Look for traces that "have to match", that is:
121122 // - 1d histogram traces on the same subplot with same orientation under barmode:stack,
122123 // - 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"
123128 for ( i = 0 ; i < histTraces . length ; i ++ ) {
124129 traceOut = histTraces [ i ] ;
130+ groupName = '' ;
131+
132+ if ( ! traceIs ( traceOut , '2dMap' ) ) {
133+ binDir = orientation2binDir ( traceOut ) ;
125134
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+ }
132151
152+ if ( groupName ) {
133153 if ( ! mustMatchTracesLookup [ groupName ] ) {
134154 mustMatchTracesLookup [ groupName ] = [ ] ;
135155 }
0 commit comments