From c7734b0ab3823bd5dc2263cadb7d468725bde021 Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Wed, 28 Sep 2022 14:13:28 +0000 Subject: [PATCH] 98_SVG.pm: add Attribute endPlotNowByHour (Forum #129182) git-svn-id: https://svn.fhem.de/fhem/trunk@26450 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_SVG.pm | 52 +++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/fhem/FHEM/98_SVG.pm b/fhem/FHEM/98_SVG.pm index de1e6066c..d8bda56b8 100644 --- a/fhem/FHEM/98_SVG.pm +++ b/fhem/FHEM/98_SVG.pm @@ -71,8 +71,9 @@ SVG_Initialize($) my @attrList = qw( captionLeft:1,0" captionPos:right,left,auto - endPlotNow - endPlotToday + endPlotNow:1,0 + endPlotNowByHour:1,0 + endPlotToday:1,0 fixedoffset fixedrange label @@ -1655,7 +1656,7 @@ SVG_render($$$$$$$$$$) # Compute & draw vertical tics, grid and labels my $ddur = ($tosec-$fromsec)/86400; my ($first_tag, $tag, $step, $tstep, $aligntext, $aligntics); - $aligntext = $aligntics = 0; + $aligntext = $aligntics = "none"; if($ddur <= 0.05) { $first_tag=". 2 1"; $tag=": 3 4"; $step = 300; $tstep = 60; @@ -1668,17 +1669,19 @@ SVG_render($$$$$$$$$$) } elsif($ddur <= 1.1) { # +0.1 -> DST $first_tag=". 2 1"; $tag=": 3 4"; $step = 4*3600; $tstep = 3600; + $aligntext = $aligntics = "hour" + if(SVG_Attr($parent_name, $name, "endPlotNowByHour", undef)); } elsif ($ddur <= 7.1) { $first_tag=". 6"; $tag=". 2 1"; $step = 24*3600; $tstep = 6*3600; } elsif ($ddur <= 31.1) { $first_tag=". 6"; $tag=". 2 1"; $step = 7*24*3600; $tstep = 24*3600; - $aligntext = 1; + $aligntext = "week"; } elsif ($ddur <= 732.1) { $first_tag=". 6"; $tag=". 1"; $step = 28*24*3600; $tstep = 28*24*3600; - $aligntext = 2; $aligntics = 2; + $aligntext = $aligntics = "month"; } else { $step = (($ddur / 365.2425) / 20) * 365 * 86400; @@ -1687,7 +1690,7 @@ SVG_render($$$$$$$$$$) } $tstep = $step; $first_tag=""; $tag=". 6"; - $aligntext = 3; $aligntics = 3; + $aligntext = $aligntics = "year"; } my $barwidth = $tstep; @@ -1770,7 +1773,7 @@ SVG_render($$$$$$$$$$) } else { # times for(my $i = $fromsec; $i < $tosec; $i += $step) { $i = SVG_time_align($i,$aligntext); - if($aligntext >= 2) { # center month and year + if($aligntext eq "month" || $aligntext eq "year") { # center $off1 = int($x+($i-$fromsec+$step/2)*$tmul); } else { $off1 = int($x+($i-$fromsec)*$tmul); @@ -2416,29 +2419,36 @@ sub SVG_time_align($$) { my ($v,$align) = @_; - my $wl = $FW_webArgs{detail}; - return $v if(!$align); - if($align == 1) { # Look for the beginning of the week + return $v if($align eq "none"); + + # Look for the beginning of the next ... + if($align eq "hour") { + return int(($v+(3600-60))/3600)*3600; + + } elsif($align eq "week") { + my $wl = $FW_webArgs{detail}; for(;;) { my @a = localtime($v); return $v if($a[6] == SVG_Attr($FW_wname, $wl, "plotWeekStartDay", 0)); $v += 86400; } - } - if($align == 2) { # Look for the beginning of the month + + } elsif($align eq "month") { for(;;) { my @a = localtime($v); return $v if($a[3] == 1); $v += 86400; } - } - if($align == 3) { # Look for the beginning of the year + + } elsif($align eq "year") { for(;;) { my @a = localtime($v); return $v if($a[7] == 0); $v += 86400; } } + + return $v; } sub @@ -2601,6 +2611,13 @@ plotAsPng(@) is not used if the SVG has the attribute startDate defined.
+ +
  • endPlotNowByHour
    + If endPlotNow and this attribute are set to 1 and the zoom-level is + "day", then the displayed hour ticks will be rounded to the complete + hour. +

  • +
  • endPlotToday
    If this attribute is set to 1, then week and month plots will @@ -2897,6 +2914,13 @@ plotAsPng(@) Attribut startDate benutzt wird.

  • + +
  • endPlotNowByHour
    + Falls endPlotNow und dieses Attribut auf 1 gesetzt sind, und Zoom-Level + ein Tag ist, dann werden die angezeigten Zeitmarker auf die volle + Stunde gerundet. +

  • +
  • endPlotToday
    Wird dieses Attribut gesetzt, so enden Wochen- bzw. Monatsplots