Conditions | 19 |
Paths | 4802 |
Total Lines | 102 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
110 | public function AutoScale($img, $min, $max, $maxsteps, $majend = true) |
||
111 | { |
||
112 | if (!is_numeric($min) || !is_numeric($max)) { |
||
113 | Util\JpGraphError::Raise(25044); |
||
114 | } |
||
115 | |||
116 | if ($this->intscale) { |
||
117 | $this->IntAutoScale($img, $min, $max, $maxsteps, $majend); |
||
118 | |||
119 | return; |
||
120 | } |
||
121 | if (abs($min - $max) < 0.00001) { |
||
122 | // We need some difference to be able to autoscale |
||
123 | // make it 5% above and 5% below value |
||
124 | if ($min == 0 && $max == 0) { |
||
125 | // Special case |
||
126 | $min = -1; |
||
127 | $max = 1; |
||
128 | } else { |
||
129 | $delta = (abs($max) + abs($min)) * 0.005; |
||
130 | $min -= $delta; |
||
131 | $max += $delta; |
||
132 | } |
||
133 | } |
||
134 | |||
135 | $gracetop = ($this->gracetop / 100.0) * abs($max - $min); |
||
136 | $gracebottom = ($this->gracebottom / 100.0) * abs($max - $min); |
||
137 | if (is_numeric($this->autoscale_min)) { |
||
138 | $min = $this->autoscale_min; |
||
139 | if ($min >= $max) { |
||
140 | 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.'); |
||
141 | } |
||
142 | if (abs($min - $max) < 0.001) { |
||
143 | $max *= 1.2; |
||
144 | } |
||
145 | } |
||
146 | |||
147 | if (is_numeric($this->autoscale_max)) { |
||
148 | $max = $this->autoscale_max; |
||
149 | if ($min >= $max) { |
||
150 | 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.'); |
||
151 | } |
||
152 | if (abs($min - $max) < 0.001) { |
||
153 | $min *= 0.8; |
||
154 | } |
||
155 | } |
||
156 | |||
157 | $min -= $gracebottom; |
||
158 | $max += $gracetop; |
||
159 | |||
160 | // First get tickmarks as multiples of 0.1, 1, 10, ... |
||
161 | if ($majend) { |
||
162 | list($num1steps, $adj1min, $adj1max, $min1step, $maj1step) = $this->CalcTicks($maxsteps, $min, $max, 1, 2); |
||
163 | } else { |
||
164 | $adj1min = $min; |
||
165 | $adj1max = $max; |
||
166 | list($num1steps, $min1step, $maj1step) = $this->CalcTicksFreeze($maxsteps, $min, $max, 1, 2, false); |
||
167 | } |
||
168 | |||
169 | // Then get tick marks as 2:s 0.2, 2, 20, ... |
||
170 | if ($majend) { |
||
171 | list($num2steps, $adj2min, $adj2max, $min2step, $maj2step) = $this->CalcTicks($maxsteps, $min, $max, 5, 2); |
||
172 | } else { |
||
173 | $adj2min = $min; |
||
174 | $adj2max = $max; |
||
175 | list($num2steps, $min2step, $maj2step) = $this->CalcTicksFreeze($maxsteps, $min, $max, 5, 2, false); |
||
176 | } |
||
177 | |||
178 | // Then get tickmarks as 5:s 0.05, 0.5, 5, 50, ... |
||
179 | if ($majend) { |
||
180 | list($num5steps, $adj5min, $adj5max, $min5step, $maj5step) = $this->CalcTicks($maxsteps, $min, $max, 2, 5); |
||
181 | } else { |
||
182 | $adj5min = $min; |
||
183 | $adj5max = $max; |
||
184 | list($num5steps, $min5step, $maj5step) = $this->CalcTicksFreeze($maxsteps, $min, $max, 2, 5, false); |
||
185 | } |
||
186 | |||
187 | // Check to see whichof 1:s, 2:s or 5:s fit better with |
||
188 | // the requested number of major ticks |
||
189 | $match1 = abs($num1steps - $maxsteps); |
||
190 | $match2 = abs($num2steps - $maxsteps); |
||
191 | $match5 = abs($num5steps - $maxsteps); |
||
192 | |||
193 | // Compare these three values and see which is the closest match |
||
194 | // We use a 0.8 weight to gravitate towards multiple of 5:s |
||
195 | $r = $this->MatchMin3($match1, $match2, $match5, 0.8); |
||
196 | switch ($r) { |
||
197 | case 1: |
||
198 | $this->Update($img, $adj1min, $adj1max); |
||
199 | $this->ticks->Set($maj1step, $min1step); |
||
200 | |||
201 | break; |
||
202 | case 2: |
||
203 | $this->Update($img, $adj2min, $adj2max); |
||
204 | $this->ticks->Set($maj2step, $min2step); |
||
205 | |||
206 | break; |
||
207 | case 3: |
||
208 | $this->Update($img, $adj5min, $adj5max); |
||
209 | $this->ticks->Set($maj5step, $min5step); |
||
210 | |||
211 | break; |
||
212 | } |
||
269 |