Merge pull request #1196 from skrashevich/feat-network-dot-enhancements
refactor(webui): enhance network visualization in network.html
This commit is contained in:
@@ -156,19 +156,20 @@ func (c *conn) host() (s string) {
|
||||
return
|
||||
}
|
||||
|
||||
func (c *conn) label() (s string) {
|
||||
s = "format_name=" + c.FormatName
|
||||
func (c *conn) label() string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("format_name=" + c.FormatName)
|
||||
if c.Protocol != "" {
|
||||
s += "\nprotocol=" + c.Protocol
|
||||
sb.WriteString("\nprotocol=" + c.Protocol)
|
||||
}
|
||||
if c.Source != "" {
|
||||
s += "\nsource=" + c.Source
|
||||
sb.WriteString("\nsource=" + c.Source)
|
||||
}
|
||||
if c.URL != "" {
|
||||
s += "\nurl=" + c.URL
|
||||
sb.WriteString("\nurl=" + c.URL)
|
||||
}
|
||||
if c.UserAgent != "" {
|
||||
s += "\nuser_agent=" + c.UserAgent
|
||||
sb.WriteString("\nuser_agent=" + c.UserAgent)
|
||||
}
|
||||
return
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
+42
-6
@@ -18,17 +18,21 @@
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#network {
|
||||
flex-grow: 1;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script src="main.js"></script>
|
||||
<div id="network"></div>
|
||||
<script src="main.js"></script>
|
||||
<script>
|
||||
/* global vis */
|
||||
window.addEventListener('load', async () => {
|
||||
window.addEventListener('load', () => {
|
||||
const url = new URL('api/streams.dot' + location.search, location.href);
|
||||
const r = await fetch(url, {cache: 'no-cache'});
|
||||
const data = vis.parseDOTNetwork(await r.text());
|
||||
|
||||
const container = document.getElementById('network');
|
||||
const options = {
|
||||
edges: {
|
||||
font: {align: 'middle'},
|
||||
@@ -37,8 +41,40 @@
|
||||
nodes: {shape: 'box'},
|
||||
physics: false,
|
||||
};
|
||||
new vis.Network(document.getElementById('network'), data, options);
|
||||
|
||||
let network;
|
||||
|
||||
async function update() {
|
||||
try {
|
||||
const response = await fetch(url, {cache: 'no-cache'});
|
||||
const dotData = await response.text();
|
||||
const data = vis.parseDOTNetwork(dotData);
|
||||
|
||||
if (!network) {
|
||||
network = new vis.Network(container, data, options);
|
||||
network.storePositions();
|
||||
} else {
|
||||
const positions = network.getPositions();
|
||||
const viewPosition = network.getViewPosition();
|
||||
const scale = network.getScale();
|
||||
|
||||
network.setData(data);
|
||||
|
||||
for (const nodeId in positions) {
|
||||
network.moveNode(nodeId, positions[nodeId].x, positions[nodeId].y);
|
||||
}
|
||||
|
||||
network.moveTo({position: viewPosition, scale: scale});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching or updating network data:', error);
|
||||
}
|
||||
|
||||
setTimeout(update, 5000);
|
||||
}
|
||||
|
||||
update();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user