Skip to content

Commit

Permalink
Merge branch 'master' of github.com:piwik/piwik
Browse files Browse the repository at this point in the history
  • Loading branch information
halfdan committed Apr 9, 2013
2 parents e3096c0 + f637d12 commit 5cb694e
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 103 deletions.
36 changes: 31 additions & 5 deletions plugins/ImageGraph/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class Piwik_ImageGraph_API
const UNICODE_FONT = 'unifont.ttf';
const DEFAULT_FONT_SIZE = 9;
const DEFAULT_LEGEND_FONT_SIZE_OFFSET = 2;
const DEFAULT_TEXT_COLOR = '222222';
const DEFAULT_BACKGROUND_COLOR = 'FFFFFF';
const DEFAULT_GRID_COLOR = 'CCCCCC';

// number of row evolutions to plot when no labels are specified, can be overridden using &filter_limit
const DEFAULT_NB_ROW_EVOLUTIONS = 5;
Expand All @@ -104,11 +107,30 @@ static public function getInstance()
return self::$instance;
}

public function get($idSite, $period, $date, $apiModule, $apiAction, $graphType = false,
$outputType = Piwik_ImageGraph_API::GRAPH_OUTPUT_INLINE, $columns = false, $labels = false, $showLegend = true,
$width = false, $height = false, $fontSize = Piwik_ImageGraph_API::DEFAULT_FONT_SIZE, $legendFontSize = false,
$aliasedGraph = true, $idGoal = false, $colors = false, $idSubtable = false, $legendAppendMetric = true)
{
public function get(
$idSite,
$period,
$date,
$apiModule,
$apiAction,
$graphType = false,
$outputType = Piwik_ImageGraph_API::GRAPH_OUTPUT_INLINE,
$columns = false,
$labels = false,
$showLegend = true,
$width = false,
$height = false,
$fontSize = Piwik_ImageGraph_API::DEFAULT_FONT_SIZE,
$legendFontSize = false,
$aliasedGraph = true,
$idGoal = false,
$colors = false,
$textColor = Piwik_ImageGraph_API::DEFAULT_TEXT_COLOR,
$backgroundColor = Piwik_ImageGraph_API::DEFAULT_BACKGROUND_COLOR,
$gridColor = Piwik_ImageGraph_API::DEFAULT_GRID_COLOR,
$idSubtable = false,
$legendAppendMetric = true
) {
Piwik::checkUserHasViewAccess($idSite);

// Health check - should we also test for GD2 only?
Expand Down Expand Up @@ -440,6 +462,9 @@ public function get($idSite, $period, $date, $apiModule, $apiAction, $graphType
$graph->setOrdinateSeries($ordinateSeries);
$graph->setOrdinateLogos($ordinateLogos);
$graph->setColors(!empty($colors) ? explode(',', $colors) : array());
$graph->setTextColor($textColor);
$graph->setBackgroundColor($backgroundColor);
$graph->setGridColor($gridColor);

// when requested period is day, x-axis unit is time and all date labels can not be displayed
// within requested width, force labels to be skipped every 6 days to delimit weeks
Expand All @@ -457,6 +482,7 @@ public function get($idSite, $period, $date, $apiModule, $apiAction, $graphType
$graph->setHeight($height);
$graph->setFont($font);
$graph->setFontSize($fontSize);
$graph->setTextColor($textColor);
$graph->setException($e);
$graph->renderGraph();
}
Expand Down
29 changes: 25 additions & 4 deletions plugins/ImageGraph/StaticGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ abstract class Piwik_ImageGraph_StaticGraph
protected $colors;
protected $font;
protected $fontSize;
protected $textColor;
protected $backgroundColor;
protected $gridColor;
protected $legendFontSize;
protected $width;
protected $height;
Expand Down Expand Up @@ -148,6 +151,21 @@ public function setFont($font)
$this->font = $font;
}

public function setTextColor($textColor)
{
$this->textColor = self::hex2rgb($textColor);
}

public function setBackgroundColor($backgroundColor)
{
$this->backgroundColor = self::hex2rgb($backgroundColor);
}

public function setGridColor($gridColor)
{
$this->gridColor = self::hex2rgb($gridColor);
}

public function setOrdinateSeries($ordinateSeries)
{
$this->ordinateSeries = $ordinateSeries;
Expand Down Expand Up @@ -241,9 +259,12 @@ protected function initpImage()
$this->pImage->Antialias = $this->aliasedGraph;

$this->pImage->setFontProperties(
array(
"FontName" => $this->font,
"FontSize" => $this->fontSize
array_merge(
array(
'FontName' => $this->font,
'FontSize' => $this->fontSize,
),
$this->textColor
)
);
}
Expand All @@ -268,7 +289,7 @@ protected function getTextWidthHeight($text, $fontSize = false)
)
);

return array($textInfo[1]["X"] + 1, $textInfo[0]["Y"] - $textInfo[2]["Y"]);
return array($textInfo[1]['X'] + 1, $textInfo[0]['Y'] - $textInfo[2]['Y']);
}

protected function getMaximumTextWidthHeight($values)
Expand Down
17 changes: 11 additions & 6 deletions plugins/ImageGraph/StaticGraph/GridGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_StaticGraph
{
const GRAPHIC_COLOR_KEY = 'GRAPHIC_COLOR';
const VALUE_COLOR_KEY = 'VALUE_COLOR';
const GRID_COLOR_KEY = 'GRID_COLOR';

const TRUNCATION_TEXT = '...';

Expand Down Expand Up @@ -51,8 +49,6 @@ abstract class Piwik_ImageGraph_StaticGraph_GridGraph extends Piwik_ImageGraph_S
protected function getDefaultColors()
{
return array(
self::VALUE_COLOR_KEY => '444444',
self::GRID_COLOR_KEY => 'CCCCCC',
self::GRAPHIC_COLOR_KEY . '1' => '5170AE',
self::GRAPHIC_COLOR_KEY . '2' => 'F29007',
self::GRAPHIC_COLOR_KEY . '3' => 'CC3399',
Expand Down Expand Up @@ -87,6 +83,15 @@ protected function initGridChart(
$bottomRightXValue = $this->width - $this->getGridRightMargin($horizontalGraph);
$bottomRightYValue = $this->getGraphBottom($horizontalGraph);

// background color
$this->pImage->drawFilledRectangle(
0,
0,
$this->width,
$this->height,
array_merge(array('Alpha' => 100), $this->backgroundColor)
);

$this->pImage->setGraphArea(
$topLeftXValue,
$topLeftYValue,
Expand Down Expand Up @@ -146,7 +151,7 @@ protected function initGridChart(
if ($modTen) $maxOrdinateValue += 10 - $modTen;
}

$gridColor = $this->colors[self::GRID_COLOR_KEY];
$gridColor = $this->gridColor;
$this->pImage->drawScale(
array(
'Mode' => SCALE_MODE_MANUAL,
Expand Down Expand Up @@ -291,7 +296,7 @@ protected function initGridChart(
}

// draw legend
$legendColor = $this->colors[self::VALUE_COLOR_KEY];
$legendColor = $this->textColor;
$this->pImage->drawLegend(
$legendTopLeftXValue,
$legendTopLeftYValue,
Expand Down
2 changes: 1 addition & 1 deletion plugins/ImageGraph/StaticGraph/HorizontalBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function renderGraph()
$verticalLegend
);

$valueColor = $this->colors[self::VALUE_COLOR_KEY];
$valueColor = $this->textColor;
$this->pImage->drawBarChart(
array(
'DisplayValues' => true,
Expand Down
Loading

0 comments on commit 5cb694e

Please sign in to comment.