Skip to content

Commit d7036a7

Browse files
committed
created a method to render path of a node
1 parent 94dc473 commit d7036a7

File tree

5 files changed

+307
-290
lines changed

5 files changed

+307
-290
lines changed

frontend/family_tree/src/App.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import React, { useLayoutEffect, useState } from "react";
1+
import React, { useEffect, useState } from "react";
22
import './App.css';
33
import Help from './Components/Help.js';
44
import SearchBar from "./Components/SearchBar";
55
import StudentData from "./Data.json";
66
import PCard from "./Components/ProfileCard.js";
77
import { ThemeProvider, createTheme } from "@material-ui/core";
88
import D3Tree from "./Components/Tree";
9+
import {client} from "./index.js";
10+
import {CHILDREN_QUERY, BATCH_QUERY, PATH_QUERY} from "./Queries.js";
911

1012
function App() {
1113

@@ -18,6 +20,22 @@ function App() {
1820
});
1921

2022
const [details, setDetails] = useState({ name:"name", branch:"branch", year:"year", email:"email", picture:"picture", linkedIn:"", hometown:"", coCurriculars:"", socialMedia:"", display:true});
23+
const [TreeData, setTreeData] = useState({});
24+
25+
async function FetchPath(rollNo) {
26+
const response = await client.query({
27+
query: PATH_QUERY,
28+
variables: {
29+
rollNo,
30+
},
31+
})
32+
return response.data.studentPath;
33+
}
34+
35+
useEffect(() => {
36+
(FetchPath("B20AI054")).then(value => {setTreeData(value);})
37+
, [TreeData]})
38+
2139

2240
return (
2341
<ThemeProvider theme={theme}>
@@ -26,10 +44,11 @@ function App() {
2644
<div className="help">
2745
<Help />
2846
</div>
29-
47+
{TreeData[0] &&
3048
<D3Tree
49+
TreeData = {TreeData}
3150
setDetails = {setDetails}
32-
/>
51+
/>}
3352

3453
<PCard
3554
branch={details.branch}

frontend/family_tree/src/Components/Tree.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ function D3Tree(props){
1414
}))
1515
.append("g")
1616
.attr("transform", "translate(" + width/2 + "," + height/3 + ")");
17-
var data = StudentData;
17+
var data = props.TreeData;
1818

1919
var treemap = d3.tree().size([height,width]).nodeSize([120, 40]);
2020

21-
var stratify = d3.stratify().id(d=>d.student.name).parentId(d=>d.parent) ;
21+
var stratify = d3.stratify().id(d=>d.rollNo).parentId(d=>d.parentId) ;
2222
var root = stratify(data);
2323

2424
var i = 0;
@@ -27,7 +27,8 @@ function D3Tree(props){
2727
root.x0 = height / 2;
2828
root.y0 = 0;
2929

30-
root.children.forEach(collapse);
30+
if(root.children){
31+
root.children.forEach(collapse);}
3132
function collapse(d) {
3233
if(d.children) {
3334
d._children = d.children
@@ -59,14 +60,14 @@ function D3Tree(props){
5960
.on('click', click)
6061
.on('contextmenu', function(node,d){
6162
props.setDetails({name: d.id,
62-
branch: d.data.student.branch,
63-
year: d.data.student.year,
64-
email: d.data.student.email,
65-
picture: d.data.student.picture,
66-
linkedIn: d.data.student.linkedIn,
67-
hometown: d.data.student.hometown,
68-
coCurriculars: d.data.student.coCurriculars,
69-
socialMedia: d.data.student.socialMedia,
63+
branch: d.data.branch,
64+
year: d.data.year,
65+
email: d.data.email,
66+
picture: d.data.picture,
67+
linkedIn: d.data.linkedIn,
68+
hometown: d.data.hometown,
69+
coCurriculars: d.data.coCurriculars,
70+
socialMedia: d.data.socialMedia,
7071
display: true
7172
});
7273
});

0 commit comments

Comments
 (0)