FHEM Forum

FHEM => Frontends => SVG / Plots / logProxy => Thema gestartet von: Nobbynews am 23 Januar 2021, 09:48:02

Titel: Fehler in Beschriftung
Beitrag von: Nobbynews am 23 Januar 2021, 09:48:02
Guten Morgen zusammen,

mir ist heute Morgen aufgefallen, dass es bei einem SVG-Plot zu einem Fehler in der Beschriftung kommt.
Ich habe folgendes SVG Plot-File definiert:
Created by FHEM/98_SVG.pm, 2021-01-16 13:50:46
set terminal png transparent size <SIZE> crop
set output '<OUT>.png'
set xdata time
set timefmt "%Y-%m-%d_%H:%M:%S"
set xlabel " "
set title '<L1>'
set ytics
set y2tics
set grid ytics
set ylabel "kWh"
set y2label "kWh"

#lp FileLog:Tagesverbrauch3:4:Shelly3.Verbrauch
#lp ConstY:$data{avg1}
#lp FileLog:VDurchschnitt3:4:Shelly3.VDurchschnitt

plot "<IN>" using 1:2 axes x1y2 title 'Tagesverbrauch' ls l0 lw 1 with lines,\
     "<IN>" using 1:2 axes x1y2 title 'Jahresdurchschnitt' ls l3 lw 1 with lines,\
     "<IN>" using 1:2 axes x1y2 title 'VDurchschnitt' ls l1 lw 1 with lines


Das Plot-Device ist mit dem Attribut fixedrange 370days definiert als:
Internals:
   DEF        Tagesverbrauch3:SVG_Tagesverbrauch3_2:CURRENT
   FUUID      5e22e7f9-f33f-8873-fc63-e49cbaa9e9b63b0e
   FVERSION   98_SVG.pm:0.234800/2021-01-06
   GPLOTFILE  SVG_Tagesverbrauch3_2
   LOGDEVICE  Tagesverbrauch3
   LOGFILE    CURRENT
   NAME       SVG_Tagesverbrauch3_2
   NR         297
   STATE      initialized
   TYPE       SVG
Attributes:
   captionPos auto
   fixedrange 370days
   label      "Tagesverbrauch Waschmaschine, Jahresdurchschnitt  ".sprintf("%.3f",$data{avg1})." kWh/d"
   plotsize   1000,200
   room       05_Tagesverbrauch


Die zugehörige Log-Datei ist mit dem Attribut createGluedFile wie folgt definiert:
Internals:
   DEF        /Festplatte/FHEM/log/Tagesverbrauch3-%Y.log (Shelly3.Verbrauch:.*|Shelly3:state:t)
   FD         72
   FUUID      5e21d184-f33f-8873-1d08-a06e3932406a765c
   FVERSION   92_FileLog.pm:0.231380/2020-11-11
   NAME       Tagesverbrauch3
   NR         290
   NTFY_ORDER 50-Tagesverbrauch3
   REGEXP     (Shelly3.Verbrauch:.*|Shelly3:state:t)
   STATE      active
   TYPE       FileLog
   currentlogfile /Festplatte/FHEM/log/Tagesverbrauch3-2021.log
   logfile    /Festplatte/FHEM/log/Tagesverbrauch3-%Y.log
   READINGS:
     2021-01-22 23:59:00   linesInTheFile  22
   pos:
     /Festplatte/FHEM/log/Tagesverbrauch3-2020.log.transit.temp.log:2020-01-18_00:00:00 0
     /Festplatte/FHEM/log/Tagesverbrauch3-2020.log.transit.temp.log:2020-01-19_00:00:00 46
     /Festplatte/FHEM/log/Tagesverbrauch3-2020.log.transit.temp.log:2020-01-20_00:00:00 92
Attributes:
   createGluedFile 1
   room       Log-Files->Shelly


Bis zum 21.1. wurde die Skalierung für die Monate einschließlich des Februars korrekt dargestellt (siehe Bild 20210121_SVG_Plot.jpg).
Seit dem 22.1. wird der Februar jedoch geschluckt und dafür am Anfang des Plots mit einem größeren Zeitraum erst ab März beschriftet (siehe Bild 20210123_SVG_Plot.jpg).

Norbert
Titel: Antw:Fehler in Beschriftung
Beitrag von: rudolfkoenig am 23 Januar 2021, 10:48:23
Zitatmir ist heute Morgen aufgefallen, dass es bei einem SVG-Plot zu einem Fehler in der Beschriftung kommt.
Ob das jetzt ein Fehler oder eine Designentscheidung ist (kein Text in die Ecke draengen), ist mAn Ansichtssache.
Titel: Antw:Fehler in Beschriftung
Beitrag von: Nobbynews am 23 Januar 2021, 10:59:07
Zitat von: rudolfkoenig am 23 Januar 2021, 10:48:23
Ob das jetzt ein Fehler oder eine Designentscheidung ist (kein Text in die Ecke draengen), ist mAn Ansichtssache.
Ob Fehler oder nicht, kann ich eigentlich gar nicht sagen. Auf jeden Fall eine Auffälligkeit und in der Tat eher ein "Schönheitsfehler".
Ist der Zusammenhang so, dass bei entfallender Bezeichnung dann auch automatisch die vertikale Bezugslinie entfällt?
Titel: Antw:Fehler in Beschriftung
Beitrag von: rudolfkoenig am 23 Januar 2021, 11:38:22
ZitatIst der Zusammenhang so, dass bei entfallender Bezeichnung dann auch automatisch die vertikale Bezugslinie entfällt?
Wenn man das Bild anschaut, scheint das der Fall zu sein.
Anders ausgedrueckt: ich weiss es nicht auswendig, und will jetzt deswegen nicht 100k an Perl-Code analysieren.
Das steht aber jedem frei.
Titel: Antw:Fehler in Beschriftung
Beitrag von: Nobbynews am 24 Januar 2021, 07:26:32
Zitat von: rudolfkoenig am 23 Januar 2021, 11:38:22
und will jetzt deswegen nicht 100k an Perl-Code analysieren.
Das kann ich sehr gut nachvollziehen.
Alles OK.
Titel: Antw:Fehler in Beschriftung
Beitrag von: gichtl am 13 Februar 2021, 12:36:33
Das fällt an einem weiteren Beispiel noch deutlicher auf:

Bei Tages- und Wochenplots beginnt die Beschriftung im Schnittpunkt mit der Y-Achse, also bei "00:00 Uhr" bzw "7. Feb". Bei Monats- und Jahresplots fehlt die erste Beschriftung und es wird immer erst ab dem zweiten Intervall beschriftet, also ab "Feb". Die Beschriftung "Jan" rutscht hinter das Diagrammende ins Folgejahr, wofür es aber gar keine Datenpunkte in der Ansicht gibt.
Titel: Antw:Fehler in Beschriftung
Beitrag von: gichtl am 16 Februar 2021, 16:33:10
Der folgende Patch behebt das Darstellungsproblem:


diff U3 a/98_SVG.pm b/98_SVG.pm
--- a/98_SVG_org.pm
+++ b/98_SVG.pm Sat
@@ -1643,7 +1643,7 @@
     }
     $tstep = $step;
     $first_tag="";   $tag=". 6";
-    $aligntext = 2; $aligntics = 2;
+    $aligntext = 3; $aligntics = 3;
   }

   my $barwidth = $tstep;
@@ -1666,12 +1666,14 @@
     }

   } else { # times
-    $initoffset = int(($tstep/2)/86400)*86400 if($aligntics);
-    for(my $i = $fromsec+$initoffset; $i < $tosec; $i += $tstep) {
+    for(my $i = $fromsec; $i < $tosec; $i += $tstep) {
       $i = SVG_time_align($i,$aligntics);
       $off1 = int($x+($i-$fromsec)*$tmul);
-      SVG_pO "<polyline class='SVGplot' points='$off1,$y $off1,$off2'/>";
-      SVG_pO "<polyline class='SVGplot' points='$off1,$off3 $off1,$off4'/>";
+      if ($off1 > $x+8 && $off1 < $x+$w-8)
+      {
+        SVG_pO "<polyline class='SVGplot' points='$off1,$y $off1,$off2'/>";
+        SVG_pO "<polyline class='SVGplot' points='$off1,$off3 $off1,$off4'/>";
+      }
     }

   }
@@ -1682,7 +1684,7 @@
   $off2 = $y+$h+$th;
   $isDE = (AttrVal("global", "language","EN") eq "DE");
   my $t = SVG_fmtTime($first_tag, $fromsec);
-  SVG_pO "<text x=\"0\" y=\"$off2\" class=\"ylabel\">$t</text>"
+  SVG_pO "<text x=\"0\" y=\"$off2\" class=\"xlabel\">$t</text>"
         if(!$conf{xrange});
   $initoffset = $step;

@@ -1703,9 +1705,9 @@

         $off1 = int($x+($tvalue-$xmin)*$xmul);
         $t = $tvalue;
-        SVG_pO "<text x=\"$off1\" y=\"$off2\" class=\"ylabel\" " .
+        SVG_pO "<text x=\"$off1\" y=\"$off2\" class=\"xlabel\" " .
                   "text-anchor=\"middle\">$t</text>";
-        SVG_pO "  <polyline points=\"$off1,$y $off1,$off4\" class=\"hgrid\"/>";
+        SVG_pO "  <polyline points=\"$off1,$y $off1,$off4\" class=\"vgrid\"/>";
       }

     } else { # auto grid
@@ -1714,23 +1716,28 @@
       for(my $i = $mi; $i <= $ma; $i += $step) {
         $off1 = int($x+($i-$xmin)*$xmul);
         $t = $i;
-        SVG_pO "<text x=\"$off1\" y=\"$off2\" class=\"ylabel\" " .
+        SVG_pO "<text x=\"$off1\" y=\"$off2\" class=\"xlabel\" " .
                   "text-anchor=\"middle\">$t</text>";
-        SVG_pO "  <polyline points=\"$off1,$y $off1,$off4\" class=\"hgrid\"/>"
+        SVG_pO "  <polyline points=\"$off1,$y $off1,$off4\" class=\"vgrid\"/>"
                 if( $i != $mi && $i != $ma );
       }

     }

   } else { # times
-    $initoffset = int(($step/2)/86400)*86400 if($aligntext);
-    for(my $i = $fromsec+$initoffset; $i < $tosec; $i += $step) {
+    for(my $i = $fromsec; $i < $tosec; $i += $step) {
       $i = SVG_time_align($i,$aligntext);
       $off1 = int($x+($i-$fromsec)*$tmul);
       $t = SVG_fmtTime($tag, $i);
-      SVG_pO "<text x=\"$off1\" y=\"$off2\" class=\"ylabel\" " .
-                "text-anchor=\"middle\">$t</text>";
+      if ($off1 < $x+$w-8)
+      {
+        SVG_pO "<text x=\"$off1\" y=\"$off2\" class=\"ylabel\" " .
+                  "text-anchor=\"middle\">$t</text>";
+      }
+      if ($off1 > $x+8 && $off1 < $x+$w-8)
+      {     
       SVG_pO "  <polyline points=\"$off1,$y $off1,$off4\" class=\"hgrid\"/>";
+      }
     }
   }

@@ -1845,10 +1852,10 @@
         #--grids
         my $off6 = $x+$w;
         if( ($a eq "x1y1") && $conf{hasygrid} )  {
-          SVG_pO "<polyline points=\"$x,$off2 $off6,$off2\" class=\"vgrid\"/>"
+          SVG_pO "<polyline points=\"$x,$off2 $off6,$off2\" class=\"hgrid\"/>"
             if($tvalue > $hmin{$a} && $tvalue < $hmax{$a});
         }elsif( ($a eq "x1y2") && $conf{hasy2grid} )  {
-          SVG_pO "  <polyline points=\"$x,$off2 $off6,$off2\" class=\"vgrid\"/>"
+          SVG_pO "  <polyline points=\"$x,$off2 $off6,$off2\" class=\"hgrid\"/>"
             if($tvalue > $hmin{$a} && $tvalue < $hmax{$a});
         }
         $off2 += $th/4;
@@ -1867,10 +1874,10 @@
         my $off6 = $x+$w;
         if( ($a eq "x1y1") && $conf{hasygrid} )  {
           my $off6 = $x+$w;
-          SVG_pO "  <polyline points=\"$x,$off2 $off6,$off2\" class=\"vgrid\"/>"
+          SVG_pO "  <polyline points=\"$x,$off2 $off6,$off2\" class=\"hgrid\"/>"
             if($i > $hmin{$a} && $i < $hmax{$a});
         }elsif(  ($a eq "x1y2") && $conf{hasy2grid} )  {
-          SVG_pO "  <polyline points=\"$x,$off2 $off6,$off2\" class=\"vgrid\"/>"
+          SVG_pO "  <polyline points=\"$x,$off2 $off6,$off2\" class=\"hgrid\"/>"
             if($i > $hmin{$a} && $i < $hmax{$a});
         }
         $off2 += $th/4;
@@ -2380,6 +2388,13 @@
       $v += 86400;
     }
   }
+  if($align == 3) {             # Look for the beginning of the year
+    for(;;) {
+      my @a = localtime($v);
+      return $v if($a[7] == 0);
+      $v += 86400;
+    }
+  }
}

sub