@@ -99,7 +99,7 @@ export class DelaunayLink extends Mark {
99
99
}
100
100
101
101
export class DelaunayMesh extends Mark {
102
- constructor ( data , options = { } ) {
102
+ constructor ( data , options = { } , defaults = meshDefaults ) {
103
103
const { x, y} = options ;
104
104
super (
105
105
data ,
@@ -108,50 +108,31 @@ export class DelaunayMesh extends Mark {
108
108
{ name : "y" , value : y , scale : "y" }
109
109
] ,
110
110
options ,
111
- meshDefaults
111
+ defaults
112
112
) ;
113
113
}
114
+ _render ( index , { x : X , y : Y } ) {
115
+ return Delaunay . from ( index , i => X [ i ] , i => Y [ i ] ) . render ( ) ;
116
+ }
114
117
render ( index , { x, y} , channels , dimensions ) {
115
- const { x : X , y : Y } = channels ;
116
118
const { dx, dy} = this ;
117
119
// TODO Group by z or stroke.
118
- const delaunay = Delaunay . from ( index , i => X [ i ] , i => Y [ i ] ) ;
119
120
return create ( "svg:g" )
120
121
. call ( applyIndirectStyles , this , dimensions )
121
122
. call ( g => g . append ( "path" )
122
123
. call ( applyDirectStyles , this )
123
124
. call ( applyTransform , x , y , offset + dx , offset + dy )
124
- . attr ( "d" , delaunay . render ( ) ) )
125
+ . attr ( "d" , this . _render ( index , channels ) ) )
125
126
. node ( ) ;
126
127
}
127
128
}
128
129
129
- export class Hull extends Mark {
130
+ export class Hull extends DelaunayMesh {
130
131
constructor ( data , options = { } ) {
131
- const { x, y} = options ;
132
- super (
133
- data ,
134
- [
135
- { name : "x" , value : x , scale : "x" } ,
136
- { name : "y" , value : y , scale : "y" }
137
- ] ,
138
- options ,
139
- hullDefaults
140
- ) ;
132
+ super ( data , options , hullDefaults ) ;
141
133
}
142
- render ( index , { x, y} , channels , dimensions ) {
143
- const { x : X , y : Y } = channels ;
144
- const { dx, dy} = this ;
145
- // TODO Group by z or stroke.
146
- // TODO Use faster monotone chain algorithm?
147
- const delaunay = Delaunay . from ( index , i => X [ i ] , i => Y [ i ] ) ;
148
- return create ( "svg:g" )
149
- . call ( applyIndirectStyles , this , dimensions )
150
- . call ( g => g . append ( "path" )
151
- . call ( applyDirectStyles , this )
152
- . call ( applyTransform , x , y , offset + dx , offset + dy )
153
- . attr ( "d" , delaunay . renderHull ( ) ) )
154
- . node ( ) ;
134
+ _render ( index , { x : X , y : Y } ) {
135
+ return Delaunay . from ( index , i => X [ i ] , i => Y [ i ] ) . renderHull ( ) ;
155
136
}
156
137
}
157
138
0 commit comments