@@ -61,25 +61,25 @@ const DependencyGraph: React.FC = () => {
6161 svg . append ( 'defs' ) . append ( 'marker' )
6262 . attr ( 'id' , 'arrowhead' )
6363 . attr ( 'viewBox' , '0 -5 10 10' )
64- . attr ( 'refX' , 8 )
64+ . attr ( 'refX' , 12 )
6565 . attr ( 'refY' , 0 )
6666 . attr ( 'orient' , 'auto' )
67- . attr ( 'markerWidth' , 6 )
68- . attr ( 'markerHeight' , 6 )
67+ . attr ( 'markerWidth' , 8 )
68+ . attr ( 'markerHeight' , 8 )
6969 . append ( 'path' )
7070 . attr ( 'd' , 'M 0,-5 L 10,0 L 0,5' )
7171 . attr ( 'fill' , '#333' )
7272 . style ( 'stroke' , 'none' ) ;
7373
7474 const nodesMap = new Map < string , DependencyNode > ( ) ;
7575 const links : DependencyLink [ ] = [ ] ;
76-
76+ // 根据cve_count设置节点颜色
7777 function processDependencies ( dep : GraphDependency , parent ?: DependencyNode ) {
7878 const nodeId = `${ dep . name_and_version } ` ;
7979 let node = nodesMap . get ( nodeId ) ;
8080 if ( ! node ) {
8181 const getColorByCveCount = ( count : number ) => {
82- if ( count === 0 ) return '#2ecc71 ' ; // 绿色
82+ if ( count === 0 ) return '#808080 ' ; // 灰色
8383 if ( count >= 10 ) return '#8b0000' ; // 深红色
8484 if ( count >= 6 ) return '#e74c3c' ; // 红色
8585 if ( count >= 3 ) return '#e67e22' ; // 橙色
@@ -108,18 +108,18 @@ const DependencyGraph: React.FC = () => {
108108 const nodes = Array . from ( nodesMap . values ( ) ) ;
109109
110110 const simulation = d3 . forceSimulation < DependencyNode > ( nodes )
111- . force ( 'link' , d3 . forceLink < DependencyNode , DependencyLink > ( links ) . id ( d => d . id ) . distance ( 80 ) )
112- . force ( 'charge' , d3 . forceManyBody ( ) . strength ( - 300 ) )
111+ . force ( 'link' , d3 . forceLink < DependencyNode , DependencyLink > ( links ) . id ( d => d . id ) . distance ( 150 ) )
112+ . force ( 'charge' , d3 . forceManyBody ( ) . strength ( - 500 ) )
113113 . force ( 'center' , d3 . forceCenter ( width / 2 , height / 2 ) )
114- . force ( 'collide' , d3 . forceCollide ( ) . radius ( 15 ) ) ;
114+ . force ( 'collide' , d3 . forceCollide ( ) . radius ( 30 ) ) ;
115115
116116 const g = svg . append ( 'g' ) ;
117117
118118 const link = g . append ( 'g' )
119119 . selectAll ( 'line' )
120120 . data ( links )
121121 . enter ( ) . append ( 'line' )
122- . attr ( 'stroke-width' , 1.5 )
122+ . attr ( 'stroke-width' , 2 )
123123 . attr ( 'stroke' , '#333' )
124124 . attr ( 'marker-end' , 'url(#arrowhead)' )
125125 . attr ( 'x2' , function ( d ) {
@@ -139,10 +139,10 @@ const DependencyGraph: React.FC = () => {
139139 . selectAll ( 'circle' )
140140 . data ( nodes )
141141 . enter ( ) . append ( 'circle' )
142- . attr ( 'r' , 8 )
142+ . attr ( 'r' , 15 )
143143 . attr ( 'fill' , d => d . color )
144144 . attr ( 'stroke' , '#333' )
145- . attr ( 'stroke-width' , 1.5 )
145+ . attr ( 'stroke-width' , 2 )
146146 . call ( d3 . drag < SVGCircleElement , DependencyNode > ( )
147147 . on ( 'start' , dragstarted )
148148 . on ( 'drag' , dragged )
@@ -157,9 +157,11 @@ const DependencyGraph: React.FC = () => {
157157 . data ( nodes )
158158 . enter ( ) . append ( 'text' )
159159 . attr ( 'dy' , '.35em' )
160- . attr ( 'x' , d => d . x ! + 10 )
160+ . attr ( 'x' , d => d . x ! + 20 )
161161 . attr ( 'y' , d => d . y ! )
162- . text ( d => d . id ) ;
162+ . text ( d => d . id )
163+ . style ( 'font-size' , '14px' )
164+ . style ( 'font-weight' , 'bold' ) ;
163165
164166 simulation
165167 . nodes ( nodes )
@@ -189,7 +191,7 @@ const DependencyGraph: React.FC = () => {
189191 . attr ( 'cy' , d => d . y ! ) ;
190192
191193 labels
192- . attr ( 'x' , d => d . x ! + 10 )
194+ . attr ( 'x' , d => d . x ! + 20 )
193195 . attr ( 'y' , d => d . y ! ) ;
194196 }
195197
0 commit comments