Skip to content

Commit 9e91f11

Browse files
committed
Fix layout bug. Convert fetched data node tags to sets
1 parent 1dfd0b3 commit 9e91f11

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

graph.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const graphElem = document.getElementById('idea-graph');
1+
const graphElem = document.getElementById("idea-graph");
22
const Graph = ForceGraph3D()(graphElem)
33
displayGraph();
44

@@ -11,10 +11,11 @@ window.onclick = function (event) {
1111
async function displayGraph() {
1212
let newData
1313
try {
14-
newData = await getData()
14+
newData = await getData();
15+
newData.nodes = newData.nodes.map(node => ({...node, tags: new Set(node.tags)}));
1516
Graph.graphData(newData)
16-
.nodeLabel('name')
17-
.onNodeHover(node => graphElem.style.cursor = node ? 'pointer' : null)
17+
.nodeLabel("name")
18+
.onNodeHover(node => graphElem.style.cursor = node ? "pointer" : null)
1819
.onNodeClick(node => {
1920
// Aim at node from outside it
2021
const distance = 40;
@@ -44,10 +45,10 @@ function displayDetail(node) {
4445
detailTags.textContent = [...node.tags].join(', ');
4546
detailCreator.textContent = node.creator;
4647
detailDescription.textContent = node.description;
47-
48-
modal.style.top = event.pageY;
49-
modal.style.left = event.pageX;
50-
modal.style.display = 'block';
48+
49+
modal.style.top = event.pageY + "px";
50+
modal.style.left = event.pageX + "px";
51+
modal.style.display = "block";
5152
}
5253

5354
function onAddItemClick() {
@@ -86,7 +87,7 @@ function onModalSubmitClick(event, form) {
8687
}
8788

8889
function onModalCloseClick(modal) {
89-
modal.parentElement.style.display = 'none';
90+
modal.parentElement.style.display = "none";
9091
}
9192

9293
function matchTags(newIdea, nodes) {
@@ -97,4 +98,5 @@ function matchTags(newIdea, nodes) {
9798
newLinks = [...newLinks, { source: newIdea.id, target: idea.id }]
9899
}
99100
}
101+
return newLinks
100102
}

index.html

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
<!DOCTYPE html>
2-
<html lang="en-US">
3-
41
<head>
52
<link rel="stylesheet" href="styles.css">
63
<script src="https://unpkg.com/3d-force-graph"></script>
74
</head>
85

96
<body>
107
<div id="idea-graph"></div>
11-
128
<button id="button-add" onclick="onAddItemClick()">Add Idea</button>
13-
149
<div id="modal-idea-new">
1510
<button class="button-modal-close" onclick="onModalCloseClick(this)">X</button>
1611
<form id="form-idea-new" onsubmit="onModalSubmitClick(event, this)">
@@ -37,9 +32,8 @@
3732
<span id="detail-description"></span><br><br>
3833
Topics: <span id="detail-tags"></span>
3934
</div>
40-
</body>
4135

42-
<script src="api.js"></script>
43-
<script src="graph.js"></script>
36+
<script src="api.js"></script>
37+
<script src="graph.js"></script>
38+
</body>
4439

45-
</html>

0 commit comments

Comments
 (0)