| 1 |
<?php |
| 2 |
/** |
| 3 |
* Copyright (C) 2021 Graham Breach |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU Lesser General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU Lesser General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Lesser General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
/** |
| 19 |
* For more information, please contact <graham@goat1000.com> |
| 20 |
*/ |
| 21 |
|
| 22 |
namespace Goat1000\SVGGraph; |
| 23 |
|
| 24 |
/** |
| 25 |
* Class for logarithmic axis with specific tick marks |
| 26 |
*/ |
| 27 |
class AxisLogTicks extends AxisLog { |
| 28 |
|
| 29 |
protected $ticks; |
| 30 |
|
| 31 |
public function __construct($length, $max_val, $min_val, $min_unit, |
| 32 |
$min_space, $fit, $units_before, $units_after, $decimal_digits, |
| 33 |
$base, $divisions, $label_callback, $values, $ticks) |
| 34 |
{ |
| 35 |
sort($ticks); |
| 36 |
$this->ticks = []; |
| 37 |
|
| 38 |
// only keep the ticks that are inside the axis bounds |
| 39 |
foreach($ticks as $t) { |
| 40 |
if($t >= $min_val && $t <= $max_val) |
| 41 |
$this->ticks[] = $t; |
| 42 |
} |
| 43 |
|
| 44 |
if(count($this->ticks) < 1) |
| 45 |
throw new \Exception('No ticks in axis range'); |
| 46 |
|
| 47 |
parent::__construct($length, $max_val, $min_val, $min_unit, |
| 48 |
$min_space, $fit, $units_before, $units_after, $decimal_digits, |
| 49 |
$base, $divisions, $label_callback, $values); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Returns the grid points as an array of GridPoints |
| 54 |
*/ |
| 55 |
public function getGridPoints($start) |
| 56 |
{ |
| 57 |
if($start === null) |
| 58 |
return; |
| 59 |
|
| 60 |
$points = []; |
| 61 |
foreach($this->ticks as $val) { |
| 62 |
$position = $this->position($val); |
| 63 |
$position = $start + ($this->direction * $position); |
| 64 |
$points[] = $this->getGridPoint($position, $val); |
| 65 |
} |
| 66 |
|
| 67 |
if($this->direction < 0) { |
| 68 |
usort($points, function($a, $b) { return $b->position - $a->position; }); |
| 69 |
} else { |
| 70 |
usort($points, function($a, $b) { return $a->position - $b->position; }); |
| 71 |
} |
| 72 |
|
| 73 |
return $points; |
| 74 |
} |
| 75 |
} |
| 76 |
|