HuasoFoundries /
jpgraph
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * JPGraph v4.0.3 |
||
| 5 | */ |
||
| 6 | |||
| 7 | namespace Amenadiel\JpGraph\Util; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * File: JPGRAPH_UTILS.INC |
||
| 11 | * // Description: Collection of non-essential "nice to have" utilities |
||
| 12 | * // Created: 2005-11-20 |
||
| 13 | * // Ver: $Id: jpgraph_utils.inc.php 1777 2009-08-23 17:34:36Z ljp $ |
||
| 14 | * // |
||
| 15 | * // Copyright (c) Asial Corporation. All rights reserved. |
||
| 16 | */ |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @class FuncGenerator |
||
| 20 | * // Description: Utility class to help generate data for function plots. |
||
| 21 | * // The class supports both parametric and regular functions. |
||
| 22 | */ |
||
| 23 | class FuncGenerator |
||
| 24 | { |
||
| 25 | private $iFunc = ''; |
||
| 26 | private $iXFunc = ''; |
||
| 27 | private $iMin; |
||
| 28 | private $iMax; |
||
| 29 | private $iStepSize; |
||
| 30 | |||
| 31 | 2 | public function __construct($aFunc, $aXFunc = '') |
|
| 32 | { |
||
| 33 | 2 | $this->iFunc = $aFunc; |
|
| 34 | 2 | $this->iXFunc = $aXFunc; |
|
| 35 | 2 | } |
|
| 36 | |||
| 37 | 2 | public function E($aXMin, $aXMax, $aSteps = 50) |
|
| 38 | { |
||
| 39 | 2 | $this->iMin = $aXMin; |
|
| 40 | 2 | $this->iMax = $aXMax; |
|
| 41 | 2 | $this->iStepSize = ($aXMax - $aXMin) / $aSteps; |
|
| 42 | |||
| 43 | 2 | if ($this->iXFunc != '') { |
|
| 44 | 1 | $t = 'for($i=' . $aXMin . '; $i<=' . $aXMax . '; $i += ' . $this->iStepSize . ') {$ya[]=' . $this->iFunc . ';$xa[]=' . $this->iXFunc . ';}'; |
|
| 45 | 2 | } elseif ($this->iFunc != '') { |
|
| 46 | 2 | $t = 'for($x=' . $aXMin . '; $x<=' . $aXMax . '; $x += ' . $this->iStepSize . ') {$ya[]=' . $this->iFunc . ';$xa[]=$x;} $x=' . $aXMax . ';$ya[]=' . $this->iFunc . ';$xa[]=$x;'; |
|
| 47 | } else { |
||
| 48 | JpGraphError::RaiseL(24001); |
||
| 49 | } |
||
| 50 | //('FuncGenerator : No function specified. '); |
||
| 51 | |||
| 52 | 2 | @eval($t); |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
Comprehensibility
Best Practice
introduced
by
|
|||
| 53 | |||
| 54 | // If there is an error in the function specifcation this is the only |
||
| 55 | // way we can discover that. |
||
| 56 | 2 | if (empty($xa) || empty($ya)) { |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||
| 57 | JpGraphError::RaiseL(24002); |
||
| 58 | } |
||
| 59 | //('FuncGenerator : Syntax error in function specification '); |
||
| 60 | |||
| 61 | 2 | return [$xa, $ya]; |
|
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Comprehensibility
Best Practice
introduced
by
|
|||
| 62 | } |
||
| 63 | } |
||
| 64 |