@@ -13,17 +13,28 @@ type JitterOptions = {
13
13
width : number ;
14
14
/** standard deviation for normal jittering */
15
15
std : number ;
16
- }
16
+ } ;
17
17
18
- export function jitterX ( { data, ...channels } : TransformArg < DataRecord > , options : JitterOptions ) : TransformArg < DataRecord > {
18
+ export function jitterX (
19
+ { data, ...channels } : TransformArg < DataRecord > ,
20
+ options : JitterOptions
21
+ ) : TransformArg < DataRecord > {
19
22
return jitter ( 'x' , data , channels , options ) ;
20
23
}
21
24
22
- export function jitterY ( { data, ...channels } : TransformArg < DataRecord > , options : JitterOptions ) : TransformArg < DataRecord > {
25
+ export function jitterY (
26
+ { data, ...channels } : TransformArg < DataRecord > ,
27
+ options : JitterOptions
28
+ ) : TransformArg < DataRecord > {
23
29
return jitter ( 'y' , data , channels , options ) ;
24
30
}
25
31
26
- export function jitter ( channel : 'x' | 'y' , data : DataRecord [ ] , channels : Channels , options : JitterOptions ) : TransformArg < DataRecord > {
32
+ export function jitter (
33
+ channel : 'x' | 'y' ,
34
+ data : DataRecord [ ] ,
35
+ channels : Channels ,
36
+ options : JitterOptions
37
+ ) : TransformArg < DataRecord > {
27
38
if ( channels [ channel ] ) {
28
39
const type = options ?. type ?? 'uniform' ;
29
40
const width = parseNumber ( options ?. width ?? 0.35 ) ;
@@ -33,21 +44,26 @@ export function jitter(channel: 'x' | 'y', data: DataRecord[], channels: Channel
33
44
const random = type === 'uniform' ? randomUniform ( - width , width ) : randomNormal ( 0 , std ) ;
34
45
const accKey = channel === 'x' ? JITTER_X : JITTER_Y ;
35
46
return {
36
- data : data . map ( row => {
47
+ data : data . map ( ( row ) => {
37
48
const value = resolveChannel ( channel , row , channels ) ;
38
49
return {
39
50
...row ,
40
- [ accKey ] : typeof value === 'number' ? value + random ( ) : isDate ( value ) ? new Date ( value . getTime ( ) + random ( ) ) : value
41
- }
51
+ [ accKey ] :
52
+ typeof value === 'number'
53
+ ? value + random ( )
54
+ : isDate ( value )
55
+ ? new Date ( value . getTime ( ) + random ( ) )
56
+ : value
57
+ } ;
42
58
} ) ,
43
59
...channels ,
44
60
// point channel to new accessor symbol
45
61
[ channel ] : accKey
46
- }
62
+ } ;
47
63
}
48
64
return {
49
65
data,
50
- ...channels ,
66
+ ...channels
51
67
} ;
52
68
}
53
69
@@ -62,4 +78,4 @@ function parseNumber(value: number | string): number {
62
78
}
63
79
}
64
80
return 0 ;
65
- }
81
+ }
0 commit comments