@@ -2,16 +2,19 @@ import {group as grouper, sort, InternSet} from "d3";
2
2
import { defined , firstof } from "../defined.js" ;
3
3
import { valueof , maybeColor , maybeTransform , maybeValue , maybeLazyChannel , lazyChannel , first , identity , take , maybeTuple } from "../mark.js" ;
4
4
5
- export function groupX ( { x, ...options } = { } ) {
6
- const [ transform , X , y ] = group1 ( x , options ) ;
7
- return { x : X , y, ...transform } ;
5
+ // Group on y, z, fill, or stroke, if any, then group on x.
6
+ export function groupX ( { x, y, out = y == null ? "y" : "fill" , ...options } = { } ) {
7
+ const [ transform , X , l ] = group1 ( x , "y" , { y, ...options } ) ;
8
+ return { x : X , ...transform , [ out ] : l } ;
8
9
}
9
10
10
- export function groupY ( { y, ...options } = { } ) {
11
- const [ transform , Y , x ] = group1 ( y , options ) ;
12
- return { y : Y , x, ...transform } ;
11
+ // Group on x, z, fill, or stroke, if any, then group on y.
12
+ export function groupY ( { y, x, out = x == null ? "x" : "fill" , ...options } = { } ) {
13
+ const [ transform , Y , l ] = group1 ( y , "x" , { x, ...options } ) ;
14
+ return { y : Y , ...transform , [ out ] : l } ;
13
15
}
14
16
17
+ // Group on z, fill, or stroke, if any.
15
18
export function groupR ( options ) {
16
19
return group ( { ...options , out : "r" } ) ;
17
20
}
@@ -21,35 +24,39 @@ export function group({x, y, out = "fill", ...options} = {}) {
21
24
return { x : X , y : Y , ...transform , [ out ] : L } ;
22
25
}
23
26
24
- function group1 ( x = identity , { domain, normalize, z, fill, stroke, ...options } = { } ) {
25
- const k = normalize === true || normalize === "z" ? 100 : + normalize ;
27
+ function group1 ( x = identity , key , { [ key ] : k , domain, normalize, z, fill, stroke, ...options } = { } ) {
28
+ const m = normalize === true || normalize === "z" ? 100 : + normalize ;
26
29
const [ X , setX ] = lazyChannel ( x ) ;
27
- const [ Y , setY ] = lazyChannel ( `Frequency${ k === 100 ? " (%)" : "" } ` ) ;
28
- const [ Z , setZ ] = maybeLazyChannel ( z ) ;
30
+ const [ L , setL ] = lazyChannel ( `Frequency${ m === 100 ? " (%)" : "" } ` ) ;
29
31
const [ vfill ] = maybeColor ( fill ) ;
30
32
const [ vstroke ] = maybeColor ( stroke ) ;
31
- const [ F = fill , setF ] = maybeLazyChannel ( vfill ) ;
32
- const [ S = stroke , setS ] = maybeLazyChannel ( vstroke ) ;
33
+ const [ BK , setBK ] = maybeLazyChannel ( k ) ;
34
+ const [ BZ , setBZ ] = maybeLazyChannel ( z ) ;
35
+ const [ BF = fill , setBF ] = maybeLazyChannel ( vfill ) ;
36
+ const [ BS = stroke , setBS ] = maybeLazyChannel ( vstroke ) ;
33
37
const defined = maybeDomain ( domain ) ;
34
38
return [
35
39
{
36
- z : Z ,
37
- fill : F ,
38
- stroke : S ,
40
+ ...key && { [ key ] : BK } ,
41
+ z : BZ ,
42
+ fill : BF ,
43
+ stroke : BS ,
39
44
...options ,
40
45
transform : maybeTransform ( options , ( data , facets ) => {
41
46
const X = valueof ( data , x ) ;
47
+ const K = valueof ( data , k ) ;
42
48
const Z = valueof ( data , z ) ;
43
49
const F = valueof ( data , vfill ) ;
44
50
const S = valueof ( data , vstroke ) ;
45
51
const groupFacets = [ ] ;
46
52
const groupData = [ ] ;
47
- const G = firstof ( Z , F , S ) ;
48
53
const BX = setX ( [ ] ) ;
49
- const BY = setY ( [ ] ) ;
50
- const BZ = Z && setZ ( [ ] ) ;
51
- const BF = F && setF ( [ ] ) ;
52
- const BS = S && setS ( [ ] ) ;
54
+ const L = setL ( [ ] ) ;
55
+ const G = firstof ( K , Z , F , S ) ;
56
+ const BK = K && setBK ( [ ] ) ;
57
+ const BZ = Z && setBZ ( [ ] ) ;
58
+ const BF = F && setBF ( [ ] ) ;
59
+ const BS = S && setBS ( [ ] ) ;
53
60
let n = data . length ;
54
61
let i = 0 ;
55
62
for ( const facet of facets ) {
@@ -62,7 +69,8 @@ function group1(x = identity, {domain, normalize, z, fill, stroke, ...options} =
62
69
groupFacet . push ( i ++ ) ;
63
70
groupData . push ( take ( data , f ) ) ;
64
71
BX . push ( x ) ;
65
- BY . push ( k ? l * k / n : l ) ;
72
+ L . push ( m ? l * m / n : l ) ;
73
+ if ( K ) BK . push ( K [ f [ 0 ] ] ) ;
66
74
if ( Z ) BZ . push ( Z [ f [ 0 ] ] ) ;
67
75
if ( F ) BF . push ( F [ f [ 0 ] ] ) ;
68
76
if ( S ) BS . push ( S [ f [ 0 ] ] ) ;
@@ -74,7 +82,7 @@ function group1(x = identity, {domain, normalize, z, fill, stroke, ...options} =
74
82
} )
75
83
} ,
76
84
X ,
77
- Y
85
+ L
78
86
] ;
79
87
}
80
88
0 commit comments