diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-07-17 13:53:31 +0200 |
---|---|---|
committer | Thomas F. K. Jorna <[email protected]> | 2021-07-17 13:53:31 +0200 |
commit | 9b46f1da6cc37204bc54913f95ef31cf879d4881 (patch) | |
tree | 4ed6cd58fa25f2d9c22ef20d9301728a5d06e531 | |
parent | dc81675878b92c12ab868804adc8afc35ab04e20 (diff) |
trying to pass the node ids to graph
-rw-r--r-- | app/components/graph/graph.tsx | 3 | ||||
-rw-r--r-- | app/screens/graph/graph-screen.tsx | 15 |
2 files changed, 11 insertions, 7 deletions
diff --git a/app/components/graph/graph.tsx b/app/components/graph/graph.tsx index 94a4fe1..e179cb9 100644 --- a/app/components/graph/graph.tsx +++ b/app/components/graph/graph.tsx @@ -30,13 +30,14 @@ export interface GraphProps { style?: StyleProp<ViewStyle> physics gData + nodeIds: string[] } /** * Describe your component here */ export const Graph = observer(function Graph(props: GraphProps): JSX.Element { - const { style, physics, gData } = props + const { style, physics, gData, nodeIds } = props const styles = flatten([CONTAINER, style]) const fgRef = useRef() 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 ( <Screen style={ROOT} preset="scroll"> <Tweaks physics={physics} setPhysics={setPhysics} /> - <Graph physics={physics} gData={graphData} /> + <Graph physics={physics} gData={graphData} nodeIds={nodeIds}/> </Screen> ) } |