@@ -52,18 +52,32 @@ module.exports = function setPositions(gd, plotinfo) {
52
52
function setGroupPositions ( gd , pa , sa , traces ) {
53
53
if ( ! traces . length ) return ;
54
54
55
- var fullLayout = gd . _fullLayout ,
56
- pLetter = pa . _id . charAt ( 0 ) ,
57
- sLetter = sa . _id . charAt ( 0 ) ;
58
-
59
- if ( fullLayout . barmode === 'overlay' ) {
60
- traces . forEach ( function ( trace ) {
61
- setOffsetAndWidth ( gd , pa , pLetter , [ trace ] ) ;
62
- } ) ;
55
+ if ( gd . _fullLayout . barmode === 'overlay' ) {
56
+ setGroupPositionsInOverlayMode ( gd , pa , sa , traces ) ;
57
+ }
58
+ else {
59
+ setOffsetAndWidth ( gd , pa , traces ) ;
60
+ setBaseAndSize ( gd , sa , traces ) ;
63
61
}
64
- else setOffsetAndWidth ( gd , pa , pLetter , traces ) ;
62
+ }
63
+
65
64
66
- setBaseAndSize ( gd , sa , sLetter , traces ) ;
65
+ function setGroupPositionsInOverlayMode ( gd , pa , sa , traces ) {
66
+ // set bar offsets and widths
67
+ traces . forEach ( function ( trace ) {
68
+ setOffsetAndWidth ( gd , pa , [ trace ] ) ;
69
+ } ) ;
70
+
71
+ // for overlaid bars,
72
+ // just make sure the size axis includes zero,
73
+ // along with the tops of each bar,
74
+ // and store these bar tops in calcdata
75
+ var sLetter = getAxisLetter ( sa ) ,
76
+ fs = function ( v ) { v [ sLetter ] = v . s ; return v . s ; } ;
77
+
78
+ for ( var i = 0 ; i < traces . length ; i ++ ) {
79
+ Axes . expand ( sa , traces [ i ] . map ( fs ) , { tozero : true , padded : true } ) ;
80
+ }
67
81
}
68
82
69
83
@@ -72,8 +86,9 @@ function setGroupPositions(gd, pa, sa, traces) {
72
86
// to find the maximum width bars that won't overlap
73
87
// for stacked or grouped bars, this is all vertical or horizontal
74
88
// bars for overlaid bars, call this individually on each trace.
75
- function setOffsetAndWidth ( gd , pa , pLetter , traces ) {
89
+ function setOffsetAndWidth ( gd , pa , traces ) {
76
90
var fullLayout = gd . _fullLayout ,
91
+ pLetter = getAxisLetter ( pa ) ,
77
92
i , trace ,
78
93
j , bar ;
79
94
@@ -135,8 +150,9 @@ function setOffsetAndWidth(gd, pa, pLetter, traces) {
135
150
}
136
151
137
152
138
- function setBaseAndSize ( gd , sa , sLetter , traces ) {
153
+ function setBaseAndSize ( gd , sa , traces ) {
139
154
var fullLayout = gd . _fullLayout ,
155
+ sLetter = getAxisLetter ( sa ) ,
140
156
i , trace ,
141
157
j , bar ;
142
158
@@ -253,3 +269,8 @@ function setBaseAndSize(gd, sa, sLetter, traces) {
253
269
}
254
270
}
255
271
}
272
+
273
+
274
+ function getAxisLetter ( ax ) {
275
+ return ax . _id . charAt ( 0 ) ;
276
+ }
0 commit comments