@@ -2,62 +2,50 @@ import {ascending} from "d3-array";
2
2
import { create } from "d3-selection" ;
3
3
import { arc as shapeArc } from "d3-shape" ;
4
4
import { filter , nonempty } from "../defined.js" ;
5
- import { Mark , maybeColor , maybeNumber , title } from "../mark.js" ;
6
- import { Style , applyDirectStyles , applyIndirectStyles , applyTransform } from "../style.js" ;
5
+ import { Mark , maybeNumber } from "../mark.js" ;
6
+ import { applyDirectStyles , applyIndirectStyles , applyTransform , applyChannelStyles , offset } from "../style.js" ;
7
7
8
- const constant = x => ( ) => x ;
8
+ const defaults = {
9
+ fill : "currentColor" ,
10
+ stroke : "none"
11
+ } ;
9
12
10
13
export class Arc extends Mark {
11
- constructor (
12
- data ,
13
- {
14
+ constructor ( data , options = { } ) {
15
+ const {
16
+ x,
17
+ y,
14
18
startAngle = d => d . startAngle ,
15
19
endAngle = d => d . endAngle ,
16
- x = constant ( 0 ) ,
17
- y = constant ( 0 ) ,
18
20
innerRadius,
19
21
outerRadius,
20
- padAngle,
22
+ padAngle,
21
23
z,
22
24
title,
23
- label,
24
- fill,
25
- stroke,
26
- transform,
27
- ...style
28
- } = { }
29
- ) {
30
- const [ vfill , cfill ] = maybeColor ( fill , "currentColor" ) ;
31
- const [ vstroke , cstroke ] = maybeColor ( stroke , cfill === "none" ? "currentColor" : cfill === "currentColor" ? "white" : "none" ) ;
25
+ label
26
+ } = options ;
32
27
const [ vsa , csa ] = maybeNumber ( startAngle , 0 ) ;
33
28
const [ vea , cea ] = maybeNumber ( endAngle , 2 * Math . PI ) ;
34
29
const [ vpa , cpa ] = maybeNumber ( padAngle , 0 ) ;
35
- const [ vx , cx ] = maybeNumber ( x , 0 ) ;
36
- const [ vy , cy ] = maybeNumber ( y , 0 ) ;
37
30
const [ vri , cri ] = maybeNumber ( innerRadius , 0 ) ;
38
31
const [ vro , cro ] = maybeNumber ( outerRadius , 100 ) ;
39
-
40
32
super (
41
33
data ,
42
34
[
43
- { name : "x" , value : vx , scale : "x" , optional : true } ,
44
- { name : "y" , value : vy , scale : "y" , optional : true } ,
35
+ { name : "x" , value : x , scale : "x" , optional : true } ,
36
+ { name : "y" , value : y , scale : "y" , optional : true } ,
45
37
{ name : "startAngle" , value : vsa , optional : true } ,
46
38
{ name : "endAngle" , value : vea , optional : true } ,
47
- { name : "innerRadius" , value : vri , optional : true } ,
48
- { name : "outerRadius" , value : vro , optional : true } ,
39
+ { name : "innerRadius" , value : vri , scale : "r" , optional : true } ,
40
+ { name : "outerRadius" , value : vro , scale : "r" , optional : true } ,
49
41
{ name : "padAngle" , value : vpa , optional : true } ,
50
42
{ name : "z" , value : z , optional : true } ,
51
43
{ name : "title" , value : title , optional : true } ,
52
- { name : "label" , value : label , optional : true } ,
53
- { name : "fill" , value : vfill , scale : "color" , optional : true } ,
54
- { name : "stroke" , value : vstroke , scale : "color" , optional : true }
44
+ { name : "label" , value : label , optional : true }
55
45
] ,
56
- transform
46
+ options ,
47
+ defaults
57
48
) ;
58
- Style ( this , { fill : cfill , stroke : cstroke , ...style } ) ;
59
- this . x = cx ;
60
- this . y = cy ;
61
49
this . sa = csa ;
62
50
this . ea = cea ;
63
51
this . ri = cri ;
@@ -66,14 +54,25 @@ export class Arc extends Mark {
66
54
}
67
55
render (
68
56
I ,
69
- { x, y, color } ,
70
- { startAngle : SA , endAngle : EA , innerRadius : RI , outerRadius : RO , padAngle : PA , x : X , y : Y , z : Z , title : T , label : L , fill : F , stroke : S } ,
71
- { marginTop , marginRight , marginBottom , marginLeft , width , height }
57
+ { x, y} ,
58
+ channels ,
59
+ { width , height , marginTop , marginRight , marginBottom , marginLeft }
72
60
) {
73
- const index = filter ( I , SA , EA , F , S ) ;
61
+ const {
62
+ startAngle : SA ,
63
+ endAngle : EA ,
64
+ innerRadius : RI ,
65
+ outerRadius : RO ,
66
+ padAngle : PA ,
67
+ x : X , y : Y , z : Z ,
68
+ label : L
69
+ } = channels ;
70
+ const { dx, dy} = this ;
71
+ let index = filter ( I , SA , EA ) ;
74
72
if ( Z ) index . sort ( ( i , j ) => ascending ( Z [ i ] , Z [ j ] ) ) ;
75
73
76
- const r0 = Math . min ( width - marginLeft - marginRight , height - marginTop - marginBottom ) / 200 ;
74
+ // const r0 = Math.min(width - marginLeft - marginRight, height - marginTop - marginBottom) / 200;
75
+ const r0 = 1 ;
77
76
78
77
const arc = shapeArc ( )
79
78
. startAngle ( SA ? ( i => SA [ i ] ) : this . sa )
@@ -83,19 +82,17 @@ export class Arc extends Mark {
83
82
. padAngle ( PA ? ( i => PA [ i ] ) : this . pa ) ;
84
83
85
84
const wrapper = create ( "svg:g" )
86
- . call ( applyTransform , x , y ) ;
87
- wrapper
88
- . append ( "g" )
85
+ // wrapper
86
+ // .append("g")
89
87
. call ( applyIndirectStyles , this )
88
+ . call ( applyTransform , x , y , offset + dx , offset + dy )
90
89
. call ( g => g . selectAll ( )
91
90
. data ( index )
92
91
. join ( "path" )
93
92
. call ( applyDirectStyles , this )
94
93
. attr ( "d" , arc )
95
- . attr ( "transform" , i => `translate(${ x ( X [ i ] ) } ,${ y ( Y [ i ] ) } )` )
96
- . attr ( "fill" , F && ( i => color ( F [ i ] ) ) )
97
- . attr ( "stroke" , S && ( i => color ( S [ i ] ) ) )
98
- . call ( title ( T ) ) ) ;
94
+ . attr ( "transform" , i => `translate(${ X ? X [ i ] : x } ,${ Y ? Y [ i ] : y } )` )
95
+ . call ( applyChannelStyles , channels ) ) ;
99
96
if ( L ) wrapper . append ( "g" ) . call ( _label ( L , index , arc ) ) ;
100
97
return wrapper . node ( ) ;
101
98
0 commit comments