Qual: Can externalize fonts.

This commit is contained in:
Laurent Destailleur 2011-08-14 18:25:15 +00:00
parent d6bb618dfe
commit 2409c7fbfd
14 changed files with 1224 additions and 1175 deletions

View File

@ -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-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/extlib/Snoopy.class.inc
embedded-php-library usr/share/dolibarr/htdocs/includes/magpierss/rss_parse.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-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

View File

@ -2,7 +2,7 @@
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
# \file build/makepack-dolibarr.pl # \file build/makepack-dolibarr.pl
# \brief Dolibarr package builder (tgz, zip, rpm, deb, exe, aps) # \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 <eldy@users.sourceforge.net> # \author (c)2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@ -45,7 +45,7 @@ if (-d "/usr/src/RPM") { $RPMDIR="/usr/src/RPM"; } # mandrake
use vars qw/ $REVISION $VERSION /; 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)"; $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/zip`;
$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/build/perl`; $ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/build/perl`;
# We remove embedded libraries or fonts # 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/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`;
$ret=`rm -fr $BUILDROOT/$FILENAMETGZ2/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip/gnu-lgpl.txt`; $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/rpm`;
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/build/zip`; $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/build/zip`;
# We remove embedded libraries or fonts # 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/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/nusoap/lib/Mail`;
$ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip`; $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/usr/share/$PROJECT/htdocs/includes/odtphp/zip/pclzip`;

View File

@ -20,7 +20,7 @@
* \file htdocs/core/class/dolgraph.class.php * \file htdocs/core/class/dolgraph.class.php
* \ingroup core * \ingroup core
* \brief Fichier de la classe mere de gestion des graph * \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: * Usage:
* $graph_data = array(array('labelA',yA),array('labelB',yB)); * $graph_data = array(array('labelA',yA),array('labelB',yB));
@ -415,6 +415,7 @@ class DolGraph
*/ */
function draw_artichow($file) function draw_artichow($file)
{ {
global $artichow_defaultfont;
dol_syslog("DolGraph.class::draw_artichow this->type=".$this->type); dol_syslog("DolGraph.class::draw_artichow this->type=".$this->type);
if (! defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP',3); if (! defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP',3);
@ -442,7 +443,8 @@ class DolGraph
if (isset($this->title)) if (isset($this->title))
{ {
$graph->title->set($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); 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 //$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 // solve a bug in Artichow with UTF8
if (sizeof($this->Legend)) if (sizeof($this->Legend))
{ {
@ -568,7 +570,7 @@ class DolGraph
} }
$group->axis->bottom->setLabelText($legends); $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(); //print $group->axis->bottom->getLabelNumber();
if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval); if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval);

View File

@ -18,27 +18,27 @@ define('ARTICHOW', dirname(__FILE__).DIRECTORY_SEPARATOR.'php'.substr(phpversion
* Path to TrueType fonts * Path to TrueType fonts
*/ */
if(defined('ARTICHOW_FONT') === FALSE) { if(defined('ARTICHOW_FONT') === FALSE) {
define('ARTICHOW_FONT', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'font'); define('ARTICHOW_FONT', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'font');
} }
/* /*
* Patterns directory * Patterns directory
*/ */
if(defined('ARTICHOW_PATTERN') === FALSE) { if(defined('ARTICHOW_PATTERN') === FALSE) {
define('ARTICHOW_PATTERN', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'patterns'); define('ARTICHOW_PATTERN', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'patterns');
} }
/* /*
* Images directory * Images directory
*/ */
if(defined('ARTICHOW_IMAGE') === FALSE) { if(defined('ARTICHOW_IMAGE') === FALSE) {
define('ARTICHOW_IMAGE', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'images'); define('ARTICHOW_IMAGE', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'images');
} }
/* /*
@ -50,9 +50,9 @@ define('ARTICHOW_CACHE', TRUE);
* Cache directory * Cache directory
*/ */
if(defined('ARTICHOW_CACHE') === FALSE) { if(defined('ARTICHOW_CACHE') === FALSE) {
define('ARTICHOW_CACHE_DIRECTORY', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'cache'); define('ARTICHOW_CACHE_DIRECTORY', ARTICHOW.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'cache');
} }
/* /*
@ -69,11 +69,19 @@ define('ARTICHOW_DEPRECATED', TRUE);
/* /*
* Fonts to use * Fonts to use
*/ */
$fonts = array(
// DOL_CHANGE LDR
if (defined('ARTICHOW_FONT_NAMES')) $fonts=explode(',',constant('ARTICHOW_FONT_NAMES'));
else $fonts = array(
'Tuffy', 'Tuffy',
'TuffyBold', 'TuffyBold',
'TuffyBoldItalic', 'TuffyBoldItalic',
'TuffyItalic' 'TuffyItalic'
); );
global $artichow_defaultfont;
$artichow_defaultfont=$fonts[0];
//var_dump(ARTICHOW_FONT);
//var_dump($fonts);
//var_dump($artichow_defaultfont);
//exit;
?> ?>

View File

@ -6,7 +6,7 @@
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
* *
*/ */
require_once dirname(__FILE__)."/Graph.class.php"; require_once dirname(__FILE__)."/Graph.class.php";
@ -23,7 +23,7 @@ require_once dirname(__FILE__)."/Graph.class.php";
* @var array * @var array
*/ */
var $components; var $components;
/** /**
* Build the component group * Build the component group
*/ */
@ -81,7 +81,7 @@ registerClass('ComponentGroup', TRUE);
* @var float * @var float
*/ */
var $y = 0.5; var $y = 0.5;
/** /**
* Component absolute width (in pixels) * Component absolute width (in pixels)
* *
@ -89,7 +89,7 @@ registerClass('ComponentGroup', TRUE);
* @var int * @var int
*/ */
var $w; var $w;
/** /**
* Component absolute height (in pixels) * Component absolute height (in pixels)
* *
@ -111,71 +111,74 @@ registerClass('ComponentGroup', TRUE);
* @var float * @var float
*/ */
var $left; var $left;
/** /**
* Component background color * Component background color
* *
* @var Color * @var Color
*/ */
var $background; var $background;
/** /**
* Component padding * Component padding
* *
* @var Side * @var Side
*/ */
var $padding; var $padding;
/** /**
* Component space * Component space
* *
* @var Side * @var Side
*/ */
var $space; var $space;
/** /**
* Component title * Component title
* *
* @var Label * @var Label
*/ */
var $title; var $title;
/** /**
* Adjust automatically the component ? * Adjust automatically the component ?
* *
* @var bool * @var bool
*/ */
var $auto = TRUE; var $auto = TRUE;
/** /**
* Legend * Legend
* *
* @var Legend * @var Legend
*/ */
var $legend; var $legend;
/** /**
* Build the component * Build the component
*/ */
function awComponent() { function awComponent() {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
// Component legend // Component legend
$this->legend = new awLegend(); $this->legend = new awLegend();
$this->padding = new awSide(25, 25, 25, 25); $this->padding = new awSide(25, 25, 25, 25);
$this->space = new awSide(0, 0, 0, 0); $this->space = new awSide(0, 0, 0, 0);
// Component title // Component title
$this->title = new awLabel( $this->title = new awLabel(
NULL, NULL,
new awTuffy(10), new $classfontname(10),
NULL, NULL,
0 0
); );
$this->title->setAlign(LABEL_CENTER, LABEL_TOP); $this->title->setAlign(LABEL_CENTER, LABEL_TOP);
} }
/** /**
* Adjust automatically the component ? * Adjust automatically the component ?
* *
@ -184,7 +187,7 @@ registerClass('ComponentGroup', TRUE);
function auto($auto) { function auto($auto) {
$this->auto = (bool)$auto; $this->auto = (bool)$auto;
} }
/** /**
* Change the size of the component * Change the size of the component
* *
@ -192,12 +195,12 @@ registerClass('ComponentGroup', TRUE);
* @param int $height Component height (from 0 to 1) * @param int $height Component height (from 0 to 1)
*/ */
function setSize($width, $height) { function setSize($width, $height) {
$this->width = (float)$width; $this->width = (float)$width;
$this->height = (float)$height; $this->height = (float)$height;
} }
/** /**
* Change the absolute size of the component * Change the absolute size of the component
* *
@ -205,12 +208,12 @@ registerClass('ComponentGroup', TRUE);
* @param int $h Component height (in pixels) * @param int $h Component height (in pixels)
*/ */
function setAbsSize($w, $h) { function setAbsSize($w, $h) {
$this->w = (int)$w; $this->w = (int)$w;
$this->h = (int)$h; $this->h = (int)$h;
} }
/** /**
* Change component background color * Change component background color
* *
@ -221,7 +224,7 @@ registerClass('ComponentGroup', TRUE);
$this->background = $color; $this->background = $color;
} }
} }
/** /**
* Change component background gradient * Change component background gradient
* *
@ -232,7 +235,7 @@ registerClass('ComponentGroup', TRUE);
$this->background = $gradient; $this->background = $gradient;
} }
} }
/** /**
* Change component background image * Change component background image
* *
@ -243,7 +246,7 @@ registerClass('ComponentGroup', TRUE);
$this->background = $image; $this->background = $image;
} }
} }
/** /**
* Return the component background * Return the component background
* *
@ -252,7 +255,7 @@ registerClass('ComponentGroup', TRUE);
function getBackground() { function getBackground() {
return $this->background; return $this->background;
} }
/** /**
* Change component padding * Change component padding
* *
@ -264,7 +267,7 @@ registerClass('ComponentGroup', TRUE);
function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) { function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->padding->set($left, $right, $top, $bottom); $this->padding->set($left, $right, $top, $bottom);
} }
/** /**
* Change component space * Change component space
* *
@ -276,7 +279,7 @@ registerClass('ComponentGroup', TRUE);
function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) { function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
$this->space->set($left, $right, $bottom, $top); $this->space->set($left, $right, $bottom, $top);
} }
/** /**
* Change the absolute position of the component on the graph * 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 * @var int $y Left-top corner Y position
*/ */
function setAbsPosition($left, $top) { function setAbsPosition($left, $top) {
$this->left = (int)$left; $this->left = (int)$left;
$this->top = (int)$top; $this->top = (int)$top;
} }
/** /**
* Set the center of the component * 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 * @param int $y Position on Y axis of the center of the component
*/ */
function setCenter($x, $y) { function setCenter($x, $y) {
$this->x = (float)$x; $this->x = (float)$x;
$this->y = (float)$y; $this->y = (float)$y;
} }
/** /**
* Get component coords with its padding * Get component coords with its padding
* *
* @return array Coords of the component * @return array Coords of the component
*/ */
function getPosition() { function getPosition() {
// Get component coords // Get component coords
$x1 = $this->padding->left; $x1 = $this->padding->left;
$y1 = $this->padding->top; $y1 = $this->padding->top;
$x2 = $this->w - $this->padding->right; $x2 = $this->w - $this->padding->right;
$y2 = $this->h - $this->padding->bottom; $y2 = $this->h - $this->padding->bottom;
return array($x1, $y1, $x2, $y2); return array($x1, $y1, $x2, $y2);
} }
/** /**
* Init the drawing of the component * Init the drawing of the component
*/ */
@ -327,57 +330,57 @@ registerClass('ComponentGroup', TRUE);
// Set component background // Set component background
$background = $this->getBackground(); $background = $this->getBackground();
if($background !== NULL) { if($background !== NULL) {
$p1 = new awPoint(0, 0); $p1 = new awPoint(0, 0);
$p2 = new awPoint($this->w - 1, $this->h - 1); $p2 = new awPoint($this->w - 1, $this->h - 1);
if(is_a($background, 'awImage')) { if(is_a($background, 'awImage')) {
$drawer->copyImage( $drawer->copyImage(
$background, $background,
$p1, $p1,
$p2 $p2
); );
} else { } else {
$drawer->filledRectangle( $drawer->filledRectangle(
$background, $background,
new awLine($p1, $p2) new awLine($p1, $p2)
); );
} }
} }
} }
/** /**
* Finalize the drawing of the component * Finalize the drawing of the component
*/ */
function finalize($drawer) { function finalize($drawer) {
// Draw component title // Draw component title
$point = new awPoint( $point = new awPoint(
$this->w / 2, $this->w / 2,
$this->padding->top - 8 $this->padding->top - 8
); );
$this->title->draw($drawer, $point); $this->title->draw($drawer, $point);
// Draw legend // Draw legend
$this->legend->draw($drawer); $this->legend->draw($drawer);
} }
/** /**
* Draw the grid around your component * Draw the grid around your component
* *
* @param Drawer A drawer * @param Drawer A drawer
* @return array Coords for the component * @return array Coords for the component
*/ */
/** /**
* Draw the component on the graph * Draw the component on the graph
* Component should be drawed into specified coords * Component should be drawed into specified coords
@ -389,8 +392,8 @@ registerClass('ComponentGroup', TRUE);
* @param int $y2 * @param int $y2
* @param bool $aliasing Use anti-aliasing to draw the component ? * @param bool $aliasing Use anti-aliasing to draw the component ?
*/ */
/** /**
* Get space width in pixels * Get space width in pixels
* *
@ -399,16 +402,16 @@ registerClass('ComponentGroup', TRUE);
* @return array * @return array
*/ */
function getSpace($width, $height) { function getSpace($width, $height) {
$left = (int)($width * $this->space->left / 100); $left = (int)($width * $this->space->left / 100);
$right = (int)($width * $this->space->right / 100); $right = (int)($width * $this->space->right / 100);
$top = (int)($height * $this->space->top / 100); $top = (int)($height * $this->space->top / 100);
$bottom = (int)($height * $this->space->bottom / 100); $bottom = (int)($height * $this->space->bottom / 100);
return array($left, $right, $top, $bottom); return array($left, $right, $top, $bottom);
} }
} }
registerClass('Component', TRUE); registerClass('Component', TRUE);

View File

@ -29,7 +29,7 @@ require_once ARTICHOW."/inc/Font.class.php";
require_once ARTICHOW."/inc/Gradient.class.php"; require_once ARTICHOW."/inc/Gradient.class.php";
/** /**
* A graph * A graph
* *
* @package Artichow * @package Artichow
*/ */
@ -48,35 +48,35 @@ class awGraph extends awImage {
* @var int * @var int
*/ */
var $timeout = 0; var $timeout = 0;
/** /**
* Graph timing ? * Graph timing ?
* *
* @var bool * @var bool
*/ */
var $timing; var $timing;
/** /**
* Components * Components
* *
* @var array * @var array
*/ */
var $components = array(); var $components = array();
/** /**
* Some labels to add to the component * Some labels to add to the component
* *
* @var array * @var array
*/ */
var $labels = array(); var $labels = array();
/** /**
* Graph title * Graph title
* *
* @var Label * @var Label
*/ */
var $title; var $title;
/** /**
* Construct a new graph * Construct a new graph
* *
@ -86,29 +86,33 @@ class awGraph extends awImage {
* @param int $timeout Cache timeout (unix timestamp) * @param int $timeout Cache timeout (unix timestamp)
*/ */
function awGraph($width = NULL, $height = NULL, $name = NULL, $timeout = 0) { 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(); parent::awImage();
$this->setSize($width, $height); $this->setSize($width, $height);
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
$this->name = $name; $this->name = $name;
$this->timeout = $timeout; $this->timeout = $timeout;
// Clean sometimes all the cache // Clean sometimes all the cache
if(mt_rand(0, 5000) === 0) { if(mt_rand(0, 5000) === 0) {
awGraph::cleanCache(); awGraph::cleanCache();
} }
if($this->name !== NULL) { if($this->name !== NULL) {
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time"; $file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
if(is_file($file)) { if(is_file($file)) {
$type = awGraph::cleanGraphCache($file); $type = awGraph::cleanGraphCache($file);
if($type === NULL) { if($type === NULL) {
awGraph::deleteFromCache($this->name); awGraph::deleteFromCache($this->name);
} else { } else {
@ -116,23 +120,23 @@ class awGraph extends awImage {
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name.""); readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
exit; exit;
} }
} }
} }
} }
$this->title = new awLabel( $this->title = new awLabel(
NULL, NULL,
new awTuffy(16), new $classfontname(16),
NULL, NULL,
0 0
); );
$this->title->setAlign(LABEL_CENTER, LABEL_BOTTOM); $this->title->setAlign(LABEL_CENTER, LABEL_BOTTOM);
} }
/** /**
* Delete a graph from the cache * Delete a graph from the cache
* *
@ -142,59 +146,59 @@ class awGraph extends awImage {
function deleteFromCache($name) { function deleteFromCache($name) {
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) { if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name.""); unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time"); unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
} }
} }
} }
/** /**
* Delete all graphs from the cache * Delete all graphs from the cache
*/ */
function deleteAllCache() { function deleteAllCache() {
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
$dp = opendir(ARTICHOW_CACHE_DIRECTORY); $dp = opendir(ARTICHOW_CACHE_DIRECTORY);
while($file = readdir($dp)) { while($file = readdir($dp)) {
if($file !== '.' and $file != '..') { if($file !== '.' and $file != '..') {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file); unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
} }
} }
} }
} }
/** /**
* Clean cache * Clean cache
*/ */
function cleanCache() { function cleanCache() {
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time"); $glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
foreach($glob as $file) { foreach($glob as $file) {
$type = awGraph::cleanGraphCache($file); $type = awGraph::cleanGraphCache($file);
if($type === NULL) { if($type === NULL) {
$name = ereg_replace(".*/(.*)\-time", "\\1", $file); $name = ereg_replace(".*/(.*)\-time", "\\1", $file);
awGraph::deleteFromCache($name); awGraph::deleteFromCache($name);
} }
} }
} }
} }
/** /**
* Enable/Disable Graph timing * Enable/Disable Graph timing
* *
@ -203,18 +207,18 @@ class awGraph extends awImage {
function setTiming($timing) { function setTiming($timing) {
$this->timing = (bool)$timing; $this->timing = (bool)$timing;
} }
/** /**
* Add a component to the graph * Add a component to the graph
* *
* @param &$component * @param &$component
*/ */
function add(&$component) { function add(&$component) {
$this->components[] = $component; $this->components[] = $component;
} }
/** /**
* Add a label to the 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 * @param int $y Position on Y axis of the center of the text
*/ */
function addLabel(&$label, $x, $y) { function addLabel(&$label, $x, $y) {
$this->labels[] = array( $this->labels[] = array(
$label, $x, $y $label, $x, $y
); );
} }
/** /**
* Add a label to the component with aboslute position * Add a label to the component with aboslute position
* *
@ -237,13 +241,13 @@ class awGraph extends awImage {
* @param $point Text position * @param $point Text position
*/ */
function addAbsLabel(&$label, $point) { function addAbsLabel(&$label, $point) {
$this->labels[] = array( $this->labels[] = array(
$label, $point $label, $point
); );
} }
/** /**
* Build the graph and draw component on it * Build the graph and draw component on it
* Image is sent to the user browser * 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. * @param string $file Save the image in the specified file. Let it null to print image to screen.
*/ */
function draw($file = NULL) { function draw($file = NULL) {
if($this->timing) { if($this->timing) {
$time = microtimeFloat(); $time = microtimeFloat();
} }
$this->create(); $this->create();
foreach($this->components as $component) { foreach($this->components as $component) {
$this->drawComponent($component); $this->drawComponent($component);
} }
$this->drawTitle(); $this->drawTitle();
$this->drawShadow(); $this->drawShadow();
$this->drawLabels(); $this->drawLabels();
if($this->timing) { if($this->timing) {
$this->drawTiming(microtimeFloat() - $time); $this->drawTiming(microtimeFloat() - $time);
} }
@ -275,104 +279,104 @@ class awGraph extends awImage {
if(ARTICHOW_CACHE and $this->name !== NULL) { if(ARTICHOW_CACHE and $this->name !== NULL) {
ob_start(); ob_start();
} }
$this->send($file); $this->send($file);
if(ARTICHOW_CACHE and $this->name !== NULL) { if(ARTICHOW_CACHE and $this->name !== NULL) {
$data = ob_get_contents(); $data = ob_get_contents();
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) { if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
trigger_error("Cache directory is not writable"); trigger_error("Cache directory is not writable");
} }
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name.""; $file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
file_put_contents($file, $data); file_put_contents($file, $data);
$file .= "-time"; $file .= "-time";
file_put_contents($file, $this->timeout."\n".$this->getFormat()); file_put_contents($file, $this->timeout."\n".$this->getFormat());
ob_clean(); ob_clean();
echo $data; echo $data;
} }
} }
function drawLabels() { function drawLabels() {
$drawer = $this->getDrawer(); $drawer = $this->getDrawer();
foreach($this->labels as $array) { foreach($this->labels as $array) {
if(count($array) === 3) { if(count($array) === 3) {
// Text in relative position // Text in relative position
list($label, $x, $y) = $array; list($label, $x, $y) = $array;
$point = new awPoint( $point = new awPoint(
$x * $this->width, $x * $this->width,
$y * $this->height $y * $this->height
); );
} else { } else {
// Text in absolute position // Text in absolute position
list($label, $point) = $array; list($label, $point) = $array;
} }
$label->draw($drawer, $point); $label->draw($drawer, $point);
} }
} }
function drawTitle() { function drawTitle() {
$drawer = $this->getDrawer(); $drawer = $this->getDrawer();
$point = new awPoint( $point = new awPoint(
$this->width / 2, $this->width / 2,
10 10
); );
$this->title->draw($drawer, $point); $this->title->draw($drawer, $point);
} }
function drawTiming($time) { function drawTiming($time) {
$drawer = $this->getDrawer(); $drawer = $this->getDrawer();
$label = new awLabel; $label = new awLabel;
$label->set("(".sprintf("%.3f", $time)." s)"); $label->set("(".sprintf("%.3f", $time)." s)");
$label->setAlign(LABEL_LEFT, LABEL_TOP); $label->setAlign(LABEL_LEFT, LABEL_TOP);
$label->border->show(); $label->border->show();
$label->setPadding(1, 0, 0, 0); $label->setPadding(1, 0, 0, 0);
$label->setBackgroundColor(new awColor(230, 230, 230, 25)); $label->setBackgroundColor(new awColor(230, 230, 230, 25));
$label->draw($drawer, new awPoint(5, $drawer->height - 5)); $label->draw($drawer, new awPoint(5, $drawer->height - 5));
} }
function cleanGraphCache($file) { function cleanGraphCache($file) {
list( list(
$time, $time,
$type $type
) = explode("\n", file_get_contents($file)); ) = explode("\n", file_get_contents($file));
$time = (int)$time; $time = (int)$time;
if($time !== 0 and $time < time()) { if($time !== 0 and $time < time()) {
return NULL; return NULL;
} else { } else {
return $type; return $type;
} }
} }
} }
@ -382,8 +386,8 @@ registerClass('Graph');
/* /*
* To preserve PHP 4 compatibility * To preserve PHP 4 compatibility
*/ */
function microtimeFloat() { function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime()); list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec; return (float)$usec + (float)$sec;
} }
?> ?>

View File

@ -22,28 +22,28 @@ class awMathFunction {
* @var Line * @var Line
*/ */
var $line; var $line;
/** /**
* Marks for your plot * Marks for your plot
* *
* @var Mark * @var Mark
*/ */
var $mark; var $mark;
/** /**
* Callback function * Callback function
* *
* @var string * @var string
*/ */
var $f; var $f;
/** /**
* Start the drawing from this value * Start the drawing from this value
* *
* @var float * @var float
*/ */
var $fromX; var $fromX;
/** /**
* Stop the drawing at this value * Stop the drawing at this value
* *
@ -57,7 +57,7 @@ class awMathFunction {
* @var Color * @var Color
*/ */
var $color; var $color;
/** /**
* Construct the function * Construct the function
* *
@ -66,17 +66,17 @@ class awMathFunction {
* @param float $toX * @param float $toX
*/ */
function awMathFunction($f, $fromX = NULL, $toX = NULL) { function awMathFunction($f, $fromX = NULL, $toX = NULL) {
$this->f = (string)$f; $this->f = (string)$f;
$this->fromX = is_null($fromX) ? NULL : (float)$fromX; $this->fromX = is_null($fromX) ? NULL : (float)$fromX;
$this->toX = is_null($toX) ? NULL : (float)$toX; $this->toX = is_null($toX) ? NULL : (float)$toX;
$this->line = new awLine; $this->line = new awLine;
$this->mark = new awMark; $this->mark = new awMark;
$this->color = new awBlack; $this->color = new awBlack;
} }
/** /**
* Change line color * Change line color
* *
@ -85,7 +85,7 @@ class awMathFunction {
function setColor($color) { function setColor($color) {
$this->color = $color; $this->color = $color;
} }
/** /**
* Get line color * Get line color
* *
@ -142,56 +142,56 @@ class awMathFunction {
} }
registerClass('MathFunction'); registerClass('MathFunction');
/** /**
* For mathematics functions * For mathematics functions
* *
* @package Artichow * @package Artichow
*/ */
class awMathPlot extends awComponent { class awMathPlot extends awComponent {
/** /**
* Functions * Functions
* *
* @var array * @var array
*/ */
var $functions = array(); var $functions = array();
/** /**
* Grid properties * Grid properties
* *
* @var Grid * @var Grid
*/ */
var $grid; var $grid;
/** /**
* X axis * X axis
* *
* @var Axis * @var Axis
*/ */
var $xAxis; var $xAxis;
/** /**
* Y axis * Y axis
* *
* @var Axis * @var Axis
*/ */
var $yAxis; var $yAxis;
/** /**
* Extremum * Extremum
* *
* @var Side * @var Side
*/ */
var $extremum = NULL; var $extremum = NULL;
/** /**
* Interval * Interval
* *
* @var float * @var float
*/ */
var $interval = 1; var $interval = 1;
/** /**
* Build the plot * Build the plot
* *
@ -201,44 +201,47 @@ class awMathPlot extends awComponent {
* @param int $yMin Minimum Y value * @param int $yMin Minimum Y value
*/ */
function awMathPlot($xMin, $xMax, $yMax, $yMin) { function awMathPlot($xMin, $xMax, $yMax, $yMin) {
parent::awComponent(); parent::awComponent();
$this->setPadding(8, 8, 8, 8); $this->setPadding(8, 8, 8, 8);
$this->grid = new awGrid; $this->grid = new awGrid;
// Hide grid by default // Hide grid by default
$this->grid->hide(TRUE); $this->grid->hide(TRUE);
// Set extremum // Set extremum
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin); $this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
// Create axis // Create axis
$this->xAxis = new awAxis; $this->xAxis = new awAxis;
$this->xAxis->setTickStyle(TICK_IN); $this->xAxis->setTickStyle(TICK_IN);
$this->xAxis->label->hideValue(0); $this->xAxis->label->hideValue(0);
$this->initAxis($this->xAxis); $this->initAxis($this->xAxis);
$this->yAxis = new awAxis; $this->yAxis = new awAxis;
$this->yAxis->setTickStyle(TICK_IN); $this->yAxis->setTickStyle(TICK_IN);
$this->yAxis->label->hideValue(0); $this->yAxis->label->hideValue(0);
$this->initAxis($this->yAxis); $this->initAxis($this->yAxis);
} }
function initAxis(&$axis) { 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->setLabelPrecision(1);
$axis->addTick('major', new awTick(0, 5)); $axis->addTick('major', new awTick(0, 5));
$axis->addTick('minor', new awTick(0, 3)); $axis->addTick('minor', new awTick(0, 3));
$axis->addTick('micro', new awTick(0, 1)); $axis->addTick('micro', new awTick(0, 1));
$axis->setNumberByTick('minor', 'major', 1); $axis->setNumberByTick('minor', 'major', 1);
$axis->setNumberByTick('micro', 'minor', 4); $axis->setNumberByTick('micro', 'minor', 4);
$axis->label->setFont(new awTuffy(7)); $axis->label->setFont(new $classfontname(7));
} }
/** /**
* Interval to calculate values * Interval to calculate values
* *
@ -247,7 +250,7 @@ class awMathPlot extends awComponent {
function setInterval($interval) { function setInterval($interval) {
$this->interval = (float)$interval; $this->interval = (float)$interval;
} }
/** /**
* Add a formula f(x) * Add a formula f(x)
* *
@ -256,104 +259,104 @@ class awMathPlot extends awComponent {
* @param int $type Type for the legend * @param int $type Type for the legend
*/ */
function add(&$function, $name = NULL, $type = LEGEND_LINE) { function add(&$function, $name = NULL, $type = LEGEND_LINE) {
$this->functions[] = $function; $this->functions[] = $function;
if($name !== NULL) { if($name !== NULL) {
$this->legend->add($function, $name, $type); $this->legend->add($function, $name, $type);
} }
} }
function init($drawer) { function init($drawer) {
list($x1, $y1, $x2, $y2) = $this->getPosition(); list($x1, $y1, $x2, $y2) = $this->getPosition();
$this->xAxis->line->setX($x1, $x2); $this->xAxis->line->setX($x1, $x2);
$this->xAxis->label->setAlign(NULL, LABEL_BOTTOM); $this->xAxis->label->setAlign(NULL, LABEL_BOTTOM);
$this->xAxis->label->move(0, 3); $this->xAxis->label->move(0, 3);
$this->xAxis->setRange($this->extremum->left, $this->extremum->right); $this->xAxis->setRange($this->extremum->left, $this->extremum->right);
$this->yAxis->line->setY($y2, $y1); $this->yAxis->line->setY($y2, $y1);
$this->yAxis->label->setAlign(LABEL_RIGHT); $this->yAxis->label->setAlign(LABEL_RIGHT);
$this->yAxis->label->move(-6, 0); $this->yAxis->label->move(-6, 0);
$this->yAxis->reverseTickStyle(); $this->yAxis->reverseTickStyle();
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top); $this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
$this->xAxis->setYCenter($this->yAxis, 0); $this->xAxis->setYCenter($this->yAxis, 0);
$this->yAxis->setXCenter($this->xAxis, 0); $this->yAxis->setXCenter($this->xAxis, 0);
if($this->yAxis->getLabelNumber() === NULL) { if($this->yAxis->getLabelNumber() === NULL) {
$number = $this->extremum->top - $this->extremum->bottom + 1; $number = $this->extremum->top - $this->extremum->bottom + 1;
$this->yAxis->setLabelNumber($number); $this->yAxis->setLabelNumber($number);
} }
if($this->xAxis->getLabelNumber() === NULL) { if($this->xAxis->getLabelNumber() === NULL) {
$number = $this->extremum->right - $this->extremum->left + 1; $number = $this->extremum->right - $this->extremum->left + 1;
$this->xAxis->setLabelNumber($number); $this->xAxis->setLabelNumber($number);
} }
// Set ticks // Set ticks
$this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber()); $this->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber()); $this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
// Set axis labels // Set axis labels
$labels = array(); $labels = array();
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) { for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i; $labels[] = $i;
} }
$this->xAxis->label->set($labels); $this->xAxis->label->set($labels);
$labels = array(); $labels = array();
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) { for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i; $labels[] = $i;
} }
$this->yAxis->label->set($labels); $this->yAxis->label->set($labels);
parent::init($drawer); parent::init($drawer);
// Create the grid // Create the grid
$this->createGrid(); $this->createGrid();
// Draw the grid // Draw the grid
$this->grid->draw($drawer, $x1, $y1, $x2, $y2); $this->grid->draw($drawer, $x1, $y1, $x2, $y2);
} }
function drawEnvelope($drawer) { function drawEnvelope($drawer) {
// Draw axis // Draw axis
$this->xAxis->draw($drawer); $this->xAxis->draw($drawer);
$this->yAxis->draw($drawer); $this->yAxis->draw($drawer);
} }
function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) { function drawComponent($drawer, $x1, $y1, $x2, $y2, $aliasing) {
foreach($this->functions as $function) { foreach($this->functions as $function) {
$f = $function->f; $f = $function->f;
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX; $fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX; $toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
$old = NULL; $old = NULL;
for($i = $fromX; $i <= $toX; $i += $this->interval) { for($i = $fromX; $i <= $toX; $i += $this->interval) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i))); $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
if($p->y >= $y1 and $p->y <= $y2) { if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p); $function->mark->draw($drawer, $p);
} }
if($old !== NULL) { if($old !== NULL) {
$line = $function->line; $line = $function->line;
$line->setLocation($old, $p); $line->setLocation($old, $p);
if( if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or ($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2) ($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -363,26 +366,26 @@ class awMathPlot extends awComponent {
$line $line
); );
} }
} }
$old = $p; $old = $p;
} }
// Draw last point if needed // Draw last point if needed
if($old !== NULL and $i - $this->interval != $toX) { if($old !== NULL and $i - $this->interval != $toX) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX))); $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
if($p->y >= $y1 and $p->y <= $y2) { if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p); $function->mark->draw($drawer, $p);
} }
$line = $function->line; $line = $function->line;
$line->setLocation($old, $p); $line->setLocation($old, $p);
if( if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or ($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2) ($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -392,34 +395,34 @@ class awMathPlot extends awComponent {
$line $line
); );
} }
} }
} }
} }
function createGrid() { function createGrid() {
// Horizontal lines of the grid // Horizontal lines of the grid
$major = $this->yAxis->tick('major'); $major = $this->yAxis->tick('major');
$interval = $major->getInterval(); $interval = $major->getInterval();
$number = $this->yAxis->getLabelNumber() - 1; $number = $this->yAxis->getLabelNumber() - 1;
$h = array(); $h = array();
if($number > 0) { if($number > 0) {
for($i = 0; $i <= $number; $i++) { for($i = 0; $i <= $number; $i++) {
$h[] = $i / $number; $h[] = $i / $number;
} }
} }
// Vertical lines // Vertical lines
$major = $this->xAxis->tick('major'); $major = $this->xAxis->tick('major');
$interval = $major->getInterval(); $interval = $major->getInterval();
$number = $this->xAxis->getLabelNumber() - 1; $number = $this->xAxis->getLabelNumber() - 1;
$w = array(); $w = array();
if($number > 0) { if($number > 0) {
for($i = 0; $i <= $number; $i++) { for($i = 0; $i <= $number; $i++) {
@ -428,9 +431,9 @@ class awMathPlot extends awComponent {
} }
} }
} }
$this->grid->setGrid($w, $h); $this->grid->setGrid($w, $h);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
* *
*/ */
require_once dirname(__FILE__)."/Graph.class.php"; require_once dirname(__FILE__)."/Graph.class.php";
@ -23,7 +23,7 @@ abstract class awComponentGroup extends awComponent {
* @var array * @var array
*/ */
protected $components; protected $components;
/** /**
* Build the component group * Build the component group
*/ */
@ -81,7 +81,7 @@ abstract class awComponent {
* @var float * @var float
*/ */
public $y = 0.5; public $y = 0.5;
/** /**
* Component absolute width (in pixels) * Component absolute width (in pixels)
* *
@ -89,7 +89,7 @@ abstract class awComponent {
* @var int * @var int
*/ */
public $w; public $w;
/** /**
* Component absolute height (in pixels) * Component absolute height (in pixels)
* *
@ -111,71 +111,75 @@ abstract class awComponent {
* @var float * @var float
*/ */
public $left; public $left;
/** /**
* Component background color * Component background color
* *
* @var Color * @var Color
*/ */
protected $background; protected $background;
/** /**
* Component padding * Component padding
* *
* @var Side * @var Side
*/ */
protected $padding; protected $padding;
/** /**
* Component space * Component space
* *
* @var Side * @var Side
*/ */
protected $space; protected $space;
/** /**
* Component title * Component title
* *
* @var Label * @var Label
*/ */
public $title; public $title;
/** /**
* Adjust automatically the component ? * Adjust automatically the component ?
* *
* @var bool * @var bool
*/ */
protected $auto = TRUE; protected $auto = TRUE;
/** /**
* Legend * Legend
* *
* @var Legend * @var Legend
*/ */
public $legend; public $legend;
/** /**
* Build the component * Build the component
*/ */
public function __construct() { public function __construct() {
// DOL_CHANGE LDR Fix to allow usage of other fonts
global $artichow_defaultfont;
$classfontname='aw'.str_replace('-','_',$artichow_defaultfont);
// Component legend // Component legend
$this->legend = new awLegend(); $this->legend = new awLegend();
$this->padding = new awSide(25, 25, 25, 25); $this->padding = new awSide(25, 25, 25, 25);
$this->space = new awSide(0, 0, 0, 0); $this->space = new awSide(0, 0, 0, 0);
// Component title // Component title
$this->title = new awLabel( $this->title = new awLabel(
NULL, NULL,
new awTuffy(10), new $classfontname(10),
NULL, NULL,
0 0
); );
$this->title->setAlign(awLabel::CENTER, awLabel::TOP); $this->title->setAlign(awLabel::CENTER, awLabel::TOP);
} }
/** /**
* Adjust automatically the component ? * Adjust automatically the component ?
* *
@ -184,7 +188,7 @@ abstract class awComponent {
public function auto($auto) { public function auto($auto) {
$this->auto = (bool)$auto; $this->auto = (bool)$auto;
} }
/** /**
* Change the size of the component * Change the size of the component
* *
@ -192,12 +196,12 @@ abstract class awComponent {
* @param int $height Component height (from 0 to 1) * @param int $height Component height (from 0 to 1)
*/ */
public function setSize($width, $height) { public function setSize($width, $height) {
$this->width = (float)$width; $this->width = (float)$width;
$this->height = (float)$height; $this->height = (float)$height;
} }
/** /**
* Change the absolute size of the component * Change the absolute size of the component
* *
@ -205,12 +209,12 @@ abstract class awComponent {
* @param int $h Component height (in pixels) * @param int $h Component height (in pixels)
*/ */
public function setAbsSize($w, $h) { public function setAbsSize($w, $h) {
$this->w = (int)$w; $this->w = (int)$w;
$this->h = (int)$h; $this->h = (int)$h;
} }
/** /**
* Change component background color * Change component background color
* *
@ -221,7 +225,7 @@ abstract class awComponent {
$this->background = $color; $this->background = $color;
} }
} }
/** /**
* Change component background gradient * Change component background gradient
* *
@ -232,7 +236,7 @@ abstract class awComponent {
$this->background = $gradient; $this->background = $gradient;
} }
} }
/** /**
* Change component background image * Change component background image
* *
@ -243,7 +247,7 @@ abstract class awComponent {
$this->background = $image; $this->background = $image;
} }
} }
/** /**
* Return the component background * Return the component background
* *
@ -252,7 +256,7 @@ abstract class awComponent {
public function getBackground() { public function getBackground() {
return $this->background; return $this->background;
} }
/** /**
* Change component padding * Change component padding
* *
@ -264,7 +268,7 @@ abstract class awComponent {
public function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) { public function setPadding($left = NULL, $right = NULL, $top = NULL, $bottom = NULL) {
$this->padding->set($left, $right, $top, $bottom); $this->padding->set($left, $right, $top, $bottom);
} }
/** /**
* Change component space * Change component space
* *
@ -276,7 +280,7 @@ abstract class awComponent {
public function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) { public function setSpace($left = NULL, $right = NULL, $bottom = NULL, $top = NULL) {
$this->space->set($left, $right, $bottom, $top); $this->space->set($left, $right, $bottom, $top);
} }
/** /**
* Change the absolute position of the component on the graph * 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 * @var int $y Left-top corner Y position
*/ */
public function setAbsPosition($left, $top) { public function setAbsPosition($left, $top) {
$this->left = (int)$left; $this->left = (int)$left;
$this->top = (int)$top; $this->top = (int)$top;
} }
/** /**
* Set the center of the component * 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 * @param int $y Position on Y axis of the center of the component
*/ */
public function setCenter($x, $y) { public function setCenter($x, $y) {
$this->x = (float)$x; $this->x = (float)$x;
$this->y = (float)$y; $this->y = (float)$y;
} }
/** /**
* Get component coords with its padding * Get component coords with its padding
* *
* @return array Coords of the component * @return array Coords of the component
*/ */
public function getPosition() { public function getPosition() {
// Get component coords // Get component coords
$x1 = $this->padding->left; $x1 = $this->padding->left;
$y1 = $this->padding->top; $y1 = $this->padding->top;
$x2 = $this->w - $this->padding->right; $x2 = $this->w - $this->padding->right;
$y2 = $this->h - $this->padding->bottom; $y2 = $this->h - $this->padding->bottom;
return array($x1, $y1, $x2, $y2); return array($x1, $y1, $x2, $y2);
} }
/** /**
* Init the drawing of the component * Init the drawing of the component
*/ */
@ -327,49 +331,49 @@ abstract class awComponent {
// Set component background // Set component background
$background = $this->getBackground(); $background = $this->getBackground();
if($background !== NULL) { if($background !== NULL) {
$p1 = new awPoint(0, 0); $p1 = new awPoint(0, 0);
$p2 = new awPoint($this->w - 1, $this->h - 1); $p2 = new awPoint($this->w - 1, $this->h - 1);
if($background instanceof awImage) { if($background instanceof awImage) {
$drawer->copyImage( $drawer->copyImage(
$background, $background,
$p1, $p1,
$p2 $p2
); );
} else { } else {
$drawer->filledRectangle( $drawer->filledRectangle(
$background, $background,
new awLine($p1, $p2) new awLine($p1, $p2)
); );
} }
} }
} }
/** /**
* Finalize the drawing of the component * Finalize the drawing of the component
*/ */
public function finalize(awDrawer $drawer) { public function finalize(awDrawer $drawer) {
// Draw component title // Draw component title
$point = new awPoint( $point = new awPoint(
$this->w / 2, $this->w / 2,
$this->padding->top - 8 $this->padding->top - 8
); );
$this->title->draw($drawer, $point); $this->title->draw($drawer, $point);
// Draw legend // Draw legend
$this->legend->draw($drawer); $this->legend->draw($drawer);
} }
/** /**
* Draw the grid around your component * Draw the grid around your component
* *
@ -377,7 +381,7 @@ abstract class awComponent {
* @return array Coords for the component * @return array Coords for the component
*/ */
abstract public function drawEnvelope(awDrawer $drawer); abstract public function drawEnvelope(awDrawer $drawer);
/** /**
* Draw the component on the graph * Draw the component on the graph
* Component should be drawed into specified coords * Component should be drawed into specified coords
@ -390,7 +394,7 @@ abstract class awComponent {
* @param bool $aliasing Use anti-aliasing to draw the component ? * @param bool $aliasing Use anti-aliasing to draw the component ?
*/ */
abstract public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing); abstract public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing);
/** /**
* Get space width in pixels * Get space width in pixels
* *
@ -399,16 +403,16 @@ abstract class awComponent {
* @return array * @return array
*/ */
protected function getSpace($width, $height) { protected function getSpace($width, $height) {
$left = (int)($width * $this->space->left / 100); $left = (int)($width * $this->space->left / 100);
$right = (int)($width * $this->space->right / 100); $right = (int)($width * $this->space->right / 100);
$top = (int)($height * $this->space->top / 100); $top = (int)($height * $this->space->top / 100);
$bottom = (int)($height * $this->space->bottom / 100); $bottom = (int)($height * $this->space->bottom / 100);
return array($left, $right, $top, $bottom); return array($left, $right, $top, $bottom);
} }
} }
registerClass('Component', TRUE); registerClass('Component', TRUE);

View File

@ -34,7 +34,7 @@ require_once ARTICHOW."/inc/Font.class.php";
require_once ARTICHOW."/inc/Gradient.class.php"; require_once ARTICHOW."/inc/Gradient.class.php";
/** /**
* A graph * A graph
* *
* @package Artichow * @package Artichow
*/ */
@ -53,35 +53,35 @@ class awGraph extends awImage {
* @var int * @var int
*/ */
protected $timeout = 0; protected $timeout = 0;
/** /**
* Graph timing ? * Graph timing ?
* *
* @var bool * @var bool
*/ */
protected $timing; protected $timing;
/** /**
* Components * Components
* *
* @var array * @var array
*/ */
private $components = array(); private $components = array();
/** /**
* Some labels to add to the component * Some labels to add to the component
* *
* @var array * @var array
*/ */
protected $labels = array(); protected $labels = array();
/** /**
* Graph title * Graph title
* *
* @var Label * @var Label
*/ */
public $title; public $title;
/** /**
* Construct a new graph * Construct a new graph
* *
@ -91,29 +91,33 @@ class awGraph extends awImage {
* @param int $timeout Cache timeout (unix timestamp) * @param int $timeout Cache timeout (unix timestamp)
*/ */
public function __construct($width = NULL, $height = NULL, $name = NULL, $timeout = 0) { 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(); parent::__construct();
$this->setSize($width, $height); $this->setSize($width, $height);
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
$this->name = $name; $this->name = $name;
$this->timeout = $timeout; $this->timeout = $timeout;
// Clean sometimes all the cache // Clean sometimes all the cache
if(mt_rand(0, 5000) === 0) { if(mt_rand(0, 5000) === 0) {
awGraph::cleanCache(); awGraph::cleanCache();
} }
if($this->name !== NULL) { if($this->name !== NULL) {
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time"; $file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."-time";
if(is_file($file)) { if(is_file($file)) {
$type = awGraph::cleanGraphCache($file); $type = awGraph::cleanGraphCache($file);
if($type === NULL) { if($type === NULL) {
awGraph::deleteFromCache($this->name); awGraph::deleteFromCache($this->name);
} else { } else {
@ -121,23 +125,23 @@ class awGraph extends awImage {
readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name.""); readfile(ARTICHOW_CACHE_DIRECTORY."/".$this->name."");
exit; exit;
} }
} }
} }
} }
$this->title = new awLabel( $this->title = new awLabel(
NULL, NULL,
new awTuffy(16), new $classfontname(16),
NULL, NULL,
0 0
); );
$this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM); $this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM);
} }
/** /**
* Delete a graph from the cache * Delete a graph from the cache
* *
@ -147,59 +151,59 @@ class awGraph extends awImage {
public static function deleteFromCache($name) { public static function deleteFromCache($name) {
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) { if(is_file(ARTICHOW_CACHE_DIRECTORY."/".$name."-time")) {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name.""); unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."");
unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time"); unlink(ARTICHOW_CACHE_DIRECTORY."/".$name."-time");
} }
} }
} }
/** /**
* Delete all graphs from the cache * Delete all graphs from the cache
*/ */
public static function deleteAllCache() { public static function deleteAllCache() {
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
$dp = opendir(ARTICHOW_CACHE_DIRECTORY); $dp = opendir(ARTICHOW_CACHE_DIRECTORY);
while($file = readdir($dp)) { while($file = readdir($dp)) {
if($file !== '.' and $file != '..') { if($file !== '.' and $file != '..') {
unlink(ARTICHOW_CACHE_DIRECTORY."/".$file); unlink(ARTICHOW_CACHE_DIRECTORY."/".$file);
} }
} }
} }
} }
/** /**
* Clean cache * Clean cache
*/ */
public static function cleanCache() { public static function cleanCache() {
if(ARTICHOW_CACHE) { if(ARTICHOW_CACHE) {
$glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time"); $glob = glob(ARTICHOW_CACHE_DIRECTORY."/*-time");
foreach($glob as $file) { foreach($glob as $file) {
$type = awGraph::cleanGraphCache($file); $type = awGraph::cleanGraphCache($file);
if($type === NULL) { if($type === NULL) {
$name = preg_replace("/.*\/(.*)\-time/", "\\1", $file); $name = preg_replace("/.*\/(.*)\-time/", "\\1", $file);
awGraph::deleteFromCache($name); awGraph::deleteFromCache($name);
} }
} }
} }
} }
/** /**
* Enable/Disable Graph timing * Enable/Disable Graph timing
* *
@ -208,18 +212,18 @@ class awGraph extends awImage {
public function setTiming($timing) { public function setTiming($timing) {
$this->timing = (bool)$timing; $this->timing = (bool)$timing;
} }
/** /**
* Add a component to the graph * Add a component to the graph
* *
* @param awComponent $component * @param awComponent $component
*/ */
public function add(awComponent $component) { public function add(awComponent $component) {
$this->components[] = $component; $this->components[] = $component;
} }
/** /**
* Add a label to the 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 * @param int $y Position on Y axis of the center of the text
*/ */
public function addLabel(awLabel $label, $x, $y) { public function addLabel(awLabel $label, $x, $y) {
$this->labels[] = array( $this->labels[] = array(
$label, $x, $y $label, $x, $y
); );
} }
/** /**
* Add a label to the component with aboslute position * Add a label to the component with aboslute position
* *
@ -242,13 +246,13 @@ class awGraph extends awImage {
* @param awPoint $point Text position * @param awPoint $point Text position
*/ */
public function addAbsLabel(awLabel $label, awPoint $point) { public function addAbsLabel(awLabel $label, awPoint $point) {
$this->labels[] = array( $this->labels[] = array(
$label, $point $label, $point
); );
} }
/** /**
* Build the graph and draw component on it * Build the graph and draw component on it
* Image is sent to the user browser * 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. * @param string $file Save the image in the specified file. Let it null to print image to screen.
*/ */
public function draw($file = NULL) { public function draw($file = NULL) {
if($this->timing) { if($this->timing) {
$time = microtimeFloat(); $time = microtimeFloat();
} }
$this->create(); $this->create();
foreach($this->components as $component) { foreach($this->components as $component) {
$this->drawComponent($component); $this->drawComponent($component);
} }
$this->drawTitle(); $this->drawTitle();
$this->drawShadow(); $this->drawShadow();
$this->drawLabels(); $this->drawLabels();
if($this->timing) { if($this->timing) {
$this->drawTiming(microtimeFloat() - $time); $this->drawTiming(microtimeFloat() - $time);
} }
@ -280,104 +284,104 @@ class awGraph extends awImage {
if(ARTICHOW_CACHE and $this->name !== NULL) { if(ARTICHOW_CACHE and $this->name !== NULL) {
ob_start(); ob_start();
} }
$this->send($file); $this->send($file);
if(ARTICHOW_CACHE and $this->name !== NULL) { if(ARTICHOW_CACHE and $this->name !== NULL) {
$data = ob_get_contents(); $data = ob_get_contents();
if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) { if(is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
trigger_error("Cache directory is not writable"); trigger_error("Cache directory is not writable");
} }
$file = ARTICHOW_CACHE_DIRECTORY."/".$this->name.""; $file = ARTICHOW_CACHE_DIRECTORY."/".$this->name."";
file_put_contents($file, $data); file_put_contents($file, $data);
$file .= "-time"; $file .= "-time";
file_put_contents($file, $this->timeout."\n".$this->getFormat()); file_put_contents($file, $this->timeout."\n".$this->getFormat());
ob_clean(); ob_clean();
echo $data; echo $data;
} }
} }
private function drawLabels() { private function drawLabels() {
$drawer = $this->getDrawer(); $drawer = $this->getDrawer();
foreach($this->labels as $array) { foreach($this->labels as $array) {
if(count($array) === 3) { if(count($array) === 3) {
// Text in relative position // Text in relative position
list($label, $x, $y) = $array; list($label, $x, $y) = $array;
$point = new awPoint( $point = new awPoint(
$x * $this->width, $x * $this->width,
$y * $this->height $y * $this->height
); );
} else { } else {
// Text in absolute position // Text in absolute position
list($label, $point) = $array; list($label, $point) = $array;
} }
$label->draw($drawer, $point); $label->draw($drawer, $point);
} }
} }
private function drawTitle() { private function drawTitle() {
$drawer = $this->getDrawer(); $drawer = $this->getDrawer();
$point = new awPoint( $point = new awPoint(
$this->width / 2, $this->width / 2,
10 10
); );
$this->title->draw($drawer, $point); $this->title->draw($drawer, $point);
} }
private function drawTiming($time) { private function drawTiming($time) {
$drawer = $this->getDrawer(); $drawer = $this->getDrawer();
$label = new awLabel; $label = new awLabel;
$label->set("(".sprintf("%.3f", $time)." s)"); $label->set("(".sprintf("%.3f", $time)." s)");
$label->setAlign(awLabel::LEFT, awLabel::TOP); $label->setAlign(awLabel::LEFT, awLabel::TOP);
$label->border->show(); $label->border->show();
$label->setPadding(1, 0, 0, 0); $label->setPadding(1, 0, 0, 0);
$label->setBackgroundColor(new awColor(230, 230, 230, 25)); $label->setBackgroundColor(new awColor(230, 230, 230, 25));
$label->draw($drawer, new awPoint(5, $drawer->height - 5)); $label->draw($drawer, new awPoint(5, $drawer->height - 5));
} }
private static function cleanGraphCache($file) { private static function cleanGraphCache($file) {
list( list(
$time, $time,
$type $type
) = explode("\n", file_get_contents($file)); ) = explode("\n", file_get_contents($file));
$time = (int)$time; $time = (int)$time;
if($time !== 0 and $time < time()) { if($time !== 0 and $time < time()) {
return NULL; return NULL;
} else { } else {
return $type; return $type;
} }
} }
} }
@ -387,8 +391,8 @@ registerClass('Graph');
/* /*
* To preserve PHP 4 compatibility * To preserve PHP 4 compatibility
*/ */
function microtimeFloat() { function microtimeFloat() {
list($usec, $sec) = explode(" ", microtime()); list($usec, $sec) = explode(" ", microtime());
return (float)$usec + (float)$sec; return (float)$usec + (float)$sec;
} }
?> ?>

View File

@ -22,28 +22,28 @@ class awMathFunction implements awLegendable {
* @var Line * @var Line
*/ */
public $line; public $line;
/** /**
* Marks for your plot * Marks for your plot
* *
* @var Mark * @var Mark
*/ */
public $mark; public $mark;
/** /**
* Callback function * Callback function
* *
* @var string * @var string
*/ */
public $f; public $f;
/** /**
* Start the drawing from this value * Start the drawing from this value
* *
* @var float * @var float
*/ */
public $fromX; public $fromX;
/** /**
* Stop the drawing at this value * Stop the drawing at this value
* *
@ -57,7 +57,7 @@ class awMathFunction implements awLegendable {
* @var Color * @var Color
*/ */
protected $color; protected $color;
/** /**
* Construct the function * Construct the function
* *
@ -66,17 +66,17 @@ class awMathFunction implements awLegendable {
* @param float $toX * @param float $toX
*/ */
public function __construct($f, $fromX = NULL, $toX = NULL) { public function __construct($f, $fromX = NULL, $toX = NULL) {
$this->f = (string)$f; $this->f = (string)$f;
$this->fromX = is_null($fromX) ? NULL : (float)$fromX; $this->fromX = is_null($fromX) ? NULL : (float)$fromX;
$this->toX = is_null($toX) ? NULL : (float)$toX; $this->toX = is_null($toX) ? NULL : (float)$toX;
$this->line = new awLine; $this->line = new awLine;
$this->mark = new awMark; $this->mark = new awMark;
$this->color = new awBlack; $this->color = new awBlack;
} }
/** /**
* Change line color * Change line color
* *
@ -85,7 +85,7 @@ class awMathFunction implements awLegendable {
public function setColor(awColor $color) { public function setColor(awColor $color) {
$this->color = $color; $this->color = $color;
} }
/** /**
* Get line color * Get line color
* *
@ -142,56 +142,56 @@ class awMathFunction implements awLegendable {
} }
registerClass('MathFunction'); registerClass('MathFunction');
/** /**
* For mathematics functions * For mathematics functions
* *
* @package Artichow * @package Artichow
*/ */
class awMathPlot extends awComponent { class awMathPlot extends awComponent {
/** /**
* Functions * Functions
* *
* @var array * @var array
*/ */
protected $functions = array(); protected $functions = array();
/** /**
* Grid properties * Grid properties
* *
* @var Grid * @var Grid
*/ */
public $grid; public $grid;
/** /**
* X axis * X axis
* *
* @var Axis * @var Axis
*/ */
public $xAxis; public $xAxis;
/** /**
* Y axis * Y axis
* *
* @var Axis * @var Axis
*/ */
public $yAxis; public $yAxis;
/** /**
* Extremum * Extremum
* *
* @var Side * @var Side
*/ */
private $extremum = NULL; private $extremum = NULL;
/** /**
* Interval * Interval
* *
* @var float * @var float
*/ */
private $interval = 1; private $interval = 1;
/** /**
* Build the plot * Build the plot
* *
@ -201,44 +201,47 @@ class awMathPlot extends awComponent {
* @param int $yMin Minimum Y value * @param int $yMin Minimum Y value
*/ */
public function __construct($xMin, $xMax, $yMax, $yMin) { public function __construct($xMin, $xMax, $yMax, $yMin) {
parent::__construct(); parent::__construct();
$this->setPadding(8, 8, 8, 8); $this->setPadding(8, 8, 8, 8);
$this->grid = new awGrid; $this->grid = new awGrid;
// Hide grid by default // Hide grid by default
$this->grid->hide(TRUE); $this->grid->hide(TRUE);
// Set extremum // Set extremum
$this->extremum = new awSide($xMin, $xMax, $yMax, $yMin); $this->extremum = new awSide($xMin, $xMax, $yMax, $yMin);
// Create axis // Create axis
$this->xAxis = new awAxis; $this->xAxis = new awAxis;
$this->xAxis->setTickStyle(awTick::IN); $this->xAxis->setTickStyle(awTick::IN);
$this->xAxis->label->hideValue(0); $this->xAxis->label->hideValue(0);
$this->initAxis($this->xAxis); $this->initAxis($this->xAxis);
$this->yAxis = new awAxis; $this->yAxis = new awAxis;
$this->yAxis->setTickStyle(awTick::IN); $this->yAxis->setTickStyle(awTick::IN);
$this->yAxis->label->hideValue(0); $this->yAxis->label->hideValue(0);
$this->initAxis($this->yAxis); $this->initAxis($this->yAxis);
} }
protected function initAxis(awAxis $axis) { 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->setLabelPrecision(1);
$axis->addTick('major', new awTick(0, 5)); $axis->addTick('major', new awTick(0, 5));
$axis->addTick('minor', new awTick(0, 3)); $axis->addTick('minor', new awTick(0, 3));
$axis->addTick('micro', new awTick(0, 1)); $axis->addTick('micro', new awTick(0, 1));
$axis->setNumberByTick('minor', 'major', 1); $axis->setNumberByTick('minor', 'major', 1);
$axis->setNumberByTick('micro', 'minor', 4); $axis->setNumberByTick('micro', 'minor', 4);
$axis->label->setFont(new awTuffy(7)); $axis->label->setFont(new $classfontname(7));
} }
/** /**
* Interval to calculate values * Interval to calculate values
* *
@ -247,7 +250,7 @@ class awMathPlot extends awComponent {
public function setInterval($interval) { public function setInterval($interval) {
$this->interval = (float)$interval; $this->interval = (float)$interval;
} }
/** /**
* Add a formula f(x) * Add a formula f(x)
* *
@ -256,44 +259,44 @@ class awMathPlot extends awComponent {
* @param int $type Type for the legend * @param int $type Type for the legend
*/ */
public function add(awMathFunction $function, $name = NULL, $type = awLegend::LINE) { public function add(awMathFunction $function, $name = NULL, $type = awLegend::LINE) {
$this->functions[] = $function; $this->functions[] = $function;
if($name !== NULL) { if($name !== NULL) {
$this->legend->add($function, $name, $type); $this->legend->add($function, $name, $type);
} }
} }
public function init(awDrawer $drawer) { public function init(awDrawer $drawer) {
list($x1, $y1, $x2, $y2) = $this->getPosition(); list($x1, $y1, $x2, $y2) = $this->getPosition();
$this->xAxis->line->setX($x1, $x2); $this->xAxis->line->setX($x1, $x2);
$this->xAxis->label->setAlign(NULL, awLabel::BOTTOM); $this->xAxis->label->setAlign(NULL, awLabel::BOTTOM);
$this->xAxis->label->move(0, 3); $this->xAxis->label->move(0, 3);
$this->xAxis->setRange($this->extremum->left, $this->extremum->right); $this->xAxis->setRange($this->extremum->left, $this->extremum->right);
$this->yAxis->line->setY($y2, $y1); $this->yAxis->line->setY($y2, $y1);
$this->yAxis->label->setAlign(awLabel::RIGHT); $this->yAxis->label->setAlign(awLabel::RIGHT);
$this->yAxis->label->move(-6, 0); $this->yAxis->label->move(-6, 0);
$this->yAxis->reverseTickStyle(); $this->yAxis->reverseTickStyle();
$this->yAxis->setRange($this->extremum->bottom, $this->extremum->top); $this->yAxis->setRange($this->extremum->bottom, $this->extremum->top);
$this->xAxis->setYCenter($this->yAxis, 0); $this->xAxis->setYCenter($this->yAxis, 0);
$this->yAxis->setXCenter($this->xAxis, 0); $this->yAxis->setXCenter($this->xAxis, 0);
if($this->yAxis->getLabelNumber() === NULL) { if($this->yAxis->getLabelNumber() === NULL) {
$number = $this->extremum->top - $this->extremum->bottom + 1; $number = $this->extremum->top - $this->extremum->bottom + 1;
$this->yAxis->setLabelNumber($number); $this->yAxis->setLabelNumber($number);
} }
if($this->xAxis->getLabelNumber() === NULL) { if($this->xAxis->getLabelNumber() === NULL) {
$number = $this->extremum->right - $this->extremum->left + 1; $number = $this->extremum->right - $this->extremum->left + 1;
$this->xAxis->setLabelNumber($number); $this->xAxis->setLabelNumber($number);
} }
// Set ticks // Set ticks
/* <php5> */ /* <php5> */
$this->xAxis->tick('major')->setNumber($this->xAxis->getLabelNumber()); $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->xAxis->ticks['major']->setNumber($this->xAxis->getLabelNumber());
$this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber()); $this->yAxis->ticks['major']->setNumber($this->yAxis->getLabelNumber());
-- </php4> */ -- </php4> */
// Set axis labels // Set axis labels
$labels = array(); $labels = array();
for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) { for($i = 0, $count = $this->xAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i; $labels[] = $i;
} }
$this->xAxis->label->set($labels); $this->xAxis->label->set($labels);
$labels = array(); $labels = array();
for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) { for($i = 0, $count = $this->yAxis->getLabelNumber(); $i < $count; $i++) {
$labels[] = $i; $labels[] = $i;
} }
$this->yAxis->label->set($labels); $this->yAxis->label->set($labels);
parent::init($drawer); parent::init($drawer);
// Create the grid // Create the grid
$this->createGrid(); $this->createGrid();
// Draw the grid // Draw the grid
$this->grid->draw($drawer, $x1, $y1, $x2, $y2); $this->grid->draw($drawer, $x1, $y1, $x2, $y2);
} }
public function drawEnvelope(awDrawer $drawer) { public function drawEnvelope(awDrawer $drawer) {
// Draw axis // Draw axis
$this->xAxis->draw($drawer); $this->xAxis->draw($drawer);
$this->yAxis->draw($drawer); $this->yAxis->draw($drawer);
} }
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) { public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) {
foreach($this->functions as $function) { foreach($this->functions as $function) {
$f = $function->f; $f = $function->f;
$fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX; $fromX = is_null($function->fromX) ? $this->extremum->left : $function->fromX;
$toX = is_null($function->toX) ? $this->extremum->right : $function->toX; $toX = is_null($function->toX) ? $this->extremum->right : $function->toX;
$old = NULL; $old = NULL;
for($i = $fromX; $i <= $toX; $i += $this->interval) { for($i = $fromX; $i <= $toX; $i += $this->interval) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i))); $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($i, $f($i)));
if($p->y >= $y1 and $p->y <= $y2) { if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p); $function->mark->draw($drawer, $p);
} }
if($old !== NULL) { if($old !== NULL) {
$line = $function->line; $line = $function->line;
$line->setLocation($old, $p); $line->setLocation($old, $p);
if( if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or ($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2) ($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -367,26 +370,26 @@ class awMathPlot extends awComponent {
$line $line
); );
} }
} }
$old = $p; $old = $p;
} }
// Draw last point if needed // Draw last point if needed
if($old !== NULL and $i - $this->interval != $toX) { if($old !== NULL and $i - $this->interval != $toX) {
$p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX))); $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($toX, $f($toX)));
if($p->y >= $y1 and $p->y <= $y2) { if($p->y >= $y1 and $p->y <= $y2) {
$function->mark->draw($drawer, $p); $function->mark->draw($drawer, $p);
} }
$line = $function->line; $line = $function->line;
$line->setLocation($old, $p); $line->setLocation($old, $p);
if( if(
($line->p1->y >= $y1 and $line->p1->y <= $y2) or ($line->p1->y >= $y1 and $line->p1->y <= $y2) or
($line->p2->y >= $y1 and $line->p2->y <= $y2) ($line->p2->y >= $y1 and $line->p2->y <= $y2)
@ -396,34 +399,34 @@ class awMathPlot extends awComponent {
$line $line
); );
} }
} }
} }
} }
protected function createGrid() { protected function createGrid() {
// Horizontal lines of the grid // Horizontal lines of the grid
$major = $this->yAxis->tick('major'); $major = $this->yAxis->tick('major');
$interval = $major->getInterval(); $interval = $major->getInterval();
$number = $this->yAxis->getLabelNumber() - 1; $number = $this->yAxis->getLabelNumber() - 1;
$h = array(); $h = array();
if($number > 0) { if($number > 0) {
for($i = 0; $i <= $number; $i++) { for($i = 0; $i <= $number; $i++) {
$h[] = $i / $number; $h[] = $i / $number;
} }
} }
// Vertical lines // Vertical lines
$major = $this->xAxis->tick('major'); $major = $this->xAxis->tick('major');
$interval = $major->getInterval(); $interval = $major->getInterval();
$number = $this->xAxis->getLabelNumber() - 1; $number = $this->xAxis->getLabelNumber() - 1;
$w = array(); $w = array();
if($number > 0) { if($number > 0) {
for($i = 0; $i <= $number; $i++) { for($i = 0; $i <= $number; $i++) {
@ -432,9 +435,9 @@ class awMathPlot extends awComponent {
} }
} }
} }
$this->grid->setGrid($w, $h); $this->grid->setGrid($w, $h);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -7,32 +7,32 @@
* *
*/ */
/** /**
* Built-in PHP fonts * Built-in PHP fonts
* *
* @package Artichow * @package Artichow
*/ */
class awFont { class awFont {
/** /**
* Used font * Used font
* *
* @param int $font * @param int $font
*/ */
public $font; public $font;
/** /**
* Build the font * Build the font
* *
* @param int $font Font identifier * @param int $font Font identifier
*/ */
public function __construct($font) { public function __construct($font) {
$this->font = $font; $this->font = $font;
} }
/** /**
* Draw a text * Draw a text
* *
@ -41,28 +41,28 @@ class awFont {
* @param awText $text The text * @param awText $text The text
*/ */
public function draw(awDrawer $drawer, awPoint $p, awText $text) { public function draw(awDrawer $drawer, awPoint $p, awText $text) {
$angle = $text->getAngle(); $angle = $text->getAngle();
if($angle !== 90 and $angle !== 0) { if($angle !== 90 and $angle !== 0) {
trigger_error("You can only use 0° and 90°", E_USER_ERROR); trigger_error("You can only use 0° and 90°", E_USER_ERROR);
} }
if($angle === 90) { if($angle === 90) {
$function = 'imagestringup'; $function = 'imagestringup';
} else { } else {
$function = 'imagestring'; $function = 'imagestring';
} }
if($angle === 90) { if($angle === 90) {
$add = $this->getTextHeight($text); $add = $this->getTextHeight($text);
} else { } else {
$add = 0; $add = 0;
} }
$color = $text->getColor(); $color = $text->getColor();
$rgb = $color->getColor($drawer->resource); $rgb = $color->getColor($drawer->resource);
$function( $function(
$drawer->resource, $drawer->resource,
$this->font, $this->font,
@ -71,55 +71,55 @@ class awFont {
$text->getText(), $text->getText(),
$rgb $rgb
); );
} }
/** /**
* Get the width of a string * Get the width of a string
* *
* @param awText $text A string * @param awText $text A string
*/ */
public function getTextWidth(awText $text) { public function getTextWidth(awText $text) {
if($text->getAngle() === 90) { if($text->getAngle() === 90) {
$text->setAngle(45); $text->setAngle(45);
return $this->getTextHeight($text); return $this->getTextHeight($text);
} else if($text->getAngle() === 45) { } else if($text->getAngle() === 45) {
$text->setAngle(90); $text->setAngle(90);
} }
$font = $text->getFont(); $font = $text->getFont();
$fontWidth = imagefontwidth($font->font); $fontWidth = imagefontwidth($font->font);
if($fontWidth === FALSE) { if($fontWidth === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR); trigger_error("Unable to get font size", E_USER_ERROR);
} }
return (int)$fontWidth * strlen($text->getText()); return (int)$fontWidth * strlen($text->getText());
} }
/** /**
* Get the height of a string * Get the height of a string
* *
* @param awText $text A string * @param awText $text A string
*/ */
public function getTextHeight(awText $text) { public function getTextHeight(awText $text) {
if($text->getAngle() === 90) { if($text->getAngle() === 90) {
$text->setAngle(45); $text->setAngle(45);
return $this->getTextWidth($text); return $this->getTextWidth($text);
} else if($text->getAngle() === 45) { } else if($text->getAngle() === 45) {
$text->setAngle(90); $text->setAngle(90);
} }
$font = $text->getFont(); $font = $text->getFont();
$fontHeight = imagefontheight($font->font); $fontHeight = imagefontheight($font->font);
if($fontHeight === FALSE) { if($fontHeight === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR); trigger_error("Unable to get font size", E_USER_ERROR);
} }
return (int)$fontHeight; return (int)$fontHeight;
} }
@ -149,13 +149,13 @@ class awTTFFont extends awFont {
* @param int $size Font size * @param int $size Font size
*/ */
public function __construct($font, $size) { public function __construct($font, $size) {
parent::__construct($font); parent::__construct($font);
$this->size = (int)$size; $this->size = (int)$size;
} }
/** /**
* Draw a text * Draw a text
* *
@ -164,23 +164,23 @@ class awTTFFont extends awFont {
* @param awText $text The text * @param awText $text The text
*/ */
public function draw(awDrawer $drawer, awPoint $p, awText $text) { public function draw(awDrawer $drawer, awPoint $p, awText $text) {
// Make easier font positionment // Make easier font positionment
$text->setText($text->getText()." "); $text->setText($text->getText()." ");
$color = $text->getColor(); $color = $text->getColor();
$rgb = $color->getColor($drawer->resource); $rgb = $color->getColor($drawer->resource);
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText()); $box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
$height = - $box[5]; $height = - $box[5];
$box = imagettfbbox($this->size, 90, $this->font, $text->getText()); $box = imagettfbbox($this->size, 90, $this->font, $text->getText());
$width = abs($box[6] - $box[2]); $width = abs($box[6] - $box[2]);
// Restore old text // Restore old text
$text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1)); $text->setText(substr($text->getText(), 0, strlen($text->getText()) - 1));
imagettftext( imagettftext(
$drawer->resource, $drawer->resource,
$this->size, $this->size,
@ -191,45 +191,45 @@ class awTTFFont extends awFont {
$this->font, $this->font,
$text->getText() $text->getText()
); );
} }
/** /**
* Get the width of a string * Get the width of a string
* *
* @param awText $text A string * @param awText $text A string
*/ */
public function getTextWidth(awText $text) { public function getTextWidth(awText $text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText()); $box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) { if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR); trigger_error("Unable to get font size", E_USER_ERROR);
return; return;
} }
list(, , $x2, $y2, , , $x1, $y1) = $box; list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($x2 - $x1); return abs($x2 - $x1);
} }
/** /**
* Get the height of a string * Get the height of a string
* *
* @param awText $text A string * @param awText $text A string
*/ */
public function getTextHeight(awText $text) { public function getTextHeight(awText $text) {
$box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText()); $box = imagettfbbox($this->size, $text->getAngle(), $this->font, $text->getText());
if($box === FALSE) { if($box === FALSE) {
trigger_error("Unable to get font size", E_USER_ERROR); trigger_error("Unable to get font size", E_USER_ERROR);
return; return;
} }
list(, , $x2, $y2, , , $x1, $y1) = $box; list(, , $x2, $y2, , , $x1, $y1) = $box;
return abs($y2 - $y1); return abs($y2 - $y1);
} }
@ -246,14 +246,14 @@ for($i = 1; $i <= 5; $i++) {
$php .= ' $php .= '
class awFont'.$i.' extends awFont { class awFont'.$i.' extends awFont {
public function __construct() { public function __construct() {
parent::__construct('.$i.'); parent::__construct('.$i.');
} }
} }
'; ';
if(ARTICHOW_PREFIX !== 'aw') { if(ARTICHOW_PREFIX !== 'aw') {
$php .= ' $php .= '
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' { class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
@ -269,19 +269,20 @@ $php = '';
foreach($fonts as $font) { foreach($fonts as $font) {
// DOL_CHANGE LDR Fix to allow - into font names
$php .= ' $php .= '
class aw'.$font.' extends awTTFFont { class aw'.str_replace('-','_',$font).' extends awTTFFont {
public function __construct($size) { public function __construct($size) {
parent::__construct(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size); parent::__construct(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
} }
} }
'; ';
if(ARTICHOW_PREFIX !== 'aw') { if(ARTICHOW_PREFIX !== 'aw') {
$php .= ' $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 .= ' $php .= '
class awFont'.$i.' extends awFont { class awFont'.$i.' extends awFont {
function awFont'.$i.'() { function awFont'.$i.'() {
parent::awFont('.$i.'); parent::awFont('.$i.');
} }
} }
'; ';
if(ARTICHOW_PREFIX !== 'aw') { if(ARTICHOW_PREFIX !== 'aw') {
$php .= ' $php .= '
class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' { class '.ARTICHOW_PREFIX.'Font'.$i.' extends awFont'.$i.' {
@ -324,14 +325,14 @@ foreach($fonts as $font) {
$php .= ' $php .= '
class aw'.$font.' extends awTTFFont { class aw'.$font.' extends awTTFFont {
function aw'.$font.'($size) { function aw'.$font.'($size) {
parent::awTTFFont(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size); parent::awTTFFont(\''.(ARTICHOW_FONT.DIRECTORY_SEPARATOR.$font.'.ttf').'\', $size);
} }
} }
'; ';
if(ARTICHOW_PREFIX !== 'aw') { if(ARTICHOW_PREFIX !== 'aw') {
$php .= ' $php .= '
class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' { class '.ARTICHOW_PREFIX.$font.' extends aw'.$font.' {

View File

@ -29,7 +29,7 @@
* \ingroup core * \ingroup core
* \brief File that defines environment for all Dolibarr process (pages or scripts) * \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 * 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('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_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('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 // 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')) { 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('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); } if (! defined('MAGPIE_DIR')) { define('MAGPIE_DIR', MAGPIERSS_PATH); }