@@ -3,34 +3,46 @@ import {ascendingDefined} from "../defined.js";
3
3
import { field , lazyChannel , maybeLazyChannel , maybeZ , mid , range , valueof , identity , maybeZero } from "../mark.js" ;
4
4
import { basic } from "./basic.js" ;
5
5
6
- export function stackX ( { y1, y = y1 , x, ...options } = { } ) {
7
- const [ transform , Y , x1 , x2 ] = stack ( y , x , "x" , options ) ;
8
- return { y1, y : Y , x1, x2, x : mid ( x1 , x2 ) , ...transform } ;
6
+ export function stackX ( stackOptions = { } , options = { } ) {
7
+ if ( arguments . length === 1 ) options = mergeOptions ( stackOptions ) ;
8
+ const { y1, y = y1 , x, ...rest } = options ; // note: consumes x!
9
+ const [ transform , Y , x1 , x2 ] = stack ( y , x , "x" , stackOptions , rest ) ;
10
+ return { ...transform , y1, y : Y , x1, x2, x : mid ( x1 , x2 ) } ;
9
11
}
10
12
11
- export function stackX1 ( { y1, y = y1 , x, ...options } = { } ) {
12
- const [ transform , Y , X ] = stack ( y , x , "x" , options ) ;
13
- return { y1, y : Y , x : X , ...transform } ;
13
+ export function stackX1 ( stackOptions = { } , options = { } ) {
14
+ if ( arguments . length === 1 ) options = mergeOptions ( stackOptions ) ;
15
+ const { y1, y = y1 , x} = options ;
16
+ const [ transform , Y , X ] = stack ( y , x , "x" , stackOptions , options ) ;
17
+ return { ...transform , y1, y : Y , x : X } ;
14
18
}
15
19
16
- export function stackX2 ( { y1, y = y1 , x, ...options } = { } ) {
17
- const [ transform , Y , , X ] = stack ( y , x , "x" , options ) ;
18
- return { y1, y : Y , x : X , ...transform } ;
20
+ export function stackX2 ( stackOptions = { } , options = { } ) {
21
+ if ( arguments . length === 1 ) options = mergeOptions ( stackOptions ) ;
22
+ const { y1, y = y1 , x} = options ;
23
+ const [ transform , Y , , X ] = stack ( y , x , "x" , stackOptions , options ) ;
24
+ return { ...transform , y1, y : Y , x : X } ;
19
25
}
20
26
21
- export function stackY ( { x1, x = x1 , y, ...options } = { } ) {
22
- const [ transform , X , y1 , y2 ] = stack ( x , y , "y" , options ) ;
23
- return { x1, x : X , y1, y2, y : mid ( y1 , y2 ) , ...transform } ;
27
+ export function stackY ( stackOptions = { } , options = { } ) {
28
+ if ( arguments . length === 1 ) options = mergeOptions ( stackOptions ) ;
29
+ const { x1, x = x1 , y, ...rest } = options ; // note: consumes y!
30
+ const [ transform , X , y1 , y2 ] = stack ( x , y , "y" , stackOptions , rest ) ;
31
+ return { ...transform , x1, x : X , y1, y2, y : mid ( y1 , y2 ) } ;
24
32
}
25
33
26
- export function stackY1 ( { x1, x = x1 , y, ...options } = { } ) {
27
- const [ transform , X , Y ] = stack ( x , y , "y" , options ) ;
28
- return { x1, x : X , y : Y , ...transform } ;
34
+ export function stackY1 ( stackOptions = { } , options = { } ) {
35
+ if ( arguments . length === 1 ) options = mergeOptions ( stackOptions ) ;
36
+ const { x1, x = x1 , y} = options ;
37
+ const [ transform , X , Y ] = stack ( x , y , "y" , stackOptions , options ) ;
38
+ return { ...transform , x1, x : X , y : Y } ;
29
39
}
30
40
31
- export function stackY2 ( { x1, x = x1 , y, ...options } = { } ) {
32
- const [ transform , X , , Y ] = stack ( x , y , "y" , options ) ;
33
- return { x1, x : X , y : Y , ...transform } ;
41
+ export function stackY2 ( stackOptions = { } , options = { } ) {
42
+ if ( arguments . length === 1 ) options = mergeOptions ( stackOptions ) ;
43
+ const { x1, x = x1 , y} = options ;
44
+ const [ transform , X , , Y ] = stack ( x , y , "y" , stackOptions , options ) ;
45
+ return { ...transform , x1, x : X , y : Y } ;
34
46
}
35
47
36
48
export function maybeStackX ( { x, x1, x2, ...options } = { } ) {
@@ -51,7 +63,15 @@ export function maybeStackY({y, y1, y2, ...options} = {}) {
51
63
return { ...options , y1, y2} ;
52
64
}
53
65
54
- function stack ( x , y = ( ) => 1 , ky , { offset, order, reverse, ...options } = { } ) {
66
+ // The reverse option is ambiguous: it is both a stack option and a basic
67
+ // transform. If only one options object is specified, we interpret it as a
68
+ // stack option, and therefore must remove it from the propagated options.
69
+ function mergeOptions ( options ) {
70
+ const { reverse} = options ;
71
+ return reverse ? { ...options , reverse : false } : options ;
72
+ }
73
+
74
+ function stack ( x , y = ( ) => 1 , ky , { offset, order, reverse} , options ) {
55
75
const z = maybeZ ( options ) ;
56
76
const [ X , setX ] = maybeLazyChannel ( x ) ;
57
77
const [ Y1 , setY1 ] = lazyChannel ( y ) ;
0 commit comments