Skip to content

Commit ab4a080

Browse files
authored
Merge pull request #227 from WeBankPartners/214_ci_query_page_optimization
#214 homepage and cmdb model page graph optimization
2 parents 2219d51 + 2510457 commit ab4a080

2 files changed

Lines changed: 64 additions & 24 deletions

File tree

cmdb-ui/src/pages/admin/cmdb-model-management.vue

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ export default {
12301230
.attr("stroke-opacity", ".2")
12311231
.attr("fill", "#7f8fa6")
12321232
.attr("fill-opacity", ".2");
1233-
d3.selectAll(".edge text").attr("fill", "#000");
1233+
d3.selectAll(".edge text").attr("fill", "#7f8fa6");
12341234
},
12351235
colorNode(nodeName) {
12361236
d3.selectAll('g[from="' + nodeName + '"] path')
@@ -1267,37 +1267,26 @@ export default {
12671267
let nodesString = this.genDOT(data);
12681268
this.loadImage(nodesString);
12691269
this.graph.graphviz.renderDot(nodesString);
1270-
addEvent("svg", "click", e => {
1270+
addEvent("svg", "mouseover", e => {
1271+
this.shadeAll();
12711272
e.preventDefault();
12721273
e.stopPropagation();
1273-
d3.selectAll("g path")
1274-
.attr("stroke", "#7f8fa6")
1275-
.attr("stroke-opacity", "1");
1276-
d3.selectAll("g polygon")
1277-
.attr("stroke", "#7f8fa6")
1278-
.attr("stroke-opacity", "1")
1279-
.attr("fill", "#7f8fa6")
1280-
.attr("fill-opacity", "1");
1281-
d3.selectAll(".edge text").attr("fill", "#000");
12821274
});
1283-
addEvent(".node", "click", async e => {
1275+
this.shadeAll();
1276+
addEvent(".node", "mouseover", async e => {
12841277
e.preventDefault();
12851278
e.stopPropagation();
1279+
d3.selectAll("g").attr("cursor", "pointer");
12861280
12871281
this.g = e.currentTarget;
12881282
this.nodeName = this.g.children[0].innerHTML.trim();
12891283
this.shadeAll();
12901284
this.colorNode(this.nodeName);
1291-
// d3.selectAll("g").attr("stroke", "");
1292-
// d3.select(g).attr("stroke", "red");
1285+
});
1286+
addEvent(".node", "click", async e => {
12931287
this.isLayerSelected = this.layers.find(_ => _.name === this.nodeName);
12941288
this.renderRightPanels();
12951289
});
1296-
addEvent(".node", "mouseover", e => {
1297-
e.preventDefault();
1298-
e.stopPropagation();
1299-
d3.selectAll("g").attr("cursor", "pointer");
1300-
});
13011290
},
13021291
renderRightPanels() {
13031292
if (!this.nodeName) return;

cmdb-ui/src/pages/home-page.vue

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as d3 from "d3-selection";
77
import * as d3Graphviz from "d3-graphviz";
88
import { getAllLayers, getAllCITypesByLayerWithAttr } from "@/api/server";
99
import { setHeaders } from "@/api/base.js";
10+
import { addEvent } from "./util/event.js";
1011
export 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

Comments
 (0)