11<template >
2- <div >
3- <svg id =" topo" width =" 1800" height =" 700" />
2+ <div style =" height : 100% " >
3+ <svg id =" topo" width =" 1800" height =" 1000" />
4+ <svg id =" fillgauge1" width =" 97%" height =" 250" ></svg >
45 <el-dialog
56 center
67 title =" 节点详情"
78 :visible.sync =" dialogVisible"
89 width =" 50%"
9- @closed =" subTopo= false"
10- @open =" subTopo= true"
10+ @closed =" subTopo = false"
11+ @open =" subTopo = true"
1112 >
1213 <sub-topo v-if =" subTopo" />
1314 <span slot =" footer" class =" dialog-footer" >
1415 <el-button @click =" dialogVisible = false" >取 消</el-button >
15- <el-button type =" primary" @click =" dialogVisible = false" >确 定</el-button >
16+ <el-button type =" primary" @click =" dialogVisible = false"
17+ >确 定</el-button
18+ >
1619 </span >
1720 </el-dialog >
1821 </div >
@@ -37,7 +40,7 @@ export default {
3740 handleClose () {
3841 this .dialogVisible = false
3942 this .subTopo = false
40- }
43+ },
4144 }
4245 ,
4346 mounted () {
@@ -254,14 +257,82 @@ export default {
254257
255258 // 绘制节点图标
256259 drawNodeSymbol () {
257- this .nodes .filter (item => item .type == ' app' )
258- .append (" circle" )
259- .attr (" r" , symbolSize / 2 )
260- .attr (" fill" , ' #fff' )
261- .attr (' class' , function (d ) {
262- return ' health' + d .health ;
263- })
264- .attr (' stroke-width' , ' 5px' )
260+ // this.nodes.filter(item => item.type == 'app')
261+ // .append("circle")
262+ // .attr("r", symbolSize / 2)
263+ // .attr("fill", '#fff')
264+ // .attr('class', function (d) {
265+ // return 'health' + d.health;
266+ // })
267+ // .attr('stroke-width', '5px')
268+
269+ // var color = colors.pink;
270+ var arc = d3 .arc ()
271+ .startAngle (0 )
272+ .innerRadius (25 )
273+ .outerRadius (25 - 5 );
274+
275+ var parent = this .nodes .filter (item => item .type == ' app' )
276+
277+ // var svg = parent.append('svg')
278+ // .attr('width', boxSize)
279+ // .attr('height', boxSize)
280+ // .attr('x', function () {
281+ // return -this.getBBox().width
282+ // })
283+ // .attr('y', function () {
284+ // return -this.getBBox().height
285+ // })
286+
287+ var defs = parent .append (' defs' );
288+
289+ var filter = defs .append (' filter' )
290+ .attr (' id' , ' blur' );
291+
292+ filter .append (' feGaussianBlur' )
293+ .attr (' in' , ' SourceGraphic' )
294+ .attr (' stdDeviation' , ' 7' );
295+
296+ var g = parent .append (' g' )
297+ .attr (' transform' , ' translate(' - symbolSize / 2 + ' ,' - symbolSize / 2 + ' )' );
298+
299+ var meter = g .append (' g' )
300+ .attr (' class' , ' progress-meter' );
301+
302+ meter .append (' path' )
303+ .attr (' class' , ' background' )
304+ .attr (' fill' , ' #ccc' )
305+ .attr (' fill-opacity' , 0.9 )
306+ .attr (' d' , arc .endAngle (Math .PI * 2 ));
307+
308+ var foreground = meter .append (' path' )
309+ .attr (' class' , ' foreground' )
310+ .attr (' fill' , (data ) => { return data .health === 1 ? ' #92e1a2' : (data .health === 2 ? ' orange' : ' red' ) })
311+ .attr (' fill-opacity' , 1 )
312+ .attr (' stroke' , (data ) => { return data .health === 1 ? ' #92e1a2' : (data .health === 2 ? ' orange' : ' red' ) })
313+ .attr (' stroke-width' , 3 )
314+ .attr (' stroke-opacity' , 1 )
315+ // .attr('filter', 'url(#blur)');//泛光
316+
317+ var front = meter .append (' path' )
318+ .attr (' class' , ' foreground' )
319+ .attr (' fill' , (data ) => { return data .health === 1 ? ' #92e1a2' : (data .health === 2 ? ' orange' : ' red' ) })
320+ .attr (' fill-opacity' , 1 );
321+
322+ var numberText = meter .append (' text' )
323+ .attr (' fill' , ' #fff' )
324+ .attr (' text-anchor' , ' middle' )
325+ .attr (' dy' , ' .35em' );
326+ console .log (' foreground' , foreground)
327+ foreground .attr (' d' , (data ) => arc .endAngle (Math .PI * 2 * (data .active / data .total )));
328+ front .attr (' d' , (data ) => arc .endAngle (Math .PI * 2 * (data .active / data .total ))());
329+ numberText .text ((d ) => {
330+ return (d .active / d .total ) * 100 + " %" ;
331+ });
332+
333+
334+
335+
265336
266337 // 在<defs>元素中定义的图形不会直接显示在SVG图像上。要显示它们需要使用<use>元素来引入它们
267338 // <use>元素通过xlink:href属性来引入<g>元素。注意在ID前面要添加一个#。
@@ -327,14 +398,13 @@ export default {
327398 return d .name ;
328399 })
329400 .attr (" dy" , symbolSize)
330- // 处理节点图标中的百分比
331- this .nodes .filter (item => item .type == ' app' ).append (" text" )
332- .text (function (d ) {
333- return (d .active / d .total ) * 100 + " %" ;
334- })
335- .attr (' dy' , fontSize / 2 )
336- .attr (' class' , ' node-call' )
337-
401+ // // 处理节点图标中的百分比
402+ // this.nodes.filter(item => item.type == 'app').append("text")
403+ // .text(function (d) {
404+ // return (d.active / d.total) * 100 + "%";
405+ // })
406+ // .attr('dy', fontSize / 2)
407+ // .attr('class', 'node-call')
338408 }
339409
340410 // 画节点链接线
@@ -346,7 +416,6 @@ export default {
346416 ' d' , link => genLinkPath (link),
347417 )
348418 } else {
349- console .log (this .edges )
350419 this .lineGroup = this .container .append (' g' )
351420 this .lineGroup .selectAll (' .link' )
352421 .data (this .edges )
@@ -464,7 +533,6 @@ export default {
464533
465534 let t = new Topo (' #topo' , options);
466535 t .render ();
467-
468536 }
469537}
470538 </script >
0 commit comments