1- import { geoCentroid as GeoCentroid , geoPath } from "d3" ;
1+ import { geoCentroid as GeoCentroid } from "d3" ;
22import { memoize1 } from "../memoize.js" ;
33import { identity , valueof } from "../options.js" ;
44import { initializer } from "./basic.js" ;
@@ -9,20 +9,17 @@ export function centroid({geometry = identity, ...options} = {}) {
99 // Suppress defaults for x and y since they will be computed by the initializer.
1010 // Propagate the (memoized) geometry channel in case it’s still needed.
1111 { ...options , x : null , y : null , geometry : { transform : getG } } ,
12- ( data , facets , channels , scales , dimensions , { projection } ) => {
12+ ( data , facets , channels , scales , dimensions , context ) => {
1313 const G = getG ( data ) ;
1414 const n = G . length ;
1515 const X = new Float64Array ( n ) ;
1616 const Y = new Float64Array ( n ) ;
17- const path = geoPath ( projection ) ;
18- for ( let i = 0 ; i < n ; ++ i ) [ X [ i ] , Y [ i ] ] = path . centroid ( G [ i ] ) ;
17+ const { centroid } = context . path ( ) ;
18+ for ( let i = 0 ; i < n ; ++ i ) [ X [ i ] , Y [ i ] ] = centroid ( G [ i ] ) ;
1919 return {
2020 data,
2121 facets,
22- channels : {
23- x : { value : X , scale : projection == null ? "x" : null , source : null } ,
24- y : { value : Y , scale : projection == null ? "y" : null , source : null }
25- }
22+ channels : { x : { value : X , scale : null , source : null } , y : { value : Y , scale : null , source : null } }
2623 } ;
2724 }
2825 ) ;
0 commit comments