11import { ascending , sum } from "d3-array" ;
22import { ScaleOrdinal , scaleOrdinal } from "d3-scale" ;
33import { schemeCategory10 } from "d3-scale-chromatic" ;
4- import { Pie , PieArcDatum , arc , pie } from "d3-shape" ;
4+ import { Pie , pie , PieArcDatum } from "d3-shape" ;
55import orderBy from "lodash/orderBy" ;
66import { useMemo } from "react" ;
77
@@ -31,7 +31,6 @@ import {
3131 getSortingOrders ,
3232 makeDimensionValueSorters ,
3333} from "@/utils/sorting-values" ;
34- import { useIsMobile } from "@/utils/use-is-mobile" ;
3534
3635import { ChartProps } from "../shared/ChartProps" ;
3736
@@ -112,7 +111,7 @@ const usePieState = (
112111 label : segment ,
113112 color :
114113 fields . color . type === "segment"
115- ? fields . color . colorMapping ! [ dvIri ] ?? schemeCategory10 [ 0 ]
114+ ? ( fields . color . colorMapping ! [ dvIri ] ?? schemeCategory10 [ 0 ] )
116115 : schemeCategory10 [ 0 ] ,
117116 } ;
118117 } ) ;
@@ -169,17 +168,7 @@ const usePieState = (
169168 left,
170169 } ;
171170 const bounds = useChartBounds ( width , margins , height ) ;
172- const { chartWidth, chartHeight } = bounds ;
173-
174- // Pie values
175- const maxSide = Math . min ( chartWidth , chartHeight ) / 2 ;
176-
177- const innerRadius = 0 ;
178- const outerRadius = Math . min ( maxSide , 100 ) ;
179-
180- const arcGenerator = arc < Observation , PieArcDatum < Observation > > ( )
181- . innerRadius ( innerRadius )
182- . outerRadius ( outerRadius ) ;
171+ const { chartWidth } = bounds ;
183172
184173 // Pie data
185174 // Sort the pie according to the segments
@@ -216,34 +205,17 @@ const usePieState = (
216205 return `${ rounded } % (${ fValue } )` ;
217206 } ;
218207
219- const isMobile = useIsMobile ( ) ;
220-
221208 // Tooltip
222209 const getAnnotationInfo = (
223210 arcDatum : PieArcDatum < Observation >
224211 ) : TooltipInfo => {
225- const [ x , y ] = arcGenerator . centroid ( arcDatum ) ;
226212 const datum = arcDatum . data ;
227213
228- const xTranslate = chartWidth / 2 ;
229- const yTranslate = chartHeight / 2 ;
230-
231- const xAnchor = isMobile ? chartWidth / 2 : x + xTranslate ;
232- const yAnchor = isMobile ? - chartHeight : y + yTranslate ;
233-
234- const xPlacement = isMobile
235- ? "center"
236- : xAnchor < chartWidth * 0.5
237- ? "right"
238- : "left" ;
214+ const xAnchor = chartWidth / 2 ;
215+ const yAnchor = - 4 ;
239216
240- const yPlacement = isMobile
241- ? "top"
242- : yAnchor > chartHeight * 0.2
243- ? "top"
244- : yAnchor < chartHeight * 0.8
245- ? "bottom"
246- : "middle" ;
217+ const xPlacement = "center" ;
218+ const yPlacement = "top" ;
247219
248220 return {
249221 xAnchor,
@@ -255,7 +227,7 @@ const usePieState = (
255227 color : colors ( getSegment ( datum ) ) as string ,
256228 } ,
257229 values : undefined ,
258- withTriangle : ! isMobile ,
230+ withTriangle : false ,
259231 } ;
260232 } ;
261233
0 commit comments