Changeset 655 for trunk/Modules/TimeMeasure/Graph.php
- Timestamp:
- May 11, 2014, 4:28:01 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/TimeMeasure/Graph.php
r569 r655 1 1 <?php 2 2 3 class GraphView extends View3 class PageGraph extends Page 4 4 { 5 var $FontSize; 6 var $FontFileName; 7 var $ValueToImageHeigthCoefficient; 8 var $DefaultWidth; 9 var $DefaultHeight; 10 11 function __construct($System) 12 { 13 parent::__construct($System); 14 $this->FontSize = 10; 15 $this->FontFileName = 'Arial.ttf'; 16 $this->ValueToImageHeigthCoefficient = 0.9; 17 } 18 19 function Show() 20 { 21 $this->ClearPage = true; 22 return($this->Render()); 23 } 24 5 25 function Render() 6 26 { 7 if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug']; 27 $PrefixMultiplier = new PrefixMultiplier(); 28 29 if(array_key_exists('Debug', $_GET)) $Debug = $_GET['Debug']; 8 30 else $Debug = 0; 9 31 10 32 if(!array_key_exists('From', $_GET)) die('Musíte zadat čas počátku'); 11 33 $StartTime = addslashes($_GET['From']); … … 15 37 $TimeDifference = $EndTime - $StartTime; 16 38 if(!array_key_exists('Measure', $_GET)) die('Musíte zadat měřenou veličinu'); 17 $MeasureId = addslashes($_GET['Measure']); 18 if(!array_key_exists('Width', $_GET)) $Width = $ DefaultWidth;39 $MeasureId = addslashes($_GET['Measure']); 40 if(!array_key_exists('Width', $_GET)) $Width = $this->DefaultWidth; 19 41 else $Width = addslashes($_GET['Width']); 20 if(!array_key_exists('Height', $_GET)) $Height = $ DefaultHeight;42 if(!array_key_exists('Height', $_GET)) $Height = $this->DefaultHeight; 21 43 else $Height = addslashes($_GET['Height']); 22 44 if(!array_key_exists('Differential', $_GET)) $Differential = $this->Config['Application']['DefaultVariables']['Differential']; 23 45 else $Differential = addslashes($_GET['Differential']); 24 $VerticalLinesCount = round($Height / ($this-> Config['Application']['FontSize']+ 4));25 26 $StopWatchStart = $this->System->GetMicrotime();46 $VerticalLinesCount = round($Height / ($this->FontSize + 4)); 47 48 $StopWatchStart = GetMicrotime(); 27 49 28 50 $Measure = new Measure($this->System); 29 51 $Measure->Load($MeasureId); 30 $Measure->LevelReducing = $this->Config['Application']['LevelReducing'];31 $Measure->ReferenceTime = $this->Config['Application']['ReferenceTime'];32 $Measure->MaxLevel = $this->Config['Application']['MaxLevel'];33 $Measure->DivisionCount = $this->Config['Application']['DivisionCount'];34 $Measure->Differential = $this->Config['Application']['DefaultVariables']['Differential'];52 //$Measure->LevelReducing = $this->LevelReducing; 53 //$Measure->ReferenceTime = $this->Config['Application']['ReferenceTime']; 54 //$Measure->MaxLevel = $this->Config['Application']['MaxLevel']; 55 //$Measure->DivisionCount = $this->Config['Application']['DivisionCount']; 56 //$Measure->Differential = $this->Config['Application']['DefaultVariables']['Differential']; 35 57 $Measure->Debug = $Debug; 36 58 $DbResult2 = $this->Database->select('MeasureMethod', '*', 'Id='.$Measure->Data['Method']); 37 59 $MeasureMethod = $DbResult2->fetch_assoc(); 38 60 39 $FontSize = $this-> Config['Application']['FontSize'];40 $FontFile = dirname(__FILE__).'/../ Style/'.$this->Config['System']['Style'].'/'.$this->Config['Application']['FontFileName'];61 $FontSize = $this->FontSize; 62 $FontFile = dirname(__FILE__).'/../../style/'.$this->System->Config['Web']['Style'].'/'.$this->FontFileName; 41 63 42 64 $Level = floor(log(($EndTime - $StartTime) / $Measure->DivisionCount / 60) / log($Measure->LevelReducing)) - 1; … … 47 69 $Points = $Measure->GetValues($StartTime, $EndTime, $Level); 48 70 49 if($Debug) echo('Points count: '.count($Points).'<br/>'); 50 //if($Debug) foreach($Points as $Index => $Item) 71 if($Debug) echo('Points count: '.count($Points).'<br/>'); 72 //if($Debug) foreach($Points as $Index => $Item) 51 73 // echo($Index.': '.$Item['min'].'<br>'); 52 74 … … 70 92 $AvgValue = $AvgValue / count($Points); //round( * $Measure['Divider']) / $Measure['Divider']; 71 93 72 // Generate polygon and recalculate y values to fit graph height 94 // Generate polygon and recalculate y values to fit graph height 73 95 $PointsMin = array(0, $Height - 1); 74 96 $PointsAvg = array(0, $Height - 1); 75 97 $PointsMax = array(0, $Height - 1); 76 98 if(($MaxValue - $MinValue) == 0) $MaxValue = $MinValue + 1; 77 { 99 { 78 100 foreach($Points as $Index => $Item) 79 101 { 80 102 $PointsMin[] = $Index * $Width / $Measure->DivisionCount; 81 $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this-> Config['Application']['ValueToImageHeigthCoefficient'];103 $PointsMin[] = $Height - 1 - ($Points[$Index]['Min'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 82 104 $PointsAvg[] = $Index * $Width / $Measure->DivisionCount; 83 $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this-> Config['Application']['ValueToImageHeigthCoefficient'];105 $PointsAvg[] = $Height - 1 - ($Points[$Index]['Avg'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 84 106 $PointsMax[] = $Index * $Width / $Measure->DivisionCount; 85 $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this-> Config['Application']['ValueToImageHeigthCoefficient'];107 $PointsMax[] = $Height - 1 - ($Points[$Index]['Max'] - $MinValue) / ($MaxValue - $MinValue) * $Height * $this->ValueToImageHeigthCoefficient; 86 108 //echo($Index.' - '.$Item.' '.$Points[$Index].'<br>'); 87 109 } … … 107 129 108 130 //print_r($PointsMax); 109 131 110 132 // Generate image 111 if(!$Debug) 133 if(!$Debug) 112 134 { 113 135 Header('Content-type: image/png'); 114 Header('Cache-Control: no-cache'); // Dynamic graph - no cache 136 Header('Cache-Control: no-cache'); // Dynamic graph - no cache 115 137 $Image = @imagecreate($Width, $Height); 116 138 $BackgroundColor = imagecolorallocate($Image, 255, 255, 255); … … 129 151 imagefilledpolygon($Image, $PointsAvg, count($PointsAvg) / 2, $LightGreen); 130 152 imagefilledpolygon($Image, $PointsMin, count($PointsMin) / 2, $LightBlue); 131 153 132 154 $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); 133 155 134 156 $TimeRange = $EndTime - $StartTime; 135 157 $TimeMarksIndex = 0; … … 137 159 if($TimeMarksIndex < 2) $TimeMarksIndex = 2; 138 160 $MajorTimeMarks = $TimeMarks[$TimeMarksIndex - 1]; 139 $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2]; 140 141 $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime; 161 $MinorTimeMarks = $TimeMarks[$TimeMarksIndex - 2]; 162 163 $TimeShift = $Measure->AlignTime($StartTime, $MajorTimeMarks) - $StartTime; 142 164 //imagestring($Image, 10, 40, 50, $TimeShift, $Black); 143 165 144 166 // Zobraz měřítko Y 145 167 $VerticalLinesDistance = $Height / $VerticalLinesCount; … … 149 171 for($X = 1; $X < $Width; $X = $X + 3) imagesetpixel($Image, $X, $Y, $Gray); 150 172 //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED); 151 } 152 153 $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime; 154 173 } 174 175 $TimeShift = $Measure->AlignTime($StartTime, $MinorTimeMarks) - $StartTime; 176 155 177 // Zobraz měřítko X 156 178 $LastTextEnd = 0; 157 179 for($Time = $StartTime; $Time < $EndTime; $Time += $MajorTimeMarks) 158 180 { 159 $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width; 181 $X = round(($Time - $StartTime + $TimeShift) / $TimeRange * $Width) % $Width; 160 182 //imageline($Image, 30, $Y, $Width-1, $Y, IMG_COLOR_STYLED); 161 183 if(($MajorTimeMarks > 60 * 60 * 24)) $Text = date('j.n.Y', $Time + $TimeShift); … … 169 191 } 170 192 else for($Y = 0; $Y < $Height; $Y = $Y + 3) imagesetpixel($Image, $X, $Y, $Gray); 171 } 172 193 } 194 173 195 // Popisky osy Y 174 196 for($I = 1; $I <= $VerticalLinesCount; $I++) 175 197 { 176 198 $Y = $Height - 1 - ($VerticalLinesDistance * $I); 177 //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * $this->Config['Application']['ValueToImageHeigthCoefficient'] * $Height); 178 $Text = $this->System->AddPrefixMultipliers(round(($I * $VerticalLinesDistance / $Height / $this->Config['Application']['ValueToImageHeigthCoefficient'] * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3); 199 //$Y = $Height - 1 - ($VerticalLinesDistance * $I / ($MaxValue - $MinValue) * 200 // $this->ValueToImageHeigthCoefficient * $Height); 201 $Text = $PrefixMultiplier->Add(round(($I * $VerticalLinesDistance / $Height / 202 $this->ValueToImageHeigthCoefficient * ($MaxValue - $MinValue) + $MinValue)), $MeasureMethod['Unit'], 3); 179 203 $BoundBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 180 204 if(($Y - ($BoundBox[5] - $BoundBox[1]) / 2) > 10) 181 205 imagettftext($Image, $FontSize, 0, 2, $Y - ($BoundBox[5] - $BoundBox[1]) / 2, $Black, $FontFile, $Text); 182 } 183 $GenerationTime = floor(( $this->System->GetMicrotime() - $StopWatchStart) * 1000 ) / 1000;206 } 207 $GenerationTime = floor((GetMicrotime() - $StopWatchStart) * 1000 ) / 1000; 184 208 185 209 $Left = $Width - 10; 186 $Text = ' Max. '.$ this->System->AddPrefixMultipliers($MaxValue, $MeasureMethod['Unit']);210 $Text = ' Max. '.$PrefixMultiplier->Add($MaxValue, $MeasureMethod['Unit']); 187 211 $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 188 212 $Left -= ($BoundingBox[2] - $BoundingBox[0]); 189 213 imagettftext($Image, $FontSize, 0, $Left, 14, $Red, $FontFile, $Text); 190 214 191 $Text = ' Avg. '.$ this->System->AddPrefixMultipliers($AvgValue, $MeasureMethod['Unit']);215 $Text = ' Avg. '.$PrefixMultiplier->Add($AvgValue, $MeasureMethod['Unit']); 192 216 $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 193 217 $Left -= ($BoundingBox[2] - $BoundingBox[0]); 194 218 imagettftext($Image, $FontSize, 0, $Left, 14, $Green, $FontFile, $Text); 195 219 196 $Text = ' Min. '.$ this->System->AddPrefixMultipliers($MinValue, $MeasureMethod['Unit']);220 $Text = ' Min. '.$PrefixMultiplier->Add($MinValue, $MeasureMethod['Unit']); 197 221 $BoundingBox = imagettfbbox($FontSize, 0, $FontFile, $Text); 198 222 $Left -= ($BoundingBox[2] - $BoundingBox[0]); … … 205 229 imagepng($Image); 206 230 imagedestroy($Image); 207 } 231 } 208 232 } 209 233 }
Note:
See TracChangeset
for help on using the changeset viewer.