Skip to content

Commit 6946fc4

Browse files
authored
Merge pull request #74 from khushi-parikh/main
Changing card data when right clicking on a node
2 parents e9eeec6 + 8baf854 commit 6946fc4

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

frontend/family_tree/src/App.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useLayoutEffect, useState } from "react";
22
import './App.css';
33
import Help from './Components/Help.js';
44
import SearchBar from "./Components/SearchBar";
@@ -17,7 +17,7 @@ function App() {
1717
}
1818
});
1919

20-
const x = StudentData[0];
20+
const [details, setDetails] = useState({ name:"name", branch:"branch", year:"year", email:"email", picture:"picture", linkedIn:"", hometown:"", coCurriculars:"", socialMedia:"", display:true});
2121

2222
return (
2323
<ThemeProvider theme={theme}>
@@ -27,20 +27,21 @@ function App() {
2727
<Help />
2828
</div>
2929

30-
<D3Tree />
30+
<D3Tree
31+
setDetails = {setDetails}
32+
/>
3133

32-
<PCard
33-
id={x.student.id}
34-
branch={x.student.branch}
35-
name={x.student.name}
36-
year={x.student.year}
37-
email={x.student.email}
38-
picture={x.student.picture}
39-
linkedIn={x.student.linkedIn}
40-
hometown={x.student.hometown}
41-
coCurriculars={x.student.coCurriculars}
42-
socialMedia={x.student.socialMedia}
43-
display= {true}
34+
<PCard
35+
branch={details.branch}
36+
name={details.name}
37+
year={details.year}
38+
email={details.email}
39+
picture={details.picture}
40+
linkedIn={details.linkedIn}
41+
hometown={details.hometown}
42+
coCurriculars={details.coCurriculars}
43+
socialMedia={details.socialMedia}
44+
display= {details.display}
4445
/>
4546
</div>
4647
</ThemeProvider>

frontend/family_tree/src/Components/Tree.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as d3 from 'd3';
22
import StudentData from "../Data1.json";
33
import React, { useLayoutEffect } from "react";
44

5-
function D3Tree(){
5+
function D3Tree(props){
66
useLayoutEffect(() =>{
77
var width = window.innerWidth;
88
var height = window.innerHeight;
@@ -56,7 +56,20 @@ function D3Tree(){
5656
.attr("transform", function(d) {
5757
return "translate(" + source.x0 + "," + source.y0 + ")";
5858
})
59-
.on('click', click);
59+
.on('click', click)
60+
.on('contextmenu', function(node,d){
61+
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,
70+
display: true
71+
});
72+
});
6073

6174
nodeEnter.append('circle')
6275
.attr('class', 'node')
@@ -155,7 +168,7 @@ function D3Tree(){
155168
update(node);
156169
}
157170
}
158-
})
171+
},[])
159172

160173
return(
161174
<div id="tree"></div>

frontend/family_tree/src/Data1.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"picture": "url",
4040
"linkedIn": "url",
4141
"hometown": "Jammu",
42-
"coCurriculars": [],
42+
"coCurriculars": ["PClub head","Branch topper","6-star coder"],
4343
"socialMedia": { "insta": "link" }
4444
},
4545
"parent": "Root"
@@ -218,7 +218,7 @@
218218
"email": "dummy@gmail.com",
219219
"picture": "url",
220220
"linkedIn": "url",
221-
"hometown": "",
221+
"hometown": "Gujarat",
222222
"coCurriculars": [],
223223
"socialMedia": { "insta": "link" }
224224
},

0 commit comments

Comments
 (0)