From 2409c7fbfdb57fd9de3c82266cd72c1315f7b9e3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 14 Aug 2011 18:25:15 +0000 Subject: [PATCH] Qual: Can externalize fonts. --- build/deb/dolibarr.lintian-overrides | 7 +- build/makepack-dolibarr.pl | 6 +- htdocs/core/class/dolgraph.class.php | 10 +- htdocs/includes/artichow/Artichow.cfg.php | 28 +- .../artichow/php4/Component.class.php | 125 ++-- htdocs/includes/artichow/php4/Graph.class.php | 194 +++--- .../includes/artichow/php4/MathPlot.class.php | 173 ++--- htdocs/includes/artichow/php4/Plot.class.php | 635 +++++++++--------- .../artichow/php5/Component.class.php | 122 ++-- htdocs/includes/artichow/php5/Graph.class.php | 194 +++--- .../includes/artichow/php5/MathPlot.class.php | 169 ++--- htdocs/includes/artichow/php5/Plot.class.php | 607 ++++++++--------- .../includes/artichow/php5/inc/Font.class.php | 125 ++-- htdocs/master.inc.php | 4 +- 14 files changed, 1224 insertions(+), 1175 deletions(-) diff --git a/build/deb/dolibarr.lintian-overrides b/build/deb/dolibarr.lintian-overrides index 0e27ea0f690..c62cae84ee0 100755 --- a/build/deb/dolibarr.lintian-overrides +++ b/build/deb/dolibarr.lintian-overrides @@ -5,9 +5,4 @@ embedded-javascript-library usr/share/dolibarr/htdocs/includes/ckeditor/ckeditor embedded-javascript-library usr/share/dolibarr/htdocs/includes/fckeditor/fckeditor.js embedded-php-library usr/share/dolibarr/htdocs/includes/magpierss/extlib/Snoopy.class.inc embedded-php-library usr/share/dolibarr/htdocs/includes/magpierss/rss_parse.inc -embedded-php-library usr/share/dolibarr/htdocs/includes/nusoap/lib/nusoap.php -# embedded fonts, wich are specific to Dolibarr usage -font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/Tuffy.ttf -font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/TuffyBold.ttf -font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/TuffyBoldItalic.ttf -font-in-non-font-package usr/share/dolibarr/htdocs/includes/artichow/font/TuffyItalic.ttf \ No newline at end of file +embedded-php-library usr/share/dolibarr/htdocs/includes/nusoap/lib/nusoap.php \ No newline at end of file diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index 60598defaef..1c5e9aa283a 100644 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -2,7 +2,7 @@ #---------------------------------------------------------------------------- # \file build/makepack-dolibarr.pl # \brief Dolibarr package builder (tgz, zip, rpm, deb, exe, aps) -# \version $Id: makepack-dolibarr.pl,v 1.144 2011/08/14 17:17:20 eldy Exp $ +# \version $Id: makepack-dolibarr.pl,v 1.145 2011/08/14 18:26:21 eldy Exp $ # \author (c)2004-2011 Laurent Destailleur #---------------------------------------------------------------------------- @@ -45,7 +45,7 @@ if (-d "/usr/src/RPM") { $RPMDIR="/usr/src/RPM"; } # mandrake use vars qw/ $REVISION $VERSION /; -$REVISION='$Revision: 1.144 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1; +$REVISION='$Revision: 1.145 $'; $REVISION =~ /\s(.*)\s/; $REVISION=$1; $VERSION="3.2 (build $REVISION)"; @@ -503,6 +503,7 @@ if ($nboftargetok) { $ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/build/zip`; $ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/build/perl`; # We remove embedded libraries or fonts + $ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/artichow/font`, $ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/barcode/php-barcode/fonts`, #$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip`; $ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip/gnu-lgpl.txt`; @@ -703,6 +704,7 @@ if ($nboftargetok) { $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/build/rpm`; $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/build/zip`; # We remove embedded libraries or fonts + $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/artichow/font`, $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/barcode/php-barcode/fonts`, $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/nusoap/lib/Mail`; $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip`; diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index ea9165804c6..c4f060e7016 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -20,7 +20,7 @@ * \file htdocs/core/class/dolgraph.class.php * \ingroup core * \brief Fichier de la classe mere de gestion des graph - * \version $Id: dolgraph.class.php,v 1.7 2011/07/31 23:45:15 eldy Exp $ + * \version $Id: dolgraph.class.php,v 1.8 2011/08/14 18:26:26 eldy Exp $ * * Usage: * $graph_data = array(array('labelA',yA),array('labelB',yB)); @@ -415,6 +415,7 @@ class DolGraph */ function draw_artichow($file) { + global $artichow_defaultfont; dol_syslog("DolGraph.class::draw_artichow this->type=".$this->type); if (! defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP',3); @@ -442,7 +443,8 @@ class DolGraph if (isset($this->title)) { $graph->title->set($this->title); - $graph->title->setFont(new Tuffy(10)); + //print $artichow_defaultfont;exit; + $graph->title->setFont(new $artichow_defaultfont(10)); } if (is_array($this->bgcolor)) $graph->setBackgroundColor($bgcolor); @@ -555,7 +557,7 @@ class DolGraph //$plot->reduce(80); // Evite temps d'affichage trop long et nombre de ticks absisce satures - $group->legend->setTextFont(new Tuffy(10)); // This is to force Artichow to use awFileFontDriver to + $group->legend->setTextFont(new $artichow_defaultfont(10)); // This is to force Artichow to use awFileFontDriver to // solve a bug in Artichow with UTF8 if (sizeof($this->Legend)) { @@ -568,7 +570,7 @@ class DolGraph } $group->axis->bottom->setLabelText($legends); - $group->axis->bottom->label->setFont(new Tuffy(7)); + $group->axis->bottom->label->setFont(new $artichow_defaultfont(7)); //print $group->axis->bottom->getLabelNumber(); if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval); diff --git a/htdocs/includes/artichow/Artichow.cfg.php b/htdocs/includes/artichow/Artichow.cfg.php index 4a8790b1b72..7894a943303 100644 --- a/htdocs/includes/artichow/Artichow.cfg.php +++ b/htdocs/includes/artichow/Artichow.cfg.php @@ -18,27 +18,27 @@ define('ARTICHOW', dirname(__FILE__).DIRECTORY_SEPARATOR.'php'.substr(phpversion * 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'); - + } /* @@ -50,9 +50,9 @@ define('ARTICHOW_CACHE', TRUE); * Cache directory */ if(defined('ARTICHOW_CACHE') === FALSE) { - + define('ARTICHOW_CACHE_DIRECTORY', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'cache'); - + } /* @@ -69,11 +69,19 @@ define('ARTICHOW_DEPRECATED', TRUE); /* * Fonts to use */ -$fonts = array( + +// DOL_CHANGE LDR +if (defined('ARTICHOW_FONT_NAMES')) $fonts=explode(',',constant('ARTICHOW_FONT_NAMES')); +else $fonts = array( 'Tuffy', 'TuffyBold', 'TuffyBoldItalic', 'TuffyItalic' ); - +global $artichow_defaultfont; +$artichow_defaultfont=$fonts[0]; +//var_dump(ARTICHOW_FONT); +//var_dump($fonts); +//var_dump($artichow_defaultfont); +//exit; ?> \ No newline at end of file diff --git a/htdocs/includes/artichow/php4/Component.class.php b/htdocs/includes/artichow/php4/Component.class.php index 4c7e36b5ac9..4e5101a048a 100644 --- a/htdocs/includes/artichow/php4/Component.class.php +++ b/htdocs/includes/artichow/php4/Component.class.php @@ -6,7 +6,7 @@ * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. * */ - + require_once dirname(__FILE__)."/Graph.class.php"; @@ -23,7 +23,7 @@ require_once dirname(__FILE__)."/Graph.class.php"; * @var array */ var $components; - + /** * Build the component group */ @@ -81,7 +81,7 @@ registerClass('ComponentGroup', TRUE); * @var float */ var $y = 0.5; - + /** * Component absolute width (in pixels) * @@ -89,7 +89,7 @@ registerClass('ComponentGroup', TRUE); * @var int */ var $w; - + /** * Component absolute height (in pixels) * @@ -111,71 +111,74 @@ registerClass('ComponentGroup', TRUE); * @var float */ var $left; - + /** * Component background color * * @var Color */ var $background; - + /** * Component padding * * @var Side */ var $padding; - + /** * Component space * * @var Side */ var $space; - + /** * Component title * * @var Label */ var $title; - + /** * Adjust automatically the component ? * * @var bool */ var $auto = TRUE; - + /** * Legend * * @var Legend */ var $legend; - + /** * Build the component */ function awComponent() { - + // 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 awTuffy(10), + new $classfontname(10), NULL, 0 ); $this->title->setAlign(LABEL_CENTER, LABEL_TOP); - + } - + /** * Adjust automatically the component ? * @@ -184,7 +187,7 @@ registerClass('ComponentGroup', TRUE); function auto($auto) { $this->auto = (bool)$auto; } - + /** * Change the size of the component * @@ -192,12 +195,12 @@ registerClass('ComponentGroup', TRUE); * @param int $height Component height (from 0 to 1) */ function setSize($width, $height) { - + $this->width = (float)$width; $this->height = (float)$height; - + } - + /** * Change the absolute size of the component * @@ -205,12 +208,12 @@ registerClass('ComponentGroup', TRUE); * @param int $h Component height (in pixels) */ function setAbsSize($w, $h) { - + $this->w = (int)$w; $this->h = (int)$h; - + } - + /** * Change component background color * @@ -221,7 +224,7 @@ registerClass('ComponentGroup', TRUE); $this->background = $color; } } - + /** * Change component background gradient * @@ -232,7 +235,7 @@ registerClass('ComponentGroup', TRUE); $this->background = $gradient; } } - + /** * Change component background image * @@ -243,7 +246,7 @@ registerClass('ComponentGroup', TRUE); $this->background = $image; } } - + /** * Return the component background * @@ -252,7 +255,7 @@ registerClass('ComponentGroup', TRUE); function getBackground() { return $this->background; } - + /** * Change component padding * @@ -264,7 +267,7 @@ registerClass('ComponentGroup', TRUE); function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) { $this->padding->set($left, $right, $top, $bottom); } - + /** * Change component space * @@ -276,7 +279,7 @@ registerClass('ComponentGroup', TRUE); 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 * @@ -284,12 +287,12 @@ registerClass('ComponentGroup', TRUE); * @var int $y Left-top corner Y position */ function setAbsPosition($left, $top) { - + $this->left = (int)$left; $this->top = (int)$top; - + } - + /** * Set the center of the component * @@ -297,29 +300,29 @@ registerClass('ComponentGroup', TRUE); * @param int $y Position on Y axis of the center of the component */ function setCenter($x, $y) { - + $this->x = (float)$x; $this->y = (float)$y; - + } - + /** * Get component coords with its padding * * @return array Coords of the component */ 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 */ @@ -327,57 +330,57 @@ registerClass('ComponentGroup', TRUE); // Set component background $background = $this->getBackground(); - + if($background !== NULL) { - + $p1 = new awPoint(0, 0); $p2 = new awPoint($this->w - 1, $this->h - 1); - + if(is_a($background, 'awImage')) { - + $drawer->copyImage( $background, $p1, $p2 ); - + } else { - + $drawer->filledRectangle( $background, new awLine($p1, $p2) ); - + } - + } } - + /** * Finalize the drawing of the component */ function finalize($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 */ - - + + /** * Draw the component on the graph * Component should be drawed into specified coords @@ -389,8 +392,8 @@ registerClass('ComponentGroup', TRUE); * @param int $y2 * @param bool $aliasing Use anti-aliasing to draw the component ? */ - - + + /** * Get space width in pixels * @@ -399,16 +402,16 @@ registerClass('ComponentGroup', TRUE); * @return array */ 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); diff --git a/htdocs/includes/artichow/php4/Graph.class.php b/htdocs/includes/artichow/php4/Graph.class.php index 47f5b5f55dc..2d2cbc8f493 100644 --- a/htdocs/includes/artichow/php4/Graph.class.php +++ b/htdocs/includes/artichow/php4/Graph.class.php @@ -29,7 +29,7 @@ require_once ARTICHOW."/inc/Font.class.php"; require_once ARTICHOW."/inc/Gradient.class.php"; /** - * A graph + * A graph * * @package Artichow */ @@ -48,35 +48,35 @@ class awGraph extends awImage { * @var int */ var $timeout = 0; - + /** * Graph timing ? * * @var bool */ var $timing; - + /** * Components * * @var array */ var $components = array(); - + /** * Some labels to add to the component * * @var array */ var $labels = array(); - + /** * Graph title * * @var Label */ var $title; - + /** * Construct a new graph * @@ -86,29 +86,33 @@ class awGraph extends awImage { * @param int $timeout Cache timeout (unix timestamp) */ function awGraph($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::awImage(); - + $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 { @@ -116,23 +120,23 @@ class awGraph extends awImage { readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name.""); exit; } - + } - + } - + } - + $this->title = new awLabel( NULL, - new awTuffy(16), + new $classfontname(16), NULL, 0 ); $this->title->setAlign(LABEL_CENTER, LABEL_BOTTOM); - + } - + /** * Delete a graph from the cache * @@ -142,59 +146,59 @@ class awGraph extends awImage { 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 */ 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 */ function cleanCache() { if(ARTICHOW_CACHE) { - + $glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time"); - + foreach($glob as $file) { - + $type = awGraph::cleanGraphCache($file); - + if($type === NULL) { $name = ereg_replace(".*/(.*)\-time", "\\1", $file); awGraph::deleteFromCache($name); } - + } - + } - + } - + /** * Enable/Disable Graph timing * @@ -203,18 +207,18 @@ class awGraph extends awImage { function setTiming($timing) { $this->timing = (bool)$timing; } - + /** * Add a component to the graph * * @param &$component */ function add(&$component) { - + $this->components[] = $component; - + } - + /** * Add a label to the component * @@ -223,13 +227,13 @@ class awGraph extends awImage { * @param int $y Position on Y axis of the center of the text */ function addLabel(&$label, $x, $y) { - + $this->labels[] = array( $label, $x, $y ); - + } - + /** * Add a label to the component with aboslute position * @@ -237,13 +241,13 @@ class awGraph extends awImage { * @param $point Text position */ function addAbsLabel(&$label, $point) { - + $this->labels[] = array( $label, $point ); - + } - + /** * Build the graph and draw component on it * Image is sent to the user browser @@ -251,23 +255,23 @@ class awGraph extends awImage { * @param string $file Save the image in the specified file. Let it null to print image to screen. */ 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); } @@ -275,104 +279,104 @@ class awGraph extends awImage { 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; - + } - + } - + 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); - + } - + } - + function drawTitle() { - + $drawer = $this->getDrawer(); - + $point = new awPoint( $this->width / 2, 10 ); - + $this->title->draw($drawer, $point); - + } - + function drawTiming($time) { - + $drawer = $this->getDrawer(); - + $label = new awLabel; $label->set("(".sprintf("%.3f", $time)." s)"); $label->setAlign(LABEL_LEFT, LABEL_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)); - + } - + 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; } - - + + } } @@ -382,8 +386,8 @@ registerClass('Graph'); /* * To preserve PHP 4 compatibility */ -function microtimeFloat() { - list($usec, $sec) = explode(" ", microtime()); - return (float)$usec + (float)$sec; +function microtimeFloat() { + list($usec, $sec) = explode(" ", microtime()); + return (float)$usec + (float)$sec; } ?> diff --git a/htdocs/includes/artichow/php4/MathPlot.class.php b/htdocs/includes/artichow/php4/MathPlot.class.php index 86f8e2b3fa8..4396cc8147a 100644 --- a/htdocs/includes/artichow/php4/MathPlot.class.php +++ b/htdocs/includes/artichow/php4/MathPlot.class.php @@ -22,28 +22,28 @@ class awMathFunction { * @var Line */ var $line; - + /** * Marks for your plot * * @var Mark */ var $mark; - + /** * Callback function * * @var string */ var $f; - + /** * Start the drawing from this value * * @var float */ var $fromX; - + /** * Stop the drawing at this value * @@ -57,7 +57,7 @@ class awMathFunction { * @var Color */ var $color; - + /** * Construct the function * @@ -66,17 +66,17 @@ class awMathFunction { * @param float $toX */ function awMathFunction($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 * @@ -85,7 +85,7 @@ class awMathFunction { function setColor($color) { $this->color = $color; } - + /** * Get line color * @@ -142,56 +142,56 @@ class awMathFunction { } registerClass('MathFunction'); - + /** * For mathematics functions * * @package Artichow */ class awMathPlot extends awComponent { - + /** * Functions * * @var array */ var $functions = array(); - + /** * Grid properties * * @var Grid */ var $grid; - + /** * X axis * * @var Axis */ var $xAxis; - + /** * Y axis * * @var Axis */ var $yAxis; - + /** * Extremum * * @var Side */ var $extremum = NULL; - + /** * Interval * * @var float */ var $interval = 1; - + /** * Build the plot * @@ -201,44 +201,47 @@ class awMathPlot extends awComponent { * @param int $yMin Minimum Y value */ function awMathPlot($xMin, $xMax, $yMax, $yMin) { - + parent::awComponent(); - + $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(TICK_IN); $this->xAxis->label->hideValue(0); $this->initAxis($this->xAxis); - + $this->yAxis = new awAxis; $this->yAxis->setTickStyle(TICK_IN); $this->yAxis->label->hideValue(0); $this->initAxis($this->yAxis); - + } - + function initAxis(&$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 awTuffy(7)); - + $axis->label->setFont(new $classfontname(7)); + } - + /** * Interval to calculate values * @@ -247,7 +250,7 @@ class awMathPlot extends awComponent { function setInterval($interval) { $this->interval = (float)$interval; } - + /** * Add a formula f(x) * @@ -256,104 +259,104 @@ class awMathPlot extends awComponent { * @param int $type Type for the legend */ function add(&$function, $name = NULL, $type = LEGEND_LINE) { - + $this->functions[] = $function; - + if($name !== NULL) { $this->legend->add($function, $name, $type); } - + } - + function init($drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + $this->xAxis->line->setX($x1, $x2); $this->xAxis->label->setAlign(NULL, LABEL_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(LABEL_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 - + $this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber()); $this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber()); - - + + // 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); - + } - + function drawEnvelope($drawer) { - + // Draw axis $this->xAxis->draw($drawer); $this->yAxis->draw($drawer); - + } - + function drawComponent($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) @@ -363,26 +366,26 @@ class awMathPlot extends awComponent { $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) @@ -392,34 +395,34 @@ class awMathPlot extends awComponent { $line ); } - + } - + } - + } - + 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++) { @@ -428,9 +431,9 @@ class awMathPlot extends awComponent { } } } - + $this->grid->setGrid($w, $h); - + } } diff --git a/htdocs/includes/artichow/php4/Plot.class.php b/htdocs/includes/artichow/php4/Plot.class.php index 8eea0d56ac3..58d19c316ed 100644 --- a/htdocs/includes/artichow/php4/Plot.class.php +++ b/htdocs/includes/artichow/php4/Plot.class.php @@ -8,7 +8,7 @@ */ require_once dirname(__FILE__)."/Component.class.php"; - + /* */ define("PLOT_LEFT", 'left'); @@ -18,14 +18,14 @@ define("PLOT_BOTTOM", 'bottom'); define("PLOT_BOTH", 'both'); /* */ - + /** * Graph using X and Y axis * * @package Artichow */ class awPlot extends awComponent { - + /** * Values for Y axis * @@ -39,149 +39,152 @@ define("PLOT_BOTH", 'both'); * @var array */ var $datax; - + /** * Grid properties * * @var Grid */ var $grid; - + /** * X axis * * @var Axis */ var $xAxis; - + /** * Y axis * * @var Axis */ var $yAxis; - + /** * Position of X axis * * @var int */ var $xAxisPosition = PLOT_BOTTOM; - + /** * Set X axis on zero ? * * @var bool */ var $xAxisZero = TRUE; - + /** * Set Y axis on zero ? * * @var bool */ var $yAxisZero = FALSE; - + /** * Position of Y axis * * @var int */ var $yAxisPosition = PLOT_LEFT; - + /** * Change min value for Y axis * * @var mixed */ var $yMin = NULL; - + /** * Change max value for Y axis * * @var mixed */ var $yMax = NULL; - + /** * Change min value for X axis * * @var mixed */ var $xMin = NULL; - + /** * Change max value for X axis * * @var mixed */ var $xMax = NULL; - + /** * Left axis * * @var int */ - - + + /** * RIGHT axis * * @var int */ - - + + /** * Top axis * * @var int */ - - + + /** * Bottom axis * * @var int */ - - + + /** * Both left/right or top/bottom axis * * @var int */ - - + + /** * Build the plot * */ function awPlot() { - + // DOL_CHANGE LDR Fix to allow usage of other fonts + global $artichow_defaultfont; + $classfontname='aw'.str_replace('-','_',$artichow_defaultfont); + parent::awComponent(); - + $this->grid = new awGrid; $this->grid->setBackgroundColor(new awWhite); $this->padding->add(20, 0, 0, 20); - + $this->xAxis = new awAxis; $this->xAxis->addTick('major', new awTick(0, 5)); $this->xAxis->addTick('minor', new awTick(0, 3)); $this->xAxis->setTickStyle(TICK_OUT); - $this->xAxis->label->setFont(new awTuffy(7)); - + $this->xAxis->label->setFont(new $classfontname(7)); + $this->yAxis = new awAxis; $this->yAxis->auto(TRUE); $this->yAxis->addTick('major', new awTick(0, 5)); $this->yAxis->addTick('minor', new awTick(0, 3)); $this->yAxis->setTickStyle(TICK_OUT); $this->yAxis->setNumberByTick('minor', 'major', 3); - $this->yAxis->label->setFont(new awTuffy(7)); + $this->yAxis->label->setFont(new $classfontname(7)); $this->yAxis->title->setAngle(90); - + } - + /** * Get plot values * @@ -190,48 +193,48 @@ define("PLOT_BOTH", 'both'); function getValues() { return $this->datay; } - + /** * Reduce number of values in the plot * * @param int $number Reduce number of values to $number */ function reduce($number) { - + $count = count($this->datay); $ratio = ceil($count / $number); - + if($ratio > 1) { - + $tmpy = $this->datay; $datay = array(); - + $datax = array(); $cbLabel = $this->xAxis->label->getCallbackFunction(); - + for($i = 0; $i < $count; $i += $ratio) { - + $slice = array_slice($tmpy, $i, $ratio); $datay[] = array_sum($slice) / count($slice); - + // Reduce data on X axis if needed if($cbLabel !== NULL) { $datax[] = $cbLabel($i + round($ratio / 2)); } - + } - + $this->setValues($datay); - + if($cbLabel !== NULL) { $this->xAxis->setLabelText($datax); } - - + + } - + } - + /** * Count values in the plot * @@ -241,7 +244,7 @@ define("PLOT_BOTH", 'both'); list($min, $max) = $this->xAxis->getRange(); return ($max - $min + 1); } - + /** * Change X axis * @@ -250,7 +253,7 @@ define("PLOT_BOTH", 'both'); function setXAxis($axis) { $this->xAxisPosition = $axis; } - + /** * Get X axis * @@ -259,7 +262,7 @@ define("PLOT_BOTH", 'both'); function getXAxis() { return $this->xAxisPosition; } - + /** * Set X axis on zero * @@ -268,7 +271,7 @@ define("PLOT_BOTH", 'both'); function setXAxisZero($zero) { $this->xAxisZero = (bool)$zero; } - + /** * Set Y axis on zero * @@ -277,7 +280,7 @@ define("PLOT_BOTH", 'both'); function setYAxisZero($zero) { $this->yAxisZero = (bool)$zero; } - + /** * Change Y axis * @@ -286,7 +289,7 @@ define("PLOT_BOTH", 'both'); function setYAxis($axis) { $this->yAxisPosition = $axis; } - + /** * Get Y axis * @@ -295,7 +298,7 @@ define("PLOT_BOTH", 'both'); function getYAxis() { return $this->yAxisPosition; } - + /** * Change min value for Y axis * Set NULL for auto selection. @@ -307,7 +310,7 @@ define("PLOT_BOTH", 'both'); $this->yAxis->auto(FALSE); $this->updateAxis(); } - + /** * Change max value for Y axis * Set NULL for auto selection. @@ -319,7 +322,7 @@ define("PLOT_BOTH", 'both'); $this->yAxis->auto(FALSE); $this->updateAxis(); } - + /** * Change min value for X axis * Set NULL for auto selection. @@ -330,7 +333,7 @@ define("PLOT_BOTH", 'both'); $this->xMin = $value; $this->updateAxis(); } - + /** * Change max value for X axis * Set NULL for auto selection. @@ -341,7 +344,7 @@ define("PLOT_BOTH", 'both'); $this->xMax = $value; $this->updateAxis(); } - + /** * Get min value for Y axis * @@ -358,7 +361,7 @@ define("PLOT_BOTH", 'both'); } return is_null($this->yMin) ? array_min($this->datay) : (float)$this->yMin; } - + /** * Get max value for Y axis * @@ -375,7 +378,7 @@ define("PLOT_BOTH", 'both'); } return is_null($this->yMax) ? array_max($this->datay) : (float)$this->yMax; } - + /** * Get min value for X axis * @@ -384,7 +387,7 @@ define("PLOT_BOTH", 'both'); function getXMin() { return floor(is_null($this->xMin) ? array_min($this->datax) : $this->xMin); } - + /** * Get max value for X axis * @@ -393,7 +396,7 @@ define("PLOT_BOTH", 'both'); function getXMax() { return (ceil(is_null($this->xMax) ? array_max($this->datax) : (float)$this->xMax)) + ($this->getXCenter() ? 1 : 0); } - + /** * Get min value with spaces for Y axis * @@ -408,7 +411,7 @@ define("PLOT_BOTH", 'both'); return is_null($this->yMin) ? $min : (float)$this->yMin; } } - + /** * Get max value with spaces for Y axis * @@ -423,88 +426,88 @@ define("PLOT_BOTH", 'both'); return is_null($this->yMax) ? $max : (float)$this->yMax; } } - + function init($drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + // Get space informations list($leftSpace, $rightSpace, $topSpace, $bottomSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + $this->xAxis->setPadding($leftSpace, $rightSpace); - + if($this->space->bottom > 0 or $this->space->top > 0) { - + list($min, $max) = $this->yAxis->getRange(); $interval = $max - $min; - + $this->yAxis->setRange( $min - $interval * $this->space->bottom / 100, $max + $interval * $this->space->top / 100 ); - + } - + // Auto-scaling mode $this->yAxis->autoScale(); - + // Number of labels is not specified if($this->yAxis->getLabelNumber() === NULL) { $number = round(($y2 - $y1) / 75) + 2; $this->yAxis->setLabelNumber($number); } - + $this->xAxis->line->setX($x1, $x2); $this->yAxis->line->setY($y2, $y1); - + // Set ticks - + $this->xAxis->ticks['major']->setNumber($this->getXAxisNumber()); $this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber()); - - + + // Center X axis on zero if($this->xAxisZero) { $this->xAxis->setYCenter($this->yAxis, 0); } - + // Center Y axis on zero if($this->yAxisZero) { $this->yAxis->setXCenter($this->xAxis, 0); } - + // Set axis labels $labels = array(); for($i = 0, $count = $this->getXAxisNumber(); $i < $count; $i++) { $labels[] = $i; } $this->xAxis->label->set($labels); - + parent::init($drawer); - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + list($leftSpace, $rightSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + // Create the grid $this->createGrid(); - + // Draw the grid $this->grid->setSpace($leftSpace, $rightSpace, 0, 0); $this->grid->draw($drawer, $x1, $y1, $x2, $y2); - + } - + function drawEnvelope($drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + if($this->getXCenter()) { $size = $this->xAxis->getDistance(0, 1); $this->xAxis->label->move($size / 2, 0); $this->xAxis->label->hideLast(TRUE); } - + // Draw top axis if($this->xAxisPosition === PLOT_TOP or $this->xAxisPosition === PLOT_BOTH) { $top = $this->xAxis; @@ -516,7 +519,7 @@ define("PLOT_BOTH", 'both'); $top->title->move(0, -25); $top->draw($drawer); } - + // Draw bottom axis if($this->xAxisPosition === PLOT_BOTTOM or $this->xAxisPosition === PLOT_BOTH) { $bottom = $this->xAxis; @@ -529,7 +532,7 @@ define("PLOT_BOTH", 'both'); $bottom->title->move(0, 25); $bottom->draw($drawer); } - + // Draw left axis if($this->yAxisPosition === PLOT_LEFT or $this->yAxisPosition === PLOT_BOTH) { $left = $this->yAxis; @@ -541,7 +544,7 @@ define("PLOT_BOTH", 'both'); $left->title->move(-25, 0); $left->draw($drawer); } - + // Draw right axis if($this->yAxisPosition === PLOT_RIGHT or $this->yAxisPosition === PLOT_BOTH) { $right = $this->yAxis; @@ -554,49 +557,49 @@ define("PLOT_BOTH", 'both'); $right->title->move(25, 0); $right->draw($drawer); } - + } - + function createGrid() { - + $max = $this->getRealYMax(); $min = $this->getRealYMin(); $number = $this->yAxis->getLabelNumber() - 1; - + if($number < 1) { return; } - + // Horizontal lines of the grid - + $h = array(); for($i = 0; $i <= $number; $i++) { $h[] = $i / $number; } - + // Vertical lines - + $major = $this->yAxis->tick('major'); $interval = $major->getInterval(); $number = $this->getXAxisNumber() - 1; - + $w = array(); - + if($number > 0) { - + for($i = 0; $i <= $number; $i++) { if($i%$interval === 0) { $w[] = $i / $number; } } - + } - + $this->grid->setGrid($w, $h); - + } - + /** * Change values of Y axis * This method ignores not numeric values @@ -605,14 +608,14 @@ define("PLOT_BOTH", 'both'); * @param array $datax */ function setValues($datay, $datax = NULL) { - + $this->checkArray($datay); - + foreach($datay as $key => $value) { unset($datay[$key]); $datay[(int)$key] = $value; } - + if($datax === NULL) { $datax = array(); for($i = 0; $i < count($datay); $i++) { @@ -624,11 +627,11 @@ define("PLOT_BOTH", 'both'); $datax[(int)$key] = $value; } } - + $this->checkArray($datax); - + if(count($datay) === count($datax)) { - + // Set values $this->datay = $datay; $this->datax = $datax; @@ -637,16 +640,16 @@ define("PLOT_BOTH", 'both'); } else { trigger_error("Plots must have the same number of X and Y points", E_USER_ERROR); } - + } - + /** * Return begin and end values * * @return array */ function getLimit() { - + $i = 0; while(array_key_exists($i, $this->datay) and $this->datay[$i] === NULL) { $i++; @@ -657,20 +660,20 @@ define("PLOT_BOTH", 'both'); $i--; } $stop = $i; - + return array($start, $stop); - + } - + /** * Return TRUE if labels must be centered on X axis, FALSE otherwise * * @return bool */ - - + + function updateAxis() { - + $this->xAxis->setRange( $this->getXMin(), $this->getXMax() @@ -679,25 +682,25 @@ define("PLOT_BOTH", 'both'); $this->getRealYMin(), $this->getRealYMax() ); - + } - + function checkArray(&$array) { - + if(is_array($array) === FALSE) { trigger_error("You tried to set a value that is not an array", E_USER_ERROR); } - + foreach($array as $key => $value) { if(is_numeric($value) === FALSE and is_null($value) === FALSE) { trigger_error("Expected numeric values for the plot", E_USER_ERROR); } } - + if(count($array) < 1) { trigger_error("Your plot must have at least 1 value", E_USER_ERROR); } - + } } @@ -738,7 +741,7 @@ class awPlotAxis { * Build the group of axis */ function awPlotAxis() { - + $this->left = new awAxis; $this->left->auto(TRUE); $this->left->label->setAlign(LABEL_RIGHT); @@ -746,7 +749,7 @@ class awPlotAxis { $this->yAxis($this->left); $this->left->setTickStyle(TICK_OUT); $this->left->title->move(-25, 0); - + $this->right = new awAxis; $this->right->auto(TRUE); $this->right->label->setAlign(LABEL_LEFT); @@ -754,39 +757,45 @@ class awPlotAxis { $this->yAxis($this->right); $this->right->setTickStyle(TICK_IN); $this->right->title->move(25, 0); - + $this->top = new awAxis; $this->top->label->setAlign(NULL, LABEL_TOP); $this->top->label->move(0, -3); $this->xAxis($this->top); $this->top->setTickStyle(TICK_OUT); $this->top->title->move(0, -25); - + $this->bottom = new awAxis; $this->bottom->label->setAlign(NULL, LABEL_BOTTOM); $this->bottom->label->move(0, 3); $this->xAxis($this->bottom); $this->bottom->setTickStyle(TICK_IN); $this->bottom->title->move(0, 25); - + } - + function xAxis(&$axis) { - + // DOL_CHANGE LDR Fix to allow usage of other fonts + global $artichow_defaultfont; + $classfontname='aw'.str_replace('-','_',$artichow_defaultfont); + $axis->addTick('major', new awTick(0, 5)); $axis->addTick('minor', new awTick(0, 3)); - $axis->label->setFont(new awTuffy(7)); - + $axis->label->setFont(new $classfontname(7)); + } - + function yAxis(&$axis) { - + // DOL_CHANGE LDR Fix to allow usage of other fonts + global $artichow_defaultfont; + $classfontname='aw'.str_replace('-','_',$artichow_defaultfont); + $axis->addTick('major', new awTick(0, 5)); $axis->addTick('minor', new awTick(0, 3)); $axis->setNumberByTick('minor', 'major', 3); - $axis->label->setFont(new awTuffy(7)); + $axis->label->setFont(new $classfontname(7)); $axis->title->setAngle(90); - + } } @@ -799,92 +808,92 @@ registerClass('PlotAxis'); * @package Artichow */ class awPlotGroup extends awComponentGroup { - + /** * Grid properties * * @var Grid */ var $grid; - + /** * Left, right, top and bottom axis * * @var PlotAxis */ var $axis; - + /** * Set the X axis on zero * * @var bool */ var $xAxisZero = TRUE; - + /** * Set the Y axis on zero * * @var bool */ var $yAxisZero = FALSE; - + /** * Real axis used for Y axis * * @var string */ var $yRealAxis = PLOT_LEFT; - + /** * Real axis used for X axis * * @var string */ var $xRealAxis = PLOT_BOTTOM; - + /** * Change min value for Y axis * * @var mixed */ var $yMin = NULL; - + /** * Change max value for Y axis * * @var mixed */ var $yMax = NULL; - + /** * Change min value for X axis * * @var mixed */ var $xMin = NULL; - + /** * Change max value for X axis * * @var mixed */ var $xMax = NULL; - + /** * Build the PlotGroup * */ function awPlotGroup() { - + parent::awComponentGroup(); - + $this->grid = new awGrid; $this->grid->setBackgroundColor(new awWhite); - + $this->axis = new awPlotAxis; - + } - + /** * Set the X axis on zero or not * @@ -893,7 +902,7 @@ class awPlotGroup extends awComponentGroup { function setXAxisZero($zero) { $this->xAxisZero = (bool)$zero; } - + /** * Set the Y axis on zero or not * @@ -902,7 +911,7 @@ class awPlotGroup extends awComponentGroup { function setYAxisZero($zero) { $this->yAxisZero = (bool)$zero; } - + /** * Change min value for Y axis * Set NULL for auto selection. @@ -914,7 +923,7 @@ class awPlotGroup extends awComponentGroup { $this->axis->right->auto(FALSE); $this->yMin = $value; } - + /** * Change max value for Y axis * Set NULL for auto selection. @@ -926,7 +935,7 @@ class awPlotGroup extends awComponentGroup { $this->axis->right->auto(FALSE); $this->yMax = $value; } - + /** * Change min value for X axis * Set NULL for auto selection. @@ -936,7 +945,7 @@ class awPlotGroup extends awComponentGroup { function setXMin($value) { $this->xMin = $value; } - + /** * Change max value for X axis * Set NULL for auto selection. @@ -946,31 +955,31 @@ class awPlotGroup extends awComponentGroup { function setXMax($value) { $this->xMax = $value; } - + /** * Get min value for X axis * * @return float $value */ function getXMin() { - + return $this->getX('min'); - + } - + /** * Get max value for X axis * * @return float $value */ function getXMax() { - + return $this->getX('max'); - + } - + function getX($type) { - + switch($type) { case 'max' : if($this->xMax !== NULL) { @@ -983,26 +992,26 @@ class awPlotGroup extends awComponentGroup { } break; } - + $value = NULL; $get = 'getX'.ucfirst($type); - + for($i = 0; $i < count($this->components); $i++) { - + $component = $this->components[$i]; - + if($value === NULL) { $value = $component->$get(); } else { $value = $type($value, $component->$get()); } - + } - + return $value; - + } - + /** * Get min value with spaces for Y axis * @@ -1010,23 +1019,23 @@ class awPlotGroup extends awComponentGroup { * @return float $value */ function getRealYMin($axis = NULL) { - + if($axis === NULL) { return NULL; } - + $min = $this->getRealY('min', $axis); $max = $this->getRealY('max', $axis); - + if($this->space->bottom !== NULL) { $interval = ($min - $max) * $this->space->bottom / 100; return $min + $interval; } else { return $min; } - + } - + /** * Get max value with spaces for Y axis * @@ -1034,25 +1043,25 @@ class awPlotGroup extends awComponentGroup { * @return float $value */ function getRealYMax($axis = NULL) { - + if($axis === NULL) { return NULL; } - + $min = $this->getRealY('min', $axis); $max = $this->getRealY('max', $axis); - + if($this->space->top !== NULL) { $interval = ($max - $min) * $this->space->top / 100; return $max + $interval; } else { return $max; } - + } - + function getRealY($type, $axis) { - + switch($type) { case 'max' : if($this->yMax !== NULL) { @@ -1065,25 +1074,25 @@ class awPlotGroup extends awComponentGroup { } break; } - + $value = NULL; $get = 'getY'.ucfirst($type); - + for($i = 0; $i < count($this->components); $i++) { - + $component = $this->components[$i]; - + switch($axis) { - + case PLOT_LEFT : case PLOT_RIGHT : $test = ($component->getYAxis() === $axis); break; default : $test = FALSE; - + } - + if($test) { if($value === NULL) { $value = $component->$get(); @@ -1091,103 +1100,103 @@ class awPlotGroup extends awComponentGroup { $value = $type($value, $component->$get()); } } - + } - + return $value; - + } - + function init($drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + // Get PlotGroup space list($leftSpace, $rightSpace, $topSpace, $bottomSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + // Count values in the group $values = $this->getXAxisNumber(); - + // Init the PlotGroup $this->axis->top->line->setX($x1, $x2); $this->axis->bottom->line->setX($x1, $x2); $this->axis->left->line->setY($y2, $y1); $this->axis->right->line->setY($y2, $y1); - + $this->axis->top->setPadding($leftSpace, $rightSpace); $this->axis->bottom->setPadding($leftSpace, $rightSpace); - + $xMin = $this->getXMin(); $xMax = $this->getXMax(); - + $this->axis->top->setRange($xMin, $xMax); $this->axis->bottom->setRange($xMin, $xMax); - + for($i = 0; $i < count($this->components); $i++) { - - + + $component = &$this->components[$i]; - + $component->auto($this->auto); - + // Copy space to the component - + $component->setSpace($this->space->left, $this->space->right, $this->space->top, $this->space->bottom); - + $component->xAxis->setPadding($leftSpace, $rightSpace); $component->xAxis->line->setX($x1, $x2); - + $component->yAxis->line->setY($y2, $y1); - + } - + // Set Y axis range foreach(array('left', 'right') as $axis) { - + if($this->isAxisUsed($axis)) { - + $min = $this->getRealYMin($axis); $max = $this->getRealYMax($axis); - + $interval = $max - $min; - + $this->axis->{$axis}->setRange( $min - $interval * $this->space->bottom / 100, $max + $interval * $this->space->top / 100 ); - + // Auto-scaling mode $this->axis->{$axis}->autoScale(); - + } - + } - + if($this->axis->left->getLabelNumber() === NULL) { $number = round(($y2 - $y1) / 75) + 2; $this->axis->left->setLabelNumber($number); } - + if($this->axis->right->getLabelNumber() === NULL) { $number = round(($y2 - $y1) / 75) + 2; $this->axis->right->setLabelNumber($number); } - + // Center labels on X axis if needed $test = array(PLOT_TOP => FALSE, PLOT_BOTTOM => FALSE); - + for($i = 0; $i < count($this->components); $i++) { - - + + $component = &$this->components[$i]; - - + + if($component->getValues() !== NULL) { - + $axis = $component->getXAxis(); - + if($test[$axis] === FALSE) { - + // Center labels for bar plots if($component->getXCenter()) { $size = $this->axis->{$axis}->getDistance(0, 1); @@ -1195,14 +1204,14 @@ class awPlotGroup extends awComponentGroup { $this->axis->{$axis}->label->hideLast(TRUE); $test[$axis] = TRUE; } - + } - + } - - + + } - + // Set axis labels $labels = array(); for($i = $xMin; $i <= $xMax; $i++) { @@ -1214,135 +1223,135 @@ class awPlotGroup extends awComponentGroup { if($this->axis->bottom->label->count() === 0) { $this->axis->bottom->label->set($labels); } - + // Set ticks - + $this->axis->top->ticks['major']->setNumber($values); $this->axis->bottom->ticks['major']->setNumber($values); $this->axis->left->ticks['major']->setNumber($this->axis->left->getLabelNumber()); $this->axis->right->ticks['major']->setNumber($this->axis->right->getLabelNumber()); - - + + // Set X axis on zero if($this->xAxisZero) { $axis = $this->selectYAxis(); $this->axis->bottom->setYCenter($axis, 0); $this->axis->top->setYCenter($axis, 0); } - + // Set Y axis on zero if($this->yAxisZero) { $axis = $this->selectXAxis(); $this->axis->left->setXCenter($axis, 1); $this->axis->right->setXCenter($axis, 1); } - + parent::init($drawer); - + list($leftSpace, $rightSpace, $topSpace, $bottomSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + // Create the grid $this->createGrid(); - + // Draw the grid $this->grid->setSpace($leftSpace, $rightSpace, 0, 0); $this->grid->draw($drawer, $x1, $y1, $x2, $y2); - + } - + function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) { - + $xMin = $this->getXMin(); $xMax = $this->getXMax(); - + $maxLeft = $this->getRealYMax(PLOT_LEFT); $maxRight = $this->getRealYMax(PLOT_RIGHT); - + $minLeft = $this->getRealYMin(PLOT_LEFT); $minRight = $this->getRealYMin(PLOT_RIGHT); - + foreach($this->components as $component) { - + $min = $component->getYMin(); $max = $component->getYMax(); - + // Set component minimum and maximum if($component->getYAxis() === PLOT_LEFT) { - + list($min, $max) = $this->axis->left->getRange(); - + $component->setYMin($min); $component->setYMax($max); - + } else { - + list($min, $max) = $this->axis->right->getRange(); - + $component->setYMin($min); $component->setYMax($max); - + } - + $component->setXAxisZero($this->xAxisZero); $component->setYAxisZero($this->yAxisZero); - + $component->xAxis->setRange($xMin, $xMax); - + $component->drawComponent( $drawer, $x1, $y1, $x2, $y2, $aliasing ); - + $component->setYMin($min); $component->setYMax($max); - + } - + } - + function drawEnvelope($drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + // Hide unused axis foreach(array(PLOT_LEFT, PLOT_RIGHT, PLOT_TOP, PLOT_BOTTOM) as $axis) { if($this->isAxisUsed($axis) === FALSE) { $this->axis->{$axis}->hide(TRUE); } } - + // Draw top axis $top = $this->axis->top; if($this->xAxisZero === FALSE) { $top->line->setY($y1, $y1); } $top->draw($drawer); - + // Draw bottom axis $bottom = $this->axis->bottom; if($this->xAxisZero === FALSE) { $bottom->line->setY($y2, $y2); } $bottom->draw($drawer); - + // Draw left axis $left = $this->axis->left; if($this->yAxisZero === FALSE) { $left->line->setX($x1, $x1); } $left->draw($drawer); - + // Draw right axis $right = $this->axis->right; if($this->yAxisZero === FALSE) { $right->line->setX($x2, $x2); } $right->draw($drawer); - + } - + /** * Is the specified axis used ? * @@ -1350,104 +1359,104 @@ class awPlotGroup extends awComponentGroup { * @return bool */ function isAxisUsed($axis) { - + for($i = 0; $i < count($this->components); $i++) { - + $component = $this->components[$i]; - + switch($axis) { - + case PLOT_LEFT : case PLOT_RIGHT : if($component->getYAxis() === $axis) { return TRUE; } break; - + case PLOT_TOP : case PLOT_BOTTOM : if($component->getXAxis() === $axis) { return TRUE; } break; - + } - + } - + return FALSE; - + } - + function createGrid() { - + $max = $this->getRealYMax(PLOT_LEFT); $min = $this->getRealYMin(PLOT_RIGHT); - + // Select axis (left if possible, right otherwise) $axis = $this->selectYAxis(); - + $number = $axis->getLabelNumber() - 1; - + if($number < 1) { return; } - + // Horizontal lines of grid - + $h = array(); for($i = 0; $i <= $number; $i++) { $h[] = $i / $number; } - + // Vertical lines - + $major = $axis->tick('major'); $interval = $major->getInterval(); $number = $this->getXAxisNumber() - 1; - + $w = array(); - + if($number > 0) { - + for($i = 0; $i <= $number; $i++) { if($i%$interval === 0) { $w[] = $i / $number; } } - + } - + $this->grid->setGrid($w, $h); - + } - + function selectYAxis(){ - + // Select axis (left if possible, right otherwise) if($this->isAxisUsed(PLOT_LEFT)) { $axis = $this->axis->left; } else { $axis = $this->axis->right; } - + return $axis; - + } - + function selectXAxis(){ - + // Select axis (bottom if possible, top otherwise) if($this->isAxisUsed(PLOT_BOTTOM)) { $axis = $this->axis->bottom; } else { $axis = $this->axis->top; } - + return $axis; - + } - + function getXAxisNumber() { $offset = $this->components[0]; $max = $offset->getXAxisNumber(); diff --git a/htdocs/includes/artichow/php5/Component.class.php b/htdocs/includes/artichow/php5/Component.class.php index 997c2ddb5c8..431a7ec35bc 100644 --- a/htdocs/includes/artichow/php5/Component.class.php +++ b/htdocs/includes/artichow/php5/Component.class.php @@ -6,7 +6,7 @@ * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. * */ - + require_once dirname(__FILE__)."/Graph.class.php"; @@ -23,7 +23,7 @@ abstract class awComponentGroup extends awComponent { * @var array */ protected $components; - + /** * Build the component group */ @@ -81,7 +81,7 @@ abstract class awComponent { * @var float */ public $y = 0.5; - + /** * Component absolute width (in pixels) * @@ -89,7 +89,7 @@ abstract class awComponent { * @var int */ public $w; - + /** * Component absolute height (in pixels) * @@ -111,71 +111,75 @@ abstract class awComponent { * @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 awTuffy(10), + new $classfontname(10), NULL, 0 ); $this->title->setAlign(awLabel::CENTER, awLabel::TOP); - + } - + /** * Adjust automatically the component ? * @@ -184,7 +188,7 @@ abstract class awComponent { public function auto($auto) { $this->auto = (bool)$auto; } - + /** * Change the size of the component * @@ -192,12 +196,12 @@ abstract class awComponent { * @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 * @@ -205,12 +209,12 @@ abstract class awComponent { * @param int $h Component height (in pixels) */ public function setAbsSize($w, $h) { - + $this->w = (int)$w; $this->h = (int)$h; - + } - + /** * Change component background color * @@ -221,7 +225,7 @@ abstract class awComponent { $this->background = $color; } } - + /** * Change component background gradient * @@ -232,7 +236,7 @@ abstract class awComponent { $this->background = $gradient; } } - + /** * Change component background image * @@ -243,7 +247,7 @@ abstract class awComponent { $this->background = $image; } } - + /** * Return the component background * @@ -252,7 +256,7 @@ abstract class awComponent { public function getBackground() { return $this->background; } - + /** * Change component padding * @@ -264,7 +268,7 @@ abstract class awComponent { public function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) { $this->padding->set($left, $right, $top, $bottom); } - + /** * Change component space * @@ -276,7 +280,7 @@ abstract class awComponent { 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 * @@ -284,12 +288,12 @@ abstract class awComponent { * @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 * @@ -297,29 +301,29 @@ abstract class awComponent { * @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 */ @@ -327,49 +331,49 @@ abstract class awComponent { // 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 * @@ -377,7 +381,7 @@ abstract class awComponent { * @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 @@ -390,7 +394,7 @@ abstract class awComponent { * @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 * @@ -399,16 +403,16 @@ abstract class awComponent { * @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); diff --git a/htdocs/includes/artichow/php5/Graph.class.php b/htdocs/includes/artichow/php5/Graph.class.php index 6370ec837de..5f26f0f4785 100644 --- a/htdocs/includes/artichow/php5/Graph.class.php +++ b/htdocs/includes/artichow/php5/Graph.class.php @@ -34,7 +34,7 @@ require_once ARTICHOW."/inc/Font.class.php"; require_once ARTICHOW."/inc/Gradient.class.php"; /** - * A graph + * A graph * * @package Artichow */ @@ -53,35 +53,35 @@ class awGraph extends awImage { * @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 * @@ -91,29 +91,33 @@ class awGraph extends awImage { * @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 { @@ -121,23 +125,23 @@ class awGraph extends awImage { readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name.""); exit; } - + } - + } - + } - + $this->title = new awLabel( NULL, - new awTuffy(16), + new $classfontname(16), NULL, 0 ); $this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM); - + } - + /** * Delete a graph from the cache * @@ -147,59 +151,59 @@ class awGraph extends awImage { 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 * @@ -208,18 +212,18 @@ class awGraph extends awImage { 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 * @@ -228,13 +232,13 @@ class awGraph extends awImage { * @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 * @@ -242,13 +246,13 @@ class awGraph extends awImage { * @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 @@ -256,23 +260,23 @@ class awGraph extends awImage { * @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); } @@ -280,104 +284,104 @@ class awGraph extends awImage { 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; } - - + + } } @@ -387,8 +391,8 @@ registerClass('Graph'); /* * To preserve PHP 4 compatibility */ -function microtimeFloat() { - list($usec, $sec) = explode(" ", microtime()); - return (float)$usec + (float)$sec; +function microtimeFloat() { + list($usec, $sec) = explode(" ", microtime()); + return (float)$usec + (float)$sec; } ?> diff --git a/htdocs/includes/artichow/php5/MathPlot.class.php b/htdocs/includes/artichow/php5/MathPlot.class.php index 415ceaa3f97..a2f41421254 100644 --- a/htdocs/includes/artichow/php5/MathPlot.class.php +++ b/htdocs/includes/artichow/php5/MathPlot.class.php @@ -22,28 +22,28 @@ class awMathFunction implements awLegendable { * @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 * @@ -57,7 +57,7 @@ class awMathFunction implements awLegendable { * @var Color */ protected $color; - + /** * Construct the function * @@ -66,17 +66,17 @@ class awMathFunction implements awLegendable { * @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 * @@ -85,7 +85,7 @@ class awMathFunction implements awLegendable { public function setColor(awColor $color) { $this->color = $color; } - + /** * Get line color * @@ -142,56 +142,56 @@ class awMathFunction implements awLegendable { } 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 * @@ -201,44 +201,47 @@ class awMathPlot extends awComponent { * @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 awTuffy(7)); - + $axis->label->setFont(new $classfontname(7)); + } - + /** * Interval to calculate values * @@ -247,7 +250,7 @@ class awMathPlot extends awComponent { public function setInterval($interval) { $this->interval = (float)$interval; } - + /** * Add a formula f(x) * @@ -256,44 +259,44 @@ class awMathPlot extends awComponent { * @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 /* */ $this->xAxis->tick('major')->setNumber($this->xAxis->getLabelNumber()); @@ -303,61 +306,61 @@ class awMathPlot extends awComponent { $this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber()); $this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber()); -- */ - + // 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) @@ -367,26 +370,26 @@ class awMathPlot extends awComponent { $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) @@ -396,34 +399,34 @@ class awMathPlot extends awComponent { $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++) { @@ -432,9 +435,9 @@ class awMathPlot extends awComponent { } } } - + $this->grid->setGrid($w, $h); - + } } diff --git a/htdocs/includes/artichow/php5/Plot.class.php b/htdocs/includes/artichow/php5/Plot.class.php index 5076fe731a4..5e3ae8b7e63 100644 --- a/htdocs/includes/artichow/php5/Plot.class.php +++ b/htdocs/includes/artichow/php5/Plot.class.php @@ -8,7 +8,7 @@ */ require_once dirname(__FILE__)."/Component.class.php"; - + /* */ define("PLOT_LEFT", 'left'); @@ -18,14 +18,14 @@ define("PLOT_BOTTOM", 'bottom'); define("PLOT_BOTH", 'both'); /* */ - + /** * Graph using X and Y axis * * @package Artichow */ abstract class awPlot extends awComponent { - + /** * Values for Y axis * @@ -39,149 +39,152 @@ abstract class awPlot extends awComponent { * @var array */ protected $datax; - + /** * Grid properties * * @var Grid */ public $grid; - + /** * X axis * * @var Axis */ public $xAxis; - + /** * Y axis * * @var Axis */ public $yAxis; - + /** * Position of X axis * * @var int */ protected $xAxisPosition = awPlot::BOTTOM; - + /** * Set X axis on zero ? * * @var bool */ protected $xAxisZero = TRUE; - + /** * Set Y axis on zero ? * * @var bool */ protected $yAxisZero = FALSE; - + /** * Position of Y axis * * @var int */ protected $yAxisPosition = awPlot::LEFT; - + /** * Change min value for Y axis * * @var mixed */ private $yMin = NULL; - + /** * Change max value for Y axis * * @var mixed */ private $yMax = NULL; - + /** * Change min value for X axis * * @var mixed */ private $xMin = NULL; - + /** * Change max value for X axis * * @var mixed */ private $xMax = NULL; - + /** * Left axis * * @var int */ const LEFT = 'left'; - + /** * RIGHT axis * * @var int */ const RIGHT = 'right'; - + /** * Top axis * * @var int */ const TOP = 'top'; - + /** * Bottom axis * * @var int */ const BOTTOM = 'bottom'; - + /** * Both left/right or top/bottom axis * * @var int */ const BOTH = 'both'; - + /** * Build the plot * */ public function __construct() { - + // DOL_CHANGE LDR Fix to allow usage of other fonts + global $artichow_defaultfont; + $classfontname='aw'.str_replace('-','_',$artichow_defaultfont); + parent::__construct(); - + $this->grid = new awGrid; $this->grid->setBackgroundColor(new awWhite); $this->padding->add(20, 0, 0, 20); - + $this->xAxis = new awAxis; $this->xAxis->addTick('major', new awTick(0, 5)); $this->xAxis->addTick('minor', new awTick(0, 3)); $this->xAxis->setTickStyle(awTick::OUT); - $this->xAxis->label->setFont(new awTuffy(7)); - + $this->xAxis->label->setFont(new $classfontname(7)); + $this->yAxis = new awAxis; $this->yAxis->auto(TRUE); $this->yAxis->addTick('major', new awTick(0, 5)); $this->yAxis->addTick('minor', new awTick(0, 3)); $this->yAxis->setTickStyle(awTick::OUT); $this->yAxis->setNumberByTick('minor', 'major', 3); - $this->yAxis->label->setFont(new awTuffy(7)); + $this->yAxis->label->setFont(new $classfontname(7)); $this->yAxis->title->setAngle(90); - + } - + /** * Get plot values * @@ -190,48 +193,48 @@ abstract class awPlot extends awComponent { public function getValues() { return $this->datay; } - + /** * Reduce number of values in the plot * * @param int $number Reduce number of values to $number */ public function reduce($number) { - + $count = count($this->datay); $ratio = ceil($count / $number); - + if($ratio > 1) { - + $tmpy = $this->datay; $datay = array(); - + $datax = array(); $cbLabel = $this->xAxis->label->getCallbackFunction(); - + for($i = 0; $i < $count; $i += $ratio) { - + $slice = array_slice($tmpy, $i, $ratio); $datay[] = array_sum($slice) / count($slice); - + // Reduce data on X axis if needed if($cbLabel !== NULL) { $datax[] = $cbLabel($i + round($ratio / 2)); } - + } - + $this->setValues($datay); - + if($cbLabel !== NULL) { $this->xAxis->setLabelText($datax); } - - + + } - + } - + /** * Count values in the plot * @@ -241,7 +244,7 @@ abstract class awPlot extends awComponent { list($min, $max) = $this->xAxis->getRange(); return ($max - $min + 1); } - + /** * Change X axis * @@ -250,7 +253,7 @@ abstract class awPlot extends awComponent { public function setXAxis($axis) { $this->xAxisPosition = $axis; } - + /** * Get X axis * @@ -259,7 +262,7 @@ abstract class awPlot extends awComponent { public function getXAxis() { return $this->xAxisPosition; } - + /** * Set X axis on zero * @@ -268,7 +271,7 @@ abstract class awPlot extends awComponent { public function setXAxisZero($zero) { $this->xAxisZero = (bool)$zero; } - + /** * Set Y axis on zero * @@ -277,7 +280,7 @@ abstract class awPlot extends awComponent { public function setYAxisZero($zero) { $this->yAxisZero = (bool)$zero; } - + /** * Change Y axis * @@ -286,7 +289,7 @@ abstract class awPlot extends awComponent { public function setYAxis($axis) { $this->yAxisPosition = $axis; } - + /** * Get Y axis * @@ -295,7 +298,7 @@ abstract class awPlot extends awComponent { public function getYAxis() { return $this->yAxisPosition; } - + /** * Change min value for Y axis * Set NULL for auto selection. @@ -307,7 +310,7 @@ abstract class awPlot extends awComponent { $this->yAxis->auto(FALSE); $this->updateAxis(); } - + /** * Change max value for Y axis * Set NULL for auto selection. @@ -319,7 +322,7 @@ abstract class awPlot extends awComponent { $this->yAxis->auto(FALSE); $this->updateAxis(); } - + /** * Change min value for X axis * Set NULL for auto selection. @@ -330,7 +333,7 @@ abstract class awPlot extends awComponent { $this->xMin = $value; $this->updateAxis(); } - + /** * Change max value for X axis * Set NULL for auto selection. @@ -341,7 +344,7 @@ abstract class awPlot extends awComponent { $this->xMax = $value; $this->updateAxis(); } - + /** * Get min value for Y axis * @@ -358,7 +361,7 @@ abstract class awPlot extends awComponent { } return is_null($this->yMin) ? array_min($this->datay) : (float)$this->yMin; } - + /** * Get max value for Y axis * @@ -375,7 +378,7 @@ abstract class awPlot extends awComponent { } return is_null($this->yMax) ? array_max($this->datay) : (float)$this->yMax; } - + /** * Get min value for X axis * @@ -384,7 +387,7 @@ abstract class awPlot extends awComponent { public function getXMin() { return floor(is_null($this->xMin) ? array_min($this->datax) : $this->xMin); } - + /** * Get max value for X axis * @@ -393,7 +396,7 @@ abstract class awPlot extends awComponent { public function getXMax() { return (ceil(is_null($this->xMax) ? array_max($this->datax) : (float)$this->xMax)) + ($this->getXCenter() ? 1 : 0); } - + /** * Get min value with spaces for Y axis * @@ -408,7 +411,7 @@ abstract class awPlot extends awComponent { return is_null($this->yMin) ? $min : (float)$this->yMin; } } - + /** * Get max value with spaces for Y axis * @@ -423,40 +426,40 @@ abstract class awPlot extends awComponent { return is_null($this->yMax) ? $max : (float)$this->yMax; } } - + public function init(awDrawer $drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + // Get space informations list($leftSpace, $rightSpace, $topSpace, $bottomSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + $this->xAxis->setPadding($leftSpace, $rightSpace); - + if($this->space->bottom > 0 or $this->space->top > 0) { - + list($min, $max) = $this->yAxis->getRange(); $interval = $max - $min; - + $this->yAxis->setRange( $min - $interval * $this->space->bottom / 100, $max + $interval * $this->space->top / 100 ); - + } - + // Auto-scaling mode $this->yAxis->autoScale(); - + // Number of labels is not specified if($this->yAxis->getLabelNumber() === NULL) { $number = round(($y2 - $y1) / 75) + 2; $this->yAxis->setLabelNumber($number); } - + $this->xAxis->line->setX($x1, $x2); $this->yAxis->line->setY($y2, $y1); - + // Set ticks /* */ $this->xAxis->tick('major')->setNumber($this->getXAxisNumber()); @@ -466,49 +469,49 @@ abstract class awPlot extends awComponent { $this->xAxis->ticks['major']->setNumber($this->getXAxisNumber()); $this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber()); -- */ - + // Center X axis on zero if($this->xAxisZero) { $this->xAxis->setYCenter($this->yAxis, 0); } - + // Center Y axis on zero if($this->yAxisZero) { $this->yAxis->setXCenter($this->xAxis, 0); } - + // Set axis labels $labels = array(); for($i = 0, $count = $this->getXAxisNumber(); $i < $count; $i++) { $labels[] = $i; } $this->xAxis->label->set($labels); - + parent::init($drawer); - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + list($leftSpace, $rightSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + // Create the grid $this->createGrid(); - + // Draw the grid $this->grid->setSpace($leftSpace, $rightSpace, 0, 0); $this->grid->draw($drawer, $x1, $y1, $x2, $y2); - + } - + public function drawEnvelope(awDrawer $drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + if($this->getXCenter()) { $size = $this->xAxis->getDistance(0, 1); $this->xAxis->label->move($size / 2, 0); $this->xAxis->label->hideLast(TRUE); } - + // Draw top axis if($this->xAxisPosition === awPlot::TOP or $this->xAxisPosition === awPlot::BOTH) { $top = clone $this->xAxis; @@ -520,7 +523,7 @@ abstract class awPlot extends awComponent { $top->title->move(0, -25); $top->draw($drawer); } - + // Draw bottom axis if($this->xAxisPosition === awPlot::BOTTOM or $this->xAxisPosition === awPlot::BOTH) { $bottom = clone $this->xAxis; @@ -533,7 +536,7 @@ abstract class awPlot extends awComponent { $bottom->title->move(0, 25); $bottom->draw($drawer); } - + // Draw left axis if($this->yAxisPosition === awPlot::LEFT or $this->yAxisPosition === awPlot::BOTH) { $left = clone $this->yAxis; @@ -545,7 +548,7 @@ abstract class awPlot extends awComponent { $left->title->move(-25, 0); $left->draw($drawer); } - + // Draw right axis if($this->yAxisPosition === awPlot::RIGHT or $this->yAxisPosition === awPlot::BOTH) { $right = clone $this->yAxis; @@ -558,49 +561,49 @@ abstract class awPlot extends awComponent { $right->title->move(25, 0); $right->draw($drawer); } - + } - + protected function createGrid() { - + $max = $this->getRealYMax(); $min = $this->getRealYMin(); $number = $this->yAxis->getLabelNumber() - 1; - + if($number < 1) { return; } - + // Horizontal lines of the grid - + $h = array(); for($i = 0; $i <= $number; $i++) { $h[] = $i / $number; } - + // Vertical lines - + $major = $this->yAxis->tick('major'); $interval = $major->getInterval(); $number = $this->getXAxisNumber() - 1; - + $w = array(); - + if($number > 0) { - + for($i = 0; $i <= $number; $i++) { if($i%$interval === 0) { $w[] = $i / $number; } } - + } - + $this->grid->setGrid($w, $h); - + } - + /** * Change values of Y axis * This method ignores not numeric values @@ -609,14 +612,14 @@ abstract class awPlot extends awComponent { * @param array $datax */ public function setValues($datay, $datax = NULL) { - + $this->checkArray($datay); - + foreach($datay as $key => $value) { unset($datay[$key]); $datay[(int)$key] = $value; } - + if($datax === NULL) { $datax = array(); for($i = 0; $i < count($datay); $i++) { @@ -628,11 +631,11 @@ abstract class awPlot extends awComponent { $datax[(int)$key] = $value; } } - + $this->checkArray($datax); - + if(count($datay) === count($datax)) { - + // Set values $this->datay = $datay; $this->datax = $datax; @@ -641,16 +644,16 @@ abstract class awPlot extends awComponent { } else { trigger_error("Plots must have the same number of X and Y points", E_USER_ERROR); } - + } - + /** * Return begin and end values * * @return array */ protected function getLimit() { - + $i = 0; while(array_key_exists($i, $this->datay) and $this->datay[$i] === NULL) { $i++; @@ -661,20 +664,20 @@ abstract class awPlot extends awComponent { $i--; } $stop = $i; - + return array($start, $stop); - + } - + /** * Return TRUE if labels must be centered on X axis, FALSE otherwise * * @return bool */ abstract public function getXCenter(); - + private function updateAxis() { - + $this->xAxis->setRange( $this->getXMin(), $this->getXMax() @@ -683,25 +686,25 @@ abstract class awPlot extends awComponent { $this->getRealYMin(), $this->getRealYMax() ); - + } - + private function checkArray(&$array) { - + if(is_array($array) === FALSE) { trigger_error("You tried to set a value that is not an array", E_USER_ERROR); } - + foreach($array as $key => $value) { if(is_numeric($value) === FALSE and is_null($value) === FALSE) { trigger_error("Expected numeric values for the plot", E_USER_ERROR); } } - + if(count($array) < 1) { trigger_error("Your plot must have at least 1 value", E_USER_ERROR); } - + } } @@ -742,7 +745,7 @@ class awPlotAxis { * Build the group of axis */ public function __construct() { - + $this->left = new awAxis; $this->left->auto(TRUE); $this->left->label->setAlign(awLabel::RIGHT); @@ -750,7 +753,7 @@ class awPlotAxis { $this->yAxis($this->left); $this->left->setTickStyle(awTick::OUT); $this->left->title->move(-25, 0); - + $this->right = new awAxis; $this->right->auto(TRUE); $this->right->label->setAlign(awLabel::LEFT); @@ -758,39 +761,45 @@ class awPlotAxis { $this->yAxis($this->right); $this->right->setTickStyle(awTick::IN); $this->right->title->move(25, 0); - + $this->top = new awAxis; $this->top->label->setAlign(NULL, awLabel::TOP); $this->top->label->move(0, -3); $this->xAxis($this->top); $this->top->setTickStyle(awTick::OUT); $this->top->title->move(0, -25); - + $this->bottom = new awAxis; $this->bottom->label->setAlign(NULL, awLabel::BOTTOM); $this->bottom->label->move(0, 3); $this->xAxis($this->bottom); $this->bottom->setTickStyle(awTick::IN); $this->bottom->title->move(0, 25); - + } - + protected function xAxis(awAxis $axis) { - + // DOL_CHANGE LDR Fix to allow usage of other fonts + global $artichow_defaultfont; + $classfontname='aw'.str_replace('-','_',$artichow_defaultfont); + $axis->addTick('major', new awTick(0, 5)); $axis->addTick('minor', new awTick(0, 3)); - $axis->label->setFont(new awTuffy(7)); - + $axis->label->setFont(new $classfontname(7)); + } - + protected function yAxis(awAxis $axis) { - + // DOL_CHANGE LDR Fix to allow usage of other fonts + global $artichow_defaultfont; + $classfontname='aw'.str_replace('-','_',$artichow_defaultfont); + $axis->addTick('major', new awTick(0, 5)); $axis->addTick('minor', new awTick(0, 3)); $axis->setNumberByTick('minor', 'major', 3); - $axis->label->setFont(new awTuffy(7)); + $axis->label->setFont(new $classfontname(7)); $axis->title->setAngle(90); - + } } @@ -803,92 +812,92 @@ registerClass('PlotAxis'); * @package Artichow */ class awPlotGroup extends awComponentGroup { - + /** * Grid properties * * @var Grid */ public $grid; - + /** * Left, right, top and bottom axis * * @var PlotAxis */ public $axis; - + /** * Set the X axis on zero * * @var bool */ protected $xAxisZero = TRUE; - + /** * Set the Y axis on zero * * @var bool */ protected $yAxisZero = FALSE; - + /** * Real axis used for Y axis * * @var string */ private $yRealAxis = awPlot::LEFT; - + /** * Real axis used for X axis * * @var string */ private $xRealAxis = awPlot::BOTTOM; - + /** * Change min value for Y axis * * @var mixed */ private $yMin = NULL; - + /** * Change max value for Y axis * * @var mixed */ private $yMax = NULL; - + /** * Change min value for X axis * * @var mixed */ private $xMin = NULL; - + /** * Change max value for X axis * * @var mixed */ private $xMax = NULL; - + /** * Build the PlotGroup * */ public function __construct() { - + parent::__construct(); - + $this->grid = new awGrid; $this->grid->setBackgroundColor(new awWhite); - + $this->axis = new awPlotAxis; - + } - + /** * Set the X axis on zero or not * @@ -897,7 +906,7 @@ class awPlotGroup extends awComponentGroup { public function setXAxisZero($zero) { $this->xAxisZero = (bool)$zero; } - + /** * Set the Y axis on zero or not * @@ -906,7 +915,7 @@ class awPlotGroup extends awComponentGroup { public function setYAxisZero($zero) { $this->yAxisZero = (bool)$zero; } - + /** * Change min value for Y axis * Set NULL for auto selection. @@ -918,7 +927,7 @@ class awPlotGroup extends awComponentGroup { $this->axis->right->auto(FALSE); $this->yMin = $value; } - + /** * Change max value for Y axis * Set NULL for auto selection. @@ -930,7 +939,7 @@ class awPlotGroup extends awComponentGroup { $this->axis->right->auto(FALSE); $this->yMax = $value; } - + /** * Change min value for X axis * Set NULL for auto selection. @@ -940,7 +949,7 @@ class awPlotGroup extends awComponentGroup { public function setXMin($value) { $this->xMin = $value; } - + /** * Change max value for X axis * Set NULL for auto selection. @@ -950,31 +959,31 @@ class awPlotGroup extends awComponentGroup { public function setXMax($value) { $this->xMax = $value; } - + /** * Get min value for X axis * * @return float $value */ public function getXMin() { - + return $this->getX('min'); - + } - + /** * Get max value for X axis * * @return float $value */ public function getXMax() { - + return $this->getX('max'); - + } - + private function getX($type) { - + switch($type) { case 'max' : if($this->xMax !== NULL) { @@ -987,26 +996,26 @@ class awPlotGroup extends awComponentGroup { } break; } - + $value = NULL; $get = 'getX'.ucfirst($type); - + for($i = 0; $i < count($this->components); $i++) { - + $component = $this->components[$i]; - + if($value === NULL) { $value = $component->$get(); } else { $value = $type($value, $component->$get()); } - + } - + return $value; - + } - + /** * Get min value with spaces for Y axis * @@ -1014,23 +1023,23 @@ class awPlotGroup extends awComponentGroup { * @return float $value */ public function getRealYMin($axis = NULL) { - + if($axis === NULL) { return NULL; } - + $min = $this->getRealY('min', $axis); $max = $this->getRealY('max', $axis); - + if($this->space->bottom !== NULL) { $interval = ($min - $max) * $this->space->bottom / 100; return $min + $interval; } else { return $min; } - + } - + /** * Get max value with spaces for Y axis * @@ -1038,25 +1047,25 @@ class awPlotGroup extends awComponentGroup { * @return float $value */ public function getRealYMax($axis = NULL) { - + if($axis === NULL) { return NULL; } - + $min = $this->getRealY('min', $axis); $max = $this->getRealY('max', $axis); - + if($this->space->top !== NULL) { $interval = ($max - $min) * $this->space->top / 100; return $max + $interval; } else { return $max; } - + } - + private function getRealY($type, $axis) { - + switch($type) { case 'max' : if($this->yMax !== NULL) { @@ -1069,25 +1078,25 @@ class awPlotGroup extends awComponentGroup { } break; } - + $value = NULL; $get = 'getY'.ucfirst($type); - + for($i = 0; $i < count($this->components); $i++) { - + $component = $this->components[$i]; - + switch($axis) { - + case awPlot::LEFT : case awPlot::RIGHT : $test = ($component->getYAxis() === $axis); break; default : $test = FALSE; - + } - + if($test) { if($value === NULL) { $value = $component->$get(); @@ -1095,40 +1104,40 @@ class awPlotGroup extends awComponentGroup { $value = $type($value, $component->$get()); } } - + } - + return $value; - + } - + public function init(awDrawer $drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + // Get PlotGroup space list($leftSpace, $rightSpace, $topSpace, $bottomSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + // Count values in the group $values = $this->getXAxisNumber(); - + // Init the PlotGroup $this->axis->top->line->setX($x1, $x2); $this->axis->bottom->line->setX($x1, $x2); $this->axis->left->line->setY($y2, $y1); $this->axis->right->line->setY($y2, $y1); - + $this->axis->top->setPadding($leftSpace, $rightSpace); $this->axis->bottom->setPadding($leftSpace, $rightSpace); - + $xMin = $this->getXMin(); $xMax = $this->getXMax(); - + $this->axis->top->setRange($xMin, $xMax); $this->axis->bottom->setRange($xMin, $xMax); - + for($i = 0; $i < count($this->components); $i++) { - + /* */ $component = $this->components[$i]; /* */ @@ -1136,68 +1145,68 @@ class awPlotGroup extends awComponentGroup { $component = &$this->components[$i]; -- */ $component->auto($this->auto); - + // Copy space to the component - + $component->setSpace($this->space->left, $this->space->right, $this->space->top, $this->space->bottom); - + $component->xAxis->setPadding($leftSpace, $rightSpace); $component->xAxis->line->setX($x1, $x2); - + $component->yAxis->line->setY($y2, $y1); - + } - + // Set Y axis range foreach(array('left', 'right') as $axis) { - + if($this->isAxisUsed($axis)) { - + $min = $this->getRealYMin($axis); $max = $this->getRealYMax($axis); - + $interval = $max - $min; - + $this->axis->{$axis}->setRange( $min - $interval * $this->space->bottom / 100, $max + $interval * $this->space->top / 100 ); - + // Auto-scaling mode $this->axis->{$axis}->autoScale(); - + } - + } - + if($this->axis->left->getLabelNumber() === NULL) { $number = round(($y2 - $y1) / 75) + 2; $this->axis->left->setLabelNumber($number); } - + if($this->axis->right->getLabelNumber() === NULL) { $number = round(($y2 - $y1) / 75) + 2; $this->axis->right->setLabelNumber($number); } - + // Center labels on X axis if needed $test = array(awPlot::TOP => FALSE, awPlot::BOTTOM => FALSE); - + for($i = 0; $i < count($this->components); $i++) { - + /* */ $component = $this->components[$i]; /* */ /* -- $component = &$this->components[$i]; -- */ - + if($component->getValues() !== NULL) { - + $axis = $component->getXAxis(); - + if($test[$axis] === FALSE) { - + // Center labels for bar plots if($component->getXCenter()) { $size = $this->axis->{$axis}->getDistance(0, 1); @@ -1205,14 +1214,14 @@ class awPlotGroup extends awComponentGroup { $this->axis->{$axis}->label->hideLast(TRUE); $test[$axis] = TRUE; } - + } - + } - - + + } - + // Set axis labels $labels = array(); for($i = $xMin; $i <= $xMax; $i++) { @@ -1224,7 +1233,7 @@ class awPlotGroup extends awComponentGroup { if($this->axis->bottom->label->count() === 0) { $this->axis->bottom->label->set($labels); } - + // Set ticks /* */ $this->axis->top->tick('major')->setNumber($values); @@ -1238,127 +1247,127 @@ class awPlotGroup extends awComponentGroup { $this->axis->left->ticks['major']->setNumber($this->axis->left->getLabelNumber()); $this->axis->right->ticks['major']->setNumber($this->axis->right->getLabelNumber()); -- */ - + // Set X axis on zero if($this->xAxisZero) { $axis = $this->selectYAxis(); $this->axis->bottom->setYCenter($axis, 0); $this->axis->top->setYCenter($axis, 0); } - + // Set Y axis on zero if($this->yAxisZero) { $axis = $this->selectXAxis(); $this->axis->left->setXCenter($axis, 1); $this->axis->right->setXCenter($axis, 1); } - + parent::init($drawer); - + list($leftSpace, $rightSpace, $topSpace, $bottomSpace) = $this->getSpace($x2 - $x1, $y2 - $y1); - + // Create the grid $this->createGrid(); - + // Draw the grid $this->grid->setSpace($leftSpace, $rightSpace, 0, 0); $this->grid->draw($drawer, $x1, $y1, $x2, $y2); - + } - + public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) { - + $xMin = $this->getXMin(); $xMax = $this->getXMax(); - + $maxLeft = $this->getRealYMax(awPlot::LEFT); $maxRight = $this->getRealYMax(awPlot::RIGHT); - + $minLeft = $this->getRealYMin(awPlot::LEFT); $minRight = $this->getRealYMin(awPlot::RIGHT); - + foreach($this->components as $component) { - + $min = $component->getYMin(); $max = $component->getYMax(); - + // Set component minimum and maximum if($component->getYAxis() === awPlot::LEFT) { - + list($min, $max) = $this->axis->left->getRange(); - + $component->setYMin($min); $component->setYMax($max); - + } else { - + list($min, $max) = $this->axis->right->getRange(); - + $component->setYMin($min); $component->setYMax($max); - + } - + $component->setXAxisZero($this->xAxisZero); $component->setYAxisZero($this->yAxisZero); - + $component->xAxis->setRange($xMin, $xMax); - + $component->drawComponent( $drawer, $x1, $y1, $x2, $y2, $aliasing ); - + $component->setYMin($min); $component->setYMax($max); - + } - + } - + public function drawEnvelope(awDrawer $drawer) { - + list($x1, $y1, $x2, $y2) = $this->getPosition(); - + // Hide unused axis foreach(array(awPlot::LEFT, awPlot::RIGHT, awPlot::TOP, awPlot::BOTTOM) as $axis) { if($this->isAxisUsed($axis) === FALSE) { $this->axis->{$axis}->hide(TRUE); } } - + // Draw top axis $top = $this->axis->top; if($this->xAxisZero === FALSE) { $top->line->setY($y1, $y1); } $top->draw($drawer); - + // Draw bottom axis $bottom = $this->axis->bottom; if($this->xAxisZero === FALSE) { $bottom->line->setY($y2, $y2); } $bottom->draw($drawer); - + // Draw left axis $left = $this->axis->left; if($this->yAxisZero === FALSE) { $left->line->setX($x1, $x1); } $left->draw($drawer); - + // Draw right axis $right = $this->axis->right; if($this->yAxisZero === FALSE) { $right->line->setX($x2, $x2); } $right->draw($drawer); - + } - + /** * Is the specified axis used ? * @@ -1366,104 +1375,104 @@ class awPlotGroup extends awComponentGroup { * @return bool */ protected function isAxisUsed($axis) { - + for($i = 0; $i < count($this->components); $i++) { - + $component = $this->components[$i]; - + switch($axis) { - + case awPlot::LEFT : case awPlot::RIGHT : if($component->getYAxis() === $axis) { return TRUE; } break; - + case awPlot::TOP : case awPlot::BOTTOM : if($component->getXAxis() === $axis) { return TRUE; } break; - + } - + } - + return FALSE; - + } - + protected function createGrid() { - + $max = $this->getRealYMax(awPlot::LEFT); $min = $this->getRealYMin(awPlot::RIGHT); - + // Select axis (left if possible, right otherwise) $axis = $this->selectYAxis(); - + $number = $axis->getLabelNumber() - 1; - + if($number < 1) { return; } - + // Horizontal lines of grid - + $h = array(); for($i = 0; $i <= $number; $i++) { $h[] = $i / $number; } - + // Vertical lines - + $major = $axis->tick('major'); $interval = $major->getInterval(); $number = $this->getXAxisNumber() - 1; - + $w = array(); - + if($number > 0) { - + for($i = 0; $i <= $number; $i++) { if($i%$interval === 0) { $w[] = $i / $number; } } - + } - + $this->grid->setGrid($w, $h); - + } - + protected function selectYAxis(){ - + // Select axis (left if possible, right otherwise) if($this->isAxisUsed(awPlot::LEFT)) { $axis = $this->axis->left; } else { $axis = $this->axis->right; } - + return $axis; - + } - + protected function selectXAxis(){ - + // Select axis (bottom if possible, top otherwise) if($this->isAxisUsed(awPlot::BOTTOM)) { $axis = $this->axis->bottom; } else { $axis = $this->axis->top; } - + return $axis; - + } - + protected function getXAxisNumber() { $offset = $this->components[0]; $max = $offset->getXAxisNumber(); diff --git a/htdocs/includes/artichow/php5/inc/Font.class.php b/htdocs/includes/artichow/php5/inc/Font.class.php index 6812bfa1d24..3e5e19b7f7b 100644 --- a/htdocs/includes/artichow/php5/inc/Font.class.php +++ b/htdocs/includes/artichow/php5/inc/Font.class.php @@ -7,32 +7,32 @@ * */ - + /** * 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 * @@ -41,28 +41,28 @@ class awFont { * @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, @@ -71,55 +71,55 @@ class awFont { $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; } @@ -149,13 +149,13 @@ class awTTFFont extends awFont { * @param int $size Font size */ public function __construct($font, $size) { - + parent::__construct($font); - + $this->size = (int)$size; - + } - + /** * Draw a text * @@ -164,23 +164,23 @@ class awTTFFont extends awFont { * @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, @@ -191,45 +191,45 @@ class awTTFFont extends awFont { $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); } @@ -246,14 +246,14 @@ 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.' { @@ -269,19 +269,20 @@ $php = ''; foreach($fonts as $font) { + // DOL_CHANGE LDR Fix to allow - into font names $php .= ' - class aw'.$font.' extends awTTFFont { - + 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.$font.' extends aw'.$font.' { + class '.ARTICHOW_PREFIX.str_replace('-','_',$font).' extends aw'.str_replace('-','_',$font).' { } '; } @@ -299,14 +300,14 @@ 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.' { @@ -324,14 +325,14 @@ 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.' { diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 57df1ccc445..66599852176 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -29,7 +29,7 @@ * \ingroup core * \brief File that defines environment for all Dolibarr process (pages or scripts) * This script reads the conf file, init $lang, $db and and empty $user - * \version $Id: master.inc.php,v 1.355 2011/08/14 17:17:20 eldy Exp $ + * \version $Id: master.inc.php,v 1.356 2011/08/14 18:26:15 eldy Exp $ */ @@ -301,7 +301,9 @@ if (! defined('NUSOAP_PATH')) { define('NUSOAP_PATH', DOL_DOCUME if (! defined('PHPEXCEL_PATH')) { define('PHPEXCEL_PATH', DOL_DOCUMENT_ROOT .'/includes/phpexcel/'); } if (! defined('ODTPHP_PATH')) { define('ODTPHP_PATH', empty($dolibarr_lib_ODTPHP_PATH)?DOL_DOCUMENT_ROOT.'/includes/odtphp/':$dolibarr_lib_ODTPHP_PATH.'/'); } if (! defined('ODTPHP_PATHTOPCLZIP')) { define('ODTPHP_PATHTOPCLZIP', empty($dolibarr_lib_ODTPHP_PATHTOPCLZIP)?DOL_DOCUMENT_ROOT.'/includes/odtphp/zip/pclzip/':$dolibarr_lib_ODTPHP_PATHTOPCLZIP.'/'); } +if (! defined('ARTICHOW_FONT')) { define('ARTICHOW_FONT', empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?DOL_DOCUMENT_ROOT.'/includes/artichow/font':dirname($dolibarr_font_DOL_DEFAULT_TTF_BOLD)); } // Other required path +if (! defined('ARTICHOW_FONT_NAMES')) { define('ARTICHOW_FONT_NAMES', empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?'Tuffy,TuffyBold,TuffyBoldItalic,TuffyItalic':'DejaVuSans,DejaVuSans-Bold,DejaVuSans-BoldOblique,DejaVuSans-Oblique'); } if (! defined('DOL_DEFAULT_TTF')) { define('DOL_DEFAULT_TTF', empty($dolibarr_font_DOL_DEFAULT_TTF)?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/Aerial.ttf':$dolibarr_font_DOL_DEFAULT_TTF); } if (! defined('DOL_DEFAULT_TTF_BOLD')) { define('DOL_DEFAULT_TTF_BOLD', empty($dolibarr_font_DOL_DEFAULT_TTF_BOLD)?DOL_DOCUMENT_ROOT.'/includes/barcode/php-barcode/fonts/AerialBd.ttf':$dolibarr_font_DOL_DEFAULT_TTF_BOLD); } if (! defined('MAGPIE_DIR')) { define('MAGPIE_DIR', MAGPIERSS_PATH); }