-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
420 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>netjsongraph.js: basic example</title> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link | ||
rel="stylesheet" | ||
href="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css" | ||
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ==" | ||
crossorigin="" | ||
/> | ||
<!-- theme can be easily customized via css --> | ||
<link href="../src/css/netjsongraph-theme.css" rel="stylesheet" /> | ||
<link href="../src/css/netjsongraph.css" rel="stylesheet" /> | ||
<style type="text/css"> | ||
#legend h4 { | ||
margin: 10px 0; | ||
text-align: center; | ||
} | ||
#legend { | ||
position: absolute; | ||
right: 25px; | ||
bottom: 25px; | ||
width: auto; | ||
height: auto; | ||
max-width: 250px; | ||
padding: 8px 15px; | ||
background: #fbfbfb; | ||
border-radius: 8px; | ||
color: #000; | ||
font-family: Arial, sans-serif; | ||
font-family: sans-serif; | ||
font-size: 14px; | ||
z-index: 1000; | ||
user-select: text; | ||
} | ||
#legend p { | ||
margin: 10px 0; | ||
display: flex; | ||
align-items: center; | ||
} | ||
#legend span { | ||
width: 16px; | ||
margin-right: 5px; | ||
} | ||
#legend .link-up, | ||
#legend .link-down { | ||
display: inline-block; | ||
height: 5px; | ||
border-bottom-width: 6px; | ||
border-bottom-style: solid; | ||
} | ||
#legend .link-up { | ||
color: #3acc38; | ||
margin-right: 10px; | ||
} | ||
#legend .link-down { | ||
color: red; | ||
margin-right: 10px; | ||
} | ||
|
||
@media only screen and (max-width: 850px) { | ||
#legend { | ||
right: 15px; | ||
} | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<script type="text/javascript" src="../dist/netjsongraph.min.js"></script> | ||
<script type="text/javascript"> | ||
const map = new NetJSONGraph("./data/netjsonmap.json", { | ||
render: "map", | ||
clustering: true, | ||
clusteringThreshold: 50, | ||
// set map initial state. | ||
mapOptions: { | ||
center: [46.86764405052012, 19.675998687744144], | ||
zoom: 4, | ||
nodeConfig: { | ||
label: { | ||
offset: [0, -10], | ||
}, | ||
}, | ||
}, | ||
linkCategories: [ | ||
{ | ||
name: "down", | ||
linkStyle: { | ||
color: "#c92517", | ||
width: 5, | ||
}, | ||
emphasis: { | ||
linkStyle: { | ||
color: "#FD0101", | ||
opacity: 1, | ||
}, | ||
}, | ||
}, | ||
], | ||
// Convert to internal json format | ||
prepareData: (data) => { | ||
data.nodes.map((node) => { | ||
node.label = node.name; | ||
node.properties = Object.assign(node.properties || {}, { | ||
location: node.location, | ||
}); | ||
}); | ||
|
||
data.links.map((link) => { | ||
link.properties = link.properties || {}; | ||
if (link.properties.status) { | ||
link.category = link.properties.status; | ||
} | ||
}); | ||
}, | ||
}); | ||
|
||
const createLegend = (key, name) => { | ||
const legendItem = document.createElement("p"); | ||
const legendIcon = document.createElement("span"); | ||
|
||
legendIcon.setAttribute("class", name); | ||
|
||
legends.appendChild(legendItem); | ||
legendItem.appendChild(legendIcon); | ||
|
||
legendItem.innerHTML += key; | ||
return legendItem; | ||
}; | ||
const legends = document.createElement("div"); | ||
const legendsHeader = document.createElement("h4"); | ||
legends.setAttribute("id", "legend"); | ||
legendsHeader.innerHTML = "Legend"; | ||
legends.appendChild(legendsHeader); | ||
legends.appendChild(createLegend("Up", "link-up")); | ||
legends.appendChild(createLegend("Down", "link-down")); | ||
|
||
document.body.appendChild(legends); | ||
|
||
map.render(); | ||
</script> | ||
</body> | ||
</html> |
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
Oops, something went wrong.