From c2a0c86d08333ef293fb41bb35576a1dc75e1812 Mon Sep 17 00:00:00 2001
From: Damian <>
Date: Wed, 29 Jun 2022 18:57:26 +0000
Subject: [PATCH] 98_DOIF.pm: neu uiTable function: cylinder_s
git-svn-id: https://svn.fhem.de/fhem/trunk@26182 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/98_DOIF.pm | 78 +++++++++++++++++++++++++++++---------------
1 file changed, 52 insertions(+), 26 deletions(-)
diff --git a/fhem/FHEM/98_DOIF.pm b/fhem/FHEM/98_DOIF.pm
index a5d28bdee..2fac8182a 100644
--- a/fhem/FHEM/98_DOIF.pm
+++ b/fhem/FHEM/98_DOIF.pm
@@ -6051,9 +6051,9 @@ sub dec
sub y_h
{
- my ($value,$min,$max,$height,$mode) = @_;
- my $offset=4.5;
- $offset=0 if (defined $mode);
+ my ($value,$min,$max,$height,$val_sum,$mode) = @_;
+ my $offset=4;
+ $offset=0 if ($mode == 0);
if ($value > $max) {
$value=$max;
} elsif ($value < $min) {
@@ -6077,9 +6077,17 @@ sub y_h
$null=$max/($max-$min)*$height;
if ($value <= 0) {
- $y=$null;
+ if ($mode==2){
+ $y=int($null-$val_sum);
+ } else {
+ $y=$null;
+ }
} else {
+ if ($mode==2){
+ $y=int($null+$offset-$val_sum-$h);
+ } else {
$y=int($null+$offset-$h);
+ }
}
$null=undef if ($max == 0 or $min == 0);
return ($y,$h,$null);
@@ -6100,14 +6108,19 @@ sub hsl_color
sub cylinder_bars {
my ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,@values) = @_;
- return(cylinder_mode ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,1,@values));
+ return(cylinder_mode ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,0,@values));
}
sub cylinder {
my ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,@values) = @_;
- return(cylinder_mode ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,undef,@values));
+ return(cylinder_mode ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,1,@values));
}
+sub cylinder_s {
+ my ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,@values) = @_;
+ return(cylinder_mode ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,2,@values));
+}
+
sub cylinder_mode
{
my ($header,$min,$max,$unit,$bwidth,$height,$size,$dec,$mode,@values) = @_;
@@ -6147,7 +6160,7 @@ sub cylinder_mode
my $width=30;
my $heightoffset=4;
- if (defined $mode) {
+ if ($mode == 0) {
$width=7;
}
@@ -6157,7 +6170,7 @@ sub cylinder_mode
$values[$i+2]="" if (!defined $values[$i+2]);
$lenmax=length($values[$i+2]) if (length($values[$i+2]) > $lenmax);
}
- if (defined $mode) {
+ if ($mode == 0) {
$bwidth=@values/3*($width+2)+60+$lenmax*4.3;
} else {
$bwidth=90+$lenmax*4.3;
@@ -6178,7 +6191,7 @@ sub cylinder_mode
$out.= '';
for (my $i=0;$i<@values;$i+=3){
my $color=$values[$i+1];
- $out.= sprintf('',$color,hsl_color($color),hsl_color($color));
+ $out.= sprintf('',$color,hsl_color($color),hsl_color($color));
}
$out.= '';
$out.= '';
@@ -6189,18 +6202,18 @@ sub cylinder_mode
$out.= sprintf('%s',$bwidth/2+11,$header) if ($header ne "");
$out.= sprintf('',$trans);
- if (defined $mode) {
- $out.= sprintf('',!defined $mode ? $width:@values/3*($width+2)+2,$height+$heightoffset+2);
+ if ($mode == 0) {
+ $out.= sprintf('',@values/3*($width+2)+2,$height+$heightoffset+2);
} else {
- $out.= sprintf('',!defined $mode ? $width:@values/3*($width+2)+2,$height+$heightoffset);
+ $out.= sprintf('',$width,$height+$heightoffset);
$out.= sprintf('',$height,$width);
$out.= sprintf('',$width);
}
- ($y,$val1,$null)=y_h(0,$min,$max,$height);
+ ($y,$val1,$null)=y_h(0,$min,$max,$height,0,$mode);
my $xLeft=15;
my $xBegin=$xLeft+33;
- $xBegin=@values/3*($width+2)+20 if(defined $mode);
+ $xBegin=@values/3*($width+2)+20 if($mode == 0);
$out.= sprintf('%s',$xBegin,$height+$heightoffset+1,$min);
$out.= sprintf('%s',$xBegin,$null+$heightoffset+2,0) if (defined $null);
@@ -6208,14 +6221,17 @@ sub cylinder_mode
my $yBegin=13+($height-@values*$heightval)/2;
my $xValue=$xLeft;
+ my $yValue=$yBegin+$heightval-1;
+ my $val_sum_pos=0;
+ my $val_sum_neg=0;
for (my $i=0;$i<@values;$i+=3){
- my $yValue=$yBegin+$heightval-1;
+
my $value=$values[$i];
my $val=$value;
- if (defined $mode) {
- $xValue=$xLeft+$i/3*($width+2)+2 if (defined $mode);
- }
+
+ $xValue=$xLeft+$i/3*($width+2)+2 if ($mode == 0);
+
if (!defined $value or $value eq "") {
$val="N/A";
$value=0;
@@ -6223,24 +6239,34 @@ sub cylinder_mode
my $color=$values[$i+1];
my $text=$values[$i+2];
- ($y,$val1,$null)=y_h($value,$min,$max,$height,$mode);
- if (!defined $mode) {
+ ($y,$val1,$null)=y_h($value,$min,$max,$height,($value > 0 ? $val_sum_pos: $val_sum_neg),$mode);
+
+ if ($mode) {
+ $out.= sprintf('',$xValue,$y,$width);
$out.= sprintf('',$xValue,$y,$width,$val1,$color);
- $out.= sprintf('',$xValue,$y,$width,$color);#,hsl_color($color,0));
## $out.= sprintf('',$xValue,$y,$width,$val1,$color);
} else {
$out.= sprintf('',$xValue,$y+2,$width,$val1+2,$color);
}
-
+ my $yText;
if (defined $text and $text ne "") {
$out.= sprintf('%s',$xBegin+10,$yBegin+$i*$heightval,hsl_color($color),$text.":");
- if ($heightval == 10) {
- $yValue+=7;
+ } else {
+ $yValue -=7;
+ }
+ if ($heightval == 10) {
+ $yText=$yValue+7;
+ } else {
+ $yText=$yValue-4;
+ }
+ $out.= sprintf('%s%s',$bwidth+5, $yText+$i*$heightval,hsl_color ($color),($val eq "N/A" ? $val:sprintf($format,$val)),$unit);
+ if ($mode == 2) {
+ if ($value> 0) {
+ $val_sum_pos+=($val1-4);
} else {
- $yValue-=4;
+ $val_sum_neg-=($val1-4);
}
}
- $out.= sprintf('%s%s',$bwidth+5, $yValue+$i*$heightval,hsl_color ($color),($val eq "N/A" ? $val:sprintf($format,$val)),$unit);
}
$out.= '';