@@ -26,6 +26,7 @@ var smartHomeBgColor = style.getPropertyValue('--d1bgCol');
2626
2727var initialread = 0 ;
2828var graphloaded = 0 ;
29+ var maxDisplayLength ;
2930var boolDisplayHouseConsumption ;
3031var boolDisplayLoad1 ;
3132var boolDisplayLoad2 ;
@@ -585,7 +586,9 @@ function putgraphtogether() {
585586 if ( ( all1 == 1 ) && ( all2 == 1 ) && ( all3 == 1 ) && ( all4 == 1 ) && ( all5 == 1 ) && ( all6 == 1 ) && ( all7 == 1 ) && ( all8 == 1 ) && ( all9 == 1 ) && ( all10 == 1 ) && ( all11 == 1 ) && ( all12 == 1 ) && ( all13 == 1 ) && ( all14 == 1 ) && ( all15 == 1 ) && ( all16 == 1 ) ) {
586587 var alldata = all1p + "\n" + all2p + "\n" + all3p + "\n" + all4p + "\n" + all5p + "\n" + all6p + "\n" + all7p + "\n" + all8p + "\n" + all9p + "\n" + all10p + "\n" + all11p + "\n" + all12p + "\n" + all13p + "\n" + all14p + "\n" + all15p + "\n" + all16p ;
587588 allChartData = parseData ( alldata ) ;
588- if ( allChartData . length >= 30 ) {
589+ console . log ( "allChartData.length: " + allChartData . length ) ;
590+ if ( allChartData . length >= 30 ) { // 5 minutes * 6 measurements/min
591+ console . log ( "received at least " + maxDisplayLength + " data sets for graph" ) ;
589592 Object . keys ( allChartData [ allChartData . length - 1 ] ) . forEach ( function ( key ) {
590593 if ( key != 'time' && key != 'timestamp' ) {
591594 initDataset ( key ) ;
@@ -594,9 +597,10 @@ function putgraphtogether() {
594597 // after receipt of all data segments, unsubscribe from these topics to save bandwidth
595598 unsubscribeMqttGraphSegments ( ) ;
596599
600+ initialread = 1 ;
601+ $ ( '#waitforgraphloadingdiv' ) . text ( 'Graph lädt...' ) ;
597602 checkgraphload ( ) ;
598603 // now we are ready to receive small updates for graph data
599- initialread = 1 ;
600604 } else {
601605 all1 = 0 ;
602606 all2 = 0 ;
@@ -623,24 +627,24 @@ function putgraphtogether() {
623627
624628function updateGraph ( dataset ) {
625629 chartUpdateBuffer = chartUpdateBuffer . concat ( parseData ( dataset ) ) ;
626- // console.log('buffer: '+chartUpdateBuffer.length);
627630 if ( initialread == 1 && myLine != undefined ) {
628631 chartUpdateBuffer . forEach ( function ( row , index ) {
629- // console.log('adding row: '+index);
630632 allChartData . push ( row ) ;
631633 } ) ;
632- // ToDo: remove data based on configured size
633- if ( allChartData . length > 30 ) {
634- allChartData . splice ( 0 , chartUpdateBuffer . length ) ;
634+ if ( typeof maxDisplayLength !== "undefined" && allChartData . length > maxDisplayLength ) {
635+ // allChartData.splice(0, chartUpdateBuffer.length);
636+ allChartData . splice ( 0 , allChartData . length - maxDisplayLength ) ;
635637 }
638+ console . log ( "allChartData.length: " + allChartData . length ) ;
636639 chartUpdateBuffer = [ ] ;
637640 myLine . update ( ) ;
638641 } else {
639- // console.log('graph not yet initialized, data stored in buffer');
642+ console . log ( 'graph not yet initialized, data stored in buffer' ) ;
640643 }
641644}
642645
643646function checkgraphload ( ) {
647+ console . log ( "checkgraphload: graphloaded: " + graphloaded + " initialread: " + initialread ) ;
644648 if ( graphloaded == 1 ) {
645649 myLine . destroy ( ) ;
646650 loadgraph ( 0 ) ; // when reloading graph, no more "pumping" animations
@@ -665,6 +669,7 @@ function checkgraphload(){
665669 typeof boolDisplayEvu === "boolean" &&
666670 typeof boolDisplayPv === "boolean" &&
667671 typeof boolDisplayLegend === "boolean" ) {
672+ console . log ( "all bools received" ) ;
668673 if ( initialread != 0 ) {
669674 if ( graphloaded == 0 ) {
670675 graphloaded = 1 ;
@@ -735,6 +740,10 @@ function forcegraphload() {
735740 if ( ! ( typeof boolDisplayLegend === "boolean" ) ) {
736741 showhidedataset ( 'boolDisplayLegend' ) ;
737742 }
743+ if ( typeof maxDisplayLength === "undefined" ) {
744+ console . log ( "setting graph duration to default of 30 minutes" ) ;
745+ maxDisplayLength = 30 * 6 ;
746+ }
738747 checkgraphload ( ) ;
739748 }
740749} // end forcegraphload
0 commit comments