Split all files mith multiple classes into multiple files
This commit is contained in:
111
src/GraphAxisHorizontal.php
Normal file
111
src/GraphAxisHorizontal.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework;
|
||||
|
||||
/** The graph Axis Horizontal class */
|
||||
class GraphAxisHorizontal extends GraphAxisGeneral
|
||||
{
|
||||
/** Calculate the position in pixels for a value
|
||||
* If the value is out of range, return null to not draw the point
|
||||
* @param string|float|integer $value The value to position
|
||||
*/
|
||||
public function position($value)
|
||||
{
|
||||
if ($value === null) {
|
||||
return null;
|
||||
}
|
||||
if (! is_numeric($value) && ! is_string($value)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"Invalid value provided to graph Axis for position"
|
||||
) . " " .
|
||||
get_class($this), 406);
|
||||
}
|
||||
if ($this->numerical === null) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"No numerical type defined for Axis"
|
||||
) . " " . get_class($this), 406);
|
||||
}
|
||||
if ($this->numerical) {
|
||||
// Numerical axis, use a standard scale
|
||||
if ($value < $this->min || $value > $this->max) {
|
||||
return null;
|
||||
}
|
||||
if (($this->max - $this->min) == 0) {
|
||||
$dividor = 1;
|
||||
} else {
|
||||
$dividor = ($this->max - $this->min);
|
||||
}
|
||||
$scale = ($value - $this->min) / $dividor;
|
||||
return intval($this->left + $scale * ($this->right - $this->left));
|
||||
} else {
|
||||
// Label axis, count them
|
||||
if (! is_array($this->data)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"No data defined for Axis"
|
||||
) . " " . get_class($this), 406);
|
||||
}
|
||||
$pos = array_search($value, $this->data);
|
||||
if ($pos === false) {
|
||||
return null;
|
||||
}
|
||||
$width = ($this->right - $this->left) / count($this->data);
|
||||
return intval($this->left + $width * $pos + $width / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/** Calculate the positionMin, used for labeled axies
|
||||
* If the value is out of range, return null to not draw the point
|
||||
* @param string|float|integer $value The value to position
|
||||
*/
|
||||
public function positionMin($value)
|
||||
{
|
||||
if ($this->numerical) {
|
||||
return $posCenter;
|
||||
}
|
||||
if (! is_array($this->data)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"No data defined for Axis"
|
||||
) . " " . get_class($this), 406);
|
||||
}
|
||||
$pos = array_search($value, $this->data);
|
||||
if ($pos === false) {
|
||||
return null;
|
||||
}
|
||||
$width = ($this->right - $this->left) / count($this->data);
|
||||
return intval($this->left + $width * $pos);
|
||||
}
|
||||
|
||||
/** Calculate the positionMax, used for labeled axies
|
||||
* If the value is out of range, return null to not draw the point
|
||||
* @param string|float|integer $value The value to position
|
||||
*/
|
||||
public function positionMax($value)
|
||||
{
|
||||
$posCenter = $this->position($value);
|
||||
if ($this->numerical) {
|
||||
return $posCenter;
|
||||
}
|
||||
if (! is_array($this->data)) {
|
||||
throw new \Exception(dgettext(
|
||||
"domframework",
|
||||
"No data defined for Axis"
|
||||
) . " " . get_class($this), 406);
|
||||
}
|
||||
$pos = array_search($value, $this->data);
|
||||
if ($pos === false) {
|
||||
return null;
|
||||
}
|
||||
$width = ($this->right - $this->left) / count($this->data);
|
||||
return intval($this->left + $width * $pos + $width);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user