Last active
March 10, 2023 22:00
-
-
Save biovisualize/6ce3326ab38c89f861b0f6d1764e4034 to your computer and use it in GitHub Desktop.
top 10 airports network viz
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
<head> | |
<script src="//unpkg.com/force-graph"></script> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
background: #1e1e1e; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="graph"></div> | |
<script> | |
const elem = document.getElementById('graph') | |
const graph = ForceGraph()(elem) | |
function enableInteraction (bool) { | |
graph | |
.enablePointerInteraction(bool) | |
.enableNodeDrag(bool) | |
if (bool) graph.resumeAnimation() | |
else graph.pauseAnimation() | |
} | |
function drawGraph(_data) { | |
graph | |
.graphData(_data) | |
.nodeLabel(node => node.id) | |
.backgroundColor("#1e1e1e") | |
.enableZoomPanInteraction(false) | |
.zoom(1.5) | |
.warmupTicks(5) | |
// .cooldownTime(2000) | |
window.addEventListener("resize", () => graph.width(window.innerWidth)) | |
elem.addEventListener("mouseover", () => enableInteraction(true)) | |
elem.addEventListener("mouseout", () => enableInteraction(false)) | |
} | |
fetch("https://gist.githubusercontent.com/biovisualize/13c002b7873522b6272a463b1c948273/raw/76205b861ebbdf5f7d62460977ae498f70c04bb3/top10_airports.json") | |
.then(response => response.text()) | |
.then((data) => { | |
drawGraph(JSON.parse(data)) | |
}) | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment