From 6a6cc7a29b1067b20bc923bd4482e9b23709d943 Mon Sep 17 00:00:00 2001 From: Fine Date: Wed, 17 Aug 2022 17:29:05 +0800 Subject: [PATCH] draw anchor --- src/store/modules/network-profiling.ts | 1 - .../components/Graph/linkProcess.ts | 38 +- .../components/ProcessTopology.vue | 45 +-- .../network-profiling/components/backup.vue | 343 ------------------ 4 files changed, 51 insertions(+), 376 deletions(-) delete mode 100644 src/views/dashboard/related/network-profiling/components/backup.vue diff --git a/src/store/modules/network-profiling.ts b/src/store/modules/network-profiling.ts index eda6338d..2a5b36ee 100644 --- a/src/store/modules/network-profiling.ts +++ b/src/store/modules/network-profiling.ts @@ -96,7 +96,6 @@ export const networkProfilingStore = defineStore({ delete d.targetObj; return d; }); - console.log(calls); this.calls = calls; this.nodes = data.nodes; }, diff --git a/src/views/dashboard/related/network-profiling/components/Graph/linkProcess.ts b/src/views/dashboard/related/network-profiling/components/Graph/linkProcess.ts index 0fe644ad..9581803b 100644 --- a/src/views/dashboard/related/network-profiling/components/Graph/linkProcess.ts +++ b/src/views/dashboard/related/network-profiling/components/Graph/linkProcess.ts @@ -20,12 +20,12 @@ export const linkElement = (graph: any) => { .append("path") .attr("class", "topo-call") .attr("marker-end", "url(#arrow)") - .attr("stroke", "#afc4dd") + .attr("stroke", "#bbb") .attr("d", (d: any) => { const controlPos = computeControlPoint( [d.source.x, d.source.y - 5], [d.target.x, d.target.y - 5], - 1 + 0.5 ); return ( "M" + @@ -50,7 +50,21 @@ export const anchorElement = (graph: any, funcs: any, tip: any) => { .append("circle") .attr("class", "topo-line-anchor") .attr("r", 5) - .attr("fill", "#217EF25f") + .attr("fill", "#ccc") + .attr("transform", (d: any) => { + const controlPos = computeControlPoint( + [d.source.x, d.source.y - 5], + [d.target.x, d.target.y - 5], + 0.5 + ); + const p = quadraticBezier( + 0.5, + { x: d.source.x, y: d.source.y - 5 }, + { x: controlPos[0], y: controlPos[1] }, + { x: d.target.x, y: d.target.y - 5 } + ); + return `translate(${p[0]}, ${p[1]})`; + }) .on("mouseover", function (event: unknown, d: unknown) { tip.html(funcs.tipHtml).show(d, this); }) @@ -69,17 +83,18 @@ export const arrowMarker = (graph: any) => { .attr("id", "arrow") .attr("class", "topo-line-arrow") .attr("markerUnits", "strokeWidth") - .attr("markerWidth", "6") - .attr("markerHeight", "6") + .attr("markerWidth", "8") + .attr("markerHeight", "8") .attr("viewBox", "0 0 12 12") .attr("refX", "10") .attr("refY", "6") .attr("orient", "auto"); const arrowPath = "M2,2 L10,6 L2,10 L6,6 L2,2"; - arrow.append("path").attr("d", arrowPath).attr("fill", "#afc4dd"); + arrow.append("path").attr("d", arrowPath).attr("fill", "#bbb"); return arrow; }; +// Control Point coordinates of quadratic Bezier curve function computeControlPoint(ps: number[], pe: number[], arc = 0.5) { const deltaX = pe[0] - ps[0]; const deltaY = pe[1] - ps[1]; @@ -91,3 +106,14 @@ function computeControlPoint(ps: number[], pe: number[], arc = 0.5) { (ps[1] + pe[1]) / 2 + len * Math.sin(newTheta), ]; } +// Point coordinates of quadratic Bezier curve +function quadraticBezier( + t: number, + ps: { x: number; y: number }, + pc: { x: number; y: number }, + pe: { x: number; y: number } +) { + const x = (1 - t) * (1 - t) * ps.x + 2 * t * (1 - t) * pc.x + t * t * pe.x; + const y = (1 - t) * (1 - t) * ps.y + 2 * t * (1 - t) * pc.y + t * t * pe.y; + return [x, y]; +} diff --git a/src/views/dashboard/related/network-profiling/components/ProcessTopology.vue b/src/views/dashboard/related/network-profiling/components/ProcessTopology.vue index 866fd321..80762e8d 100644 --- a/src/views/dashboard/related/network-profiling/components/ProcessTopology.vue +++ b/src/views/dashboard/related/network-profiling/components/ProcessTopology.vue @@ -87,7 +87,7 @@ async function init() { return; } drawGraph(); - update(); + drawTopology(); } function drawGraph() { @@ -149,7 +149,7 @@ function createPolygon(radius: number, sides = 6, offset = 0) { return poly; } -function update() { +function drawTopology() { if (!node.value || !link.value) { return; } @@ -254,30 +254,23 @@ function update() { link.value = link.value.data(calls, (d: Call) => d.id); link.value.exit().remove(); link.value = linkElement(link.value.enter()).merge(link.value); - // anchorElement - // anchor.value = anchor.value.data( - // networkProfilingStore.calls, - // (d: Call) => d.id - // ); - // anchor.value.exit().remove(); - // anchor.value = anchorElement( - // anchor.value.enter(), - // { - // handleLinkClick: handleLinkClick, - // tipHtml: (data: Call) => { - // const html = `
${t( - // "detectPoint" - // )}:${data.detectPoints.join(" | ")}
`; - // return html; - // }, - // }, - // tip.value - // ).merge(anchor.value); + anchor.value = anchor.value.data(calls, (d: Call) => d.id); + anchor.value.exit().remove(); + anchor.value = anchorElement( + anchor.value.enter(), + { + handleLinkClick: handleLinkClick, + tipHtml: (data: Call) => { + const html = `
${t( + "detectPoint" + )}:${data.detectPoints.join(" | ")}
`; + return html; + }, + }, + tip.value + ).merge(anchor.value); // arrow marker - arrow.value = arrow.value.data( - networkProfilingStore.calls, - (d: Call) => d.id - ); + arrow.value = arrow.value.data(calls, (d: Call) => d.id); arrow.value.exit().remove(); arrow.value = arrowMarker(arrow.value.enter()).merge(arrow.value); } @@ -351,7 +344,7 @@ async function freshNodes() { return; } drawGraph(); - update(); + drawTopology(); } watch( () => networkProfilingStore.nodes, diff --git a/src/views/dashboard/related/network-profiling/components/backup.vue b/src/views/dashboard/related/network-profiling/components/backup.vue deleted file mode 100644 index 812d65dc..00000000 --- a/src/views/dashboard/related/network-profiling/components/backup.vue +++ /dev/null @@ -1,343 +0,0 @@ - - - -