@@ -59,7 +59,7 @@ interface PieDef {
5959 /** The inner radius of sectors */
6060 innerRadius ?: number | string ;
6161 /** The outer radius of sectors */
62- outerRadius ?: number | string ;
62+ outerRadius ?: number | string | ( ( dataPoint : any ) => number ) ;
6363 cornerRadius ?: number | string ;
6464}
6565
@@ -340,22 +340,36 @@ const getTextAnchor = (x: number, cx: number) => {
340340 return 'middle' ;
341341} ;
342342
343+ const getOuterRadius = (
344+ dataPoint : any ,
345+ outerRadius ?: number | string | ( ( element : any ) => number ) ,
346+ maxPieRadius ?: number ,
347+ ) => {
348+ if ( typeof outerRadius === 'function' ) {
349+ return outerRadius ( dataPoint ) ;
350+ }
351+ return getPercentValue ( outerRadius , maxPieRadius , maxPieRadius * 0.8 ) ;
352+ } ;
353+
343354const parseCoordinateOfPie = (
344355 item : {
345356 cx ?: number | string ;
346357 cy ?: number | string ;
347358 innerRadius ?: number | string ;
348- outerRadius ?: number | string ;
359+ outerRadius ?: number | string | ( ( dataPoint : any ) => number ) ;
349360 maxRadius ?: number ;
350361 } ,
351362 offset : ChartOffset ,
363+ dataPoint : any ,
352364) : PieCoordinate => {
353365 const { top, left, width, height } = offset ;
354366 const maxPieRadius = getMaxRadius ( width , height ) ;
355367 const cx = left + getPercentValue ( item . cx , width , width / 2 ) ;
356368 const cy = top + getPercentValue ( item . cy , height , height / 2 ) ;
357369 const innerRadius = getPercentValue ( item . innerRadius , maxPieRadius , 0 ) ;
358- const outerRadius = getPercentValue ( item . outerRadius , maxPieRadius , maxPieRadius * 0.8 ) ;
370+
371+ const outerRadius = getOuterRadius ( dataPoint , item . outerRadius , maxPieRadius ) ;
372+
359373 const maxRadius = item . maxRadius || Math . sqrt ( width * width + height * height ) / 2 ;
360374
361375 return { cx, cy, innerRadius, outerRadius, maxRadius } ;
@@ -423,15 +437,14 @@ export function computePieSectors({
423437 paddingAngle ?: number ;
424438 minAngle ?: number ;
425439 innerRadius ?: number | string ;
426- outerRadius ?: number | string ;
440+ outerRadius ?: number | string | ( ( dataPoint : any ) => number ) ;
427441 cornerRadius ?: number | string ;
428442 presentationProps ?: Record < string , string > ;
429443 } ;
430444 offset : ChartOffset ;
431- } ) : { sectors : ReadonlyArray < PieSectorDataItem > ; coordinate : PieCoordinate } {
445+ } ) : { sectors : ReadonlyArray < PieSectorDataItem > } {
432446 const { cornerRadius, startAngle, endAngle, dataKey, nameKey, tooltipType } = pieSettings ;
433447 const minAngle = Math . abs ( pieSettings . minAngle ) ;
434- const coordinate = parseCoordinateOfPie ( pieSettings , offset ) ;
435448 const deltaAngle = parseDeltaAngle ( startAngle , endAngle ) ;
436449 const absDeltaAngle = Math . abs ( deltaAngle ) ;
437450 const paddingAngle = displayedData . length <= 1 ? 0 : ( pieSettings . paddingAngle ?? 0 ) ;
@@ -451,6 +464,7 @@ export function computePieSectors({
451464 sectors = displayedData . map ( ( entry : any , i : number ) => {
452465 const val = getValueByDataKey ( entry , dataKey , 0 ) ;
453466 const name = getValueByDataKey ( entry , nameKey , i ) ;
467+ const coordinate = parseCoordinateOfPie ( pieSettings , offset , entry ) ;
454468 const percent = ( isNumber ( val ) ? val : 0 ) / sum ;
455469 let tempStartAngle ;
456470
@@ -497,12 +511,10 @@ export function computePieSectors({
497511 payload : entryWithCellInfo ,
498512 paddingAngle : mathSign ( deltaAngle ) * paddingAngle ,
499513 } ;
500-
501514 return prev ;
502515 } ) ;
503516 }
504-
505- return { sectors, coordinate } ;
517+ return { sectors } ;
506518}
507519
508520export class PieWithState extends PureComponent < InternalProps , State > {
0 commit comments