From c5ca57af7ec80def21a4055a987502c96e650ebc Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Tue, 13 Mar 2018 20:48:41 +0000
Subject: [PATCH] 98_SVG.pm: 10year/20year zoomlevel by simonberry (Forum
#85687)
git-svn-id: https://svn.fhem.de/fhem/trunk@16401 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/98_SVG.pm | 75 +++++++++++++++++++++++++++++++--------------
1 file changed, 52 insertions(+), 23 deletions(-)
diff --git a/fhem/FHEM/98_SVG.pm b/fhem/FHEM/98_SVG.pm
index 0ae5b002e..249ba5cc1 100644
--- a/fhem/FHEM/98_SVG.pm
+++ b/fhem/FHEM/98_SVG.pm
@@ -596,7 +596,7 @@ SVG_zoomLink($$$)
if($d eq "zoom") {
my $n = 0;
- my @FW_zoom = ("hour","qday","day","week","month","year");
+ my @FW_zoom=("hour","qday","day","week","month","year","10years","20years");
my %FW_zoom = map { $_, $n++ } @FW_zoom;
$val = "day" if(!$val);
@@ -621,6 +621,10 @@ SVG_zoomLink($$$)
$w_off = ($off < 0) ? $w_off*12: int($w_off/4);
} elsif($val eq "year") {
$w_off = int($w_off/12);
+ } elsif($val eq "10years") {
+ $w_off = int($w_off/120);
+ } elsif($val eq "20years") {
+ $w_off = int($w_off/240);
}
$cmd .= "zoom=$val;off=$w_off";
@@ -934,7 +938,8 @@ SVG_calcOffsets($$)
$fr = AttrVal($wl, "fixedrange", undef);
if($fr) {
if($fr =~ "^(hour|qday|day|week|month|year)" ||
- $fr =~ m/^\d+days$/ ) { #fixedrange with offset
+ $fr =~ m/^\d+days$/ || #fixedrange with offset
+ $fr =~ m/^\d+years$/ ) { #fixedrange with offset
$frx=$fr; #fixedrange with offset
} else {
@@ -1054,24 +1059,33 @@ SVG_calcOffsets($$)
$SVG_devs{$d}{from} = SVG_tspec( 0, 0, 0,$sd,$sm,$sy);
$SVG_devs{$d}{to} = SVG_tspec(59,59,23,$ed,$em,$ey);
- } elsif($zoom eq "year") {
+ } elsif($zoom =~ m/^(\d+)?year/) {
+ my $nyear = $1 ? ($1-1) : 0;
my @l = localtime($now);
$l[5] += ($off-1);
- if(SVG_Attr($FW_wname, $wl, "endPlotToday", undef)) {
- $SVG_devs{$d}{from} = SVG_tspec( 0, 0, 0,$l[3],$l[4],$l[5]);
+ if ($st) { #
+ $l[5]++;
+ $SVG_devs{$d}{from} = SVG_tspec( 0, 0, 0, 1, 0,$l[5] ); #Jan01 00:00:00
+ $SVG_devs{$d}{to} = SVG_tspec(59,59,23,31,11,$l[5]+$nyear);
+
+ } elsif(SVG_Attr($FW_wname, $wl, "endPlotToday", undef)) {
+ $SVG_devs{$d}{from} = SVG_tspec( 0, 0, 0,$l[3],$l[4],$l[5] - $nyear);
$l[5]++; # today, 23:59
$SVG_devs{$d}{to} = SVG_tspec(59,59,23,$l[3],$l[4],$l[5]);
} elsif(SVG_Attr($FW_wname, $wl, "endPlotNow", undef)) {
- $SVG_devs{$d}{from} = SVG_tspec(0, $l[0], @l);
- $SVG_devs{$d}{from} = SVG_tspec(@l);
+ #$SVG_devs{$d}{from} = SVG_tspec(0, $l[0], @l);
+ $SVG_devs{$d}{from} = SVG_tspec($l[0], $l[1], $l[2],$l[3],$l[4],
+ $l[5] - $nyear);
+ #$SVG_devs{$d}{from} = SVG_tspec(@l);
$l[5]++; # now
$SVG_devs{$d}{to} = SVG_tspec(@l);
} else {
$l[5]++;
- $SVG_devs{$d}{from} = SVG_tspec( 0, 0, 0, 1, 0,$l[5]); #Jan01 00:00:00
+ $SVG_devs{$d}{from} = SVG_tspec( 0, 0, 0, 1, 0,$l[5]-$nyear);
$SVG_devs{$d}{to} = SVG_tspec(59,59,23,31,11,$l[5]); #Dec31 23:59:59
+
}
}
}
@@ -1599,18 +1613,32 @@ SVG_render($$$$$$$$$$)
if($ddur <= 0.1) {
$first_tag=". 2 1"; $tag=": 3 4"; $step = 300; $tstep = 60;
+
} elsif($ddur <= 0.5) {
$first_tag=". 2 1"; $tag=": 3 4"; $step = 3600; $tstep = 900;
+
} elsif($ddur <= 1.1) { # +0.1 -> DST
$first_tag=". 2 1"; $tag=": 3 4"; $step = 4*3600; $tstep = 3600;
+
} 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;
- } else {
+
+ } elsif ($ddur <= 732.1) {
$first_tag=". 6"; $tag=". 1"; $step = 28*24*3600; $tstep = 28*24*3600;
$aligntext = 2; $aligntics = 2;
+
+ } else {
+ $step = (($ddur / 365.2425) / 20) * 365 * 86400;
+ if($step < 365 * 86400) {
+ $step = 365 * 86400;
+ }
+ $tstep = $step;
+ $first_tag=""; $tag=". 6";
+ $aligntext = 2; $aligntics = 2;
}
my $barwidth = $tstep;
@@ -2493,11 +2521,11 @@ plotAsPng(@)
In plotmode gnuplot-scroll(-svg) or SVG the given time-range will be
used, and no scrolling for this SVG will be possible. Needed e.g. for
looking at last-years data without scrolling.
If the value is
- one of hour, day, <N>days, week, month, year then set the zoom
- level for this SVG independently of the user specified zoom-level. This
- is useful for pages with multiple plots: one of the plots is best
- viewed in with the default (day) zoom, the other one with a week
- zoom.
+ one of hour, day, <N>days, week, month, year, <N>years then
+ set the zoom level for this SVG independently of the user specified
+ zoom-level. This is useful for pages with multiple plots: one of the
+ plots is best viewed in with the default (day) zoom, the other one with
+ a week zoom.
If given, the optional integer parameter offset refers to a different
period (e.g. last year: fixedrange year -1, 2 days ago: fixedrange day
@@ -2724,14 +2752,15 @@ plotAsPng(@)
Jahre auf eine Seite anzusehen.
Zweite Alternative:
- Wenn der Wert entweder hour, day, <N>days, week, month oder year
- lautet, kann der Zoom-Level für dieses SVG unabhängig vom
- User-spezifischen Zoom eingestellt werden. Diese Einstellung ist
- nützlich für mehrere Plots auf einer Seite: Eine Grafik ist mit
- dem Standard-Zoom am aussagekräftigsten, die anderen mit einem Zoom
- über eine Woche. Der optionale ganzzahlige Parameter [offset] setzt
- ein anderes Zeitintervall (z.B. letztes Jahr: fixedrange year
- -1
, vorgestern: fixedrange day -2
).
+ Wenn der Wert entweder hour, day, <N>days, week, month, year oder
+ <N>years lautet, kann der Zoom-Level für dieses SVG
+ unabhängig vom User-spezifischen Zoom eingestellt werden. Diese
+ Einstellung ist nützlich für mehrere Plots auf einer Seite:
+ Eine Grafik ist mit dem Standard-Zoom am aussagekräftigsten, die
+ anderen mit einem Zoom über eine Woche. Der optionale ganzzahlige
+ Parameter [offset] setzt ein anderes Zeitintervall (z.B. letztes Jahr:
+ fixedrange year -1
, vorgestern:
+ fixedrange day -2
).
@@ -2873,7 +2902,7 @@ plotAsPng(@)
Expression ausgewertet. Das Ergebnis muss in der Form [min:max] sein.
- Die sichtbarkeit des Plot-Editors kann mit dem FHEMWEB Attribut ploteditor konfiguriert werden.