diff --git a/src/types/topology.d.ts b/src/types/topology.d.ts index d3c5f14c..ff87c5e9 100644 --- a/src/types/topology.d.ts +++ b/src/types/topology.d.ts @@ -46,6 +46,7 @@ export interface Node { layer?: string; serviceName?: string; height?: number; + width?: number; x?: number; y?: number; level?: number; diff --git a/src/views/dashboard/related/topology/components/Graph.vue b/src/views/dashboard/related/topology/components/Graph.vue index 10b14a82..6ba2e68c 100644 --- a/src/views/dashboard/related/topology/components/Graph.vue +++ b/src/views/dashboard/related/topology/components/Graph.vue @@ -37,7 +37,7 @@ limitations under the License. --> {{ n.name.length > 20 ? `${n.name.substring(0, 20)}...` : n.name }} @@ -78,7 +78,7 @@ limitations under the License. --> import type { Node, Call } from "@/types/topology"; import { useDashboardStore } from "@/store/modules/dashboard"; import icons from "@/assets/img/icons"; - import { layout, changeNode, computeLevels } from "./utils/layout"; + import { changeNode, computeLevels, hierarchy } from "./utils/layout"; import zoom from "@/views/dashboard/related/components/utils/zoom"; /*global Nullable, defineProps */ @@ -110,7 +110,7 @@ limitations under the License. --> const graphWidth = ref(100); const currentNode = ref>(null); const diff = computed(() => [(width.value - graphWidth.value - 120) / 2, 0]); - const radius = 8; + const radius = 4; async function init() { const dom = document.querySelector(".hierarchy-related")?.getBoundingClientRect() || { @@ -129,7 +129,7 @@ limitations under the License. --> function draw() { const levels = computeLevels(props.calls, props.nodes, []); - topologyLayout.value = layout(levels, props.calls, radius); + topologyLayout.value = hierarchy(levels, props.calls, radius); graphWidth.value = topologyLayout.value.layout.width; const drag: any = d3.drag().on("drag", (d: { x: number; y: number }) => { topologyLayout.value.calls = changeNode(d, currentNode.value, topologyLayout.value, radius); diff --git a/src/views/dashboard/related/topology/components/utils/layout.ts b/src/views/dashboard/related/topology/components/utils/layout.ts index d0a20fde..d1a417c1 100644 --- a/src/views/dashboard/related/topology/components/utils/layout.ts +++ b/src/views/dashboard/related/topology/components/utils/layout.ts @@ -227,3 +227,46 @@ export function changeNode(d: { x: number; y: number }, currentNode: Nullable l.forEach((n: any) => n && (n.level = i))); + + const nodes: Node[] = levels.reduce((a, x) => a.concat(x), []); + // layout + const padding = 30; + const node_height = 120; + const node_width = 100; + const bundle_width = 14; + const metro_d = 4; + for (const n of nodes) { + n.width = 5 * metro_d; + } + + let y_offset = padding; + let x_offset = 0; + for (const level of levels) { + x_offset = 0; + y_offset += 5 * bundle_width; + for (const l of level) { + const n: any = l; + for (const call of calls) { + if (call.source === n.id) { + call.sourceObj = n; + } + if (call.target === n.id) { + call.targetObj = n; + } + } + n.x = node_width + x_offset + n.width / 2; + n.y = n.level * node_height + y_offset; + x_offset += node_height + n.width; + } + } + const layout = { + width: d3.max(nodes as any, (n: { x: number }) => n.x) || 0 + node_width + 2 * padding, + height: d3.max(nodes as any, (n: { y: number }) => n.y) || 0 + node_height / 2 + 2 * padding, + }; + + return { nodes, layout, calls: computeCallPos(calls, radius) }; +}