From ad5aa2cd4985f9d22b354a7dc49d107015f096ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katharina=20W=C3=BCnsche?= Date: Mon, 9 Sep 2024 14:42:44 +0200 Subject: [PATCH] feat: add filter option to network --- components/networkVisualization.vue | 81 +++++++++++++++++------------ messages/de.json | 3 +- messages/en.json | 3 +- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/components/networkVisualization.vue b/components/networkVisualization.vue index de4ccd4..647e82a 100644 --- a/components/networkVisualization.vue +++ b/components/networkVisualization.vue @@ -2,7 +2,7 @@ import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "@headlessui/vue"; import { useQuery } from "@tanstack/vue-query"; import type { LinkObject } from "force-graph"; -import { Check, ChevronDown } from "lucide-vue-next"; +import { Check, ChevronDown, Share2 } from "lucide-vue-next"; import { bgColors, colorCodes } from "@/lib/colors"; import { loadNetworkData } from "@/lib/load-network-data"; @@ -27,7 +27,8 @@ const { data, isLoading } = useQuery({ }, }), }); -function getGraph(data: Array) { + +function getGraph(data: Array, minDegree = 0) { let graph = { nodes: [] as Array<{ id: string; @@ -39,21 +40,23 @@ function getGraph(data: Array) { links: [] as Array, }; data.forEach((entity) => { - graph.nodes.push({ - id: String(entity.id), - name: entity.name, - val: entity.related_to.length, - color: colorCodes[entity.type], - class: entity.type, - }); + if (entity.related_to.length >= minDegree) + graph.nodes.push({ + id: String(entity.id), + name: entity.name, + val: entity.related_to.length, + color: colorCodes[entity.type], + class: entity.type, + }); }); const edgeDict: Record> = {}; data.flatMap((entity) => { - entity.related_to.forEach((target) => { - if (entity.id < target) return; - if (!(String(target) in edgeDict)) edgeDict[String(target)] = []; - edgeDict[String(target)]?.push(`${entity.id}-${String(target)}`); - }); + if (entity.related_to.length >= minDegree) + entity.related_to.forEach((target) => { + if (entity.id < target) return; + if (!(String(target) in edgeDict)) edgeDict[String(target)] = []; + edgeDict[String(target)]?.push(`${entity.id}-${String(target)}`); + }); }); const flattenedEdges = [ ...new Set( @@ -68,38 +71,26 @@ function getGraph(data: Array) { }); return graph; } -const graph = computed(() => getGraph(data.value ?? [])); +const minDegree = ref(1); +const maxDegree = computed(() => + Math.min(Math.max(...(data.value?.map((node) => node.related_to.length) ?? [1])), 10), +); +const graph = computed(() => getGraph(data.value ?? [], minDegree.value));