@@ -13,6 +13,7 @@ var Lib = require('../../lib');
13
13
var Drawing = require ( '../../components/drawing' ) ;
14
14
var boxPlot = require ( '../box/plot' ) ;
15
15
var linePoints = require ( '../scatter/line_points' ) ;
16
+ var helpers = require ( './helpers' ) ;
16
17
17
18
module . exports = function plot ( gd , plotinfo , cd ) {
18
19
var fullLayout = gd . _fullLayout ;
@@ -128,10 +129,68 @@ module.exports = function plot(gd, plotinfo, cd) {
128
129
129
130
} ) ;
130
131
131
- if ( trace . points ) {
132
- boxPlot . plotPoints ( sel , plotinfo , trace , t ) ;
132
+ if ( trace . showinnerbox ) {
133
+ var innerBoxWidth = trace . innerboxwidth ;
134
+ var innerBoxLineWidth = trace . innerboxlinewidth ;
135
+ var bdPosScaled ;
136
+ var bPosPxOffset ;
137
+
138
+ if ( hasBothSides ) {
139
+ bdPosScaled = bdPos * innerBoxWidth ;
140
+ bPosPxOffset = 0 ;
141
+ } else if ( hasPositiveSide ) {
142
+ bdPosScaled = [ 0 , bdPos * innerBoxWidth / 2 ] ;
143
+ bPosPxOffset = - innerBoxLineWidth ;
144
+ } else {
145
+ bdPosScaled = [ bdPos * innerBoxWidth / 2 , 0 ] ;
146
+ bPosPxOffset = innerBoxLineWidth ;
147
+ }
148
+
149
+ // do not draw whiskers on inner boxes
150
+ trace . whiskerwidth = 0 ;
151
+
152
+ boxPlot . plotBoxAndWhiskers ( sel , { pos : posAxis , val : valAxis } , trace , {
153
+ bPos : bPos ,
154
+ bdPos : bdPosScaled ,
155
+ bPosPxOffset : bPosPxOffset
156
+ } ) ;
157
+
158
+ // if both showinnerbox and showmeanline are turned on, show mean
159
+ // line inside inner box
160
+
161
+ if ( trace . showmeanline ) {
162
+ boxPlot . plotBoxMean ( sel , { pos : posAxis , val : valAxis } , trace , {
163
+ bPos : bPos ,
164
+ bdPos : bdPosScaled ,
165
+ bPosPxOffset : bPosPxOffset
166
+ } ) ;
167
+ }
168
+ }
169
+ else {
170
+ if ( trace . showmeanline ) {
171
+ sel . selectAll ( 'path.mean' )
172
+ . data ( Lib . identity )
173
+ . enter ( ) . append ( 'path' )
174
+ . attr ( 'class' , 'mean' )
175
+ . style ( {
176
+ fill : 'none' ,
177
+ 'vector-effect' : 'non-scaling-stroke'
178
+ } )
179
+ . each ( function ( d ) {
180
+ var v = valAxis . c2p ( d . mean , true ) ;
181
+ var p = helpers . getPositionOnKdePath ( d , trace , v ) ;
182
+
183
+ d3 . select ( this ) . attr ( 'd' ,
184
+ trace . orientation === 'h' ?
185
+ 'M' + v + ',' + p [ 0 ] + 'V' + p [ 1 ] :
186
+ 'M' + p [ 0 ] + ',' + v + 'H' + p [ 1 ]
187
+ ) ;
188
+ } ) ;
189
+ }
133
190
}
134
191
135
- // TODO quartile line etc
192
+ if ( trace . points ) {
193
+ boxPlot . plotPoints ( sel , { x : xa , y : ya } , trace , t ) ;
194
+ }
136
195
} ) ;
137
196
} ;
0 commit comments