@@ -46,64 +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 , trace , transitionConfig , joinDirection ) {
50
- var size ;
51
-
52
- var hasTransition = transitionConfig && ( transitionConfig || { } ) . duration > 0 ;
53
-
54
- if ( hasTransition ) {
55
- size = s . size ( ) ;
49
+ drawing . translatePoint = function ( d , sel , xa , ya , trace , transitionConfig , joinDirection ) {
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 + ')' ) ;
60
+ }
56
61
}
62
+ else sel . remove ( ) ;
63
+ } ;
57
64
65
+ drawing . translatePoints = function ( s , xa , ya , trace , transitionConfig , joinDirection ) {
58
66
s . each ( function ( d , i ) {
59
- // put xp and yp into d if pixel scaling is already done
60
- var x = d . xp || xa . c2p ( d . x ) ,
61
- y = d . yp || ya . c2p ( d . y ) ,
62
- p = d3 . select ( this ) ;
63
- if ( isNumeric ( x ) && isNumeric ( y ) ) {
64
- // for multiline text this works better
65
- if ( this . nodeName === 'text' ) {
66
- p . attr ( 'x' , x ) . attr ( 'y' , y ) ;
67
- } else {
68
- if ( hasTransition ) {
69
- var trans ;
70
- if ( ! joinDirection ) {
71
- trans = p . transition ( )
72
- . delay ( transitionConfig . delay )
73
- . duration ( transitionConfig . duration )
74
- . ease ( transitionConfig . ease )
75
- . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
76
-
77
- if ( trace ) {
78
- trans . call ( drawing . pointStyle , trace ) ;
79
- }
80
- } else if ( joinDirection === - 1 ) {
81
- trans = p . style ( 'opacity' , 1 )
82
- . transition ( )
83
- . duration ( transitionConfig . duration )
84
- . ease ( transitionConfig . ease )
85
- . style ( 'opacity' , 0 )
86
- . remove ( ) ;
87
- } else if ( joinDirection === 1 ) {
88
- trans = p . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
89
-
90
- if ( trace ) {
91
- trans . call ( drawing . pointStyle , trace ) ;
92
- }
93
-
94
- trans . style ( 'opacity' , 0 )
95
- . transition ( )
96
- . duration ( transitionConfig . duration )
97
- . ease ( transitionConfig . ease )
98
- . style ( 'opacity' , 1 ) ;
99
- }
100
-
101
- } else {
102
- p . attr ( 'transform' , 'translate(' + x + ',' + y + ')' ) ;
103
- }
104
- }
105
- }
106
- else p . remove ( ) ;
67
+ var sel = d3 . select ( this ) ;
68
+ drawing . translatePoint ( d , sel , xa , ya , trace , transitionConfig , joinDirection ) ;
107
69
} ) ;
108
70
} ;
109
71
@@ -126,6 +88,16 @@ drawing.crispRound = function(td, lineWidth, dflt) {
126
88
return Math . round ( lineWidth ) ;
127
89
} ;
128
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
+
129
101
drawing . lineGroupStyle = function ( s , lw , lc , ld ) {
130
102
s . style ( 'fill' , 'none' )
131
103
. each ( function ( d ) {
@@ -221,6 +193,64 @@ drawing.symbolNumber = function(v) {
221
193
return Math . floor ( Math . max ( v , 0 ) ) ;
222
194
} ;
223
195
196
+ function singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , markerLine ) {
197
+
198
+ // 'so' is suspected outliers, for box plots
199
+ var fillColor ,
200
+ lineColor ,
201
+ lineWidth ;
202
+ if ( d . so ) {
203
+ lineWidth = markerLine . outlierwidth ;
204
+ lineColor = markerLine . outliercolor ;
205
+ fillColor = marker . outliercolor ;
206
+ }
207
+ else {
208
+ lineWidth = ( d . mlw + 1 || markerLine . width + 1 ||
209
+ // TODO: we need the latter for legends... can we get rid of it?
210
+ ( d . trace ? d . trace . marker . line . width : 0 ) + 1 ) - 1 ;
211
+
212
+ if ( 'mlc' in d ) lineColor = d . mlcc = lineScale ( d . mlc ) ;
213
+ // weird case: array wasn't long enough to apply to every point
214
+ else if ( Array . isArray ( markerLine . color ) ) lineColor = Color . defaultLine ;
215
+ else lineColor = markerLine . color ;
216
+
217
+ if ( 'mc' in d ) fillColor = d . mcc = markerScale ( d . mc ) ;
218
+ else if ( Array . isArray ( marker . color ) ) fillColor = Color . defaultLine ;
219
+ else fillColor = marker . color || 'rgba(0,0,0,0)' ;
220
+ }
221
+
222
+ if ( d . om ) {
223
+ // open markers can't have zero linewidth, default to 1px,
224
+ // and use fill color as stroke color
225
+ sel . call ( Color . stroke , fillColor )
226
+ . style ( {
227
+ 'stroke-width' : ( lineWidth || 1 ) + 'px' ,
228
+ fill : 'none'
229
+ } ) ;
230
+ }
231
+ else {
232
+ sel . style ( 'stroke-width' , lineWidth + 'px' )
233
+ . call ( Color . fill , fillColor ) ;
234
+ if ( lineWidth ) {
235
+ sel . call ( Color . stroke , lineColor ) ;
236
+ }
237
+ }
238
+ } ;
239
+
240
+ drawing . singlePointStyle = function ( d , sel , trace ) {
241
+ var marker = trace . marker ,
242
+ markerLine = marker . line ;
243
+
244
+ // allow array marker and marker line colors to be
245
+ // scaled by given max and min to colorscales
246
+ var markerIn = ( trace . _input || { } ) . marker || { } ,
247
+ markerScale = drawing . tryColorscale ( marker , markerIn , '' ) ,
248
+ lineScale = drawing . tryColorscale ( marker , markerIn , 'line.' ) ;
249
+
250
+ singlePointStyle ( d , sel , trace , markerScale , lineScale , marker , markerLine ) ;
251
+
252
+ }
253
+
224
254
drawing . pointStyle = function ( s , trace ) {
225
255
if ( ! s . size ( ) ) return ;
226
256
@@ -265,47 +295,7 @@ drawing.pointStyle = function(s, trace) {
265
295
lineScale = drawing . tryColorscale ( marker , markerIn , 'line.' ) ;
266
296
267
297
s . each ( function ( d ) {
268
- // 'so' is suspected outliers, for box plots
269
- var fillColor ,
270
- lineColor ,
271
- lineWidth ;
272
- if ( d . so ) {
273
- lineWidth = markerLine . outlierwidth ;
274
- lineColor = markerLine . outliercolor ;
275
- fillColor = marker . outliercolor ;
276
- }
277
- else {
278
- lineWidth = ( d . mlw + 1 || markerLine . width + 1 ||
279
- // TODO: we need the latter for legends... can we get rid of it?
280
- ( d . trace ? d . trace . marker . line . width : 0 ) + 1 ) - 1 ;
281
-
282
- if ( 'mlc' in d ) lineColor = d . mlcc = lineScale ( d . mlc ) ;
283
- // weird case: array wasn't long enough to apply to every point
284
- else if ( Array . isArray ( markerLine . color ) ) lineColor = Color . defaultLine ;
285
- else lineColor = markerLine . color ;
286
-
287
- if ( 'mc' in d ) fillColor = d . mcc = markerScale ( d . mc ) ;
288
- else if ( Array . isArray ( marker . color ) ) fillColor = Color . defaultLine ;
289
- else fillColor = marker . color || 'rgba(0,0,0,0)' ;
290
- }
291
-
292
- var p = d3 . select ( this ) ;
293
- if ( d . om ) {
294
- // open markers can't have zero linewidth, default to 1px,
295
- // and use fill color as stroke color
296
- p . call ( Color . stroke , fillColor )
297
- . style ( {
298
- 'stroke-width' : ( lineWidth || 1 ) + 'px' ,
299
- fill : 'none'
300
- } ) ;
301
- }
302
- else {
303
- p . style ( 'stroke-width' , lineWidth + 'px' )
304
- . call ( Color . fill , fillColor ) ;
305
- if ( lineWidth ) {
306
- p . call ( Color . stroke , lineColor ) ;
307
- }
308
- }
298
+ drawing . singlePointStyle ( d , d3 . select ( this ) , trace , markerScale , lineScale )
309
299
} ) ;
310
300
} ;
311
301
0 commit comments