From be5125c85f77a026c1e06386865bc317b1002b67 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 29 Mar 2007 19:27:15 +0000 Subject: [PATCH] =?UTF-8?q?Possibilit=E9=20de=20forcer=20la=20largeur=20mi?= =?UTF-8?q?nimum=20de=20la=20zone=20de=20l=E9gende=20des=20tableaux?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/compta/bank/graph.php | 20 ++- htdocs/dolgraph.class.php | 301 ++++++++++++++++++----------------- 2 files changed, 168 insertions(+), 153 deletions(-) diff --git a/htdocs/compta/bank/graph.php b/htdocs/compta/bank/graph.php index 83378473611..6ebd714e625 100644 --- a/htdocs/compta/bank/graph.php +++ b/htdocs/compta/bank/graph.php @@ -148,7 +148,7 @@ if ($account > 0) } // Fabrication tableau 1 - $file= $conf->banque->dir_temp."/solde.$account.$year.$month.png"; + $file= $conf->banque->dir_temp."/balance.$account.$year.$month.png"; $title=$langs->transnoentities("Balance").' '.$langs->transnoentities("Month").': '.$month.' '.$langs->transnoentities("Year").': '.$year; $graph_datas=array(); foreach($datas as $i => $val) @@ -160,6 +160,7 @@ if ($account > 0) $px->SetData($graph_datas); if ($acct->min_desired) $px->SetLegend(array($langs->transnoentities("Balance"),$langs->transnoentities("BalanceMinimalDesired"))); else $px->SetLegend(array($langs->transnoentities("Balance"))); + $px->SetLegendWidthMin(180); $px->SetMaxValue($px->GetCeilMaxValue()<0?0:$px->GetCeilMaxValue()); $px->SetMinValue($px->GetFloorMinValue()>0?0:$px->GetFloorMinValue()); $px->SetTitle($title); @@ -246,7 +247,7 @@ if ($account > 0) } // Fabrication tableau 2 - $file= $conf->banque->dir_temp."/solde.$account.$year.png"; + $file= $conf->banque->dir_temp."/balance.$account.$year.png"; $title=$langs->transnoentities("Balance").' '.$langs->transnoentities("Year").': '.$year; $graph_datas=array(); foreach($datas as $i => $val) @@ -258,6 +259,7 @@ if ($account > 0) $px->SetData($graph_datas); if ($acct->min_desired) $px->SetLegend(array($langs->transnoentities("Balance"),$langs->transnoentities("BalanceMinimalDesired"))); else $px->SetLegend(array($langs->transnoentities("Balance"))); + $px->SetLegendWidthMin(180); $px->SetMaxValue($px->GetCeilMaxValue()<0?0:$px->GetCeilMaxValue()); $px->SetMinValue($px->GetFloorMinValue()>0?0:$px->GetFloorMinValue()); $px->SetTitle($title); @@ -328,7 +330,7 @@ if ($account > 0) } // Fabrication tableau 3 - $file= $conf->banque->dir_temp."/solde.$account.png"; + $file= $conf->banque->dir_temp."/balance.$account.png"; $title=$langs->transnoentities("Balance"); $graph_datas=array(); foreach($datas as $i => $val) @@ -340,6 +342,7 @@ if ($account > 0) $px->SetData($graph_datas); if ($acct->min_desired) $px->SetLegend(array($langs->transnoentities("Balance"),$langs->transnoentities("BalanceMinimalDesired"))); else $px->SetLegend(array($langs->transnoentities("Balance"))); + $px->SetLegendWidthMin(180); $px->SetMaxValue($px->GetCeilMaxValue()<0?0:$px->GetCeilMaxValue()); $px->SetMinValue($px->GetFloorMinValue()>0?0:$px->GetFloorMinValue()); $px->SetTitle($title); @@ -408,7 +411,7 @@ if ($account > 0) } // Fabrication tableau 4 - $file= $conf->banque->dir_temp."/mouvement.$account.$year.png"; + $file= $conf->banque->dir_temp."/movement.$account.$year.png"; $title=$langs->transnoentities("Movements").' '.$langs->transnoentities("Year").': '.$year; $graph_datas=array(); foreach($data_credit as $i => $val) @@ -418,6 +421,7 @@ if ($account > 0) $px = new DolGraph(); $px->SetData($graph_datas); $px->SetLegend(array($langs->transnoentities("Credit"),$langs->transnoentities("Debit"))); + $px->SetLegendWidthMin(180); $px->SetMaxValue($px->GetCeilMaxValue()<0?0:$px->GetCeilMaxValue()); $px->SetMinValue($px->GetFloorMinValue()>0?0:$px->GetFloorMinValue()); $px->SetTitle($title); @@ -438,22 +442,22 @@ if ($account > 0) print ''; print ''; print ''; print ''; print ''; diff --git a/htdocs/dolgraph.class.php b/htdocs/dolgraph.class.php index 96860448082..35015bcc404 100644 --- a/htdocs/dolgraph.class.php +++ b/htdocs/dolgraph.class.php @@ -58,7 +58,9 @@ class DolGraph var $PrecisionY=-1; var $SetHorizTickIncrement=-1; var $SetNumXTicks=-1; - + var $Legend=''; + var $LegendWidthMin=0; + var $graph; // Objet Graph (PHPlot ou Artichow...) var $error; @@ -285,165 +287,170 @@ class DolGraph } /** - * \brief Génère le fichier graphique sur le disque - * \param file Nom du fichier image + * \brief Génère le fichier graphique sur le disque + * via la librairie PHPlot 5 ou 4 + * \param file Nom du fichier image */ - function draw_phplot($file) - { - dolibarr_syslog("DolGraph.class::draw_phplot this->type=".$this->type); + function draw_phplot($file) + { + dolibarr_syslog("DolGraph.class::draw_phplot this->type=".$this->type); - // Vérifie que chemin vers PHPLOT_PATH est connu et on definie $graphpathdir - $graphpathdir=DOL_DOCUMENT_ROOT."/includes/phplot"; - if (defined('PHPLOT_PATH')) $graphpathdir=PHPLOT_PATH; - if ($conf->global->PHPLOT_PATH) $graphpathdir=$conf->global->PHPLOT_PATH; - if (! eregi('[\\\/]$',$graphpathdir)) $graphpathdir.='/'; - include_once($graphpathdir.'phplot.php'); - $phplotversion=4; - if (defined('TOTY')) $phplotversion=5; + // Vérifie que chemin vers PHPLOT_PATH est connu et on definie $graphpathdir + $graphpathdir=DOL_DOCUMENT_ROOT."/includes/phplot"; + if (defined('PHPLOT_PATH')) $graphpathdir=PHPLOT_PATH; + if ($conf->global->PHPLOT_PATH) $graphpathdir=$conf->global->PHPLOT_PATH; + if (! eregi('[\\\/]$',$graphpathdir)) $graphpathdir.='/'; + include_once($graphpathdir.'phplot.php'); + $phplotversion=4; + if (defined('TOTY')) $phplotversion=5; - // Create graph - $this->graph = new PHPlot($this->width, $this->height); - $this->graph->SetIsInline(1); - $this->graph->SetPlotType($this->type); - $this->graph->SetDataValues($this->data); + // Create graph + $this->graph = new PHPlot($this->width, $this->height); + $this->graph->SetIsInline(1); + $this->graph->SetPlotType($this->type); + $this->graph->SetDataValues($this->data); - // Precision axe y (pas de decimal si 3 chiffres ou plus) - if ($this->PrecisionY > -1) - { - $this->graph->SetPrecisionY($this->PrecisionY); - if ($this->PrecisionY == 0) // Si precision de 0 - { - // Determine un nombre de ticks qui permet decoupage qui tombe juste - $maxval=$this->getMaxValue(); - $minval=$this->getMinValue(); - if ($maxval * $minval >= 0) // Si du meme signe - { - $plage=$maxval; - } - else - { - $plage=$maxval-$minval; - } - if (abs($plage) <= 2) - { - $this->SetMaxValue(2); - $maxticks=2; - } - else - { - $maxticks=10; - if (substr($plage,0,1) == 3 || substr($plage,0,1) == 6) - { - $maxticks=min(6,$plage); - } - elseif (substr($plage,0,1) == 4 || substr($plage,0,1) == 8) - { - $maxticks=min(8,$plage); - } - elseif (substr($plage,0,1) == 7) - { - $maxticks=min(7,$plage); - } - elseif (substr($plage,0,1) == 9) - { - $maxticks=min(9,$plage); - } - } - $this->graph->SetNumVertTicks($maxticks); - // print 'minval='.$minval.' - maxval='.$maxval.' - plage='.$plage.' - maxticks='.$maxticks.'
'; - } - } - else - { - $this->graph->SetPrecisionY(3-strlen(round($this->GetMaxValueInData()))); - } - $this->graph->SetPrecisionX(0); + // Precision axe y (pas de decimal si 3 chiffres ou plus) + if ($this->PrecisionY > -1) + { + $this->graph->SetPrecisionY($this->PrecisionY); + if ($this->PrecisionY == 0) // Si precision de 0 + { + // Determine un nombre de ticks qui permet decoupage qui tombe juste + $maxval=$this->getMaxValue(); + $minval=$this->getMinValue(); + if ($maxval * $minval >= 0) // Si du meme signe + { + $plage=$maxval; + } + else + { + $plage=$maxval-$minval; + } + if (abs($plage) <= 2) + { + $this->SetMaxValue(2); + $maxticks=2; + } + else + { + $maxticks=10; + if (substr($plage,0,1) == 3 || substr($plage,0,1) == 6) + { + $maxticks=min(6,$plage); + } + elseif (substr($plage,0,1) == 4 || substr($plage,0,1) == 8) + { + $maxticks=min(8,$plage); + } + elseif (substr($plage,0,1) == 7) + { + $maxticks=min(7,$plage); + } + elseif (substr($plage,0,1) == 9) + { + $maxticks=min(9,$plage); + } + } + $this->graph->SetNumVertTicks($maxticks); + // print 'minval='.$minval.' - maxval='.$maxval.' - plage='.$plage.' - maxticks='.$maxticks.'
'; + } + } + else + { + $this->graph->SetPrecisionY(3-strlen(round($this->GetMaxValueInData()))); + } + $this->graph->SetPrecisionX(0); - // Set areas - $top_space=40; - if ($phplotversion >= 5) $top_space=25; - $left_space=80; // For y labels - $right_space=10; // If no legend - if (isset($this->Legend)) - { - foreach($this->Legend as $key => $val) - { - $maxlen=max($maxlen,$val); - } - $right_space=50+strlen($maxlen)*6; // For legend - } + // Set areas + $top_space=40; + if ($phplotversion >= 5) $top_space=25; + $left_space=80; // For y labels + $right_space=10; // If no legend + if (isset($this->Legend)) + { + foreach($this->Legend as $key => $val) + { + $maxlen=max($maxlen,$val); + } + $right_space=50+strlen($maxlen)*6; // For legend + if ($this->LegendWidthMin && $right_space < $this->LegendWidthMin) + { + $right_space=$this->LegendWidthMin; + } + } - $this->graph->SetNewPlotAreaPixels($left_space, $top_space, $this->width-$right_space, $this->height-40); - if (isset($this->MaxValue)) - { - $this->graph->SetPlotAreaWorld(0,$this->MinValue,sizeof($this->data),$this->MaxValue); - } + $this->graph->SetNewPlotAreaPixels($left_space, $top_space, $this->width - $right_space, $this->height-40); + if (isset($this->MaxValue)) + { + $this->graph->SetPlotAreaWorld(0,$this->MinValue,sizeof($this->data),$this->MaxValue); + } - // Define title - if (isset($this->title)) $this->graph->SetTitle($this->title); + // Define title + if (isset($this->title)) $this->graph->SetTitle($this->title); - // Défini position du graphe (et legende) au sein de l'image - if (isset($this->Legend)) - { - $this->graph->SetLegendPixels($this->width-$right_space+8,40,''); - $this->graph->SetLegend($this->Legend); - } + // Défini position du graphe (et legende) au sein de l'image + if (isset($this->Legend)) + { + $this->graph->SetLegendPixels($this->width - $right_space+8,40,''); + $this->graph->SetLegend($this->Legend); + } - if (isset($this->SetShading)) - { - $this->graph->SetShading($this->SetShading); - } + if (isset($this->SetShading)) + { + $this->graph->SetShading($this->SetShading); + } - $this->graph->SetTickLength(6); + $this->graph->SetTickLength(6); - $this->graph->SetBackgroundColor($this->bgcolor); - $this->graph->SetDataColors($this->datacolor, $this->bordercolor); + $this->graph->SetBackgroundColor($this->bgcolor); + $this->graph->SetDataColors($this->datacolor, $this->bordercolor); - if ($this->SetNumXTicks > -1) - { - if ($phplotversion >= 5) // If PHPlot 5, for compatibility - { - $this->graph->SetXLabelType(''); - $this->graph->SetNumXTicks($this->SetNumXTicks); - } - else - { - $this->graph->SetNumHorizTicks($this->SetNumXTicks); - } - } - if ($this->SetHorizTickIncrement > -1) - { - // Les ticks sont en mode forc - $this->graph->SetHorizTickIncrement($this->SetHorizTickIncrement); - if ($phplotversion >= 5) // If PHPlot 5, for compatibility - { - $this->graph->SetXLabelType(''); - $this->graph->SetXTickLabelPos('none'); - } - } - else - { - // Les ticks sont en mode automatique - if ($phplotversion >= 5) // If PHPlot 5, for compatibility - { - $this->graph->SetXDataLabelPos('none'); - } - } + if ($this->SetNumXTicks > -1) + { + if ($phplotversion >= 5) // If PHPlot 5, for compatibility + { + $this->graph->SetXLabelType(''); + $this->graph->SetNumXTicks($this->SetNumXTicks); + } + else + { + $this->graph->SetNumHorizTicks($this->SetNumXTicks); + } + } + if ($this->SetHorizTickIncrement > -1) + { + // Les ticks sont en mode forc + $this->graph->SetHorizTickIncrement($this->SetHorizTickIncrement); + if ($phplotversion >= 5) // If PHPlot 5, for compatibility + { + $this->graph->SetXLabelType(''); + $this->graph->SetXTickLabelPos('none'); + } + } + else + { + // Les ticks sont en mode automatique + if ($phplotversion >= 5) // If PHPlot 5, for compatibility + { + $this->graph->SetXDataLabelPos('none'); + } + } - if ($phplotversion >= 5) - { - // Ne gere la transparence qu'en phplot >= 5 - // $this->graph->SetBgImage(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo_2.png','tile'); - $this->graph->SetDrawPlotAreaBackground(array(255,255,255)); - } + if ($phplotversion >= 5) + { + // Ne gere la transparence qu'en phplot >= 5 + // $this->graph->SetBgImage(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo_2.png','tile'); + $this->graph->SetDrawPlotAreaBackground(array(255,255,255)); + } - $this->graph->SetPlotBorderType("left"); // Affiche axe y a gauche uniquement - $this->graph->SetVertTickPosition('plotleft'); // Affiche tick axe y a gauche uniquement - $this->graph->SetOutputFile($file); + $this->graph->SetPlotBorderType("left"); // Affiche axe y a gauche uniquement + $this->graph->SetVertTickPosition('plotleft'); // Affiche tick axe y a gauche uniquement + $this->graph->SetOutputFile($file); - // Generate file - $this->graph->DrawGraph(); - } + // Generate file + $this->graph->DrawGraph(); + } @@ -503,6 +510,10 @@ class DolGraph { $this->Legend = $legend; } + function SetLegendWidthMin($legendwidthmin) + { + $this->LegendWidthMin = $legendwidthmin; + } function SetMaxValue($max) {
'; - $file = "mouvement.$account.$year.png"; + $file = "movement.$account.$year.png"; print ''; print '
'; - $file = "solde.$account.$year.$month.png"; + $file = "balance.$account.$year.$month.png"; print ''; print '
'; - $file = "solde.$account.$year.png"; + $file = "balance.$account.$year.png"; print ''; print '
'; - $file = "solde.$account.png"; + $file = "balance.$account.png"; print ''; print '