|
34 | 34 | </div> |
35 | 35 |
|
36 | 36 | <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 | + } |
76 | 76 |
|
77 | 77 | function onAddItemClick() { |
78 | 78 | const modal = document.getElementById("modal-idea-new"); |
|
0 commit comments