From f98c5ae62ace4c133f5930613d9b0ba8ba9ee59c Mon Sep 17 00:00:00 2001 From: Qiuxia Fan Date: Thu, 10 Feb 2022 16:15:31 +0800 Subject: [PATCH] feat: add legend and metrics --- src/styles/lib.scss | 6 +++-- .../dashboard/related/topology/Graph.vue | 25 ++++++++++--------- .../related/topology/utils/nodeElement.ts | 22 +++++++++++++--- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/styles/lib.scss b/src/styles/lib.scss index e49087a4..63310205 100644 --- a/src/styles/lib.scss +++ b/src/styles/lib.scss @@ -95,6 +95,10 @@ background-color: #a7aebb; } +.mb-5 { + margin-bottom: 5px; +} + .ml-5 { margin-left: 5px; } @@ -129,11 +133,9 @@ @keyframes loading { 0% { transform: rotate(0deg); - transform: rotate(0deg); } to { transform: rotate(1turn); - transform: rotate(1turn); } } diff --git a/src/views/dashboard/related/topology/Graph.vue b/src/views/dashboard/related/topology/Graph.vue index f7789520..09271f8b 100644 --- a/src/views/dashboard/related/topology/Graph.vue +++ b/src/views/dashboard/related/topology/Graph.vue @@ -25,21 +25,13 @@ import { simulationInit, simulationSkip } from "./utils/simulation"; import nodeElement from "./utils/nodeElement"; import { linkElement, anchorElement, arrowMarker } from "./utils/linkElement"; // import tool from "./utils/tool"; -// import topoLegend from "./utils/legend"; +import topoLegend from "./utils/legend"; import { Node, Call } from "@/types/topology"; import { useTopologyStore } from "@/store/modules/topology"; import { useDashboardStore } from "@/store/modules/dashboard"; import { EntityType } from "../../data"; -/*global defineProps, Nullable */ -// const props = defineProps({ -// current: { -// type: Object as PropType<{ [key: string]: number[] }>, -// default: () => ({}), -// }, -// nodes: { type: Array as PropType, default: () => [] }, -// links: { type: Array as PropType, default: () => [] }, -// }); +/*global Nullable */ const { t } = useI18n(); const topologyStore = useTopologyStore(); const dashboardStore = useDashboardStore(); @@ -55,6 +47,7 @@ const link = ref(null); const anchor = ref(null); const arrow = ref(null); const tools = ref(null); +const legend = ref(null); onMounted(async () => { await getTopology(); @@ -87,6 +80,13 @@ onMounted(async () => { // { icon: "ENDPOINT", click: handleGoEndpointDependency }, // { icon: "" }, // ]); + // legend + legend.value = graph.value.append("g").attr("class", "topo-legend"); + topoLegend(legend.value, height.value, width.value); + svg.value.on("click", (event: any) => { + event.stopPropagation(); + event.preventDefault(); + }); }); async function getTopology() { switch (dashboardStore.entity) { @@ -173,7 +173,8 @@ function update() { dragended: dragended, handleNodeClick: handleNodeClick, }, - tip.value + tip.value, + t ).merge(node.value); // line element link.value = link.value.data(topologyStore.calls, (d: Call) => d.id); @@ -196,7 +197,7 @@ function update() { }
${t( "detectPoint" - )}:${data.detectPoints.join(" | ")}
+ )}: ${data.detectPoints.join(" | ")} `, }, tip.value diff --git a/src/views/dashboard/related/topology/utils/nodeElement.ts b/src/views/dashboard/related/topology/utils/nodeElement.ts index 34b0a73c..cabdd942 100644 --- a/src/views/dashboard/related/topology/utils/nodeElement.ts +++ b/src/views/dashboard/related/topology/utils/nodeElement.ts @@ -15,9 +15,17 @@ * limitations under the License. */ import icons from "./icons"; +import { Node } from "@/types/topology"; icons["KAFKA-CONSUMER"] = icons.KAFKA; -export default (d3: any, graph: any, tool: any, funcs: any, tip: any) => { +export default ( + d3: any, + graph: any, + tool: any, + funcs: any, + tip: any, + t: any +) => { const nodeEnter = graph .append("g") .call( @@ -27,10 +35,18 @@ export default (d3: any, graph: any, tool: any, funcs: any, tip: any) => { .on("drag", funcs.dragged) .on("end", funcs.dragended) ) - .on("mouseover", function (event: any, d: { name: string }) { + .on("mouseover", function (event: any, d: Node) { tip .html(() => { - return `
${d.name}
`; + return ` +
${t("cpm")}: ${ + d.cpm + }
+
${t("latency")}: ${ + d.latency + }
+
${t("sla")}: ${d.sla}
+ `; }) .show(d, this); })