Skip to content

Commit

Permalink
Merge c8d7a35 into 2d55af8
Browse files Browse the repository at this point in the history
  • Loading branch information
totallynotvaishnav committed Jul 26, 2022
2 parents 2d55af8 + c8d7a35 commit 79e8bd4
Show file tree
Hide file tree
Showing 42 changed files with 2,946 additions and 1,924 deletions.
6 changes: 3 additions & 3 deletions dist/netjsongraph.min.js

Large diffs are not rendered by default.

40 changes: 3 additions & 37 deletions examples/data/netjson-elementsLegend.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@
}
],
"links": [
{
"source": "172.16.146.6",
"target": "172.16.145.2",
"cost": 1.2939453125,
"properties": {
"lq": 0.9,
"nlq": 0.497,
"bitrate": "20 mbit/s",
"type": "fiber",
"time": "2019-04-06T20:06:54.000Z"
}
},
{
"source": "172.16.146.6",
"target": "172.16.146.4",
Expand All @@ -92,18 +80,7 @@
"lq": 1.0,
"nlq": 1.0,
"bitrate": "30 mbit/s",
"type": "vpn"
}
},
{
"source": "172.16.145.2",
"target": "172.16.146.7",
"cost": 12.739,
"properties": {
"lq": 0.345,
"nlq": 0.227,
"bitrate": "1 mbit/s",
"type": "wireless_weak"
"type": "ethernet"
}
},
{
Expand All @@ -114,7 +91,7 @@
"lq": 1.0,
"nlq": 1.0,
"bitrate": "35 mbit/s",
"type": "wireless"
"type": "ethernet"
}
},
{
Expand All @@ -136,7 +113,7 @@
"lq": 1.0,
"nlq": 1.0,
"bitrate": "32 mbit/s",
"type": "fiber"
"type": "wireless"
}
},
{
Expand All @@ -160,17 +137,6 @@
"bitrate": "45 mbit/s",
"type": "wireless"
}
},
{
"source": "172.16.146.7",
"target": "172.16.146.4",
"cost": 1.0,
"properties": {
"lq": 1.0,
"nlq": 1.0,
"bitrate": "39 mbit/s",
"type": "fiber"
}
}
]
}
41 changes: 34 additions & 7 deletions examples/data/netjsonmap.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,22 +294,42 @@
}
],
"links": [
{"source": "172.16.146.6", "target": "172.16.146.4", "cost": 1},
{
"source": "172.16.146.6",
"target": "172.16.146.4",
"cost": 1
},
{"source": "172.16.139.4", "target": "172.16.138.1", "cost": 1.02734375},
{"source": "172.16.135.15", "target": "10.123.10.10", "cost": 1},
{"source": "192.168.145.145", "target": "10.254.254.2", "cost": 1},
{"source": "172.16.186.249", "target": "172.16.159.187", "cost": 1},
{"source": "172.16.186.249", "target": "172.16.159.50", "cost": 1},
{"source": "172.16.12.10", "target": "172.16.12.12", "cost": 1},
{"source": "172.16.177.31", "target": "172.16.155.4", "cost": 1.1796875},
{"source": "10.183.1.11", "target": "172.16.145.3", "cost": 1},
{
"source": "172.16.177.31",
"target": "172.16.155.4",
"cost": 1.1796875
},
{
"source": "10.183.1.11",
"target": "172.16.145.3",
"cost": 1,
"properties": {
"status": "down"
}
},
{"source": "172.16.200.67", "target": "172.16.200.2", "cost": 1},
{"source": "172.16.185.11", "target": "192.168.176.10", "cost": 1},
{"source": "172.16.159.187", "target": "172.16.159.50", "cost": 1},
{"source": "172.16.159.187", "target": "172.16.39.31", "cost": 1.36328125},
{"source": "10.254.254.4", "target": "10.254.254.2", "cost": 1},
{"source": "10.254.254.2", "target": "10.254.254.4", "cost": 1},
{"source": "10.254.254.2", "target": "10.254.254.4", "cost": 1.3},
{
"source": "10.254.254.2",
"target": "10.254.254.4",
"cost": 1.3,
"properties": {
"status": "down"
}
},
{"source": "172.16.171.1", "target": "172.16.169.1", "cost": 1.1181640625},
{"source": "172.16.155.5", "target": "172.16.155.4", "cost": 1},
{"source": "172.16.155.5", "target": "172.16.44.10", "cost": 1.1328125},
Expand All @@ -319,7 +339,14 @@
{"source": "10.149.3.3", "target": "172.16.146.4", "cost": 1.26171875},
{"source": "172.16.185.13", "target": "10.185.1.1", "cost": 1},
{"source": "172.16.185.13", "target": "10.185.1.11", "cost": 1},
{"source": "10.185.1.11", "target": "10.185.1.1", "cost": 1},
{
"source": "10.185.1.11",
"target": "10.185.1.1",
"cost": 1,
"properties": {
"status": "down"
}
},
{
"source": "172.16.133.11",
"target": "192.168.176.10",
Expand Down
125 changes: 80 additions & 45 deletions examples/netjson-searchElements.html
Original file line number Diff line number Diff line change
@@ -1,67 +1,102 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<title>netjsongraph.js: basic example</title>
<meta charset="utf-8">
<meta charset="utf-8" />
<!-- theme can be easily customized via css -->
<link href="../src/css/netjsongraph-theme.css" rel="stylesheet">
<link href="../src/css/netjsongraph.css" rel="stylesheet">
</head>
<body>
<link href="../src/css/netjsongraph-theme.css" rel="stylesheet" />
<link href="../src/css/netjsongraph.css" rel="stylesheet" />
</head>
<body>
<script type="text/javascript" src="../dist/netjsongraph.min.js"></script>
<script type="text/javascript">
/*
/*
The demo is used to show the use of the `searchElements` function.
For test, you can input `test` and click the `search` button.
See the following comments for details.
*/
// `graph` render defaultly.
const graph = new NetJSONGraph("./data/netjsonmap.json", {
onLoad: function(){
let searchContainer = document.createElement("div"),
searchInput = document.createElement("input"),
searchBtn = document.createElement("button"),
/*
// `graph` render defaultly.
let graph = new NetJSONGraph("./data/netjsonmap.json", {
onLoad: function () {
const gui = this.utils.getGUI(this);
gui.init();
if (this.config.metadata) {
gui.createAboutContainer(graph);
this.utils.updateMetadata.call(this);
}
if (this.config.switchMode) {
gui.renderModeSelector.onclick = () => {
if (this.config.render === this.utils.mapRender) {
this.config.render = this.utils.graphRender;
this.echarts.dispose();
graph = new NetJSONGraph(this.data, {
...this.config,
});
graph.render();
} else {
this.config.render = this.utils.mapRender;
this.config.render(this.data, this);
}
};
}
this.config.onClickElement = (type, data) => {
let nodeLinkData;
if (type === "node") {
nodeLinkData = this.utils.nodeInfo(data);
} else {
nodeLinkData = this.utils.linkInfo(data);
}
gui.getNodeLinkInfo(type, nodeLinkData);
gui.sideBar.classList.remove("hidden");
};
let searchContainer = document.createElement("div"),
searchInput = document.createElement("input"),
searchBtn = document.createElement("button"),
/*
Pass in the url to listen to, and save the returned function.
Please ensure that the return value of the api is the specified json format.
*/
searchFunc = this.utils.searchElements.call(this, "https://ee3bdf59-d14c-4280-b514-52bd3dfc2c17.mock.pstmn.io/?search=");
searchFunc = this.utils.searchElements.call(
this,
"https://ee3bdf59-d14c-4280-b514-52bd3dfc2c17.mock.pstmn.io/?search=",
);

searchInput.setAttribute("class", "njg-searchInput");
searchInput.placeholder =
"Input value for searching special elements.";
searchBtn.setAttribute("class", "njg-searchBtn");
searchBtn.innerHTML = "search";
searchContainer.setAttribute("class", "njg-searchContainer");
searchContainer.appendChild(searchInput);
searchContainer.appendChild(searchBtn);
this.el.appendChild(searchContainer);

searchInput.setAttribute("class", "njg-searchInput");
searchInput.placeholder = "Input value for searching special elements.";
searchBtn.setAttribute("class", "njg-searchBtn");
searchBtn.innerHTML = "search";
searchContainer.setAttribute("class", "njg-searchContainer");
searchContainer.appendChild(searchInput);
searchContainer.appendChild(searchBtn);
this.el.appendChild(searchContainer);
searchInput.onchange = () => {
// do something to deal user input value.
};

searchInput.onchange = () => {
// do something to deal user input value.
};
searchBtn.onclick = () => {
let inputValue = searchInput.value.trim();

searchBtn.onclick = () => {
let inputValue = searchInput.value.trim();

/*
Pass in the relevant search value,
/*
Pass in the relevant search value,
which will re-render automatically according to the request result within the function.
*/
if(inputValue === "appendData"){
// appendData
searchFunc(inputValue, false);
}
else{
searchFunc(inputValue);
}
if (inputValue === "appendData") {
// appendData
searchFunc(inputValue, false);
} else {
searchFunc(inputValue);
}

searchInput.value = "";
}
searchInput.value = "";
};

this.utils.hideLoading();
}
});
graph.render();
this.utils.hideLoading();
},
});

graph.render();
</script>
</body>
</html>
Loading

0 comments on commit 79e8bd4

Please sign in to comment.