LinearScale::SetConstants()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
rs 10
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
 * @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
    public function __construct($aMin = 0, $aMax = 0, $aType = 'y')
42
    {
43
        assert($aType == 'x' || $aType == 'y');
44
        assert($aMin <= $aMax);
45
46
        $this->type       = $aType;
47
        $this->scale      = [$aMin, $aMax];
48
        $this->world_size = $aMax - $aMin;
0 ignored issues
show
Bug Best Practice introduced by
The property world_size does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
49
        $this->ticks      = new LinearTicks();
50
    }
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
    public function IsSpecified()
55
    {
56
        if ($this->GetMinVal() == $this->GetMaxVal()) {
57
            // Scale not set
58
            return false;
59
        }
60
61
        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
    public function SetAutoMin($aMin)
68
    {
69
        $this->autoscale_min = $aMin;
70
    }
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
    public function SetAutoMax($aMax)
76
    {
77
        $this->autoscale_max = $aMax;
78
    }
79
80
    // If the user manually specifies a scale should the ticks
81
    // still be set automatically?
82
    public function SetAutoTicks($aFlag = true)
83
    {
84
        $this->auto_ticks = $aFlag;
85
    }
86
87
    // Specify scale "grace" value (top and bottom)
88
    public function SetGrace($aGraceTop, $aGraceBottom = 0)
89
    {
90
        if ($aGraceTop < 0 || $aGraceBottom < 0) {
91
            Util\JpGraphError::RaiseL(25069); //(" Grace must be larger then 0");
92
        }
93
        $this->gracetop    = $aGraceTop;
94
        $this->gracebottom = $aGraceBottom;
95
    }
96
97
    // Get the minimum value in the scale
98
    public function GetMinVal()
99
    {
100
        return $this->scale[0];
101
    }
102
103
    // get maximum value for scale
104
    public function GetMaxVal()
105
    {
106
        return $this->scale[1];
107
    }
108
109
    // Specify a new min/max value for sclae
110
    public function Update($aImg, $aMin, $aMax)
111
    {
112
        $this->scale      = [$aMin, $aMax];
113
        $this->world_size = $aMax - $aMin;
0 ignored issues
show
Bug Best Practice introduced by
The property world_size does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
114
        $this->InitConstants($aImg);
115
    }
116
117
    // Translate between world and screen
118
    public function Translate($aCoord)
119
    {
120
        if (!is_numeric($aCoord)) {
121
            if ($aCoord != '' && $aCoord != '-' && $aCoord != 'x') {
122
                Util\JpGraphError::RaiseL(25070); //('Your data contains non-numeric values.');
123
            }
124
125
            return 0;
126
        }
127
128
        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
    public function SetIntScale($aIntScale = true)
148
    {
149
        $this->intscale = $aIntScale;
150
    }
151
152
    // Calculate an integer autoscale
153
    public function IntAutoScale($img, $min, $max, $maxsteps, $majend = true)
154
    {
155
        // Make sure limits are integers
156
        $min = floor($min);
157
        $max = ceil($max);
158
        if (abs($min - $max) == 0) {
159
            --$min;
160
            ++$max;
161
        }
162
        $maxsteps = floor($maxsteps);
163
164
        $gracetop    = round(($this->gracetop / 100.0) * abs($max - $min));
165
        $gracebottom = round(($this->gracebottom / 100.0) * abs($max - $min));
166
        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
        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
        if (abs($min - $max) == 0) {
181
            ++$max;
182
            --$min;
183
        }
184
185
        $min -= $gracebottom;
186
        $max += $gracetop;
187
188
        // First get tickmarks as multiples of 1, 10, ...
189
        if ($majend) {
190
            list($num1steps, $adj1min, $adj1max, $maj1step) = $this->IntCalcTicks($maxsteps, $min, $max, 1);
191
        } else {
192
            $adj1min                    = $min;
193
            $adj1max                    = $max;
194
            list($num1steps, $maj1step) = $this->IntCalcTicksFreeze($maxsteps, $min, $max, 1);
195
        }
196
197
        if (abs($min - $max) > 2) {
198
            // Then get tick marks as 2:s 2, 20, ...
199
            if ($majend) {
200
                list($num2steps, $adj2min, $adj2max, $maj2step) = $this->IntCalcTicks($maxsteps, $min, $max, 5);
201
            } else {
202
                $adj2min                    = $min;
203
                $adj2max                    = $max;
204
                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
        if (abs($min - $max) > 5) {
211
            // Then get tickmarks as 5:s 5, 50, 500, ...
212
            if ($majend) {
213
                list($num5steps, $adj5min, $adj5max, $maj5step) = $this->IntCalcTicks($maxsteps, $min, $max, 2);
214
            } else {
215
                $adj5min                    = $min;
216
                $adj5max                    = $max;
217
                list($num5steps, $maj5step) = $this->IntCalcTicksFreeze($maxsteps, $min, $max, 2);
218
            }
219
        } else {
220
            $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
        $match1 = abs($num1steps - $maxsteps);
226
        $match2 = abs($num2steps - $maxsteps);
227
        if (!empty($maj5step) && $maj5step > 1) {
228
            $match5 = abs($num5steps - $maxsteps);
229
        } else {
230
            $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
        if ($match1 < $match2) {
236
            if ($match1 < $match5) {
237
                $r = 1;
238
            } else {
239
                $r = 3;
240
            }
241
        } else {
242
            if ($match2 < $match5) {
243
                $r = 2;
244
            } else {
245
                $r = 3;
246
            }
247
        }
248
        // Minsteps are always the same as maxsteps for integer scale
249
        switch ($r) {
250
            case 1:
251
                $this->ticks->Set($maj1step, $maj1step);
252
                $this->Update($img, $adj1min, $adj1max);
253
254
                break;
255
            case 2:
256
                $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
                $this->Update($img, $adj2min, $adj2max);
0 ignored issues
show
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...
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...
258
259
                break;
260
            case 3:
261
                $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
                $this->Update($img, $adj5min, $adj5max);
0 ignored issues
show
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...
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...
263
264
                break;
265
            default:
266
                Util\JpGraphError::RaiseL(25073, $r); //('Internal error. Integer scale algorithm comparison out of bound (r=$r)');
267
        }
268
    }
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
    public function AutoScale($img, $min, $max, $maxsteps, $majend = true)
273
    {
274
        if (!is_numeric($min) || !is_numeric($max)) {
275
            Util\JpGraphError::Raise(25044);
276
        }
277
278
        if ($this->intscale) {
279
            $this->IntAutoScale($img, $min, $max, $maxsteps, $majend);
280
281
            return;
282
        }
283
        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
            if ($min == 0 && $max == 0) {
287
                // Special case
288
                $min = -1;
289
                $max = 1;
290
            } else {
291
                $delta = (abs($max) + abs($min)) * 0.005;
292
                $min -= $delta;
293
                $max += $delta;
294
            }
295
        }
296
297
        $gracetop    = ($this->gracetop / 100.0) * abs($max - $min);
298
        $gracebottom = ($this->gracebottom / 100.0) * abs($max - $min);
299
        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
            $min = $this->autoscale_min;
301
            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
            if (abs($min - $max) < 0.001) {
305
                $max *= 1.2;
306
            }
307
        }
308
309
        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
            $max = $this->autoscale_max;
311
            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
            if (abs($min - $max) < 0.001) {
315
                $min *= 0.8;
316
            }
317
        }
318
319
        $min -= $gracebottom;
320
        $max += $gracetop;
321
322
        // First get tickmarks as multiples of 0.1, 1, 10, ...
323
        if ($majend) {
324
            list($num1steps, $adj1min, $adj1max, $min1step, $maj1step) = $this->CalcTicks($maxsteps, $min, $max, 1, 2);
325
        } else {
326
            $adj1min                               = $min;
327
            $adj1max                               = $max;
328
            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
        if ($majend) {
333
            list($num2steps, $adj2min, $adj2max, $min2step, $maj2step) = $this->CalcTicks($maxsteps, $min, $max, 5, 2);
334
        } else {
335
            $adj2min                               = $min;
336
            $adj2max                               = $max;
337
            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
        if ($majend) {
342
            list($num5steps, $adj5min, $adj5max, $min5step, $maj5step) = $this->CalcTicks($maxsteps, $min, $max, 2, 5);
343
        } else {
344
            $adj5min                               = $min;
345
            $adj5max                               = $max;
346
            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
        $match1 = abs($num1steps - $maxsteps);
352
        $match2 = abs($num2steps - $maxsteps);
353
        $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
        $r = $this->MatchMin3($match1, $match2, $match5, 0.8);
358
        switch ($r) {
359
            case 1:
360
                $this->Update($img, $adj1min, $adj1max);
361
                $this->ticks->Set($maj1step, $min1step);
362
363
                break;
364
            case 2:
365
                $this->Update($img, $adj2min, $adj2max);
366
                $this->ticks->Set($maj2step, $min2step);
367
368
                break;
369
            case 3:
370
                $this->Update($img, $adj5min, $adj5max);
371
                $this->ticks->Set($maj5step, $min5step);
372
373
                break;
374
        }
375
    }
376
377
    /**
378
     * PRIVATE METHODS.
379
     *
380
     * @param mixed $img
381
     */
382
383
    // This method recalculates all constants that are depending on the
384
    // margins in the image. If the margins in the image are changed
385
    // this method should be called for every scale that is registred with
386
    // that image. Should really be installed as an observer of that image.
387
    public function InitConstants($img)
388
    {
389
        if ($this->type == 'x') {
390
            $this->world_abs_size = $img->width - $img->left_margin - $img->right_margin;
391
            $this->off            = $img->left_margin;
392
            $this->scale_factor   = 0;
393
            if ($this->world_size > 0) {
394
                $this->scale_factor = $this->world_abs_size / ($this->world_size * 1.0);
395
            }
396
        } else {
397
            // y scale
398
            $this->world_abs_size = $img->height - $img->top_margin - $img->bottom_margin;
399
            $this->off            = $img->top_margin + $this->world_abs_size;
400
            $this->scale_factor   = 0;
401
            if ($this->world_size > 0) {
402
                $this->scale_factor = -$this->world_abs_size / ($this->world_size * 1.0);
403
            }
404
        }
405
        $size            = $this->world_size * $this->scale_factor;
406
        $this->scale_abs = [$this->off, $this->off + $size];
407
    }
408
409
    // Initialize the conversion constants for this scale
410
    // This tries to pre-calculate as much as possible to speed up the
411
    // actual conversion (with Translate()) later on
412
    // $start =scale start in absolute pixels (for x-scale this is an y-position
413
    //     and for an y-scale this is an x-position
414
    // $len   =absolute length in pixels of scale
415
    public function SetConstants($aStart, $aLen)
416
    {
417
        $this->world_abs_size = $aLen;
418
        $this->off            = $aStart;
419
420
        if ($this->world_size <= 0) {
421
            // This should never ever happen !!
422
            Util\JpGraphError::RaiseL(25074);
423
            //("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.");
424
        }
425
426
        // scale_factor = number of pixels per world unit
427
        $this->scale_factor = $this->world_abs_size / ($this->world_size * 1.0);
428
429
        // scale_abs = start and end points of scale in absolute pixels
430
        $this->scale_abs = [$this->off, $this->off + $this->world_size * $this->scale_factor];
431
    }
432
433
    // Calculate number of ticks steps with a specific division
434
    // $a is the divisor of 10**x to generate the first maj tick intervall
435
    // $a=1, $b=2 give major ticks with multiple of 10, ...,0.1,1,10,...
436
    // $a=5, $b=2 give major ticks with multiple of 2:s ...,0.2,2,20,...
437
    // $a=2, $b=5 give major ticks with multiple of 5:s ...,0.5,5,50,...
438
    // We return a vector of
439
    //  [$numsteps,$adjmin,$adjmax,$minstep,$majstep]
440
    // If $majend==true then the first and last marks on the axis will be major
441
    // labeled tick marks otherwise it will be adjusted to the closest min tick mark
442
    public function CalcTicks($maxsteps, $min, $max, $a, $b, $majend = true)
443
    {
444
        $diff = $max - $min;
445
        if ($diff == 0) {
446
            $ld = 0;
447
        } else {
448
            $ld = floor(log10($diff));
449
        }
450
451
        // Gravitate min towards zero if we are close
452
        if ($min > 0 && $min < pow(10, $ld)) {
453
            $min = 0;
454
        }
455
456
        //$majstep=pow(10,$ld-1)/$a;
457
        $majstep = pow(10, $ld) / $a;
458
        $minstep = $majstep / $b;
459
460
        $adjmax   = ceil($max / $minstep) * $minstep;
461
        $adjmin   = floor($min / $minstep) * $minstep;
462
        $adjdiff  = $adjmax - $adjmin;
463
        $numsteps = $adjdiff / $majstep;
464
465
        while ($numsteps > $maxsteps) {
466
            $majstep  = pow(10, $ld) / $a;
467
            $numsteps = $adjdiff / $majstep;
468
            ++$ld;
469
        }
470
471
        $minstep = $majstep / $b;
472
        $adjmin  = floor($min / $minstep) * $minstep;
473
        $adjdiff = $adjmax - $adjmin;
0 ignored issues
show
Unused Code introduced by
The assignment to $adjdiff is dead and can be removed.
Loading history...
474
        if ($majend) {
475
            $adjmin  = floor($min / $majstep) * $majstep;
476
            $adjdiff = $adjmax - $adjmin;
477
            $adjmax  = ceil($adjdiff / $majstep) * $majstep + $adjmin;
478
        } else {
479
            $adjmax = ceil($max / $minstep) * $minstep;
480
        }
481
482
        return [$numsteps, $adjmin, $adjmax, $minstep, $majstep];
483
    }
484
485
    public function CalcTicksFreeze($maxsteps, $min, $max, $a, $b)
486
    {
487
        // Same as CalcTicks but don't adjust min/max values
488
        $diff = $max - $min;
489
        if ($diff == 0) {
490
            $ld = 0;
491
        } else {
492
            $ld = floor(log10($diff));
493
        }
494
495
        //$majstep=pow(10,$ld-1)/$a;
496
        $majstep  = pow(10, $ld) / $a;
497
        $minstep  = $majstep / $b;
0 ignored issues
show
Unused Code introduced by
The assignment to $minstep is dead and can be removed.
Loading history...
498
        $numsteps = floor($diff / $majstep);
499
500
        while ($numsteps > $maxsteps) {
501
            $majstep  = pow(10, $ld) / $a;
502
            $numsteps = floor($diff / $majstep);
503
            ++$ld;
504
        }
505
        $minstep = $majstep / $b;
506
507
        return [$numsteps, $minstep, $majstep];
508
    }
509
510
    public function IntCalcTicks($maxsteps, $min, $max, $a, $majend = true)
511
    {
512
        $diff = $max - $min;
513
        if ($diff == 0) {
514
            Util\JpGraphError::RaiseL(25075); //('Can\'t automatically determine ticks since min==max.');
515
        } else {
516
            $ld = floor(log10($diff));
517
        }
518
519
        // Gravitate min towards zero if we are close
520
        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...
521
            $min = 0;
522
        }
523
        if ($ld == 0) {
524
            $ld = 1;
525
        }
526
        if ($a == 1) {
527
            $majstep = 1;
528
        } else {
529
            $majstep = pow(10, $ld) / $a;
530
        }
531
        $adjmax = ceil($max / $majstep) * $majstep;
532
533
        $adjmin   = floor($min / $majstep) * $majstep;
534
        $adjdiff  = $adjmax - $adjmin;
535
        $numsteps = $adjdiff / $majstep;
536
        while ($numsteps > $maxsteps) {
537
            $majstep  = pow(10, $ld) / $a;
538
            $numsteps = $adjdiff / $majstep;
539
            ++$ld;
540
        }
541
542
        $adjmin  = floor($min / $majstep) * $majstep;
543
        $adjdiff = $adjmax - $adjmin;
0 ignored issues
show
Unused Code introduced by
The assignment to $adjdiff is dead and can be removed.
Loading history...
544
        if ($majend) {
545
            $adjmin  = floor($min / $majstep) * $majstep;
546
            $adjdiff = $adjmax - $adjmin;
547
            $adjmax  = ceil($adjdiff / $majstep) * $majstep + $adjmin;
548
        } else {
549
            $adjmax = ceil($max / $majstep) * $majstep;
550
        }
551
552
        return [$numsteps, $adjmin, $adjmax, $majstep];
553
    }
554
555
    public function IntCalcTicksFreeze($maxsteps, $min, $max, $a)
556
    {
557
        // Same as IntCalcTick but don't change min/max values
558
        $diff = $max - $min;
559
        if ($diff == 0) {
560
            Util\JpGraphError::RaiseL(25075); //('Can\'t automatically determine ticks since min==max.');
561
        } else {
562
            $ld = floor(log10($diff));
563
        }
564
        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...
565
            $ld = 1;
566
        }
567
        if ($a == 1) {
568
            $majstep = 1;
569
        } else {
570
            $majstep = pow(10, $ld) / $a;
571
        }
572
573
        $numsteps = floor($diff / $majstep);
574
        while ($numsteps > $maxsteps) {
575
            $majstep  = pow(10, $ld) / $a;
576
            $numsteps = floor($diff / $majstep);
577
            ++$ld;
578
        }
579
580
        return [$numsteps, $majstep];
581
    }
582
583
    // Determine the minimum of three values witha  weight for last value
584
    public function MatchMin3($a, $b, $c, $weight)
585
    {
586
        if ($a < $b) {
587
            if ($a < ($c * $weight)) {
588
                return 1; // $a smallest
589
            }
590
591
            return 3; // $c smallest
592
        }
593
        if ($b < ($c * $weight)) {
594
            return 2; // $b smallest
595
        }
596
597
        return 3; // $c smallest
598
    }
599
600
    public function __get($name)
601
    {
602
        $variable_name = '_' . $name;
603
604
        if (isset($this->{$variable_name})) {
605
            return $this->{$variable_name} * SUPERSAMPLING_SCALE;
606
        }
607
        Util\JpGraphError::RaiseL('25132', $name);
608
    }
609
610
    public function __set($name, $value)
611
    {
612
        $this->{'_' . $name} = $value;
613
    }
614
} // @class
615