@@ -52,8 +52,11 @@ function plot(gd, plotinfo, cdbox, boxLayer) {
5252}
5353
5454function plotBoxAndWhiskers ( sel , axes , trace , t ) {
55- var posAxis = axes . pos ;
55+ var isHorizontal = trace . orientation === 'h' ;
5656 var valAxis = axes . val ;
57+ var posAxis = axes . pos ;
58+ var posHasRangeBreaks = ! ! posAxis . rangebreaks ;
59+
5760 var bPos = t . bPos ;
5861 var wdPos = t . wdPos || 0 ;
5962 var bPosPxOffset = t . bPosPxOffset || 0 ;
@@ -87,11 +90,15 @@ function plotBoxAndWhiskers(sel, axes, trace, t) {
8790 if ( d . empty ) return 'M0,0Z' ;
8891
8992 var lcenter = posAxis . c2l ( d . pos + bPos , true ) ;
90- var posc = posAxis . l2p ( lcenter ) + bPosPxOffset ;
93+
9194 var pos0 = posAxis . l2p ( lcenter - bdPos0 ) + bPosPxOffset ;
9295 var pos1 = posAxis . l2p ( lcenter + bdPos1 ) + bPosPxOffset ;
93- var posw0 = posAxis . l2p ( lcenter - wdPos ) + bPosPxOffset ;
94- var posw1 = posAxis . l2p ( lcenter + wdPos ) + bPosPxOffset ;
96+ var posc = posHasRangeBreaks ? ( pos0 + pos1 ) / 2 : posAxis . l2p ( lcenter ) + bPosPxOffset ;
97+
98+ var r = trace . whiskerwidth ;
99+ var posw0 = posHasRangeBreaks ? pos0 * r + ( 1 - r ) * posc : posAxis . l2p ( lcenter - wdPos ) + bPosPxOffset ;
100+ var posw1 = posHasRangeBreaks ? pos1 * r + ( 1 - r ) * posc : posAxis . l2p ( lcenter + wdPos ) + bPosPxOffset ;
101+
95102 var posm0 = posAxis . l2p ( lcenter - bdPos0 * nw ) + bPosPxOffset ;
96103 var posm1 = posAxis . l2p ( lcenter + bdPos1 * nw ) + bPosPxOffset ;
97104 var q1 = valAxis . c2p ( d . q1 , true ) ;
@@ -115,30 +122,45 @@ function plotBoxAndWhiskers(sel, axes, trace, t) {
115122 var ln = valAxis . c2p ( d . ln , true ) ;
116123 var un = valAxis . c2p ( d . un , true ) ;
117124
118- if ( trace . orientation === 'h' ) {
125+ if ( isHorizontal ) {
119126 d3 . select ( this ) . attr ( 'd' ,
120127 'M' + m + ',' + posm0 + 'V' + posm1 + // median line
121128 'M' + q1 + ',' + pos0 + 'V' + pos1 + // left edge
122- ( notched ? 'H' + ln + 'L' + m + ',' + posm1 + 'L' + un + ',' + pos1 : '' ) + // top notched edge
129+ ( notched ?
130+ 'H' + ln + 'L' + m + ',' + posm1 + 'L' + un + ',' + pos1 :
131+ ''
132+ ) + // top notched edge
123133 'H' + q3 + // end of the top edge
124134 'V' + pos0 + // right edge
125135 ( notched ? 'H' + un + 'L' + m + ',' + posm0 + 'L' + ln + ',' + pos0 : '' ) + // bottom notched edge
126136 'Z' + // end of the box
127137 'M' + q1 + ',' + posc + 'H' + lf + 'M' + q3 + ',' + posc + 'H' + uf + // whiskers
128- ( ( whiskerWidth === 0 ) ? '' : // whisker caps
129- 'M' + lf + ',' + posw0 + 'V' + posw1 + 'M' + uf + ',' + posw0 + 'V' + posw1 ) ) ;
138+ ( whiskerWidth === 0 ?
139+ '' : // whisker caps
140+ 'M' + lf + ',' + posw0 + 'V' + posw1 + 'M' + uf + ',' + posw0 + 'V' + posw1
141+ )
142+ ) ;
130143 } else {
131144 d3 . select ( this ) . attr ( 'd' ,
132145 'M' + posm0 + ',' + m + 'H' + posm1 + // median line
133146 'M' + pos0 + ',' + q1 + 'H' + pos1 + // top of the box
134- ( notched ? 'V' + ln + 'L' + posm1 + ',' + m + 'L' + pos1 + ',' + un : '' ) + // notched right edge
147+ ( notched ?
148+ 'V' + ln + 'L' + posm1 + ',' + m + 'L' + pos1 + ',' + un :
149+ ''
150+ ) + // notched right edge
135151 'V' + q3 + // end of the right edge
136152 'H' + pos0 + // bottom of the box
137- ( notched ? 'V' + un + 'L' + posm0 + ',' + m + 'L' + pos0 + ',' + ln : '' ) + // notched left edge
153+ ( notched ?
154+ 'V' + un + 'L' + posm0 + ',' + m + 'L' + pos0 + ',' + ln :
155+ ''
156+ ) + // notched left edge
138157 'Z' + // end of the box
139158 'M' + posc + ',' + q1 + 'V' + lf + 'M' + posc + ',' + q3 + 'V' + uf + // whiskers
140- ( ( whiskerWidth === 0 ) ? '' : // whisker caps
141- 'M' + posw0 + ',' + lf + 'H' + posw1 + 'M' + posw0 + ',' + uf + 'H' + posw1 ) ) ;
159+ ( whiskerWidth === 0 ?
160+ '' : // whisker caps
161+ 'M' + posw0 + ',' + lf + 'H' + posw1 + 'M' + posw0 + ',' + uf + 'H' + posw1
162+ )
163+ ) ;
142164 }
143165 } ) ;
144166}
@@ -254,8 +276,10 @@ function plotPoints(sel, axes, trace, t) {
254276}
255277
256278function plotBoxMean ( sel , axes , trace , t ) {
257- var posAxis = axes . pos ;
258279 var valAxis = axes . val ;
280+ var posAxis = axes . pos ;
281+ var posHasRangeBreaks = ! ! posAxis . rangebreaks ;
282+
259283 var bPos = t . bPos ;
260284 var bPosPxOffset = t . bPosPxOffset || 0 ;
261285
@@ -289,9 +313,11 @@ function plotBoxMean(sel, axes, trace, t) {
289313
290314 paths . each ( function ( d ) {
291315 var lcenter = posAxis . c2l ( d . pos + bPos , true ) ;
292- var posc = posAxis . l2p ( lcenter ) + bPosPxOffset ;
316+
293317 var pos0 = posAxis . l2p ( lcenter - bdPos0 ) + bPosPxOffset ;
294318 var pos1 = posAxis . l2p ( lcenter + bdPos1 ) + bPosPxOffset ;
319+ var posc = posHasRangeBreaks ? ( pos0 + pos1 ) / 2 : posAxis . l2p ( lcenter ) + bPosPxOffset ;
320+
295321 var m = valAxis . c2p ( d . mean , true ) ;
296322 var sl = valAxis . c2p ( d . mean - d . sd , true ) ;
297323 var sh = valAxis . c2p ( d . mean + d . sd , true ) ;
0 commit comments