2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-15 16:19:11 +00:00

SVG: added new styles

git-svn-id: https://svn.fhem.de/fhem/trunk@4275 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-11-23 14:25:15 +00:00
parent b76991bf6d
commit e90b734d3d
3 changed files with 108 additions and 68 deletions

View File

@ -37,6 +37,7 @@ sub SVG_showLog($);
sub SVG_substcfg($$$$$$);
sub SVG_time_align($$);
sub SVG_time_to_sec($);
sub SVG_openFile($$$);
my ($SVG_lt, $SVG_ltstr);
my %SVG_devs; # hash of from/to entries per device
@ -269,6 +270,13 @@ SVG_PEdit($$$$)
$ret .= "<td>$desc</td>";
$ret .=" <td>Y-Axis,Plot-Type,Style,Width</td></tr>";
my @lineStyles;
if(SVG_openFile($FW_cssdir,
AttrVal($FW_wname,"stylesheetPrefix",""), "svg_style.css")) {
map { push(@lineStyles,$1) if($_ =~ m/^\.(l[^{ ]*)/) } <FH>;
close(FH);
}
my $r = 0;
for($r=0; $r < $max; $r++) {
$ret .= "<tr class=\"".(($r&1)?"odd":"even")."\"><td>";
@ -287,8 +295,7 @@ SVG_PEdit($$$$)
$ls =~ s/class=//g;
$ls =~ s/"//g;
}
$ret .= SVG_sel("style_${r}", "l0,l1,l2,l3,l4,l5,l6,l7,l8,".
"l0fill,l1fill,l2fill,l3fill,l4fill,l5fill,l6fill", $ls);
$ret .= SVG_sel("style_${r}", join(",", @lineStyles), $ls);
my $lw = $conf{lWidth}[$r];
if($lw) {
$lw =~ s/.*stroke-width://g;
@ -593,68 +600,68 @@ SVG_calcOffsets($$)
if(AttrVal($FW_wname, "endPlotNow", undef) && !$st) {
my $t = int(($now + $off*3600 - 3600)/300.0)*300 + 300;
my @l = localtime($t);
$SVG_devs{$d}{from} =
sprintf("%04d-%02d-%02d_%02d:%02d:00",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
$SVG_devs{$d}{from} = sprintf("%04d-%02d-%02d_%02d:%02d:00",
$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
@l = localtime($t+3600);
$SVG_devs{$d}{to} =
sprintf("%04d-%02d-%02d_%02d:%02d:01",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
$SVG_devs{$d}{to} = sprintf("%04d-%02d-%02d_%02d:%02d:01",
$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
} else {
my $t = $now + $off*3600;
my @l = localtime($t);
$SVG_devs{$d}{from}
= sprintf("%04d-%02d-%02d_%02d:00:00",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
$SVG_devs{$d}{from} = sprintf("%04d-%02d-%02d_%02d:00:00",
$l[5]+1900,$l[4]+1,$l[3],$l[2]);
@l = localtime($t+3600);
$SVG_devs{$d}{to}
= sprintf("%04d-%02d-%02d_%02d:00:01",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
$SVG_devs{$d}{to} = sprintf("%04d-%02d-%02d_%02d:00:01",
$l[5]+1900,$l[4]+1,$l[3],$l[2]);
}
} elsif($zoom eq "qday") {
if(AttrVal($FW_wname, "endPlotNow", undef) && !$st) {
my $t = int(($now + $off*21600 - 21600)/300.0)*300 + 300;
my @l = localtime($t);
$SVG_devs{$d}{from} =
sprintf("%04d-%02d-%02d_%02d:%02d:00",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
$SVG_devs{$d}{from} = sprintf("%04d-%02d-%02d_%02d:%02d:00",
$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
@l = localtime($t+21600);
$SVG_devs{$d}{to} =
sprintf("%04d-%02d-%02d_%02d:%02d:01",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
$SVG_devs{$d}{to} = sprintf("%04d-%02d-%02d_%02d:%02d:01",
$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
} else {
my $t = $now + $off*21600;
my @l = localtime($t);
$l[2] = int($l[2]/6)*6;
$SVG_devs{$d}{from} =
sprintf("%04d-%02d-%02d_%02d:00:00",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
$SVG_devs{$d}{from} = sprintf("%04d-%02d-%02d_%02d:00:00",
$l[5]+1900,$l[4]+1,$l[3],$l[2]);
@l = localtime($t+21600);
$l[2] = int($l[2]/6)*6;
$SVG_devs{$d}{to} =
sprintf("%04d-%02d-%02d_%02d:00:01",$l[5]+1900,$l[4]+1,$l[3],$l[2]);
$SVG_devs{$d}{to} = sprintf("%04d-%02d-%02d_%02d:00:01",
$l[5]+1900,$l[4]+1,$l[3],$l[2]);
}
} elsif($zoom eq "day") {
if(AttrVal($FW_wname, "endPlotNow", undef) && !$st) {
my $t = int(($now + $off*86400 - 86400)/900.0)*900 + 900;
my @l = localtime($t);
$SVG_devs{$d}{from} =
sprintf("%04d-%02d-%02d_%02d:%02d:00",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
$SVG_devs{$d}{from} = sprintf("%04d-%02d-%02d_%02d:%02d:00",
$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
@l = localtime($t+86400);
$SVG_devs{$d}{to} =
sprintf("%04d-%02d-%02d_%02d:%02d:01",$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
$SVG_devs{$d}{to} = sprintf("%04d-%02d-%02d_%02d:%02d:01",
$l[5]+1900,$l[4]+1,$l[3],$l[2],$l[1]);
} else {
my $t = $now + $off*86400;
my @l = localtime($t);
$SVG_devs{$d}{from} =
sprintf("%04d-%02d-%02d_00:00:00",$l[5]+1900,$l[4]+1,$l[3]);
$SVG_devs{$d}{from} = sprintf("%04d-%02d-%02d_00:00:00",
$l[5]+1900,$l[4]+1,$l[3]);
@l = localtime($t+86400);
$SVG_devs{$d}{to} =
sprintf("%04d-%02d-%02d_00:00:01",$l[5]+1900,$l[4]+1,$l[3]);
$SVG_devs{$d}{to} = sprintf("%04d-%02d-%02d_00:00:01",
$l[5]+1900,$l[4]+1,$l[3]);
}
} elsif($zoom eq "week") {
my @l = localtime($now);
my $start = (AttrVal($FW_wname, "endPlotToday", undef) ? 6 : $l[6]);
my $t = $now - ($start*86400) + ($off*86400)*7;
@l = localtime($t);
$SVG_devs{$d}{from} =
sprintf("%04d-%02d-%02d_00:00:00",$l[5]+1900,$l[4]+1,$l[3]);
$SVG_devs{$d}{from} = sprintf("%04d-%02d-%02d_00:00:00",
$l[5]+1900,$l[4]+1,$l[3]);
@l = localtime($t+7*86400);
$SVG_devs{$d}{to} =
sprintf("%04d-%02d-%02d_00:00:01",$l[5]+1900,$l[4]+1,$l[3]);
$SVG_devs{$d}{to} = sprintf("%04d-%02d-%02d_00:00:01",
$l[5]+1900,$l[4]+1,$l[3]);
} elsif($zoom eq "month") {
my ($endDay, @l);
@ -874,6 +881,20 @@ SVG_digestConf($$)
return %conf;
}
sub
SVG_openFile($$$)
{
my ($dir, $prf, $fName) = @_;
my $baseStyle = $prf;
$baseStyle =~ s/(touchpad|smallscreen)//;
if(open(FH, "$dir/${prf}$fName") ||
open(FH, "$dir/${baseStyle}$fName") ||
open(FH, "$dir/$fName")) {
return 1;
}
return 0;
}
#####################################
sub
SVG_render($$$$$$$$$)
@ -917,12 +938,8 @@ SVG_render($$$$$$$$$)
'xmlns:xlink="http://www.w3.org/1999/xlink" '.$flog.'>';
my $prf = AttrVal($parent_name, "stylesheetPrefix", "");
my $baseStyle = $prf; $baseStyle =~ s/(touchpad|smallscreen)//;
SVG_pO "<style type=\"text/css\"><![CDATA[";
if(open(FH, "$parent_dir/${prf}svg_style.css") ||
open(FH, "$parent_dir/${baseStyle}svg_style.css") ||
open(FH, "$parent_dir/svg_style.css")) {
if(SVG_openFile($parent_dir, $prf, "svg_style.css")) {
SVG_pO join("", <FH>);
close(FH);
} else {
@ -932,9 +949,7 @@ SVG_render($$$$$$$$$)
######################
# gradient definitions
if(open(FH, "$parent_dir/${prf}svg_defs.svg") ||
open(FH, "$parent_dir/${baseStyle}svg_defs.svg") ||
open(FH, "$parent_dir/svg_defs.svg")) {
if(SVG_openFile($parent_dir, $prf, "svg_defs.svg")) {
SVG_pO join("", <FH>);
close(FH);
} else {

View File

@ -40,4 +40,21 @@
<stop offset="100%" style="stop-color:#ccc; stop-opacity:.4"/>
</linearGradient>
<pattern id="gr0_stripe" width="4" height="4"
patternUnits="userSpaceOnUse" patternTransform="rotate(-45 2 2)">
<path d="M -1,2 l 6,0" stroke="#f00" stroke-width="0.5"/>
</pattern>
<pattern id="gr1_stripe" width="4" height="4"
patternUnits="userSpaceOnUse" patternTransform="rotate(45 2 2)">
<path d="M -1,2 l 6,0" stroke="green" stroke-width="0.5"/>
</pattern>
<linearGradient id="gr0_gyr" x1="0%" y1="0%" x2="0%" y2="100%">
<stop offset= "0%" style="stop-color:#f00; stop-opacity:.6"/>
<stop offset= "50%" style="stop-color:#ff0; stop-opacity:.6"/>
<stop offset="100%" style="stop-color:#0f0; stop-opacity:.6"/>
</linearGradient>
</defs>

View File

@ -1,30 +1,38 @@
.background { fill:#FFFFE7; font-opacity: 0; }
text { font-family:Times; font-size:12px; }
text.title { font-size:16px; }
text.copy { text-decoration:underline; stroke:none; fill:blue; }
text.paste { text-decoration:underline; stroke:none; fill:blue; }
polyline { stroke:black; fill:none; }
.border { stroke:black; fill:url(#gr_bg); }
.vgrid { stroke:gray; stroke-dasharray:2,6; }
.hgrid { stroke:gray; stroke-dasharray:2,6; }
.pasted { stroke:black; stroke-dasharray:1,1; }
.l0 { stroke:red; } text.l0 { stroke:none; fill:red; }
.l1 { stroke:green; } text.l1 { stroke:none; fill:green; }
.l2 { stroke:blue; } text.l2 { stroke:none; fill:blue; }
.l3 { stroke:magenta; } text.l3 { stroke:none; fill:magenta; }
.l4 { stroke:brown; } text.l4 { stroke:none; fill:brown; }
.l5 { stroke:black; } text.l5 { stroke:none; fill:black; }
.l6 { stroke:olive; } text.l6 { stroke:none; fill:olive; }
.l7 { stroke:gray; } text.l7 { stroke:none; fill:gray; }
.l8 { stroke:yellow; } text.l8 { stroke:none; fill:yellow; }
.l0fill{ stroke:#f00; fill:url(#gr_0); } text.l0fill{ stroke:none; fill:#f00; }
.l1fill{ stroke:#291; fill:url(#gr_1); } text.l1fill{ stroke:none; fill:#291; }
.l2fill{ stroke:#00f; fill:url(#gr_2); } text.l2fill{ stroke:none; fill:#00f; }
.l3fill{ stroke:#f0f; fill:url(#gr_3); } text.l3fill{ stroke:none; fill:#f0f; }
.l4fill{ stroke:#ff0; fill:url(#gr_4); } text.l4fill{ stroke:none; fill:#ff0; }
.l5fill{ stroke:#0ff; fill:url(#gr_5); } text.l5fill{ stroke:none; fill:#0ff; }
.l6fill{ stroke:#000; fill:url(#gr_6); } text.l6fill{ stroke:none; fill:#000; }
.background { fill:#FFFFE7; font-opacity: 0; }
text { font-family:Times; font-size:12px; }
text.title { font-size:16px; }
text.copy { text-decoration:underline; stroke:none; fill:blue; }
text.paste { text-decoration:underline; stroke:none; fill:blue; }
polyline { stroke:black; fill:none; }
.border { stroke:black; fill:url(#gr_bg); }
.vgrid { stroke:gray; stroke-dasharray:2,6; }
.hgrid { stroke:gray; stroke-dasharray:2,6; }
.pasted { stroke:black; stroke-dasharray:1,1; }
.l0 { stroke:red; } text.l0 { stroke:none; fill:red; }
.l1 { stroke:green; } text.l1 { stroke:none; fill:green; }
.l2 { stroke:blue; } text.l2 { stroke:none; fill:blue; }
.l3 { stroke:magenta; } text.l3 { stroke:none; fill:magenta; }
.l4 { stroke:brown; } text.l4 { stroke:none; fill:brown; }
.l5 { stroke:black; } text.l5 { stroke:none; fill:black; }
.l6 { stroke:olive; } text.l6 { stroke:none; fill:olive; }
.l7 { stroke:gray; } text.l7 { stroke:none; fill:gray; }
.l8 { stroke:yellow; } text.l8 { stroke:none; fill:yellow; }
.l0fill{ stroke:#f00; fill:url(#gr_0); } text.l0fill{ stroke:none; fill:#f00; }
.l1fill{ stroke:#291; fill:url(#gr_1); } text.l1fill{ stroke:none; fill:#291; }
.l2fill{ stroke:#00f; fill:url(#gr_2); } text.l2fill{ stroke:none; fill:#00f; }
.l3fill{ stroke:#f0f; fill:url(#gr_3); } text.l3fill{ stroke:none; fill:#f0f; }
.l4fill{ stroke:#ff0; fill:url(#gr_4); } text.l4fill{ stroke:none; fill:#ff0; }
.l5fill{ stroke:#0ff; fill:url(#gr_5); } text.l5fill{ stroke:none; fill:#0ff; }
.l6fill{ stroke:#000; fill:url(#gr_6); } text.l6fill{ stroke:none; fill:#000; }
.l0dot { stroke:red; stroke-dasharray:2,4; } text.ldot { stroke:none; fill:red; }
.l1dot { stroke:green; stroke-dasharray:2,4; } text.ldot { stroke:none; fill:green; }
.l0fill_stripe {stroke:red; fill:url(#gr0_stripe);} text.l0fill_stripe {stroke:none; fill:red;}
.l1fill_stripe {stroke:green; fill:url(#gr1_stripe);} text.l1fill_stripe {stroke:none; fill:green;}
.l0fill_gyr {stroke:red; fill:url(#gr0_gyr);} text.l0fill_gyr {stroke:none; fill:red;}