@@ -52,8 +52,11 @@ function plot(gd, plotinfo, cdbox, boxLayer) {
52
52
}
53
53
54
54
function plotBoxAndWhiskers ( sel , axes , trace , t ) {
55
- var posAxis = axes . pos ;
55
+ var isHorizontal = trace . orientation === 'h' ;
56
56
var valAxis = axes . val ;
57
+ var posAxis = axes . pos ;
58
+ var posHasRangeBreaks = ! ! posAxis . rangebreaks ;
59
+
57
60
var bPos = t . bPos ;
58
61
var wdPos = t . wdPos || 0 ;
59
62
var bPosPxOffset = t . bPosPxOffset || 0 ;
@@ -87,11 +90,15 @@ function plotBoxAndWhiskers(sel, axes, trace, t) {
87
90
if ( d . empty ) return 'M0,0Z' ;
88
91
89
92
var lcenter = posAxis . c2l ( d . pos + bPos , true ) ;
90
- var posc = posAxis . l2p ( lcenter ) + bPosPxOffset ;
93
+
91
94
var pos0 = posAxis . l2p ( lcenter - bdPos0 ) + bPosPxOffset ;
92
95
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
+
95
102
var posm0 = posAxis . l2p ( lcenter - bdPos0 * nw ) + bPosPxOffset ;
96
103
var posm1 = posAxis . l2p ( lcenter + bdPos1 * nw ) + bPosPxOffset ;
97
104
var q1 = valAxis . c2p ( d . q1 , true ) ;
@@ -115,30 +122,45 @@ function plotBoxAndWhiskers(sel, axes, trace, t) {
115
122
var ln = valAxis . c2p ( d . ln , true ) ;
116
123
var un = valAxis . c2p ( d . un , true ) ;
117
124
118
- if ( trace . orientation === 'h' ) {
125
+ if ( isHorizontal ) {
119
126
d3 . select ( this ) . attr ( 'd' ,
120
127
'M' + m + ',' + posm0 + 'V' + posm1 + // median line
121
128
'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
123
133
'H' + q3 + // end of the top edge
124
134
'V' + pos0 + // right edge
125
135
( notched ? 'H' + un + 'L' + m + ',' + posm0 + 'L' + ln + ',' + pos0 : '' ) + // bottom notched edge
126
136
'Z' + // end of the box
127
137
'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
+ ) ;
130
143
} else {
131
144
d3 . select ( this ) . attr ( 'd' ,
132
145
'M' + posm0 + ',' + m + 'H' + posm1 + // median line
133
146
'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
135
151
'V' + q3 + // end of the right edge
136
152
'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
138
157
'Z' + // end of the box
139
158
'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
+ ) ;
142
164
}
143
165
} ) ;
144
166
}
@@ -254,8 +276,10 @@ function plotPoints(sel, axes, trace, t) {
254
276
}
255
277
256
278
function plotBoxMean ( sel , axes , trace , t ) {
257
- var posAxis = axes . pos ;
258
279
var valAxis = axes . val ;
280
+ var posAxis = axes . pos ;
281
+ var posHasRangeBreaks = ! ! posAxis . rangebreaks ;
282
+
259
283
var bPos = t . bPos ;
260
284
var bPosPxOffset = t . bPosPxOffset || 0 ;
261
285
@@ -289,9 +313,11 @@ function plotBoxMean(sel, axes, trace, t) {
289
313
290
314
paths . each ( function ( d ) {
291
315
var lcenter = posAxis . c2l ( d . pos + bPos , true ) ;
292
- var posc = posAxis . l2p ( lcenter ) + bPosPxOffset ;
316
+
293
317
var pos0 = posAxis . l2p ( lcenter - bdPos0 ) + bPosPxOffset ;
294
318
var pos1 = posAxis . l2p ( lcenter + bdPos1 ) + bPosPxOffset ;
319
+ var posc = posHasRangeBreaks ? ( pos0 + pos1 ) / 2 : posAxis . l2p ( lcenter ) + bPosPxOffset ;
320
+
295
321
var m = valAxis . c2p ( d . mean , true ) ;
296
322
var sl = valAxis . c2p ( d . mean - d . sd , true ) ;
297
323
var sh = valAxis . c2p ( d . mean + d . sd , true ) ;
0 commit comments