@@ -46,18 +46,26 @@ drawing.setRect = function(s, x, y, w, h) {
46
46
s . call ( drawing . setPosition , x , y ) . call ( drawing . setSize , w , h ) ;
47
47
} ;
48
48
49
- drawing . translatePoints = function ( s , xa , ya ) {
50
- s . each ( function ( d ) {
51
- // put xp and yp into d if pixel scaling is already done
52
- var x = d . xp || xa . c2p ( d . x ) ,
53
- y = d . yp || ya . c2p ( d . y ) ,
54
- p = d3 . select ( this ) ;
55
- if ( isNumeric ( x ) && isNumeric ( y ) ) {
56
- // for multiline text this works better
57
- if ( this . nodeName === 'text' ) p . attr ( 'x' , x ) . attr ( 'y' , y ) ;
58
- else p . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
49
+ drawing . translatePoint = function ( d , sel , xa , ya ) {
50
+ // put xp and yp into d if pixel scaling is already done
51
+ var x = d . xp || xa . c2p ( d . x ) ,
52
+ y = d . yp || ya . c2p ( d . y ) ;
53
+
54
+ if ( isNumeric ( x ) && isNumeric ( y ) ) {
55
+ // for multiline text this works better
56
+ if ( this . nodeName === 'text' ) {
57
+ sel . node ( ) . attr ( 'x' , x ) . attr ( 'y' , y ) ;
58
+ } else {
59
+ sel . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
59
60
}
60
- else p . remove ( ) ;
61
+ }
62
+ else sel . remove ( ) ;
63
+ } ;
64
+
65
+ drawing . translatePoints = function ( s , xa , ya , trace ) {
66
+ s . each ( function ( d ) {
67
+ var sel = d3 . select ( this ) ;
68
+ drawing . translatePoint ( d , sel , xa , ya , trace ) ;
61
69
} ) ;
62
70
} ;
63
71
@@ -80,6 +88,16 @@ drawing.crispRound = function(td, lineWidth, dflt) {
80
88
return Math . round ( lineWidth ) ;
81
89
} ;
82
90
91
+ drawing . singleLineStyle = function ( d , s , lw , lc , ld ) {
92
+ s . style ( 'fill' , 'none' ) ;
93
+ var line = ( ( ( d || [ ] ) [ 0 ] || { } ) . trace || { } ) . line || { } ,
94
+ lw1 = lw || line . width || 0 ,
95
+ dash = ld || line . dash || '' ;
96
+
97
+ Color . stroke ( s , lc || line . color ) ;
98
+ drawing . dashLine ( s , dash , lw1 ) ;
99
+ } ;
100
+
83
101
drawing . lineGroupStyle = function ( s , lw , lc , ld ) {
84
102
s . style ( 'fill' , 'none' )
85
103
. each ( function ( d ) {
@@ -175,18 +193,13 @@ drawing.symbolNumber = function(v) {
175
193
return Math . floor ( Math . max ( v , 0 ) ) ;
176
194
} ;
177
195
178
- drawing . pointStyle = function ( s , trace ) {
179
- if ( ! s . size ( ) ) return ;
180
-
181
- var marker = trace . marker ,
182
- markerLine = marker . line ;
183
-
196
+ function singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , markerLine ) {
184
197
// only scatter & box plots get marker path and opacity
185
198
// bars, histograms don't
186
199
if ( Registry . traceIs ( trace , 'symbols' ) ) {
187
200
var sizeFn = makeBubbleSizeFn ( trace ) ;
188
201
189
- s . attr ( 'd' , function ( d ) {
202
+ sel . attr ( 'd' , function ( d ) {
190
203
var r ;
191
204
192
205
// handle multi-trace graph edit case
@@ -212,54 +225,75 @@ drawing.pointStyle = function(s, trace) {
212
225
return ( d . mo + 1 || marker . opacity + 1 ) - 1 ;
213
226
} ) ;
214
227
}
228
+
229
+ // 'so' is suspected outliers, for box plots
230
+ var fillColor ,
231
+ lineColor ,
232
+ lineWidth ;
233
+ if ( d . so ) {
234
+ lineWidth = markerLine . outlierwidth ;
235
+ lineColor = markerLine . outliercolor ;
236
+ fillColor = marker . outliercolor ;
237
+ }
238
+ else {
239
+ lineWidth = ( d . mlw + 1 || markerLine . width + 1 ||
240
+ // TODO: we need the latter for legends... can we get rid of it?
241
+ ( d . trace ? d . trace . marker . line . width : 0 ) + 1 ) - 1 ;
242
+
243
+ if ( 'mlc' in d ) lineColor = d . mlcc = lineScale ( d . mlc ) ;
244
+ // weird case: array wasn't long enough to apply to every point
245
+ else if ( Array . isArray ( markerLine . color ) ) lineColor = Color . defaultLine ;
246
+ else lineColor = markerLine . color ;
247
+
248
+ if ( 'mc' in d ) fillColor = d . mcc = markerScale ( d . mc ) ;
249
+ else if ( Array . isArray ( marker . color ) ) fillColor = Color . defaultLine ;
250
+ else fillColor = marker . color || 'rgba(0,0,0,0)' ;
251
+ }
252
+
253
+ if ( d . om ) {
254
+ // open markers can't have zero linewidth, default to 1px,
255
+ // and use fill color as stroke color
256
+ sel . call ( Color . stroke , fillColor )
257
+ . style ( {
258
+ 'stroke-width' : ( lineWidth || 1 ) + 'px' ,
259
+ fill : 'none'
260
+ } ) ;
261
+ }
262
+ else {
263
+ sel . style ( 'stroke-width' , lineWidth + 'px' )
264
+ . call ( Color . fill , fillColor ) ;
265
+ if ( lineWidth ) {
266
+ sel . call ( Color . stroke , lineColor ) ;
267
+ }
268
+ }
269
+ }
270
+
271
+ drawing . singlePointStyle = function ( d , sel , trace ) {
272
+ var marker = trace . marker ,
273
+ markerLine = marker . line ;
274
+
215
275
// allow array marker and marker line colors to be
216
276
// scaled by given max and min to colorscales
217
277
var markerIn = ( trace . _input || { } ) . marker || { } ,
218
278
markerScale = drawing . tryColorscale ( marker , markerIn , '' ) ,
219
279
lineScale = drawing . tryColorscale ( marker , markerIn , 'line.' ) ;
220
280
221
- s . each ( function ( d ) {
222
- // 'so' is suspected outliers, for box plots
223
- var fillColor ,
224
- lineColor ,
225
- lineWidth ;
226
- if ( d . so ) {
227
- lineWidth = markerLine . outlierwidth ;
228
- lineColor = markerLine . outliercolor ;
229
- fillColor = marker . outliercolor ;
230
- }
231
- else {
232
- lineWidth = ( d . mlw + 1 || markerLine . width + 1 ||
233
- // TODO: we need the latter for legends... can we get rid of it?
234
- ( d . trace ? d . trace . marker . line . width : 0 ) + 1 ) - 1 ;
235
-
236
- if ( 'mlc' in d ) lineColor = d . mlcc = lineScale ( d . mlc ) ;
237
- // weird case: array wasn't long enough to apply to every point
238
- else if ( Array . isArray ( markerLine . color ) ) lineColor = Color . defaultLine ;
239
- else lineColor = markerLine . color ;
240
-
241
- if ( 'mc' in d ) fillColor = d . mcc = markerScale ( d . mc ) ;
242
- else if ( Array . isArray ( marker . color ) ) fillColor = Color . defaultLine ;
243
- else fillColor = marker . color || 'rgba(0,0,0,0)' ;
244
- }
281
+ singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , markerLine ) ;
245
282
246
- var p = d3 . select ( this ) ;
247
- if ( d . om ) {
248
- // open markers can't have zero linewidth, default to 1px,
249
- // and use fill color as stroke color
250
- p . call ( Color . stroke , fillColor )
251
- . style ( {
252
- 'stroke-width' : ( lineWidth || 1 ) + 'px' ,
253
- fill : 'none'
254
- } ) ;
255
- }
256
- else {
257
- p . style ( 'stroke-width' , lineWidth + 'px' )
258
- . call ( Color . fill , fillColor ) ;
259
- if ( lineWidth ) {
260
- p . call ( Color . stroke , lineColor ) ;
261
- }
262
- }
283
+ } ;
284
+
285
+ drawing . pointStyle = function ( s , trace ) {
286
+ if ( ! s . size ( ) ) return ;
287
+
288
+ // allow array marker and marker line colors to be
289
+ // scaled by given max and min to colorscales
290
+ var marker = trace . marker ;
291
+ var markerIn = ( trace . _input || { } ) . marker || { } ,
292
+ markerScale = drawing . tryColorscale ( marker , markerIn , '' ) ,
293
+ lineScale = drawing . tryColorscale ( marker , markerIn , 'line.' ) ;
294
+
295
+ s . each ( function ( d ) {
296
+ drawing . singlePointStyle ( d , d3 . select ( this ) , trace , markerScale , lineScale ) ;
263
297
} ) ;
264
298
} ;
265
299
0 commit comments