diff --git a/draw.php b/draw.php
index 90b5aea..f3c3649 100644
--- a/draw.php
+++ b/draw.php
@@ -227,6 +227,7 @@ function generateChart($today,$mode,$hours=0,$dateInput){
$svg=false;
if(isset($_GET['lib'])){
$svg=true;
+ $clima = $_GET['lib'] === "clima";
if(file_exists("charts/".$chartname.".svg")){
$file_exists=true;
}
@@ -241,7 +242,22 @@ function generateChart($today,$mode,$hours=0,$dateInput){
#if((date("d.m.Y")==$date &&$force) || !file_exists($chartname) || $force){
#if(true){#always redraw
if($svg){
- include('ownlib.php');
+ if($clima && $mode == 1){
+ include('lib/climaDiagram.php');
+ $cd = new ClimaDiagram();
+ $cd->setLocation('Bischberg','Deutschland','50`, 50`', 'north');
+ $cd->setMode('day');
+ $values=prepareData($datas[1],$div,$selectionStart,$selectionEnd,$chartdistance);
+ foreach($values as $i=>$value){
+ if(!($i == 0 || $i == 25)){
+ $day_values[]=$value;
+ }
+ }
+ $cd->setTemperatureData($day_values);
+ file_put_contents("charts/".$chartname.".svg", $cd->getGraph());
+ }else{
+ include('ownlib.php');
+ }
}else{
chdir('pchart');
include("class/pData.class.php");
diff --git a/lib/climaDiagram.php b/lib/climaDiagram.php
new file mode 100644
index 0000000..4d785eb
--- /dev/null
+++ b/lib/climaDiagram.php
@@ -0,0 +1,254 @@
+array(1, 600),'month'=>array(2.6, 1337),'day'=>array(2, 1050));
+ private $mode='year';
+ private $languages=array('de');
+ private $language='de';
+
+ private $temperatureData=array();
+ private $rainData=array();
+ private $locationName="";
+ private $locationCountry="";
+ private $locationHeight="";
+ private $locationCoordinates="";
+ private $hemisphere='north';
+ private $result="";
+
+ private function drawBase(){
+ foreach ($this->modes as $mode => $prop) {
+ if ($this->mode==$mode) {
+ $xOffset=$prop[0];
+ $width=$prop[1];
+ }
+ }
+ $base='
+ '.$this->locationName.','.$this->locationCountry.' ('.$this->locationHeight.' m)
+ '.$this->locationCoordinates.'
+
+ T in C
+ N in mm'."\n";
+ $horizontalLines="";
+ $rainIndex=400; // Text Höchster Niederschlag
+ $rainMarker=0;
+ $temperatureMarker=240;
+ $temperatureIndex=50; // Text Höchste Temperatur
+ for ($i=90+30; $i < 740; $i+=30) {
+ $horizontalLines.=''."\n";
+ if ($i>=$temperatureMarker) {
+ $horizontalLines.=''.$temperatureIndex.''."\n";
+ $temperatureMarker=$i+60;
+ $temperatureIndex-=10;
+ }
+ if ($i>=$rainMarker && $rainIndex>=0) {
+ $horizontalLines.=''.$rainIndex.''."\n";
+ if ($i<180) {
+ $rainMarker=$i+30;
+ $rainIndex-=100;
+ } elseif ($i<240) {
+ $rainMarker=$i+30;
+ $rainIndex-=50;
+ }else {
+ $rainMarker=$i+60;
+ $rainIndex-=20;
+ }
+ }
+ }
+ $base.=$horizontalLines;
+ $horizontalLines=null;
+ if ($this->mode=='year'){
+ $base.=$this->yearDiagram()."\n";
+ }elseif ($this->mode=='day') {
+ $base.=$this->dayDiagram()."\n";
+ }else{
+ $base.='TODO: modes'."\n";
+ }
+ $this->result=$base;
+ $base=null;
+ }
+
+ private function yearDiagram(){
+ $verticalLines="";
+ foreach ($this->months as $index => $month) {
+ $verticalLines.=''."\n";
+ $verticalLines.=''.$month.''."\n";
+ }
+ $verticalLines.=$this->drawRain();
+ $verticalLines.=$this->drawTemperature();
+ return $verticalLines;
+ }
+
+ private function dayDiagram(){
+ $verticalLines="";
+ for($i=1;$i<=24;$i++) {
+ $verticalLines.=''."\n";
+ $verticalLines.=''.$i.''."\n";
+ }
+ $verticalLines.=$this->drawRain();
+ $verticalLines.=$this->drawTemperature();
+ return $verticalLines;
+ }
+
+ private function drawTemperature(){
+ $zero=540;
+ $max=240;
+ $difference=50;
+ $resolution=($zero-$max)/$difference;
+ $startX=40;
+ $path='';
+ $lastX=0;
+ $lastY=0;
+ $i=0;
+ foreach ($this->temperatureData as $index=>$value) {
+ $x=20+$startX*($i+1);
+ $y=$zero+$resolution*-$value;
+ if (empty($path)) {
+ $path="M ".($x-20).' '.$y.' L '.$x.' '.$y.' ';
+ }else{
+ $path.=$x.' '.$y.' ';
+ }
+ $lastX=$x;
+ $lastY=$y;
+ $i++;
+ }
+ $path.=($lastX+20).' '.$lastY;
+ return '';
+ }
+
+ private function drawRain(){
+ $rain="";
+ $startX=40;
+ $startY=540;
+ foreach ($this->rainData as $index => $value) {
+ if ($value==0) {
+ continue;
+ }
+ if($value>200){
+ $localvalue=$value-200;
+ $value=200;
+ $zero=180;
+ $max=90;
+ $difference=300;
+ $resolution=($max-$zero)/$difference;
+ $height=($localvalue*$resolution);
+ $rain.=''."\n";
+ }if ($value>100) {
+ $localvalue=$value-100;
+ $value=100;
+ $zero=240;
+ $max=180;
+ $difference=100;
+ $resolution=($max-$zero)/$difference;
+ $height=($localvalue*$resolution);
+ $rain.=''."\n";
+ }
+ if($value<=100){
+ $zero=540;
+ $max=240;
+ $difference=100;
+ $resolution=($max-$zero)/$difference;
+ $height=($value*$resolution);
+ $rain.=''."\n";
+ }
+ }
+ return $rain;
+ }
+
+ public function getGraph(){
+ foreach ($this->modes as $mode => $prop) {
+ if ($this->mode==$mode) {
+ $width=$prop[1];
+ }
+ }
+ $this->drawBase();
+ return ''."\n".
+ ''."\n".
+ '';
+ }
+
+ public function setLocation($city,$country,$height,$coordinates,$hemisphere='north'){
+ $this->locationName=$city;
+ $this->locationCountry=$country;
+ $this->locationHeight=$height;
+ $this->locationCoordinates=$coordinates;
+ $this->hemisphere=$hemisphere;
+ }
+ public function setTemperatureData($data){
+ if (is_array($data) && !empty($data)) {
+ $this->temperatureData=$data;
+ }
+ }
+ public function setRainData($data){
+ if (is_array($data) && !empty($data)) {
+ $this->rainData=$data;
+ }
+ }
+ public function setMode($mode){
+ if (array_key_exists($mode, $this->modes)) {
+ $this->mode=$mode;
+ return true;
+ echo "TRUE";
+ }
+ return false;
+ }
+
+}
+
+################
+## TESTING ##
+################
+
+#$test=new ClimaDiagram();
+#$test->setLocation('Ort','Land','100','50`, 50`' ,'north');
+#// $temp=array(25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8);
+#// $rain=array(1,5,17,48,100,155,425,320,280,76,8,4);
+#$temp=array(25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8,25,30,40,-10,5,6.75,50,20,-5,-15.9,-12,-8);
+#$rain=array(1,5,17,48,100,155,425,320,280,76,8,4,1,5,17,48,100,155,425,320,280,76,8,4);
+#$test->setMode('day');
+#// $test->setMode('month');
+#$test->setRainData($rain);
+#$test->setTemperatureData($temp);
+#echo $test->getGraph();
+?>