Skip to content

Commit 9e1158f

Browse files
author
a19hu
committed
fix:commit and remove all the commit
1 parent e377dd8 commit 9e1158f

File tree

6 files changed

+666
-0
lines changed

6 files changed

+666
-0
lines changed

frontend/family_tree/src/App.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import React, { useEffect, useState } from "react";
2+
import './App.css';
3+
import Help from './Components/Help.js';
4+
import SearchBar from "./Components/SearchBar";
5+
import StudentData from "./Data.json";
6+
import PCard from "./Components/ProfileCard.js";
7+
import { ThemeProvider, createTheme } from "@material-ui/core";
8+
import D3Tree from "./Components/Tree";
9+
import {client} from "./index.js";
10+
<<<<<<< HEAD
11+
import {CHILDREN_QUERY, BATCH_QUERY, PATH_QUERY} from "./Queries.js";
12+
=======
13+
import {PATH_QUERY, ALL_QUERY} from "./Queries.js";
14+
>>>>>>> a052d25 (added method to show search suggestions)
15+
16+
function App() {
17+
18+
const theme = createTheme({
19+
palette: {
20+
primary: {
21+
main: "#2a4158"
22+
}
23+
}
24+
});
25+
26+
const [details, setDetails] = useState({ name:"name", branch:"branch", year:"year", email:"email", picture:"picture", linkedIn:"", hometown:"", coCurriculars:"", socialMedia:"", display:true});
27+
const [TreeData, setTreeData] = useState({});
28+
const [SearchData, setSearchData] = useState({});
29+
30+
async function FetchPath(rollNo) {
31+
const response = await client.query({
32+
query: PATH_QUERY,
33+
variables: {
34+
rollNo,
35+
},
36+
})
37+
return response.data.studentPath;
38+
}
39+
40+
async function FetchAll() {
41+
const response = await client.query({
42+
query: ALL_QUERY,
43+
})
44+
return response.data.students;
45+
}
46+
47+
useEffect(() => {
48+
(FetchAll())
49+
.then(value => {setSearchData(value);})
50+
, []})
51+
52+
useEffect(() => {
53+
(FetchPath("B20AI054")).then(value => {setTreeData(value);})
54+
, [TreeData]})
55+
56+
57+
return (
58+
<ThemeProvider theme={theme}>
59+
<div className="App">
60+
<<<<<<< HEAD
61+
<SearchBar placeholder="Enter the Name or Roll Number..." studentData={StudentData} />
62+
=======
63+
<SearchBar placeholder="Enter the Name or Roll Number..." studentData={SearchData} />
64+
>>>>>>> a052d25 (added method to show search suggestions)
65+
<div className="help">
66+
<Help />
67+
</div>
68+
{TreeData[0] &&
69+
<D3Tree
70+
TreeData = {TreeData}
71+
setDetails = {setDetails}
72+
/>}
73+
74+
<PCard
75+
branch={details.branch}
76+
name={details.name}
77+
year={details.year}
78+
email={details.email}
79+
picture={details.picture}
80+
linkedIn={details.linkedIn}
81+
hometown={details.hometown}
82+
coCurriculars={details.coCurriculars}
83+
socialMedia={details.socialMedia}
84+
display= {details.display}
85+
/>
86+
</div>
87+
</ThemeProvider>
88+
);
89+
}
90+
91+
export default App;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, { useState } from "react";
2+
import "../Styles/SearchBar.css";
3+
import SearchIcon from "@material-ui/icons/Search";
4+
import CloseIcon from "@material-ui/icons/Close"
5+
6+
function SearchBar({ placeholder, studentData }) {
7+
const [filteredData, setFilteredData] = useState([]);
8+
const [wordEntered, setWordEntered] = useState("");
9+
10+
const handleFilter = (event) => {
11+
const searchWord = event.target.value;
12+
setWordEntered(searchWord);
13+
if (searchWord.length < 3) {
14+
setFilteredData([]);
15+
} else {
16+
const filteredResults = studentData.filter((query) => {
17+
return query.name.toLowerCase().includes(searchWord.toLowerCase()) + query.rollNo.toLowerCase().includes(searchWord.toLowerCase());
18+
});
19+
setFilteredData(filteredResults);
20+
}
21+
};
22+
23+
const clearState = () => {
24+
setFilteredData([]);
25+
setWordEntered("");
26+
};
27+
28+
return (
29+
<div className="search">
30+
<div className="searchInputs">
31+
<input
32+
type="text"
33+
placeholder={placeholder}
34+
value={wordEntered}
35+
onChange={handleFilter}
36+
/>
37+
<div className="searchIcon">
38+
{wordEntered.length === 0 ? (
39+
<SearchIcon />
40+
) : (
41+
<CloseIcon id="clearBtn" onClick={clearState} />
42+
)}
43+
</div>
44+
</div>
45+
{filteredData.length !== 0 && (
46+
<div className="dataResult">
47+
{filteredData.slice(0, 5).map((value) => {
48+
return (
49+
<p className="dataItem">{`${value.name} (${value.rollNo})`} </p>
50+
);
51+
})}
52+
</div>
53+
)}
54+
</div>
55+
);
56+
}
57+
58+
export default SearchBar;
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
import * as d3 from 'd3';
2+
import StudentData from "../Data1.json";
3+
import React, { useLayoutEffect } from "react";
4+
5+
function D3Tree(props){
6+
useLayoutEffect(() =>{
7+
var width = window.innerWidth;
8+
var height = window.innerHeight;
9+
10+
var svg = d3.select("#tree")
11+
.append("svg").attr("width", width).attr("height", height)
12+
.call(d3.zoom().on("zoom", function (event) {
13+
svg.attr("transform", event.transform)
14+
}))
15+
.append("g")
16+
.attr("transform", "translate(" + width/2 + "," + height/3 + ")");
17+
var data = props.TreeData;
18+
19+
var treemap = d3.tree().size([height,width]).nodeSize([120, 40]);
20+
21+
var stratify = d3.stratify().id(d=>d.rollNo).parentId(d=>d.parentId) ;
22+
var root = stratify(data);
23+
24+
var i = 0;
25+
var duration = 750;
26+
27+
root.x0 = height / 2;
28+
root.y0 = 0;
29+
30+
if(root.children){
31+
root.children.forEach(collapse);}
32+
function collapse(d) {
33+
if(d.children) {
34+
d._children = d.children
35+
d._children.forEach(collapse)
36+
d.children = null
37+
}
38+
}
39+
update(root);
40+
41+
function update(source) {
42+
var treeData = treemap(root);
43+
44+
var nodes = treeData.descendants(),
45+
links = treeData.descendants().slice(1);
46+
47+
nodes.forEach(function(d){
48+
d.y = d.depth * 180 ;
49+
});
50+
51+
52+
var node = svg.selectAll('g.node')
53+
.data(nodes, function(d) {return d.id || (d.id = ++i); });
54+
55+
var nodeEnter = node.enter().append('g')
56+
.attr('class', 'node')
57+
.attr("transform", function(d) {
58+
return "translate(" + source.x0 + "," + source.y0 + ")";
59+
})
60+
.on('click', click)
61+
.on("mouseover", function(d,node) {
62+
updateChildren(d,node)
63+
var g = d3.select(this);
64+
if(g.property("childNodes").length<3) {
65+
g.append('circle')
66+
.attr('class', 'button')
67+
.attr('fill', 'gray')
68+
.attr('r', 10)
69+
.attr("cx", -10)
70+
.attr("cy", -14);
71+
g.select('.button')
72+
.append('animate')
73+
.classed('animate', true)
74+
.attr('attributeName', 'r')
75+
.attr('values', '0;10')
76+
.attr('begin', 'indefinite')
77+
.attr('dur', '0.2s')
78+
.attr('repeatCount', 1);
79+
g.append('text')
80+
.classed('button', true)
81+
.attr('x', -16)
82+
.attr('y', -10)
83+
.text("FB")
84+
.style("border", "solid")
85+
.style("stroke", "white")
86+
.style("cursor", "pointer")
87+
.on('click', test);
88+
g._groups[0][0].getElementsByTagName("animate")[0].beginElement();
89+
}else{
90+
g.selectAll('.button').style("visibility", "visible");
91+
}
92+
})
93+
.on("mouseout", function() {
94+
d3.select(this).selectAll('.button').style("visibility", "hidden");
95+
})
96+
.on('contextmenu', function(node,d){
97+
props.setDetails({name: d.id,
98+
branch: d.data.branch,
99+
year: d.data.year,
100+
email: d.data.email,
101+
picture: d.data.picture,
102+
linkedIn: d.data.linkedIn,
103+
hometown: d.data.hometown,
104+
coCurriculars: d.data.coCurriculars,
105+
socialMedia: d.data.socialMedia,
106+
display: true
107+
});
108+
});
109+
110+
nodeEnter.append('circle')
111+
.attr('class', 'node')
112+
.attr('r', 1e-6)
113+
.style("fill", function(d) {
114+
return d._children ? "lightsteelblue" : "#fff";
115+
})
116+
.on('mouseover',(d)=>{
117+
var g=d.target.parentNode
118+
if(g.childNodes.length>3){
119+
g.getElementsByTagName("animate")[0].beginElement();
120+
}
121+
});
122+
123+
nodeEnter.append('text')
124+
.attr("dy", ".35em")
125+
.attr("x", 13)
126+
.text(function(d) {
127+
return d.id;
128+
});
129+
130+
var nodeUpdate = nodeEnter.merge(node)
131+
.attr("fill", "#fff")
132+
.attr("stroke", "steelblue")
133+
.attr("stroke-width", "3px;")
134+
.style('font', '12px sans-serif')
135+
136+
nodeUpdate.transition()
137+
.duration(duration)
138+
.attr("transform", function(d) {
139+
return "translate(" + d.x + "," + d.y + ")";
140+
});
141+
142+
nodeUpdate.select('circle.node')
143+
.attr('r', 10)
144+
.style("fill", function(d) {
145+
return d._children ? "lightsteelblue" : "#fff";
146+
})
147+
.attr('cursor', 'pointer');
148+
149+
var nodeExit = node.exit().transition()
150+
.duration(duration)
151+
.attr("transform", function(d) {
152+
return "translate(" + source.x + "," + source.y + ")";
153+
})
154+
.remove();
155+
156+
nodeExit.select('circle')
157+
.attr('r', 1e-6);
158+
159+
nodeExit.select('text')
160+
.style('fill-opacity', 1e-6);
161+
162+
var link = svg.selectAll('path.link')
163+
.data(links, function(d) { return d.id; });
164+
165+
var linkEnter = link.enter().insert('path', "g")
166+
.attr("class", "link")
167+
.attr('d', function(d){
168+
var o = {x: source.x0, y: source.y0}
169+
return diagonal(o, o)
170+
});
171+
172+
var linkUpdate = linkEnter.merge(link)
173+
.attr("fill", "none")
174+
.attr("stroke", "#ccc")
175+
.attr("stroke-width", "2px")
176+
177+
linkUpdate.transition()
178+
.duration(duration)
179+
.attr('d', function(d){ return diagonal(d, d.parent) });
180+
181+
var linkExit = link.exit().transition()
182+
.duration(duration)
183+
.attr('d', function(d) {
184+
var o = {x: source.x, y: source.y}
185+
return diagonal(o, o)
186+
})
187+
.remove();
188+
189+
nodes.forEach(function(d){
190+
d.x0 = d.x;
191+
d.y0 = d.y;
192+
});
193+
194+
function diagonal(s, d) {
195+
const path = `M ${s.x} ${s.y}
196+
C ${(s.x + d.x) / 2} ${s.y},
197+
${(s.x + d.x) / 2} ${d.y},
198+
${d.x} ${d.y}`
199+
return path;
200+
}
201+
202+
function test(){
203+
console.log("clicked");
204+
}
205+
206+
function click(d,node) {
207+
if (node.children) {
208+
node._children = node.children;
209+
node.children = null;
210+
} else {
211+
node.children = node._children;
212+
node._children = null;
213+
}
214+
update(node);
215+
}
216+
}
217+
},[])
218+
219+
return(
220+
<div id="tree"></div>
221+
)
222+
}
223+
export default D3Tree;

0 commit comments

Comments
 (0)