1
- import { useFetchKnowledgeGraph } from '@/hooks/chunk-hooks' ;
2
1
import { ElementDatum , Graph , IElementEvent } from '@antv/g6' ;
3
2
import { useCallback , useEffect , useMemo , useRef } from 'react' ;
4
- import { buildNodesAndCombos , isDataExist } from './util' ;
3
+ import { buildNodesAndCombos } from './util' ;
5
4
6
5
import styles from './index.less' ;
7
6
@@ -11,14 +10,18 @@ const TooltipColorMap = {
11
10
edge : 'blue' ,
12
11
} ;
13
12
14
- const ForceGraph = ( ) => {
13
+ interface IProps {
14
+ data : any ;
15
+ show : boolean ;
16
+ }
17
+
18
+ const ForceGraph = ( { data, show } : IProps ) => {
15
19
const containerRef = useRef < HTMLDivElement > ( null ) ;
16
20
const graphRef = useRef < Graph | null > ( null ) ;
17
- const { data } = useFetchKnowledgeGraph ( ) ;
18
21
19
22
const nextData = useMemo ( ( ) => {
20
- if ( isDataExist ( data ) ) {
21
- const graphData = data . data ;
23
+ if ( data ) {
24
+ const graphData = data ;
22
25
const mi = buildNodesAndCombos ( graphData . nodes ) ;
23
26
return { edges : graphData . links , ...mi } ;
24
27
}
@@ -113,7 +116,7 @@ const ForceGraph = () => {
113
116
} , [ nextData ] ) ;
114
117
115
118
useEffect ( ( ) => {
116
- if ( isDataExist ( data ) ) {
119
+ if ( data ) {
117
120
render ( ) ;
118
121
}
119
122
} , [ data , render ] ) ;
@@ -122,7 +125,11 @@ const ForceGraph = () => {
122
125
< div
123
126
ref = { containerRef }
124
127
className = { styles . forceContainer }
125
- style = { { width : '100%' , height : '80vh' } }
128
+ style = { {
129
+ width : '90vh' ,
130
+ height : '80vh' ,
131
+ display : show ? 'block' : 'none' ,
132
+ } }
126
133
/>
127
134
) ;
128
135
} ;
0 commit comments