@@ -26,6 +26,7 @@ var smartHomeBgColor = style.getPropertyValue('--d1bgCol');
26
26
27
27
var initialread = 0 ;
28
28
var graphloaded = 0 ;
29
+ var maxDisplayLength ;
29
30
var boolDisplayHouseConsumption ;
30
31
var boolDisplayLoad1 ;
31
32
var boolDisplayLoad2 ;
@@ -585,7 +586,9 @@ function putgraphtogether() {
585
586
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 ) ) {
586
587
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 ;
587
588
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" ) ;
589
592
Object . keys ( allChartData [ allChartData . length - 1 ] ) . forEach ( function ( key ) {
590
593
if ( key != 'time' && key != 'timestamp' ) {
591
594
initDataset ( key ) ;
@@ -594,9 +597,10 @@ function putgraphtogether() {
594
597
// after receipt of all data segments, unsubscribe from these topics to save bandwidth
595
598
unsubscribeMqttGraphSegments ( ) ;
596
599
600
+ initialread = 1 ;
601
+ $ ( '#waitforgraphloadingdiv' ) . text ( 'Graph lädt...' ) ;
597
602
checkgraphload ( ) ;
598
603
// now we are ready to receive small updates for graph data
599
- initialread = 1 ;
600
604
} else {
601
605
all1 = 0 ;
602
606
all2 = 0 ;
@@ -623,24 +627,24 @@ function putgraphtogether() {
623
627
624
628
function updateGraph ( dataset ) {
625
629
chartUpdateBuffer = chartUpdateBuffer . concat ( parseData ( dataset ) ) ;
626
- // console.log('buffer: '+chartUpdateBuffer.length);
627
630
if ( initialread == 1 && myLine != undefined ) {
628
631
chartUpdateBuffer . forEach ( function ( row , index ) {
629
- // console.log('adding row: '+index);
630
632
allChartData . push ( row ) ;
631
633
} ) ;
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 ) ;
635
637
}
638
+ console . log ( "allChartData.length: " + allChartData . length ) ;
636
639
chartUpdateBuffer = [ ] ;
637
640
myLine . update ( ) ;
638
641
} else {
639
- // console.log('graph not yet initialized, data stored in buffer');
642
+ console . log ( 'graph not yet initialized, data stored in buffer' ) ;
640
643
}
641
644
}
642
645
643
646
function checkgraphload ( ) {
647
+ console . log ( "checkgraphload: graphloaded: " + graphloaded + " initialread: " + initialread ) ;
644
648
if ( graphloaded == 1 ) {
645
649
myLine . destroy ( ) ;
646
650
loadgraph ( 0 ) ; // when reloading graph, no more "pumping" animations
@@ -665,6 +669,7 @@ function checkgraphload(){
665
669
typeof boolDisplayEvu === "boolean" &&
666
670
typeof boolDisplayPv === "boolean" &&
667
671
typeof boolDisplayLegend === "boolean" ) {
672
+ console . log ( "all bools received" ) ;
668
673
if ( initialread != 0 ) {
669
674
if ( graphloaded == 0 ) {
670
675
graphloaded = 1 ;
@@ -735,6 +740,10 @@ function forcegraphload() {
735
740
if ( ! ( typeof boolDisplayLegend === "boolean" ) ) {
736
741
showhidedataset ( 'boolDisplayLegend' ) ;
737
742
}
743
+ if ( typeof maxDisplayLength === "undefined" ) {
744
+ console . log ( "setting graph duration to default of 30 minutes" ) ;
745
+ maxDisplayLength = 30 * 6 ;
746
+ }
738
747
checkgraphload ( ) ;
739
748
}
740
749
} // end forcegraphload
0 commit comments