From 6de4b3a6f24c5ff9d29e014589414cfecdb37b00 Mon Sep 17 00:00:00 2001
From: "Thomas F. K. Jorna" <thomasfkjorna@gmail.com>
Date: Sat, 17 Jul 2021 19:49:39 +0200
Subject: implemented hover

---
 app/screens/graph/graph-screen.tsx | 106 ++++++++++++++++++++++---------------
 1 file changed, 64 insertions(+), 42 deletions(-)

(limited to 'app/screens/graph/graph-screen.tsx')

diff --git a/app/screens/graph/graph-screen.tsx b/app/screens/graph/graph-screen.tsx
index 6fa7539..6a01927 100644
--- a/app/screens/graph/graph-screen.tsx
+++ b/app/screens/graph/graph-screen.tsx
@@ -94,50 +94,72 @@ export const GraphScreen = observer(function GraphScreen() {
   // Get previous settings and the data from the org-roam-server
   const sanitizeGraph = (data, nodeIds: string[]) => {
     const cleanLinks = [];
-    data.links.forEach((link, i) => {
-        for (i=0; i<=nodeIds.length; i++){
-        if (link.target === nodeIds[i]) {
+    data.links.forEach((link) => {
+        let target;
+        let source;
+      for (let i = 0; i < nodeIds.length; i++) {
+            let a = data.nodes[i];
+            !a.neighbors && (a.neighbors = []);
+            !a.links && (a.links = []);
+          if (link.target === nodeIds[i]) {
+            //let a = data.nodes[i];
+            //!a.neighbors && (a.neighbors = []);
+            //a.neighbors.push(a);
+            a.links.push(link);
+            target=[a, i];
           cleanLinks.push(link);
-          break;
-        };
+          } else if (link.source === nodeIds[i]) {
+            //let a = data.nodes[i];
+            //!a.neighbors && (a.neighbors = []);
+            //a.neighbors.push(a);
+            a.links.push(link);
+            source=[a, i];
+          };
       };
+        if (target && source) {
+            console.log(link);
+            console.log("target" + target);
+            console.log("source" + source);
+           data.nodes[target[1]].neighbors.push(source[0]);
+           data.nodes[source[1]].neighbors.push(target[0]);
+        }
     });
-      console.log(cleanLinks);
-      data.links = cleanLinks;
-      return data;
-    };
+    console.log(cleanLinks);
+    data.links = cleanLinks;
+    return data;
+  };
 
-    const getNodesById = (data) => {
-        let temp = [];
-        data.nodes.forEach(node => temp.push(node.id));
-        setNodeIds(temp);
-        return temp;
-    };
+  const getNodesById = (data) => {
+    let temp = [];
+    data.nodes.forEach(node => temp.push(node.id));
+    setNodeIds(temp);
+    return temp;
+  };
 
-    useEffect(() => {
-      getData().then((data) => setPhysics(data));
-      axios.get("http://localhost:35901/graph")
-        .then((dataa) => {
-          let nods = getNodesById(dataa.data);
-          setNodeIds(nods);
-          console.log(nodeIds);
-          let cleanData = sanitizeGraph(dataa.data, nods);
-          console.log(cleanData)
-          setGraphData(cleanData);
-        })
-        .catch((e) => {
-          console.log(e);
-          console.log("Couldn't get data.");
-          //setGraphData(rando);
-        });
-    }, [])
-    if (!graphData) { return null }
-    else {
-      return (
-        <Screen style={ROOT} preset="scroll">
-          <Tweaks physics={physics} setPhysics={setPhysics} />
-          <Graph physics={physics} gData={graphData} nodeIds={nodeIds}/>
-        </Screen>
-      )
-    }
-  })
+  useEffect(() => {
+    getData().then((data) => setPhysics(data));
+    axios.get("http://localhost:35901/graph")
+      .then((dataa) => {
+        let nods = getNodesById(dataa.data);
+        setNodeIds(nods);
+        console.log(nodeIds);
+        let cleanData = sanitizeGraph(dataa.data, nods);
+        console.log(cleanData)
+        setGraphData(cleanData);
+      })
+      .catch((e) => {
+        console.log(e);
+        console.log("Couldn't get data.");
+        //setGraphData(rando);
+      });
+  }, [])
+  if (!graphData) { return null }
+  else {
+    return (
+      <Screen style={ROOT} preset="scroll">
+        <Tweaks physics={physics} setPhysics={setPhysics} />
+        <Graph physics={physics} gData={graphData} nodeIds={nodeIds} />
+      </Screen>
+    )
+  }
+})
-- 
cgit v1.2.3

