Passed
Push — master ( 3dc74f...81d6e9 )
by Felipe
04:17
created

LinearScale::IntCalcTicks()   C

Complexity

Conditions 8
Paths 64

Size

Total Lines 43
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 8.0231

Importance

Changes 0
Metric Value
cc 8
eloc 30
nc 64
nop 5
dl 0
loc 43
ccs 26
cts 28
cp 0.9286
crap 8.0231
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * JPGraph v3.6.15
5
 */
6
7
namespace Amenadiel\JpGraph\Graph;
8
9
use Amenadiel\JpGraph\Util;
10
11
/**
12
 * @class LinearScale
13
 * // Description: Handle linear scaling between screen and world
14
 */
15
class LinearScale
16
{
17
    public $textscale = false; // Just a flag to let the Plot class find out if
18
    // we are a textscale or not. This is a cludge since
19
    // this information is available in Graph::axtype but
20
    // we don't have access to the graph object in the Plots
21
    // stroke method. So we let graph store the status here
22
    // when the linear scale is created. A real cludge...
23
    public $type; // is this x or y scale ?
24
    public $ticks; // Store ticks
25
    public $text_scale_off = 0;
26
    public $scale_abs      = [0, 0];
27
    public $scale_factor; // Scale factor between world and screen
28
    public $off; // Offset between image edge and plot area
29
    public $scale      = [0, 0];
30
    public $name       = 'lin';
31
    public $auto_ticks = false; // When using manual scale should the ticks be automatically set?
32
    public $world_abs_size; // Plot area size in pixels (Needed public in jpgraph_radar.php)
33
    public $intscale         = false; // Restrict autoscale to integers
34
    protected $autoscale_min = false; // Forced minimum value, auto determine max
35
    protected $autoscale_max = false; // Forced maximum value, auto determine min
36
    private $gracetop        = 0;
37
    private $gracebottom     = 0;
38
39
    private $_world_size; // Plot area size in world coordinates
40
41 14
    public function __construct($aMin = 0, $aMax = 0, $aType = 'y')
42
    {
43 14
        assert($aType == 'x' || $aType == 'y');
44 14
        assert($aMin <= $aMax);
45
46 14
        $this->type       = $aType;
47 14
        $this->scale      = [$aMin, $aMax];
48 14
        $this->world_size = $aMax - $aMin;
49 14
        $this->ticks      = new LinearTicks();
50 14
    }
51
52
    // Check if scale is set or if we should autoscale
53
    // We should do this is either scale or ticks has not been set
54 14
    public function IsSpecified()
55
    {
56 14
        if ($this->GetMinVal() == $this->GetMaxVal()) {
57
            // Scale not set
58 13
            return false;
59
        }
60
61 6
        return true;
62
    }
63
64
    // Set the minimum data value when the autoscaling is used.
65
    // Usefull if you want a fix minimum (like 0) but have an
66
    // automatic maximum
67 2
    public function SetAutoMin($aMin)
68
    {
69 2
        $this->autoscale_min = $aMin;
70 2
    }
71
72
    // Set the minimum data value when the autoscaling is used.
73
    // Usefull if you want a fix minimum (like 0) but have an
74
    // automatic maximum
75 1
    public function SetAutoMax($aMax)
76
    {
77 1
        $this->autoscale_max = $aMax;
78 1
    }
79
80
    // If the user manually specifies a scale should the ticks
81
    // still be set automatically?
82 1
    public function SetAutoTicks($aFlag = true)
83
    {
84 1
        $this->auto_ticks = $aFlag;
85 1
    }
86
87
    // Specify scale "grace" value (top and bottom)
88 5
    public function SetGrace($aGraceTop, $aGraceBottom = 0)
89
    {
90 5
        if ($aGraceTop < 0 || $aGraceBottom < 0) {
91
            Util\JpGraphError::RaiseL(25069); //(" Grace must be larger then 0");
92
        }
93 5
        $this->gracetop    = $aGraceTop;
94 5
        $this->gracebottom = $aGraceBottom;
95 5
    }
96
97
    // Get the minimum value in the scale
98 14
    public function GetMinVal()
99
    {
100 14
        return $this->scale[0];
101
    }
102
103
    // get maximum value for scale
104 14
    public function GetMaxVal()
105
    {
106 14
        return $this->scale[1];
107
    }
108
109
    // Specify a new min/max value for sclae
110 14
    public function Update($aImg, $aMin, $aMax)
111
    {
112 14
        $this->scale      = [$aMin, $aMax];
113 14
        $this->world_size = $aMax - $aMin;
114 14
        $this->InitConstants($aImg);
115 14
    }
116
117
    // Translate between world and screen
118 14
    public function Translate($aCoord)
119
    {
120 14
        if (!is_numeric($aCoord)) {
121 2
            if ($aCoord != '' && $aCoord != '-' && $aCoord != 'x') {
122
                Util\JpGraphError::RaiseL(25070); //('Your data contains non-numeric values.');
123
            }
124
125 2
            return 0;
126
        }
127
128 14
        return round($this->off + ($aCoord - $this->scale[0]) * $this->scale_factor);
129
    }
130
131
    // Relative translate (don't include offset) usefull when we just want
132
    // to know the relative position (in pixels) on the axis
133
    public function RelTranslate($aCoord)
134
    {
135
        if (!is_numeric($aCoord)) {
136
            if ($aCoord != '' && $aCoord != '-' && $aCoord != 'x') {
137
                Util\JpGraphError::RaiseL(25070); //('Your data contains non-numeric values.');
138
            }
139
140
            return 0;
141
        }
142
143
        return ($aCoord - $this->scale[0]) * $this->scale_factor;
144
    }
145
146
    // Restrict autoscaling to only use integers
147 7
    public function SetIntScale($aIntScale = true)
148
    {
149 7
        $this->intscale = $aIntScale;
150 7
    }
151
152
    // Calculate an integer autoscale
153 7
    public function IntAutoScale($img, $min, $max, $maxsteps, $majend = true)
154
    {
155
        // Make sure limits are integers
156 7
        $min = floor($min);
157 7
        $max = ceil($max);
158 7
        if (abs($min - $max) == 0) {
159
            --$min;
160
            ++$max;
161
        }
162 7
        $maxsteps = floor($maxsteps);
163
164 7
        $gracetop    = round(($this->gracetop / 100.0) * abs($max - $min));
165 7
        $gracebottom = round(($this->gracebottom / 100.0) * abs($max - $min));
166 7
        if (is_numeric($this->autoscale_min)) {
0 ignored issues
show
introduced by
The condition is_numeric($this->autoscale_min) is always false.
Loading history...
167
            $min = ceil($this->autoscale_min);
168
            if ($min >= $max) {
169
                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.');
170
            }
171
        }
172
173 7
        if (is_numeric($this->autoscale_max)) {
0 ignored issues
show
introduced by
The condition is_numeric($this->autoscale_max) is always false.
Loading history...
174
            $max = ceil($this->autoscale_max);
175
            if ($min >= $max) {
176
                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.');
177
            }
178
        }
179
180 7
        if (abs($min - $max) == 0) {
181
            ++$max;
182
            --$min;
183
        }
184
185 7
        $min -= $gracebottom;
186 7
        $max += $gracetop;
187
188
        // First get tickmarks as multiples of 1, 10, ...
189 7
        if ($majend) {
190 6
            list($num1steps, $adj1min, $adj1max, $maj1step) = $this->IntCalcTicks($maxsteps, $min, $max, 1);
191
        } else {
192 3
            $adj1min                    = $min;
193 3
            $adj1max                    = $max;
194 3
            list($num1steps, $maj1step) = $this->IntCalcTicksFreeze($maxsteps, $min, $max, 1);
195
        }
196
197 7
        if (abs($min - $max) > 2) {
198
            // Then get tick marks as 2:s 2, 20, ...
199 7
            if ($majend) {
200 6
                list($num2steps, $adj2min, $adj2max, $maj2step) = $this->IntCalcTicks($maxsteps, $min, $max, 5);
201
            } else {
202 3
                $adj2min                    = $min;
203 3
                $adj2max                    = $max;
204 7
                list($num2steps, $maj2step) = $this->IntCalcTicksFreeze($maxsteps, $min, $max, 5);
205
            }
206
        } else {
207
            $num2steps = 10000; // Dummy high value so we don't choose this
208
        }
209
210 7
        if (abs($min - $max) > 5) {
211
            // Then get tickmarks as 5:s 5, 50, 500, ...
212 7
            if ($majend) {
213 6
                list($num5steps, $adj5min, $adj5max, $maj5step) = $this->IntCalcTicks($maxsteps, $min, $max, 2);
214
            } else {
215 3
                $adj5min                    = $min;
216 3
                $adj5max                    = $max;
217 7
                list($num5steps, $maj5step) = $this->IntCalcTicksFreeze($maxsteps, $min, $max, 2);
218
            }
219
        } else {
220 2
            $num5steps = 10000; // Dummy high value so we don't choose this
221
        }
222
223
        // Check to see whichof 1:s, 2:s or 5:s fit better with
224
        // the requested number of major ticks
225 7
        $match1 = abs($num1steps - $maxsteps);
226 7
        $match2 = abs($num2steps - $maxsteps);
227 7
        if (!empty($maj5step) && $maj5step > 1) {
228 7
            $match5 = abs($num5steps - $maxsteps);
229
        } else {
230 2
            $match5 = 10000; // Dummy high value
231
        }
232
233
        // Compare these three values and see which is the closest match
234
        // We use a 0.6 weight to gravitate towards multiple of 5:s
235 7
        if ($match1 < $match2) {
236 7
            if ($match1 < $match5) {
237 7
                $r = 1;
238
            } else {
239 7
                $r = 3;
240
            }
241
        } else {
242 3
            if ($match2 < $match5) {
243 3
                $r = 2;
244
            } else {
245
                $r = 3;
246
            }
247
        }
248
        // Minsteps are always the same as maxsteps for integer scale
249
        switch ($r) {
250 7
            case 1:
251 7
                $this->ticks->Set($maj1step, $maj1step);
252 7
                $this->Update($img, $adj1min, $adj1max);
253
254 7
                break;
255 4
            case 2:
256 3
                $this->ticks->Set($maj2step, $maj2step);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $maj2step does not seem to be defined for all execution paths leading up to this point.
Loading history...
257 3
                $this->Update($img, $adj2min, $adj2max);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $adj2min does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $adj2max does not seem to be defined for all execution paths leading up to this point.
Loading history...
258
259 3
                break;
260 3
            case 3:
261 3
                $this->ticks->Set($maj5step, $maj5step);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $maj5step does not seem to be defined for all execution paths leading up to this point.
Loading history...
262 3
                $this->Update($img, $adj5min, $adj5max);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $adj5max does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $adj5min does not seem to be defined for all execution paths leading up to this point.
Loading history...
263
264 3
                break;
265
            default:
266
                Util\JpGraphError::RaiseL(25073, $r); //('Internal error. Integer scale algorithm comparison out of bound (r=$r)');
267
        }
268 7
    }
269
270
    // Calculate autoscale. Used if user hasn't given a scale and ticks
271
    // $maxsteps is the maximum number of major tickmarks allowed.
272 14
    public function AutoScale($img, $min, $max, $maxsteps, $majend = true)
273
    {
274 14
        if (!is_numeric($min) || !is_numeric($max)) {
275
            Util\JpGraphError::Raise(25044);
276
        }
277
278 14
        if ($this->intscale) {
279 7
            $this->IntAutoScale($img, $min, $max, $maxsteps, $majend);
280
281 7
            return;
282
        }
283 13
        if (abs($min - $max) < 0.00001) {
284
            // We need some difference to be able to autoscale
285
            // make it 5% above and 5% below value
286 1
            if ($min == 0 && $max == 0) {
287
                // Special case
288
                $min = -1;
289
                $max = 1;
290
            } else {
291 1
                $delta = (abs($max) + abs($min)) * 0.005;
292 1
                $min -= $delta;
293 1
                $max += $delta;
294
            }
295
        }
296
297 13
        $gracetop    = ($this->gracetop / 100.0) * abs($max - $min);
298 13
        $gracebottom = ($this->gracebottom / 100.0) * abs($max - $min);
299 13
        if (is_numeric($this->autoscale_min)) {
0 ignored issues
show
introduced by
The condition is_numeric($this->autoscale_min) is always false.
Loading history...
300 2
            $min = $this->autoscale_min;
301 2
            if ($min >= $max) {
302
                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.');
303
            }
304 2
            if (abs($min - $max) < 0.001) {
305
                $max *= 1.2;
306
            }
307
        }
308
309 13
        if (is_numeric($this->autoscale_max)) {
0 ignored issues
show
introduced by
The condition is_numeric($this->autoscale_max) is always false.
Loading history...
310 1
            $max = $this->autoscale_max;
311 1
            if ($min >= $max) {
312
                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.');
313
            }
314 1
            if (abs($min - $max) < 0.001) {
315
                $min *= 0.8;
316
            }
317
        }
318
319 13
        $min -= $gracebottom;
320 13
        $max += $gracetop;
321
322
        // First get tickmarks as multiples of 0.1, 1, 10, ...
323 13
        if ($majend) {
324 13
            list($num1steps, $adj1min, $adj1max, $min1step, $maj1step) = $this->CalcTicks($maxsteps, $min, $max, 1, 2);
325
        } else {
326 5
            $adj1min                               = $min;
327 5
            $adj1max                               = $max;
328 5
            list($num1steps, $min1step, $maj1step) = $this->CalcTicksFreeze($maxsteps, $min, $max, 1, 2, false);
0 ignored issues
show
Unused Code introduced by
The call to Amenadiel\JpGraph\Graph\...cale::CalcTicksFreeze() has too many arguments starting with false. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

328
            /** @scrutinizer ignore-call */ 
329
            list($num1steps, $min1step, $maj1step) = $this->CalcTicksFreeze($maxsteps, $min, $max, 1, 2, false);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
329
        }
330
331
        // Then get tick marks as 2:s 0.2, 2, 20, ...
332 13
        if ($majend) {
333 13
            list($num2steps, $adj2min, $adj2max, $min2step, $maj2step) = $this->CalcTicks($maxsteps, $min, $max, 5, 2);
334
        } else {
335 5
            $adj2min                               = $min;
336 5
            $adj2max                               = $max;
337 5
            list($num2steps, $min2step, $maj2step) = $this->CalcTicksFreeze($maxsteps, $min, $max, 5, 2, false);
338
        }
339
340
        // Then get tickmarks as 5:s 0.05, 0.5, 5, 50, ...
341 13
        if ($majend) {
342 13
            list($num5steps, $adj5min, $adj5max, $min5step, $maj5step) = $this->CalcTicks($maxsteps, $min, $max, 2, 5);
343
        } else {
344 5
            $adj5min                               = $min;
345 5
            $adj5max                               = $max;
346 5
            list($num5steps, $min5step, $maj5step) = $this->CalcTicksFreeze($maxsteps, $min, $max, 2, 5, false);
347
        }
348
349
        // Check to see whichof 1:s, 2:s or 5:s fit better with
350
        // the requested number of major ticks
351 13
        $match1 = abs($num1steps - $maxsteps);
352 13
        $match2 = abs($num2steps - $maxsteps);
353 13
        $match5 = abs($num5steps - $maxsteps);
354
355
        // Compare these three values and see which is the closest match
356
        // We use a 0.8 weight to gravitate towards multiple of 5:s
357 13
        $r = $this->MatchMin3($match1, $match2, $match5, 0.8);
358
        switch ($r) {
359 13
            case 1:
360 9
                $this->Update($img, $adj1min, $adj1max);
361 9
                $this->ticks->Set($maj1step, $min1step);
362
363 9
                break;
364 11
            case 2:
365 8
                $this->Update($img, $adj2min, $adj2max);
366 8
                $this->ticks->Set($maj2step, $min2step);
367
368 8
                break;
369 10
            case 3:
370 10
                $this->Update($img, $adj5min, $adj5max);
371 10
                $this->ticks->Set($maj5step, $min5step);
372
373 10
                break;
374
        }
375 13
    }
376
377
    /**
378
     * PRIVATE METHODS
379
     */
380
381
    // This method recalculates all constants that are depending on the
382
    // margins in the image. If the margins in the image are changed
383
    // this method should be called for every scale that is registred with
384
    // that image. Should really be installed as an observer of that image.
385 14
    public function InitConstants($img)
386
    {
387 14
        if ($this->type == 'x') {
388 14
            $this->world_abs_size = $img->width - $img->left_margin - $img->right_margin;
389 14
            $this->off            = $img->left_margin;
390 14
            $this->scale_factor   = 0;
391 14
            if ($this->world_size > 0) {
392 14
                $this->scale_factor = $this->world_abs_size / ($this->world_size * 1.0);
393
            }
394
        } else {
395
            // y scale
396 14
            $this->world_abs_size = $img->height - $img->top_margin - $img->bottom_margin;
397 14
            $this->off            = $img->top_margin + $this->world_abs_size;
398 14
            $this->scale_factor   = 0;
399 14
            if ($this->world_size > 0) {
400 14
                $this->scale_factor = -$this->world_abs_size / ($this->world_size * 1.0);
401
            }
402
        }
403 14
        $size            = $this->world_size * $this->scale_factor;
404 14
        $this->scale_abs = [$this->off, $this->off + $size];
405 14
    }
406
407
    // Initialize the conversion constants for this scale
408
    // This tries to pre-calculate as much as possible to speed up the
409
    // actual conversion (with Translate()) later on
410
    // $start =scale start in absolute pixels (for x-scale this is an y-position
411
    //     and for an y-scale this is an x-position
412
    // $len   =absolute length in pixels of scale
413
    public function SetConstants($aStart, $aLen)
414
    {
415
        $this->world_abs_size = $aLen;
416
        $this->off            = $aStart;
417
418
        if ($this->world_size <= 0) {
419
            // This should never ever happen !!
420
            Util\JpGraphError::RaiseL(25074);
421
            //("You have unfortunately stumbled upon a bug in JpGraph. It seems like the scale range is ".$this->world_size." [for ".$this->type." scale] <br> Please report Bug #01 to [email protected] and include the script that gave this error. This problem could potentially be caused by trying to use \"illegal\" values in the input data arrays (like trying to send in strings or only NULL values) which causes the autoscaling to fail.");
422
        }
423
424
        // scale_factor = number of pixels per world unit
425
        $this->scale_factor = $this->world_abs_size / ($this->world_size * 1.0);
426
427
        // scale_abs = start and end points of scale in absolute pixels
428
        $this->scale_abs = [$this->off, $this->off + $this->world_size * $this->scale_factor];
429
    }
430
431
    // Calculate number of ticks steps with a specific division
432
    // $a is the divisor of 10**x to generate the first maj tick intervall
433
    // $a=1, $b=2 give major ticks with multiple of 10, ...,0.1,1,10,...
434
    // $a=5, $b=2 give major ticks with multiple of 2:s ...,0.2,2,20,...
435
    // $a=2, $b=5 give major ticks with multiple of 5:s ...,0.5,5,50,...
436
    // We return a vector of
437
    //  [$numsteps,$adjmin,$adjmax,$minstep,$majstep]
438
    // If $majend==true then the first and last marks on the axis will be major
439
    // labeled tick marks otherwise it will be adjusted to the closest min tick mark
440 13
    public function CalcTicks($maxsteps, $min, $max, $a, $b, $majend = true)
441
    {
442 13
        $diff = $max - $min;
443 13
        if ($diff == 0) {
444
            $ld = 0;
445
        } else {
446 13
            $ld = floor(log10($diff));
447
        }
448
449
        // Gravitate min towards zero if we are close
450 13
        if ($min > 0 && $min < pow(10, $ld)) {
451 9
            $min = 0;
452
        }
453
454
        //$majstep=pow(10,$ld-1)/$a;
455 13
        $majstep = pow(10, $ld) / $a;
456 13
        $minstep = $majstep / $b;
457
458 13
        $adjmax   = ceil($max / $minstep) * $minstep;
459 13
        $adjmin   = floor($min / $minstep) * $minstep;
460 13
        $adjdiff  = $adjmax - $adjmin;
461 13
        $numsteps = $adjdiff / $majstep;
462
463 13
        while ($numsteps > $maxsteps) {
464 13
            $majstep  = pow(10, $ld) / $a;
465 13
            $numsteps = $adjdiff / $majstep;
466 13
            ++$ld;
467
        }
468
469 13
        $minstep = $majstep / $b;
470 13
        $adjmin  = floor($min / $minstep) * $minstep;
471 13
        $adjdiff = $adjmax - $adjmin;
0 ignored issues
show
Unused Code introduced by
The assignment to $adjdiff is dead and can be removed.
Loading history...
472 13
        if ($majend) {
473 13
            $adjmin  = floor($min / $majstep) * $majstep;
474 13
            $adjdiff = $adjmax - $adjmin;
475 13
            $adjmax  = ceil($adjdiff / $majstep) * $majstep + $adjmin;
476
        } else {
477
            $adjmax = ceil($max / $minstep) * $minstep;
478
        }
479
480 13
        return [$numsteps, $adjmin, $adjmax, $minstep, $majstep];
481
    }
482
483 5
    public function CalcTicksFreeze($maxsteps, $min, $max, $a, $b)
484
    {
485
        // Same as CalcTicks but don't adjust min/max values
486 5
        $diff = $max - $min;
487 5
        if ($diff == 0) {
488
            $ld = 0;
489
        } else {
490 5
            $ld = floor(log10($diff));
491
        }
492
493
        //$majstep=pow(10,$ld-1)/$a;
494 5
        $majstep  = pow(10, $ld) / $a;
495 5
        $minstep  = $majstep / $b;
0 ignored issues
show
Unused Code introduced by
The assignment to $minstep is dead and can be removed.
Loading history...
496 5
        $numsteps = floor($diff / $majstep);
497
498 5
        while ($numsteps > $maxsteps) {
499 2
            $majstep  = pow(10, $ld) / $a;
500 2
            $numsteps = floor($diff / $majstep);
501 2
            ++$ld;
502
        }
503 5
        $minstep = $majstep / $b;
504
505 5
        return [$numsteps, $minstep, $majstep];
506
    }
507
508 6
    public function IntCalcTicks($maxsteps, $min, $max, $a, $majend = true)
509
    {
510 6
        $diff = $max - $min;
511 6
        if ($diff == 0) {
512
            Util\JpGraphError::RaiseL(25075); //('Can\'t automatically determine ticks since min==max.');
513
        } else {
514 6
            $ld = floor(log10($diff));
515
        }
516
517
        // Gravitate min towards zero if we are close
518 6
        if ($min > 0 && $min < pow(10, $ld)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ld does not seem to be defined for all execution paths leading up to this point.
Loading history...
519 1
            $min = 0;
520
        }
521 6
        if ($ld == 0) {
522 4
            $ld = 1;
523
        }
524 6
        if ($a == 1) {
525 6
            $majstep = 1;
526
        } else {
527 6
            $majstep = pow(10, $ld) / $a;
528
        }
529 6
        $adjmax = ceil($max / $majstep) * $majstep;
530
531 6
        $adjmin   = floor($min / $majstep) * $majstep;
532 6
        $adjdiff  = $adjmax - $adjmin;
533 6
        $numsteps = $adjdiff / $majstep;
534 6
        while ($numsteps > $maxsteps) {
535 3
            $majstep  = pow(10, $ld) / $a;
536 3
            $numsteps = $adjdiff / $majstep;
537 3
            ++$ld;
538
        }
539
540 6
        $adjmin  = floor($min / $majstep) * $majstep;
541 6
        $adjdiff = $adjmax - $adjmin;
0 ignored issues
show
Unused Code introduced by
The assignment to $adjdiff is dead and can be removed.
Loading history...
542 6
        if ($majend) {
543 6
            $adjmin  = floor($min / $majstep) * $majstep;
544 6
            $adjdiff = $adjmax - $adjmin;
545 6
            $adjmax  = ceil($adjdiff / $majstep) * $majstep + $adjmin;
546
        } else {
547
            $adjmax = ceil($max / $majstep) * $majstep;
548
        }
549
550 6
        return [$numsteps, $adjmin, $adjmax, $majstep];
551
    }
552
553 3
    public function IntCalcTicksFreeze($maxsteps, $min, $max, $a)
554
    {
555
        // Same as IntCalcTick but don't change min/max values
556 3
        $diff = $max - $min;
557 3
        if ($diff == 0) {
558
            Util\JpGraphError::RaiseL(25075); //('Can\'t automatically determine ticks since min==max.');
559
        } else {
560 3
            $ld = floor(log10($diff));
561
        }
562 3
        if ($ld == 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ld does not seem to be defined for all execution paths leading up to this point.
Loading history...
563 1
            $ld = 1;
564
        }
565 3
        if ($a == 1) {
566 3
            $majstep = 1;
567
        } else {
568 3
            $majstep = pow(10, $ld) / $a;
569
        }
570
571 3
        $numsteps = floor($diff / $majstep);
572 3
        while ($numsteps > $maxsteps) {
573 3
            $majstep  = pow(10, $ld) / $a;
574 3
            $numsteps = floor($diff / $majstep);
575 3
            ++$ld;
576
        }
577
578 3
        return [$numsteps, $majstep];
579
    }
580
581
    // Determine the minimum of three values witha  weight for last value
582 13
    public function MatchMin3($a, $b, $c, $weight)
583
    {
584 13
        if ($a < $b) {
585 13
            if ($a < ($c * $weight)) {
586 9
                return 1; // $a smallest
587
            }
588
589 10
            return 3; // $c smallest
590
        }
591 8
        if ($b < ($c * $weight)) {
592 8
            return 2; // $b smallest
593
        }
594
595
        return 3; // $c smallest
596
    }
597
598 14
    public function __get($name)
599
    {
600 14
        $variable_name = '_' . $name;
601
602 14
        if (isset($this->{$variable_name})) {
603 14
            return $this->{$variable_name} * SUPERSAMPLING_SCALE;
604
        }
605
        Util\JpGraphError::RaiseL('25132', $name);
606
    }
607
608 14
    public function __set($name, $value)
609
    {
610 14
        $this->{'_' . $name} = $value;
611 14
    }
612
} // @class
613