Compare commits

...

2 Commits

Author SHA1 Message Date
Dominique FOURNIER
e7c6833d2d Graph : Use Color in namespace
Graph : Allow to hide a serie available in the data
2021-05-18 12:23:17 +02:00
adafd14564 RobotsTxt : The Crawldelay must not be set to 3s if it doesn't exists in the content of the Robots file 2021-05-13 22:31:52 +02:00
2 changed files with 72 additions and 43 deletions

View File

@@ -66,6 +66,9 @@ class Graph
if (! function_exists ("imagecreatetruecolor")) if (! function_exists ("imagecreatetruecolor"))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"No GD support in PHP : can't create image"), 500); "No GD support in PHP : can't create image"), 500);
if (! function_exists ("bccomp"))
throw new \Exception (dgettext ("domframework",
"No BCMath support in PHP : can't create image"), 500);
$this->title = new GraphTitle (); $this->title = new GraphTitle ();
$this->legend = new GraphLegend (); $this->legend = new GraphLegend ();
$this->data = new GraphData (); $this->data = new GraphData ();
@@ -131,7 +134,7 @@ class Graph
if ($bgcolor === null) if ($bgcolor === null)
return $this->bgcolor; return $this->bgcolor;
if (! is_string ($bgcolor) || if (! is_string ($bgcolor) ||
! in_array ($bgcolor, \color::colorList ())) ! in_array ($bgcolor, Color::colorList ()))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid bgcolor provided to graph"), 406); "Invalid bgcolor provided to graph"), 406);
$this->bgcolor = $bgcolor; $this->bgcolor = $bgcolor;
@@ -165,7 +168,7 @@ class Graph
! in_array ($style, array ("line", "points", "linePoints"))) ! in_array ($style, array ("line", "points", "linePoints")))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid style provided to graph"), 406); "Invalid style provided to graph"), 406);
$styleClass = "GraphStyle".$style; $styleClass = __NAMESPACE__."\\GraphStyle".ucfirst($style);
if ($this->style === null || $this->style ()->name () !== $style) if ($this->style === null || $this->style ()->name () !== $style)
{ {
$this->style = new $styleClass (); $this->style = new $styleClass ();
@@ -310,7 +313,7 @@ class Graph
$gd = imagecreatetruecolor ($this->width, $this->height); $gd = imagecreatetruecolor ($this->width, $this->height);
// Put the background color // Put the background color
imagefilledrectangle ($gd, 0, 0, $this->width - 1 , $this->height - 1 , imagefilledrectangle ($gd, 0, 0, $this->width - 1 , $this->height - 1 ,
\color::allocateFromText ($gd, $this->bgcolor)); Color::allocateFromText ($gd, $this->bgcolor));
// The coordinates of the free space. Will be modified each time something // The coordinates of the free space. Will be modified each time something
// is drawing on the graph // is drawing on the graph
// xtop, ytop, xbottom, ybottom // xtop, ytop, xbottom, ybottom
@@ -415,7 +418,14 @@ class GraphSeries
*/ */
public function getList () public function getList ()
{ {
return array_keys ($this->series); $series = [];
foreach ($this->series as $name => $serie)
{
if ($serie->hide() === true)
continue;
$series[] = $name;
}
return $series;
} }
/** Remove an existing serie /** Remove an existing serie
@@ -472,6 +482,9 @@ class GraphSerie
/** The style object for the serie /** The style object for the serie
*/ */
private $style; private $style;
/** If set, hide this serie and do not display it
*/
private $hide;
/** The axis used to draw the serie. /** The axis used to draw the serie.
* If false for main Y axis * If false for main Y axis
@@ -637,6 +650,20 @@ class GraphSerie
$this->style = new $styleClass (); $this->style = new $styleClass ();
return $this->style; return $this->style;
} }
/** Set/Get the hidden state of the serie
* If the parameter is not provided, return the actual state
* @param boolean|null $hide The hidden state
*/
public function hide ($hide = null)
{
if ($hide === null)
return $this->hide;
if (! is_bool ($hide))
throw new \Exception (dgettext ("domframework",
"Invalid hide mode provided to serie"), 406);
$this->hide = $hide;
return $this;
}
/** The serie is based on the secondary Y axis /** The serie is based on the secondary Y axis
* Set the value if the parameter is provided, get the value if the parameter * Set the value if the parameter is provided, get the value if the parameter
@@ -663,6 +690,8 @@ class GraphSerie
*/ */
public function draw ($gd, $free, $axisX, $axisY) public function draw ($gd, $free, $axisX, $axisY)
{ {
if ($this->hide === true)
return;
$this->style->draw ($gd, $free, $this->data, $axisX, $axisY); $this->style->draw ($gd, $free, $this->data, $axisX, $axisY);
} }
} }
@@ -1016,7 +1045,7 @@ class GraphTitle
if ($color === null) if ($color === null)
return $this->color; return $this->color;
if (! is_string ($color) || if (! is_string ($color) ||
! in_array ($color, \color::colorList ())) ! in_array ($color, Color::colorList ()))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid color provided to graph title"), 406); "Invalid color provided to graph title"), 406);
$this->color = $color; $this->color = $color;
@@ -1057,7 +1086,7 @@ class GraphTitle
$x += $free[0]; $x += $free[0];
$y += $free[1]; $y += $free[1];
imagettftext ($gd, $this->fontsize, 0, $x, $y, imagettftext ($gd, $this->fontsize, 0, $x, $y,
\color::allocateFromText ($gd, $this->color), Color::allocateFromText ($gd, $this->color),
$this->fontfile, $this->text); $this->fontfile, $this->text);
return array (intval ($free[0]), intval ($free[1] + $y + $this->padding), return array (intval ($free[0]), intval ($free[1] + $y + $this->padding),
intval ($free[2]), intval ($free[3])); intval ($free[2]), intval ($free[3]));
@@ -1152,7 +1181,7 @@ class GraphLegend
if ($color === null) if ($color === null)
return $this->color; return $this->color;
if (! is_string ($color) || if (! is_string ($color) ||
! in_array ($color, \color::colorList ())) ! in_array ($color, Color::colorList ()))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid color provided to graph legend"), 406); "Invalid color provided to graph legend"), 406);
$this->color = $color; $this->color = $color;
@@ -1168,7 +1197,7 @@ class GraphLegend
if ($bgcolor === null) if ($bgcolor === null)
return $this->bgcolor; return $this->bgcolor;
if (! is_string ($bgcolor) || if (! is_string ($bgcolor) ||
! in_array ($bgcolor, \color::colorList ())) ! in_array ($bgcolor, Color::colorList ()))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid bgcolor provided to graph legend"), 406); "Invalid bgcolor provided to graph legend"), 406);
$this->bgcolor = $bgcolor; $this->bgcolor = $bgcolor;
@@ -1184,7 +1213,7 @@ class GraphLegend
if ($borderColor === null) if ($borderColor === null)
return $this->borderColor; return $this->borderColor;
if (! is_string ($borderColor) || if (! is_string ($borderColor) ||
! in_array ($borderColor, \color::colorList ())) ! in_array ($borderColor, Color::colorList ()))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid borderColor provided to graph legend"), 406); "Invalid borderColor provided to graph legend"), 406);
$this->borderColor = $borderColor; $this->borderColor = $borderColor;
@@ -1244,10 +1273,10 @@ class GraphLegend
$border = 1; $border = 1;
// Draw the background rectangle // Draw the background rectangle
imagefilledrectangle ($gd, $x1, $y1, $x2, $y2, imagefilledrectangle ($gd, $x1, $y1, $x2, $y2,
\color::allocateFromText ($gd, $this->borderColor)); Color::allocateFromText ($gd, $this->borderColor));
imagefilledrectangle ($gd, $x1+$border, $y1+$border, imagefilledrectangle ($gd, $x1+$border, $y1+$border,
$x2-$border, $y2-$border, $x2-$border, $y2-$border,
\color::allocateFromText ($gd, $this->bgcolor)); Color::allocateFromText ($gd, $this->bgcolor));
// Display the serie names // Display the serie names
$y = $y1; $y = $y1;
@@ -1259,7 +1288,7 @@ class GraphLegend
$y += $height; $y += $height;
imagettftext ($gd, $this->fontsize, 0, imagettftext ($gd, $this->fontsize, 0,
$x1 + 30, intval ($y + $height / 2), $x1 + 30, intval ($y + $height / 2),
\color::allocateFromText ($gd, $this->color), Color::allocateFromText ($gd, $this->color),
$this->fontfile, $serie); $this->fontfile, $serie);
// Draw the sample // Draw the sample
$series->serie ($serie)->style ()->sample ($gd, $x1 + 15, $y); $series->serie ($serie)->style ()->sample ($gd, $x1 + 15, $y);
@@ -1509,7 +1538,7 @@ class GraphAxisGeneral
if ($axisColor === null) if ($axisColor === null)
return $this->axisColor; return $this->axisColor;
if (! is_string ($axisColor) || if (! is_string ($axisColor) ||
! in_array ($axisColor, \color::colorList ())) ! in_array ($axisColor, Color::colorList ()))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid axisColor provided to graph axis"), 406); "Invalid axisColor provided to graph axis"), 406);
$this->axisColor = $axisColor; $this->axisColor = $axisColor;
@@ -1525,7 +1554,7 @@ class GraphAxisGeneral
if ($gridColor === null) if ($gridColor === null)
return $this->gridColor; return $this->gridColor;
if (! is_string ($gridColor) || if (! is_string ($gridColor) ||
! in_array ($gridColor, \color::colorList ())) ! in_array ($gridColor, Color::colorList ()))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid gridColor provided to graph grid"), 406); "Invalid gridColor provided to graph grid"), 406);
$this->gridColor = $gridColor; $this->gridColor = $gridColor;
@@ -1581,7 +1610,7 @@ class GraphAxisGeneral
// Return the 0 label and the values arround it // Return the 0 label and the values arround it
$zeroAlreadyDraw = false; $zeroAlreadyDraw = false;
for ($i = 0 ; for ($i = 0 ;
bccomp ($i, 1.2 * $max, abs ($base) + 1) < 1 ; \bccomp ($i, 1.2 * $max, abs ($base) + 1) < 1 ;
$i += $scale) $i += $scale)
{ {
if ($i === 0) if ($i === 0)
@@ -1590,7 +1619,7 @@ class GraphAxisGeneral
$labels[] = $i; $labels[] = $i;
} }
for ($i = 0 ; for ($i = 0 ;
bccomp ($i, 1.4 * $min, abs ($base) + 1) >= 0 ; \bccomp ($i, 1.4 * $min, abs ($base) + 1) >= 0 ;
$i -= $scale) $i -= $scale)
{ {
if ($zeroAlreadyDraw === true && $i === 0) if ($zeroAlreadyDraw === true && $i === 0)
@@ -1603,7 +1632,7 @@ class GraphAxisGeneral
{ {
// No 0 Axis : From $this->min to $this->max // No 0 Axis : From $this->min to $this->max
for ($i = $min ; for ($i = $min ;
bccomp ($i, $max, abs ($base) + 1) < 1 ; \bccomp ($i, $max, abs ($base) + 1) < 1 ;
$i += $scale) $i += $scale)
{ {
if ($deb) echo "Values no Zero : add val $i\n"; if ($deb) echo "Values no Zero : add val $i\n";
@@ -1619,14 +1648,14 @@ class GraphAxisGeneral
else else
$label = sprintf ("%".intval ($base)."d", $label); $label = sprintf ("%".intval ($base)."d", $label);
if ($this->labelMin === null || if ($this->labelMin === null ||
bccomp ($this->labelMin, $label, abs ($base) + 1) >= 0) \bccomp ($this->labelMin, $label, abs ($base) + 1) >= 0)
$this->labelMin = $label; $this->labelMin = $label;
if ($this->labelMax === null || if ($this->labelMax === null ||
bccomp ($this->labelMax, $label, abs ($base) + 1) <= 0) \bccomp ($this->labelMax, $label, abs ($base) + 1) <= 0)
$this->labelMax = $label; $this->labelMax = $label;
} }
if (bccomp ($this->labelMin, $this->min, abs ($base) + 1) > 0) if (\bccomp ($this->labelMin, $this->min, abs ($base) + 1) > 0)
{ {
// Add a label in the minimum // Add a label in the minimum
$this->labelMin = $this->labelMin - $scale; $this->labelMin = $this->labelMin - $scale;
@@ -1637,7 +1666,7 @@ class GraphAxisGeneral
else else
$labels[] = sprintf ("%".intval ($base)."d", $this->labelMin); $labels[] = sprintf ("%".intval ($base)."d", $this->labelMin);
} }
if (bccomp ($this->labelMax, $this->max, abs ($base) + 1) < 0) if (\bccomp ($this->labelMax, $this->max, abs ($base) + 1) < 0)
{ {
$this->labelMax = $this->labelMax + $scale; $this->labelMax = $this->labelMax + $scale;
if ($deb) echo "Force Add Max $this->labelMax\n"; if ($deb) echo "Force Add Max $this->labelMax\n";
@@ -1828,7 +1857,7 @@ class GraphAxisX extends GraphAxisHorizontal
*/ */
public function draw ($gd) public function draw ($gd)
{ {
$axisColor = \color::allocateFromText ($gd, $this->axisColor); $axisColor = Color::allocateFromText ($gd, $this->axisColor);
if ($this->numerical) if ($this->numerical)
{ {
if ($this->angle === null) if ($this->angle === null)
@@ -1847,7 +1876,7 @@ class GraphAxisX extends GraphAxisHorizontal
$y = $this->bottom - $this->padding; $y = $this->bottom - $this->padding;
// The font color is forced to black // The font color is forced to black
imagettftext ($gd, $this->fontsize, $this->angle, $x, $y, imagettftext ($gd, $this->fontsize, $this->angle, $x, $y,
\color::allocateFromText ($gd, "black"), Color::allocateFromText ($gd, "black"),
$this->fontfile, $value); $this->fontfile, $value);
// Draw the scale // Draw the scale
@@ -1883,7 +1912,7 @@ class GraphAxisX extends GraphAxisHorizontal
$y = $this->bottom - $this->padding; $y = $this->bottom - $this->padding;
// The font color is forced to black // The font color is forced to black
imagettftext ($gd, $this->fontsize, $this->angle, $x, $y, imagettftext ($gd, $this->fontsize, $this->angle, $x, $y,
\color::allocateFromText ($gd, "black"), Color::allocateFromText ($gd, "black"),
$this->fontfile, $value); $this->fontfile, $value);
// Draw the separators // Draw the separators
@@ -1912,7 +1941,7 @@ class GraphAxisX extends GraphAxisHorizontal
{ {
if ($this->gridColor === null || $this->gridColor === "transparent") if ($this->gridColor === null || $this->gridColor === "transparent")
return; return;
$gridColor = \color::allocateFromText ($gd, $this->gridColor); $gridColor = Color::allocateFromText ($gd, $this->gridColor);
if ($position === null) if ($position === null)
return; return;
$y = $this->bottom - $this->height; $y = $this->bottom - $this->height;
@@ -2065,7 +2094,7 @@ class GraphAxisVertical extends GraphAxisGeneral
*/ */
public function draw ($gd) public function draw ($gd)
{ {
$axisColor = \color::allocateFromText ($gd, $this->axisColor); $axisColor = Color::allocateFromText ($gd, $this->axisColor);
if ($this->numerical) if ($this->numerical)
{ {
// Look at the minimum distance between two labeled values // Look at the minimum distance between two labeled values
@@ -2112,7 +2141,7 @@ class GraphAxisY1 extends GraphAxisVertical
*/ */
protected function drawOne ($gd, $width, $val) protected function drawOne ($gd, $width, $val)
{ {
$axisColor = \color::allocateFromText ($gd, $this->axisColor); $axisColor = Color::allocateFromText ($gd, $this->axisColor);
if ($this->numerical) if ($this->numerical)
{ {
// Do not allow the label to be longer than $this->max // Do not allow the label to be longer than $this->max
@@ -2131,7 +2160,7 @@ class GraphAxisY1 extends GraphAxisVertical
imagettftext ($gd, $this->fontsize, 0, imagettftext ($gd, $this->fontsize, 0,
$width - $labelwidth, $width - $labelwidth,
$y + $labelheight / 2, $y + $labelheight / 2,
\color::allocateFromText ($gd, "black"), Color::allocateFromText ($gd, "black"),
$this->fontfile, $itmp); $this->fontfile, $itmp);
// Display the separators // Display the separators
@@ -2150,7 +2179,7 @@ die ("graphAxisY1:: drawOne NOT numerical line ".__LINE__."\n");
*/ */
protected function drawAxis ($gd, $width) protected function drawAxis ($gd, $width)
{ {
$axisColor = \color::allocateFromText ($gd, $this->axisColor); $axisColor = Color::allocateFromText ($gd, $this->axisColor);
imageline ($gd, $width, $this->bottom, $width, $this->top, $axisColor); imageline ($gd, $width, $this->bottom, $width, $this->top, $axisColor);
} }
@@ -2163,7 +2192,7 @@ die ("graphAxisY1:: drawOne NOT numerical line ".__LINE__."\n");
{ {
if ($this->gridColor === null || $this->gridColor === "transparent") if ($this->gridColor === null || $this->gridColor === "transparent")
return; return;
$gridColor = \color::allocateFromText ($gd, $this->gridColor); $gridColor = Color::allocateFromText ($gd, $this->gridColor);
if ($this->numerical) if ($this->numerical)
{ {
$y = $this->position ($val); $y = $this->position ($val);
@@ -2190,7 +2219,7 @@ class GraphAxisY2 extends GraphAxisVertical
*/ */
protected function drawOne ($gd, $width, $val) protected function drawOne ($gd, $width, $val)
{ {
$axisColor = \color::allocateFromText ($gd, $this->axisColor); $axisColor = Color::allocateFromText ($gd, $this->axisColor);
if ($this->numerical) if ($this->numerical)
{ {
// Do not allow the label to be longer than $this->max // Do not allow the label to be longer than $this->max
@@ -2209,7 +2238,7 @@ class GraphAxisY2 extends GraphAxisVertical
imagettftext ($gd, $this->fontsize, 0, imagettftext ($gd, $this->fontsize, 0,
$this->left + $this->padding + 3, $this->left + $this->padding + 3,
$y + $labelheight / 2, $y + $labelheight / 2,
\color::allocateFromText ($gd, "black"), Color::allocateFromText ($gd, "black"),
$this->fontfile, $itmp); $this->fontfile, $itmp);
// Display the separators // Display the separators
@@ -2228,7 +2257,7 @@ die ("graphAxisY2:: drawOne NOT numerical line ".__LINE__."\n");
*/ */
protected function drawAxis ($gd, $width) protected function drawAxis ($gd, $width)
{ {
$axisColor = \color::allocateFromText ($gd, $this->axisColor); $axisColor = Color::allocateFromText ($gd, $this->axisColor);
imageline ($gd, $this->left, $this->bottom, imageline ($gd, $this->left, $this->bottom,
$this->left, $this->top, $axisColor); $this->left, $this->top, $axisColor);
} }
@@ -2296,7 +2325,7 @@ class GraphStyleLinePoints
return $this->lineColor; return $this->lineColor;
if (! is_string ($lineColor) || if (! is_string ($lineColor) ||
($lineColor !== "transparent" && ($lineColor !== "transparent" &&
! in_array ($lineColor, \color::colorList ()))) ! in_array ($lineColor, Color::colorList ())))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid lineColor provided to line style"), 406); "Invalid lineColor provided to line style"), 406);
$this->lineColor = $lineColor; $this->lineColor = $lineColor;
@@ -2328,7 +2357,7 @@ class GraphStyleLinePoints
return $this->pointBgcolor; return $this->pointBgcolor;
if (! is_string ($pointBgcolor) || if (! is_string ($pointBgcolor) ||
($pointBgcolor !== "transparent" && ($pointBgcolor !== "transparent" &&
! in_array ($pointBgcolor, \color::colorList ()))) ! in_array ($pointBgcolor, Color::colorList ())))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid pointBgcolor provided to line style"), 406); "Invalid pointBgcolor provided to line style"), 406);
$this->pointBgcolor = $pointBgcolor; $this->pointBgcolor = $pointBgcolor;
@@ -2345,7 +2374,7 @@ class GraphStyleLinePoints
return $this->pointColor; return $this->pointColor;
if (! is_string ($pointColor) || if (! is_string ($pointColor) ||
($pointColor !== "transparent" && ($pointColor !== "transparent" &&
! in_array ($pointColor, \color::colorList ()))) ! in_array ($pointColor, Color::colorList ())))
throw new \Exception (dgettext ("domframework", throw new \Exception (dgettext ("domframework",
"Invalid pointColor provided to line style"), 406); "Invalid pointColor provided to line style"), 406);
$this->pointColor = $pointColor; $this->pointColor = $pointColor;
@@ -2419,7 +2448,7 @@ class GraphStyleLinePoints
public function draw ($gd, $free, $data, $axisX, $axisY) public function draw ($gd, $free, $data, $axisX, $axisY)
{ {
if ($this->lineColor !== "transparent") if ($this->lineColor !== "transparent")
$lineColor = \color::allocateFromText ($gd, $this->lineColor); $lineColor = Color::allocateFromText ($gd, $this->lineColor);
$lastX = null; $lastX = null;
$lastY = null; $lastY = null;
foreach ($data as $key=>$value) foreach ($data as $key=>$value)
@@ -2465,9 +2494,9 @@ class GraphStyleLinePoints
private function drawPoint ($gd, $posX, $posY) private function drawPoint ($gd, $posX, $posY)
{ {
if ($this->pointColor !== "transparent") if ($this->pointColor !== "transparent")
$pointColor = \color::allocateFromText ($gd, $this->pointColor); $pointColor = Color::allocateFromText ($gd, $this->pointColor);
if ($this->pointBgcolor !== "transparent") if ($this->pointBgcolor !== "transparent")
$pointBgcolor = \color::allocateFromText ($gd, $this->pointBgcolor); $pointBgcolor = Color::allocateFromText ($gd, $this->pointBgcolor);
$half = intval ($this->pointWidth / 2); $half = intval ($this->pointWidth / 2);
switch ($this->pointShape) switch ($this->pointShape)
{ {
@@ -2530,7 +2559,7 @@ class GraphStyleLinePoints
{ {
if ($this->lineColor !== "transparent") if ($this->lineColor !== "transparent")
{ {
$lineColor = \color::allocateFromText ($gd, $this->lineColor); $lineColor = Color::allocateFromText ($gd, $this->lineColor);
imageline ($gd, $x-10, $y, $x+10, $y, $lineColor); imageline ($gd, $x-10, $y, $x+10, $y, $lineColor);
} }
if ($this->pointWidth === null) if ($this->pointWidth === null)

View File

@@ -31,9 +31,9 @@ class Robotstxt
*/ */
private $sitemaps = array (); private $sitemaps = array ();
/** The crawldelay defined in the file (3s if not defined) /** The crawldelay defined in the file
*/ */
private $crawldelay = 3; private $crawldelay = null;
/** The host can be specified as default website /** The host can be specified as default website
*/ */
@@ -125,7 +125,7 @@ class Robotstxt
elseif (stripos ($line, "crawl-delay:") === 0) elseif (stripos ($line, "crawl-delay:") === 0)
{ {
$val = $this->getValueFromLine ($line); $val = $this->getValueFromLine ($line);
if ($val > 1 && $val < 60 && $this->crawldelay === 3) if ($val > 1 && $val < 60 && $this->crawldelay === null)
$this->crawldelay = intval ($val); $this->crawldelay = intval ($val);
else else
$this->errors[$i] = dgettext ("domframework", $this->errors[$i] = dgettext ("domframework",