mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
artichow was used only for captcha generation so i replaced with
dolibarr code to allow to remove completely artichow (artichow project is dead).
This commit is contained in:
parent
4c0d7378d3
commit
ebf8a6eef4
|
|
@ -30,31 +30,38 @@ if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC',1);
|
|||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1);
|
||||
|
||||
require_once("../main.inc.php");
|
||||
require_once(ARTICHOW_PATH.'Artichow.cfg.php');
|
||||
require_once(ARTICHOW.'/AntiSpam.class.php');
|
||||
|
||||
$object = new AntiSpam();
|
||||
|
||||
// Value of image will contains 5 characters
|
||||
$value=$object->setRand(5);
|
||||
$object->setSize(128,36);
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
// Set value in session variable dol_antispam_value
|
||||
$object->save('dol_antispam_value');
|
||||
$length=5;
|
||||
$letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
|
||||
$number = strlen($letters);
|
||||
$string = '';
|
||||
for($i = 0; $i < $length; $i++)
|
||||
{
|
||||
$string .= $letters{mt_rand(0, $number - 1)};
|
||||
}
|
||||
//print $string;
|
||||
|
||||
$object->setNoise(0);
|
||||
$object->setAntiAliasing(false);
|
||||
|
||||
$colorbg1=new Color(250,250,250);
|
||||
$colorbg2=new Color(230,220,210);
|
||||
$colorfg=new Color(100,100,100);
|
||||
$colorbr=new Color(220,210,200);
|
||||
$colorra=new LinearGradient($colorbg1,$colorbg2,90);
|
||||
//$object->setBackgroundColor($colorbg);
|
||||
$object->setBackgroundGradient($colorra);
|
||||
$object->border->setColor($colorbr);
|
||||
$sessionkey='dol_antispam_value';
|
||||
$_SESSION[$sessionkey]=$string;
|
||||
|
||||
// On affiche l'image à l'écran
|
||||
$object->draw();
|
||||
header("Content-type: image/png");
|
||||
|
||||
$img = imagecreate(80,32);
|
||||
if (empty($img))
|
||||
{
|
||||
dol_print_error('',"Problem with GD creation");
|
||||
exit;
|
||||
}
|
||||
|
||||
$background_color = imagecolorallocate($img, 250, 250, 250);
|
||||
$ecriture_color = imagecolorallocate($img, 0, 0, 0);
|
||||
imagestring($img, 4, 24, 8, $string, $ecriture_color);
|
||||
imagepng($img);
|
||||
|
||||
?>
|
||||
|
|
@ -245,7 +245,7 @@ jQuery(document).ready(function () {
|
|||
|
||||
<table style="width: 100px;"><tr>
|
||||
<td><input id="securitycode" class="flat" type="text" size="6" maxlength="5" name="code" tabindex="4" /></td>
|
||||
<td><img src="<?php echo DOL_URL_ROOT ?>/core/antispamimage.php" border="0" width="128" height="36" /></td>
|
||||
<td><img src="<?php echo DOL_URL_ROOT ?>/core/antispamimage.php" border="0" width="80" height="32" /></td>
|
||||
<td><a href="<?php echo $php_self; ?>"><?php echo $captcha_refresh; ?></a></td>
|
||||
</tr></table>
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ function donnefocus() {
|
|||
|
||||
<table style="width: 100px;"><tr>
|
||||
<td><input id="securitycode" class="flat" type="text" size="6" maxlength="5" name="code" tabindex="3"></td>
|
||||
<td><img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="128" height="36"></td>
|
||||
<td><img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="80" height="32"></td>
|
||||
<td><a href="<?php echo $php_self; ?>"><?php echo $captcha_refresh; ?></a></td>
|
||||
</tr></table>
|
||||
|
||||
|
|
|
|||
|
|
@ -189,13 +189,13 @@ if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', (!isset(
|
|||
if (! defined('GEOIP_PATH')) { define('GEOIP_PATH', (!isset($dolibarr_lib_GEOIP_PATH))?DOL_DOCUMENT_ROOT.'/includes/geoip/':(empty($dolibarr_lib_GEOIP_PATH)?'':$dolibarr_lib_GEOIP_PATH.'/')); }
|
||||
if (! defined('ODTPHP_PATH')) { define('ODTPHP_PATH', (!isset($dolibarr_lib_ODTPHP_PATH))?DOL_DOCUMENT_ROOT.'/includes/odtphp/':(empty($dolibarr_lib_ODTPHP_PATH)?'':$dolibarr_lib_ODTPHP_PATH.'/')); }
|
||||
if (! defined('ODTPHP_PATHTOPCLZIP')) { define('ODTPHP_PATHTOPCLZIP', (!isset($dolibarr_lib_ODTPHP_PATHTOPCLZIP))?DOL_DOCUMENT_ROOT.'/includes/odtphp/zip/pclzip/':(empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP)?'':$dolibarr_lib_ODTPHP_PATHTOPCLZIP.'/')); }
|
||||
if (! defined('ARTICHOW_PATH')) { define('ARTICHOW_PATH', (!isset($dolibarr_lib_ARTICHOW))?DOL_DOCUMENT_ROOT.'/includes/artichow/':(empty($dolibarr_lib_ARTICHOW)?'':$dolibarr_lib_ARTICHOW.'/')); }
|
||||
// Other required path
|
||||
if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/fonts':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
|
||||
if (! defined('ARTICHOW_FONT_NAMES')) { define('ARTICHOW_FONT_NAMES', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?'Aerial,AerialBd,AerialBdIt,AerialIt':'DejaVuSans,DejaVuSans-Bold,DejaVuSans-BoldOblique,DejaVuSans-Oblique'); }
|
||||
if (! defined('DOL_DEFAULT_TTF')) { define('DOL_DEFAULT_TTF', (!isset($dolibarr_font_DOL_DEFAULT_TTF))?DOL_DOCUMENT_ROOT.'/includes/fonts/Aerial.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF)?'':$dolibarr_font_DOL_DEFAULT_TTF)); }
|
||||
if (! defined('DOL_DEFAULT_TTF_BOLD')) { define('DOL_DEFAULT_TTF_BOLD', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/fonts/AerialBd.ttf':(empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?'':$dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
|
||||
// Old path to root deprecated (no more used).
|
||||
//if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?DOL_DOCUMENT_ROOT.'/includes/fonts':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); }
|
||||
//if (! defined('ARTICHOW_FONT_NAMES')) { define('ARTICHOW_FONT_NAMES', (!isset($dolibarr_font_DOL_DEFAULT_TTF_BOLD))?'Aerial,AerialBd,AerialBdIt,AerialIt':'DejaVuSans,DejaVuSans-Bold,DejaVuSans-BoldOblique,DejaVuSans-Oblique'); }
|
||||
//if (! defined('ARTICHOW_PATH')) { define('ARTICHOW_PATH', (!isset($dolibarr_lib_ARTICHOW))?DOL_DOCUMENT_ROOT.'/includes/artichow/':(empty($dolibarr_lib_ARTICHOW)?'':$dolibarr_lib_ARTICHOW.'/')); }
|
||||
//if (! defined('FPDF_PATH')) { define('FPDF_PATH', DOL_DOCUMENT_ROOT .'/includes/fpdf/fpdf/'); }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Path to Artichow
|
||||
*/
|
||||
|
||||
define('ARTICHOW', dirname(__FILE__).DIRECTORY_SEPARATOR.'php5');
|
||||
|
||||
|
||||
/*
|
||||
* Path to TrueType fonts
|
||||
*/
|
||||
if(defined('ARTICHOW_FONT') === FALSE) {
|
||||
|
||||
define('ARTICHOW_FONT', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'font');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Patterns directory
|
||||
*/
|
||||
if(defined('ARTICHOW_PATTERN') === FALSE) {
|
||||
|
||||
define('ARTICHOW_PATTERN', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'patterns');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Images directory
|
||||
*/
|
||||
if(defined('ARTICHOW_IMAGE') === FALSE) {
|
||||
|
||||
define('ARTICHOW_IMAGE', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'images');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable/disable cache support
|
||||
*/
|
||||
define('ARTICHOW_CACHE', TRUE);
|
||||
|
||||
/*
|
||||
* Cache directory
|
||||
*/
|
||||
if(defined('ARTICHOW_CACHE') === FALSE) {
|
||||
|
||||
define('ARTICHOW_CACHE_DIRECTORY', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'cache');
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Prefix for class names
|
||||
* No prefix by default
|
||||
*/
|
||||
define('ARTICHOW_PREFIX', '');
|
||||
|
||||
/*
|
||||
* Trigger errors when use of a deprecated feature
|
||||
*/
|
||||
define('ARTICHOW_DEPRECATED', TRUE);
|
||||
|
||||
/*
|
||||
* Fonts to use
|
||||
*/
|
||||
|
||||
// DOL_CHANGE LDR
|
||||
if (defined('ARTICHOW_FONT_NAMES')) $fonts=explode(',',constant('ARTICHOW_FONT_NAMES'));
|
||||
else $fonts = array(
|
||||
'Aerial',
|
||||
'AerialBd',
|
||||
'AerialBdIt',
|
||||
'AerialIt'
|
||||
);
|
||||
global $artichow_defaultfont;
|
||||
$artichow_defaultfont=$fonts[0];
|
||||
//var_dump(ARTICHOW_FONT);
|
||||
//var_dump($fonts);
|
||||
//var_dump($artichow_defaultfont);
|
||||
//exit;
|
||||
?>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?php
|
||||
require_once dirname(__FILE__).'/Artichow.cfg.php';
|
||||
require_once ARTICHOW.'/BarPlot.class.php';
|
||||
?>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?php
|
||||
require_once dirname(__FILE__).'/Artichow.cfg.php';
|
||||
require_once ARTICHOW.'/Graph.class.php';
|
||||
?>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?php
|
||||
require_once dirname(__FILE__).'/Artichow.cfg.php';
|
||||
require_once ARTICHOW.'/Image.class.php';
|
||||
?>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?php
|
||||
require_once dirname(__FILE__).'/Artichow.cfg.php';
|
||||
require_once ARTICHOW.'/LinePlot.class.php';
|
||||
?>
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
<?php
|
||||
require_once dirname(__FILE__).'/Artichow.cfg.php';
|
||||
require_once ARTICHOW.'/Pie.class.php';
|
||||
?>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
Source
|
||||
|
||||
http://www.artichow.org/data/Artichow-1.0.7-php4+5.tar.gz
|
||||
|
||||
Ne pas utiliser la version 1.0.9 qui est buggee
|
||||
|
|
@ -1,218 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
/**
|
||||
* AntiSpam
|
||||
* String printed on the images are case insensitive.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awAntiSpam extends awImage {
|
||||
|
||||
/**
|
||||
* Anti-spam string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $string;
|
||||
|
||||
/**
|
||||
* Noise intensity
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $noise = 0;
|
||||
|
||||
/**
|
||||
* Construct a new awAntiSpam image
|
||||
*
|
||||
* @param string $string A string to display
|
||||
*/
|
||||
public function __construct($string = '') {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->string = (string)$string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random string
|
||||
*
|
||||
* @param int $length String length
|
||||
* @return string String created
|
||||
*/
|
||||
public function setRand($length) {
|
||||
|
||||
$length = (int)$length;
|
||||
|
||||
$this->string = '';
|
||||
|
||||
$letters = 'aAbBCDeEFgGhHJKLmMnNpPqQRsStTuVwWXYZz2345679';
|
||||
$number = strlen($letters);
|
||||
|
||||
for($i = 0; $i < $length; $i++) {
|
||||
$this->string .= $letters{mt_rand(0, $number - 1)};
|
||||
}
|
||||
|
||||
return $this->string;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set noise on image
|
||||
*
|
||||
* @param int $nois Noise intensity (from 0 to 10)
|
||||
*/
|
||||
public function setNoise($noise) {
|
||||
if($noise < 0) {
|
||||
$noise = 0;
|
||||
}
|
||||
if($noise > 10) {
|
||||
$noise = 10;
|
||||
}
|
||||
$this->noise = (int)$noise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save string value in session
|
||||
* You can use check() to verify the value later
|
||||
*
|
||||
* @param string $qName A name that identify the anti-spam image
|
||||
*/
|
||||
public function save($qName) {
|
||||
$this->session();
|
||||
$session = 'artichow_'.(string)$qName;
|
||||
$_SESSION[$session] = $this->string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify user entry
|
||||
*
|
||||
* @param string $qName A name that identify the anti-spam image
|
||||
* @param string $value User-defined value
|
||||
* @param bool $case TRUE for case insensitive check, FALSE for case sensitive check ? (default to TRUE)
|
||||
* @return bool TRUE if the value is correct, FALSE otherwise
|
||||
*/
|
||||
public function check($qName, $value, $case = TRUE) {
|
||||
|
||||
$this->session();
|
||||
|
||||
$session = 'artichow_'.(string)$qName;
|
||||
|
||||
return (
|
||||
array_key_exists($session, $_SESSION) === TRUE and
|
||||
$case ?
|
||||
(strtolower($_SESSION[$session]) === strtolower((string)$value)) :
|
||||
($_SESSION[$session] === (string)$value)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw image
|
||||
*/
|
||||
public function draw() {
|
||||
|
||||
// We redefine $fonts here because we need a full path to font
|
||||
$fonts = array(
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'Aerial.ttf',
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'AerialBd.ttf',
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'AerialBdIt.ttf',
|
||||
ARTICHOW_FONT.DIRECTORY_SEPARATOR.'AerialIt.ttf'
|
||||
);
|
||||
|
||||
$sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19);
|
||||
|
||||
$widths = array();
|
||||
$heights = array();
|
||||
$texts = array();
|
||||
|
||||
for($i = 0; $i < strlen($this->string); $i++) {
|
||||
|
||||
$fontKey = array_rand($fonts);
|
||||
$sizeKey = array_rand($sizes);
|
||||
|
||||
$font = new awTTFFont(
|
||||
$fonts[$fontKey], $sizes[$sizeKey]
|
||||
);
|
||||
|
||||
$text = new awText(
|
||||
$this->string{$i},
|
||||
$font,
|
||||
NULL,
|
||||
mt_rand(-15, 15)
|
||||
);
|
||||
|
||||
$widths[] = $font->getTextWidth($text);
|
||||
$heights[] = $font->getTextHeight($text);
|
||||
$texts[] = $text;
|
||||
|
||||
}
|
||||
|
||||
$width = array_sum($widths);
|
||||
$height = array_max($heights);
|
||||
|
||||
$totalWidth = $width + 10 + count($texts) * 10;
|
||||
$totalHeight = $height + 20;
|
||||
|
||||
$this->setSize($totalWidth, $totalHeight);
|
||||
|
||||
$this->create();
|
||||
|
||||
for($i = 0; $i < strlen($this->string); $i++) {
|
||||
|
||||
$this->drawer->string(
|
||||
$texts[$i],
|
||||
new awPoint(
|
||||
5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10,
|
||||
10 + ($height - $heights[$i]) / 2
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->drawNoise($totalWidth, $totalHeight);
|
||||
|
||||
$this->send();
|
||||
|
||||
}
|
||||
|
||||
protected function drawNoise($width, $height) {
|
||||
|
||||
$points = $this->noise * 30;
|
||||
$color = new awColor(0, 0, 0);
|
||||
|
||||
for($i = 0; $i < $points; $i++) {
|
||||
$this->drawer->point(
|
||||
$color,
|
||||
new awPoint(
|
||||
mt_rand(0, $width),
|
||||
mt_rand(0, $height)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function session() {
|
||||
|
||||
// Start session if needed
|
||||
if(!session_id()) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('AntiSpam');
|
||||
?>
|
||||
|
|
@ -1,364 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/**
|
||||
* BarPlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBarPlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Labels on your bar plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Bar plot identifier
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $identifier;
|
||||
|
||||
/**
|
||||
* Bar plot number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $number;
|
||||
|
||||
/**
|
||||
* Bar plot depth
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $depth;
|
||||
|
||||
/**
|
||||
* For moving bars
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $move;
|
||||
|
||||
/**
|
||||
* Bars shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
public $barShadow;
|
||||
|
||||
/**
|
||||
* Bars border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $barBorder;
|
||||
|
||||
/**
|
||||
* Bars padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $barPadding;
|
||||
|
||||
/**
|
||||
* Bars space
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $barSpace = 0;
|
||||
|
||||
/**
|
||||
* Bars background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $barBackground;
|
||||
|
||||
/**
|
||||
* Construct a new awBarPlot
|
||||
*
|
||||
* @param array $values Some numeric values for Y axis
|
||||
* @param int $identifier Plot identifier
|
||||
* @param int $number Bar plot number
|
||||
* @param int $depth Bar plot depth in pixels
|
||||
*/
|
||||
public function __construct($values, $identifier = 1, $number = 1, $depth = 0) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->barPadding = new awSide(0.08, 0.08, 0, 0);
|
||||
$this->barShadow = new awShadow(awShadow::RIGHT_TOP);
|
||||
$this->barBorder = new awBorder;
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
$this->identifier = (int)$identifier;
|
||||
$this->number = (int)$number;
|
||||
$this->depth = (int)$depth;
|
||||
|
||||
$this->move = new awSide;
|
||||
|
||||
// Hide vertical grid
|
||||
$this->grid->hideVertical(TRUE);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars padding
|
||||
* This method is not compatible with awBarPlot::setBarPadding()
|
||||
*
|
||||
* @param float $left Left padding (between 0 and 1)
|
||||
* @param float $right Right padding (between 0 and 1)
|
||||
*/
|
||||
public function setBarPadding($left = NULL, $right = NULL) {
|
||||
$this->barPadding->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars size
|
||||
* This method is not compatible with awBarPlot::setBarPadding()
|
||||
*
|
||||
* @param int $width Bars size (between 0 and 1)
|
||||
*/
|
||||
public function setBarSize($size) {
|
||||
$padding = (1 - $size) / 2;
|
||||
$this->barPadding->set($padding, $padding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move bars
|
||||
*
|
||||
* @param int $x
|
||||
* @param int $y
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
$this->move->set($x, NULL, $y, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change bars space
|
||||
*
|
||||
* @param int $space Space in pixels
|
||||
*/
|
||||
public function setBarSpace($space) {
|
||||
$this->barSpace = (int)$space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBarColor(awColor $color) {
|
||||
$this->barBackground = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBarGradient(awGradient $gradient) {
|
||||
$this->barBackground = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return $this->barBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
}
|
||||
|
||||
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->datay);
|
||||
$max = $this->getRealYMax(NULL);
|
||||
$min = $this->getRealYMin(NULL);
|
||||
|
||||
// Find zero for bars
|
||||
if($this->xAxisZero and $min <= 0 and $max >= 0) {
|
||||
$zero = 0;
|
||||
} else if($max < 0) {
|
||||
$zero = $max;
|
||||
} else {
|
||||
$zero = $min;
|
||||
}
|
||||
|
||||
// Get base position
|
||||
$zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint(0, $zero));
|
||||
|
||||
// Distance between two values on the graph
|
||||
$distance = $this->xAxis->getDistance(0, 1);
|
||||
|
||||
// Compute paddings
|
||||
$leftPadding = $this->barPadding->left * $distance;
|
||||
$rightPadding = $this->barPadding->right * $distance;
|
||||
|
||||
$padding = $leftPadding + $rightPadding;
|
||||
$space = $this->barSpace * ($this->number - 1);
|
||||
|
||||
$barSize = ($distance - $padding - $space) / $this->number;
|
||||
$barPosition = $leftPadding + $barSize * ($this->identifier - 1);
|
||||
|
||||
for($key = 0; $key < $count; $key++) {
|
||||
|
||||
$value = $this->datay[$key];
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$position = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, $value)
|
||||
);
|
||||
|
||||
$barStart = $barPosition + ($this->identifier - 1) * $this->barSpace + $position->x;
|
||||
$barStop = $barStart + $barSize;
|
||||
|
||||
$t1 = min($zero->y, $position->y);
|
||||
$t2 = max($zero->y, $position->y);
|
||||
|
||||
if(round($t2 - $t1) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$p1 = new awPoint(
|
||||
round($barStart) + $this->depth + $this->move->left,
|
||||
round($t1) - $this->depth + $this->move->top
|
||||
);
|
||||
|
||||
$p2 = new awPoint(
|
||||
round($barStop) + $this->depth + $this->move->left,
|
||||
round($t2) - $this->depth + $this->move->top
|
||||
);
|
||||
|
||||
$this->drawBar($drawer, $p1, $p2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw labels
|
||||
foreach($this->datay as $key => $value) {
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$position = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, $value)
|
||||
);
|
||||
|
||||
$point = new awPoint(
|
||||
$barPosition + ($this->identifier - 1) * $this->barSpace + $position->x + $barSize / 2 + 1 + $this->depth,
|
||||
$position->y - $this->depth
|
||||
);
|
||||
|
||||
$this->label->draw($drawer, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getXAxisNumber() {
|
||||
return count($this->datay) + 1;
|
||||
}
|
||||
// ça bidouille à fond ici !
|
||||
public function getXMax() {
|
||||
return array_max($this->datax) + 1;
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
protected function drawBar(awDrawer $drawer, awPoint $p1, awPoint $p2) {
|
||||
|
||||
// Draw shadow
|
||||
$this->barShadow->draw(
|
||||
$drawer,
|
||||
$p1,
|
||||
$p2,
|
||||
awShadow::OUT
|
||||
);
|
||||
|
||||
if(abs($p2->y - $p1->y) > 1) {
|
||||
|
||||
$this->barBorder->rectangle(
|
||||
$drawer,
|
||||
$p1,
|
||||
$p2
|
||||
);
|
||||
|
||||
if($this->barBackground !== NULL) {
|
||||
|
||||
$size = $this->barBorder->visible() ? 1 : 0;
|
||||
|
||||
$b1 = $p1->move($size, $size);
|
||||
$b2 = $p2->move(-1 * $size, -1 * $size);
|
||||
|
||||
// Draw background
|
||||
$drawer->filledRectangle(
|
||||
$this->barBackground,
|
||||
new awLine($b1, $b2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('BarPlot');
|
||||
?>
|
||||
|
|
@ -1,419 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
|
||||
/**
|
||||
* A graph can contain some groups of components
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awComponentGroup extends awComponent {
|
||||
|
||||
/**
|
||||
* Components of this group
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $components;
|
||||
|
||||
/**
|
||||
* Build the component group
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->components = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to the group
|
||||
*
|
||||
* @param awComponent $component A component
|
||||
*/
|
||||
public function add(awComponent $component) {
|
||||
$this->components[] = $component;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('ComponentGroup', TRUE);
|
||||
|
||||
abstract class awComponent {
|
||||
|
||||
/**
|
||||
* Component drawer
|
||||
*
|
||||
* @var Drawer
|
||||
*/
|
||||
protected $drawer;
|
||||
|
||||
/**
|
||||
* Component width
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $width = 1.0;
|
||||
|
||||
/**
|
||||
* Component height
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $height = 1.0;
|
||||
|
||||
/**
|
||||
* Position X of the center the graph (from 0 to 1)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $x = 0.5;
|
||||
|
||||
/**
|
||||
* Position Y of the center the graph (from 0 to 1)
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $y = 0.5;
|
||||
|
||||
/**
|
||||
* Component absolute width (in pixels)
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $w;
|
||||
|
||||
/**
|
||||
* Component absolute height (in pixels)
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $h;
|
||||
|
||||
/**
|
||||
* Left-top corner Y position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $top;
|
||||
|
||||
/**
|
||||
* Left-top corner X position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $left;
|
||||
|
||||
/**
|
||||
* Component background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $background;
|
||||
|
||||
/**
|
||||
* Component padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $padding;
|
||||
|
||||
/**
|
||||
* Component space
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $space;
|
||||
|
||||
/**
|
||||
* Component title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Adjust automatically the component ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $auto = TRUE;
|
||||
|
||||
/**
|
||||
* Legend
|
||||
*
|
||||
* @var Legend
|
||||
*/
|
||||
public $legend;
|
||||
|
||||
/**
|
||||
* Build the component
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// DOL_CHANGE LDR Fix to allow usage of other fonts
|
||||
global $artichow_defaultfont;
|
||||
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
|
||||
|
||||
// Component legend
|
||||
$this->legend = new awLegend();
|
||||
|
||||
$this->padding = new awSide(25, 25, 25, 25);
|
||||
$this->space = new awSide(0, 0, 0, 0);
|
||||
|
||||
// Component title
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
new $classfontname(10),
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
$this->title->setAlign(awLabel::CENTER, awLabel::TOP);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust automatically the component ?
|
||||
*
|
||||
* @param bool $auto
|
||||
*/
|
||||
public function auto($auto) {
|
||||
$this->auto = (bool)$auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the size of the component
|
||||
*
|
||||
* @param int $width Component width (from 0 to 1)
|
||||
* @param int $height Component height (from 0 to 1)
|
||||
*/
|
||||
public function setSize($width, $height) {
|
||||
|
||||
$this->width = (float)$width;
|
||||
$this->height = (float)$height;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the absolute size of the component
|
||||
*
|
||||
* @param int $w Component width (in pixels)
|
||||
* @param int $h Component height (in pixels)
|
||||
*/
|
||||
public function setAbsSize($w, $h) {
|
||||
|
||||
$this->w = (int)$w;
|
||||
$this->h = (int)$h;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background color
|
||||
*
|
||||
* @param awColor $color (can be null)
|
||||
*/
|
||||
public function setBackgroundColor($color) {
|
||||
if($color === NULL or $color instanceof awColor) {
|
||||
$this->background = $color;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background gradient
|
||||
*
|
||||
* @param awGradient $gradient (can be null)
|
||||
*/
|
||||
public function setBackgroundGradient($gradient) {
|
||||
if($gradient === NULL or $gradient instanceof awGradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component background image
|
||||
*
|
||||
* @param awImage $image (can be null)
|
||||
*/
|
||||
public function setBackgroundImage($image) {
|
||||
if($image === NULL or $image instanceof awImage) {
|
||||
$this->background = $image;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the component background
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getBackground() {
|
||||
return $this->background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component padding
|
||||
*
|
||||
* @param int $left Padding in pixels (NULL to keep old value)
|
||||
* @param int $right Padding in pixels (NULL to keep old value)
|
||||
* @param int $top Padding in pixels (NULL to keep old value)
|
||||
* @param int $bottom Padding in pixels (NULL to keep old value)
|
||||
*/
|
||||
public function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
$this->padding->set($left, $right, $top, $bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change component space
|
||||
*
|
||||
* @param float $left Space in % (NULL to keep old value)
|
||||
* @param float $right Space in % (NULL to keep old value)
|
||||
* @param float $bottom Space in % (NULL to keep old value)
|
||||
* @param float $top Space in % (NULL to keep old value)
|
||||
*/
|
||||
public function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
|
||||
$this->space->set($left, $right, $bottom, $top);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the absolute position of the component on the graph
|
||||
*
|
||||
* @var int $x Left-top corner X position
|
||||
* @var int $y Left-top corner Y position
|
||||
*/
|
||||
public function setAbsPosition($left, $top) {
|
||||
|
||||
$this->left = (int)$left;
|
||||
$this->top = (int)$top;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the center of the component
|
||||
*
|
||||
* @param int $x Position on X axis of the center of the component
|
||||
* @param int $y Position on Y axis of the center of the component
|
||||
*/
|
||||
public function setCenter($x, $y) {
|
||||
|
||||
$this->x = (float)$x;
|
||||
$this->y = (float)$y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get component coords with its padding
|
||||
*
|
||||
* @return array Coords of the component
|
||||
*/
|
||||
public function getPosition() {
|
||||
|
||||
// Get component coords
|
||||
$x1 = $this->padding->left;
|
||||
$y1 = $this->padding->top;
|
||||
$x2 = $this->w - $this->padding->right;
|
||||
$y2 = $this->h - $this->padding->bottom;
|
||||
|
||||
return array($x1, $y1, $x2, $y2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the drawing of the component
|
||||
*/
|
||||
public function init(awDrawer $drawer) {
|
||||
|
||||
// Set component background
|
||||
$background = $this->getBackground();
|
||||
|
||||
if($background !== NULL) {
|
||||
|
||||
$p1 = new awPoint(0, 0);
|
||||
$p2 = new awPoint($this->w - 1, $this->h - 1);
|
||||
|
||||
if($background instanceof awImage) {
|
||||
|
||||
$drawer->copyImage(
|
||||
$background,
|
||||
$p1,
|
||||
$p2
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$background,
|
||||
new awLine($p1, $p2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the drawing of the component
|
||||
*/
|
||||
public function finalize(awDrawer $drawer) {
|
||||
|
||||
// Draw component title
|
||||
$point = new awPoint(
|
||||
$this->w / 2,
|
||||
$this->padding->top - 8
|
||||
);
|
||||
$this->title->draw($drawer, $point);
|
||||
|
||||
// Draw legend
|
||||
$this->legend->draw($drawer);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the grid around your component
|
||||
*
|
||||
* @param Drawer A drawer
|
||||
* @return array Coords for the component
|
||||
*/
|
||||
abstract public function drawEnvelope(awDrawer $drawer);
|
||||
|
||||
/**
|
||||
* Draw the component on the graph
|
||||
* Component should be drawed into specified coords
|
||||
*
|
||||
* @param Drawer A drawer
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
* @param bool $aliasing Use anti-aliasing to draw the component ?
|
||||
*/
|
||||
abstract public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing);
|
||||
|
||||
/**
|
||||
* Get space width in pixels
|
||||
*
|
||||
* @param int $width Component width
|
||||
* @param int $height Component height
|
||||
* @return array
|
||||
*/
|
||||
protected function getSpace($width, $height) {
|
||||
|
||||
$left = (int)($width * $this->space->left / 100);
|
||||
$right = (int)($width * $this->space->right / 100);
|
||||
$top = (int)($height * $this->space->top / 100);
|
||||
$bottom = (int)($height * $this->space->bottom / 100);
|
||||
|
||||
return array($left, $right, $top, $bottom);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Component', TRUE);
|
||||
?>
|
||||
|
|
@ -1,398 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
// Artichow configuration
|
||||
/* <php5> */
|
||||
if(is_file(dirname(__FILE__)."/Artichow.cfg.php")) { // For PHP 4+5 version
|
||||
require_once dirname(__FILE__)."/Artichow.cfg.php";
|
||||
}
|
||||
/* </php5> */
|
||||
|
||||
// Some useful files
|
||||
require_once ARTICHOW."/common.php";
|
||||
require_once ARTICHOW."/Component.class.php";
|
||||
require_once ARTICHOW."/Image.class.php";
|
||||
|
||||
require_once ARTICHOW."/inc/Grid.class.php";
|
||||
require_once ARTICHOW."/inc/Tools.class.php";
|
||||
require_once ARTICHOW."/inc/Drawer.class.php";
|
||||
require_once ARTICHOW."/inc/Math.class.php";
|
||||
require_once ARTICHOW."/inc/Tick.class.php";
|
||||
require_once ARTICHOW."/inc/Axis.class.php";
|
||||
require_once ARTICHOW."/inc/Legend.class.php";
|
||||
require_once ARTICHOW."/inc/Mark.class.php";
|
||||
require_once ARTICHOW."/inc/Label.class.php";
|
||||
require_once ARTICHOW."/inc/Text.class.php";
|
||||
require_once ARTICHOW."/inc/Color.class.php";
|
||||
require_once ARTICHOW."/inc/Font.class.php";
|
||||
require_once ARTICHOW."/inc/Gradient.class.php";
|
||||
|
||||
/**
|
||||
* A graph
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awGraph extends awImage {
|
||||
|
||||
/**
|
||||
* Graph name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Cache timeout
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $timeout = 0;
|
||||
|
||||
/**
|
||||
* Graph timing ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $timing;
|
||||
|
||||
/**
|
||||
* Components
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $components = array();
|
||||
|
||||
/**
|
||||
* Some labels to add to the component
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels = array();
|
||||
|
||||
/**
|
||||
* Graph title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Construct a new graph
|
||||
*
|
||||
* @param int $width Graph width
|
||||
* @param int $height Graph height
|
||||
* @param string $name Graph name for the cache (must be unique). Let it null to not use the cache.
|
||||
* @param int $timeout Cache timeout (unix timestamp)
|
||||
*/
|
||||
public function __construct($width = NULL, $height = NULL, $name = NULL, $timeout = 0) {
|
||||
|
||||
// DOL_CHANGE LDR Fix to allow usage of other fonts
|
||||
global $artichow_defaultfont;
|
||||
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->setSize($width, $height);
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$this->name = $name;
|
||||
$this->timeout = $timeout;
|
||||
|
||||
// Clean sometimes all the cache
|
||||
if(mt_rand(0, 5000) === 0) {
|
||||
awGraph::cleanCache();
|
||||
}
|
||||
|
||||
if($this->name !== NULL) {
|
||||
|
||||
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
|
||||
|
||||
if(is_file($file)) {
|
||||
|
||||
$type = awGraph::cleanGraphCache($file);
|
||||
|
||||
if($type === NULL) {
|
||||
awGraph::deleteFromCache($this->name);
|
||||
} else {
|
||||
header("Content-Type: image/".$type);
|
||||
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
new $classfontname(16),
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
$this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a graph from the cache
|
||||
*
|
||||
* @param string $name Graph name
|
||||
* @return bool TRUE on success, FALSE on failure
|
||||
*/
|
||||
public static function deleteFromCache($name) {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all graphs from the cache
|
||||
*/
|
||||
public static function deleteAllCache() {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$dp = opendir(ARTICHOW_CACHE_DIRECTORY);
|
||||
|
||||
while($file = readdir($dp)) {
|
||||
if($file !== '.' and $file != '..') {
|
||||
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean cache
|
||||
*/
|
||||
public static function cleanCache() {
|
||||
|
||||
if(ARTICHOW_CACHE) {
|
||||
|
||||
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
|
||||
|
||||
foreach($glob as $file) {
|
||||
|
||||
$type = awGraph::cleanGraphCache($file);
|
||||
|
||||
if($type === NULL) {
|
||||
$name = preg_replace("/.*\/(.*)\-time/", "\\1", $file);
|
||||
awGraph::deleteFromCache($name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable Graph timing
|
||||
*
|
||||
* @param bool $timing
|
||||
*/
|
||||
public function setTiming($timing) {
|
||||
$this->timing = (bool)$timing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a component to the graph
|
||||
*
|
||||
* @param awComponent $component
|
||||
*/
|
||||
public function add(awComponent $component) {
|
||||
|
||||
$this->components[] = $component;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a label to the component
|
||||
*
|
||||
* @param awLabel $label
|
||||
* @param int $x Position on X axis of the center of the text
|
||||
* @param int $y Position on Y axis of the center of the text
|
||||
*/
|
||||
public function addLabel(awLabel $label, $x, $y) {
|
||||
|
||||
$this->labels[] = array(
|
||||
$label, $x, $y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a label to the component with aboslute position
|
||||
*
|
||||
* @param awLabel $label
|
||||
* @param awPoint $point Text position
|
||||
*/
|
||||
public function addAbsLabel(awLabel $label, awPoint $point) {
|
||||
|
||||
$this->labels[] = array(
|
||||
$label, $point
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the graph and draw component on it
|
||||
* Image is sent to the user browser
|
||||
*
|
||||
* @param string $file Save the image in the specified file. Let it null to print image to screen.
|
||||
*/
|
||||
public function draw($file = NULL) {
|
||||
|
||||
if($this->timing) {
|
||||
$time = microtimeFloat();
|
||||
}
|
||||
|
||||
$this->create();
|
||||
|
||||
foreach($this->components as $component) {
|
||||
|
||||
$this->drawComponent($component);
|
||||
|
||||
}
|
||||
|
||||
$this->drawTitle();
|
||||
$this->drawShadow();
|
||||
$this->drawLabels();
|
||||
|
||||
if($this->timing) {
|
||||
$this->drawTiming(microtimeFloat() - $time);
|
||||
}
|
||||
|
||||
if(ARTICHOW_CACHE and $this->name !== NULL) {
|
||||
ob_start();
|
||||
}
|
||||
|
||||
$this->send($file);
|
||||
|
||||
if(ARTICHOW_CACHE and $this->name !== NULL) {
|
||||
|
||||
$data = ob_get_contents();
|
||||
|
||||
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
|
||||
trigger_error("Cache directory is not writable");
|
||||
}
|
||||
|
||||
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
|
||||
file_put_contents($file, $data);
|
||||
|
||||
$file .= "-time";
|
||||
file_put_contents($file, $this->timeout."\n".$this->getFormat());
|
||||
|
||||
ob_clean();
|
||||
|
||||
echo $data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function drawLabels() {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
foreach($this->labels as $array) {
|
||||
|
||||
if(count($array) === 3) {
|
||||
|
||||
// Text in relative position
|
||||
list($label, $x, $y) = $array;
|
||||
|
||||
$point = new awPoint(
|
||||
$x * $this->width,
|
||||
$y * $this->height
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
// Text in absolute position
|
||||
list($label, $point) = $array;
|
||||
|
||||
}
|
||||
|
||||
$label->draw($drawer, $point);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function drawTitle() {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
$point = new awPoint(
|
||||
$this->width / 2,
|
||||
10
|
||||
);
|
||||
|
||||
$this->title->draw($drawer, $point);
|
||||
|
||||
}
|
||||
|
||||
private function drawTiming($time) {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
$label = new awLabel;
|
||||
$label->set("(".sprintf("%.3f", $time)." s)");
|
||||
$label->setAlign(awLabel::LEFT, awLabel::TOP);
|
||||
$label->border->show();
|
||||
$label->setPadding(1, 0, 0, 0);
|
||||
$label->setBackgroundColor(new awColor(230, 230, 230, 25));
|
||||
|
||||
$label->draw($drawer, new awPoint(5, $drawer->height - 5));
|
||||
|
||||
}
|
||||
|
||||
private static function cleanGraphCache($file) {
|
||||
|
||||
list(
|
||||
$time,
|
||||
$type
|
||||
) = explode("\n", file_get_contents($file));
|
||||
|
||||
$time = (int)$time;
|
||||
|
||||
if($time !== 0 and $time < time()) {
|
||||
return NULL;
|
||||
} else {
|
||||
return $type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Graph');
|
||||
|
||||
/*
|
||||
* To preserve PHP 4 compatibility
|
||||
*/
|
||||
function microtimeFloat() {
|
||||
list($usec, $sec) = explode(" ", microtime());
|
||||
return (float)$usec + (float)$sec;
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,421 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("IMAGE_JPEG", 1);
|
||||
define("IMAGE_PNG", 2);
|
||||
define("IMAGE_GIF", 3);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/*
|
||||
* Check for GD2
|
||||
*/
|
||||
if(function_exists('imagecreatetruecolor') === FALSE) {
|
||||
trigger_error("You must compile PHP with GD2 support to use Artichow", E_USER_ERROR);
|
||||
}
|
||||
|
||||
require_once ARTICHOW."/inc/Shadow.class.php";
|
||||
require_once ARTICHOW."/inc/Border.class.php";
|
||||
|
||||
/**
|
||||
* An image for a graph
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awImage {
|
||||
|
||||
/**
|
||||
* Graph width
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $width;
|
||||
|
||||
/**
|
||||
* Graph height
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $height;
|
||||
|
||||
/**
|
||||
* Use anti-aliasing ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $antiAliasing = FALSE;
|
||||
|
||||
/**
|
||||
* Image format
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $format = awImage::PNG;
|
||||
|
||||
/**
|
||||
* Image background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $background;
|
||||
|
||||
/**
|
||||
* GD resource
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* Image drawer
|
||||
*
|
||||
* @var Drawer
|
||||
*/
|
||||
protected $drawer;
|
||||
|
||||
/**
|
||||
* Shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
public $shadow;
|
||||
|
||||
/**
|
||||
* Image border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Use JPEG for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const JPEG = IMG_JPG;
|
||||
|
||||
/**
|
||||
* Use PNG for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PNG = IMG_PNG;
|
||||
|
||||
/**
|
||||
* Use GIF for image
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const GIF = IMG_GIF;
|
||||
|
||||
/**
|
||||
* Build the image
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->background = new awColor(255, 255, 255);
|
||||
$this->shadow = new awShadow(awShadow::RIGHT_BOTTOM);
|
||||
$this->border = new awBorder;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get drawer of the image
|
||||
*
|
||||
* @param int $w Drawer width (from 0 to 1) (default to 1)
|
||||
* @param int $h Drawer height (from 0 to 1) (default to 1)
|
||||
* @param float $x Position on X axis of the center of the drawer (default to 0.5)
|
||||
* @param float $y Position on Y axis of the center of the drawer (default to 0.5)
|
||||
* @return Drawer
|
||||
*/
|
||||
public function getDrawer($w = 1, $h = 1, $x = 0.5, $y = 0.5) {
|
||||
$this->create();
|
||||
$this->drawer->setSize($w, $h);
|
||||
$this->drawer->setPosition($x, $y);
|
||||
return $this->drawer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the image size
|
||||
*
|
||||
* @var int $width Image width
|
||||
* @var int $height Image height
|
||||
*/
|
||||
public function setSize($width, $height) {
|
||||
|
||||
if($width !== NULL) {
|
||||
$this->width = (int)$width;
|
||||
}
|
||||
if($height !== NULL) {
|
||||
$this->height = (int)$height;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can we use anti-aliasing ?
|
||||
*
|
||||
* @var bool $bool
|
||||
*/
|
||||
public function setAntiAliasing($bool) {
|
||||
$this->antiAliasing = (bool)$bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change image format
|
||||
*
|
||||
* @var int $format New image format
|
||||
*/
|
||||
public function setFormat($format) {
|
||||
if($format === awImage::JPEG or $format === awImage::PNG or $format === awImage::GIF) {
|
||||
$this->format = $format;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new awimage
|
||||
*/
|
||||
public function create() {
|
||||
|
||||
if($this->resource === NULL) {
|
||||
|
||||
// Create image
|
||||
|
||||
$this->resource = imagecreatetruecolor($this->width, $this->height);
|
||||
if(!$this->resource) {
|
||||
trigger_error("Unable to create a graph", E_USER_ERROR);
|
||||
}
|
||||
|
||||
imagealphablending($this->resource, TRUE);
|
||||
|
||||
if($this->antiAliasing and function_exists('imageantialias')) {
|
||||
imageantialias($this->resource, TRUE);
|
||||
}
|
||||
|
||||
$this->drawer = new awDrawer($this->resource);
|
||||
$this->drawer->setImageSize($this->width, $this->height);
|
||||
|
||||
// Original color
|
||||
$this->drawer->filledRectangle(
|
||||
new awWhite,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->width, $this->height)
|
||||
)
|
||||
);
|
||||
|
||||
$shadow = $this->shadow->getSpace();
|
||||
|
||||
$p1 = new awPoint($shadow->left, $shadow->top);
|
||||
$p2 = new awPoint($this->width - $shadow->right - 1, $this->height - $shadow->bottom - 1);
|
||||
|
||||
// Draw image background
|
||||
$this->drawer->filledRectangle($this->background, new awLine($p1, $p2));
|
||||
$this->background->free();
|
||||
|
||||
// Draw image border
|
||||
$this->border->rectangle($this->drawer, $p1, $p2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a component on the image
|
||||
*
|
||||
* @var awComponent $component A component
|
||||
*/
|
||||
public function drawComponent(awComponent $component) {
|
||||
|
||||
$shadow = $this->shadow->getSpace(); // Image shadow
|
||||
$border = $this->border->visible() ? 1 : 0; // Image border size
|
||||
|
||||
$drawer = clone $this->drawer;
|
||||
$drawer->setImageSize(
|
||||
$this->width - $shadow->left - $shadow->right - $border * 2,
|
||||
$this->height - $shadow->top - $shadow->bottom - $border * 2
|
||||
);
|
||||
|
||||
// No absolute size specified
|
||||
if($component->w === NULL and $component->h === NULL) {
|
||||
|
||||
list($width, $height) = $drawer->setSize($component->width, $component->height);
|
||||
|
||||
// Set component size in pixels
|
||||
$component->setAbsSize($width, $height);
|
||||
|
||||
} else {
|
||||
|
||||
$drawer->setAbsSize($component->w, $component->h);
|
||||
|
||||
}
|
||||
|
||||
if($component->top !== NULL and $component->left !== NULL) {
|
||||
$drawer->setAbsPosition(
|
||||
$border + $shadow->left + $component->left,
|
||||
$border + $shadow->top + $component->top
|
||||
);
|
||||
} else {
|
||||
$drawer->setPosition($component->x, $component->y);
|
||||
}
|
||||
|
||||
$drawer->movePosition($border + $shadow->left, $border + $shadow->top);
|
||||
|
||||
list($x1, $y1, $x2, $y2) = $component->getPosition();
|
||||
|
||||
$component->init($drawer);
|
||||
|
||||
$component->drawComponent($drawer, $x1, $y1, $x2, $y2, $this->antiAliasing);
|
||||
$component->drawEnvelope($drawer, $x1, $y1, $x2, $y2);
|
||||
|
||||
$component->finalize($drawer);
|
||||
|
||||
}
|
||||
|
||||
protected function drawShadow() {
|
||||
|
||||
$drawer = $this->getDrawer();
|
||||
|
||||
$this->shadow->draw(
|
||||
$drawer,
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->width, $this->height),
|
||||
awShadow::IN
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the image into a file or to the user browser
|
||||
*
|
||||
* @var string $file Save image into a file if you provide a file name
|
||||
*/
|
||||
public function send($file = NULL) {
|
||||
|
||||
// Test if format is available
|
||||
if((imagetypes() & $this->format) === FALSE) {
|
||||
trigger_error("Format '".$this->format."' is not available on your system. Check that your PHP has been compiled with the good libraries.");
|
||||
}
|
||||
|
||||
// Get some infos about this image
|
||||
|
||||
switch($this->format) {
|
||||
case awImage::JPEG :
|
||||
$function = 'imagejpeg';
|
||||
break;
|
||||
case awImage::PNG :
|
||||
$function = 'imagepng';
|
||||
break;
|
||||
case awImage::GIF :
|
||||
$function = 'imagegif';
|
||||
break;
|
||||
}
|
||||
|
||||
// Create image
|
||||
|
||||
if($file !== NULL) {
|
||||
|
||||
$function($this->resource, $file);
|
||||
|
||||
} else {
|
||||
|
||||
// Send headers to the browser
|
||||
if(headers_sent() === FALSE) {
|
||||
header("Content-type: image/".$this->getFormat());
|
||||
}
|
||||
|
||||
$function($this->resource);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getFormat() {
|
||||
|
||||
switch($this->format) {
|
||||
case awImage::JPEG :
|
||||
return 'jpeg';
|
||||
case awImage::PNG :
|
||||
return 'png';
|
||||
case awImage::GIF :
|
||||
return 'gif';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Image');
|
||||
|
||||
|
||||
/**
|
||||
* Load an image from a file
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awFileImage extends awImage {
|
||||
|
||||
/**
|
||||
* Build a new awimage
|
||||
*
|
||||
* @param string $file Image file name
|
||||
*/
|
||||
public function __construct($file) {
|
||||
|
||||
$image = @getimagesize($file);
|
||||
|
||||
if($image and in_array($image[2], array(2, 3))) {
|
||||
|
||||
$this->setSize($image[0], $image[1]);
|
||||
|
||||
switch($image[2]) {
|
||||
|
||||
case 2 :
|
||||
$this->resource = imagecreatefromjpeg($file);
|
||||
break;
|
||||
|
||||
case 3 :
|
||||
$this->resource = imagecreatefrompng($file);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$this->drawer = new awDrawer($this->resource);
|
||||
$this->drawer->setImageSize($this->width, $this->height);
|
||||
|
||||
} else {
|
||||
trigger_error("Artichow does not support this image (must be in PNG or JPEG)", E_USER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('FileImage');
|
||||
?>
|
||||
|
|
@ -1,596 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LINEPLOT_LINE", 0);
|
||||
define("LINEPLOT_MIDDLE", 1);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* LinePlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLinePlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Add marks to your line plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
public $mark;
|
||||
|
||||
/**
|
||||
* Labels on your line plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Filled areas
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $areas = array();
|
||||
|
||||
/**
|
||||
* Is the line hidden
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $lineHide = FALSE;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $lineColor;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineMode = awLinePlot::LINE;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStyle = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Line background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $lineBackground;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LINE = 0;
|
||||
|
||||
/**
|
||||
* Line in the middle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MIDDLE = 1;
|
||||
|
||||
/**
|
||||
* Construct a new awLinePlot
|
||||
*
|
||||
* @param array $values Some numeric values for Y axis
|
||||
* @param int $mode
|
||||
*/
|
||||
public function __construct($values, $mode = awLinePlot::LINE) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->mark = new awMark;
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->lineMode = (int)$mode;
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide line
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideLine($hide) {
|
||||
$this->lineHide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a filled area
|
||||
*
|
||||
* @param int $start Begining of the area
|
||||
* @param int $end End of the area
|
||||
* @param mixed $background Background color or gradient of the area
|
||||
*/
|
||||
public function setFilledArea($start, $stop, $background) {
|
||||
|
||||
if($stop <= $start) {
|
||||
trigger_error("End position can not be greater than begin position in awLinePlot::setFilledArea()", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$this->areas[] = array((int)$start, (int)$stop, $background);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
public function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setFillColor(awColor $color) {
|
||||
$this->lineBackground = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setFillGradient(awGradient $gradient) {
|
||||
$this->lineBackground = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return $this->lineBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$max = $this->getRealYMax();
|
||||
$min = $this->getRealYMin();
|
||||
|
||||
// Get start and stop values
|
||||
list($start, $stop) = $this->getLimit();
|
||||
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
$inc = $this->xAxis->getDistance(0, 1) / 2;
|
||||
} else {
|
||||
$inc = 0;
|
||||
}
|
||||
|
||||
// Build the polygon
|
||||
$polygon = new awPolygon;
|
||||
|
||||
for($key = $start; $key <= $stop; $key++) {
|
||||
|
||||
$value = $this->datay[$key];
|
||||
|
||||
if($value !== NULL) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, $value));
|
||||
$p = $p->move($inc, 0);
|
||||
$polygon->set($key, $p);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw backgrounds
|
||||
if($this->lineBackground instanceof awColor or $this->lineBackground instanceof awGradient) {
|
||||
|
||||
$backgroundPolygon = new awPolygon;
|
||||
|
||||
$p = $this->xAxisPoint($start);
|
||||
$p = $p->move($inc, 0);
|
||||
$backgroundPolygon->append($p);
|
||||
|
||||
// Add others points
|
||||
foreach($polygon->all() as $point) {
|
||||
$backgroundPolygon->append(clone $point);
|
||||
}
|
||||
|
||||
$p = $this->xAxisPoint($stop);
|
||||
$p = $p->move($inc, 0);
|
||||
$backgroundPolygon->append($p);
|
||||
|
||||
// Draw polygon background
|
||||
$drawer->filledPolygon($this->lineBackground, $backgroundPolygon);
|
||||
|
||||
}
|
||||
|
||||
$this->drawArea($drawer, $polygon);
|
||||
|
||||
// Draw line
|
||||
$prev = NULL;
|
||||
|
||||
// Line color
|
||||
if($this->lineHide === FALSE) {
|
||||
|
||||
if($this->lineColor === NULL) {
|
||||
$this->lineColor = new awColor(0, 0, 0);
|
||||
}
|
||||
|
||||
foreach($polygon->all() as $point) {
|
||||
|
||||
if($prev !== NULL) {
|
||||
$drawer->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$prev,
|
||||
$point,
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
}
|
||||
$prev = $point;
|
||||
|
||||
}
|
||||
|
||||
$this->lineColor->free();
|
||||
|
||||
}
|
||||
|
||||
// Draw marks and labels
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
$this->mark->draw($drawer, $point);
|
||||
$this->label->draw($drawer, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function drawArea(awDrawer $drawer, awPolygon $polygon) {
|
||||
|
||||
$starts = array();
|
||||
foreach($this->areas as $area) {
|
||||
list($start) = $area;
|
||||
$starts[$start] = TRUE;
|
||||
}
|
||||
|
||||
// Draw filled areas
|
||||
foreach($this->areas as $area) {
|
||||
|
||||
list($start, $stop, $background) = $area;
|
||||
|
||||
$polygonArea = new awPolygon;
|
||||
|
||||
$p = $this->xAxisPoint($start);
|
||||
$polygonArea->append($p);
|
||||
|
||||
for($i = $start; $i <= $stop; $i++) {
|
||||
$p = clone $polygon->get($i);
|
||||
if($i === $stop and array_key_exists($stop, $starts)) {
|
||||
$p = $p->move(-1, 0);
|
||||
}
|
||||
$polygonArea->append($p);
|
||||
}
|
||||
|
||||
$p = $this->xAxisPoint($stop);
|
||||
if(array_key_exists($stop, $starts)) {
|
||||
$p = $p->move(-1, 0);
|
||||
}
|
||||
$polygonArea->append($p);
|
||||
|
||||
// Draw area
|
||||
$drawer->filledPolygon($background, $polygonArea);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getXAxisNumber() {
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
return count($this->datay) + 1;
|
||||
} else {
|
||||
return count($this->datay);
|
||||
}
|
||||
}
|
||||
|
||||
protected function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return ($this->lineMode === awLinePlot::MIDDLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('LinePlot');
|
||||
|
||||
|
||||
/**
|
||||
* Simple LinePlot
|
||||
* Useful to draw simple horizontal lines
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awSimpleLinePlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $lineColor;
|
||||
|
||||
/**
|
||||
* Line start
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStart;
|
||||
|
||||
/**
|
||||
* Line stop
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStop;
|
||||
|
||||
/**
|
||||
* Line value
|
||||
*
|
||||
* @var flaot
|
||||
*/
|
||||
protected $lineValue;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineMode = awLinePlot::LINE;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStyle = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Line mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LINE = 0;
|
||||
|
||||
/**
|
||||
* Line in the middle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MIDDLE = 1;
|
||||
|
||||
/**
|
||||
* Construct a new awLinePlot
|
||||
*
|
||||
* @param float $value A Y value
|
||||
* @param int $start Line start index
|
||||
* @param int $stop Line stop index
|
||||
* @param int $mode Line mode
|
||||
*/
|
||||
public function __construct($value, $start, $stop, $mode = awLinePlot::LINE) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->lineMode = (int)$mode;
|
||||
|
||||
$this->lineStart = (int)$start;
|
||||
$this->lineStop = (int)$stop;
|
||||
$this->lineValue = (float)$value;
|
||||
|
||||
$this->lineColor = new awColor(0, 0, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
public function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
public function getLegendBackground() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function getLegendMark() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
$inc = $this->xAxis->getDistance(0, 1) / 2;
|
||||
} else {
|
||||
$inc = 0;
|
||||
}
|
||||
|
||||
$p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue));
|
||||
$p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue));
|
||||
|
||||
$drawer->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$p1->move($inc, 0),
|
||||
$p2->move($inc, 0),
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
|
||||
$this->lineColor->free();
|
||||
|
||||
}
|
||||
|
||||
public function getXAxisNumber() {
|
||||
if($this->lineMode === awLinePlot::MIDDLE) {
|
||||
return count($this->datay) + 1;
|
||||
} else {
|
||||
return count($this->datay);
|
||||
}
|
||||
}
|
||||
|
||||
protected function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return ($this->lineMode === awLinePlot::MIDDLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('SimpleLinePlot');
|
||||
?>
|
||||
|
|
@ -1,446 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Component.class.php";
|
||||
|
||||
/**
|
||||
* A mathematic function
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMathFunction implements awLegendable {
|
||||
|
||||
/**
|
||||
* Function line
|
||||
*
|
||||
* @var Line
|
||||
*/
|
||||
public $line;
|
||||
|
||||
/**
|
||||
* Marks for your plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
public $mark;
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $f;
|
||||
|
||||
/**
|
||||
* Start the drawing from this value
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $fromX;
|
||||
|
||||
/**
|
||||
* Stop the drawing at this value
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $toX;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Construct the function
|
||||
*
|
||||
* @param string $f Callback function
|
||||
* @param float $fromX
|
||||
* @param float $toX
|
||||
*/
|
||||
public function __construct($f, $fromX = NULL, $toX = NULL) {
|
||||
|
||||
$this->f = (string)$f;
|
||||
$this->fromX = is_null($fromX) ? NULL : (float)$fromX;
|
||||
$this->toX = is_null($toX) ? NULL : (float)$toX;
|
||||
|
||||
$this->line = new awLine;
|
||||
$this->mark = new awMark;
|
||||
$this->color = new awBlack;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color A new awcolor
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line color
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->line->getThickness();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->line->getStyle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('MathFunction');
|
||||
|
||||
/**
|
||||
* For mathematics functions
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMathPlot extends awComponent {
|
||||
|
||||
/**
|
||||
* Functions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $functions = array();
|
||||
|
||||
/**
|
||||
* Grid properties
|
||||
*
|
||||
* @var Grid
|
||||
*/
|
||||
public $grid;
|
||||
|
||||
/**
|
||||
* X axis
|
||||
*
|
||||
* @var Axis
|
||||
*/
|
||||
public $xAxis;
|
||||
|
||||
/**
|
||||
* Y axis
|
||||
*
|
||||
* @var Axis
|
||||
*/
|
||||
public $yAxis;
|
||||
|
||||
/**
|
||||
* Extremum
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
private $extremum = NULL;
|
||||
|
||||
/**
|
||||
* Interval
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
private $interval = 1;
|
||||
|
||||
/**
|
||||
* Build the plot
|
||||
*
|
||||
* @param int $xMin Minimum X value
|
||||
* @param int $xMax Maximum X value
|
||||
* @param int $yMax Maximum Y value
|
||||
* @param int $yMin Minimum Y value
|
||||
*/
|
||||
public function __construct($xMin, $xMax, $yMax, $yMin) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->setPadding(8, 8, 8, 8);
|
||||
|
||||
$this->grid = new awGrid;
|
||||
|
||||
// Hide grid by default
|
||||
$this->grid->hide(TRUE);
|
||||
|
||||
// Set extremum
|
||||
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
|
||||
|
||||
// Create axis
|
||||
$this->xAxis = new awAxis;
|
||||
$this->xAxis->setTickStyle(awTick::IN);
|
||||
$this->xAxis->label->hideValue(0);
|
||||
$this->initAxis($this->xAxis);
|
||||
|
||||
$this->yAxis = new awAxis;
|
||||
$this->yAxis->setTickStyle(awTick::IN);
|
||||
$this->yAxis->label->hideValue(0);
|
||||
$this->initAxis($this->yAxis);
|
||||
|
||||
}
|
||||
|
||||
protected function initAxis(awAxis $axis) {
|
||||
// DOL_CHANGE LDR Fix to allow usage of other fonts
|
||||
global $artichow_defaultfont;
|
||||
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
|
||||
|
||||
$axis->setLabelPrecision(1);
|
||||
$axis->addTick('major', new awTick(0, 5));
|
||||
$axis->addTick('minor', new awTick(0, 3));
|
||||
$axis->addTick('micro', new awTick(0, 1));
|
||||
$axis->setNumberByTick('minor', 'major', 1);
|
||||
$axis->setNumberByTick('micro', 'minor', 4);
|
||||
$axis->label->setFont(new $classfontname(7));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Interval to calculate values
|
||||
*
|
||||
* @param float $interval
|
||||
*/
|
||||
public function setInterval($interval) {
|
||||
$this->interval = (float)$interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a formula f(x)
|
||||
*
|
||||
* @param awMathFunction $function
|
||||
* @param string $name Name for the legend (can be NULL if you don't want to set a legend)
|
||||
* @param int $type Type for the legend
|
||||
*/
|
||||
public function add(awMathFunction $function, $name = NULL, $type = awLegend::LINE) {
|
||||
|
||||
$this->functions[] = $function;
|
||||
|
||||
if($name !== NULL) {
|
||||
$this->legend->add($function, $name, $type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function init(awDrawer $drawer) {
|
||||
|
||||
list($x1, $y1, $x2, $y2) = $this->getPosition();
|
||||
|
||||
$this->xAxis->line->setX($x1, $x2);
|
||||
$this->xAxis->label->setAlign(NULL, awLabel::BOTTOM);
|
||||
$this->xAxis->label->move(0, 3);
|
||||
$this->xAxis->setRange($this->extremum->left, $this->extremum->right);
|
||||
|
||||
$this->yAxis->line->setY($y2, $y1);
|
||||
$this->yAxis->label->setAlign(awLabel::RIGHT);
|
||||
$this->yAxis->label->move(-6, 0);
|
||||
$this->yAxis->reverseTickStyle();
|
||||
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
|
||||
|
||||
|
||||
$this->xAxis->setYCenter($this->yAxis, 0);
|
||||
$this->yAxis->setXCenter($this->xAxis, 0);
|
||||
|
||||
if($this->yAxis->getLabelNumber() === NULL) {
|
||||
$number = $this->extremum->top - $this->extremum->bottom + 1;
|
||||
$this->yAxis->setLabelNumber($number);
|
||||
}
|
||||
|
||||
if($this->xAxis->getLabelNumber() === NULL) {
|
||||
$number = $this->extremum->right - $this->extremum->left + 1;
|
||||
$this->xAxis->setLabelNumber($number);
|
||||
}
|
||||
|
||||
// Set ticks
|
||||
/* <php5> */
|
||||
$this->xAxis->tick('major')->setNumber($this->xAxis->getLabelNumber());
|
||||
$this->yAxis->tick('major')->setNumber($this->yAxis->getLabelNumber());
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
$this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
|
||||
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
|
||||
-- </php4> */
|
||||
|
||||
// Set axis labels
|
||||
$labels = array();
|
||||
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
|
||||
$labels[] = $i;
|
||||
}
|
||||
$this->xAxis->label->set($labels);
|
||||
|
||||
$labels = array();
|
||||
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
|
||||
$labels[] = $i;
|
||||
}
|
||||
$this->yAxis->label->set($labels);
|
||||
|
||||
parent::init($drawer);
|
||||
|
||||
// Create the grid
|
||||
$this->createGrid();
|
||||
|
||||
// Draw the grid
|
||||
$this->grid->draw($drawer, $x1, $y1, $x2, $y2);
|
||||
|
||||
}
|
||||
|
||||
public function drawEnvelope(awDrawer $drawer) {
|
||||
|
||||
// Draw axis
|
||||
$this->xAxis->draw($drawer);
|
||||
$this->yAxis->draw($drawer);
|
||||
|
||||
}
|
||||
|
||||
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
foreach($this->functions as $function) {
|
||||
|
||||
$f = $function->f;
|
||||
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
|
||||
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
|
||||
|
||||
$old = NULL;
|
||||
|
||||
for($i = $fromX; $i <= $toX; $i += $this->interval) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
|
||||
|
||||
if($p->y >= $y1 and $p->y <= $y2) {
|
||||
$function->mark->draw($drawer, $p);
|
||||
}
|
||||
|
||||
if($old !== NULL) {
|
||||
|
||||
$line = $function->line;
|
||||
$line->setLocation($old, $p);
|
||||
|
||||
if(
|
||||
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
|
||||
($line->p2->y >= $y1 and $line->p2->y <= $y2)
|
||||
) {
|
||||
$drawer->line(
|
||||
$function->getColor(),
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$old = $p;
|
||||
|
||||
}
|
||||
|
||||
// Draw last point if needed
|
||||
if($old !== NULL and $i - $this->interval != $toX) {
|
||||
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
|
||||
|
||||
if($p->y >= $y1 and $p->y <= $y2) {
|
||||
$function->mark->draw($drawer, $p);
|
||||
}
|
||||
|
||||
|
||||
$line = $function->line;
|
||||
$line->setLocation($old, $p);
|
||||
|
||||
if(
|
||||
($line->p1->y >= $y1 and $line->p1->y <= $y2) or
|
||||
($line->p2->y >= $y1 and $line->p2->y <= $y2)
|
||||
) {
|
||||
$drawer->line(
|
||||
$function->getColor(),
|
||||
$line
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function createGrid() {
|
||||
|
||||
// Horizontal lines of the grid
|
||||
|
||||
$major = $this->yAxis->tick('major');
|
||||
$interval = $major->getInterval();
|
||||
$number = $this->yAxis->getLabelNumber() - 1;
|
||||
|
||||
$h = array();
|
||||
if($number > 0) {
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
$h[] = $i / $number;
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical lines
|
||||
|
||||
$major = $this->xAxis->tick('major');
|
||||
$interval = $major->getInterval();
|
||||
$number = $this->xAxis->getLabelNumber() - 1;
|
||||
|
||||
$w = array();
|
||||
if($number > 0) {
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
if($i%$interval === 0) {
|
||||
$w[] = $i / $number;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->grid->setGrid($w, $h);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('MathPlot');
|
||||
?>
|
||||
|
|
@ -1,97 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Graph.class.php";
|
||||
|
||||
/**
|
||||
* All patterns must derivate from this class
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awPattern {
|
||||
|
||||
/**
|
||||
* Pattern arguments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $args = array();
|
||||
|
||||
/**
|
||||
* Load a pattern
|
||||
*
|
||||
* @param string $pattern Pattern name
|
||||
* @return Component
|
||||
*/
|
||||
public static function get($pattern) {
|
||||
|
||||
$file = ARTICHOW_PATTERN.DIRECTORY_SEPARATOR.$pattern.'.php';
|
||||
|
||||
if(is_file($file)) {
|
||||
|
||||
require_once $file;
|
||||
|
||||
$class = $pattern.'Pattern';
|
||||
|
||||
if(class_exists($class)) {
|
||||
return new $class;
|
||||
} else {
|
||||
trigger_error("Class '".$class."' does not exist", E_USER_ERROR);
|
||||
}
|
||||
|
||||
} else {
|
||||
trigger_error("Pattern '".$pattern."' does not exist", E_USER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change pattern argument
|
||||
*
|
||||
* @param string $name Argument name
|
||||
* @param mixed $value Argument value
|
||||
*/
|
||||
public function setArg($name, $value) {
|
||||
if(is_string($name)) {
|
||||
$this->args[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an argument
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $default Default value if the argument does not exist (default to NULL)
|
||||
* @return mixed Argument value
|
||||
*/
|
||||
protected function getArg($name, $default = NULL) {
|
||||
if(array_key_exists($name, $this->args)) {
|
||||
return $this->args[$name];
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change several arguments
|
||||
*
|
||||
* @param array $args New arguments
|
||||
*/
|
||||
public function setArgs($args) {
|
||||
if(is_array($args)) {
|
||||
foreach($args as $name => $value) {
|
||||
$this->setArg($name, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Pattern', TRUE);
|
||||
?>
|
||||
|
|
@ -1,680 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Component.class.php";
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("PIE_DARK", 1);
|
||||
define("PIE_COLORED", 2);
|
||||
define("PIE_AQUA", 3);
|
||||
define("PIE_EARTH", 4);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Pie
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPie extends awComponent {
|
||||
|
||||
/**
|
||||
* A dark theme for pies
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DARK = 1;
|
||||
|
||||
/**
|
||||
* A colored theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const COLORED = 2;
|
||||
|
||||
/**
|
||||
* A water theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const AQUA = 3;
|
||||
|
||||
/**
|
||||
* A earth theme for pies
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const EARTH = 4;
|
||||
|
||||
/**
|
||||
* Pie values
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $values;
|
||||
|
||||
/**
|
||||
* Pie colors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $colors;
|
||||
|
||||
/**
|
||||
* Pie legend
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $legendValues = array();
|
||||
|
||||
/**
|
||||
* Intensity of the 3D effect
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size;
|
||||
|
||||
/**
|
||||
* Border color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $border;
|
||||
|
||||
/**
|
||||
* Pie explode
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $explode = array();
|
||||
|
||||
/**
|
||||
* Initial angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $angle = 0;
|
||||
|
||||
/**
|
||||
* Labels precision
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $precision;
|
||||
|
||||
/**
|
||||
* Labels number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $number;
|
||||
|
||||
/**
|
||||
* Labels minimum
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $minimum;
|
||||
|
||||
/**
|
||||
* Labels position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $position = 15;
|
||||
|
||||
/**
|
||||
* Labels of your pie
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Build the plot
|
||||
*
|
||||
* @param array $values Pie values
|
||||
*/
|
||||
public function __construct($values, $colors = awPie::COLORED) {
|
||||
|
||||
$this->setValues($values);
|
||||
|
||||
if(is_array($colors)) {
|
||||
$this->colors = $colors;
|
||||
} else {
|
||||
|
||||
switch($colors) {
|
||||
|
||||
case awPie::AQUA :
|
||||
$this->colors = array(
|
||||
new awColor(131, 220, 215),
|
||||
new awColor(131, 190, 215),
|
||||
new awColor(131, 160, 215),
|
||||
new awColor(160, 140, 215),
|
||||
new awColor(190, 131, 215),
|
||||
new awColor(220, 131, 215)
|
||||
);
|
||||
break;
|
||||
|
||||
case awPie::EARTH :
|
||||
$this->colors = array(
|
||||
new awColor(97, 179, 110),
|
||||
new awColor(130, 179, 97),
|
||||
new awColor(168, 179, 97),
|
||||
new awColor(179, 147, 97),
|
||||
new awColor(179, 108, 97),
|
||||
new awColor(99, 107, 189),
|
||||
new awColor(99, 165, 189)
|
||||
);
|
||||
break;
|
||||
|
||||
case awPie::DARK :
|
||||
$this->colors = array(
|
||||
new awColor(140, 100, 170),
|
||||
new awColor(130, 170, 100),
|
||||
new awColor(160, 160, 120),
|
||||
new awColor(150, 110, 140),
|
||||
new awColor(130, 150, 160),
|
||||
new awColor(90, 170, 140)
|
||||
);
|
||||
break;
|
||||
|
||||
default :
|
||||
$this->colors = array(
|
||||
new awColor(187, 213, 151),
|
||||
new awColor(223, 177, 151),
|
||||
new awColor(111, 186, 132),
|
||||
new awColor(197, 160, 230),
|
||||
new awColor(165, 169, 63),
|
||||
new awColor(218, 177, 89),
|
||||
new awColor(116, 205, 121),
|
||||
new awColor(200, 201, 78),
|
||||
new awColor(127, 205, 177),
|
||||
new awColor(205, 160, 160),
|
||||
new awColor(190, 190, 190)
|
||||
);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->label = new awLabel;
|
||||
$this->label->setCallbackFunction('callbackPerCent');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend values
|
||||
*
|
||||
* @param array $legend An array of values for each part of the pie
|
||||
*/
|
||||
public function setLegend($legend) {
|
||||
|
||||
$this->legendValues = (array)$legend;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a border all around the pie
|
||||
*
|
||||
* @param awColor $color A color for the border
|
||||
*/
|
||||
public function setBorder(awColor $color) {
|
||||
$this->border = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change 3D effect intensity
|
||||
*
|
||||
* @param int $size Effect size
|
||||
*/
|
||||
public function set3D($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change initial angle
|
||||
*
|
||||
* @param int $angle New angle in degrees
|
||||
*/
|
||||
public function setStartAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label precision
|
||||
*
|
||||
* @param int $precision New precision
|
||||
*/
|
||||
public function setLabelPrecision($precision) {
|
||||
$this->precision = (int)$precision;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label position
|
||||
*
|
||||
* @param int $position New position in pixels
|
||||
*/
|
||||
public function setLabelPosition($position) {
|
||||
$this->position = (int)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label number
|
||||
*
|
||||
* @param int $number New number
|
||||
*/
|
||||
public function setLabelNumber($number) {
|
||||
$this->number = is_null($number) ? $number : (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label minimum
|
||||
*
|
||||
* @param int $minimum New minimum
|
||||
*/
|
||||
public function setLabelMinimum($minimum) {
|
||||
$this->minimum = is_null($minimum) ? $minimum : (int)$minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Pie explode
|
||||
*
|
||||
* @param array $explode
|
||||
*/
|
||||
public function explode($explode) {
|
||||
$this->explode = (array)$explode;
|
||||
}
|
||||
|
||||
public function drawEnvelope(awDrawer $drawer) {
|
||||
|
||||
}
|
||||
|
||||
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->values);
|
||||
$sum = array_sum($this->values);
|
||||
|
||||
$width = $x2 - $x1;
|
||||
$height = $y2 - $y1;
|
||||
|
||||
if($aliasing) {
|
||||
$x = $width / 2;
|
||||
$y = $height / 2;
|
||||
} else {
|
||||
$x = $width / 2 + $x1;
|
||||
$y = $height / 2 + $y1;
|
||||
}
|
||||
|
||||
$position = $this->angle;
|
||||
$values = array();
|
||||
$parts = array();
|
||||
$angles = 0;
|
||||
|
||||
if($aliasing) {
|
||||
$side = new awSide(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
foreach($this->values as $key => $value) {
|
||||
|
||||
$angle = ($value / $sum * 360);
|
||||
|
||||
if($key === $count - 1) {
|
||||
$angle = 360 - $angles;
|
||||
}
|
||||
|
||||
$angles += $angle;
|
||||
|
||||
if(array_key_exists($key, $this->explode)) {
|
||||
$middle = 360 - ($position + $angle / 2);
|
||||
$posX = $this->explode[$key] * cos($middle * M_PI / 180);
|
||||
$posY = $this->explode[$key] * sin($middle * M_PI / 180) * -1;
|
||||
|
||||
if($aliasing) {
|
||||
$explode = new awPoint(
|
||||
$posX * 2,
|
||||
$posY * 2
|
||||
);
|
||||
$side->set(
|
||||
max($side->left, $posX * -2),
|
||||
max($side->right, $posX * 2),
|
||||
max($side->top, $posY * -2),
|
||||
max($side->bottom, $posY * 2)
|
||||
);
|
||||
} else {
|
||||
$explode = new awPoint(
|
||||
$posX,
|
||||
$posY
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
$explode = new awPoint(0, 0);
|
||||
}
|
||||
|
||||
$values[$key] = array(
|
||||
$position, ($position + $angle), $explode
|
||||
);
|
||||
|
||||
$color = $this->colors[$key % count($this->colors)];
|
||||
$parts[$key] = new awPiePart($color);
|
||||
|
||||
// Add part to the legend
|
||||
$legend = array_key_exists($key, $this->legendValues) ? $this->legendValues[$key] : $key;
|
||||
$this->legend->add($parts[$key], $legend, awLegend::BACKGROUND);
|
||||
|
||||
$position += $angle;
|
||||
|
||||
}
|
||||
|
||||
if($aliasing) {
|
||||
|
||||
$mainDrawer = $drawer;
|
||||
|
||||
$x *= 2;
|
||||
$y *= 2;
|
||||
$width *= 2;
|
||||
$height *= 2;
|
||||
$this->size *= 2;
|
||||
|
||||
$image = new awImage;
|
||||
$image->border->hide();
|
||||
$image->setSize(
|
||||
$width + $side->left + $side->right,
|
||||
$height + $side->top + $side->bottom + $this->size + 1 /* bugs.php.net ! */
|
||||
);
|
||||
|
||||
$drawer = $image->getDrawer(
|
||||
$width / $image->width,
|
||||
$height / $image->height,
|
||||
($width / 2 + $side->left) / $image->width,
|
||||
($height / 2 + $side->top) / $image->height
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// Draw 3D effect
|
||||
for($i = $this->size; $i > 0; $i--) {
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
|
||||
$color = clone $this->colors[$key % count($this->colors)];
|
||||
$color->brightness(-50);
|
||||
|
||||
list($from, $to, $explode) = $value;
|
||||
|
||||
$drawer->filledArc($color, $explode->move($x, $y + $i), $width, $height, $from, $to);
|
||||
|
||||
$color->free();
|
||||
unset($color);
|
||||
|
||||
if($this->border instanceof awColor) {
|
||||
|
||||
$point = $explode->move($x, $y);
|
||||
|
||||
if($i === $this->size) {
|
||||
|
||||
$drawer->arc($this->border, $point->move(0, $this->size), $width, $height, $from, $to);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
|
||||
$color = $this->colors[$key % count($this->colors)];
|
||||
|
||||
list($from, $to, $explode) = $value;
|
||||
|
||||
$drawer->filledArc($color, $explode->move($x, $y), $width, $height, $from, $to);
|
||||
|
||||
if($this->border instanceof awColor) {
|
||||
|
||||
$point = $explode->move($x, $y);
|
||||
$drawer->arc($this->border, $point, $width, $height, $from, $to);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($aliasing) {
|
||||
|
||||
$x = $x / 2 + $x1;
|
||||
$y = $y / 2 + $y1;
|
||||
$width /= 2;
|
||||
$height /= 2;
|
||||
$this->size /= 2;
|
||||
|
||||
foreach($values as $key => $value) {
|
||||
$old = $values[$key][2];
|
||||
$values[$key][2] = new awPoint(
|
||||
$old->x / 2, $old->y / 2
|
||||
);
|
||||
}
|
||||
|
||||
$mainDrawer->copyResizeImage(
|
||||
$image,
|
||||
new awPoint($x1 - $side->left / 2, $y1 - $side->top / 2),
|
||||
new awPoint($x1 - $side->left / 2 + $image->width / 2, $y1 - $side->top / 2 + $image->height/ 2),
|
||||
new awPoint(0, 0),
|
||||
new awPoint($image->width, $image->height),
|
||||
TRUE
|
||||
);
|
||||
|
||||
$drawer = $mainDrawer;
|
||||
|
||||
}
|
||||
|
||||
// Get labels values
|
||||
$pc = array();
|
||||
foreach($this->values as $key => $value) {
|
||||
$pc[$key] = round($value / $sum * 100, $this->precision);
|
||||
}
|
||||
if($this->label->count() === 0) { // Check that there is no user defined values
|
||||
$this->label->set($pc);
|
||||
}
|
||||
|
||||
$position = 0;
|
||||
|
||||
foreach($pc as $key => $value) {
|
||||
|
||||
// Limit number of labels to display
|
||||
if($position === $this->number) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(is_null($this->minimum) === FALSE and $value < $this->minimum) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$position++;
|
||||
|
||||
list($from, $to, $explode) = $values[$key];
|
||||
|
||||
$angle = $from + ($to - $from) / 2;
|
||||
$angleRad = (360 - $angle) * M_PI / 180;
|
||||
|
||||
$point = new awPoint(
|
||||
$x + $explode->x + cos($angleRad) * ($width / 2 + $this->position),
|
||||
$y + $explode->y - sin($angleRad) * ($height / 2 + $this->position)
|
||||
);
|
||||
|
||||
$angle %= 360;
|
||||
|
||||
// We don't display labels on the 3D effect
|
||||
if($angle > 0 and $angle < 180) {
|
||||
$point = $point->move(0, -1 * sin($angleRad) * $this->size);
|
||||
}
|
||||
|
||||
if($angle >= 45 and $angle < 135) {
|
||||
$this->label->setAlign(awLabel::CENTER, awLabel::BOTTOM);
|
||||
} else if($angle >= 135 and $angle < 225) {
|
||||
$this->label->setAlign(awLabel::RIGHT, awLabel::MIDDLE);
|
||||
} else if($angle >= 225 and $angle < 315) {
|
||||
$this->label->setAlign(awLabel::CENTER, awLabel::TOP);
|
||||
} else {
|
||||
$this->label->setAlign(awLabel::LEFT, awLabel::MIDDLE);
|
||||
}
|
||||
|
||||
$this->label->draw(
|
||||
$drawer,
|
||||
$point,
|
||||
$key
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return margins around the component
|
||||
*
|
||||
* @return array Left, right, top and bottom margins
|
||||
*/
|
||||
public function getMargin() {
|
||||
|
||||
// Get axis informations
|
||||
|
||||
$leftAxis = $this->padding->left;
|
||||
$rightAxis = $this->padding->right;
|
||||
$topAxis = $this->padding->top;
|
||||
$bottomAxis = $this->padding->bottom;
|
||||
|
||||
return array($leftAxis, $rightAxis, $topAxis, $bottomAxis);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change values of Y axis
|
||||
* This method ignores not numeric values
|
||||
*
|
||||
* @param array $values
|
||||
*/
|
||||
public function setValues($values) {
|
||||
|
||||
$this->checkArray($values);
|
||||
$this->values = $values;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return values of Y axis
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues() {
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
private function checkArray(&$array) {
|
||||
|
||||
if(is_array($array) === FALSE) {
|
||||
trigger_error("You tried to set values that are not an array");
|
||||
}
|
||||
|
||||
foreach($array as $key => $value) {
|
||||
if(is_numeric($value) === FALSE) {
|
||||
unset($array[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if(count($array) < 1) {
|
||||
trigger_error("Your graph must have at least 1 value");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Pie');
|
||||
|
||||
/**
|
||||
* Pie
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPiePart implements awLegendable {
|
||||
|
||||
/**
|
||||
* Pie part color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Build a new awPiePart
|
||||
*
|
||||
* @param awColor $color Pie part color
|
||||
*/
|
||||
public function __construct(awColor $color) {
|
||||
|
||||
$this->color = $color;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return NULL
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('PiePart');
|
||||
|
||||
function callbackPerCent($value) {
|
||||
return $value.'%';
|
||||
}
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,303 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__)."/Plot.class.php";
|
||||
|
||||
/**
|
||||
* ScatterPlot
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awScatterPlot extends awPlot implements awLegendable {
|
||||
|
||||
/**
|
||||
* Add marks to the scatter plot
|
||||
*
|
||||
* @var Mark
|
||||
*/
|
||||
public $mark;
|
||||
|
||||
/**
|
||||
* Labels on the plot
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Link points ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $link = FALSE;
|
||||
|
||||
/**
|
||||
* Display impulses
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $impulse = NULL;
|
||||
|
||||
/**
|
||||
* Link NULL points ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $linkNull = FALSE;
|
||||
|
||||
/**
|
||||
* Line color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $lineColor;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineStyle = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Line thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $lineThickness = 1;
|
||||
|
||||
/**
|
||||
* Construct a new awScatterPlot
|
||||
*
|
||||
* @param array $datay Numeric values for Y axis
|
||||
* @param array $datax Numeric values for X axis
|
||||
* @param int $mode
|
||||
*/
|
||||
public function __construct($datay, $datax = NULL) {
|
||||
|
||||
parent::__construct();
|
||||
|
||||
// Defaults marks
|
||||
$this->mark = new awMark;
|
||||
$this->mark->setType(awMark::CIRCLE);
|
||||
$this->mark->setSize(7);
|
||||
$this->mark->border->show();
|
||||
|
||||
$this->label = new awLabel;
|
||||
|
||||
$this->setValues($datay, $datax);
|
||||
$this->setColor(new awBlack);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Display plot as impulses
|
||||
*
|
||||
* @param awColor $impulse Impulses color (or NULL to disable impulses)
|
||||
*/
|
||||
public function setImpulse($color) {
|
||||
$this->impulse = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link scatter plot points
|
||||
*
|
||||
* @param bool $link
|
||||
* @param awColor $color Line color (default to black)
|
||||
*/
|
||||
public function link($link, $color = NULL) {
|
||||
$this->link = (bool)$link;
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore null values for Y data and continue linking
|
||||
*
|
||||
* @param bool $link
|
||||
*/
|
||||
public function linkNull($link) {
|
||||
$this->linkNull = (bool)$link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->lineColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->lineStyle = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line tickness
|
||||
*
|
||||
* @param int $tickness
|
||||
*/
|
||||
public function setThickness($tickness) {
|
||||
$this->lineThickness = (int)$tickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness() {
|
||||
return $this->lineThickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle() {
|
||||
return $this->lineStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor() {
|
||||
return $this->lineColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark() {
|
||||
return $this->mark;
|
||||
}
|
||||
|
||||
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
|
||||
|
||||
$count = count($this->datay);
|
||||
|
||||
// Get start and stop values
|
||||
list($start, $stop) = $this->getLimit();
|
||||
|
||||
// Build the polygon
|
||||
$polygon = new awPolygon;
|
||||
|
||||
for($key = 0; $key < $count; $key++) {
|
||||
|
||||
$x = $this->datax[$key];
|
||||
$y = $this->datay[$key];
|
||||
|
||||
if($y !== NULL) {
|
||||
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
|
||||
$polygon->set($key, $p);
|
||||
} else if($this->linkNull === FALSE) {
|
||||
$polygon->set($key, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Link points if needed
|
||||
if($this->link) {
|
||||
|
||||
$prev = NULL;
|
||||
|
||||
foreach($polygon->all() as $point) {
|
||||
|
||||
if($prev !== NULL and $point !== NULL) {
|
||||
$drawer->line(
|
||||
$this->lineColor,
|
||||
new awLine(
|
||||
$prev,
|
||||
$point,
|
||||
$this->lineStyle,
|
||||
$this->lineThickness
|
||||
)
|
||||
);
|
||||
}
|
||||
$prev = $point;
|
||||
|
||||
}
|
||||
|
||||
$this->lineColor->free();
|
||||
|
||||
}
|
||||
|
||||
// Draw impulses
|
||||
if($this->impulse instanceof awColor) {
|
||||
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
if($point !== NULL) {
|
||||
|
||||
$zero = awAxis::toPosition(
|
||||
$this->xAxis,
|
||||
$this->yAxis,
|
||||
new awPoint($key, 0)
|
||||
);
|
||||
|
||||
$drawer->line(
|
||||
$this->impulse,
|
||||
new awLine(
|
||||
$zero,
|
||||
$point,
|
||||
awLine::SOLID,
|
||||
1
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Draw marks and labels
|
||||
foreach($polygon->all() as $key => $point) {
|
||||
|
||||
$this->mark->draw($drawer, $point);
|
||||
$this->label->draw($drawer, $point, $key);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function xAxisPoint($position) {
|
||||
$y = $this->xAxisZero ? 0 : $this->getRealYMin();
|
||||
return awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($position, $y));
|
||||
}
|
||||
|
||||
public function getXCenter() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('ScatterPlot');
|
||||
?>
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get the minimum of an array and ignore non numeric values
|
||||
*/
|
||||
function array_min($array) {
|
||||
|
||||
if(is_array($array) and count($array) > 0) {
|
||||
|
||||
do {
|
||||
$min = array_pop($array);
|
||||
if(is_numeric($min === FALSE)) {
|
||||
$min = NULL;
|
||||
}
|
||||
} while(count($array) > 0 and $min === NULL);
|
||||
|
||||
if($min !== NULL) {
|
||||
$min = (float)$min;
|
||||
}
|
||||
|
||||
foreach($array as $value) {
|
||||
if(is_numeric($value) and (float)$value < $min) {
|
||||
$min = (float)$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $min;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the maximum of an array and ignore non numeric values
|
||||
*/
|
||||
function array_max($array) {
|
||||
|
||||
if(is_array($array) and count($array) > 0) {
|
||||
|
||||
do {
|
||||
$max = array_pop($array);
|
||||
if(is_numeric($max === FALSE)) {
|
||||
$max = NULL;
|
||||
}
|
||||
} while(count($array) > 0 and $max === NULL);
|
||||
|
||||
if($max !== NULL) {
|
||||
$max = (float)$max;
|
||||
}
|
||||
|
||||
foreach($array as $value) {
|
||||
if(is_numeric($value) and (float)$value > $max) {
|
||||
$max = (float)$value;
|
||||
}
|
||||
}
|
||||
|
||||
return $max;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Register a class with the prefix in configuration file
|
||||
*/
|
||||
function registerClass($class, $abstract = FALSE) {
|
||||
|
||||
if(ARTICHOW_PREFIX === 'aw') {
|
||||
return;
|
||||
}
|
||||
|
||||
/* <php5> */
|
||||
if($abstract) {
|
||||
$abstract = 'abstract';
|
||||
} else {
|
||||
$abstract = '';
|
||||
}
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
$abstract = '';
|
||||
-- </php4> */
|
||||
|
||||
eval($abstract." class ".ARTICHOW_PREFIX.$class." extends aw".$class." { }");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Register an interface with the prefix in configuration file
|
||||
*/
|
||||
function registerInterface($interface) {
|
||||
|
||||
if(ARTICHOW_PREFIX === 'aw') {
|
||||
return;
|
||||
}
|
||||
|
||||
/* <php5> */
|
||||
eval("interface ".ARTICHOW_PREFIX.$interface." extends aw".$interface." { }");
|
||||
/* </php5> */
|
||||
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,799 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Handle axis
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awAxis {
|
||||
|
||||
/**
|
||||
* Axis line
|
||||
*
|
||||
* @var Line
|
||||
*/
|
||||
public $line;
|
||||
|
||||
/**
|
||||
* Axis labels
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* Axis title
|
||||
*
|
||||
* @var Label
|
||||
*/
|
||||
public $title;
|
||||
|
||||
/**
|
||||
* Title position
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $titlePosition = 0.5;
|
||||
|
||||
/**
|
||||
* Labels number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $labelNumber;
|
||||
|
||||
/**
|
||||
* Axis ticks
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $ticks = array();
|
||||
|
||||
/**
|
||||
* Axis and ticks color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Axis left and right padding
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $padding;
|
||||
|
||||
/**
|
||||
* Axis range
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $range;
|
||||
|
||||
/**
|
||||
* Hide axis
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Auto-scaling mode
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $auto = TRUE;
|
||||
|
||||
/**
|
||||
* Axis range callback function
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rangeCallback = array(
|
||||
'toValue' => 'toProportionalValue',
|
||||
'toPosition' => 'toProportionalPosition'
|
||||
);
|
||||
|
||||
/**
|
||||
* Build the axis
|
||||
*
|
||||
* @param float $min Begin of the range of the axis
|
||||
* @param float $max End of the range of the axis
|
||||
*/
|
||||
public function __construct($min = NULL, $max = NULL) {
|
||||
|
||||
$this->line = new awVector(
|
||||
new awPoint(0, 0),
|
||||
new awPoint(0, 0)
|
||||
);
|
||||
|
||||
$this->label = new awLabel;
|
||||
$this->padding = new awSide;
|
||||
|
||||
$this->title = new awLabel(
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
0
|
||||
);
|
||||
|
||||
$this->setColor(new awBlack);
|
||||
|
||||
if($min !== NULL and $max !== NULL) {
|
||||
$this->setRange($min, $max);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable auto-scaling mode
|
||||
*
|
||||
* @param bool $auto
|
||||
*/
|
||||
public function auto($auto) {
|
||||
$this->auto = (bool)$auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get auto-scaling mode status
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isAuto() {
|
||||
return $this->auto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide axis
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show axis
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = !(bool)$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tick object from its name
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
* @return Tick
|
||||
*/
|
||||
public function tick($name) {
|
||||
/* <php5> */
|
||||
return array_key_exists($name, $this->ticks) ? $this->ticks[$name] : NULL;
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
if(array_key_exists($name, $this->ticks)) {
|
||||
return $tick = &$this->ticks[$name];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
-- </php4> */
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a tick object
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
* @param awTick $tick Tick object
|
||||
*/
|
||||
public function addTick($name, awTick $tick) {
|
||||
/* <php5> */
|
||||
$this->ticks[$name] = $tick;
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
$this->ticks[$name] = &$tick;
|
||||
-- </php4> */
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a tick object
|
||||
*
|
||||
* @param string $name Tick object name
|
||||
*/
|
||||
public function deleteTick($name) {
|
||||
if(array_key_exists($name, $this->ticks)) {
|
||||
unset($this->ticks[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all ticks
|
||||
*
|
||||
* @param bool $hide Hide or not ?
|
||||
*/
|
||||
public function hideTicks($hide = TRUE) {
|
||||
/* <php5> */
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->hide($hide);
|
||||
}
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
$this->ticks[$key]->hide($hide);
|
||||
}
|
||||
-- </php4> */
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks style
|
||||
*
|
||||
* @param int $style Ticks style
|
||||
*/
|
||||
public function setTickStyle($style) {
|
||||
/* <php5> */
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->setStyle($style);
|
||||
}
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
$this->ticks[$key]->setStyle($style);
|
||||
}
|
||||
-- </php4> */
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks interval
|
||||
*
|
||||
* @param int $interval Ticks interval
|
||||
*/
|
||||
public function setTickInterval($interval) {
|
||||
/* <php5> */
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->setInterval($interval);
|
||||
}
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
$this->ticks[$key]->setInterval($interval);
|
||||
}
|
||||
-- </php4> */
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks relative to others ticks
|
||||
*
|
||||
* @param awTick $to Change number of theses ticks
|
||||
* @param awTick $from Ticks reference
|
||||
* @param float $number Number of ticks by the reference
|
||||
*/
|
||||
public function setNumberByTick($to, $from, $number) {
|
||||
$this->ticks[$to]->setNumberByTick($this->ticks[$from], $number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse ticks style
|
||||
*/
|
||||
public function reverseTickStyle() {
|
||||
/* <php5> */
|
||||
foreach($this->ticks as $tick) {
|
||||
if($tick->getStyle() === awTick::IN) {
|
||||
$tick->setStyle(awTick::OUT);
|
||||
} else if($tick->getStyle() === awTick::OUT) {
|
||||
$tick->setStyle(awTick::IN);
|
||||
}
|
||||
}
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
foreach($this->ticks as $key => $tick) {
|
||||
if($this->ticks[$key]->getStyle() === awTick::IN) {
|
||||
$this->ticks[$key]->setStyle(awTick::OUT);
|
||||
} else if($this->ticks[$key]->getStyle() === awTick::OUT) {
|
||||
$this->ticks[$key]->setStyle(awTick::IN);
|
||||
}
|
||||
}
|
||||
-- </php4> */
|
||||
}
|
||||
|
||||
/**
|
||||
* Change interval of labels
|
||||
*
|
||||
* @param int $interval Interval
|
||||
*/
|
||||
public function setLabelInterval($interval) {
|
||||
$this->auto(FALSE);
|
||||
$this->setTickInterval($interval);
|
||||
$this->label->setInterval($interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of labels
|
||||
*
|
||||
* @param int $number Number of labels to display (can be NULL)
|
||||
*/
|
||||
public function setLabelNumber($number) {
|
||||
$this->auto(FALSE);
|
||||
$this->labelNumber = is_null($number) ? NULL : (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of labels
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLabelNumber() {
|
||||
return $this->labelNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change precision of labels
|
||||
*
|
||||
* @param int $precision Precision
|
||||
*/
|
||||
public function setLabelPrecision($precision) {
|
||||
$this->auto(FALSE);
|
||||
$function = 'axis'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
return sprintf("%.'.(int)$precision.'f", $value);
|
||||
}');
|
||||
$this->label->setCallbackFunction($function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text of labels
|
||||
*
|
||||
* @param array $texts Some texts
|
||||
*/
|
||||
public function setLabelText($texts) {
|
||||
if(is_array($texts)) {
|
||||
$this->auto(FALSE);
|
||||
$function = 'axis'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
$texts = '.var_export($texts, TRUE).';
|
||||
return isset($texts[$value]) ? $texts[$value] : \'?\';
|
||||
}');
|
||||
$this->label->setCallbackFunction($function);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the position of a point
|
||||
*
|
||||
* @param awAxis $xAxis X axis
|
||||
* @param awAxis $yAxis Y axis
|
||||
* @param awPoint $p Position of the point
|
||||
* @return Point Position on the axis
|
||||
*/
|
||||
public static function toPosition(awAxis $xAxis, awAxis $yAxis, awPoint $p) {
|
||||
|
||||
$p1 = $xAxis->getPointFromValue($p->x);
|
||||
$p2 = $yAxis->getPointFromValue($p->y);
|
||||
|
||||
return new awPoint(
|
||||
round($p1->x),
|
||||
round($p2->y)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change title alignment
|
||||
*
|
||||
* @param int $alignment New Alignment
|
||||
*/
|
||||
public function setTitleAlignment($alignment) {
|
||||
|
||||
switch($alignment) {
|
||||
|
||||
case awLabel::TOP :
|
||||
$this->setTitlePosition(1);
|
||||
$this->title->setAlign(NULL, awLabel::BOTTOM);
|
||||
break;
|
||||
|
||||
case awLabel::BOTTOM :
|
||||
$this->setTitlePosition(0);
|
||||
$this->title->setAlign(NULL, awLabel::TOP);
|
||||
break;
|
||||
|
||||
case awLabel::LEFT :
|
||||
$this->setTitlePosition(0);
|
||||
$this->title->setAlign(awLabel::LEFT);
|
||||
break;
|
||||
|
||||
case awLabel::RIGHT :
|
||||
$this->setTitlePosition(1);
|
||||
$this->title->setAlign(awLabel::RIGHT);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change title position on the axis
|
||||
*
|
||||
* @param float $position A new awposition between 0 and 1
|
||||
*/
|
||||
public function setTitlePosition($position) {
|
||||
$this->titlePosition = (float)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis and axis title color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
$this->title->setColor($color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis padding
|
||||
*
|
||||
* @param int $left Left padding in pixels
|
||||
* @param int $right Right padding in pixels
|
||||
*/
|
||||
public function setPadding($left, $right) {
|
||||
$this->padding->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get axis padding
|
||||
*
|
||||
* @return Side
|
||||
*/
|
||||
public function getPadding() {
|
||||
return $this->padding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis range
|
||||
*
|
||||
* @param float $min
|
||||
* @param float $max
|
||||
*/
|
||||
public function setRange($min, $max) {
|
||||
if($min !== NULL) {
|
||||
$this->range[0] = (float)$min;
|
||||
}
|
||||
if($max !== NULL) {
|
||||
$this->range[1] = (float)$max;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get axis range
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRange() {
|
||||
return $this->range;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change axis range callback function
|
||||
*
|
||||
* @param string $toValue Transform a position between 0 and 1 to a value
|
||||
* @param string $toPosition Transform a value to a position between 0 and 1 on the axis
|
||||
*/
|
||||
public function setRangeCallback($toValue, $toPosition) {
|
||||
$this->rangeCallback = array(
|
||||
'toValue' => (string)$toValue,
|
||||
'toPosition' => (string)$toPosition
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Center X values of the axis
|
||||
*
|
||||
* @param awAxis $axis An axis
|
||||
* @param float $value The reference value on the axis
|
||||
*/
|
||||
public function setXCenter(awAxis $axis, $value) {
|
||||
|
||||
// Check vector angle
|
||||
if($this->line->isVertical() === FALSE) {
|
||||
trigger_error("setXCenter() can only be used on vertical axes", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$p = $axis->getPointFromValue($value);
|
||||
|
||||
$this->line->setX(
|
||||
$p->x,
|
||||
$p->x
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Center Y values of the axis
|
||||
*
|
||||
* @param awAxis $axis An axis
|
||||
* @param float $value The reference value on the axis
|
||||
*/
|
||||
public function setYCenter(awAxis $axis, $value) {
|
||||
|
||||
// Check vector angle
|
||||
if($this->line->isHorizontal() === FALSE) {
|
||||
trigger_error("setYCenter() can only be used on horizontal axes", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$p = $axis->getPointFromValue($value);
|
||||
|
||||
$this->line->setY(
|
||||
$p->y,
|
||||
$p->y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance between to values on the axis
|
||||
*
|
||||
* @param float $from The first value
|
||||
* @param float $to The last value
|
||||
* @return Point
|
||||
*/
|
||||
public function getDistance($from, $to) {
|
||||
|
||||
$p1 = $this->getPointFromValue($from);
|
||||
$p2 = $this->getPointFromValue($to);
|
||||
|
||||
return $p1->getDistance($p2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on the axis from a value
|
||||
*
|
||||
* @param float $value
|
||||
* @return Point
|
||||
*/
|
||||
protected function getPointFromValue($value) {
|
||||
|
||||
$callback = $this->rangeCallback['toPosition'];
|
||||
|
||||
list($min, $max) = $this->range;
|
||||
$position = $callback($value, $min, $max);
|
||||
|
||||
return $this->getPointFromPosition($position);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on the axis from a position
|
||||
*
|
||||
* @param float $position A position between 0 and 1
|
||||
* @return Point
|
||||
*/
|
||||
protected function getPointFromPosition($position) {
|
||||
|
||||
$vector = $this->getVector();
|
||||
|
||||
$angle = $vector->getAngle();
|
||||
$size = $vector->getSize();
|
||||
|
||||
return $vector->p1->move(
|
||||
cos($angle) * $size * $position,
|
||||
-1 * sin($angle) * $size * $position
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw axis
|
||||
*
|
||||
* @param awDrawer $drawer A drawer
|
||||
*/
|
||||
public function draw(awDrawer $drawer) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$vector = $this->getVector();
|
||||
|
||||
// Draw axis ticks
|
||||
$this->drawTicks($drawer, $vector);
|
||||
|
||||
// Draw axis line
|
||||
$this->line($drawer);
|
||||
|
||||
// Draw labels
|
||||
$this->drawLabels($drawer);
|
||||
|
||||
// Draw axis title
|
||||
$p = $this->getPointFromPosition($this->titlePosition);
|
||||
$this->title->draw($drawer, $p);
|
||||
|
||||
}
|
||||
|
||||
public function autoScale() {
|
||||
|
||||
if($this->isAuto() === FALSE) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($min, $max) = $this->getRange();
|
||||
$interval = $max - $min;
|
||||
|
||||
if($interval > 0) {
|
||||
$partMax = $max / $interval;
|
||||
$partMin = $min / $interval;
|
||||
} else {
|
||||
$partMax = 0;
|
||||
$partMin = 0;
|
||||
}
|
||||
|
||||
$difference = log($interval) / log(10);
|
||||
$difference = floor($difference);
|
||||
|
||||
$pow = pow(10, $difference);
|
||||
|
||||
if($pow > 0) {
|
||||
$intervalNormalize = $interval / $pow;
|
||||
} else {
|
||||
$intervalNormalize = 0;
|
||||
}
|
||||
|
||||
if($difference <= 0) {
|
||||
|
||||
$precision = $difference * -1 + 1;
|
||||
|
||||
if($intervalNormalize > 2) {
|
||||
$precision--;
|
||||
}
|
||||
|
||||
} else {
|
||||
$precision = 0;
|
||||
}
|
||||
|
||||
if($min != 0 and $max != 0) {
|
||||
$precision++;
|
||||
}
|
||||
|
||||
$this->setLabelPrecision($precision);
|
||||
|
||||
if($intervalNormalize <= 1.5) {
|
||||
$intervalReal = 1.5;
|
||||
$labelNumber = 4;
|
||||
} else if($intervalNormalize <= 2) {
|
||||
$intervalReal = 2;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 3) {
|
||||
$intervalReal = 3;
|
||||
$labelNumber = 4;
|
||||
} else if($intervalNormalize <= 4) {
|
||||
$intervalReal = 4;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 5) {
|
||||
$intervalReal = 5;
|
||||
$labelNumber = 6;
|
||||
} else if($intervalNormalize <= 8) {
|
||||
$intervalReal = 8;
|
||||
$labelNumber = 5;
|
||||
} else if($intervalNormalize <= 10) {
|
||||
$intervalReal = 10;
|
||||
$labelNumber = 6;
|
||||
}
|
||||
|
||||
if($min == 0) {
|
||||
|
||||
$this->setRange(
|
||||
$min,
|
||||
$intervalReal * $pow
|
||||
);
|
||||
|
||||
} else if($max == 0) {
|
||||
|
||||
$this->setRange(
|
||||
$intervalReal * $pow * -1,
|
||||
0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->setLabelNumber($labelNumber);
|
||||
|
||||
}
|
||||
|
||||
protected function line(awDrawer $drawer) {
|
||||
|
||||
$drawer->line(
|
||||
$this->color,
|
||||
$this->line
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function drawTicks(awDrawer $drawer, awVector $vector) {
|
||||
|
||||
foreach($this->ticks as $tick) {
|
||||
$tick->setColor($this->color);
|
||||
$tick->draw($drawer, $vector);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function drawLabels($drawer) {
|
||||
|
||||
if($this->labelNumber !== NULL) {
|
||||
list($min, $max) = $this->range;
|
||||
$number = $this->labelNumber - 1;
|
||||
if($number < 1) {
|
||||
return;
|
||||
}
|
||||
$function = $this->rangeCallback['toValue'];
|
||||
$labels = array();
|
||||
for($i = 0; $i <= $number; $i++) {
|
||||
$labels[] = $function($i / $number, $min, $max);
|
||||
}
|
||||
$this->label->set($labels);
|
||||
}
|
||||
|
||||
$labels = $this->label->count();
|
||||
|
||||
for($i = 0; $i < $labels; $i++) {
|
||||
|
||||
$p = $this->getPointFromValue($this->label->get($i));
|
||||
$this->label->draw($drawer, $p, $i);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getVector() {
|
||||
|
||||
$angle = $this->line->getAngle();
|
||||
|
||||
// Compute paddings
|
||||
$vector = new awVector(
|
||||
$this->line->p1->move(
|
||||
cos($angle) * $this->padding->left,
|
||||
-1 * sin($angle) * $this->padding->left
|
||||
),
|
||||
$this->line->p2->move(
|
||||
-1 * cos($angle) * $this->padding->right,
|
||||
-1 * -1 * sin($angle) * $this->padding->right
|
||||
)
|
||||
);
|
||||
|
||||
return $vector;
|
||||
|
||||
}
|
||||
|
||||
public function __clone() {
|
||||
|
||||
$this->label = clone $this->label;
|
||||
$this->line = clone $this->line;
|
||||
$this->title = clone $this->title;
|
||||
|
||||
foreach($this->ticks as $name => $tick) {
|
||||
$this->ticks[$name] = clone $tick;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Axis');
|
||||
|
||||
function toProportionalValue($position, $min, $max) {
|
||||
return $min + ($max - $min) * $position;
|
||||
}
|
||||
|
||||
function toProportionalPosition($value, $min, $max) {
|
||||
if($max - $min == 0) {
|
||||
return 0;
|
||||
}
|
||||
return ($value - $min) / ($max - $min);
|
||||
}
|
||||
?>
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Draw border
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBorder {
|
||||
|
||||
/**
|
||||
* Border color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Hide border ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Border line style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $style;
|
||||
|
||||
/**
|
||||
* Build the border
|
||||
*
|
||||
* @param awColor $color Border color
|
||||
* @param int $style Border style
|
||||
*/
|
||||
public function __construct($color = NULL, $style = awLine::SOLID) {
|
||||
|
||||
$this->setStyle($style);
|
||||
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
} else {
|
||||
$this->setColor(new awBlack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change border color
|
||||
* This method automatically shows the border if it is hidden
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
$this->show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change border style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide border ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show border ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the border visible ?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function visible() {
|
||||
return !$this->hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw border as a rectangle
|
||||
*
|
||||
* @param awDrawer $drawer
|
||||
* @param awPoint $p1 Top-left corner
|
||||
* @param awPoint $p2 Bottom-right corner
|
||||
*/
|
||||
public function rectangle(awDrawer $drawer, awPoint $p1, awPoint $p2) {
|
||||
|
||||
// Border is hidden
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$line = new awLine;
|
||||
$line->setStyle($this->style);
|
||||
$line->setLocation($p1, $p2);
|
||||
|
||||
$drawer->rectangle($this->color, $line);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw border as an ellipse
|
||||
*
|
||||
* @param awDrawer $drawer
|
||||
* @param awPoint $center Ellipse center
|
||||
* @param int $width Ellipse width
|
||||
* @param int $height Ellipse height
|
||||
*/
|
||||
public function ellipse(awDrawer $drawer, awPoint $center, $width, $height) {
|
||||
|
||||
// Border is hidden
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch($this->style) {
|
||||
|
||||
case awLine::SOLID :
|
||||
$drawer->ellipse($this->color, $center, $width, $height);
|
||||
break;
|
||||
|
||||
default :
|
||||
trigger_error("Dashed and dotted borders and not yet implemented on ellipses", E_USER_ERROR);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Border');
|
||||
?>
|
||||
|
|
@ -1,232 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create your colors
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awColor {
|
||||
|
||||
public $red;
|
||||
public $green;
|
||||
public $blue;
|
||||
public $alpha;
|
||||
|
||||
private $resource;
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Build your color
|
||||
*
|
||||
* @var int $red Red intensity (from 0 to 255)
|
||||
* @var int $green Green intensity (from 0 to 255)
|
||||
* @var int $blue Blue intensity (from 0 to 255)
|
||||
* @var int $alpha Alpha channel (from 0 to 100)
|
||||
*/
|
||||
public function __construct($red, $green, $blue, $alpha = 0) {
|
||||
|
||||
$this->red = (int)$red;
|
||||
$this->green = (int)$green;
|
||||
$this->blue = (int)$blue;
|
||||
$this->alpha = (int)round($alpha * 127 / 100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a GDised color
|
||||
*
|
||||
* @param resource $resource A GD resource
|
||||
* @return int
|
||||
*/
|
||||
public function getColor($resource) {
|
||||
|
||||
$this->resource = $resource;
|
||||
|
||||
if($this->color === NULL) {
|
||||
|
||||
if($this->alpha === 0 or function_exists('imagecolorallocatealpha') === FALSE) {
|
||||
$this->color = imagecolorallocate($this->resource, $this->red, $this->green, $this->blue);
|
||||
} else {
|
||||
$this->color = imagecolorallocatealpha($this->resource, $this->red, $this->green, $this->blue, $this->alpha);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $this->color;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change color brightness
|
||||
*
|
||||
* @param int $brightness Add this intensity to the color (betweeen -255 and +255)
|
||||
*/
|
||||
public function brightness($brightness) {
|
||||
|
||||
$brightness = (int)$brightness;
|
||||
|
||||
$this->red = min(255, max(0, $this->red + $brightness));
|
||||
$this->green = min(255, max(0, $this->green + $brightness));
|
||||
$this->blue = min(255, max(0, $this->blue + $brightness));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RGB and alpha values of your color
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rgba() {
|
||||
|
||||
return array($this->red, $this->green, $this->blue, $this->alpha);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Free resources used for this color
|
||||
*/
|
||||
public function free() {
|
||||
|
||||
if($this->resource !== NULL) {
|
||||
|
||||
@imagecolordeallocate($this->resource, $this->color);
|
||||
$this->resource = NULL;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
|
||||
$this->free();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Color');
|
||||
|
||||
$colors = array(
|
||||
'Black' => array(0, 0, 0),
|
||||
'AlmostBlack' => array(48, 48, 48),
|
||||
'VeryDarkGray' => array(88, 88, 88),
|
||||
'DarkGray' => array(128, 128, 128),
|
||||
'MidGray' => array(160, 160, 160),
|
||||
'LightGray' => array(195, 195, 195),
|
||||
'VeryLightGray' => array(220, 220, 220),
|
||||
'White' => array(255, 255, 255),
|
||||
'VeryDarkRed' => array(64, 0, 0),
|
||||
'DarkRed' => array(128, 0, 0),
|
||||
'MidRed' => array(192, 0, 0),
|
||||
'Red' => array(255, 0, 0),
|
||||
'LightRed' => array(255, 192, 192),
|
||||
'VeryDarkGreen' => array(0, 64, 0),
|
||||
'DarkGreen' => array(0, 128, 0),
|
||||
'MidGreen' => array(0, 192, 0),
|
||||
'Green' => array(0, 255, 0),
|
||||
'LightGreen' => array(192, 255, 192),
|
||||
'VeryDarkBlue' => array(0, 0, 64),
|
||||
'DarkBlue' => array(0, 0, 128),
|
||||
'MidBlue' => array(0, 0, 192),
|
||||
'Blue' => array(0, 0, 255),
|
||||
'LightBlue' => array(192, 192, 255),
|
||||
'VeryDarkYellow' => array(64, 64, 0),
|
||||
'DarkYellow' => array(128, 128, 0),
|
||||
'MidYellow' => array(192, 192, 0),
|
||||
'Yellow' => array(255, 255, 2),
|
||||
'LightYellow' => array(255, 255, 192),
|
||||
'VeryDarkCyan' => array(0, 64, 64),
|
||||
'DarkCyan' => array(0, 128, 128),
|
||||
'MidCyan' => array(0, 192, 192),
|
||||
'Cyan' => array(0, 255, 255),
|
||||
'LightCyan' => array(192, 255, 255),
|
||||
'VeryDarkMagenta' => array(64, 0, 64),
|
||||
'DarkMagenta' => array(128, 0, 128),
|
||||
'MidMagenta' => array(192, 0, 192),
|
||||
'Magenta' => array(255, 0, 255),
|
||||
'LightMagenta' => array(255, 192, 255),
|
||||
'DarkOrange' => array(192, 88, 0),
|
||||
'Orange' => array(255, 128, 0),
|
||||
'LightOrange' => array(255, 168, 88),
|
||||
'VeryLightOrange' => array(255, 220, 168),
|
||||
'DarkPink' => array(192, 0, 88),
|
||||
'Pink' => array(255, 0, 128),
|
||||
'LightPink' => array(255, 88, 168),
|
||||
'VeryLightPink' => array(255, 168, 220),
|
||||
'DarkPurple' => array(88, 0, 192),
|
||||
'Purple' => array(128, 0, 255),
|
||||
'LightPurple' => array(168, 88, 255),
|
||||
'VeryLightPurple' => array(220, 168, 255),
|
||||
);
|
||||
|
||||
/* <php5> */
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($colors as $name => $color) {
|
||||
|
||||
list($red, $green, $blue) = $color;
|
||||
|
||||
$php .= '
|
||||
class aw'.$name.' extends awColor {
|
||||
|
||||
public function __construct($alpha = 0) {
|
||||
parent::__construct('.$red.', '.$green.', '.$blue.', $alpha);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
|
||||
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($colors as $name => $color) {
|
||||
|
||||
list($red, $green, $blue) = $color;
|
||||
|
||||
$php .= '
|
||||
class aw'.$name.' extends awColor {
|
||||
|
||||
function aw'.$name.'($alpha = 0) {
|
||||
parent::awColor('.$red.', '.$green.', '.$blue.', $alpha);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.$name.' extends aw'.$name.' {
|
||||
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
-- </php4> */
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,349 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Built-in PHP fonts
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awFont {
|
||||
|
||||
/**
|
||||
* Used font
|
||||
*
|
||||
* @param int $font
|
||||
*/
|
||||
public $font;
|
||||
|
||||
/**
|
||||
* Build the font
|
||||
*
|
||||
* @param int $font Font identifier
|
||||
*/
|
||||
public function __construct($font) {
|
||||
|
||||
$this->font = $font;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a text
|
||||
*
|
||||
* @param awDrawer $drawer
|
||||
* @param awPoint $p Draw text at this point
|
||||
* @param awText $text The text
|
||||
*/
|
||||
public function draw(awDrawer $drawer, awPoint $p, awText $text) {
|
||||
|
||||
$angle = $text->getAngle();
|
||||
|
||||
if($angle !== 90 and $angle !== 0) {
|
||||
trigger_error("You can only use 0° and 90°", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if($angle === 90) {
|
||||
$function = 'imagestringup';
|
||||
} else {
|
||||
$function = 'imagestring';
|
||||
}
|
||||
|
||||
if($angle === 90) {
|
||||
$add = $this->getTextHeight($text);
|
||||
} else {
|
||||
$add = 0;
|
||||
}
|
||||
|
||||
$color = $text->getColor();
|
||||
$rgb = $color->getColor($drawer->resource);
|
||||
|
||||
$function(
|
||||
$drawer->resource,
|
||||
$this->font,
|
||||
$drawer->x + $p->x,
|
||||
$drawer->y + $p->y + $add,
|
||||
$text->getText(),
|
||||
$rgb
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a string
|
||||
*
|
||||
* @param awText $text A string
|
||||
*/
|
||||
public function getTextWidth(awText $text) {
|
||||
|
||||
if($text->getAngle() === 90) {
|
||||
$text->setAngle(45);
|
||||
return $this->getTextHeight($text);
|
||||
} else if($text->getAngle() === 45) {
|
||||
$text->setAngle(90);
|
||||
}
|
||||
|
||||
$font = $text->getFont();
|
||||
$fontWidth = imagefontwidth($font->font);
|
||||
|
||||
if($fontWidth === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
}
|
||||
|
||||
return (int)$fontWidth * strlen($text->getText());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of a string
|
||||
*
|
||||
* @param awText $text A string
|
||||
*/
|
||||
public function getTextHeight(awText $text) {
|
||||
|
||||
if($text->getAngle() === 90) {
|
||||
$text->setAngle(45);
|
||||
return $this->getTextWidth($text);
|
||||
} else if($text->getAngle() === 45) {
|
||||
$text->setAngle(90);
|
||||
}
|
||||
|
||||
$font = $text->getFont();
|
||||
$fontHeight = imagefontheight($font->font);
|
||||
|
||||
if($fontHeight === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
}
|
||||
|
||||
return (int)$fontHeight;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Font');
|
||||
|
||||
/**
|
||||
* TTF fonts
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awTTFFont extends awFont {
|
||||
|
||||
/**
|
||||
* Font size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $size;
|
||||
|
||||
/**
|
||||
* Font file
|
||||
*
|
||||
* @param string $font Font file
|
||||
* @param int $size Font size
|
||||
*/
|
||||
public function __construct($font, $size) {
|
||||
|
||||
parent::__construct($font);
|
||||
|
||||
$this->size = (int)$size;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a text
|
||||
*
|
||||
* @param awDrawer $drawer
|
||||
* @param awPoint $p Draw text at this point
|
||||
* @param awText $text The text
|
||||
*/
|
||||
public function draw(awDrawer $drawer, awPoint $p, awText $text) {
|
||||
|
||||
// Make easier font positionment
|
||||
$text->setText($text->getText()." ");
|
||||
|
||||
$color = $text->getColor();
|
||||
$rgb = $color->getColor($drawer->resource);
|
||||
|
||||
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
|
||||
|
||||
$height = - $box[5];
|
||||
|
||||
$box = imagettfbbox($this->size, 90, $this->font, $text->getText());
|
||||
$width = abs($box[6] - $box[2]);
|
||||
|
||||
// Restore old text
|
||||
$text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
|
||||
|
||||
imagettftext(
|
||||
$drawer->resource,
|
||||
$this->size,
|
||||
$text->getAngle(),
|
||||
$drawer->x + $p->x + $width * sin($text->getAngle() / 180 * M_PI),
|
||||
$drawer->y + $p->y + $height,
|
||||
$rgb,
|
||||
$this->font,
|
||||
$text->getText()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of a string
|
||||
*
|
||||
* @param awText $text A string
|
||||
*/
|
||||
public function getTextWidth(awText $text) {
|
||||
|
||||
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
|
||||
|
||||
if($box === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
list(, , $x2, $y2, , , $x1, $y1) = $box;
|
||||
|
||||
return abs($x2 - $x1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of a string
|
||||
*
|
||||
* @param awText $text A string
|
||||
*/
|
||||
public function getTextHeight(awText $text) {
|
||||
|
||||
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
|
||||
|
||||
if($box === FALSE) {
|
||||
trigger_error("Unable to get font size", E_USER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
list(, , $x2, $y2, , , $x1, $y1) = $box;
|
||||
|
||||
return abs($y2 - $y1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('TTFFont');
|
||||
|
||||
/* <php5> */
|
||||
|
||||
$php = '';
|
||||
|
||||
for($i = 1; $i <= 5; $i++) {
|
||||
|
||||
$php .= '
|
||||
class awFont'.$i.' extends awFont {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('.$i.');
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($fonts as $font) {
|
||||
|
||||
// DOL_CHANGE LDR Fix to allow - into font names
|
||||
$php .= '
|
||||
class aw'.str_replace('-','_',$font).' extends awTTFFont {
|
||||
|
||||
public function __construct($size) {
|
||||
parent::__construct(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.str_replace('-','_',$font).' extends aw'.str_replace('-','_',$font).' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
|
||||
$php = '';
|
||||
|
||||
for($i = 1; $i <= 5; $i++) {
|
||||
|
||||
$php .= '
|
||||
class awFont'.$i.' extends awFont {
|
||||
|
||||
function awFont'.$i.'() {
|
||||
parent::awFont('.$i.');
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
$php = '';
|
||||
|
||||
foreach($fonts as $font) {
|
||||
|
||||
$php .= '
|
||||
class aw'.$font.' extends awTTFFont {
|
||||
|
||||
function aw'.$font.'($size) {
|
||||
parent::awTTFFont(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
|
||||
}
|
||||
|
||||
}
|
||||
';
|
||||
|
||||
if(ARTICHOW_PREFIX !== 'aw') {
|
||||
$php .= '
|
||||
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {
|
||||
}
|
||||
';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
eval($php);
|
||||
|
||||
-- </php4> */
|
||||
|
||||
?>
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create your gradients
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
abstract class awGradient {
|
||||
|
||||
/**
|
||||
* From color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
public $from;
|
||||
|
||||
/**
|
||||
* To color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
public $to;
|
||||
|
||||
/**
|
||||
* Build the gradient
|
||||
*
|
||||
* @param awColor $from From color
|
||||
* @param awColor $to To color
|
||||
*/
|
||||
public function __construct($from, $to) {
|
||||
|
||||
$this->from = $from;
|
||||
$this->to = $to;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Free memory used by the colors of the gradient
|
||||
*/
|
||||
public function free() {
|
||||
|
||||
$this->from->free();
|
||||
$this->to->free();
|
||||
|
||||
}
|
||||
|
||||
public function __destruct( ){
|
||||
|
||||
$this->free();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Gradient', TRUE);
|
||||
|
||||
|
||||
/**
|
||||
* Create a linear gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLinearGradient extends awGradient {
|
||||
|
||||
/**
|
||||
* Gradient angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $angle;
|
||||
|
||||
/**
|
||||
* Build the linear gradient
|
||||
*
|
||||
* @param awColor $from From color
|
||||
* @param awColor $to To color
|
||||
* @param int $angle Gradient angle
|
||||
*/
|
||||
public function __construct($from, $to, $angle) {
|
||||
|
||||
parent::__construct(
|
||||
$from, $to
|
||||
);
|
||||
|
||||
$this->angle = $angle;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('LinearGradient');
|
||||
|
||||
|
||||
/**
|
||||
* Create a bilinear gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awBilinearGradient extends awLinearGradient {
|
||||
|
||||
/**
|
||||
* Gradient center
|
||||
*
|
||||
* @var int Center between 0 and 1
|
||||
*/
|
||||
public $center;
|
||||
|
||||
/**
|
||||
* Build the bilinear gradient
|
||||
*
|
||||
* @param awColor $from From color
|
||||
* @param awColor $to To color
|
||||
* @param int $angle Gradient angle
|
||||
* @param int $center Gradient center
|
||||
*/
|
||||
public function __construct($from, $to, $angle, $center = 0.5) {
|
||||
|
||||
parent::__construct(
|
||||
$from, $to, $angle
|
||||
);
|
||||
|
||||
$this->center = $center;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('BilinearGradient');
|
||||
|
||||
/**
|
||||
* Create a radial gradient
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awRadialGradient extends awGradient {
|
||||
|
||||
}
|
||||
|
||||
registerClass('RadialGradient');
|
||||
?>
|
||||
|
|
@ -1,289 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Grid
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awGrid {
|
||||
|
||||
/**
|
||||
* Vertical lines of the grid
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $xgrid = array();
|
||||
|
||||
/**
|
||||
* Horizontal lines of the grid
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $ygrid = array();
|
||||
|
||||
/**
|
||||
* Is the component grid hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Are horizontal lines hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hideHorizontal = FALSE;
|
||||
|
||||
/**
|
||||
* Are vertical lines hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hideVertical = FALSE;
|
||||
|
||||
/**
|
||||
* Grid color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Grid space
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $space;
|
||||
|
||||
/**
|
||||
* Line type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $type = awLine::SOLID;
|
||||
|
||||
/**
|
||||
* Grid interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $interval = array(1, 1);
|
||||
|
||||
/**
|
||||
* Grid background color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $background;
|
||||
|
||||
/**
|
||||
* Build the factory
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
// Set a grid default color
|
||||
$this->color = new awColor(210, 210, 210);
|
||||
$this->background = new awColor(255, 255, 255, 100);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide grid ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide horizontal lines ?
|
||||
*
|
||||
* @param bool $hideHorizontal
|
||||
*/
|
||||
public function hideHorizontal($hide = TRUE) {
|
||||
$this->hideHorizontal = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide vertical lines ?
|
||||
*
|
||||
* @param bool $hideVertical
|
||||
*/
|
||||
public function hideVertical($hide = TRUE) {
|
||||
$this->hideVertical = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove grid background
|
||||
*/
|
||||
public function setNoBackground() {
|
||||
$this->background = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line type
|
||||
*
|
||||
* @param int $type
|
||||
*/
|
||||
public function setType($type) {
|
||||
$this->type = (int)$type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change grid interval
|
||||
*
|
||||
* @param int $hInterval
|
||||
* @param int $vInterval
|
||||
*/
|
||||
public function setInterval($hInterval, $vInterval) {
|
||||
$this->interval = array((int)$hInterval, (int)$vInterval);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set grid space
|
||||
*
|
||||
* @param int $left Left space in pixels
|
||||
* @param int $right Right space in pixels
|
||||
* @param int $top Top space in pixels
|
||||
* @param int $bottom Bottom space in pixels
|
||||
*/
|
||||
public function setSpace($left, $right, $top, $bottom) {
|
||||
$this->space = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the current grid
|
||||
*
|
||||
* @param array $xgrid Vertical lines
|
||||
* @param array $ygrid Horizontal lines
|
||||
*/
|
||||
public function setGrid($xgrid, $ygrid) {
|
||||
|
||||
$this->xgrid = $xgrid;
|
||||
$this->ygrid = $ygrid;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw grids
|
||||
*
|
||||
* @param awDrawer $drawer A drawer object
|
||||
* @param int $x1
|
||||
* @param int $y1
|
||||
* @param int $x2
|
||||
* @param int $y2
|
||||
*/
|
||||
public function draw(awDrawer $drawer, $x1, $y1, $x2, $y2) {
|
||||
|
||||
if($this->background instanceof awColor) {
|
||||
|
||||
// Draw background color
|
||||
$drawer->filledRectangle(
|
||||
$this->background,
|
||||
awLine::build($x1, $y1, $x2, $y2)
|
||||
);
|
||||
|
||||
$this->background->free();
|
||||
|
||||
}
|
||||
|
||||
if($this->hide === FALSE) {
|
||||
|
||||
$this->drawGrid(
|
||||
$drawer,
|
||||
$this->color,
|
||||
$this->hideVertical ? array() : $this->xgrid,
|
||||
$this->hideHorizontal ? array() : $this->ygrid,
|
||||
$x1, $y1, $x2, $y2,
|
||||
$this->type,
|
||||
$this->space,
|
||||
$this->interval[0],
|
||||
$this->interval[1]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
$this->color->free();
|
||||
|
||||
}
|
||||
|
||||
private function drawGrid(
|
||||
awDrawer $drawer, awColor $color,
|
||||
$nx, $ny, $x1, $y1, $x2, $y2,
|
||||
$type, $space, $hInterval, $vInterval
|
||||
) {
|
||||
|
||||
list($left, $right, $top, $bottom) = $space;
|
||||
|
||||
$width = $x2 - $x1 - $left - $right;
|
||||
$height = $y2 - $y1 - $top - $bottom;
|
||||
|
||||
foreach($nx as $key => $n) {
|
||||
|
||||
if(($key % $vInterval) === 0) {
|
||||
|
||||
$pos = (int)round($x1 + $left + $n * $width);
|
||||
$drawer->line(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($pos, $y1),
|
||||
new awPoint($pos, $y2),
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
foreach($ny as $key => $n) {
|
||||
|
||||
if(($key % $hInterval) === 0) {
|
||||
|
||||
$pos = (int)round($y1 + $top + $n * $height);
|
||||
$drawer->line(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($x1, $pos),
|
||||
new awPoint($x2, $pos),
|
||||
$type
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Grid');
|
||||
?>
|
||||
|
|
@ -1,596 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LABEL_LEFT", 1);
|
||||
define("LABEL_RIGHT", 2);
|
||||
define("LABEL_CENTER", 3);
|
||||
define("LABEL_TOP", 4);
|
||||
define("LABEL_BOTTOM", 5);
|
||||
define("LABEL_MIDDLE", 6);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Draw labels
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLabel implements awPositionable {
|
||||
|
||||
/**
|
||||
* Label border
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Label texts
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $texts;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $font;
|
||||
|
||||
/**
|
||||
* Text angle
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $angle = 0;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Text background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
private $background;
|
||||
|
||||
/**
|
||||
* Callback function
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $function;
|
||||
|
||||
/**
|
||||
* Padding
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $padding;
|
||||
|
||||
/**
|
||||
* Move position from this vector
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
protected $move;
|
||||
|
||||
/**
|
||||
* Label interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $interval = 1;
|
||||
|
||||
/**
|
||||
* Horizontal align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $hAlign = awLabel::CENTER;
|
||||
|
||||
/**
|
||||
* Vertical align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $vAlign = awLabel::MIDDLE;
|
||||
|
||||
/**
|
||||
* Hide all labels ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Keys to hide
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hideKey = array();
|
||||
|
||||
/**
|
||||
* Values to hide
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hideValue = array();
|
||||
|
||||
/**
|
||||
* Hide first label
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideFirst = FALSE;
|
||||
|
||||
/**
|
||||
* Hide last label
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideLast = FALSE;
|
||||
|
||||
/**
|
||||
* Build the label
|
||||
*
|
||||
* @param string $label First label
|
||||
*/
|
||||
public function __construct($label = NULL, $font = NULL, $color = NULL, $angle = 0) {
|
||||
|
||||
if(is_array($label)) {
|
||||
$this->set($label);
|
||||
} else if(is_string($label)) {
|
||||
$this->set(array($label));
|
||||
}
|
||||
|
||||
if($font === NULL) {
|
||||
$font = new awFont2;
|
||||
}
|
||||
|
||||
$this->setFont($font);
|
||||
$this->setAngle($angle);
|
||||
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
} else {
|
||||
$this->setColor(new awColor(0, 0, 0));
|
||||
}
|
||||
|
||||
$this->move = new awPoint(0, 0);
|
||||
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an element of the label from its key
|
||||
*
|
||||
* @param int $key Element key
|
||||
* @return string A value
|
||||
*/
|
||||
public function get($key) {
|
||||
return array_key_exists($key, $this->texts) ? $this->texts[$key] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all() {
|
||||
return $this->texts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set one or several labels
|
||||
*
|
||||
* @param array $labels Array of string or a string
|
||||
*/
|
||||
public function set($labels) {
|
||||
|
||||
if(is_string($labels)) {
|
||||
$this->texts = array($labels);
|
||||
} else if(is_array($labels)) {
|
||||
$this->texts = $labels;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of texts in the label
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return is_array($this->texts) ? count($this->texts) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a callback function for labels
|
||||
*
|
||||
* @param string $function
|
||||
*/
|
||||
public function setCallbackFunction($function) {
|
||||
$this->function = is_null($function) ? $function : (string)$function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the callback function for labels
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallbackFunction() {
|
||||
return $this->function;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change labels format
|
||||
*
|
||||
* @param string $format New format (printf style: %.2f for example)
|
||||
*/
|
||||
public function setFormat($format) {
|
||||
$function = 'label'.time().'_'.(microtime() * 1000000);
|
||||
eval('function '.$function.'($value) {
|
||||
return sprintf("'.addcslashes($format, '"').'", $value);
|
||||
}');
|
||||
$this->setCallbackFunction($function);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font for label
|
||||
*
|
||||
* @param awFont $font New font
|
||||
* @param awColor $color Font color (can be NULL)
|
||||
*/
|
||||
public function setFont(awFont $font, $color = NULL) {
|
||||
$this->font = $font;
|
||||
if($color instanceof awColor) {
|
||||
$this->setColor($color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font angle
|
||||
*
|
||||
* @param int $angle New angle
|
||||
*/
|
||||
public function setAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change font color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor($color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
public function setBackground($background) {
|
||||
$this->background = $background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background color
|
||||
*
|
||||
* @param Color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background gradient
|
||||
*
|
||||
* @param Gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change padding
|
||||
*
|
||||
* @param int $left Left padding
|
||||
* @param int $right Right padding
|
||||
* @param int $top Top padding
|
||||
* @param int $bottom Bottom padding
|
||||
*/
|
||||
public function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all labels ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all labels ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide a key
|
||||
*
|
||||
* @param int $key The key to hide
|
||||
*/
|
||||
public function hideKey($key) {
|
||||
$this->hideKey[$key] = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide a value
|
||||
*
|
||||
* @param int $value The value to hide
|
||||
*/
|
||||
public function hideValue($value) {
|
||||
$this->hideValue[] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide first label
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideFirst($hide) {
|
||||
$this->hideFirst = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide last label
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideLast($hide) {
|
||||
$this->hideLast = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set label interval
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
public function setInterval($interval) {
|
||||
|
||||
$this->interval = (int)$interval;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change label position
|
||||
*
|
||||
* @param int $x Add this interval to X coord
|
||||
* @param int $y Add this interval to Y coord
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
|
||||
$this->move = $this->move->move($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
public function setAlign($h = NULL, $v = NULL) {
|
||||
if($h !== NULL) {
|
||||
$this->hAlign = (int)$h;
|
||||
}
|
||||
if($v !== NULL) {
|
||||
$this->vAlign = (int)$v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a text from the labele
|
||||
*
|
||||
* @param mixed $key Key in the array text
|
||||
* @return Text
|
||||
*/
|
||||
public function getText($key) {
|
||||
|
||||
if(is_array($this->texts) and array_key_exists($key, $this->texts)) {
|
||||
|
||||
$value = $this->texts[$key];
|
||||
|
||||
if(is_string($this->function)) {
|
||||
$value = call_user_func($this->function, $value);
|
||||
}
|
||||
|
||||
$text = new awText($value);
|
||||
$text->setFont($this->font);
|
||||
$text->setAngle($this->angle);
|
||||
$text->setColor($this->color);
|
||||
|
||||
if($this->background instanceof awColor) {
|
||||
$text->setBackgroundColor($this->background);
|
||||
} else if($this->background instanceof awGradient) {
|
||||
$text->setBackgroundGradient($this->background);
|
||||
}
|
||||
|
||||
$text->border = $this->border;
|
||||
|
||||
if($this->padding !== NULL) {
|
||||
call_user_func_array(array($text, 'setPadding'), $this->padding);
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max width of all texts
|
||||
*
|
||||
* @param awDrawer $drawer A drawer
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxWidth(awDrawer $drawer) {
|
||||
|
||||
return $this->getMax($drawer, 'getTextWidth');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max height of all texts
|
||||
*
|
||||
* @param awDrawer $drawer A drawer
|
||||
* @return int
|
||||
*/
|
||||
public function getMaxHeight(awDrawer $drawer) {
|
||||
|
||||
return $this->getMax($drawer, 'getTextHeight');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the label
|
||||
*
|
||||
* @param awDrawer $drawer
|
||||
* @param awPoint $p Label center
|
||||
* @param int $key Text position in the array of texts (default to zero)
|
||||
*/
|
||||
public function draw(awDrawer $drawer, awPoint $p, $key = 0) {
|
||||
|
||||
if(($key % $this->interval) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide all labels
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Key is hidden
|
||||
if(array_key_exists($key, $this->hideKey)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide first label
|
||||
if($key === 0 and $this->hideFirst) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Hide last label
|
||||
if($key === count($this->texts) - 1 and $this->hideLast) {
|
||||
return;
|
||||
}
|
||||
|
||||
$text = $this->getText($key);
|
||||
|
||||
if($text !== NULL) {
|
||||
|
||||
// Value must be hidden
|
||||
if(in_array($text->getText(), $this->hideValue)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$x = $p->x;
|
||||
$y = $p->y;
|
||||
|
||||
// Get padding
|
||||
list($left, $right, $top, $bottom) = $text->getPadding();
|
||||
|
||||
$font = $text->getFont();
|
||||
$width = $font->getTextWidth($text);
|
||||
$height = $font->getTextHeight($text);
|
||||
|
||||
switch($this->hAlign) {
|
||||
|
||||
case awLabel::RIGHT :
|
||||
$x -= ($width + $right);
|
||||
break;
|
||||
|
||||
case awLabel::CENTER :
|
||||
$x -= ($width - $left + $right) / 2;
|
||||
break;
|
||||
|
||||
case awLabel::LEFT :
|
||||
$x += $left;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
switch($this->vAlign) {
|
||||
|
||||
case awLabel::TOP :
|
||||
$y -= ($height + $bottom);
|
||||
break;
|
||||
|
||||
case awLabel::MIDDLE :
|
||||
$y -= ($height - $top + $bottom) / 2;
|
||||
break;
|
||||
|
||||
case awLabel::BOTTOM :
|
||||
$y += $top;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$drawer->string($text, $this->move->move($x, $y));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getMax(awDrawer $drawer, $function) {
|
||||
|
||||
$max = NULL;
|
||||
|
||||
foreach($this->texts as $key => $text) {
|
||||
|
||||
$text = $this->getText($key);
|
||||
$font = $text->getFont();
|
||||
|
||||
if(is_null($max)) {
|
||||
$max = $font->{$function}($text);
|
||||
} else {
|
||||
$max = max($max, $font->{$function}($text));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $max;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Label');
|
||||
?>
|
||||
|
|
@ -1,728 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LEGEND_LINE", 1);
|
||||
define("LEGEND_BACKGROUND", 2);
|
||||
define("LEGEND_MARK", 3);
|
||||
define("LEGEND_MARKONLY", 4);
|
||||
|
||||
define("LEGEND_MODEL_RIGHT", 1);
|
||||
define("LEGEND_MODEL_BOTTOM", 2);
|
||||
|
||||
define("LEGEND_LEFT", 1);
|
||||
define("LEGEND_RIGHT", 2);
|
||||
define("LEGEND_CENTER", 3);
|
||||
define("LEGEND_TOP", 4);
|
||||
define("LEGEND_BOTTOM", 5);
|
||||
define("LEGEND_MIDDLE", 6);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Some legends
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLegend implements awPositionable {
|
||||
|
||||
/**
|
||||
* Legends added
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $legends = array();
|
||||
|
||||
/**
|
||||
* The current component
|
||||
*
|
||||
* @var Component
|
||||
*/
|
||||
protected $component;
|
||||
|
||||
/**
|
||||
* Background color or gradient
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $background;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $textColor;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var Font
|
||||
*/
|
||||
protected $textFont;
|
||||
|
||||
/**
|
||||
* Text margin
|
||||
*
|
||||
* @var Side
|
||||
*/
|
||||
protected $textMargin;
|
||||
|
||||
/**
|
||||
* Number of columns
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $columns = NULL;
|
||||
|
||||
/**
|
||||
* Number of rows
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $rows = NULL;
|
||||
|
||||
/**
|
||||
* Legend position
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* Hide legend ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Space between each legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $space = 4;
|
||||
|
||||
/**
|
||||
* Horizontal alignment
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $hAlign;
|
||||
|
||||
/**
|
||||
* Vertical alignment
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $vAlign;
|
||||
|
||||
/**
|
||||
* Margin
|
||||
*
|
||||
* @var array Array for left, right, top and bottom margins
|
||||
*/
|
||||
private $margin;
|
||||
|
||||
/**
|
||||
* Legend shadow
|
||||
*
|
||||
* @var Shadow
|
||||
*/
|
||||
public $shadow;
|
||||
|
||||
/**
|
||||
* Legend border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Line legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LINE = 1;
|
||||
|
||||
/**
|
||||
* Color/Gradient background legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const BACKGROUND = 2;
|
||||
|
||||
/**
|
||||
* Use marks and line as legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MARK = 3;
|
||||
|
||||
/**
|
||||
* Use marks as legend
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MARKONLY = 4;
|
||||
|
||||
/**
|
||||
* Right side model
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MODEL_RIGHT = 1;
|
||||
|
||||
/**
|
||||
* Bottom side model
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MODEL_BOTTOM = 2;
|
||||
|
||||
/**
|
||||
* Build the legend
|
||||
*
|
||||
* @param int $model Legend model
|
||||
*/
|
||||
public function __construct($model = awLegend::MODEL_RIGHT) {
|
||||
|
||||
$this->shadow = new awShadow(awShadow::LEFT_BOTTOM);
|
||||
$this->border = new awBorder;
|
||||
|
||||
$this->textMargin = new awSide(4);
|
||||
$this->setModel($model);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a predefined model for the legend
|
||||
*
|
||||
* @param int $model
|
||||
*/
|
||||
public function setModel($model) {
|
||||
|
||||
$this->setBackgroundColor(new awColor(255, 255, 255, 15));
|
||||
$this->setPadding(8, 8, 8, 8);
|
||||
$this->setTextFont(new awFont2);
|
||||
$this->shadow->setSize(3);
|
||||
|
||||
switch($model) {
|
||||
|
||||
case awLegend::MODEL_RIGHT :
|
||||
|
||||
$this->setColumns(1);
|
||||
$this->setAlign(awLegend::RIGHT, awLegend::MIDDLE);
|
||||
$this->setPosition(0.96, 0.50);
|
||||
|
||||
break;
|
||||
|
||||
case awLegend::MODEL_BOTTOM :
|
||||
|
||||
$this->setRows(1);
|
||||
$this->setAlign(awLegend::CENTER, awLegend::TOP);
|
||||
$this->setPosition(0.50, 0.92);
|
||||
|
||||
break;
|
||||
|
||||
default :
|
||||
|
||||
$this->setPosition(0.5, 0.5);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide legend ?
|
||||
*
|
||||
* @param bool $hide TRUE to hide legend, FALSE otherwise
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show legend ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a Legendable object to the legend
|
||||
*
|
||||
* @param awLegendable $legendable
|
||||
* @param string $title Legend title
|
||||
* @param int $type Legend type (default to awLegend::LINE)
|
||||
*/
|
||||
public function add(awLegendable $legendable, $title, $type = awLegend::LINE) {
|
||||
|
||||
$legend = array($legendable, $title, $type);
|
||||
|
||||
$this->legends[] = $legend;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend padding
|
||||
*
|
||||
* @param int $left
|
||||
* @param int $right
|
||||
* @param int $top
|
||||
* @param int $bottom
|
||||
*/
|
||||
public function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change space between each legend
|
||||
*
|
||||
* @param int $space
|
||||
*/
|
||||
public function setSpace($space) {
|
||||
$this->space = (int)$space;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
public function setAlign($h = NULL, $v = NULL) {
|
||||
if($h !== NULL) {
|
||||
$this->hAlign = (int)$h;
|
||||
}
|
||||
if($v !== NULL) {
|
||||
$this->vAlign = (int)$v;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of columns
|
||||
*
|
||||
* @param int $columns
|
||||
*/
|
||||
public function setColumns($columns) {
|
||||
$this->rows = NULL;
|
||||
$this->columns = (int)$columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of rows
|
||||
*
|
||||
* @param int $rows
|
||||
*/
|
||||
public function setRows($rows) {
|
||||
$this->columns = NULL;
|
||||
$this->rows = (int)$rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change legend position
|
||||
* X and Y positions must be between 0 and 1.
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
public function setPosition($x = NULL, $y = NULL) {
|
||||
$x = (is_null($x) and !is_null($this->position)) ? $this->position->x : $x;
|
||||
$y = (is_null($y) and !is_null($this->position)) ? $this->position->y : $y;
|
||||
|
||||
$this->position = new awPoint($x, $y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get legend position
|
||||
*
|
||||
* @return Point
|
||||
*/
|
||||
public function getPosition() {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text font
|
||||
*
|
||||
* @param awFont $font
|
||||
*/
|
||||
public function setTextFont(awFont $font) {
|
||||
$this->textFont = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text margin
|
||||
*
|
||||
* @param int $left
|
||||
* @param int $right
|
||||
*/
|
||||
public function setTextMargin($left, $right) {
|
||||
$this->textMargin->set($left, $right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setTextColor(awColor $color) {
|
||||
$this->textColor = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background
|
||||
*
|
||||
* @param mixed $background
|
||||
*/
|
||||
public function setBackground($background) {
|
||||
$this->background = $background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of Legendable objects in the legend
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count($this->legends);
|
||||
}
|
||||
|
||||
public function draw(awDrawer $drawer) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$count = $this->count();
|
||||
|
||||
// No legend to print
|
||||
if($count === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get text widths and heights of each element of the legend
|
||||
$widths = array();
|
||||
$heights = array();
|
||||
$texts = array();
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
list(, $title, ) = $this->legends[$i];
|
||||
$text = new awText(
|
||||
$title,
|
||||
$this->textFont,
|
||||
$this->textColor,
|
||||
0
|
||||
);
|
||||
$font = $text->getFont();
|
||||
$widths[$i] = $font->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right;
|
||||
$heights[$i] = $font->getTextHeight($text);
|
||||
$texts[$i] = $text;
|
||||
}
|
||||
|
||||
// Maximum height of the font used
|
||||
$heightMax = array_max($heights);
|
||||
|
||||
// Get number of columns
|
||||
if($this->columns !== NULL) {
|
||||
$columns = $this->columns;
|
||||
} else if($this->rows !== NULL) {
|
||||
$columns = ceil($count / $this->rows);
|
||||
} else {
|
||||
$columns = $count;
|
||||
}
|
||||
|
||||
// Number of rows
|
||||
$rows = (int)ceil($count / $columns);
|
||||
|
||||
// Get maximum with of each column
|
||||
$widthMax = array();
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
// Get column width
|
||||
$column = $i % $columns;
|
||||
if(array_key_exists($column, $widthMax) === FALSE) {
|
||||
$widthMax[$column] = $widths[$i];
|
||||
} else {
|
||||
$widthMax[$column] = max($widthMax[$column], $widths[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$width = $this->padding[0] + $this->padding[1] - $this->space;
|
||||
for($i = 0; $i < $columns; $i++) {
|
||||
$width += $this->space + 5 + 10 + $widthMax[$i];
|
||||
}
|
||||
|
||||
$height = ($heightMax + $this->space) * $rows - $this->space + $this->padding[2] + $this->padding[3];
|
||||
|
||||
// Look for legends position
|
||||
list($x, $y) = $drawer->getSize();
|
||||
|
||||
$p = new awPoint(
|
||||
$this->position->x * $x,
|
||||
$this->position->y * $y
|
||||
);
|
||||
|
||||
switch($this->hAlign) {
|
||||
|
||||
case awLegend::CENTER :
|
||||
$p->x -= $width / 2;
|
||||
break;
|
||||
|
||||
case awLegend::RIGHT :
|
||||
$p->x -= $width;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
switch($this->vAlign) {
|
||||
|
||||
case awLegend::MIDDLE :
|
||||
$p->y -= $height / 2;
|
||||
break;
|
||||
|
||||
case awLegend::BOTTOM :
|
||||
$p->y -= $height;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// Draw legend shadow
|
||||
$this->shadow->draw(
|
||||
$drawer,
|
||||
$p,
|
||||
$p->move($width, $height),
|
||||
awShadow::OUT
|
||||
);
|
||||
|
||||
// Draw legends base
|
||||
$this->drawBase($drawer, $p, $width, $height);
|
||||
|
||||
// Draw each legend
|
||||
for($i = 0; $i < $count; $i++) {
|
||||
|
||||
list($component, $title, $type) = $this->legends[$i];
|
||||
|
||||
$column = $i % $columns;
|
||||
$row = (int)floor($i / $columns);
|
||||
|
||||
// Get width of all previous columns
|
||||
$previousColumns = 0;
|
||||
for($j = 0; $j < $column; $j++) {
|
||||
$previousColumns += $this->space + 10 + 5 + $widthMax[$j];
|
||||
}
|
||||
|
||||
// Draw legend text
|
||||
$drawer->string(
|
||||
$texts[$i],
|
||||
$p->move(
|
||||
$this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left,
|
||||
$this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2
|
||||
)
|
||||
);
|
||||
|
||||
// Draw legend icon
|
||||
switch($type) {
|
||||
|
||||
case awLegend::LINE :
|
||||
case awLegend::MARK :
|
||||
case awLegend::MARKONLY :
|
||||
|
||||
// Get vertical position
|
||||
$x = $this->padding[0] + $previousColumns;
|
||||
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $component->getLegendLineThickness();
|
||||
|
||||
// Draw two lines
|
||||
if($component->getLegendLineColor() !== NULL) {
|
||||
|
||||
$color = $component->getLegendLineColor();
|
||||
|
||||
if($color instanceof awColor and $type !== awLegend::MARKONLY) {
|
||||
|
||||
$drawer->line(
|
||||
$color,
|
||||
new awLine(
|
||||
$p->move(
|
||||
$x, // YaPB ??
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
),
|
||||
$p->move(
|
||||
$x + 10,
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
),
|
||||
$component->getLegendLineStyle(),
|
||||
$component->getLegendLineThickness()
|
||||
)
|
||||
);
|
||||
|
||||
$color->free();
|
||||
unset($color);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($type === awLegend::MARK or $type === awLegend::MARKONLY) {
|
||||
|
||||
$mark = $component->getLegendMark();
|
||||
|
||||
if($mark !== NULL) {
|
||||
$mark->draw(
|
||||
$drawer,
|
||||
$p->move(
|
||||
$x + 5.5,
|
||||
$y + $component->getLegendLineThickness() / 2
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
unset($mark);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case awLegend::BACKGROUND :
|
||||
|
||||
// Get vertical position
|
||||
$x = $this->padding[0] + $previousColumns;
|
||||
$y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - 5;
|
||||
|
||||
$from = $p->move(
|
||||
$x,
|
||||
$y
|
||||
);
|
||||
|
||||
$to = $p->move(
|
||||
$x + 10,
|
||||
$y + 10
|
||||
);
|
||||
|
||||
$background = $component->getLegendBackground();
|
||||
|
||||
if($background !== NULL) {
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$component->getLegendBackground(),
|
||||
new awLine($from, $to)
|
||||
);
|
||||
|
||||
// Draw rectangle border
|
||||
$this->border->rectangle(
|
||||
$drawer,
|
||||
$from->move(0, 0),
|
||||
$to->move(0, 0)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
unset($background, $from, $to);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function drawBase(awDrawer $drawer, awPoint $p, $width, $height) {
|
||||
|
||||
$this->border->rectangle(
|
||||
$drawer,
|
||||
$p,
|
||||
$p->move($width, $height)
|
||||
);
|
||||
|
||||
$size = $this->border->visible() ? 1 : 0;
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$this->background,
|
||||
new awLine(
|
||||
$p->move($size, $size),
|
||||
$p->move($width - $size, $height - $size)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Legend');
|
||||
|
||||
/**
|
||||
* You can add a legend to components which implements this interface
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
interface awLegendable {
|
||||
|
||||
/**
|
||||
* Get the line type
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineStyle();
|
||||
|
||||
/**
|
||||
* Get the line thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getLegendLineThickness();
|
||||
|
||||
/**
|
||||
* Get the color of line
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getLegendLineColor();
|
||||
|
||||
/**
|
||||
* Get the background color or gradient of an element of the component
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getLegendBackground();
|
||||
|
||||
/**
|
||||
* Get a Mark object
|
||||
*
|
||||
* @return Mark
|
||||
*/
|
||||
public function getLegendMark();
|
||||
|
||||
}
|
||||
|
||||
registerInterface('Legendable');
|
||||
?>
|
||||
|
|
@ -1,335 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("MARK_CIRCLE", 1);
|
||||
define("MARK_SQUARE", 2);
|
||||
define("MARK_IMAGE", 3);
|
||||
define("MARK_STAR", 4);
|
||||
define("MARK_PAPERCLIP", 5);
|
||||
define("MARK_BOOK", 6);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Draw marks
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awMark {
|
||||
|
||||
/**
|
||||
* Circle mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CIRCLE = 1;
|
||||
|
||||
/**
|
||||
* Quare mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const SQUARE = 2;
|
||||
|
||||
/**
|
||||
* Image mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const IMAGE = 3;
|
||||
|
||||
/**
|
||||
* Star mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const STAR = 4;
|
||||
|
||||
/**
|
||||
* Paperclip mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const PAPERCLIP = 5;
|
||||
|
||||
/**
|
||||
* Book mark
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const BOOK = 6;
|
||||
|
||||
/**
|
||||
* Must marks be hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide;
|
||||
|
||||
/**
|
||||
* Mark type
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Mark size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size = 8;
|
||||
|
||||
/**
|
||||
* Fill mark
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
protected $fill;
|
||||
|
||||
/**
|
||||
* Mark image
|
||||
*
|
||||
* @var Image
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* To draw marks
|
||||
*
|
||||
* @var Drawer
|
||||
*/
|
||||
protected $drawer;
|
||||
|
||||
/**
|
||||
* Move position from this vector
|
||||
*
|
||||
* @var Point
|
||||
*/
|
||||
protected $move;
|
||||
|
||||
/**
|
||||
* Marks border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Build the mark
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->fill = new awColor(255, 0, 0, 0);
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
$this->move = new awPoint(0, 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark position
|
||||
*
|
||||
* @param int $x Add this interval to X coord
|
||||
* @param int $y Add this interval to Y coord
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
|
||||
$this->move = $this->move->move($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide marks ?
|
||||
*
|
||||
* @param bool $hide TRUE to hide marks, FALSE otherwise
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show marks ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark type
|
||||
*
|
||||
* @param int $size Size in pixels
|
||||
*/
|
||||
public function setSize($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change mark type
|
||||
*
|
||||
* @param int $type New mark type
|
||||
* @param int $size Mark size (can be NULL)
|
||||
*/
|
||||
public function setType($type, $size = NULL) {
|
||||
$this->type = (int)$type;
|
||||
if($size !== NULL) {
|
||||
$this->setSize($size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill the mark with a color or a gradient
|
||||
*
|
||||
* @param mixed $fill A color or a gradient
|
||||
*/
|
||||
public function setFill($fill) {
|
||||
if($fill instanceof awColor or $fill instanceof awGradient) {
|
||||
$this->fill = $fill;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an image
|
||||
* Only for awMark::IMAGE type.
|
||||
*
|
||||
* @param Image An image
|
||||
*/
|
||||
public function setImage(awImage $image) {
|
||||
$this->image = $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the mark
|
||||
*
|
||||
* @param awDrawer $drawer
|
||||
* @param awPoint $point Mark center
|
||||
*/
|
||||
public function draw(awDrawer $drawer, awPoint $point) {
|
||||
|
||||
// Hide marks ?
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we can print marks
|
||||
if($this->type !== NULL) {
|
||||
|
||||
$this->drawer = $drawer;
|
||||
$realPoint = $this->move->move($point->x, $point->y);
|
||||
|
||||
switch($this->type) {
|
||||
|
||||
case awMark::CIRCLE :
|
||||
$this->drawCircle($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::SQUARE :
|
||||
$this->drawSquare($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::IMAGE :
|
||||
$this->drawImage($realPoint);
|
||||
break;
|
||||
|
||||
case awMark::STAR :
|
||||
$this->changeType('star');
|
||||
$this->draw($drawer, $point);
|
||||
break;
|
||||
|
||||
case awMark::PAPERCLIP :
|
||||
$this->changeType('paperclip');
|
||||
$this->draw($drawer, $point);
|
||||
break;
|
||||
|
||||
case awMark::BOOK :
|
||||
$this->changeType('book');
|
||||
$this->draw($drawer, $point);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function changeType($image) {
|
||||
$this->setType(awMARK::IMAGE);
|
||||
$this->setImage(new awFileImage(ARTICHOW_IMAGE.DIRECTORY_SEPARATOR.$image.'.png'));
|
||||
}
|
||||
|
||||
protected function drawCircle(awPoint $point) {
|
||||
|
||||
$this->drawer->filledEllipse(
|
||||
$this->fill,
|
||||
$point,
|
||||
$this->size, $this->size
|
||||
);
|
||||
|
||||
$this->border->ellipse(
|
||||
$this->drawer,
|
||||
$point,
|
||||
$this->size, $this->size
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function drawSquare(awPoint $point) {
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$x1 = (int)($x - $this->size / 2);
|
||||
$x2 = $x1 + $this->size;
|
||||
$y1 = (int)($y - $this->size / 2);
|
||||
$y2 = $y1 + $this->size;
|
||||
|
||||
$this->border->rectangle($this->drawer, new awPoint($x1, $y1), new awPoint($x2, $y2));
|
||||
|
||||
$size = $this->border->visible() ? 1 : 0;
|
||||
|
||||
$this->drawer->filledRectangle(
|
||||
$this->fill,
|
||||
new awLine(
|
||||
new awPoint($x1 + $size, $y1 + $size),
|
||||
new awPoint($x2 - $size, $y2 - $size)
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected function drawImage(awPoint $point) {
|
||||
|
||||
if($this->image instanceof awImage) {
|
||||
|
||||
$width = $this->image->width;
|
||||
$height = $this->image->height;
|
||||
|
||||
list($x, $y) = $point->getLocation();
|
||||
|
||||
$x1 = (int)($x - $width / 2);
|
||||
$x2 = $x1 + $width;
|
||||
$y1 = (int)($y - $width / 2);
|
||||
$y2 = $y1 + $height;
|
||||
|
||||
$this->border->rectangle($this->drawer, new awPoint($x1 - 1, $y1 - 1), new awPoint($x2 + 1, $y2 + 1));
|
||||
|
||||
$this->drawer->copyImage($this->image, new awPoint($x1, $y1), new awPoint($x2, $y2));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Mark');
|
||||
?>
|
||||
|
|
@ -1,492 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
abstract class awShape {
|
||||
|
||||
/**
|
||||
* Is the shape hidden ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Shape style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $style;
|
||||
|
||||
/**
|
||||
* Shape thickness
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $thickness;
|
||||
|
||||
/**
|
||||
* Solid shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const SOLID = 1;
|
||||
|
||||
/**
|
||||
* Dotted shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DOTTED = 2;
|
||||
|
||||
/**
|
||||
* Dashed shape
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const DASHED = 3;
|
||||
|
||||
/**
|
||||
* Change shape style
|
||||
*
|
||||
* @param int $style Line style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return shape style
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStyle() {
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shape thickness
|
||||
*
|
||||
* @param int $thickness Shape thickness in pixels
|
||||
*/
|
||||
public function setThickness($thickness) {
|
||||
$this->thickness = (int)$thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return shape thickness
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getThickness() {
|
||||
return $this->thickness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide the shape
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the shape
|
||||
*
|
||||
* @param bool $shape
|
||||
*/
|
||||
public function show($shape) {
|
||||
$this->hide = (bool)!$shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the line hidden ?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHidden() {
|
||||
return $this->hide;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Shape', TRUE);
|
||||
|
||||
/**
|
||||
* Describe a point
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPoint extends awShape {
|
||||
|
||||
/**
|
||||
* X coord
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $x;
|
||||
|
||||
/**
|
||||
* Y coord
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
public $y;
|
||||
|
||||
/**
|
||||
* Build a new awpoint
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
public function __construct($x, $y) {
|
||||
|
||||
$this->setLocation($x, $y);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change X value
|
||||
*
|
||||
* @param float $x
|
||||
*/
|
||||
public function setX($x) {
|
||||
$this->x = (float)$x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Y value
|
||||
*
|
||||
* @param float $y
|
||||
*/
|
||||
public function setY($y) {
|
||||
$this->y = (float)$y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change point location
|
||||
*
|
||||
* @param float $x
|
||||
* @param float $y
|
||||
*/
|
||||
public function setLocation($x, $y) {
|
||||
$this->setX($x);
|
||||
$this->setY($y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get point location
|
||||
*
|
||||
* @param array Point location
|
||||
*/
|
||||
public function getLocation() {
|
||||
return array($this->x, $this->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get distance to another point
|
||||
*
|
||||
* @param awPoint $p A point
|
||||
* @return float
|
||||
*/
|
||||
public function getDistance(awPoint $p) {
|
||||
|
||||
return sqrt(pow($p->x - $this->x, 2) + pow($p->y - $this->y, 2));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the point to another location
|
||||
*
|
||||
* @param Point A Point with the new awlocation
|
||||
*/
|
||||
public function move($x, $y) {
|
||||
|
||||
return new awPoint(
|
||||
$this->x + $x,
|
||||
$this->y + $y
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Point');
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("LINE_SOLID", 1);
|
||||
define("LINE_DOTTED", 2);
|
||||
define("LINE_DASHED", 3);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Describe a line
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awLine extends awShape {
|
||||
|
||||
/**
|
||||
* Line first point
|
||||
*
|
||||
* @param Point
|
||||
*/
|
||||
public $p1;
|
||||
|
||||
/**
|
||||
* Line second point
|
||||
*
|
||||
* @param Point
|
||||
*/
|
||||
public $p2;
|
||||
|
||||
/**
|
||||
* Build a new awline
|
||||
*
|
||||
* @param awPoint $p1 First point
|
||||
* @param awPoint $p2 Second point
|
||||
* @param int $type Style of line (default to solid)
|
||||
* @param int $thickness Line thickness (default to 1)
|
||||
*/
|
||||
public function __construct($p1 = NULL, $p2 = NULL, $type = awLine::SOLID, $thickness = 1) {
|
||||
|
||||
$this->setLocation($p1, $p2);
|
||||
$this->setStyle($type);
|
||||
$this->setThickness($thickness);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a line from 4 coords
|
||||
*
|
||||
* @param int $x1 Left position
|
||||
* @param int $y1 Top position
|
||||
* @param int $x2 Right position
|
||||
* @param int $y2 Bottom position
|
||||
*/
|
||||
public static function build($x1, $y1, $x2, $y2) {
|
||||
|
||||
return new awLine(
|
||||
new awPoint($x1, $y1),
|
||||
new awPoint($x2, $y2)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change X values of the line
|
||||
*
|
||||
* @param int $x1 Begin value
|
||||
* @param int $x2 End value
|
||||
*/
|
||||
public function setX($x1, $x2) {
|
||||
$this->p1->setX($x1);
|
||||
$this->p2->setX($x2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change Y values of the line
|
||||
*
|
||||
* @param int $y1 Begin value
|
||||
* @param int $y2 End value
|
||||
*/
|
||||
public function setY($y1, $y2) {
|
||||
$this->p1->setY($y1);
|
||||
$this->p2->setY($y2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change line location
|
||||
*
|
||||
* @param awPoint $p1 First point
|
||||
* @param awPoint $p2 Second point
|
||||
*/
|
||||
public function setLocation($p1, $p2) {
|
||||
if(is_null($p1) or $p1 instanceof awPoint) {
|
||||
$this->p1 = $p1;
|
||||
}
|
||||
if(is_null($p2) or $p2 instanceof awPoint) {
|
||||
$this->p2 = $p2;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line location
|
||||
*
|
||||
* @param array Line location
|
||||
*/
|
||||
public function getLocation() {
|
||||
return array($this->p1, $this->p2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line size
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getSize() {
|
||||
|
||||
$square = pow($this->p2->x - $this->p1->x, 2) + pow($this->p2->y - $this->p1->y, 2);
|
||||
return sqrt($square);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line can be considered as a point
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPoint() {
|
||||
return ($this->p1->x === $this->p2->x and $this->p1->y === $this->p2->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line is a vertical line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isVertical() {
|
||||
return ($this->p1->x === $this->p2->x);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the line is an horizontal line
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHorizontal() {
|
||||
return ($this->p1->y === $this->p2->y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Line');
|
||||
|
||||
/**
|
||||
* A vector is a type of line
|
||||
* The sense of the vector goes from $p1 to $p2.
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awVector extends awLine {
|
||||
|
||||
/**
|
||||
* Get vector angle in radians
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getAngle() {
|
||||
|
||||
if($this->isPoint()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
$size = $this->getSize();
|
||||
|
||||
$width = ($this->p2->x - $this->p1->x);
|
||||
$height = ($this->p2->y - $this->p1->y) * -1;
|
||||
|
||||
if($width >= 0 and $height >= 0) {
|
||||
return acos($width / $size);
|
||||
} else if($width <= 0 and $height >= 0) {
|
||||
return acos($width / $size);
|
||||
} else {
|
||||
$height *= -1;
|
||||
if($width >= 0 and $height >= 0) {
|
||||
return 2 * M_PI - acos($width / $size);
|
||||
} else if($width <= 0 and $height >= 0) {
|
||||
return 2 * M_PI - acos($width / $size);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Vector');
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("POLYGON_SOLID", 1);
|
||||
define("POLYGON_DOTTED", 2);
|
||||
define("POLYGON_DASHED", 3);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Describe a polygon
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awPolygon extends awShape {
|
||||
|
||||
/**
|
||||
* Polygon points
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $points = array();
|
||||
|
||||
/**
|
||||
* Set a point in the polygon
|
||||
*
|
||||
* @param int $pos Point position
|
||||
* @param awPoint $point
|
||||
*/
|
||||
public function set($pos, $point) {
|
||||
if(is_null($point) or $point instanceof awPoint) {
|
||||
$this->points[$pos] = $point;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point at the end of the polygon
|
||||
*
|
||||
* @param awPoint $point
|
||||
*/
|
||||
public function append($point) {
|
||||
if(is_null($point) or $point instanceof awPoint) {
|
||||
$this->points[] = $point;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point at a position in the polygon
|
||||
*
|
||||
* @param int $pos Point position
|
||||
* @return Point
|
||||
*/
|
||||
public function get($pos) {
|
||||
return $this->points[$pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* Count number of points in the polygon
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function count() {
|
||||
return count($this->points);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all points in the polygon
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function all() {
|
||||
return $this->points;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Polygon');
|
||||
?>
|
||||
|
|
@ -1,415 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("SHADOW_LEFT_TOP", 1);
|
||||
define("SHADOW_LEFT_BOTTOM", 2);
|
||||
define("SHADOW_RIGHT_TOP", 3);
|
||||
define("SHADOW_RIGHT_BOTTOM", 4);
|
||||
|
||||
define("SHADOW_IN", 1);
|
||||
define("SHADOW_OUT", 2);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Draw shadows
|
||||
*
|
||||
*/
|
||||
class awShadow {
|
||||
|
||||
/**
|
||||
* Shadow on left and top sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LEFT_TOP = 1;
|
||||
|
||||
/**
|
||||
* Shadow on left and bottom sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LEFT_BOTTOM = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Shadow on right and top sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RIGHT_TOP = 3;
|
||||
|
||||
/**
|
||||
* Shadow on right and bottom sides
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RIGHT_BOTTOM = 4;
|
||||
|
||||
/**
|
||||
* In mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const IN = 1;
|
||||
|
||||
/**
|
||||
* Out mode
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const OUT = 2;
|
||||
|
||||
/**
|
||||
* Shadow size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $size = 0;
|
||||
|
||||
/**
|
||||
* Hide shadow ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Shadow color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Shadow position
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $position;
|
||||
|
||||
/**
|
||||
* Smooth shadow ?
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $smooth = FALSE;
|
||||
|
||||
/**
|
||||
* Shadow constructor
|
||||
*
|
||||
* @param int $position Shadow position
|
||||
*/
|
||||
public function __construct($position) {
|
||||
$this->setPosition($position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide shadow ?
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide = TRUE) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show shadow ?
|
||||
*
|
||||
* @param bool $show
|
||||
*/
|
||||
public function show($show = TRUE) {
|
||||
$this->hide = (bool)!$show;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow size
|
||||
*
|
||||
* @param int $size
|
||||
* @param bool $smooth Smooth the shadow (facultative argument)
|
||||
*/
|
||||
public function setSize($size, $smooth = NULL) {
|
||||
$this->size = (int)$size;
|
||||
if($smooth !== NULL) {
|
||||
$this->smooth($smooth);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change shadow position
|
||||
*
|
||||
* @param int $position
|
||||
*/
|
||||
public function setPosition($position) {
|
||||
$this->position = (int)$position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smooth shadow ?
|
||||
*
|
||||
* @param bool $smooth
|
||||
*/
|
||||
public function smooth($smooth) {
|
||||
$this->smooth = (bool)$smooth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the space taken by the shadow
|
||||
*
|
||||
* @return Side
|
||||
*/
|
||||
public function getSpace() {
|
||||
|
||||
return new awSide(
|
||||
($this->position === awShadow::LEFT_TOP or $this->position === awShadow::LEFT_BOTTOM) ? $this->size : 0,
|
||||
($this->position === awShadow::RIGHT_TOP or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0,
|
||||
($this->position === awShadow::LEFT_TOP or $this->position === awShadow::RIGHT_TOP) ? $this->size : 0,
|
||||
($this->position === awShadow::LEFT_BOTTOM or $this->position === awShadow::RIGHT_BOTTOM) ? $this->size : 0
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw shadow
|
||||
*
|
||||
* @param awDrawer $drawer
|
||||
* @param awPoint $p1 Top-left point
|
||||
* @param awPoint $p2 Right-bottom point
|
||||
* @param int Drawing mode
|
||||
*/
|
||||
public function draw(awDrawer $drawer, awPoint $p1, awPoint $p2, $mode) {
|
||||
|
||||
if($this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
if($this->size <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$drawer = clone $drawer;
|
||||
|
||||
$color = ($this->color instanceof awColor) ? $this->color : new awColor(125, 125, 125);
|
||||
|
||||
switch($this->position) {
|
||||
|
||||
case awShadow::RIGHT_BOTTOM :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move($this->size + 1, $this->size + 1);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($width - $this->size, $this->size),
|
||||
new awPoint($width - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, $height - $this->size),
|
||||
new awPoint($width - $this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothPast($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case awShadow::LEFT_TOP :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(- $this->size, - $this->size);
|
||||
$t2 = $p2->move(0, 0);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$height = max($height + 1, $this->size);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint(0, 0),
|
||||
new awPoint($this->size - 1, $height - $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, 0),
|
||||
new awPoint($width - $this->size - 1, $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothPast($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case awShadow::RIGHT_TOP :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(0, - $this->size);
|
||||
$t2 = $p2->move($this->size + 1, 0);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$height = max($height + 1, $this->size);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($width - $this->size, 0),
|
||||
new awPoint($width - 1, $height - $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, 0),
|
||||
new awPoint($width - $this->size - 1, $this->size - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothFuture($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
case awShadow::LEFT_BOTTOM :
|
||||
|
||||
if($mode === awShadow::OUT) {
|
||||
$t1 = $p1->move(- $this->size, 0);
|
||||
$t2 = $p2->move(0, $this->size + 1);
|
||||
} else { // PHP 4 compatibility
|
||||
$t1 = $p1->move(0, 0);
|
||||
$t2 = $p2->move(0, 0);
|
||||
}
|
||||
|
||||
$width = $t2->x - $t1->x;
|
||||
$height = $t2->y - $t1->y;
|
||||
|
||||
$drawer->setAbsPosition($t1->x + $drawer->x, $t1->y + $drawer->y);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint(0, $this->size),
|
||||
new awPoint($this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$drawer->filledRectangle(
|
||||
$color,
|
||||
new awLine(
|
||||
new awPoint($this->size, $height - $this->size),
|
||||
new awPoint($width - $this->size - 1, $height - 1)
|
||||
)
|
||||
);
|
||||
|
||||
$this->smoothFuture($drawer, $color, $width, $height);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function smoothPast(awDrawer $drawer, awColor $color, $width, $height) {
|
||||
|
||||
if($this->smooth) {
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($i, $j + $height - $this->size)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($width - $this->size + $j, $i)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function smoothFuture(awDrawer $drawer, awColor $color, $width, $height) {
|
||||
|
||||
if($this->smooth) {
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($i, $this->size - $j - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < $this->size; $i++) {
|
||||
for($j = 0; $j <= $i; $j++) {
|
||||
$drawer->point(
|
||||
$color,
|
||||
new awPoint($width - $this->size + $j, $height - $i - 1)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Shadow');
|
||||
?>
|
||||
|
|
@ -1,217 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* To handle text
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awText {
|
||||
|
||||
/**
|
||||
* Your text
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $text;
|
||||
|
||||
/**
|
||||
* Text font
|
||||
*
|
||||
* @var Font
|
||||
*/
|
||||
private $font;
|
||||
|
||||
/**
|
||||
* Text angle
|
||||
* Can be 0 or 90
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $angle;
|
||||
|
||||
/**
|
||||
* Text color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
private $color;
|
||||
|
||||
/**
|
||||
* Text background
|
||||
*
|
||||
* @var Color, Gradient
|
||||
*/
|
||||
private $background;
|
||||
|
||||
/**
|
||||
* Padding
|
||||
*
|
||||
* @var array Array for left, right, top and bottom paddings
|
||||
*/
|
||||
private $padding;
|
||||
|
||||
/**
|
||||
* Text border
|
||||
*
|
||||
* @var Border
|
||||
*/
|
||||
public $border;
|
||||
|
||||
/**
|
||||
* Build a new awtext
|
||||
*
|
||||
* @param string $text Your text
|
||||
*/
|
||||
public function __construct($text, $font = NULL, $color = NULL, $angle = 0) {
|
||||
|
||||
if(is_null($font)) {
|
||||
$font = new awFont2;
|
||||
}
|
||||
|
||||
$this->setText($text);
|
||||
$this->setFont($font);
|
||||
|
||||
// Set default color to black
|
||||
if($color === NULL) {
|
||||
$color = new awColor(0, 0, 0);
|
||||
}
|
||||
|
||||
$this->setColor($color);
|
||||
$this->setAngle($angle);
|
||||
|
||||
$this->border = new awBorder;
|
||||
$this->border->hide();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getText() {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text
|
||||
*
|
||||
* @param string $text New text
|
||||
*/
|
||||
public function setText($text) {
|
||||
$this->text = (string)$text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text font
|
||||
*
|
||||
* @param Font
|
||||
*/
|
||||
public function setFont(awFont $font) {
|
||||
$this->font = $font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text font
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFont() {
|
||||
return $this->font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text angle
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
public function setAngle($angle) {
|
||||
$this->angle = (int)$angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text angle
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAngle() {
|
||||
return $this->angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text color
|
||||
*
|
||||
* @param Color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text color
|
||||
*
|
||||
* @return Color
|
||||
*/
|
||||
public function getColor() {
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setBackgroundColor(awColor $color) {
|
||||
$this->background = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change text background gradient
|
||||
*
|
||||
* @param awGradient $gradient
|
||||
*/
|
||||
public function setBackgroundGradient(awGradient $gradient) {
|
||||
$this->background = $gradient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text background
|
||||
*
|
||||
* @return Color, Gradient
|
||||
*/
|
||||
public function getBackground() {
|
||||
return $this->background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change padding
|
||||
*
|
||||
* @param int $left Left padding
|
||||
* @param int $right Right padding
|
||||
* @param int $top Top padding
|
||||
* @param int $bottom Bottom padding
|
||||
*/
|
||||
public function setPadding($left, $right, $top, $bottom) {
|
||||
$this->padding = array((int)$left, (int)$right, (int)$top, (int)$bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current padding
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPadding() {
|
||||
return $this->padding;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Text');
|
||||
?>
|
||||
|
|
@ -1,352 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/* <php4> */
|
||||
|
||||
define("TICK_IN", 0);
|
||||
define("TICK_OUT", 1);
|
||||
define("TICK_IN_OUT", 2);
|
||||
|
||||
/* </php4> */
|
||||
|
||||
/**
|
||||
* Handle ticks
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awTick {
|
||||
|
||||
/**
|
||||
* Ticks style
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $style = awTick::IN;
|
||||
|
||||
/**
|
||||
* Ticks size
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $size;
|
||||
|
||||
/**
|
||||
* Ticks color
|
||||
*
|
||||
* @var Color
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
* Ticks number
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $number;
|
||||
|
||||
/**
|
||||
* Ticks number by other tick
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $numberByTick;
|
||||
|
||||
/**
|
||||
* Ticks interval
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $interval = 1;
|
||||
|
||||
/**
|
||||
* Hide ticks
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hide = FALSE;
|
||||
|
||||
/**
|
||||
* Hide first tick
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideFirst = FALSE;
|
||||
|
||||
/**
|
||||
* Hide last tick
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $hideLast = FALSE;
|
||||
|
||||
/**
|
||||
* In mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
const IN = 0;
|
||||
|
||||
/**
|
||||
* Out mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
const OUT = 1;
|
||||
|
||||
/**
|
||||
* In and out mode
|
||||
*
|
||||
* @param int
|
||||
*/
|
||||
const IN_OUT = 2;
|
||||
|
||||
/**
|
||||
* Build the ticks
|
||||
*
|
||||
* @param int $number Number of ticks
|
||||
* @param int $size Ticks size
|
||||
*/
|
||||
public function __construct($number, $size) {
|
||||
|
||||
$this->setSize($size);
|
||||
$this->setNumber($number);
|
||||
$this->setColor(new awBlack);
|
||||
$this->style = awTick::IN;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks style
|
||||
*
|
||||
* @param int $style
|
||||
*/
|
||||
public function setStyle($style) {
|
||||
$this->style = (int)$style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ticks style
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getStyle() {
|
||||
return $this->style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks color
|
||||
*
|
||||
* @param awColor $color
|
||||
*/
|
||||
public function setColor(awColor $color) {
|
||||
$this->color = $color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change ticks size
|
||||
*
|
||||
* @param int $size
|
||||
*/
|
||||
public function setSize($size) {
|
||||
$this->size = (int)$size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change interval of ticks
|
||||
*
|
||||
* @param int $interval
|
||||
*/
|
||||
public function setInterval($interval) {
|
||||
$this->interval = (int)$interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interval between each tick
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getInterval() {
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks
|
||||
*
|
||||
* @param int $number
|
||||
*/
|
||||
public function setNumber($number) {
|
||||
$this->number = (int)$number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of ticks
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNumber() {
|
||||
return $this->number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change number of ticks relative to others ticks
|
||||
*
|
||||
* @param awTick $tick Ticks reference
|
||||
* @param int $number Number of ticks
|
||||
*/
|
||||
public function setNumberByTick(awTick $tick, $number) {
|
||||
/* <php5> */
|
||||
$this->numberByTick = array($tick, (int)$number);
|
||||
/* </php5> */
|
||||
/* <php4> --
|
||||
$this->numberByTick = array(&$tick, (int)$number);
|
||||
-- </php4> */
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide ticks
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hide($hide) {
|
||||
$this->hide = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide first tick
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideFirst($hide) {
|
||||
$this->hideFirst = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide last tick
|
||||
*
|
||||
* @param bool $hide
|
||||
*/
|
||||
public function hideLast($hide) {
|
||||
$this->hideLast = (bool)$hide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw ticks on a vector
|
||||
*
|
||||
* @param awDrawer $drawer A drawer
|
||||
* @param awVector $vector A vector
|
||||
*/
|
||||
public function draw(awDrawer $drawer, awVector $vector) {
|
||||
|
||||
if($this->numberByTick !== NULL) {
|
||||
list($tick, $number) = $this->numberByTick;
|
||||
$this->number = 1 + ($tick->getNumber() - 1) * ($number + 1);
|
||||
$this->interval = $tick->getInterval();
|
||||
}
|
||||
|
||||
if($this->number < 2 or $this->hide) {
|
||||
return;
|
||||
}
|
||||
|
||||
$angle = $vector->getAngle();
|
||||
// echo "INIT:".$angle."<br>";
|
||||
switch($this->style) {
|
||||
|
||||
case awTick::IN :
|
||||
$this->drawTicks($drawer, $vector, NULL, $angle + M_PI / 2);
|
||||
break;
|
||||
|
||||
case awTick::OUT :
|
||||
$this->drawTicks($drawer, $vector, $angle + 3 * M_PI / 2, NULL);
|
||||
break;
|
||||
|
||||
default :
|
||||
$this->drawTicks($drawer, $vector, $angle + M_PI / 2, $angle + 3 * M_PI / 2);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function drawTicks(awDrawer $drawer, awVector $vector, $from, $to) {
|
||||
|
||||
// Draw last tick
|
||||
if($this->hideLast === FALSE) {
|
||||
|
||||
//echo '<b>';
|
||||
if(($this->number - 1) % $this->interval === 0) {
|
||||
$this->drawTick($drawer, $vector->p2, $from, $to);
|
||||
}
|
||||
//echo '</b>';
|
||||
|
||||
}
|
||||
|
||||
$number = $this->number - 1;
|
||||
$size = $vector->getSize();
|
||||
|
||||
// Get tick increment in pixels
|
||||
$inc = $size / $number;
|
||||
|
||||
// Check if we must hide the first tick
|
||||
$start = $this->hideFirst ? $inc : 0;
|
||||
$stop = $inc * $number;
|
||||
|
||||
$position = 0;
|
||||
|
||||
for($i = $start; round($i, 6) < $stop; $i += $inc) {
|
||||
|
||||
if($position % $this->interval === 0) {
|
||||
$p = $vector->p1->move(
|
||||
round($i * cos($vector->getAngle()), 6),
|
||||
round($i * sin($vector->getAngle() * -1), 6)
|
||||
);
|
||||
$this->drawTick($drawer, $p, $from, $to);
|
||||
}
|
||||
|
||||
$position++;
|
||||
|
||||
}
|
||||
//echo '<br><br>';
|
||||
}
|
||||
|
||||
protected function drawTick(awDrawer $drawer, awPoint $p, $from, $to) {
|
||||
// echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/';
|
||||
// The round avoid some errors in the calcul
|
||||
// For example, 12.00000008575245 becomes 12
|
||||
$p1 = $p;
|
||||
$p2 = $p;
|
||||
|
||||
if($from !== NULL) {
|
||||
$p1 = $p1->move(
|
||||
round($this->size * cos($from), 6),
|
||||
round($this->size * sin($from) * -1, 6)
|
||||
);
|
||||
}
|
||||
|
||||
if($to !== NULL) {
|
||||
$p2 = $p2->move(
|
||||
round($this->size * cos($to), 6),
|
||||
round($this->size * sin($to) * -1, 6)
|
||||
);
|
||||
}
|
||||
//echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/';
|
||||
$vector = new awVector(
|
||||
$p1, $p2
|
||||
);
|
||||
|
||||
$drawer->line(
|
||||
$this->color,
|
||||
$vector
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Tick');
|
||||
?>
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This work is hereby released into the Public Domain.
|
||||
* To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Objects capable of being positioned
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
interface awPositionable {
|
||||
|
||||
/**
|
||||
* Left align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const LEFT = 1;
|
||||
|
||||
/**
|
||||
* Right align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const RIGHT = 2;
|
||||
|
||||
/**
|
||||
* Center align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const CENTER = 3;
|
||||
|
||||
/**
|
||||
* Top align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const TOP = 4;
|
||||
|
||||
/**
|
||||
* Bottom align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const BOTTOM = 5;
|
||||
|
||||
/**
|
||||
* Middle align
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const MIDDLE = 6;
|
||||
|
||||
/**
|
||||
* Change alignment
|
||||
*
|
||||
* @param int $h Horizontal alignment
|
||||
* @param int $v Vertical alignment
|
||||
*/
|
||||
public function setAlign($h = NULL, $v = NULL);
|
||||
|
||||
}
|
||||
|
||||
registerInterface('Positionable');
|
||||
|
||||
/**
|
||||
* Manage left, right, top and bottom sides
|
||||
*
|
||||
* @package Artichow
|
||||
*/
|
||||
class awSide {
|
||||
|
||||
/**
|
||||
* Left side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $left = 0;
|
||||
|
||||
/**
|
||||
* Right side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $right = 0;
|
||||
|
||||
/**
|
||||
* Top side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $top = 0;
|
||||
|
||||
/**
|
||||
* Bottom side
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $bottom = 0;
|
||||
|
||||
/**
|
||||
* Build the side
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
public function __construct($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
$this->set($left, $right, $top, $bottom);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change side values
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
public function set($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
|
||||
if($left !== NULL) {
|
||||
$this->left = (float)$left;
|
||||
}
|
||||
if($right !== NULL) {
|
||||
$this->right = (float)$right;
|
||||
}
|
||||
if($top !== NULL) {
|
||||
$this->top = (float)$top;
|
||||
}
|
||||
if($bottom !== NULL) {
|
||||
$this->bottom = (float)$bottom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add values to each side
|
||||
*
|
||||
* @param mixed $left
|
||||
* @param mixed $right
|
||||
* @param mixed $top
|
||||
* @param mixed $bottom
|
||||
*/
|
||||
public function add($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
|
||||
|
||||
if($left !== NULL) {
|
||||
$this->left += (float)$left;
|
||||
}
|
||||
if($right !== NULL) {
|
||||
$this->right += (float)$right;
|
||||
}
|
||||
if($top !== NULL) {
|
||||
$this->top += (float)$top;
|
||||
}
|
||||
if($bottom !== NULL) {
|
||||
$this->bottom += (float)$bottom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
registerClass('Side');
|
||||
?>
|
||||
|
|
@ -348,7 +348,7 @@ if (! defined('NOLOGIN'))
|
|||
// Verification security graphic code
|
||||
if (GETPOST("username","alpha",2) && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA))
|
||||
{
|
||||
$sessionkey = 'artichow_dol_antispam_value';
|
||||
$sessionkey = 'dol_antispam_value';
|
||||
$ok=(array_key_exists($sessionkey, $_SESSION) === TRUE && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
|
||||
|
||||
// Verifie code
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ jQuery(document).ready(function () {
|
|||
<input id="securitycode" class="flat" type="text" size="6" maxlength="5" name="code" tabindex="4" />
|
||||
</div>
|
||||
<div class="captchaImg">
|
||||
<img src="<?php echo DOL_URL_ROOT ?>/core/antispamimage.php" border="0" width="128" height="36" id="captcha" />
|
||||
<img src="<?php echo DOL_URL_ROOT ?>/core/antispamimage.php" border="0" width="80" height="32" id="captcha" />
|
||||
<a href="<?php echo $php_self; ?>"><?php echo $captcha_refresh; ?></a>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ function donnefocus() {
|
|||
<input id="securitycode" class="flat" type="text" size="6" maxlength="5" name="code" tabindex="3">
|
||||
</div>
|
||||
<div class="captchaImg">
|
||||
<img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="128" height="36" id="captcha">
|
||||
<img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="80" height="32" id="captcha">
|
||||
<a href="<?php echo $php_self; ?>"><?php echo $captcha_refresh; ?></a>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ top_httphead();
|
|||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<?php
|
||||
<?php
|
||||
include('header.tpl.php');
|
||||
?>
|
||||
<body>
|
||||
|
|
@ -63,7 +63,7 @@ jQuery(document).bind("mobileinit", function(){
|
|||
<?php if ($captcha) { ?>
|
||||
<label for="securitycode"><?php echo $langs->trans('SecurityCode'); ?></label>
|
||||
<input type="text" id="securitycode" name="securitycode" />
|
||||
<div align="center"><img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="128" height="36" /></div>
|
||||
<div align="center"><img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="80" height="32" /></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ top_httphead();
|
|||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<?php
|
||||
<?php
|
||||
include('header.tpl.php');
|
||||
?>
|
||||
<body>
|
||||
|
|
@ -51,7 +51,7 @@ include('header.tpl.php');
|
|||
<?php if ($captcha) { ?>
|
||||
<label for="securitycode"><?php echo $langs->trans('SecurityCode'); ?></label>
|
||||
<input type="text" id="securitycode" name="securitycode" />
|
||||
<div align="center"><img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="256" height="48" /></div>
|
||||
<div align="center"><img src="<?php echo $dol_url_root.'/core/antispamimage.php'; ?>" border="0" width="80" height="32" /></div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ if ($action == 'validatenewpassword' && $username && $passwordmd5)
|
|||
// Action modif mot de passe
|
||||
if ($action == 'buildnewpassword' && $username)
|
||||
{
|
||||
$sessionkey = 'artichow_dol_antispam_value';
|
||||
$sessionkey = 'dol_antispam_value';
|
||||
$ok=(array_key_exists($sessionkey, $_SESSION) === TRUE && (strtolower($_SESSION[$sessionkey]) == strtolower($_POST['code'])));
|
||||
|
||||
// Verify code
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
<directory suffix=".php">../../htdocs/contact/canvas/</directory>
|
||||
<directory suffix=".php">../../htdocs/societe/canvas/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/adodbtime/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/artichow/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/ckeditor/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/fpdfi/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/geoip/</directory>
|
||||
|
|
@ -51,7 +50,6 @@
|
|||
<directory suffix=".php">../../htdocs/contact/canvas/</directory>
|
||||
<directory suffix=".php">../../htdocs/societe/canvas/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/adodbtime/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/artichow/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/ckeditor/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/fpdfi/</directory>
|
||||
<directory suffix=".php">../../htdocs/includes/geoip/</directory>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user