@@ -7,6 +7,7 @@ import * as d3 from "d3-selection";
77import * as d3Graphviz from " d3-graphviz" ;
88import { getAllLayers , getAllCITypesByLayerWithAttr } from " @/api/server" ;
99import { setHeaders } from " @/api/base.js" ;
10+ import { addEvent } from " ./util/event.js" ;
1011export default {
1112 data () {
1213 return {
@@ -105,14 +106,64 @@ export default {
105106 " X-XSRF-TOKEN" : uploadToken && uploadToken .split (" =" )[1 ]
106107 });
107108 initEvent ();
108- let nodesString = this .genDOT (ciResponse .data );
109- this .loadImage (nodesString);
110- this .graph .graphviz .renderDot (nodesString);
111- let svg = d3 .select (" #graph" ).select (" svg" );
112- svg .append (" g" ).lower ();
109+ this .renderGraph (ciResponse .data );
113110 }
114111 }
115112 },
113+ renderGraph (data ) {
114+ let nodesString = this .genDOT (data);
115+ this .loadImage (nodesString);
116+ this .graph .graphviz .renderDot (nodesString);
117+ let svg = d3 .select (" #graph" ).select (" svg" );
118+ svg .append (" g" ).lower ();
119+ addEvent (" svg" , " mouseover" , e => {
120+ this .shadeAll ();
121+ e .preventDefault ();
122+ e .stopPropagation ();
123+ });
124+ this .shadeAll ();
125+ addEvent (" .node" , " mouseover" , async e => {
126+ e .preventDefault ();
127+ e .stopPropagation ();
128+ d3 .selectAll (" g" ).attr (" cursor" , " pointer" );
129+
130+ this .g = e .currentTarget ;
131+ this .nodeName = this .g .children [0 ].innerHTML .trim ();
132+ this .shadeAll ();
133+ this .colorNode (this .nodeName );
134+ });
135+ },
136+ shadeAll () {
137+ d3 .selectAll (" g path" )
138+ .attr (" stroke" , " #7f8fa6" )
139+ .attr (" stroke-opacity" , " .2" );
140+ d3 .selectAll (" g polygon" )
141+ .attr (" stroke" , " #7f8fa6" )
142+ .attr (" stroke-opacity" , " .2" )
143+ .attr (" fill" , " #7f8fa6" )
144+ .attr (" fill-opacity" , " .2" );
145+ d3 .selectAll (" .edge text" ).attr (" fill" , " #7f8fa6" );
146+ },
147+ colorNode (nodeName ) {
148+ d3 .selectAll (' g[from="' + nodeName + ' "] path' )
149+ .attr (" stroke" , " red" )
150+ .attr (" stroke-opacity" , " 1" );
151+ d3 .selectAll (' g[from="' + nodeName + ' "] text' ).attr (" fill" , " red" );
152+ d3 .selectAll (' g[from="' + nodeName + ' "] polygon' )
153+ .attr (" stroke" , " red" )
154+ .attr (" fill" , " red" )
155+ .attr (" fill-opacity" , " 1" )
156+ .attr (" stroke-opacity" , " 1" );
157+ d3 .selectAll (' g[to="' + nodeName + ' "] path' )
158+ .attr (" stroke" , " green" )
159+ .attr (" stroke-opacity" , " 1" );
160+ d3 .selectAll (' g[to="' + nodeName + ' "] text' ).attr (" fill" , " green" );
161+ d3 .selectAll (' g[to="' + nodeName + ' "] polygon' )
162+ .attr (" stroke" , " green" )
163+ .attr (" fill" , " green" )
164+ .attr (" fill-opacity" , " 1" )
165+ .attr (" stroke-opacity" , " 1" );
166+ },
116167 renderRightPanels () {
117168 if (! this .nodeName ) return ;
118169 if (!! this .isLayerSelected ) {
0 commit comments