11import { DisplayObject } from '@antv/g' ;
22import { deepMix } from '@antv/util' ;
33import { group } from '@antv/vendor/d3-array' ;
4- import { arc } from '@antv/vendor/d3-shape' ;
54import { isPolar } from '../utils/coordinate' ;
6- import { getArcObject } from '../shape/utils' ;
75import {
86 createDatumof ,
97 createUseState ,
@@ -55,61 +53,40 @@ export function elementHoverScale(
5553
5654 let out ;
5755
58- // Apply radial growth effect for polar coordinates by modifying the arc path
59- const applyPolarRadialGrowth = ( element : DisplayObject ) : boolean => {
60- const data = ( element as any ) . __data__ ;
61- if ( ! data || ! data . points || data . points . length < 4 ) return false ;
62-
63- const { y, y1 } = data ;
64- if ( y === undefined ) return false ;
65-
66- // Calculate current arc parameters and increase outer radius
67- const arcObject = getArcObject ( coordinate , data . points , [ y , y1 ] ) ;
68- const newOuterRadius = arcObject . outerRadius * scaleFactor ;
69-
70- // Generate new arc path with increased outer radius
71- const arcGenerator = arc ( )
72- . cornerRadius ( ( element . style . radius || 0 ) as number )
73- . padAngle ( ( ( element . style . inset || 0 ) * Math . PI ) / 180 ) ;
74-
75- const newPath = arcGenerator ( {
76- ...arcObject ,
77- outerRadius : newOuterRadius ,
78- } as any ) ;
79-
80- if ( ! newPath ) return false ;
81-
82- element . attr ( 'd' , newPath ) ;
83- return true ;
84- } ;
85-
8656 const applyHoverEffect = ( element : DisplayObject ) => {
8757 if ( originalStyles . has ( element ) ) return ;
8858
8959 const currentTransform = element . style . transform || '' ;
60+ const currentTransformOrigin = element . style . transformOrigin || '' ;
61+ // Normalize 'none' to empty string as 'none' is not a valid transform value for concatenation
62+ const normalizedTransform =
63+ currentTransform === 'none' ? '' : currentTransform ;
9064
91- // Save original styles
65+ // Save original styles for restoration
9266 originalStyles . set ( element , {
9367 transform : currentTransform ,
94- d : element . attr ( 'd' ) || '' ,
68+ transformOrigin : currentTransformOrigin ,
9569 zIndex : element . style . zIndex || 0 ,
9670 shadowColor : element . style . shadowColor || '' ,
9771 shadowBlur : element . style . shadowBlur || 0 ,
9872 shadowOffsetX : element . style . shadowOffsetX || 0 ,
9973 shadowOffsetY : element . style . shadowOffsetY || 0 ,
10074 } ) ;
10175
102- // Apply radial growth for polar coordinates, otherwise use scale transform
103- const isPolarCoord = coordinate && isPolar ( coordinate ) ;
104- const appliedRadialGrowth = isPolarCoord && applyPolarRadialGrowth ( element ) ;
105-
106- if ( ! appliedRadialGrowth ) {
107- const scaleTransform = `scale(${ scaleFactor } )` ;
108- element . style . transform = currentTransform . includes ( 'translate' )
109- ? `${ currentTransform } ${ scaleTransform } `
110- : scaleTransform ;
76+ // For polar coordinates without transform, set transformOrigin to coordinate center
77+ // When legend filtering occurs, element positioning changes from translate to absolute path coords
78+ // Setting transformOrigin to center ensures consistent radial growth in both cases
79+ if ( coordinate && isPolar ( coordinate ) && ! normalizedTransform ) {
80+ const center = coordinate . getCenter ( ) as [ number , number ] ;
81+ element . style . transformOrigin = `${ center [ 0 ] } px ${ center [ 1 ] } px` ;
11182 }
11283
84+ // Apply scale transform
85+ const scaleTransform = `scale(${ scaleFactor } )` ;
86+ element . style . transform = normalizedTransform
87+ ? `${ normalizedTransform } ${ scaleTransform } `
88+ : scaleTransform ;
89+
11390 // Apply visual effects
11491 element . style . zIndex = zIndex ;
11592
@@ -125,9 +102,9 @@ export function elementHoverScale(
125102 const original = originalStyles . get ( element ) ;
126103 if ( ! original ) return ;
127104
128- // Restore original path and styles
129- if ( original . d ) element . attr ( 'd' , original . d ) ;
105+ // Restore all original styles
130106 element . style . transform = original . transform ;
107+ element . style . transformOrigin = original . transformOrigin ;
131108 element . style . zIndex = original . zIndex ;
132109 element . style . shadowColor = original . shadowColor ;
133110 element . style . shadowBlur = original . shadowBlur ;
0 commit comments