1
1
import type { IVChart , SankeyProps } from '@sensoro-design/chart' ;
2
2
import { Sankey } from '@sensoro-design/chart' ;
3
- import { uniqueId } from 'es-toolkit/compat' ;
4
3
import React from 'react' ;
5
4
import tree from 'tree-lodash' ;
6
5
@@ -20,57 +19,72 @@ const values = [
20
19
{
21
20
nodes : [
22
21
{
23
- key : uniqueId ( ) ,
24
22
name : '今日巡航次数' ,
25
23
value : 160 ,
26
24
total : 1087875 ,
27
25
children : [
28
26
{
29
- key : uniqueId ( ) ,
30
27
name : '公共安全' ,
31
28
value : 40 ,
32
29
total : 287875 ,
33
30
children : [
34
- { key : uniqueId ( ) , name : '高风险' , value : 10 , total : 18764 } ,
35
- { key : uniqueId ( ) , name : '中风险' , value : 10 , total : 22329 } ,
36
- { key : uniqueId ( ) , name : '低风险' , value : 10 , total : 43093 } ,
37
- { key : uniqueId ( ) , name : '无风险' , value : 10 , total : 763875 } ,
31
+ {
32
+ name : '紧急响应' ,
33
+ value : 10 ,
34
+ total : 18764 ,
35
+ children : [
36
+ { name : '暴力行为' , value : 10 , total : 1864 } ,
37
+ { name : '突发状况' , value : 10 , total : 1864 } ,
38
+ ] ,
39
+ } ,
40
+ {
41
+ name : '异常跟踪' ,
42
+ value : 10 ,
43
+ total : 22329 ,
44
+ } ,
45
+ { name : '持续监测' , value : 10 , total : 43093 } ,
46
+ { name : '巡航正常' , value : 10 , total : 763875 } ,
38
47
] ,
39
48
} ,
40
49
{
41
- key : uniqueId ( ) ,
42
50
name : '交通安全' ,
43
51
value : 40 ,
44
52
total : 200653 ,
45
53
children : [
46
- { key : uniqueId ( '' ) , name : '高风险' , value : 10 , total : 18764 } ,
47
- { key : uniqueId ( ) , name : '中风险' , value : 10 , total : 22329 } ,
48
- { key : uniqueId ( ) , name : '低风险' , value : 10 , total : 43093 } ,
49
- { key : uniqueId ( ) , name : '无风险' , value : 10 , total : 763875 } ,
54
+ {
55
+ name : '紧急响应' ,
56
+ value : 10 ,
57
+ total : 18764 ,
58
+ children : [
59
+ { name : '暴力行为' , value : 10 , total : 1864 } ,
60
+ { name : '突发状况' , value : 10 , total : 1864 } ,
61
+ ] ,
62
+ } ,
63
+ { name : '异常跟踪' , value : 10 , total : 22329 } ,
64
+ { name : '持续监测' , value : 10 , total : 43093 } ,
65
+ { name : '巡航正常' , value : 10 , total : 763875 } ,
50
66
] ,
51
67
} ,
52
68
{
53
- key : uniqueId ( ) ,
54
69
name : '市容市政' ,
55
70
value : 40 ,
56
71
total : 406765 ,
57
72
children : [
58
- { key : uniqueId ( ) , name : '高风险 ' , value : 10 , total : 18764 } ,
59
- { key : uniqueId ( ) , name : '中风险 ' , value : 10 , total : 22329 } ,
60
- { key : uniqueId ( ) , name : '低风险 ' , value : 10 , total : 43093 } ,
61
- { key : uniqueId ( ) , name : '无风险 ' , value : 10 , total : 763875 } ,
73
+ { name : '紧急响应 ' , value : 10 , total : 18764 } ,
74
+ { name : '异常跟踪 ' , value : 10 , total : 22329 } ,
75
+ { name : '持续监测 ' , value : 10 , total : 43093 } ,
76
+ { name : '巡航正常 ' , value : 10 , total : 763875 } ,
62
77
] ,
63
78
} ,
64
79
{
65
- key : uniqueId ( ) ,
66
80
name : '城市秩序' ,
67
81
value : 40 ,
68
82
total : 82854 ,
69
83
children : [
70
- { key : uniqueId ( ) , name : '高风险 ' , value : 10 , total : 18764 } ,
71
- { key : uniqueId ( ) , name : '中风险 ' , value : 10 , total : 22329 } ,
72
- { key : uniqueId ( ) , name : '低风险 ' , value : 10 , total : 43093 } ,
73
- { key : uniqueId ( ) , name : '无风险 ' , value : 10 , total : 763875 } ,
84
+ { name : '紧急响应 ' , value : 10 , total : 18764 } ,
85
+ { name : '异常跟踪 ' , value : 10 , total : 22329 } ,
86
+ { name : '持续监测 ' , value : 10 , total : 43093 } ,
87
+ { name : '巡航正常 ' , value : 10 , total : 763875 } ,
74
88
] ,
75
89
} ,
76
90
] ,
@@ -81,10 +95,10 @@ const values = [
81
95
82
96
const colors = [ '#423CD1' , '#E7474D' , '#E7AF2C' , '#51C2E1' , '#3AC583' ] ;
83
97
const defaultSpecified = {
84
- 高风险 : colors [ 1 ] ,
85
- 中风险 : colors [ 2 ] ,
86
- 低风险 : colors [ 3 ] ,
87
- 无风险 : colors [ 4 ] ,
98
+ 紧急响应 : colors [ 1 ] ,
99
+ 异常跟踪 : colors [ 2 ] ,
100
+ 持续监测 : colors [ 3 ] ,
101
+ 巡航正常 : colors [ 4 ] ,
88
102
} ;
89
103
const specified : Record < string , string > = {
90
104
...defaultSpecified ,
@@ -131,7 +145,7 @@ function Example() {
131
145
const timeoutRef = React . useRef < NodeJS . Timeout > ( ) ;
132
146
const intervalRef = React . useRef < NodeJS . Timeout | null > ( null ) ;
133
147
const [ tooltipStyles , setTooltipStyles ] = React . useState < React . CSSProperties > ( { } ) ;
134
- const [ hideLabel , setHideLabel ] = React . useState ( false ) ;
148
+ const [ isAutoHover , setIsAutoHover ] = React . useState ( false ) ;
135
149
136
150
const spec : SankeyProps = {
137
151
height : 600 ,
@@ -155,8 +169,27 @@ function Example() {
155
169
// @ts -expect-error 忽略报错
156
170
return datum . name ;
157
171
} ,
158
- nodeHeight ( node ) {
159
- return node . depth === 0 ? 160 : 40 ;
172
+ nodeHeight : ( node ) => {
173
+ if ( node . depth === 0 ) {
174
+ return 160 ;
175
+ }
176
+
177
+ if ( node . depth === 1 || node . depth === 2 ) {
178
+ return 40 ;
179
+ }
180
+
181
+ return 20 ;
182
+ } ,
183
+ linkHeight ( _ , sourceNode ) {
184
+ if ( sourceNode . depth === 0 ) {
185
+ return 40 ;
186
+ }
187
+
188
+ if ( sourceNode . depth === 1 ) {
189
+ return 10 ;
190
+ }
191
+
192
+ return 20 ;
160
193
} ,
161
194
node : {
162
195
style : {
@@ -175,8 +208,6 @@ function Example() {
175
208
visible : true ,
176
209
offset : - 12 ,
177
210
formatMethod ( _ , datum ) {
178
- if ( hideLabel )
179
- return `` ;
180
211
return `${ datum ?. name } ${ datum ?. total ?. toLocaleString ( ) } ` ;
181
212
} ,
182
213
style : {
@@ -223,7 +254,7 @@ function Example() {
223
254
emphasis : {
224
255
enable : true ,
225
256
trigger : 'hover' ,
226
- effect : 'related' ,
257
+ effect : isAutoHover ? 'adjacency' : 'related' ,
227
258
} ,
228
259
} ;
229
260
@@ -239,6 +270,8 @@ function Example() {
239
270
if ( chart ) {
240
271
chart . setHovered ( null ) ;
241
272
}
273
+
274
+ setIsAutoHover ( false ) ;
242
275
} ;
243
276
244
277
const startAutoHover = ( ) => {
@@ -261,6 +294,8 @@ function Example() {
261
294
] ) ;
262
295
}
263
296
} , 2 * 1000 ) ;
297
+
298
+ setIsAutoHover ( true ) ;
264
299
} ;
265
300
266
301
const handlePointerEnter = ( ) => {
@@ -338,16 +373,6 @@ function Example() {
338
373
[ ] ,
339
374
) ;
340
375
341
- React . useEffect ( ( ) => {
342
- const timeout = setTimeout ( ( ) => {
343
- setHideLabel ( true ) ;
344
- } , 5 * 1000 ) ;
345
-
346
- return ( ) => {
347
- timeout && clearTimeout ( timeout ) ;
348
- } ;
349
- } , [ ] ) ;
350
-
351
376
const handleClick : SankeyProps [ 'onClick' ] = ( e ) => {
352
377
if ( e . node ?. type === 'rect' ) {
353
378
const { datum } = e ;
@@ -365,7 +390,6 @@ function Example() {
365
390
if ( datum . datum . name === item . name ) {
366
391
item . children = [
367
392
{
368
- key : uniqueId ( ) ,
369
393
name : '测试节点' ,
370
394
value : 5 ,
371
395
total : 1000 ,
@@ -389,6 +413,7 @@ function Example() {
389
413
< Sankey
390
414
{ ...spec }
391
415
ref = { chartRef }
416
+ skipFunctionDiff
392
417
onClick = { handleClick }
393
418
onDblClick = { handleDblClick }
394
419
/>
0 commit comments