@@ -151,6 +151,44 @@ const CytoscapeTopology = () => {
151151
152152 const layout = { name : 'cose-bilkent' , animate : true , idealEdgeLength : 100 , nodeRepulsion : 4500 }
153153
154+ const cyRef = useRef ( null )
155+
156+ useEffect ( ( ) => {
157+ const cy = cyRef . current
158+ if ( ! cy ) return
159+ let dashOffset = 0
160+ let running = true
161+ function animate ( ) {
162+ dashOffset = ( dashOffset + 2 ) % 40
163+ // 主干(服务器间)
164+ cy . edges ( 'edge[source^="server-"][target^="server-"]' ) . forEach ( ( edge ) => {
165+ edge . style ( 'line-dash-pattern' , [ 12 , 8 ] )
166+ edge . style ( 'line-dash-offset' , dashOffset )
167+ edge . style ( 'line-color' , '#1976D2' )
168+ edge . style ( 'target-arrow-color' , '#1976D2' )
169+ edge . style ( 'width' , 5 )
170+ edge . style ( 'opacity' , 0.7 )
171+ edge . style ( 'line-style' , 'dashed' )
172+ } )
173+ // 依赖(项目间)
174+ cy . edges ( 'edge[source^="proj-"]' ) . forEach ( ( edge ) => {
175+ edge . style ( 'line-dash-pattern' , [ 6 , 4 ] )
176+ edge . style ( 'line-dash-offset' , dashOffset )
177+ edge . style ( 'line-color' , '#aaa' )
178+ edge . style ( 'target-arrow-color' , '#aaa' )
179+ edge . style ( 'width' , 3 )
180+ edge . style ( 'opacity' , 1 )
181+ edge . style ( 'line-style' , 'dashed' )
182+ } )
183+ cy . style ( ) . update ( ) // 强制刷新
184+ if ( running ) requestAnimationFrame ( animate )
185+ }
186+ animate ( )
187+ return ( ) => {
188+ running = false
189+ }
190+ } , [ ] )
191+
154192 return (
155193 < FixTabPanel fill = { true } >
156194 < CytoscapeComponent
@@ -159,6 +197,7 @@ const CytoscapeTopology = () => {
159197 stylesheet = { stylesheet }
160198 layout = { layout }
161199 cy = { ( cy ) => {
200+ cyRef . current = cy
162201 console . log ( 'Cytoscape实例就绪' , cy )
163202 } }
164203 />
0 commit comments