-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* serializes some network data; dynamic network-view * visualize filtered edges
- Loading branch information
Showing
8 changed files
with
1,038 additions
and
1,028 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,76 @@ | ||
import { | ||
Cosmograph, | ||
CosmographSearch, | ||
CosmographTimeline, | ||
} from "@cosmograph/cosmograph"; | ||
import * as d3 from "d3"; | ||
|
||
const edge_csv = "/media/edges.csv"; | ||
const node_csv = "/media/nodes.csv"; | ||
|
||
const edge_promis = d3.csv(edge_csv); | ||
const node_promis = d3.csv(node_csv); | ||
const alertNode = document.getElementById("alert") | ||
const spinnerNode = document.getElementById("spinner"); | ||
const legendNode = document.getElementById("legend"); | ||
const canvas = document.createElement("div"); | ||
|
||
Promise.all([edge_promis, node_promis]).then(([edge_data, node_data]) => { | ||
const links = edge_data.map((d) => ({ | ||
source: parseInt(d.source), | ||
target: parseInt(d.target), | ||
date: Date.parse(d.date), | ||
})); | ||
|
||
const nodes = node_data.map((d) => ({ | ||
id: parseInt(d.id), | ||
label: d.label, | ||
color: d.color, | ||
})); | ||
const appNode = document.getElementById("app"); | ||
|
||
// remove spinner | ||
spinnerNode.classList.add("visually-hidden"); | ||
legendNode.style.visibility = "visible"; | ||
alertNode.classList.add("visually-hidden"); | ||
appNode.appendChild(canvas); | ||
const searchContainer = document.createElement("div"); | ||
appNode.appendChild(searchContainer); | ||
const config = { | ||
nodeColor: (d) => d.color, | ||
nodeLabelAccessor: (d) => d.label, | ||
showTopLabels: true, | ||
showDynamicLabels: false, | ||
linkGreyoutOpacity: 0, | ||
nodeLabelColor: "white", | ||
hoveredNodeLabelColor: "white", | ||
linkWidth: 1, | ||
linkArrows: false, | ||
onClick: (data) => alert(data.label) | ||
}; | ||
const cosmograph = new Cosmograph(canvas, config); | ||
|
||
const timelineContainer = document.createElement("div"); | ||
const timeline = new CosmographTimeline(cosmograph, timelineContainer); | ||
|
||
|
||
const search = new CosmographSearch(cosmograph, searchContainer); | ||
cosmograph.setData(nodes, links); | ||
appNode.appendChild(timelineContainer); | ||
|
||
}); | ||
import { Cosmograph, CosmographTimeline } from "@cosmograph/cosmograph"; | ||
|
||
async function init() { | ||
const alertNode = document.getElementById("alert"); | ||
const spinnerNode = document.getElementById("spinner"); | ||
const legendNode = document.getElementById("legend"); | ||
const canvas = document.createElement("div"); | ||
|
||
const queryString = window.location.search; | ||
const url = `/network/csv/${queryString}`; | ||
|
||
try { | ||
const res = await fetch(url); | ||
const data = await res.json(); | ||
|
||
const colors = { | ||
person: "#720e07", | ||
place: "#5bc0eb", | ||
work: "#ff8600", | ||
event: "#9bc53d", | ||
institution: "#ffdd1b", | ||
}; | ||
|
||
const links = data["edges"].map((d) => ({ | ||
source: parseInt(d.s), | ||
target: parseInt(d.t), | ||
date: Date.parse(d.start), | ||
})); | ||
|
||
const nodes = data["nodes"].map((d) => ({ | ||
id: parseInt(d.id), | ||
label: d.l, | ||
color: colors[d["k"]], | ||
})); | ||
|
||
const appNode = document.getElementById("app"); | ||
|
||
// Remove spinner | ||
spinnerNode.classList.add("visually-hidden"); | ||
legendNode.style.visibility = "visible"; | ||
alertNode.classList.add("visually-hidden"); | ||
|
||
appNode.appendChild(canvas); | ||
const searchContainer = document.createElement("div"); | ||
appNode.appendChild(searchContainer); | ||
|
||
const config = { | ||
nodeColor: (d) => d.color, | ||
nodeLabelAccessor: (d) => d.label, | ||
showTopLabels: true, | ||
showDynamicLabels: false, | ||
linkGreyoutOpacity: 0, | ||
nodeLabelColor: "white", | ||
hoveredNodeLabelColor: "white", | ||
linkWidth: 1, | ||
linkArrows: false, | ||
onClick: (data) => alert(data.label), | ||
simulationRepulsion: 1, | ||
linkDistance: 5, | ||
gravity: 0.5 | ||
}; | ||
|
||
const cosmograph = new Cosmograph(canvas, config); | ||
|
||
const timelineContainer = document.createElement("div"); | ||
const timeline = new CosmographTimeline(cosmograph, timelineContainer); | ||
cosmograph.setData(nodes, links); | ||
appNode.appendChild(timelineContainer); | ||
} catch (error) { | ||
console.error("Failed to fetch data:", error); | ||
alertNode.textContent = "Failed to load data. Please try again later."; | ||
alertNode.style.visibility = "visible"; | ||
} | ||
} | ||
|
||
init(); |
2 changes: 1 addition & 1 deletion
2
static/vite/browser-CBdNgIts.js → static/vite/browser-lg2ZDdSy.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
{ | ||
"_browser-CBdNgIts.js": { | ||
"file": "browser-CBdNgIts.js", | ||
"_browser-lg2ZDdSy.js": { | ||
"file": "browser-lg2ZDdSy.js", | ||
"name": "browser", | ||
"isDynamicEntry": true, | ||
"imports": [ | ||
"js/main.js" | ||
] | ||
}, | ||
"js/main.js": { | ||
"file": "main-CJBCyQtR.js", | ||
"file": "main-Dnusw_Zv.js", | ||
"name": "main", | ||
"src": "js/main.js", | ||
"isEntry": true, | ||
"dynamicImports": [ | ||
"_browser-CBdNgIts.js" | ||
"_browser-lg2ZDdSy.js" | ||
] | ||
} | ||
} |