File tree Expand file tree Collapse file tree 2 files changed +13
-13
lines changed
Expand file tree Collapse file tree 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -89,21 +89,14 @@ const withTreemap = <IProps extends TreemapProps = TreemapProps>(View: Component
8989 return false ;
9090 }
9191
92- getSelectionStyle ( record ) {
93- const { state, props } = this ;
94- const { selected } = state ;
95- if ( ! selected || ! selected . length ) {
92+ generateSelectionStyle ( record : Record < string , unknown > , isSelected : boolean ) {
93+ if ( ! this . state . selected ?. length ) {
9694 return null ;
9795 }
98- const { selection } = props ;
99- const { selectedStyle, unSelectedStyle } = selection ;
10096
101- const isSelected = this . isSelected ( record ) ;
102-
103- if ( isSelected ) {
104- return isFunction ( selectedStyle ) ? selectedStyle ( record ) : selectedStyle ;
105- }
106- return isFunction ( unSelectedStyle ) ? unSelectedStyle ( record ) : unSelectedStyle ;
97+ const { selectedStyle, unSelectedStyle } = this . props . selection || { } ;
98+ const style = isSelected ? selectedStyle : unSelectedStyle ;
99+ return isFunction ( style ) ? style ( record ) : style ;
107100 }
108101
109102 willMount ( ) {
@@ -162,14 +155,16 @@ const withTreemap = <IProps extends TreemapProps = TreemapProps>(View: Component
162155 yMax : y1 ,
163156 } ;
164157
165- const style = this . getSelectionStyle ( data ) ;
158+ const selected = this . isSelected ( data ) ;
159+ const style = this . generateSelectionStyle ( data , selected ) ;
166160
167161 return {
168162 key : data . key ,
169163 origin : data ,
170164 color,
171165 ...rect ,
172166 style,
167+ selected,
173168 } ;
174169 } ) ;
175170 }
Original file line number Diff line number Diff line change @@ -112,9 +112,11 @@ describe('Treemap', () => {
112112 canvas . destroy ( ) ;
113113 } ) ;
114114 it ( 'select ' , async ( ) => {
115+ const treemapRef = { current : null } ;
115116 const { props } = (
116117 < Canvas context = { context } pixelRatio = { 1 } >
117118 < Treemap
119+ ref = { treemapRef }
118120 data = { data }
119121 color = { {
120122 field : 'name' ,
@@ -147,10 +149,12 @@ describe('Treemap', () => {
147149
148150 await delay ( 1000 ) ;
149151 expect ( context ) . toMatchImageSnapshot ( ) ;
152+ expect ( treemapRef . current ?. records [ 0 ] ?. selected ) . toBe ( true ) ;
150153
151154 const { props : nextProps } = (
152155 < Canvas context = { context } pixelRatio = { 1 } >
153156 < Treemap
157+ ref = { treemapRef }
154158 data = { data }
155159 color = { {
156160 field : 'name' ,
@@ -181,6 +185,7 @@ describe('Treemap', () => {
181185 canvas . update ( nextProps ) ;
182186 await delay ( 1000 ) ;
183187 expect ( context ) . toMatchImageSnapshot ( ) ;
188+ expect ( treemapRef . current ?. records [ 2 ] ?. selected ) . toBe ( true ) ;
184189 await delay ( 100 ) ;
185190 canvas . destroy ( ) ;
186191 } ) ;
You can’t perform that action at this time.
0 commit comments