@@ -192,6 +192,48 @@ function Example() {
192
192
} ,
193
193
} ;
194
194
195
+ const startAutoHover = ( ) => {
196
+ const chart = chartRef . current ;
197
+ const names : string [ ] = [ ] ;
198
+
199
+ foreach (
200
+ values [ 0 ] . nodes ,
201
+ ( item ) => {
202
+ const name = item . name as unknown as string ;
203
+ if ( ! names . includes ( name ) && name !== '今日巡航次数' ) {
204
+ names . push ( name ) ;
205
+ }
206
+ } ,
207
+ {
208
+ strategy : 'breadth' ,
209
+ } ,
210
+ ) ;
211
+
212
+ if ( ! chart )
213
+ return ;
214
+
215
+ intervalRef . current = setInterval ( ( ) => {
216
+ const name = getRandomElement ( names ) ;
217
+
218
+ if ( name ) {
219
+ chart . setHovered ( [
220
+ {
221
+ name,
222
+ } ,
223
+ ] ) ;
224
+ }
225
+ } , 2 * 1000 ) ;
226
+ } ;
227
+
228
+ const closeAutoHover = ( ) => {
229
+ const chart = chartRef . current ;
230
+
231
+ intervalRef . current && clearInterval ( intervalRef . current ) ;
232
+ if ( chart ) {
233
+ chart . setHovered ( null ) ;
234
+ }
235
+ } ;
236
+
195
237
React . useEffect (
196
238
( ) => {
197
239
timeoutRef . current = setTimeout ( ( ) => {
@@ -203,32 +245,7 @@ function Example() {
203
245
if ( ! chart )
204
246
return ;
205
247
206
- const names : string [ ] = [ ] ;
207
-
208
- foreach (
209
- values [ 0 ] . nodes ,
210
- ( item ) => {
211
- const name = item . name as unknown as string ;
212
- if ( ! names . includes ( name ) && name !== '今日巡航次数' ) {
213
- names . push ( name ) ;
214
- }
215
- } ,
216
- {
217
- strategy : 'breadth' ,
218
- } ,
219
- ) ;
220
-
221
- intervalRef . current = setInterval ( ( ) => {
222
- const name = getRandomElement ( names ) ;
223
-
224
- if ( name ) {
225
- chart . setHovered ( [
226
- {
227
- name,
228
- } ,
229
- ] ) ;
230
- }
231
- } , 2 * 1000 ) ;
248
+ startAutoHover ( ) ;
232
249
233
250
chart . setTooltipHandler ( {
234
251
showTooltip : ( activeType , data , params ) => {
@@ -270,7 +287,7 @@ function Example() {
270
287
271
288
return ( ) => {
272
289
timeoutRef . current && clearTimeout ( timeoutRef . current ) ;
273
- intervalRef . current && clearInterval ( intervalRef . current ) ;
290
+ closeAutoHover ( ) ;
274
291
} ;
275
292
} ,
276
293
[ ] ,
0 commit comments