Ignore:
Timestamp:
Jul 27, 2014, 9:05:14 PM (10 years ago)
Author:
chronos
Message:
  • Opraveno: SQL aktualizace 40 plus chybějící tabulka MeasureMethod.
  • Opraveno: Neplatné ukázkové konfigurační soubory.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/View/Graph.php

    r45 r46  
    66class GraphView extends View
    77{
     8  var $DefaultWidth;
     9  var $DefaultHeight;
     10
     11  function __construct($System)
     12  {
     13        parent::__construct($System);
     14    $this->DefaultWidth = 800;
     15    $this->DefaultHeight = 200;
     16  }
     17
    818  function Render()
    919  {
    10     if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug']; 
     20    if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug'];
    1121      else $Debug = 0;
    12  
     22
    1323    if(!array_key_exists('From', $_GET)) die('Musíte zadat čas počátku');
    1424    $StartTime = addslashes($_GET['From']);
     
    1828    $TimeDifference = $EndTime - $StartTime;
    1929    if(!array_key_exists('Measure', $_GET)) die('Musíte zadat měřenou veličinu');
    20     $MeasureId = addslashes($_GET['Measure']);   
    21     if(!array_key_exists('Width', $_GET)) $Width = $DefaultWidth;
     30    $MeasureId = addslashes($_GET['Measure']);
     31    if(!array_key_exists('Width', $_GET)) $Width = $this->DefaultWidth;
    2232      else $Width = addslashes($_GET['Width']);
    23     if(!array_key_exists('Height', $_GET)) $Height = $DefaultHeight;
     33    if(!array_key_exists('Height', $_GET)) $Height = $this->DefaultHeight;
    2434      else $Height = addslashes($_GET['Height']);
    2535    if(!array_key_exists('Differential', $_GET)) $Differential = $this->Config['Application']['DefaultVariables']['Differential'];
     
    5060    $Points = $Measure->GetValues($StartTime, $EndTime, $Level);
    5161
    52     if($Debug) echo('Points count: '.count($Points).'<br/>'); 
    53     //if($Debug) foreach($Points as $Index => $Item) 
    54     // echo($Index.': '.$Item['min'].'<br>');
     62    if($Debug) echo('Points count: '.count($Points).'<br/>');
     63    //if($Debug) foreach($Points as $Index => $Item)
     64    // echo($Index.': '.$Item['min'].'<br/>');
    5565
    5666    // Calculate total max, avg, min value
     
    7383    $AvgValue = $AvgValue / count($Points); //round( * $Measure['Divider']) / $Measure['Divider'];
    7484
    75     // Generate polygon and recalculate y values to fit graph height 
     85    // Generate polygon and recalculate y values to fit graph height
    7686    $PointsMin = array(0, $Height - 1);
    7787    $PointsAvg = array(0, $Height - 1);
    7888    $PointsMax = array(0, $Height - 1);
    7989    if(($MaxValue - $MinValue) == 0) $MaxValue = $MinValue + 1;
    80     { 
     90    {
    8191      foreach($Points as $Index => $Item)
    8292      {
     
    8797        $PointsMax[] = $Index * $Width / $Measure->DivisionCount;
    8898        $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->Config['Application']['ValueToImageHeigthCoefficient'];
    89         //echo($Index.' - '.$Item.' '.$Points[$Index].'<br>');
     99        //echo($Index.' - '.$Item.' '.$Points[$Index].'<br/>');
    90100      }
    91101    }
     
    107117    //array_unshift($Points, 0);
    108118    //$Points[] = $Width - 1;
    109     //$Points[] = $Height - 1;
     119    //$Points[] = $Height - 1;      echo('sds');
     120
    110121
    111122    //print_r($PointsMax);
    112  
     123
    113124    // Generate image
    114     if(!$Debug) 
     125    if(!$Debug)
    115126    {
    116127      Header('Content-type: image/png');
    117       Header('Cache-Control: no-cache');  // Dynamic graph - no cache 
     128      Header('Cache-Control: no-cache');  // Dynamic graph - no cache
    118129      $Image = @imagecreate($Width, $Height);
    119130      $BackgroundColor = imagecolorallocate($Image, 255, 255, 255);
     
    132143      imagefilledpolygon($Image, $PointsAvg, count($PointsAvg) / 2, $LightGreen);
    133144      imagefilledpolygon($Image, $PointsMin, count($PointsMin) / 2, $LightBlue);
    134  
     145
    135146      $TimeMarks = array(1, 60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30, 60*60*24*365, 60*60*24*365*10);
    136  
     147
    137148      $TimeRange = $EndTime - $StartTime;
    138149      $TimeMarksIndex = 0;
     
    140151      if($TimeMarksIndex < 2) $TimeMarksIndex = 2;
    141152      $MajorTimeMarks = $TimeMarks[$TimeMarksIndex - 1];
    142       $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2]; 
    143    
    144       $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime; 
     153      $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2];
     154
     155      $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime;
    145156      //imagestring($Image, 10, 40, 50, $TimeShift, $Black);
    146  
     157
    147158      // Zobraz měřítko Y
    148159      $VerticalLinesDistance = $Height / $VerticalLinesCount;
     
    152163        for($X = 1; $X < $Width; $X = $X + 3) imagesetpixel($Image, $X, $Y, $Gray);
    153164        //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
    154       } 
    155 
    156       $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime; 
    157  
     165      }
     166
     167      $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime;
     168
    158169      // Zobraz měřítko X
    159170      $LastTextEnd = 0;
    160171      for($Time = $StartTime; $Time < $EndTime; $Time += $MajorTimeMarks)
    161172      {
    162         $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width; 
     173        $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width;
    163174        //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED);
    164175        if(($MajorTimeMarks > 60 * 60 * 24)) $Text = date('j.n.Y', $Time + $TimeShift);
     
    172183        }
    173184        else for($Y = 0; $Y < $Height; $Y = $Y + 3) imagesetpixel($Image, $X, $Y, $Gray);
    174       } 
    175  
     185      }
     186
    176187      // Popisky osy Y
    177188      for($I = 1; $I <= $VerticalLinesCount; $I++)
     
    183194        if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10)
    184195          imagettftext($Image, $FontSize, 0, 2,  $Y - ($BoundBox[5] - $BoundBox[1]) / 2, $Black, $FontFile, $Text);
    185       } 
     196      }
    186197      $GenerationTime = floor(($this->System->GetMicrotime() - $StopWatchStart) * 1000  ) / 1000;
    187198
     
    208219      imagepng($Image);
    209220      imagedestroy($Image);
    210     }   
     221    }
    211222  }
    212223}
Note: See TracChangeset for help on using the changeset viewer.