From 9b46f1da6cc37204bc54913f95ef31cf879d4881 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Sat, 17 Jul 2021 13:53:31 +0200 Subject: trying to pass the node ids to graph --- app/screens/graph/graph-screen.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'app/screens/graph') diff --git a/app/screens/graph/graph-screen.tsx b/app/screens/graph/graph-screen.tsx index 9f1f08c..1c91721 100644 --- a/app/screens/graph/graph-screen.tsx +++ b/app/screens/graph/graph-screen.tsx @@ -32,6 +32,7 @@ export const GraphScreen = observer(function GraphScreen() { const [physics, setPhysics] = useState({}) const [graphData, setGraphData] = useState(); + const [nodeIds, setNodeIds] = useState([]); // { "nodes": [{ "id": 1 }, { "id": 2 }], "links": [{ "target": 1, "source": 2 }] }); const physicsInit = { charge: -30, @@ -105,18 +106,20 @@ export const GraphScreen = observer(function GraphScreen() { }; const getNodesById = (data) => { - const nodeIds: string[] = []; - data.nodes.forEach(node => nodeIds.push(node.id)); - return nodeIds; + 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) => { - const nodeIds = getNodesById(dataa.data); + let nods = getNodesById(dataa.data); + setNodeIds(nods); console.log(nodeIds); - const cleanData = sanitizeGraph(dataa.data, nodeIds); + let cleanData = sanitizeGraph(dataa.data, nods); console.log(cleanData) setGraphData(cleanData); }) @@ -131,7 +134,7 @@ export const GraphScreen = observer(function GraphScreen() { return ( - + ) } -- cgit v1.2.3