1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * JPGraph v4.0.3 |
||||
5 | */ |
||||
6 | |||||
7 | namespace Amenadiel\JpGraph\Graph; |
||||
8 | |||||
9 | use Amenadiel\JpGraph\Util; |
||||
10 | |||||
11 | /* |
||||
12 | * File: JPGRAPH_LOG.PHP |
||||
13 | * // Description: Log scale plot extension for JpGraph |
||||
14 | * // Created: 2001-01-08 |
||||
15 | * // Ver: $Id: jpgraph_log.php 1106 2009-02-22 20:16:35Z ljp $ |
||||
16 | * // |
||||
17 | * // Copyright (c) Asial Corporation. All rights reserved. |
||||
18 | */ |
||||
19 | 1 | define('LOGLABELS_PLAIN', 0); |
|||
20 | 1 | define('LOGLABELS_MAGNITUDE', 1); |
|||
21 | |||||
22 | /** |
||||
23 | * @class LogScale |
||||
24 | * // Description: Logarithmic scale between world and screen |
||||
25 | */ |
||||
26 | class LogScale extends LinearScale |
||||
27 | { |
||||
28 | /** |
||||
29 | * CONSTRUCTOR. |
||||
30 | * |
||||
31 | * @param mixed $min |
||||
32 | * @param mixed $max |
||||
33 | * @param mixed $type |
||||
34 | */ |
||||
35 | // Log scale is specified using the log of min and max |
||||
36 | 3 | public function __construct($min, $max, $type = 'y') |
|||
37 | { |
||||
38 | 3 | parent::__construct($min, $max, $type); |
|||
39 | 3 | $this->ticks = new LogTicks('log'); |
|||
40 | 3 | $this->name = 'log'; |
|||
41 | 3 | } |
|||
42 | |||||
43 | /** |
||||
44 | * PUBLIC METHODS. |
||||
45 | * |
||||
46 | * @param mixed $a |
||||
47 | */ |
||||
48 | // Translate between world and screen |
||||
49 | 3 | public function Translate($a) |
|||
50 | { |
||||
51 | 3 | if (!is_numeric($a)) { |
|||
52 | if ($a != '' && $a != '-' && $a != 'x') { |
||||
53 | Util\JpGraphError::RaiseL(11001); |
||||
54 | // ('Your data contains non-numeric values.'); |
||||
55 | } |
||||
56 | |||||
57 | return 1; |
||||
58 | } |
||||
59 | 3 | if ($a < 0) { |
|||
60 | Util\JpGraphError::RaiseL(11002); |
||||
61 | //("Negative data values can not be used in a log scale."); |
||||
62 | exit(1); |
||||
0 ignored issues
–
show
|
|||||
63 | } |
||||
64 | 3 | if ($a == 0) { |
|||
65 | $a = 1; |
||||
66 | } |
||||
67 | |||||
68 | 3 | $a = log10($a); |
|||
69 | |||||
70 | 3 | return ceil($this->off + ($a * 1.0 - $this->scale[0]) * $this->scale_factor); |
|||
71 | } |
||||
72 | |||||
73 | // Relative translate (don't include offset) usefull when we just want |
||||
74 | // to know the relative position (in pixels) on the axis |
||||
75 | public function RelTranslate($a) |
||||
76 | { |
||||
77 | if (!is_numeric($a)) { |
||||
78 | if ($a != '' && $a != '-' && $a != 'x') { |
||||
79 | Util\JpGraphError::RaiseL(11001); |
||||
80 | //('Your data contains non-numeric values.'); |
||||
81 | } |
||||
82 | |||||
83 | return 1; |
||||
84 | } |
||||
85 | if ($a == 0) { |
||||
86 | $a = 1; |
||||
87 | } |
||||
88 | $a = log10($a); |
||||
89 | |||||
90 | return round(($a * 1.0 - $this->scale[0]) * $this->scale_factor); |
||||
91 | } |
||||
92 | |||||
93 | // Use bcpow() for increased precision |
||||
94 | 3 | public function GetMinVal() |
|||
95 | { |
||||
96 | 3 | if (function_exists('bcpow')) { |
|||
97 | 3 | return round(bcpow(10, $this->scale[0], 15), 14); |
|||
0 ignored issues
–
show
bcpow(10, $this->scale[0], 15) of type string is incompatible with the type double|integer expected by parameter $num of round() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
98 | } |
||||
99 | |||||
100 | return round(pow(10, $this->scale[0]), 14); |
||||
101 | } |
||||
102 | |||||
103 | 3 | public function GetMaxVal() |
|||
104 | { |
||||
105 | 3 | if (function_exists('bcpow')) { |
|||
106 | 3 | return round(bcpow(10, $this->scale[1], 15), 14); |
|||
0 ignored issues
–
show
bcpow(10, $this->scale[1], 15) of type string is incompatible with the type double|integer expected by parameter $num of round() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
107 | } |
||||
108 | |||||
109 | return round(pow(10, $this->scale[1]), 14); |
||||
110 | } |
||||
111 | |||||
112 | // Logarithmic autoscaling is much simplier since we just |
||||
113 | // set the min and max to logs of the min and max values. |
||||
114 | // Note that for log autoscale the "maxstep" the fourth argument |
||||
115 | // isn't used. This is just included to give the method the same |
||||
116 | // signature as the linear counterpart. |
||||
117 | 3 | public function AutoScale($img, $min, $max, $maxsteps, $majend = true) |
|||
118 | { |
||||
119 | 3 | if ($min == 0) { |
|||
120 | $min = 1; |
||||
121 | } |
||||
122 | |||||
123 | 3 | if ($max <= 0) { |
|||
124 | Util\JpGraphError::RaiseL(11004); |
||||
125 | //('Scale error for logarithmic scale. You have a problem with your data values. The max value must be greater than 0. It is mathematically impossible to have 0 in a logarithmic scale.'); |
||||
126 | } |
||||
127 | 3 | if (is_numeric($this->autoscale_min)) { |
|||
0 ignored issues
–
show
|
|||||
128 | $smin = round($this->autoscale_min); |
||||
129 | $smax = ceil(log10($max)); |
||||
130 | if ($min >= $max) { |
||||
131 | Util\JpGraphError::RaiseL(25071); //('You have specified a min value with SetAutoMin() which is larger than the maximum value used for the scale. This is not possible.'); |
||||
132 | } |
||||
133 | } else { |
||||
134 | 3 | $smin = floor(log10($min)); |
|||
135 | 3 | if (is_numeric($this->autoscale_max)) { |
|||
0 ignored issues
–
show
|
|||||
136 | $smax = round($this->autoscale_max); |
||||
137 | if ($smin >= $smax) { |
||||
138 | Util\JpGraphError::RaiseL(25072); //('You have specified a max value with SetAutoMax() which is smaller than the miminum value used for the scale. This is not possible.'); |
||||
139 | } |
||||
140 | } else { |
||||
141 | 3 | $smax = ceil(log10($max)); |
|||
142 | } |
||||
143 | } |
||||
144 | |||||
145 | 3 | $this->Update($img, $smin, $smax); |
|||
146 | 3 | } |
|||
147 | |||||
148 | /* |
||||
149 | * PRIVATE METHODS |
||||
150 | */ |
||||
151 | } // @class |
||||
152 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.