From 1b411b1fed4fa33d17739542ce53f2870a161998 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 16 Jun 2024 10:18:45 +0300 Subject: [PATCH 1/6] refactor(streams): optimize label generation with strings.Builder feat(network): add periodic data fetching and network update --- internal/streams/dot.go | 15 ++++---- www/network.html | 83 +++++++++++++++++++++++++++++++---------- 2 files changed, 72 insertions(+), 26 deletions(-) diff --git a/internal/streams/dot.go b/internal/streams/dot.go index aa008c40..9aacccb5 100644 --- a/internal/streams/dot.go +++ b/internal/streams/dot.go @@ -146,19 +146,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() } diff --git a/www/network.html b/www/network.html index 5193b6a9..519e0eba 100644 --- a/www/network.html +++ b/www/network.html @@ -21,24 +21,69 @@ - -
- + +
+ + \ No newline at end of file From a69eb8a66e576cbfe369c4af985ea37be5abd096 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 16 Jun 2024 14:53:08 +0300 Subject: [PATCH 2/6] style(network): add flex-grow to network div and move script tag --- www/network.html | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/www/network.html b/www/network.html index 519e0eba..b0edd31c 100644 --- a/www/network.html +++ b/www/network.html @@ -18,11 +18,15 @@ height: 100%; width: 100%; } + + #network { + flex-grow: 1; + } -
+ - \ No newline at end of file From cb44d5431a854efd2a84af52d747e98aabc862b9 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 16 Jun 2024 15:01:40 +0300 Subject: [PATCH 3/6] feat(network): preserve pan and scale on data reload --- www/network.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/www/network.html b/www/network.html index b0edd31c..18d4a640 100644 --- a/www/network.html +++ b/www/network.html @@ -68,6 +68,8 @@ network.storePositions(); } else { const positions = network.getPositions(); + const viewState = network.getViewPosition(); + const scale = network.getScale(); network.setData(data); @@ -76,6 +78,8 @@ network.moveNode(nodeId, positions[nodeId].x, positions[nodeId].y); } } + + network.moveTo({ position: viewState, scale: scale }); } } catch (error) { From d8aed552bc54e98804d92e74993389cf18ea1469 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 16 Jun 2024 15:22:33 +0300 Subject: [PATCH 4/6] fix(network): ensure consistent node positions by storing and reusing seed --- www/network.html | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/www/network.html b/www/network.html index 18d4a640..53f1ca68 100644 --- a/www/network.html +++ b/www/network.html @@ -31,13 +31,11 @@ let network; let nodes = new vis.DataSet(); let edges = new vis.DataSet(); + let seed = ""; /* global vis */ window.addEventListener('load', () => { const url = new URL('api/streams.dot' + location.search, location.href); const options = { - layout: { - randomSeed: "0.4597730541017021:1718519934576" - }, edges: { font: { align: 'middle' }, smooth: false, @@ -66,16 +64,19 @@ edges = new vis.DataSet(data.edges); network = new vis.Network(container, { nodes, edges }, options); network.storePositions(); + seed = network.getSeed(); } else { const positions = network.getPositions(); const viewState = network.getViewPosition(); const scale = network.getScale(); - + network.setOptions({layout: { + randomSeed: seed + }}) network.setData(data); for (const nodeId in positions) { if (positions.hasOwnProperty(nodeId)) { - network.moveNode(nodeId, positions[nodeId].x, positions[nodeId].y); + network.moveNode(nodeId, Math.floor(positions[nodeId].x), Math.floor(positions[nodeId].y)); } } From 5b481a27c67cdf1b75b02e295ce6e172eca58878 Mon Sep 17 00:00:00 2001 From: Sergey Krashevich Date: Sun, 16 Jun 2024 21:57:48 +0300 Subject: [PATCH 5/6] fix(network): enable autoResize in network settings --- www/network.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/network.html b/www/network.html index 53f1ca68..17c3570c 100644 --- a/www/network.html +++ b/www/network.html @@ -47,7 +47,7 @@ enabled: false, } }, - autoResize: false, + autoResize: true, locale: navigator.language.toLowerCase().split('-').slice(0, 2).join('-'), }; const container = document.getElementById('network'); From e6fa97c738560dd03374994818e2bdd032096051 Mon Sep 17 00:00:00 2001 From: Alex X Date: Sun, 16 Jun 2024 22:12:52 +0300 Subject: [PATCH 6/6] Code refactoring after #1196 --- www/network.html | 99 ++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 58 deletions(-) diff --git a/www/network.html b/www/network.html index 17c3570c..7a4ff229 100644 --- a/www/network.html +++ b/www/network.html @@ -25,73 +25,56 @@ -
- - + + update(); + }); + - \ No newline at end of file +