1111
1212var isNumeric = require ( 'fast-isnumeric' ) ;
1313
14- var Plotly = require ( '../../plotly' ) ;
14+ var Plots = require ( '../../plots/plots' ) ;
15+ var Axes = require ( '../../plots/cartesian/axes' ) ;
1516var Lib = require ( '../../lib' ) ;
1617
1718/*
@@ -27,22 +28,23 @@ module.exports = function setPositions(gd, plotinfo) {
2728 ya = plotinfo . y ( ) ,
2829 i , j ;
2930
30- [ 'v' , 'h' ] . forEach ( function ( dir ) {
31+ [ 'v' , 'h' ] . forEach ( function ( dir ) {
3132 var bl = [ ] ,
32- pLetter = { v :'x' , h :'y' } [ dir ] ,
33- sLetter = { v :'y' , h :'x' } [ dir ] ,
33+ pLetter = { v :'x' , h :'y' } [ dir ] ,
34+ sLetter = { v :'y' , h :'x' } [ dir ] ,
3435 pa = plotinfo [ pLetter ] ( ) ,
3536 sa = plotinfo [ sLetter ] ( ) ;
3637
3738 gd . _fullData . forEach ( function ( trace , i ) {
3839 if ( trace . visible === true &&
39- Plotly . Plots . traceIs ( trace , 'bar' ) &&
40+ Plots . traceIs ( trace , 'bar' ) &&
4041 trace . orientation === dir &&
4142 trace . xaxis === xa . _id &&
4243 trace . yaxis === ya . _id ) {
4344 bl . push ( i ) ;
4445 }
4546 } ) ;
47+
4648 if ( ! bl . length ) return ;
4749
4850 // bar position offset and width calculation
@@ -53,9 +55,9 @@ module.exports = function setPositions(gd, plotinfo) {
5355 function barposition ( bl1 ) {
5456 // find the min. difference between any points
5557 // in any traces in bl1
56- var pvals = [ ] ;
58+ var pvals = [ ] ;
5759 bl1 . forEach ( function ( i ) {
58- gd . calcdata [ i ] . forEach ( function ( v ) { pvals . push ( v . p ) ; } ) ;
60+ gd . calcdata [ i ] . forEach ( function ( v ) { pvals . push ( v . p ) ; } ) ;
5961 } ) ;
6062 var dv = Lib . distinctVals ( pvals ) ,
6163 pv2 = dv . vals ,
@@ -65,7 +67,8 @@ module.exports = function setPositions(gd, plotinfo) {
6567 // if so, let them have full width even if mode is group
6668 var overlap = false ,
6769 comparelist = [ ] ;
68- if ( fullLayout . barmode === 'group' ) {
70+
71+ if ( fullLayout . barmode === 'group' ) {
6972 bl1 . forEach ( function ( i ) {
7073 if ( overlap ) return ;
7174 gd . calcdata [ i ] . forEach ( function ( v ) {
@@ -82,36 +85,37 @@ module.exports = function setPositions(gd, plotinfo) {
8285 }
8386
8487 // check forced minimum dtick
85- Plotly . Axes . minDtick ( pa , barDiff , pv2 [ 0 ] , overlap ) ;
88+ Axes . minDtick ( pa , barDiff , pv2 [ 0 ] , overlap ) ;
8689
8790 // position axis autorange - always tight fitting
88- Plotly . Axes . expand ( pa , pv2 , { vpad : barDiff / 2 } ) ;
91+ Axes . expand ( pa , pv2 , { vpad : barDiff / 2 } ) ;
8992
9093 // bar widths and position offsets
91- barDiff *= 1 - fullLayout . bargap ;
92- if ( overlap ) barDiff /= bl . length ;
94+ barDiff *= 1 - fullLayout . bargap ;
95+ if ( overlap ) barDiff /= bl . length ;
9396
9497 var barCenter ;
9598 function setBarCenter ( v ) { v [ pLetter ] = v . p + barCenter ; }
9699
97- for ( var i = 0 ; i < bl1 . length ; i ++ ) {
100+ for ( var i = 0 ; i < bl1 . length ; i ++ ) {
98101 var t = gd . calcdata [ bl1 [ i ] ] [ 0 ] . t ;
99- t . barwidth = barDiff * ( 1 - fullLayout . bargroupgap ) ;
100- t . poffset = ( ( overlap ? ( 2 * i + 1 - bl1 . length ) * barDiff : 0 ) -
101- t . barwidth ) / 2 ;
102+ t . barwidth = barDiff * ( 1 - fullLayout . bargroupgap ) ;
103+ t . poffset = ( ( overlap ? ( 2 * i + 1 - bl1 . length ) * barDiff : 0 ) -
104+ t . barwidth ) / 2 ;
102105 t . dbar = dv . minDiff ;
103106
104107 // store the bar center in each calcdata item
105- barCenter = t . poffset + t . barwidth / 2 ;
108+ barCenter = t . poffset + t . barwidth / 2 ;
106109 gd . calcdata [ bl1 [ i ] ] . forEach ( setBarCenter ) ;
107110 }
108111 }
109- if ( fullLayout . barmode === 'overlay' ) {
112+
113+ if ( fullLayout . barmode === 'overlay' ) {
110114 bl . forEach ( function ( bli ) { barposition ( [ bli ] ) ; } ) ;
111115 }
112116 else barposition ( bl ) ;
113117
114- var stack = fullLayout . barmode === 'stack' ,
118+ var stack = ( fullLayout . barmode === 'stack' ) ,
115119 norm = fullLayout . barnorm ;
116120
117121 // bar size range and stacking calculation
@@ -127,20 +131,20 @@ module.exports = function setPositions(gd, plotinfo) {
127131
128132 // make sure if p is different only by rounding,
129133 // we still stack
130- sumround = gd . calcdata [ bl [ 0 ] ] [ 0 ] . t . barwidth / 100 ,
134+ sumround = gd . calcdata [ bl [ 0 ] ] [ 0 ] . t . barwidth / 100 ,
131135 sv = 0 ,
132136 padded = true ,
133137 barEnd ,
134138 ti ,
135139 scale ;
136140
137- for ( i = 0 ; i < bl . length ; i ++ ) { // trace index
141+ for ( i = 0 ; i < bl . length ; i ++ ) { // trace index
138142 ti = gd . calcdata [ bl [ i ] ] ;
139- for ( j = 0 ; j < ti . length ; j ++ ) {
140- sv = Math . round ( ti [ j ] . p / sumround ) ;
141- var previousSum = sums [ sv ] || 0 ;
143+ for ( j = 0 ; j < ti . length ; j ++ ) {
144+ sv = Math . round ( ti [ j ] . p / sumround ) ;
145+ var previousSum = sums [ sv ] || 0 ;
142146 if ( stack ) ti [ j ] . b = previousSum ;
143- barEnd = ti [ j ] . b + ti [ j ] . s ;
147+ barEnd = ti [ j ] . b + ti [ j ] . s ;
144148 sums [ sv ] = previousSum + ti [ j ] . s ;
145149
146150 // store the bar top in each calcdata item
@@ -160,9 +164,9 @@ module.exports = function setPositions(gd, plotinfo) {
160164 tiny = top / 1e9 ; // in case of rounding error in sum
161165 sMin = 0 ;
162166 sMax = stack ? top : 0 ;
163- for ( i = 0 ; i < bl . length ; i ++ ) { // trace index
167+ for ( i = 0 ; i < bl . length ; i ++ ) { // trace index
164168 ti = gd . calcdata [ bl [ i ] ] ;
165- for ( j = 0 ; j < ti . length ; j ++ ) {
169+ for ( j = 0 ; j < ti . length ; j ++ ) {
166170 scale = top / sums [ Math . round ( ti [ j ] . p / sumround ) ] ;
167171 ti [ j ] . b *= scale ;
168172 ti [ j ] . s *= scale ;
@@ -183,16 +187,16 @@ module.exports = function setPositions(gd, plotinfo) {
183187 }
184188 }
185189
186- Plotly . Axes . expand ( sa , [ sMin , sMax ] , { tozero : true , padded : padded } ) ;
190+ Axes . expand ( sa , [ sMin , sMax ] , { tozero : true , padded : padded } ) ;
187191 }
188192 else {
189193 // for grouped or overlaid bars, just make sure zero is
190194 // included, along with the tops of each bar, and store
191195 // these bar tops in calcdata
192- var fs = function ( v ) { v [ sLetter ] = v . s ; return v . s ; } ;
196+ var fs = function ( v ) { v [ sLetter ] = v . s ; return v . s ; } ;
193197
194- for ( i = 0 ; i < bl . length ; i ++ ) {
195- Plotly . Axes . expand ( sa , gd . calcdata [ bl [ i ] ] . map ( fs ) ,
198+ for ( i = 0 ; i < bl . length ; i ++ ) {
199+ Axes . expand ( sa , gd . calcdata [ bl [ i ] ] . map ( fs ) ,
196200 { tozero : true , padded : true } ) ;
197201 }
198202 }
0 commit comments