Changeset 62 for trunk/graph.php


Ignore:
Timestamp:
Jan 1, 2016, 12:13:34 PM (9 years ago)
Author:
chronos
Message:
  • Modified: stat_functions changed to PHP class.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/graph.php

    r61 r62  
    1212if($EndTime < $StartTime) $EndTime = $StartTime + 60;
    1313$TimeDifference = $EndTime - $StartTime;
    14 if(!array_key_exists('Measure',$_GET)) die('Musíte zadat měřenou veličinu');
     14if(!array_key_exists('Measure', $_GET)) die('Musíte zadat měřenou veličinu');
    1515$MeasureId = addslashes($_GET['Measure']);
    1616if(!array_key_exists('Width', $_GET)) $Width = $DefaultWidth;
     
    2424$StopWatchStart = GetMicrotime();
    2525
    26 $Measure = GetMeasureById($MeasureId);
     26$Measure = new Measure($Database);
     27$Measure->Load($MeasureId);
     28$Measure->DivisionCount = $Config['DivisionCount'];
     29$Measure->LevelReducing = $Config['LevelReducing'];
     30$Measure->MaxLevel = $Config['MaxLevel'];
     31$Measure->ReferenceTime = $Config['ReferenceTime'];
     32$Measure->Differential = $Differential;
    2733
    28 $Level = floor(log(($EndTime - $StartTime) / $DivisionCount / 60) / log($LevelReducing)) - 1;
     34$Level = floor(log(($EndTime - $StartTime) / $Measure->DivisionCount / 60) / log($Measure->LevelReducing)) - 1;
    2935if($Level < 0) $Level = 0;
    30 if($Level > $MaxLevel) $Level = $MaxLevel;
     36if($Level > $Measure->MaxLevel) $Level = $Measure->MaxLevel;
    3137
    32 $Points = GetValues($Measure, $StartTime, $EndTime, $Level);
     38$Points = $Measure->GetValues($StartTime, $EndTime, $Level);
    3339
    3440if($Debug) echo('Points count: '.count($Points).'<br>');
     
    5662
    5763// Generate polygon and recalculate y values to fit graph height
    58 $PointsMin = array(0, $Height-1);
    59 $PointsAvg = array(0, $Height-1);
    60 $PointsMax = array(0, $Height-1);
     64$PointsMin = array(0, $Height - 1);
     65$PointsAvg = array(0, $Height - 1);
     66$PointsMax = array(0, $Height - 1);
    6167if(($MaxValue - $MinValue) == 0) $MaxValue = $MinValue + 1;
    6268{
    6369  foreach($Points as $Index => $Item)
    6470  {
    65     $PointsMin[] = $Index*$Width/$DivisionCount;
     71    $PointsMin[] = $Index * $Width / $Measure->DivisionCount;
    6672    $PointsMin[] = $Height - 1 - ($Points[$Index]['min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $K;
    67     $PointsAvg[] = $Index*$Width/$DivisionCount;
     73    $PointsAvg[] = $Index * $Width / $Measure->DivisionCount;
    6874    $PointsAvg[] = $Height - 1 - ($Points[$Index]['avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $K;
    69     $PointsMax[] = $Index*$Width/$DivisionCount;
     75    $PointsMax[] = $Index * $Width / $Measure->DivisionCount;
    7076    $PointsMax[] = $Height - 1 - ($Points[$Index]['max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $K;
    7177    //echo($Index.' - '.$Item.' '.$Points[$Index].'<br>');
     
    9096//$Points[] = $Width - 1;
    9197//$Points[] = $Height - 1;
    92 
    93 //print_r($PointsMax);
    9498
    9599// Generate image
     
    124128  $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2];
    125129
    126   $TimeShift = AlignTime($StartTime, $MajorTimeMarks) - $StartTime;
     130  $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime;
    127131  //imagestring($Image, 10, 40, 50, $TimeShift, $Black);
    128132
     
    136140  }
    137141
    138   $TimeShift = AlignTime($StartTime, $MinorTimeMarks) - $StartTime;
     142  $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime;
    139143
    140144  // Zobraz měřítko X
     
    161165    $Y = $Height - 1 - ($VerticalLinesDistance * $I);
    162166    //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * $K * $Height);
    163     $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance / $Height / $K * ($MaxValue - $MinValue) + $MinValue)), $Measure['Unit'], 3);
     167    $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance / $Height /
     168      $K * ($MaxValue - $MinValue) + $MinValue)), $Measure->Data['Unit'], 3);
    164169    $BoundBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    165170    if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10)
     
    169174
    170175  $Left = $Width - 10;
    171   $Text = "    Max. ".$PrefixMultiplier->Add($MaxValue, $Measure['Unit']);
     176  $Text = "    Max. ".$PrefixMultiplier->Add($MaxValue, $Measure->Data['Unit']);
    172177  $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    173178  $Left -= ($BoundingBox[2] - $BoundingBox[0]);
    174179  imagettftext($Image, $FontSize, 0, $Left, 14, $Red, $FontFile, $Text);
    175180
    176   $Text = "    Avg.  ".$PrefixMultiplier->Add($AvgValue, $Measure['Unit'], 4);
     181  $Text = "    Avg.  ".$PrefixMultiplier->Add($AvgValue, $Measure->Data['Unit'], 4);
    177182  $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    178183  $Left -= ($BoundingBox[2] - $BoundingBox[0]);
    179184  imagettftext($Image, $FontSize, 0, $Left, 14, $Green, $FontFile, $Text);
    180185
    181   $Text = "    Min.  ".$PrefixMultiplier->Add($MinValue, $Measure['Unit']);
     186  $Text = "    Min.  ".$PrefixMultiplier->Add($MinValue, $Measure->Data['Unit']);
    182187  $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text);
    183188  $Left -= ($BoundingBox[2] - $BoundingBox[0]);
     
    186191  //imagestring($Image, 2, 50, 30, 'Level: '.$Level, $Black);
    187192
    188   imagettftext($Image, $FontSize, 0, 70, 14, $Black, $FontFile, $Measure['Description']);
     193  imagettftext($Image, $FontSize, 0, 70, 14, $Black, $FontFile, $Measure->Data['Description']);
    189194  imagerectangle($Image, 0, 0, $Width - 1, $Height - 1, $Black);   // Frame border
    190195  imagepng($Image);
Note: See TracChangeset for help on using the changeset viewer.