Skip to content
Extraits de code Groupes Projets
Valider ccf04f6f rédigé par JulienMoumne's avatar JulienMoumne
Parcourir les fichiers

refs #1721 refs #3013

 * show label icons in evolution graph
 * smaller legend font size
 * draw colored shadows in legend
 * vertical legend for evolution graphs
 * enhanced label skipping for daily evolution graph

git-svn-id: http://dev.piwik.org/svn/trunk@6947 59fd770c-687e-43c8-a1e3-f5a4ff64c105
parent e40cfe4e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -273,6 +273,8 @@ class Piwik_ImageGraph_API ...@@ -273,6 +273,8 @@ class Piwik_ImageGraph_API
break; break;
} }
$ordinateLogos = array();
// row evolutions // row evolutions
if($isMultiplePeriod && $reportHasDimension) if($isMultiplePeriod && $reportHasDimension)
{ {
...@@ -336,6 +338,17 @@ class Piwik_ImageGraph_API ...@@ -336,6 +338,17 @@ class Piwik_ImageGraph_API
$ordinateColumn = $plottedMetric . '_' . $i++; $ordinateColumn = $plottedMetric . '_' . $i++;
$ordinateColumns[] = $metric; $ordinateColumns[] = $metric;
$ordinateLabels[$ordinateColumn] = $info['name']; $ordinateLabels[$ordinateColumn] = $info['name'];
if(isset($info['logo']))
{
$ordinateLogo = $info['logo'];
// @review pChart does not support gifs in graph legends, would it be possible to convert all plugin pictures (cookie.gif, flash.gif, ..) to png files?
if(!strstr($ordinateLogo, '.gif'))
{
$ordinateLogos[$ordinateColumn] = $ordinateLogo;
}
}
} }
} }
else else
...@@ -362,8 +375,8 @@ class Piwik_ImageGraph_API ...@@ -362,8 +375,8 @@ class Piwik_ImageGraph_API
} }
// prepare abscissa and ordinate series // prepare abscissa and ordinate series
$abscissaSeries = array(); $abscissaSeries = array();
$abscissaLogos = array();
$ordinateSeries = array(); $ordinateSeries = array();
$ordinateLogos = array();
$reportData = $processedReport['reportData']; $reportData = $processedReport['reportData'];
$hasData = false; $hasData = false;
$hasNonZeroValue = false; $hasNonZeroValue = false;
...@@ -397,7 +410,7 @@ class Piwik_ImageGraph_API ...@@ -397,7 +410,7 @@ class Piwik_ImageGraph_API
$rowMetadata = $reportMetadata[$i]->getColumns(); $rowMetadata = $reportMetadata[$i]->getColumns();
if(isset($rowMetadata['logo'])) if(isset($rowMetadata['logo']))
{ {
$ordinateLogos[$i] = $rowMetadata['logo']; $abscissaLogos[$i] = $rowMetadata['logo'];
} }
} }
$i++; $i++;
...@@ -466,9 +479,14 @@ class Piwik_ImageGraph_API ...@@ -466,9 +479,14 @@ class Piwik_ImageGraph_API
$graph->setShowLegend($showLegend); $graph->setShowLegend($showLegend);
$graph->setAliasedGraph($aliasedGraph); $graph->setAliasedGraph($aliasedGraph);
$graph->setAbscissaSeries($abscissaSeries); $graph->setAbscissaSeries($abscissaSeries);
$graph->setAbscissaLogos($abscissaLogos);
$graph->setOrdinateSeries($ordinateSeries); $graph->setOrdinateSeries($ordinateSeries);
$graph->setOrdinateLogos($ordinateLogos); $graph->setOrdinateLogos($ordinateLogos);
$graph->setColors(!empty($colors) ? explode(',', $colors) : array()); $graph->setColors(!empty($colors) ? explode(',', $colors) : array());
if($period == 'day')
{
$graph->setForceSkippedLabels(6);
}
// render graph // render graph
$graph->renderGraph(); $graph->renderGraph();
......
...@@ -28,6 +28,8 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -28,6 +28,8 @@ abstract class Piwik_ImageGraph_StaticGraph
const GRAPH_TYPE_3D_PIE = "3dPie"; const GRAPH_TYPE_3D_PIE = "3dPie";
const GRAPH_TYPE_BASIC_PIE = "pie"; const GRAPH_TYPE_BASIC_PIE = "pie";
const CAUTIONARY_FONT_HEIGHT_OFFSET = 4;
static private $availableStaticGraphTypes = array( static private $availableStaticGraphTypes = array(
self::GRAPH_TYPE_BASIC_LINE => 'Piwik_ImageGraph_StaticGraph_Evolution', self::GRAPH_TYPE_BASIC_LINE => 'Piwik_ImageGraph_StaticGraph_Evolution',
self::GRAPH_TYPE_VERTICAL_BAR => 'Piwik_ImageGraph_StaticGraph_VerticalBar', self::GRAPH_TYPE_VERTICAL_BAR => 'Piwik_ImageGraph_StaticGraph_VerticalBar',
...@@ -37,8 +39,6 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -37,8 +39,6 @@ abstract class Piwik_ImageGraph_StaticGraph
); );
const ABSCISSA_SERIE_NAME = 'ABSCISSA'; const ABSCISSA_SERIE_NAME = 'ABSCISSA';
const WIDTH_KEY = 'WIDTH';
const HEIGHT_KEY = 'HEIGHT';
private $aliasedGraph; private $aliasedGraph;
...@@ -47,6 +47,7 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -47,6 +47,7 @@ abstract class Piwik_ImageGraph_StaticGraph
protected $ordinateLabels; protected $ordinateLabels;
protected $showLegend; protected $showLegend;
protected $abscissaSeries; protected $abscissaSeries;
protected $abscissaLogos;
protected $ordinateSeries; protected $ordinateSeries;
protected $ordinateLogos; protected $ordinateLogos;
protected $colors; protected $colors;
...@@ -54,6 +55,7 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -54,6 +55,7 @@ abstract class Piwik_ImageGraph_StaticGraph
protected $fontSize; protected $fontSize;
protected $width; protected $width;
protected $height; protected $height;
protected $forceSkippedLabels = false;
abstract protected function getDefaultColors(); abstract protected function getDefaultColors();
...@@ -150,6 +152,11 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -150,6 +152,11 @@ abstract class Piwik_ImageGraph_StaticGraph
$this->ordinateLogos = $ordinateLogos; $this->ordinateLogos = $ordinateLogos;
} }
public function setAbscissaLogos($abscissaLogos)
{
$this->abscissaLogos = $abscissaLogos;
}
public function setAbscissaSeries($abscissaSeries) public function setAbscissaSeries($abscissaSeries)
{ {
$this->abscissaSeries = $abscissaSeries; $this->abscissaSeries = $abscissaSeries;
...@@ -160,6 +167,11 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -160,6 +167,11 @@ abstract class Piwik_ImageGraph_StaticGraph
$this->showLegend = $showLegend; $this->showLegend = $showLegend;
} }
public function setForceSkippedLabels($forceSkippedLabels)
{
$this->forceSkippedLabels = $forceSkippedLabels;
}
public function setOrdinateLabels($ordinateLabels) public function setOrdinateLabels($ordinateLabels)
{ {
$this->ordinateLabels = $ordinateLabels; $this->ordinateLabels = $ordinateLabels;
...@@ -212,6 +224,11 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -212,6 +224,11 @@ abstract class Piwik_ImageGraph_StaticGraph
{ {
$this->pData->addPoints($data, $column); $this->pData->addPoints($data, $column);
$this->pData->setSerieDescription($column,$this->ordinateLabels[$column]); $this->pData->setSerieDescription($column,$this->ordinateLabels[$column]);
if(isset($this->ordinateLogos[$column]))
{
$ordinateLogo = $this->ordinateLogos[$column];
$this->pData->setSeriePicture($column, $ordinateLogo);
}
} }
$this->pData->addPoints($this->abscissaSeries, self::ABSCISSA_SERIE_NAME); $this->pData->addPoints($this->abscissaSeries, self::ABSCISSA_SERIE_NAME);
...@@ -231,17 +248,33 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -231,17 +248,33 @@ abstract class Piwik_ImageGraph_StaticGraph
); );
} }
protected function getTextWidthHeight($text) protected function getTextWidth($text, $fontSize = false)
{ {
$position = imageftbbox($this->fontSize, 0, $this->font, $text); if(!$fontSize)
{
$fontSize = $this->fontSize;
}
if(!$this->pImage)
{
$this->initpImage();
}
return array( // could not find a way to get pixel perfect width & height info using imageftbbox
self::WIDTH_KEY => ($position[0]) + abs($position[2]), // drawing the text with no opacity and looking at its properties does return accurate width (not height)
self::HEIGHT_KEY => ($position[1]) + abs($position[5]) $textInfo = $this->pImage->drawText(
0, 0, $text,
array(
'Alpha'=>0,
'FontSize'=>$fontSize,
'FontName' => $this->font
)
); );
return $textInfo[1]["X"] + 1;
} }
protected function maxWidthHeight($values) protected function getMaximumTextWidth($values)
{ {
if(array_values($values) === $values) if(array_values($values) === $values)
{ {
...@@ -249,31 +282,33 @@ abstract class Piwik_ImageGraph_StaticGraph ...@@ -249,31 +282,33 @@ abstract class Piwik_ImageGraph_StaticGraph
} }
$maxWidth = 0; $maxWidth = 0;
$maxHeight = 0;
foreach($values as $column => $data) foreach($values as $column => $data)
{ {
foreach($data as $value) foreach($data as $value)
{ {
$valueWidthHeight = $this->getTextWidthHeight($value); $valueWidth= $this->getTextWidth($value);
$valueWidth= $valueWidthHeight[self::WIDTH_KEY];
$valueHeight= $valueWidthHeight[self::HEIGHT_KEY];
if($valueWidth > $maxWidth) if($valueWidth > $maxWidth)
{ {
$maxWidth = $valueWidth; $maxWidth = $valueWidth;
} }
if($valueHeight > $maxHeight)
{
$maxHeight = $valueHeight;
}
} }
} }
return array( return $maxWidth;
self::WIDTH_KEY => $maxWidth, }
self::HEIGHT_KEY => $maxHeight
); protected function getMaximumTextHeight($fontSize = false)
{
if(!$fontSize)
{
$fontSize = $this->fontSize;
}
// could not find a way to accurately get a text height
// pChart uses the font size, however, the font size is not always the maximum character height
// after trialing, a safe cautionary font height offset has been set
return $fontSize + self::CAUTIONARY_FONT_HEIGHT_OFFSET;
} }
private static function hex2rgb($hexColor) private static function hex2rgb($hexColor)
......
...@@ -24,7 +24,8 @@ class Piwik_ImageGraph_StaticGraph_Evolution extends Piwik_ImageGraph_StaticGrap ...@@ -24,7 +24,8 @@ class Piwik_ImageGraph_StaticGraph_Evolution extends Piwik_ImageGraph_StaticGrap
$displayVerticalGridLines = true, $displayVerticalGridLines = true,
$drawCircles = true, $drawCircles = true,
$horizontalGraph = false, $horizontalGraph = false,
$showTicks = true $showTicks = true,
$verticalLegend = true
); );
$this->pImage->drawLineChart(); $this->pImage->drawLineChart();
......
...@@ -36,12 +36,11 @@ class Piwik_ImageGraph_StaticGraph_Exception extends Piwik_ImageGraph_StaticGrap ...@@ -36,12 +36,11 @@ class Piwik_ImageGraph_StaticGraph_Exception extends Piwik_ImageGraph_StaticGrap
$this->pData = new pData(); $this->pData = new pData();
$message = $this->exception->getMessage(); $message = $this->exception->getMessage();
$messageWidthHeight = $this->getTextWidthHeight($message, false); $messageHeight = $this->getMaximumTextHeight();
$messageHeight = $messageWidthHeight[self::HEIGHT_KEY];
if($this->width == null) if($this->width == null)
{ {
$this->width = $messageWidthHeight[self::WIDTH_KEY] + self::MESSAGE_RIGHT_MARGIN; $this->width = $this->getMaximumTextWidth($message) + self::MESSAGE_RIGHT_MARGIN;
} }
if($this->height == null) if($this->height == null)
......
...@@ -26,13 +26,22 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -26,13 +26,22 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
const LEFT_GRID_MARGIN = 4; const LEFT_GRID_MARGIN = 4;
const BOTTOM_GRID_MARGIN = 10; const BOTTOM_GRID_MARGIN = 10;
const TOP_GRID_MARGIN_HORIZONTAL_GRAPH = 1; const TOP_GRID_MARGIN_HORIZONTAL_GRAPH = 1;
const RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH = 5; const RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH = 4;
const LEGEND_LEFT_MARGIN = 4;
const LEGEND_BOTTOM_MARGIN = 10;
const OUTER_TICK_WIDTH = 5; const OUTER_TICK_WIDTH = 5;
const INNER_TICK_WIDTH = 0; const INNER_TICK_WIDTH = 0;
const LABEL_SPACE_VERTICAL_GRAPH = 10; const LABEL_SPACE_VERTICAL_GRAPH = 10;
const HORIZONTAL_LEGEND_TOP_MARGIN = 2;
const LEGEND_LEFT_MARGIN = 5;
const HORIZONTAL_LEGEND_BOTTOM_MARGIN = 10;
const LEGEND_FONT_SIZE_OFFSET = -1;
const LEGEND_BULLET_SIZE = 5;
const LEGEND_BULLET_RIGHT_PADDING = 5;
const LEGEND_ITEM_HORIZONTAL_INTERSTICE = 6;
const LEGEND_ITEM_VERTICAL_INTERSTICE = 12;
const LEGEND_SHADOW_OPACITY = 20;
const PCHART_HARD_CODED_VERTICAL_LEGEND_INTERSTICE = 5;
protected function getDefaultColors() protected function getDefaultColors()
{ {
return array( return array(
...@@ -51,7 +60,8 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -51,7 +60,8 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
$displayVerticalGridLines, $displayVerticalGridLines,
$drawCircles, $drawCircles,
$horizontalGraph, $horizontalGraph,
$showTicks $showTicks,
$verticalLegend
) )
{ {
$this->initpData(); $this->initpData();
...@@ -68,9 +78,9 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -68,9 +78,9 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
// graph area coordinates // graph area coordinates
$topLeftXValue = $this->getGridLeftMargin($horizontalGraph, $withLabel = true); $topLeftXValue = $this->getGridLeftMargin($horizontalGraph, $withLabel = true);
$topLeftYValue = $this->getGridTopMargin($horizontalGraph); $topLeftYValue = $this->getGridTopMargin($horizontalGraph, $verticalLegend);
$bottomRightXValue = $this->width - $this->getGridRightMargin($horizontalGraph); $bottomRightXValue = $this->width - $this->getGridRightMargin($horizontalGraph);
$bottomRightYValue = $this->getGraphBottom(); $bottomRightYValue = $this->getGraphBottom($horizontalGraph);
$this->pImage->setGraphArea( $this->pImage->setGraphArea(
$topLeftXValue, $topLeftXValue,
...@@ -83,8 +93,7 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -83,8 +93,7 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
$skippedLabels = 0; $skippedLabels = 0;
if(!$horizontalGraph) if(!$horizontalGraph)
{ {
$abscissaMaxWidthHeight = $this->maxWidthHeight($this->abscissaSeries); $abscissaMaxWidth = $this->getMaximumTextWidth($this->abscissaSeries);
$abscissaMaxWidth = $abscissaMaxWidthHeight[self::WIDTH_KEY];
$graphWidth = $bottomRightXValue - $topLeftXValue; $graphWidth = $bottomRightXValue - $topLeftXValue;
$maxNumOfLabels = floor($graphWidth / ($abscissaMaxWidth + self::LABEL_SPACE_VERTICAL_GRAPH)); $maxNumOfLabels = floor($graphWidth / ($abscissaMaxWidth + self::LABEL_SPACE_VERTICAL_GRAPH));
...@@ -111,8 +120,13 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -111,8 +120,13 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
} }
} }
if($this->forceSkippedLabels && $skippedLabels && $skippedLabels < $this->forceSkippedLabels)
{
$skippedLabels = $this->forceSkippedLabels;
}
$ordinateAxisLength = $ordinateAxisLength =
$horizontalGraph ? $bottomRightXValue - $topLeftXValue : $this->getGraphHeight($horizontalGraph); $horizontalGraph ? $bottomRightXValue - $topLeftXValue : $this->getGraphHeight($horizontalGraph, $verticalLegend);
$maxOrdinateValue = 0; $maxOrdinateValue = 0;
foreach($this->ordinateSeries as $column => $data) foreach($this->ordinateSeries as $column => $data)
...@@ -156,43 +170,129 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -156,43 +170,129 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
if($this->showLegend) if($this->showLegend)
{ {
$legendFontSize = $this->getLegendFontSize();
$maxLegendTextHeight = $this->getMaximumTextHeight($legendFontSize);
$legendTopLeftXValue = $topLeftXValue + self::LEGEND_LEFT_MARGIN;
// this value is used by pChart to position the top edge of item bullets
$legendTopLeftYValue = ($verticalLegend ? 0 : self::HORIZONTAL_LEGEND_TOP_MARGIN) + ($maxLegendTextHeight / 4);
// maximum logo width & height
$maxLogoWidth = 0;
$maxLogoHeight = 0;
foreach($this->ordinateLogos as $metricCode => $logo)
{
$pathInfo = getimagesize($this->ordinateLogos[$metricCode]);
$logoWidth = $pathInfo[0];
$logoHeight = $pathInfo[1];
if($logoWidth > $maxLogoWidth)
{
$maxLogoWidth = $logoWidth;
}
if($logoHeight > $maxLogoHeight)
{
$maxLogoHeight = $logoHeight;
}
}
// add colored background to each legend item
$currentPosition = $verticalLegend ? $legendTopLeftYValue : $legendTopLeftXValue;
$colorIndex = 1;
foreach($this->ordinateLabels as $metricCode => $label)
{
$color = $this->colors[self::GRAPHIC_COLOR_KEY . $colorIndex++];
$bulletSize = self::LEGEND_BULLET_SIZE;
if(isset($this->ordinateLogos[$metricCode]))
{
$bulletSize = $maxLogoWidth;
}
$rectangleTopLeftXValue = $verticalLegend ? $legendTopLeftXValue : $currentPosition;
$rectangleTopLeftYValue = $verticalLegend ? $currentPosition : self::HORIZONTAL_LEGEND_TOP_MARGIN;
$rectangleWidth = $bulletSize + self::LEGEND_BULLET_RIGHT_PADDING + $this->getTextWidth($label, $legendFontSize);
$legendItemWidth = $rectangleWidth + self::LEGEND_ITEM_HORIZONTAL_INTERSTICE;
$rectangleBottomRightXValue = $rectangleTopLeftXValue + $rectangleWidth;
$rectangleBottomRightYValue = $rectangleTopLeftYValue + $maxLegendTextHeight;
$this->pImage->drawFilledRectangle(
$rectangleTopLeftXValue,
$rectangleTopLeftYValue,
$rectangleBottomRightXValue,
$rectangleBottomRightYValue,
array(
'Alpha' => self::LEGEND_SHADOW_OPACITY,
'R' => $color['R'],
'G' => $color['G'],
'B' => $color['B'],
)
);
$currentPosition +=
$verticalLegend
? ($maxLogoHeight > self::LEGEND_ITEM_VERTICAL_INTERSTICE ? $maxLogoHeight : self::LEGEND_ITEM_VERTICAL_INTERSTICE) + self::PCHART_HARD_CODED_VERTICAL_LEGEND_INTERSTICE
: $legendItemWidth;
}
// draw legend
$legendColor = $this->colors[self::VALUE_COLOR_KEY]; $legendColor = $this->colors[self::VALUE_COLOR_KEY];
$this->pImage->drawLegend( $this->pImage->drawLegend(
$topLeftXValue + self::LEGEND_LEFT_MARGIN, $legendTopLeftXValue,
$this->getLegendHeight() / 2, $legendTopLeftYValue,
array( array(
'Style' => LEGEND_NOBORDER, 'Style' => LEGEND_NOBORDER,
'Mode' => LEGEND_HORIZONTAL, 'FontSize' => $legendFontSize,
'FontR' => $legendColor['R'], 'FontName' => $this->font,
'FontG' => $legendColor['G'], 'BoxWidth' => self::LEGEND_BULLET_SIZE,
'FontB' => $legendColor['B'], 'XSpacing' => self::LEGEND_ITEM_HORIZONTAL_INTERSTICE, // not effective when vertical
'Mode' => $verticalLegend ? LEGEND_VERTICAL : LEGEND_HORIZONTAL,
'BoxHeight' => $verticalLegend ? self::LEGEND_ITEM_VERTICAL_INTERSTICE : null,
'Family' => $drawCircles ? LEGEND_FAMILY_LINE : LEGEND_FAMILY_BOX,
'FontR' => $legendColor['R'],
'FontG' => $legendColor['G'],
'FontB' => $legendColor['B'],
) )
); );
} }
if($drawCircles) if($drawCircles)
{ {
// drawPlotChart uses series pictures when they are specified
// remove series pictures (ie. logos) so that drawPlotChart draws simple dots
foreach($this->ordinateSeries as $column => $data)
{
if(isset($this->ordinateLogos[$column]))
{
$this->pData->setSeriePicture($column,null);
}
}
$this->pImage->drawPlotChart(); $this->pImage->drawPlotChart();
} }
} }
protected function getLegendFontSize()
{
return $this->fontSize + self::LEGEND_FONT_SIZE_OFFSET;
}
protected function getGridLeftMargin($horizontalGraph, $withLabel) protected function getGridLeftMargin($horizontalGraph, $withLabel)
{ {
$gridLeftMargin = self::LEFT_GRID_MARGIN + self::OUTER_TICK_WIDTH; $gridLeftMargin = self::LEFT_GRID_MARGIN + self::OUTER_TICK_WIDTH;
if($withLabel) if($withLabel)
{ {
$maxWidthHeight = $this->maxWidthHeight($horizontalGraph ? $this->abscissaSeries : $this->ordinateSeries); $gridLeftMargin += $this->getMaximumTextWidth($horizontalGraph ? $this->abscissaSeries : $this->ordinateSeries);
$gridLeftMargin += $maxWidthHeight[self::WIDTH_KEY];
} }
return $gridLeftMargin; return $gridLeftMargin;
} }
protected function getGridTopMargin($horizontalGraph) protected function getGridTopMargin($horizontalGraph, $verticalLegend)
{ {
$ordinateMaxWidthHeight = $this->maxWidthHeight($this->ordinateSeries); $ordinateMaxHeight = $this->getMaximumTextHeight();
$ordinateMaxHeight = $ordinateMaxWidthHeight[self::HEIGHT_KEY];
if($horizontalGraph) if($horizontalGraph)
{ {
...@@ -203,47 +303,40 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -203,47 +303,40 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
$topMargin = $ordinateMaxHeight / 2; $topMargin = $ordinateMaxHeight / 2;
} }
if($this->showLegend) if($this->showLegend && !$verticalLegend)
{ {
$topMargin += $this->getLegendHeight() + self::LEGEND_BOTTOM_MARGIN; $topMargin += $this->getHorizontalLegendHeight();
} }
return $topMargin; return $topMargin;
} }
private function getLegendHeight() private function getHorizontalLegendHeight()
{ {
$maxMetricLegendHeight = 0; return $this->getMaximumTextHeight($this->getLegendFontSize()) + self::HORIZONTAL_LEGEND_BOTTOM_MARGIN + self::HORIZONTAL_LEGEND_TOP_MARGIN;
foreach($this->ordinateLabels as $column => $label)
{
$metricTitleWidthHeight = $this->getTextWidthHeight($label);
$metricTitleHeight = $metricTitleWidthHeight[self::HEIGHT_KEY];
if($metricTitleHeight > $maxMetricLegendHeight)
{
$maxMetricLegendHeight = $metricTitleHeight;
}
}
return $maxMetricLegendHeight;
} }
protected function getGraphHeight($horizontalGraph) protected function getGraphHeight($horizontalGraph, $verticalLegend)
{ {
return $this->getGraphBottom() - $this->getGridTopMargin($horizontalGraph); return $this->getGraphBottom($horizontalGraph) - $this->getGridTopMargin($horizontalGraph, $verticalLegend);
} }
private function getGridBottomMargin() private function getGridBottomMargin($horizontalGraph)
{ {
$abscissaMaxWidthHeight = $this->maxWidthHeight($this->abscissaSeries); $gridBottomMargin = self::BOTTOM_GRID_MARGIN;
return $abscissaMaxWidthHeight[self::HEIGHT_KEY] + self::BOTTOM_GRID_MARGIN; if(!$horizontalGraph)
{
$gridBottomMargin += $this->getMaximumTextHeight();
}
return $gridBottomMargin;
} }
protected function getGridRightMargin($horizontalGraph) protected function getGridRightMargin($horizontalGraph)
{ {
if($horizontalGraph) if($horizontalGraph)
{ {
$ordinateMaxWidthHeight = $this->maxWidthHeight($this->ordinateSeries); // in horizontal graphs, metric values are displayed on the far right of the bar
return self::RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH + $ordinateMaxWidthHeight[self::WIDTH_KEY]; return self::RIGHT_GRID_MARGIN_HORIZONTAL_GRAPH + $this->getMaximumTextWidth($this->ordinateSeries);
} }
else else
{ {
...@@ -251,8 +344,8 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S ...@@ -251,8 +344,8 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
} }
} }
protected function getGraphBottom() protected function getGraphBottom($horizontalGraph)
{ {
return $this->height - $this->getGridBottomMargin(); return $this->height - $this->getGridBottomMargin($horizontalGraph);
} }
} }
\ No newline at end of file
...@@ -26,20 +26,22 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -26,20 +26,22 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
public function renderGraph() public function renderGraph()
{ {
$verticalLegend = false;
// determine the maximum logo width & height // determine the maximum logo width & height
$maxLogoWidth = 0; $maxLogoWidth = 0;
$maxLogoHeight = 0; $maxLogoHeight = 0;
$logoPathToSizes = array(); $logoPathToHeight = array();
foreach($this->ordinateLogos as $logoPath) foreach($this->abscissaLogos as $logoPath)
{ {
$absoluteLogoPath = self::getAbsoluteLogoPath($logoPath); $absoluteLogoPath = self::getAbsoluteLogoPath($logoPath);
if(file_exists($absoluteLogoPath)) if(file_exists($absoluteLogoPath))
{ {
$logoWidthHeight = self::getLogoWidthHeight($absoluteLogoPath); $pathInfo = getimagesize($absoluteLogoPath);
$logoWidth = $logoWidthHeight[self::WIDTH_KEY]; $logoWidth = $pathInfo[0];
$logoHeight = $logoWidthHeight[self::HEIGHT_KEY]; $logoHeight = $pathInfo[1];
$logoPathToSizes[$absoluteLogoPath] = $logoWidthHeight; $logoPathToHeight[$absoluteLogoPath] = $logoHeight;
if($logoWidth > $maxLogoWidth) if($logoWidth > $maxLogoWidth)
{ {
$maxLogoWidth = $logoWidth; $maxLogoWidth = $logoWidth;
...@@ -53,14 +55,13 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -53,14 +55,13 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
} }
// truncate report // truncate report
$graphHeight = $this->getGraphBottom() - $this->getGridTopMargin($horizontalGraph = true); $graphHeight = $this->getGraphBottom($horizontalGraph = true) - $this->getGridTopMargin($horizontalGraph = true, $verticalLegend);
$abscissaMaxWidthHeight = $this->maxWidthHeight($this->abscissaSeries); $maximumTextHeight = $this->getMaximumTextHeight();
$abscissaMaxHeight = $abscissaMaxWidthHeight[self::HEIGHT_KEY]; $abscissaMaxHeight = $maximumTextHeight;
$ordinateMaxWidthHeight = $this->maxWidthHeight($this->ordinateSeries);
$numberOfSeries = count($this->ordinateSeries); $numberOfSeries = count($this->ordinateSeries);
$ordinateMaxHeight = $ordinateMaxWidthHeight[self::HEIGHT_KEY] * $numberOfSeries; $ordinateMaxHeight = $maximumTextHeight * $numberOfSeries;
$textMaxHeight = $abscissaMaxHeight > $ordinateMaxHeight ? $abscissaMaxHeight : $ordinateMaxHeight; $textMaxHeight = $abscissaMaxHeight > $ordinateMaxHeight ? $abscissaMaxHeight : $ordinateMaxHeight;
...@@ -72,7 +73,7 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -72,7 +73,7 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
{ {
$sumOfOthers = array(); $sumOfOthers = array();
$truncatedOrdinateSeries = array(); $truncatedOrdinateSeries = array();
$truncatedOrdinateLogos = array(); $truncatedAbscissaLogos = array();
$truncatedAbscissaSeries = array(); $truncatedAbscissaSeries = array();
foreach($this->ordinateSeries as $column => $data) foreach($this->ordinateSeries as $column => $data)
{ {
...@@ -88,7 +89,7 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -88,7 +89,7 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
$truncatedOrdinateSeries[$column][] = $data[$i]; $truncatedOrdinateSeries[$column][] = $data[$i];
} }
$truncatedOrdinateLogos[] = isset($this->ordinateLogos[$i]) ? $this->ordinateLogos[$i] : null; $truncatedAbscissaLogos[] = isset($this->abscissaLogos[$i]) ? $this->abscissaLogos[$i] : null;
$truncatedAbscissaSeries[] = $this->abscissaSeries[$i]; $truncatedAbscissaSeries[] = $this->abscissaSeries[$i];
} }
...@@ -108,7 +109,7 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -108,7 +109,7 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
$truncatedAbscissaSeries[] = Piwik_Translate('General_Others'); $truncatedAbscissaSeries[] = Piwik_Translate('General_Others');
$this->abscissaSeries = $truncatedAbscissaSeries; $this->abscissaSeries = $truncatedAbscissaSeries;
$this->ordinateSeries = $truncatedOrdinateSeries; $this->ordinateSeries = $truncatedOrdinateSeries;
$this->ordinateLogos = $truncatedOrdinateLogos; $this->abscissaLogos = $truncatedAbscissaLogos;
} }
// blank characters are used to pad labels so the logo can be displayed // blank characters are used to pad labels so the logo can be displayed
...@@ -119,21 +120,18 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -119,21 +120,18 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
while($paddingWidth < $maxLogoWidth + self::LOGO_MIN_RIGHT_MARGIN) while($paddingWidth < $maxLogoWidth + self::LOGO_MIN_RIGHT_MARGIN)
{ {
$paddingText .= self::PADDING_CHARS; $paddingText .= self::PADDING_CHARS;
$paddingTextWidthHeight = $this->getTextWidthHeight($paddingText); $paddingWidth = $this->getTextWidth($paddingText);
$paddingWidth = $paddingTextWidthHeight[self::WIDTH_KEY];
} }
} }
// determine the maximum label width according to the minimum comfortable graph size // determine the maximum label width according to the minimum comfortable graph size
$gridRightMargin = $this->getGridRightMargin($horizontalGraph = true); $gridRightMargin = $this->getGridRightMargin($horizontalGraph = true);
$minGraphSize = ($this->width - $gridRightMargin) / 2; $minGraphSize = ($this->width - $gridRightMargin) / 2;
$metricLegendWidth = 0; $metricLegendWidth = 0;
foreach($this->ordinateLabels as $column => $label) foreach($this->ordinateLabels as $column => $label)
{ {
$metricTitleWidthHeight = $this->getTextWidthHeight($label); $metricLegendWidth += $this->getTextWidth($label);
$metricLegendWidth += $metricTitleWidthHeight[self::WIDTH_KEY];
} }
$legendWidth = $metricLegendWidth + ((self::LEGEND_LEFT_MARGIN + self::LEGEND_SQUARE_WIDTH) * $numberOfSeries); $legendWidth = $metricLegendWidth + ((self::LEGEND_LEFT_MARGIN + self::LEGEND_SQUARE_WIDTH) * $numberOfSeries);
...@@ -154,12 +152,10 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -154,12 +152,10 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
- $minGraphSize; - $minGraphSize;
// truncate labels if needed // truncate labels if needed
$truncationTextWidthHeight = $this->getTextWidthHeight(self::TRUNCATION_TEXT); $truncationTextWidth = $this->getTextWidth(self::TRUNCATION_TEXT);
$truncationTextWidth = $truncationTextWidthHeight[self::WIDTH_KEY];
foreach($this->abscissaSeries as &$label) foreach($this->abscissaSeries as &$label)
{ {
$labelWidthHeight = $this->getTextWidthHeight($label); $labelWidth = $this->getTextWidth($label);
$labelWidth = $labelWidthHeight[self::WIDTH_KEY];
if($labelWidth > $labelWidthLimit) if($labelWidth > $labelWidthLimit)
{ {
$averageCharWidth = $labelWidth / strlen($label); $averageCharWidth = $labelWidth / strlen($label);
...@@ -180,7 +176,8 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -180,7 +176,8 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
$displayVerticalGridLines = false, $displayVerticalGridLines = false,
$drawCircles = false, $drawCircles = false,
$horizontalGraph = true, $horizontalGraph = true,
$showTicks = false $showTicks = false,
$verticalLegend
); );
$valueColor = $this->colors[self::VALUE_COLOR_KEY]; $valueColor = $this->colors[self::VALUE_COLOR_KEY];
...@@ -197,17 +194,17 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -197,17 +194,17 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
// // display icons // // display icons
$graphData = $this->pData->getData(); $graphData = $this->pData->getData();
$numberOfRows = count($this->abscissaSeries); $numberOfRows = count($this->abscissaSeries);
$logoInterleave = $this->getGraphHeight(true) / $numberOfRows; $logoInterleave = $this->getGraphHeight(true, $verticalLegend) / $numberOfRows;
for($i = 0; $i < $numberOfRows; $i++) for($i = 0; $i < $numberOfRows; $i++)
{ {
if(isset($this->ordinateLogos[$i])) if(isset($this->abscissaLogos[$i]))
{ {
$logoPath = $this->ordinateLogos[$i]; $logoPath = $this->abscissaLogos[$i];
$absoluteLogoPath = self::getAbsoluteLogoPath($logoPath); $absoluteLogoPath = self::getAbsoluteLogoPath($logoPath);
if(isset($logoPathToSizes[$absoluteLogoPath])) if(isset($logoPathToHeight[$absoluteLogoPath]))
{ {
$logoWidthHeight = $logoPathToSizes[$absoluteLogoPath]; $logoHeight = $logoPathToHeight[$absoluteLogoPath];
$pathInfo = pathinfo($logoPath); $pathInfo = pathinfo($logoPath);
$logoExtension = strtoupper($pathInfo['extension']); $logoExtension = strtoupper($pathInfo['extension']);
...@@ -215,9 +212,9 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -215,9 +212,9 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
$logoYPosition = $logoYPosition =
($logoInterleave * $i) ($logoInterleave * $i)
+ $this->getGridTopMargin(true) + $this->getGridTopMargin(true, $verticalLegend)
+ $graphData['Axis'][1]['Margin'] + $graphData['Axis'][1]['Margin']
- $logoWidthHeight[self::HEIGHT_KEY] / 2 - $logoHeight / 2
+ 1; + 1;
$this->pImage->$drawingFunction( $this->pImage->$drawingFunction(
...@@ -234,13 +231,4 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static ...@@ -234,13 +231,4 @@ class Piwik_ImageGraph_StaticGraph_HorizontalBar extends Piwik_ImageGraph_Static
{ {
return PIWIK_INCLUDE_PATH . '/' . $relativeLogoPath; return PIWIK_INCLUDE_PATH . '/' . $relativeLogoPath;
} }
private static function getLogoWidthHeight($logoPath)
{
$pathInfo = getimagesize($logoPath);
return array(
self::WIDTH_KEY => $pathInfo[0],
self::HEIGHT_KEY => $pathInfo[1]
);
}
} }
...@@ -25,7 +25,8 @@ class Piwik_ImageGraph_StaticGraph_VerticalBar extends Piwik_ImageGraph_StaticGr ...@@ -25,7 +25,8 @@ class Piwik_ImageGraph_StaticGraph_VerticalBar extends Piwik_ImageGraph_StaticGr
$displayVerticalGridLines = false, $displayVerticalGridLines = false,
$drawCircles = false, $drawCircles = false,
$horizontalGraph = false, $horizontalGraph = false,
$showTicks = true $showTicks = true,
$verticalLegend = false
); );
$this->pImage->drawBarChart( $this->pImage->drawBarChart(
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter