Skip to content

Commit a863e3c

Browse files
'实现节点上渲染环形进度图'
1 parent b9254e7 commit a863e3c

File tree

9 files changed

+342
-1718
lines changed

9 files changed

+342
-1718
lines changed

package-lock.json

Lines changed: 226 additions & 1662 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
"d3": "^5.16.0",
1313
"dagre-d3": "^0.6.4",
1414
"element-ui": "^2.13.2",
15-
"jquery": "^3.5.1",
1615
"less-loader": "^6.1.0",
17-
"vfd": "^1.0.5",
1816
"vue": "^2.6.11",
1917
"vue-router": "^3.3.2"
2018
},
@@ -25,6 +23,7 @@
2523
"babel-eslint": "^10.1.0",
2624
"eslint": "^6.7.2",
2725
"eslint-plugin-vue": "^6.2.2",
26+
"jquery": "^3.6.0",
2827
"vue-template-compiler": "^2.6.11"
2928
},
3029
"eslintConfig": {

src/App.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default {
3434
text-align: center;
3535
color: #2c3e50;
3636
margin-top: 60px;
37+
height: 100%;
3738
}
3839
.links {
3940
text-decoration: none;

src/jsondata/data.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ let options = {
33
{
44
type: 'app', // 节点类型
55
name: 'monitor-app', // 节点名称
6-
active: 3, // 已完成数
6+
active: 9, // 已完成数
77
total: 10, // 总数
88
health: 1, // 监控健康程度
99
underText: 'underText', // 节点之间连接线下方的文字
1010
upwardText: "upwardText", // 节点之间连接线上方的文字
1111
isConfig: "true" // 节点配置状态
1212
},
13+
{
14+
type: 'app',
15+
name: 'monitor-app2',
16+
active: 1,
17+
total: 10,
18+
health: 3,
19+
underText: 'underText',
20+
upwardText: "upwardText",
21+
isConfig: "true"
22+
},
1323
{
1424
type: 'database',
1525
name: 'Mysql',
@@ -72,8 +82,11 @@ let options = {
7282
{
7383
source: 1,
7484
target: 2,
75-
}
76-
,
85+
},
86+
{
87+
source: 1,
88+
target: 6,
89+
},
7790
{
7891
source: 1,
7992
target: 3,

src/jsondata/togo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import d3 from 'd3'
12
export class Togo {
23
/**/
34
constructor(svg, option) {

src/router/router.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Vue from "vue"
22
import VueRouter from "vue-router"
33
import topoindex from "../views/topo/index.vue"
44
import treetopo from "../views/treetopo/index.vue"
5-
import vfd from "../views/vfd/index.vue"
65
Vue.use(VueRouter)
76
export default new VueRouter({
87
routes: [
@@ -16,11 +15,5 @@ export default new VueRouter({
1615
name: "treetopo",
1716
component: treetopo
1817
},
19-
{
20-
path: '/vfd',
21-
name: "vfd",
22-
component: vfd
23-
}
24-
2518
]
2619
})

src/views/topo/index.vue

Lines changed: 92 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
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>

src/views/treetopo/index.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
title="节点详情"
1111
:visible.sync="dialogVisible"
1212
width="50%"
13-
@closed="subDialogVisible=false"
14-
@open="subDialogVisible=true"
13+
@closed="subDialogVisible = false"
14+
@open="subDialogVisible = true"
1515
>
1616
<sub-topo v-if="subDialogVisible" />
1717
<span slot="footer" class="dialog-footer">
1818
<el-button @click="dialogVisible = false">取 消</el-button>
19-
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
19+
<el-button type="primary" @click="dialogVisible = false"
20+
>确 定</el-button
21+
>
2022
</span>
2123
</el-dialog>
2224
<svg width="1800" height="700">
@@ -140,8 +142,6 @@ export default {
140142
<style lang="less">
141143
svg {
142144
font-size: 14px;
143-
height: 700px;
144-
width: 1800px;
145145
border: 1px solid #000;
146146
}
147147

src/views/vfd/index.vue

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)