1818 height : 100% ;
1919 width : 100% ;
2020 }
21+
22+ # network {
23+ flex-grow : 1 ;
24+ }
2125 </ style >
2226</ head >
2327< body >
24- < script src ="main.js "> </ script >
2528< div id ="network "> </ div >
29+ < script src ="main.js "> </ script >
2630< script >
2731 /* global vis */
28- window . addEventListener ( 'load' , async ( ) => {
32+ window . addEventListener ( 'load' , ( ) => {
2933 const url = new URL ( 'api/streams.dot' + location . search , location . href ) ;
30- const r = await fetch ( url , { cache : 'no-cache' } ) ;
31- const data = vis . parseDOTNetwork ( await r . text ( ) ) ;
34+
35+ const container = document . getElementById ( 'network' ) ;
3236 const options = {
3337 edges : {
3438 font : { align : 'middle' } ,
3741 nodes : { shape : 'box' } ,
3842 physics : false ,
3943 } ;
40- new vis . Network ( document . getElementById ( 'network' ) , data , options ) ;
44+
45+ let network ;
46+
47+ async function update ( ) {
48+ try {
49+ const response = await fetch ( url , { cache : 'no-cache' } ) ;
50+ const dotData = await response . text ( ) ;
51+ const data = vis . parseDOTNetwork ( dotData ) ;
52+
53+ if ( ! network ) {
54+ network = new vis . Network ( container , data , options ) ;
55+ network . storePositions ( ) ;
56+ } else {
57+ const positions = network . getPositions ( ) ;
58+ const viewPosition = network . getViewPosition ( ) ;
59+ const scale = network . getScale ( ) ;
60+
61+ network . setData ( data ) ;
62+
63+ for ( const nodeId in positions ) {
64+ network . moveNode ( nodeId , positions [ nodeId ] . x , positions [ nodeId ] . y ) ;
65+ }
66+
67+ network . moveTo ( { position : viewPosition , scale : scale } ) ;
68+ }
69+ } catch ( error ) {
70+ console . error ( 'Error fetching or updating network data:' , error ) ;
71+ }
72+
73+ setTimeout ( update , 5000 ) ;
74+ }
75+
76+ update ( ) ;
4177 } ) ;
4278</ script >
4379</ body >
44- </ html >
80+ </ html >
0 commit comments