Skip to content

Commit 41b0df6

Browse files
committed
Add api call to fetch data. Update graph display to use fetched data
1 parent d10a233 commit 41b0df6

3 files changed

Lines changed: 52 additions & 39 deletions

File tree

backend-aws/handler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
def format_response(status_code, body):
88
response = {
99
"statusCode": status_code,
10+
"headers": {
11+
"Access-Control-Allow-Credentials": True,
12+
"Access-Control-Allow-Origin": "*",
13+
"Content-Type": "application/json",
14+
},
1015
"body": json.dumps(body)
1116
}
1217
return response

backend-aws/requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
boto3==1.9.89
2+
botocore==1.12.89
3+
docutils==0.14
4+
jmespath==0.9.3
5+
python-dateutil==2.8.0
6+
s3transfer==0.2.0
7+
six==1.12.0
8+
urllib3==1.24.1

index.html

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,45 @@
3434
</div>
3535

3636
<script>
37-
const web = document.getElementById('idea-web');
38-
const data = {
39-
nodes: [
40-
{
41-
id: 0, val: 1, name: "Dance Visualizer", tags: new Set(["computer vision", "dance"]),
42-
description: "Take old dance videos as input and track movements to create visualizations", creator: "Sruti"
43-
},
44-
{
45-
id: 1, val: 1, name: "Route Optimizer", tags: new Set(["routing", "constraint optimization"]),
46-
description: "Find optimal route for multiple locations and time constraints", creator: "Sruti"
47-
},
48-
{
49-
id: 2, val: 1, name: "Dance Moves Database", tags: new Set(["computer vision", "dance", "machine learning"]),
50-
description: "Analyze dance moves from different styles to learn and understand history", creator: "Marko"
51-
},
52-
{
53-
id: 3, val: 1, name: "Meet in the Middle", tags: new Set(["routing", "constraint optimization", "machine learning"]),
54-
description: "Find a convenient meeting point for two people in different locations", creator: "Dan"
55-
}],
56-
links: [{ source: 0, target: 2 }, { source: 1, target: 3 }, { source: 2, target: 3 }]
57-
};
58-
59-
const Graph = ForceGraph3D()
60-
(web)
61-
.graphData(data)
62-
.nodeLabel('name')
63-
.onNodeHover(node => web.style.cursor = node ? 'pointer' : null)
64-
.onNodeClick(node => {
65-
// Aim at node from outside it
66-
const distance = 40;
67-
const distRatio = 1 + distance / Math.hypot(node.x, node.y, node.z);
68-
69-
Graph.cameraPosition(
70-
{ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }, // new position
71-
node, // lookAt ({ x, y, z })
72-
3000 // ms transition duration
73-
);
74-
detailDisplay(node);
75-
});
37+
displayGraph();
38+
39+
async function displayGraph() {
40+
const web = document.getElementById('idea-web');
41+
let newData
42+
try {
43+
newData = await getData()
44+
const Graph = ForceGraph3D()
45+
(web)
46+
.graphData(newData)
47+
.nodeLabel('name')
48+
.onNodeHover(node => web.style.cursor = node ? 'pointer' : null)
49+
.onNodeClick(node => {
50+
// Aim at node from outside it
51+
const distance = 40;
52+
const distRatio = 1 + distance / Math.hypot(node.x, node.y, node.z);
53+
54+
Graph.cameraPosition(
55+
{ x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }, // new position
56+
node, // lookAt ({ x, y, z })
57+
3000 // ms transition duration
58+
);
59+
detailDisplay(node);
60+
});
61+
}
62+
catch (error) {
63+
console.log(error)
64+
}
65+
}
66+
67+
function getData() {
68+
return fetch('https://syar2tbuna.execute-api.us-east-1.amazonaws.com/dev/data')
69+
.then(response => {
70+
if (response.ok) {
71+
return response.json()
72+
} throw new Error(response.statusText)
73+
})
74+
.catch(error => { throw new Error(error.message) });
75+
}
7676

7777
function onAddItemClick() {
7878
const modal = document.getElementById("modal-idea-new");

0 commit comments

Comments
 (0)