Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormatt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105>2009-04-27 08:18:16 +0400
committermatt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105>2009-04-27 08:18:16 +0400
commitbfba0e7e3e0ad6814598d25852289024e8083c9d (patch)
tree6379b457ce107dc84454e26c2ce5938ff3befab2 /core
parent343f365af322f68d6ea86ea929041ce34e8957d6 (diff)
- API CHANGE: the API for the function Piwik_AddWidget has changed. The new API is Piwik_AddWidget( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array()). See examples of calls in all the core Piwik plugins. This change was necessary to make widgets more modular (they now accept custom parameters).
- API CHANGE: a small number of CSV outputs for some API calls would change following the simplification of DataTable_Simple implementation. Affected calls are VisitsSummary.get, Goals.get, VisitFrequency.get. This is due to a change in the implementation of DataTable_Simple (we simplified implementation). - FIXED #84 Added proper translations for all columns, in tables, and graphs. - FIXED #322 piwik is now using open flash chart 2 - FIXED #126 all dates should be correctly displayed in all graphs. For example, evolution graph for days would show, on the X axis "Mon 29", "Wed 31". For months it would show "Aug 2009", etc. - ADDED: when hovering any of the sparklines, the UI makes it clear that clicking will refresh the evolution graph. This feature was in Piwik for months, and even Google Analytics implemented this UI feature after Piwik. However in Piwik it wasn't clear to the user that the sparklines were clickable. - ADDED: now widgets can be created with custom parameters. This makes it possible to create a widget that calls a controller->action with other custom parameters, this is used in Piwik to draw an evolution graph (module=VisitsSummary & action=getEvolutionGraph) for a given metric (&columns[]=nb_visits). These custom parameters are automatically forwarded to the sparkline url, the flash graph when clicked on sparkline, etc. - The widget layout is now saved as a JSON string rather than a custom data structure. The dashboard code should be able to read & restore most of the layouts from the old format (except the evolution graphs widgets). Simplified the Dashboard.js, widgetMenu.js, cleaned up what was a messy code. - Added sentence in Widgetize to let users know they can easily export the Piwik dashboard in an iframe. - Changed the way translations used in Javascript are loaded: all translations strings finishing by _js will be loaded to be used in the templates when calling {loadJavascriptTranslations plugins='YOUR_PLUGIN_NAME'} - Moved all templates in plugins under plugins/$PLUGIN/templates/ - 'Khtml (Konqueror, Safari)' now displayed as 'KHTML (Safari, Chrome)'
Diffstat (limited to 'core')
-rw-r--r--core/API/ResponseBuilder.php13
-rw-r--r--core/Archive/Array/IndexedByDate.php5
-rw-r--r--core/Archive/Array/IndexedBySite.php1
-rw-r--r--core/Archive/Single.php5
-rw-r--r--core/ArchiveProcessing.php12
-rw-r--r--core/ArchiveProcessing/Day.php10
-rw-r--r--core/ArchiveProcessing/Period.php2
-rw-r--r--core/Controller.php29
-rw-r--r--core/DataTable/Array.php10
-rw-r--r--core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php28
-rw-r--r--core/DataTable/Filter/SafeDecodeLabel.php9
-rw-r--r--core/DataTable/Renderer/Console.php15
-rw-r--r--core/DataTable/Renderer/Csv.php21
-rw-r--r--core/DataTable/Renderer/Html.php6
-rw-r--r--core/DataTable/Renderer/Php.php11
-rw-r--r--core/DataTable/Renderer/Rss.php6
-rw-r--r--core/DataTable/Renderer/Xml.php4
-rw-r--r--core/DataTable/Simple.php24
-rw-r--r--core/Date.php29
-rw-r--r--core/FrontController.php1
-rw-r--r--core/Period.php4
-rw-r--r--core/Period/Day.php14
-rw-r--r--core/Period/Month.php7
-rw-r--r--core/Period/Range.php12
-rw-r--r--core/Period/Week.php11
-rw-r--r--core/Period/Year.php7
-rw-r--r--core/Piwik.php9
-rw-r--r--core/PluginsFunctions/WidgetsList.php17
-rw-r--r--core/Site.php5
-rw-r--r--core/SmartyPlugins/function.loadJavascriptTranslations.php48
-rw-r--r--core/Translate.php19
-rw-r--r--core/Url.php4
-rw-r--r--core/ViewDataTable.php46
-rw-r--r--core/ViewDataTable/GenerateGraphData.php73
-rw-r--r--core/ViewDataTable/GenerateGraphData/ChartEvolution.php247
-rw-r--r--core/ViewDataTable/GenerateGraphHTML.php2
-rw-r--r--core/ViewDataTable/HtmlTable.php51
-rw-r--r--core/ViewDataTable/HtmlTable/AllColumns.php3
-rw-r--r--core/ViewDataTable/HtmlTable/Goals.php2
-rw-r--r--core/ViewDataTable/Sparkline.php95
-rw-r--r--core/Visualization/Chart.php180
-rw-r--r--core/Visualization/Chart/Evolution.php126
-rw-r--r--core/Visualization/Chart/Pie.php61
-rw-r--r--core/Visualization/Chart/VerticalBar.php56
-rw-r--r--core/Visualization/OpenFlashChart.php1637
-rw-r--r--core/Visualization/Sparkline.php44
46 files changed, 767 insertions, 2254 deletions
diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php
index 52e2d0ee14..1f6f04c8fb 100644
--- a/core/API/ResponseBuilder.php
+++ b/core/API/ResponseBuilder.php
@@ -156,11 +156,16 @@ class Piwik_API_ResponseBuilder
// if asked for original dataStructure
if($format == 'original')
{
- // if the original dataStructure is a simpleDataTable and has only one row, we return the value
- if($dataTable instanceof Piwik_DataTable_Simple
- && $dataTable->getRowsCount() == 1)
+ // if the original dataStructure is a simpleDataTable
+ // and has only one column, we return the value
+ if($dataTable instanceof Piwik_DataTable_Simple)
{
- return $dataTable->getRowFromId(0)->getColumn('value');
+ $columns = $dataTable->getFirstRow()->getColumns();
+ if(count($columns) == 1)
+ {
+ $values = array_values($columns);
+ return $values[0];
+ }
}
// by default "original" data is not serialized
diff --git a/core/Archive/Array/IndexedByDate.php b/core/Archive/Array/IndexedByDate.php
index 57ab78bb1c..f9fe5eb3a1 100644
--- a/core/Archive/Array/IndexedByDate.php
+++ b/core/Archive/Array/IndexedByDate.php
@@ -34,6 +34,7 @@ class Piwik_Archive_Array_IndexedByDate extends Piwik_Archive_Array
$table->metadata[$archive->getPrettyDate()] = array(
'timestamp' => $archive->getTimestampStartDate(),
'site' => $archive->getSite(),
+ 'period' => $archive->getPeriod(),
);
}
@@ -78,7 +79,7 @@ class Piwik_Archive_Array_IndexedByDate extends Piwik_Archive_Array
foreach($queries as $table => $aIds)
{
$inIds = implode(', ', $aIds);
- $sql = "SELECT value, name, idarchive, UNIX_TIMESTAMP(date1) as timestamp
+ $sql = "SELECT value, name, UNIX_TIMESTAMP(date1) as timestamp
FROM $table
WHERE idarchive IN ( $inIds )
AND name IN ( $inNames )";
@@ -87,7 +88,7 @@ class Piwik_Archive_Array_IndexedByDate extends Piwik_Archive_Array
foreach($values as $value)
{
- $arrayValues[$value['timestamp']][$value['name']] = $value['value'];
+ $arrayValues[$value['timestamp']][$value['name']] = (float)$value['value'];
}
}
diff --git a/core/Archive/Array/IndexedBySite.php b/core/Archive/Array/IndexedBySite.php
index 1a27c10ce5..7dbf0f5a30 100644
--- a/core/Archive/Array/IndexedBySite.php
+++ b/core/Archive/Array/IndexedBySite.php
@@ -66,6 +66,7 @@ class Piwik_Archive_Array_IndexedBySite extends Piwik_Archive_Array
private function getValues($fields)
{
+ $arrayValues = array();
foreach($this->loadValuesFromDB($fields) as $value)
{
$arrayValues[$value['idsite']][$value['name']] = $value['value'];
diff --git a/core/Archive/Single.php b/core/Archive/Single.php
index e4d6c4d472..475d5319eb 100644
--- a/core/Archive/Single.php
+++ b/core/Archive/Single.php
@@ -107,6 +107,11 @@ class Piwik_Archive_Single extends Piwik_Archive
$this->period = $period;
}
+ public function getPeriod()
+ {
+ return $this->period;
+ }
+
/**
* Returns the timestamp of the first date in the period for this Archive.
* This is used to sort archives by date when working on a Archive_Array
diff --git a/core/ArchiveProcessing.php b/core/ArchiveProcessing.php
index 3418447d10..d2b5c6f72f 100644
--- a/core/ArchiveProcessing.php
+++ b/core/ArchiveProcessing.php
@@ -174,6 +174,13 @@ abstract class Piwik_ArchiveProcessing
protected $debugAlwaysArchive = false;
/**
+ * If the archive has at least 1 visit, this is set to true.
+ *
+ * @var bool
+ */
+ public $isThereSomeVisits = false;
+
+ /**
* Constructor
*/
public function __construct()
@@ -290,11 +297,6 @@ abstract class Piwik_ArchiveProcessing
{
return null;
}
- else
- {
- $this->isThereSomeVisits = true;
- }
-
return $this->idArchive;
}
diff --git a/core/ArchiveProcessing/Day.php b/core/ArchiveProcessing/Day.php
index 7fcc512c46..1b0a21c19b 100644
--- a/core/ArchiveProcessing/Day.php
+++ b/core/ArchiveProcessing/Day.php
@@ -22,16 +22,6 @@
*/
class Piwik_ArchiveProcessing_Day extends Piwik_ArchiveProcessing
{
- /**
- * If the archive has at least 1 visit, this is set to true.
- *
- * @var bool
- */
- public $isThereSomeVisits = false;
-
- /**
- * Constructor
- */
function __construct()
{
parent::__construct();
diff --git a/core/ArchiveProcessing/Period.php b/core/ArchiveProcessing/Period.php
index e2bcfda5c9..06cd6ab894 100644
--- a/core/ArchiveProcessing/Period.php
+++ b/core/ArchiveProcessing/Period.php
@@ -267,7 +267,7 @@ class Piwik_ArchiveProcessing_Period extends Piwik_ArchiveProcessing
$nbVisits = $record['nb_visits']->value;
$nbVisitsConverted = $record['nb_visits_converted']->value;
- $this->isThereSomeVisits = ( $nbVisits!= 0);
+ $this->isThereSomeVisits = ( $nbVisits > 0);
if($this->isThereSomeVisits === false)
{
return;
diff --git a/core/Controller.php b/core/Controller.php
index ed615103a9..8718b20cf2 100644
--- a/core/Controller.php
+++ b/core/Controller.php
@@ -68,6 +68,21 @@ abstract class Piwik_Controller
return 'index';
}
+ protected $standardColumnNameToTranslation = array(
+ 'label' => 'General_ColumnLabel',
+ 'nb_visits' => 'General_ColumnNbVisits',
+ 'nb_actions' => 'General_ColumnNbActions',
+ 'max_actions' => 'General_ColumnMaxActions',
+ 'sum_visit_length' => 'General_ColumnSumVisitLength',
+ 'nb_uniq_visitors' => 'General_ColumnNbUniqVisitors',
+ 'nb_actions_per_visit' => 'General_ColumnActionsPerVisit',
+ 'avg_time_on_site' => 'General_ColumnAvgTimeOnSite',
+ 'bounce_rate' => 'General_ColumnBounceRate',
+
+ 'revenue_per_visit' => 'General_ColumnValuePerVisit',
+ 'goals_conversion_rate' => 'General_ColumnVisitsWithConversions',
+ );
+
/**
* Given an Object implementing Piwik_iView interface, we either:
* - echo the output of the rendering if fetch = false
@@ -88,6 +103,9 @@ abstract class Piwik_Controller
'controllerActionCalledWhenRequestSubTable' => $view->getControllerActionCalledWhenRequestSubTable(),
)
);
+
+ $standardColumnNameToTranslation = array_map('Piwik_Translate', $this->standardColumnNameToTranslation);
+ $view->setColumnsTranslations($standardColumnNameToTranslation);
$view->main();
$rendered = $view->getView()->render();
if($fetch)
@@ -118,7 +136,7 @@ abstract class Piwik_Controller
if( !is_null($this->date))
{
$view->setParametersToModify(
- $this->getGraphParamsModified( array('date'=>$this->strDate))
+ $this->getGraphParamsModified( array('date' => $this->strDate))
);
}
@@ -192,20 +210,22 @@ abstract class Piwik_Controller
}
/**
- * Returns the current URL to use in a <img src=X> to display a sparkline.
+ * Returns the current URL to use in a img src=X to display a sparkline.
* $action must be the name of a Controller method that requests data using the Piwik_ViewDataTable::factory
* It will automatically build a sparkline by setting the viewDataTable=sparkline parameter in the URL.
* It will also computes automatically the 'date' for the 'last30' days/weeks/etc.
*
* @param string $action, eg. method name of the controller to call in the img src
+ * @param array array of name => value of parameters to set in the generated GET url
* @return string the generated URL
*/
- protected function getUrlSparkline( $action )
+ protected function getUrlSparkline( $action, $customParameters = array() )
{
$params = $this->getGraphParamsModified(
array( 'viewDataTable' => 'sparkline',
'action' => $action,
'module' => $this->pluginName)
+ + $customParameters
);
$url = Piwik_Url::getCurrentQueryStringWithParametersModified($params);
return $url;
@@ -214,7 +234,8 @@ abstract class Piwik_Controller
protected function setGeneralVariablesView($view)
{
$oDate = Piwik_Date::factory($this->strDate);
- $localizedDateFormat = Piwik_Translate('CoreHome_LocalizedDateFormat');
+ //TODO TO FIX
+ $localizedDateFormat = Piwik_Translate('CoreHome_DayFormat');
$view->prettyDate = $oDate->getLocalized($localizedDateFormat);
$view->date = $this->strDate;
diff --git a/core/DataTable/Array.php b/core/DataTable/Array.php
index 63bbd6704b..11b812e894 100644
--- a/core/DataTable/Array.php
+++ b/core/DataTable/Array.php
@@ -111,7 +111,7 @@ class Piwik_DataTable_Array
*/
public function filter($className, $parameters = array())
{
- foreach($this->array as $table)
+ foreach($this->array as $id => $table)
{
$table->filter($className, $parameters);
}
@@ -161,6 +161,14 @@ class Piwik_DataTable_Array
$table->enableRecursiveSort();
}
}
+
+ public function deleteColumns($columns)
+ {
+ foreach($this->array as $table)
+ {
+ $table->deleteColumns($columns);
+ }
+ }
}
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
index 7032a3a873..15ffab66c5 100644
--- a/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
+++ b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
@@ -16,22 +16,32 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage extends Piwik_Dat
{
private $columnValueToRead;
private $columnNamePercentageToAdd;
- private $totalValueUsedToComputePercentage;
+ private $columnNameUsedAsDivisor;
+ private $totalValueUsedAsDivisor;
private $percentagePrecision;
/**
* @param Piwik_DataTable $table
* @param string $columnValueToRead
* @param string $columnNamePercentageToAdd
- * @param double $totalValueUsedToComputePercentage
+ * @param numeric|string $totalValueUsedToComputePercentageOrColumnName
+ * if a numeric value is given, we use this value as the divisor to process the percentage.
+ * if a string is given, this string is the column name's value used as the divisor.
* @param int $percentagePrecision precision 0 means "11", 1 means "11.2"
*/
- public function __construct( $table, $columnValueToRead, $columnNamePercentageToAdd, $totalValueUsedToComputePercentage, $percentagePrecision = 0 )
+ public function __construct( $table, $columnValueToRead, $columnNamePercentageToAdd, $totalValueUsedToComputePercentageOrColumnName, $percentagePrecision = 0 )
{
parent::__construct($table);
$this->columnValueToRead = $columnValueToRead;
$this->columnNamePercentageToAdd = $columnNamePercentageToAdd;
- $this->totalValueUsedToComputePercentage = $totalValueUsedToComputePercentage;
+ if(is_numeric($totalValueUsedToComputePercentageOrColumnName))
+ {
+ $this->totalValueUsedAsDivisor = $totalValueUsedToComputePercentageOrColumnName;
+ }
+ else
+ {
+ $this->columnNameUsedAsDivisor = $totalValueUsedToComputePercentageOrColumnName;
+ }
$this->percentagePrecision = $percentagePrecision;
$this->filter();
}
@@ -41,7 +51,15 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage extends Piwik_Dat
foreach($this->table->getRows() as $key => $row)
{
$value = $row->getColumn($this->columnValueToRead);
- $percentage = round( 100 * $value / $this->totalValueUsedToComputePercentage, $this->percentagePrecision);
+ if(!is_null($this->totalValueUsedAsDivisor))
+ {
+ $divisor = $this->totalValueUsedAsDivisor;
+ }
+ else
+ {
+ $divisor = $row->getColumn($this->columnNameUsedAsDivisor);
+ }
+ $percentage = Piwik::getPercentageSafe($value, $divisor, $this->percentagePrecision);
$row->addColumn($this->columnNamePercentageToAdd, $percentage);
}
}
diff --git a/core/DataTable/Filter/SafeDecodeLabel.php b/core/DataTable/Filter/SafeDecodeLabel.php
index fc293d9107..454d4599f4 100644
--- a/core/DataTable/Filter/SafeDecodeLabel.php
+++ b/core/DataTable/Filter/SafeDecodeLabel.php
@@ -28,13 +28,18 @@ class Piwik_DataTable_Filter_SafeDecodeLabel extends Piwik_DataTable_Filter
{
foreach($this->table->getRows() as $row)
{
- $row->setColumn( $this->columnToDecode,
+ $value = $row->getColumn($this->columnToDecode);
+ if($value !== false)
+ {
+ $row->setColumn(
+ $this->columnToDecode,
htmlspecialchars(
htmlspecialchars_decode(
- urldecode($row->getColumn($this->columnToDecode)),
+ urldecode($value),
ENT_QUOTES),
ENT_QUOTES)
);
+ }
}
}
}
diff --git a/core/DataTable/Renderer/Console.php b/core/DataTable/Renderer/Console.php
index b0c00e3f6f..d324370024 100644
--- a/core/DataTable/Renderer/Console.php
+++ b/core/DataTable/Renderer/Console.php
@@ -29,16 +29,27 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
$this->prefixRows = $str;
}
- protected function renderDataTableArray(Piwik_DataTable_Array $table, $prefix )
+ protected function renderDataTableArray(Piwik_DataTable_Array $tableArray, $prefix )
{
$output = "Piwik_DataTable_Array<hr>";
$prefix = $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
- foreach($table->getArray() as $descTable => $table)
+ foreach($tableArray->getArray() as $descTable => $table)
{
$output .= $prefix . "<b>". $descTable. "</b><br>";
$output .= $prefix . $this->renderTable($table, $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;');
$output .= "<hr>";
}
+ $output .= "Metadata<br>";
+ foreach($tableArray->metadata as $id => $metadata)
+ {
+ $output .= "<br>";
+ $output .= $prefix . " <b>$id</b> <br>";
+ foreach($metadata as $name => $value)
+ {
+ $output .= $prefix . $prefix . "$name => $value";
+ }
+ }
+ $output .= "<hr>";
return $output;
}
diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php
index 55a4887370..53dbc25a8d 100644
--- a/core/DataTable/Renderer/Csv.php
+++ b/core/DataTable/Renderer/Csv.php
@@ -110,16 +110,21 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer
protected function renderDataTable( $table )
{
- if($table instanceof Piwik_DataTable_Simple
- && $table->getRowsCount() == 1)
+ if($table instanceof Piwik_DataTable_Simple)
{
- $str = 'value' . $this->lineEnd . $this->formatValue($table->getRowFromId(0)->getColumn('value'));
- return $str;
+ $row = $table->getFirstRow();
+ if($row !== false)
+ {
+ $columnNameToValue = $row->getColumns();
+ if(count($columnNameToValue) == 1)
+ {
+ $value = array_values($columnNameToValue);
+ $str = 'value' . $this->lineEnd . $this->formatValue($value[0]);
+ return $str;
+ }
+ }
}
-
- $csv = array();
-
- $allColumns = array();
+ $csv = $allColumns = array();
foreach($table->getRows() as $row)
{
$csvRow = array();
diff --git a/core/DataTable/Renderer/Html.php b/core/DataTable/Renderer/Html.php
index ef9664ba23..6601a6c7ad 100644
--- a/core/DataTable/Renderer/Html.php
+++ b/core/DataTable/Renderer/Html.php
@@ -51,12 +51,6 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer
{
return "<b><i>Empty table</i></b> <br>\n";
}
- if($table instanceof Piwik_DataTable_Simple
- && $table->getRowsCount() ==1)
- {
- $table->deleteColumn('label');
- }
-
static $depth=0;
$i = 1;
$someMetadata = false;
diff --git a/core/DataTable/Renderer/Php.php b/core/DataTable/Renderer/Php.php
index b098fedeb8..1fcfea5d3b 100644
--- a/core/DataTable/Renderer/Php.php
+++ b/core/DataTable/Renderer/Php.php
@@ -97,7 +97,6 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
}
}
- // A DataTable_Simple is already flattened so no need to do some crazy stuff to convert it
else if($dataTable instanceof Piwik_DataTable_Simple)
{
$flatArray = $this->renderSimpleTable($dataTable);
@@ -198,9 +197,15 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
protected function renderSimpleTable($table)
{
$array = array();
- foreach($table->getRows() as $row)
+
+ $row = $table->getFirstRow();
+ if($row === false)
+ {
+ return $array;
+ }
+ foreach($row->getColumns() as $columnName => $columnValue)
{
- $array[$row->getColumn('label')] = $row->getColumn('value');
+ $array[$columnName] = $columnValue;
}
return $array;
}
diff --git a/core/DataTable/Renderer/Rss.php b/core/DataTable/Renderer/Rss.php
index 311925a9e7..fc8565bf66 100644
--- a/core/DataTable/Renderer/Rss.php
+++ b/core/DataTable/Renderer/Rss.php
@@ -95,16 +95,10 @@ class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer
protected function renderDataTable($table)
{
-
if($table->getRowsCount() == 0)
{
return "<b><i>Empty table</i></b> <br>\n";
}
- if($table instanceof Piwik_DataTable_Simple
- && $table->getRowsCount() ==1)
- {
- $table->deleteColumn('label');
- }
$i = 1;
$tableStructure = array();
diff --git a/core/DataTable/Renderer/Xml.php b/core/DataTable/Renderer/Xml.php
index f509c3e9bf..5d70a44bf8 100644
--- a/core/DataTable/Renderer/Xml.php
+++ b/core/DataTable/Renderer/Xml.php
@@ -160,9 +160,9 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
{
if(is_array($dataTableSimple))
{
- $dataTableSimple = "\n" . $this->renderDataTableSimple($dataTableSimple, $prefixLines . "\t") . "\t" ;
+ $dataTableSimple = "\n" . $this->renderDataTableSimple($dataTableSimple, $prefixLines . "\t") . $prefixLines . "\t";
}
- $xml .= $prefixLines . "\t<result $nameDescriptionAttribute=\"$valueAttribute\">".$dataTableSimple. $prefixLines . "</result>\n";
+ $xml .= $prefixLines . "\t<result $nameDescriptionAttribute=\"$valueAttribute\">".$dataTableSimple. "</result>\n";
}
}
return $xml;
diff --git a/core/DataTable/Simple.php b/core/DataTable/Simple.php
index 33c9f87b79..8dfdbaefec 100644
--- a/core/DataTable/Simple.php
+++ b/core/DataTable/Simple.php
@@ -34,28 +34,6 @@ class Piwik_DataTable_Simple extends Piwik_DataTable
*/
function addRowsFromArray($array)
{
- foreach($array as $label => $value)
- {
- $row = new Piwik_DataTable_Row;
- $row->addColumn('label', $label);
- $row->addColumn('value', $value);
- $this->addRow($row);
- }
- }
-
- /**
- * Returns the 'value' column of the row that has a label '$label'.
- *
- * @param string Label of the row we want the value
- * @return false|mixed The 'value' column of the row labelled $label
- */
- function getColumn( $label )
- {
- $row = $this->getRowFromLabel($label);
- if($row === false)
- {
- return false;
- }
- return $row->getColumn('value');
+ $this->addRowsFromSimpleArray(array($array));
}
}
diff --git a/core/Date.php b/core/Date.php
index fc708ffd86..394adab8d4 100644
--- a/core/Date.php
+++ b/core/Date.php
@@ -237,20 +237,23 @@ class Piwik_Date
return date($part, $this->getTimestamp());
}
- /**
- * Returns a localized representation of a date or datepart
- *
- * @see Windows compatible arguments http://msdn.microsoft.com/en-us/library/fe06s4ak(VS.71).aspx
- * @param string OPTIONAL Part of the date to return (in strftime format), if null timestamp is returned
- * @return integer|string date or datepart
- */
- public function getLocalized($part = null)
+ //TODO to test
+ public function getLocalized($template)
{
- if(is_null($part))
- {
- return $this->getTimestamp();
- }
- return strftime($part, $this->getTimestamp());
+ $day = $this->toString('j');
+ $dayOfWeek = $this->toString('N');
+ $monthOfYear = $this->toString('n');
+ $patternToValue = array(
+ "%day%" => $day,
+ "%shortMonth%" => Piwik_Translate('General_ShortMonth_'.$monthOfYear),
+ "%longMonth%" => Piwik_Translate('General_LongMonth_'.$monthOfYear),
+ "%shortDay%" => Piwik_Translate('General_ShortDay_'.$dayOfWeek),
+ "%longDay%" => Piwik_Translate('General_LongDay_'.$dayOfWeek),
+ "%longYear%" => $this->toString('Y'),
+ "%shortYear%" => $this->toString('y'),
+ );
+ $out = str_replace(array_keys($patternToValue), array_values($patternToValue), $template);
+ return $out;
}
/**
diff --git a/core/FrontController.php b/core/FrontController.php
index bccd477520..8270f53212 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -235,6 +235,7 @@ class Piwik_FrontController
Piwik::createAccessObject();
require_once "CoreUpdater/Controller.php";
+ //TODO should not be a controller!
$updaterController = new Piwik_CoreUpdater_Controller();
$updaterController->checkForCoreAndPluginsUpdates();
diff --git a/core/Period.php b/core/Period.php
index 50201bf583..b5fbd33e0e 100644
--- a/core/Period.php
+++ b/core/Period.php
@@ -221,7 +221,8 @@ abstract class Piwik_Period
public function __toString()
{
- return $this->toString();
+ $elements = $this->toString();
+ return implode(",", $elements);
}
public function get( $part= null )
@@ -234,6 +235,7 @@ abstract class Piwik_Period
}
abstract public function getPrettyString();
+ abstract public function getLocalizedShortString();
}
diff --git a/core/Period/Day.php b/core/Period/Day.php
index e4597945de..55f158a796 100644
--- a/core/Period/Day.php
+++ b/core/Period/Day.php
@@ -7,12 +7,20 @@
class Piwik_Period_Day extends Piwik_Period
{
protected $label = 'day';
-
+
public function getPrettyString()
{
$out = $this->getDateStart()->toString() ;
return $out;
}
+ public function getLocalizedShortString()
+ {
+ //"Mon 15 Aug"
+ $date = $this->getDateStart();
+ $template = "%shortDay% %day% %shortMonth%";
+ $out = $date->getLocalized($template);
+ return $out;
+ }
public function isFinished()
{
@@ -37,4 +45,8 @@ class Piwik_Period_Day extends Piwik_Period
{
return $this->date->toString("Y-m-d");
}
+ public function __toString()
+ {
+ return $this->toString();
+ }
}
diff --git a/core/Period/Month.php b/core/Period/Month.php
index 57fd1d25c5..3d6e9f9d77 100644
--- a/core/Period/Month.php
+++ b/core/Period/Month.php
@@ -7,6 +7,13 @@ class Piwik_Period_Month extends Piwik_Period
{
protected $label = 'month';
+ public function getLocalizedShortString()
+ {
+ //"Aug 09"
+ $out = $this->getDateStart()->getLocalized("%shortMonth% %shortYear%");
+ return $out;
+ }
+
public function getPrettyString()
{
$out = $this->getDateStart()->toString('Y-m');
diff --git a/core/Period/Range.php b/core/Period/Range.php
index d3cdc1982a..dea4ed73ad 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -12,7 +12,17 @@ class Piwik_Period_Range extends Piwik_Period
$this->strDate = $strDate;
$this->defaultEndDate = null;
}
-
+ public function getLocalizedShortString()
+ {
+ //"30 Dec 08 - 26 Feb 09"
+ $dateStart = $this->getDateStart();
+ $dateEnd = $this->getDateEnd();
+ $template = "%day% %shortMonth% %shortYear%";
+ $shortDateStart = $dateStart->getLocalized($template);
+ $shortDateEnd = $dateEnd->getLocalized($template);
+ $out = "$shortDateStart - $shortDateEnd";
+ return $out;
+ }
public function getPrettyString()
{
$out = "From ".$this->getDateStart()->toString() . " to " . $this->getDateEnd()->toString();
diff --git a/core/Period/Week.php b/core/Period/Week.php
index f24002c878..f0c682241a 100644
--- a/core/Period/Week.php
+++ b/core/Period/Week.php
@@ -7,6 +7,17 @@
class Piwik_Period_Week extends Piwik_Period
{
protected $label = 'week';
+
+ public function getLocalizedShortString()
+ {
+ //"Week 30 Dec - 6 Jan 09"
+ $dateStart = $this->getDateStart();
+ $dateEnd = $this->getDateEnd();
+ $shortDateStart = $dateStart->getLocalized("%day% %shortMonth%");
+ $shortDateEnd = $dateEnd->getLocalized("%day% %shortMonth% %shortYear%");
+ $out = "$shortDateStart - $shortDateEnd";
+ return $out;
+ }
public function getPrettyString()
{
diff --git a/core/Period/Year.php b/core/Period/Year.php
index 5ff4f083a7..c916e5ca7a 100644
--- a/core/Period/Year.php
+++ b/core/Period/Year.php
@@ -9,6 +9,13 @@ class Piwik_Period_Year extends Piwik_Period
{
protected $label = 'year';
+ public function getLocalizedShortString()
+ {
+ //"2009"
+ $out = $this->getDateStart()->getLocalized("%longYear%");
+ return $out;
+ }
+
public function getPrettyString()
{
$out = $this->getDateStart()->toString('Y');
diff --git a/core/Piwik.php b/core/Piwik.php
index ae7360c375..8f928ccf3f 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -407,6 +407,15 @@ class Piwik
return sprintf("$symbol%.2f", $value);
}
+ static public function getPercentageSafe($dividend, $divisor, $precision = 0)
+ {
+ if($divisor == 0)
+ {
+ return 0;
+ }
+ return round(100 * $dividend / $divisor, $precision);
+ }
+
static public function getPrettyTimeFromSeconds($numberOfSeconds)
{
$numberOfSeconds = (double)$numberOfSeconds;
diff --git a/core/PluginsFunctions/WidgetsList.php b/core/PluginsFunctions/WidgetsList.php
index d06f8e8aef..e8339543f7 100644
--- a/core/PluginsFunctions/WidgetsList.php
+++ b/core/PluginsFunctions/WidgetsList.php
@@ -4,9 +4,9 @@ function Piwik_GetWidgetsList()
return Piwik_WidgetsList::get();
}
-function Piwik_AddWidget( $pluginName, $controllerMethodToCall, $widgetTitle )
+function Piwik_AddWidget( $widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters = array())
{
- Piwik_WidgetsList::add($pluginName, $controllerMethodToCall, $widgetTitle);
+ Piwik_WidgetsList::add($widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters);
}
class Piwik_WidgetsList
@@ -19,8 +19,17 @@ class Piwik_WidgetsList
return self::$widgets;
}
- static function add($pluginName, $controllerMethodToCall, $widgetTitle)
+ static function add($widgetCategory, $widgetName, $controllerName, $controllerAction, $customParameters)
{
- self::$widgets[$pluginName][] = array( $widgetTitle, $controllerMethodToCall );
+ $widgetCategory = Piwik_Translate($widgetCategory);
+ $widgetName = Piwik_Translate($widgetName);
+ $widgetUniqueId = 'widget' . $controllerName . $controllerAction;
+ self::$widgets[$widgetCategory][] = array(
+ 'name' => $widgetName,
+ 'uniqueId' => $widgetUniqueId,
+ 'parameters' => array ( 'module' => $controllerName,
+ 'action' => $controllerAction
+ ) + $customParameters
+ );
}
}
diff --git a/core/Site.php b/core/Site.php
index eeb7ef68c0..4b04df8915 100644
--- a/core/Site.php
+++ b/core/Site.php
@@ -28,6 +28,11 @@ class Piwik_Site
}
}
+ function __toString()
+ {
+ return "site id=".$this->getId().", name=".$this->getName();
+ }
+
function getName()
{
return self::$infoSites[$this->id]['name'];
diff --git a/core/SmartyPlugins/function.loadJavascriptTranslations.php b/core/SmartyPlugins/function.loadJavascriptTranslations.php
index 64d218160b..bd1a7fc634 100644
--- a/core/SmartyPlugins/function.loadJavascriptTranslations.php
+++ b/core/SmartyPlugins/function.loadJavascriptTranslations.php
@@ -1,38 +1,24 @@
<?php
/**
- * inserts javascript translation array into the template from given plugins
- * must be called with 'plugins' argument which consists of space-separated module names (i.e. plugins)
- *
- *
- * Example (use in template):
+ * Load translation strings suffixed with _js for a given list of modules.
+ * This function needs to be called when you want to i18n the user interface.
*
+ * How to use the function in smarty templates:
* {loadJavascriptTranslations plugins='SitesManager CoreHome General'}
*
- * loads javascript array translations from main translation file ('General')
- * and both 'CoreHome' and 'SitesManager' plugins translations
- *
- * Note: You can put noHtml=1 option in order to output pure JS code
- *
- * only translations with '_fs' suffix will be loaded
+ * This will load the javascript translations array for the modules specified as parameters.
+ * Only translations string with their ids suffixed with '_js' will be loaded
+ * Note: You can specify disableOutputScriptTag=1 and the returned value won't be enclosed in Javascript tags.
*
- * in order to use translation in your javascript use _pk_translate function
- * (it is always loaded with translations):
+ * You can then translate strings in javascript by calling the javascript function:
+ * _pk_translate('MY_TRANSLATION_STRING_js')
*
- * <script type="text/javascript">
- * alert(_pk_translate('MY_TRANSLATION_STRING'))
- * </script>
- *
- * Note: Use translation string from your translation file WITHOUT '_js' suffix.
- *
- * _pk_translate DOES NOT support printf() arguments, but you can call:
- *
- * sprintf(_pk_translate('_NB_OF_EGGS'),'ten')
- * (where _NB_OF_EGGS is defined in translation file as i.e. 'There is %s eggs on the table')
- *
- * sprintf() function is by default included when loading translations
+ * _pk_translate does NOT support printf() arguments, but you can call:
+ * sprintf(_pk_translate('MyPlugin_numberOfEggs_js'),'ten')
+ * where you would have the following in your translation file plugins/MyPlugin/lang/en.php:
+ * 'MyPlugin_numberOfEggs_js' => 'There are %s eggs.'
*/
-
function smarty_function_loadJavascriptTranslations($params, &$smarty)
{
static $pluginTranslationsAlreadyLoaded = array();
@@ -45,12 +31,9 @@ function smarty_function_loadJavascriptTranslations($params, &$smarty)
return;
}
$pluginTranslationsAlreadyLoaded[] = $params['plugins'];
- $translate = Piwik_Translate::getInstance();
- $jsTranslations = $translate->getJavascriptTranslations(explode(' ',$params['plugins']));
-
- $jsCode = "";
-
- if( isset($params['noHtml']) )
+ $jsTranslations = Piwik_Translate::getInstance()->getJavascriptTranslations(explode(' ',$params['plugins']));
+ $jsCode = '';
+ if( isset($params['disableOutputScriptTag']) )
{
$jsCode .= $jsTranslations;
}
@@ -60,6 +43,5 @@ function smarty_function_loadJavascriptTranslations($params, &$smarty)
$jsCode .= $jsTranslations;
$jsCode .= '</script>';
}
-
return $jsCode;
}
diff --git a/core/Translate.php b/core/Translate.php
index 48b53029c6..3917bca56f 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -113,24 +113,17 @@ class Piwik_Translate
foreach($GLOBALS['Piwik_translations'] as $key => $value)
{
- $matches = array();
-
- if( preg_match($moduleRegex,$key,$matches) ) {
- $varName = $matches[1].'_'.$matches[2];
- $varValue = $value;
-
- $js .= "".$varName.": '".str_replace("'","\\'",$varValue)."',";
+ if( preg_match($moduleRegex,$key) ) {
+ $js .= '"'.$key.'": "'.str_replace('"','\"',$value).'",';
}
-
- $matches = null;
}
$js = substr($js,0,-1);
$js .= '};';
$js .= 'if(typeof(piwik_translations) == \'undefined\') { var piwik_translations = new Object; }'.
'for(var i in translations) { piwik_translations[i] = translations[i];} ';
- $js .= 'function _pk_translate(tvar, str) { '.
- 'var s = str; if( typeof(piwik_translations[tvar]) != \'undefined\' ){ s = piwik_translations[tvar]; }'.
- 'return s;}';
+ $js .= 'function _pk_translate(translationStringId) { '.
+ 'if( typeof(piwik_translations[translationStringId]) != \'undefined\' ){ return piwik_translations[translationStringId]; }'.
+ 'return "The string "+translationStringId+" was not loaded in javascript. Make sure it is prefixed with _js";}';
return $js;
}
@@ -175,5 +168,3 @@ function Piwik_TranslateException($message, $args = array())
return $message;
}
}
-
-
diff --git a/core/Url.php b/core/Url.php
index e0e221e06f..27b57310ec 100644
--- a/core/Url.php
+++ b/core/Url.php
@@ -174,6 +174,10 @@ class Piwik_Url
$query = '';
foreach($urlValues as $name => $value)
{
+ if(empty($value))
+ {
+ continue;
+ }
if(is_array($value))
{
foreach($value as $theValue)
diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php
index 9854c2b081..c30cb185d6 100644
--- a/core/ViewDataTable.php
+++ b/core/ViewDataTable.php
@@ -110,6 +110,13 @@ abstract class Piwik_ViewDataTable
protected $view = null;
/**
+ * Array of columns names translations
+ *
+ * @var array
+ */
+ protected $columnsTranslations = array();
+
+ /**
* Method to be implemented by the ViewDataTable_*.
* This method should create and initialize a $this->view object @see Piwik_iView
* @return mixed either prints the result or returns the output string
@@ -755,6 +762,45 @@ abstract class Piwik_ViewDataTable
$this->variablesDefault['filter_sort_order'] = $order;
}
+
+ /**
+ * Sets translation string for given column
+ *
+ * @param string $columnName column name
+ * @param string $columnTranslation column name translation
+ */
+ public function setColumnTranslation( $columnName, $columnTranslation )
+ {
+ $this->columnsTranslations[$columnName] = $columnTranslation;
+ }
+
+ /**
+ * Returns column translation if available, in other case given column name
+ *
+ * @param string $columnName column name
+ */
+ public function getColumnTranslation( $columnName )
+ {
+ if( isset($this->columnsTranslations[$columnName]) )
+ {
+ return $this->columnsTranslations[$columnName];
+ }
+ else
+ {
+ return $columnName;
+ }
+ }
+
+ /**
+ * Sets columns translations array.
+ *
+ * @param array $columnsTranslations An associative array indexed by column names, eg. array('nb_visit'=>"Numer of visits")
+ */
+ public function setColumnsTranslations( $columnsTranslations )
+ {
+ $this->columnsTranslations += $columnsTranslations;
+ }
+
/**
* Sets a custom parameter, that will be printed in the javascript array associated with each datatable
*
diff --git a/core/ViewDataTable/GenerateGraphData.php b/core/ViewDataTable/GenerateGraphData.php
index c041ed75ed..bf5285cca9 100644
--- a/core/ViewDataTable/GenerateGraphData.php
+++ b/core/ViewDataTable/GenerateGraphData.php
@@ -37,13 +37,25 @@ abstract class Piwik_ViewDataTable_GenerateGraphData extends Piwik_ViewDataTable
*/
protected $graphLimit = null;
+ protected $columnsToDisplay = array();
+
+ public function setColumnsToDisplay($columns)
+ {
+ $this->columnsToDisplay = $columns;
+ }
+
+ public function getColumnsToDisplay()
+ {
+ return $this->columnsToDisplay;
+ }
+
/**
* Sets the number max of elements to display (number of pie slice, vertical bars, etc.)
* If the data has more elements than $limit then the last part of the data will be the sum of all the remaining data.
*
* @param int $limit
*/
- function setGraphLimit( $limit )
+ public function setGraphLimit( $limit )
{
$this->graphLimit = $limit;
}
@@ -57,7 +69,7 @@ abstract class Piwik_ViewDataTable_GenerateGraphData extends Piwik_ViewDataTable
{
return $this->graphLimit;
}
-
+
public function main()
{
if($this->mainAlreadyExecuted)
@@ -82,52 +94,41 @@ abstract class Piwik_ViewDataTable_GenerateGraphData extends Piwik_ViewDataTable
)
);
}
- $this->dataAvailable = $this->dataTable->getRowsCount() != 0;
-
- if(!$this->dataAvailable)
+ $this->isDataAvailable = $this->dataTable->getRowsCount() != 0;
+
+ if(!$this->isDataAvailable)
{
- $this->view->customizeGraph();
- $this->view->title(Piwik_Translate('General_NoDataForGraph'), '{font-size: 25px;}');
+ $this->view->setTitle(Piwik_Translate('General_NoDataForGraph'), '{font-size: 25px;}');
}
else
{
- $data = $this->generateDataFromDataTable();
- $this->view->setData($data);
- $this->view->customizeGraph();
+ $this->generateDataFromDataTable();
}
+ //TODO rename
+ $this->view->customizeGraph();
}
-
- /**
- * Returns a format friendly array from the dataTable
- *
- * @return array
- */
+
+ //TODO rename
protected function generateDataFromDataTable()
{
$this->dataTable->applyQueuedFilters();
+
// We apply a filter to the DataTable, decoding the label column (useful for keywords for example)
- $this->dataTable->filter('ColumnCallbackReplace',
- array('label','urldecode')
- );
- $data = array();
- foreach($this->dataTable->getRows() as $row)
+ $this->dataTable->filter('ColumnCallbackReplace', array('label','urldecode') );
+
+ $xLabels = $this->dataTable->getColumn('label');
+ $columnNames = array_keys($this->dataTable->getFirstRow()->getColumns());
+ unset($columnNames[array_search('label',$columnNames)]);
+
+ $columnNameToTranslation = $columnNameToValue = array();
+ foreach($columnNames as $columnName)
{
- $label = $row->getColumn('label');
- $value = $row->getColumn('nb_uniq_visitors');
-
- // case no unique visitors
- if($value === false)
- {
- $value = $row->getColumn('nb_visits');
- }
-
- $data[] = array(
- 'label' => $label,
- 'value' => $value,
- 'url' => $row->getMetadata('url'),
- );
+ $columnNameToTranslation[$columnName] = $this->getColumnTranslation($columnName);
+ $columnNameToValue[$columnName] = $this->dataTable->getColumn($columnName);
}
- return $data;
+ $this->view->setAxisXLabels($xLabels);
+ $this->view->setAxisYValues($columnNameToValue);
+ $this->view->setAxisYLabels($columnNameToTranslation);
}
}
diff --git a/core/ViewDataTable/GenerateGraphData/ChartEvolution.php b/core/ViewDataTable/GenerateGraphData/ChartEvolution.php
index 0dd6c56468..30ee37fd1f 100644
--- a/core/ViewDataTable/GenerateGraphData/ChartEvolution.php
+++ b/core/ViewDataTable/GenerateGraphData/ChartEvolution.php
@@ -12,196 +12,133 @@ class Piwik_ViewDataTable_GenerateGraphData_ChartEvolution extends Piwik_ViewDat
{
return 'generateDataChartEvolution';
}
+
function __construct()
{
require_once "Visualization/Chart/Evolution.php";
$this->view = new Piwik_Visualization_Chart_Evolution;
}
- var $lineLabels = array();
- var $data = array();
-
- private function generateLine( $dataArray, $columns, $schema = "##label## ##column##" )
+ protected function generateDataFromDataTable()
{
- $data = array();
- foreach($dataArray as $keyName => $table)
+ $this->dataTable->applyQueuedFilters();
+ if(!($this->dataTable instanceof Piwik_DataTable_Array))
{
- $table->applyQueuedFilters();
- // initialize data (default values for all lines is 0)
- $dataRow = array();
- $rows = $table->getRows();
- foreach($rows as $row)
- {
- $rowLabel = $schema;
- if( strpos($rowLabel, "##label##") !== false )
- {
- $rowLabel = str_replace("##label##", $row->getColumn('label'), $rowLabel);
- }
- foreach($columns as $col)
- {
- $label = $rowLabel;
- if( strpos($label, "##column##") !== false )
- {
- $label = str_replace("##column##", $col, $label);
- }
- if( !isset($this->lineLabels[$label]) )
- {
- $this->lineLabels[$label] = count($this->lineLabels);
- }
- $lineNb = $this->lineLabels[$label];
-
- $value = $row->getColumn($col);
-
- $dataRow['value'.$lineNb] = $value;
- }
- }
- $data[] = $dataRow;
+ throw new Exception("Expecting a DataTable_Array with custom format to draw an evolution chart");
}
- return $data;
- }
-
- private function generateLabels( $dataArray )
- {
- $data = array();
-
- foreach($dataArray as $keyName => $table)
+ $xLabels = $uniqueIdsDataTable = array();
+ foreach($this->dataTable->metadata as $idDataTable => $metadataDataTable)
{
- $table->applyQueuedFilters();
-
- $data[] = array('label' => $keyName);
+ $xLabels[] = $metadataDataTable['period']->getLocalizedShortString();
+ $uniqueIdsDataTable[] = $idDataTable;
}
- return $data;
- }
-
- private function addArray( &$data, $newData )
- {
- for($i = 0; $i < count($newData); $i++)
+ // list of column names requested to be plotted, we only need to forward these to the Graph object
+ $columnNameRequested = $this->getColumnsToDisplay();
+
+ $columnNameToValue = array();
+ foreach($this->dataTable->getArray() as $idDataTable => $dataTable)
{
- foreach($newData[$i] as $key => $value)
+ if($dataTable->getRowsCount() > 1)
{
- $data[$i][$key] = $value;
+ throw new Exception("Expecting only one row per DataTable");
}
- }
- }
-
- private function fillValues( &$data )
- {
- $nbLines = count($this->lineLabels);
-
- for($i = 0; $i < count($data); $i++)
- {
- for($j = 0; $j < $nbLines; $j++)
+ $row = $dataTable->getFirstRow();
+ if($row !== false)
{
- if( !isset($data[$i]['value'.$j]) )
+ foreach($row->getColumns() as $columnName => $columnValue)
{
- $data[$i]['value'.$j] = 0;
+ if(array_search($columnName, $columnNameRequested) !== false)
+ {
+ $columnNameToValue[$columnName][$idDataTable] = $columnValue;
+ }
}
}
}
- }
-
- /*
- * generates data for evolution graph from a numeric DataTable (DataTable that has only 'label' and 'value' columns)
- */
- protected function generateDataFromNumericDataTable($dataArray, $siteLabel = "")
- {
- $columnsToDisplay = Piwik_Common::getRequestVar('columns', array(), 'array');
-
- // for numeric we want to have only one column name
- if( count($columnsToDisplay) != 1 )
- {
- $columnsToDisplay = array( 'nb_visits' );
- }
- $label = $siteLabel . array_shift($columnsToDisplay);
- $this->addArray($this->data, $this->generateLabels($dataArray));
- $this->addArray($this->data, $this->generateLine($dataArray,array('value'),$label));
- $this->fillValues($this->data);
- }
-
- /*
- * generates data for evolution graph from a DataTable that has named columns (i.e. 'nb_hits', 'nb_visits')
- */
- protected function generateDataFromRegularDataTable($dataArray, $siteLabel = "")
- {
- // get list of columns to display i.e. array('nb_hits','nb_visits')
- $columnsToDisplay = Piwik_Common::getRequestVar('columns', array(), 'array');
-
- // default column
- if( count($columnsToDisplay) == 0 )
+ // make sure all column values are set (at least zero) in order for all unique idDataTable
+ $columnNameToValueCleaned = array();
+ foreach($uniqueIdsDataTable as $uniqueIdDataTable)
{
- $columnsToDisplay = array( 'nb_visits' );
- }
-
- $this->addArray($this->data, $this->generateLabels($dataArray));
- $this->addArray($this->data, $this->generateLine($dataArray, $columnsToDisplay, $siteLabel."##label## ##column##"));
- $this->fillValues($this->data);
- }
-
- protected function handleSiteGenerateDataFromDataTable($dataArray, $siteLabel = "")
- {
- // detect if we got numeric Datatable or regular DataTable
- foreach($dataArray as $table)
- {
- $row = $table->getFirstRow();
-
- if( $row != null )
+ foreach($columnNameToValue as $columnName => $idDataTableToColumnValue)
{
- $columns = $row->getColumns();
-
- // if we got 2 columns - 'label' and 'value' this is numeric DataTable
- if( count($columns) == 2 && isset($columns['label']) && isset($columns['value']) )
+ if(isset($idDataTableToColumnValue[$uniqueIdDataTable]))
{
- $this->generateDataFromNumericDataTable($dataArray, $siteLabel);
+ $columnValue = $idDataTableToColumnValue[$uniqueIdDataTable];
}
else
{
- $this->generateDataFromRegularDataTable($dataArray, $siteLabel);
+ $columnValue = 0;
}
- break;
+ $columnNameToValueCleaned[$columnName][] = $columnValue;
}
}
- }
-
- public function generateDataFromDataTable()
- {
- $data = array();
-
- if( $this->dataTable->getRowsCount() )
+ $columnNames = array_keys($columnNameToValueCleaned);
+ $columnNameToTranslation = array();
+ $columnNameToType = array();
+ $nameToType = array(
+ '_rate' => '%',
+ '_revenue' => Piwik::getCurrency(),
+ );
+ foreach($columnNames as $columnName)
{
- $row = null;
-
- // find first table with rows
- foreach($this->dataTable->getArray() as $idsite => $table)
+ $columnNameToTranslation[$columnName] = $this->getColumnTranslation($columnName);
+ $columnNameToType[$columnName] = false;
+ foreach($nameToType as $pattern => $type)
{
- // detect if we got data from more than one site
- if( $table instanceof Piwik_DataTable_Array)
- {
- // multiple sites
- $site = new Piwik_Site($idsite);
-
- $this->handleSiteGenerateDataFromDataTable($table->getArray(), $site->getName()." ");
- }
- else if( $table instanceof Piwik_DataTable_Simple && $this->dataTable->getKeyName() == 'idSite')
- {
- // multiple sites (when numeric DataTable)
- $site = new Piwik_Site($idsite);
-
- $this->handleSiteGenerateDataFromDataTable($table->getFirstRow()->getColumn('value')->getArray(), $site->getName()." ");
- }
- else
+ if(strpos($columnName, $pattern) !== false)
{
- // single site
- $this->handleSiteGenerateDataFromDataTable($this->dataTable->getArray());
+ $columnNameToType[$columnName] = $type;
break;
- }
- }
+ }
+ }
+ }
+ $this->view->setAxisXLabels($xLabels);
+ $this->view->setAxisYValues($columnNameToValueCleaned);
+ $this->view->setAxisYLabels($columnNameToTranslation);
+ $this->view->setAxisYValuesTypes($columnNameToType);
+
+ $firstDatatable = reset($this->dataTable->metadata);
+ $period = $firstDatatable['period'];
+ switch($period->getLabel()) {
+ case 'day': $steps = 7; break;
+ case 'week': $steps = 10; break;
+ case 'month': $steps = 6; break;
+ case 'year': $steps = 2; break;
+ default: $steps = 10; break;
+ }
+ $this->view->setXSteps($steps);
+
+ if($this->isLinkEnabled())
+ {
+ $axisXOnClick = array();
+ foreach($this->dataTable->metadata as $idDataTable => $metadataDataTable)
+ {
+ $period = $metadataDataTable['period'];
+ $dateInUrl = $period->getDateStart();
+ $link = Piwik_Url::getCurrentUrlWithoutQueryString() .
+ Piwik_Url::getCurrentQueryStringWithParametersModified( array(
+ 'date' => $dateInUrl,
+ 'module' => 'CoreHome',
+ 'action' => 'index',
+ 'viewDataTable' => null, // we reset the viewDataTable parameter (useless in the link)
+ 'idGoal' => null, // we reset idGoal
+ 'columns' => null,
+ ));
+ $axisXOnClick[] = $link;
+ }
+ $this->view->setAxisXOnClick($axisXOnClick);
+ }
+ }
- }
- array_unshift($this->data, array_keys($this->lineLabels));
-
- return $this->data;
+ private function isLinkEnabled()
+ {
+ static $linkEnabled;
+ if(!isset($linkEnabled))
+ {
+ $linkEnabled = !Piwik_Common::getRequestVar('disableLink', 0, 'int');
+ }
+ return $linkEnabled;
}
}
diff --git a/core/ViewDataTable/GenerateGraphHTML.php b/core/ViewDataTable/GenerateGraphHTML.php
index 90ccfa54e7..0523531a82 100644
--- a/core/ViewDataTable/GenerateGraphHTML.php
+++ b/core/ViewDataTable/GenerateGraphHTML.php
@@ -127,7 +127,7 @@ abstract class Piwik_ViewDataTable_GenerateGraphHTML extends Piwik_ViewDataTable
$return .= '
</noscript></div></div>
<script type="text/javascript">
-swfobject.embedSWF("'.$pathToLibraryOpenChart.'open-flash-chart.swf", "'. $obj_id .'_swf", "'. $width . '", "' . $height . '", "9.0.0", false, {"data":"'.$url.'"}, {"allowScriptAccess":"sameDomain","wmode":"opaque"}, {"bgcolor":"#FFFFFF"});
+swfobject.embedSWF("'.$pathToLibraryOpenChart.'open-flash-chart.swf", "'. $obj_id .'_swf", "'. $width . '", "' . $height . '", "9.0.0", false, {"data-file":"'.$url.'"}, {"allowScriptAccess":"sameDomain","wmode":"opaque"}, {"bgcolor":"#FFFFFF"});
</script>';
}
diff --git a/core/ViewDataTable/HtmlTable.php b/core/ViewDataTable/HtmlTable.php
index 7eb9e5160e..ac6d56ca44 100644
--- a/core/ViewDataTable/HtmlTable.php
+++ b/core/ViewDataTable/HtmlTable.php
@@ -25,13 +25,6 @@ class Piwik_ViewDataTable_HtmlTable extends Piwik_ViewDataTable
* @var array
*/
protected $columnsToDisplay = array();
-
- /**
- * Array of columns names translations
- *
- * @var array
- */
- protected $columnsTranslations = array();
/**
* Set to true when the DataTable must be loaded along with all its children subtables
@@ -63,11 +56,6 @@ class Piwik_ViewDataTable_HtmlTable extends Piwik_ViewDataTable
$this->dataTableTemplate = 'CoreHome/templates/datatable.tpl';
$this->variablesDefault['enable_sort'] = '1';
- // load general columns translations
- $this->setColumnTranslation('nb_visits', Piwik_Translate('General_ColumnNbVisits'));
- $this->setColumnTranslation('label', Piwik_Translate('General_ColumnLabel'));
- $this->setColumnTranslation('nb_uniq_visitors', Piwik_Translate('General_ColumnNbUniqVisitors'));
-
$this->handleLowPopulation();
}
@@ -175,44 +163,6 @@ class Piwik_ViewDataTable_HtmlTable extends Piwik_ViewDataTable
}
/**
- * Sets translation string for given column
- *
- * @param string $columnName column name
- * @param string $columnTranslation column name translation
- */
- public function setColumnTranslation( $columnName, $columnTranslation )
- {
- $this->columnsTranslations[$columnName] = $columnTranslation;
- }
-
- /**
- * Returns column translation if available, in other case given column name
- *
- * @param string $columnName column name
- */
- public function getColumnTranslation( $columnName )
- {
- if( isset($this->columnsTranslations[$columnName]) )
- {
- return $this->columnsTranslations[$columnName];
- }
- else
- {
- return $columnName;
- }
- }
-
- /**
- * Sets columns translations array.
- *
- * @param array $columnsTranslations An associative array indexed by column names, eg. array('nb_visit'=>"Numer of visits")
- */
- public function setColumnsTranslations( $columnsTranslations )
- {
- $this->columnsTranslations = $columnsTranslations;
- }
-
- /**
* Returns array(
* array('name' => 'nb_visits', 'displayName' => 'Visits'),
* array('name' => 'nb_uniq_visitors', 'displayName' => 'Unique Visitors'),
@@ -281,6 +231,7 @@ class Piwik_ViewDataTable_HtmlTable extends Piwik_ViewDataTable
}
return $requestString;
}
+
/**
* Set the flag to load the datatable recursively so we can search on subtables as well
*
diff --git a/core/ViewDataTable/HtmlTable/AllColumns.php b/core/ViewDataTable/HtmlTable/AllColumns.php
index 786763abf1..2efdfbf129 100644
--- a/core/ViewDataTable/HtmlTable/AllColumns.php
+++ b/core/ViewDataTable/HtmlTable/AllColumns.php
@@ -37,8 +37,5 @@ class Piwik_ViewDataTable_HtmlTable_AllColumns extends Piwik_ViewDataTable_HtmlT
'bounce_rate'));
$this->dataTable->filter('ColumnCallbackReplace', array('avg_time_on_site', create_function('$averageTimeOnSite', 'return Piwik::getPrettyTimeFromSeconds($averageTimeOnSite);')));
$this->dataTable->filter('ColumnCallbackReplace', array('bounce_rate', create_function('$bounceRate', 'return $bounceRate."%";')));
- $this->setColumnTranslation('nb_actions_per_visit', Piwik_Translate('General_ColumnActionsPerVisit'));
- $this->setColumnTranslation('avg_time_on_site', Piwik_Translate('General_ColumnAvgTimeOnSite'));
- $this->setColumnTranslation('bounce_rate', Piwik_Translate('General_ColumnBounceRate'));
}
}
diff --git a/core/ViewDataTable/HtmlTable/Goals.php b/core/ViewDataTable/HtmlTable/Goals.php
index 1bc961940e..6f4f46ad65 100644
--- a/core/ViewDataTable/HtmlTable/Goals.php
+++ b/core/ViewDataTable/HtmlTable/Goals.php
@@ -70,8 +70,6 @@ class Piwik_ViewDataTable_HtmlTable_Goals extends Piwik_ViewDataTable_HtmlTable
protected function postDataTableLoadedFromAPI()
{
parent::postDataTableLoadedFromAPI();
- $this->setColumnTranslation('revenue_per_visit', 'Value per Visit');
- $this->setColumnTranslation('goals_conversion_rate', 'Visits with Conversions');
$this->columnsToPercentageFilter[] = 'goals_conversion_rate';
foreach($this->columnsToPercentageFilter as $columnName)
{
diff --git a/core/ViewDataTable/Sparkline.php b/core/ViewDataTable/Sparkline.php
index 8b694468ee..1982cba555 100644
--- a/core/ViewDataTable/Sparkline.php
+++ b/core/ViewDataTable/Sparkline.php
@@ -22,6 +22,18 @@ class Piwik_ViewDataTable_Sparkline extends Piwik_ViewDataTable
{
return 'sparkline';
}
+
+ protected $columnsToDisplay = array();
+
+ public function setColumnsToDisplay($columns)
+ {
+ $this->columnsToDisplay = $columns;
+ }
+
+ public function getColumnsToDisplay()
+ {
+ return $this->columnsToDisplay;
+ }
/**
* @see Piwik_ViewDataTable::main()
@@ -37,82 +49,55 @@ class Piwik_ViewDataTable_Sparkline extends Piwik_ViewDataTable
// we load the data with the filters applied
$this->loadDataTableFromAPI();
- $this->dataAvailable = $this->dataTable->getRowsCount() != 0;
- if(!$this->dataAvailable)
+ $this->isDataAvailable = $this->dataTable->getRowsCount() != 0;
+ if(!$this->isDataAvailable)
{
throw new Exception(Piwik_Translate('General_NoDataForGraph'));
}
- $data = $this->generateDataFromDataTableArray($this->dataTable);
+ $values = $this->getValuesFromDataTable($this->dataTable);
$graph = new Piwik_Visualization_Sparkline;
- $graph->setData($data);
+ $graph->setValues($values);
$graph->main();
$this->view = $graph;
}
- /**
- * Given a Piwik_DataTable_Array made of DataTable_Simple rows, returns a php array with the structure:
- * array(
- * array( label => X, value => Y),
- * array( label => A, value => B),
- * ...
- * )
- *
- * This is used for example for the evolution graph (last 30 days visits) or the sparklines.
- *
- * @param Piwik_DataTable_Array $dataTableArray
- * @return array
- */
- protected function generateDataFromDataTableArray( Piwik_DataTable_Array $dataTableArray)
+ protected function getValuesFromDataTable( Piwik_DataTable_Array $dataTableArray)
{
- $data = array();
+ $dataTableArray->applyQueuedFilters();
+
+ $columns = $this->getColumnsToDisplay();
+ $columnToPlot = false;
+ if(!empty($columns))
+ {
+ $columnToPlot = $columns[0];
+ }
+ $values = array();
foreach($dataTableArray->getArray() as $keyName => $table)
{
- if($table instanceof Piwik_DataTable_Array)
+ $value = 0;
+ if($table->getRowsCount() > 1)
{
- throw new Exception("Operation not supported (yet)");
+ throw new Exception("Expecting only one row per DataTable");
}
- $value = false;
-
$onlyRow = $table->getFirstRow();
if($onlyRow !== false)
{
- $value = $onlyRow->getColumn('value');
- if($value == false)
+ if(!empty($columnToPlot))
{
- // TEMP
- // quite a hack, useful in the case at this point we do have a normal row with nb_visits, nb_actions, nb_uniq_visitors, etc.
- // instead of the dataTable_Simple row (label, value)
- // to do it properly we'd need to
- // - create a filter that removes columns
- // - apply this filter to keep only the column called nb_uniq_visitors
- // - rename this column as 'value'
- // and at this point the getcolumn('value') would have worked
- // this code is executed eg. when displaying a sparkline for the last 30 days displaying the number of unique visitors coming from search engines
-
- //TODO solution: use a filter rename column etc.
-
- // another solution would be to add a method to the Referers API giving directly the integer 'visits from search engines'
- // and we would build automatically the dataTable_array of datatatble_simple from these integers
- // but we'd have to add this integer to be recorded during archiving etc.
- $value = $onlyRow->getColumn('nb_uniq_visitors');
- if($value === false)
- {
- $value = $onlyRow->getColumn('nb_visits');
- }
+ $value = $onlyRow->getColumn($columnToPlot);
+ }
+ // if not specified, we load by default the first column found
+ // eg. case of getLastDistinctCountriesGraph
+ else
+ {
+ $columns = $onlyRow->getColumns();
+ $value = current($columns);
}
}
-
- if($value === false)
- {
- $value = 0;
- }
- $data[] = array(
- 'label' => $keyName,
- 'value' => $value
- );
+ $values[] = $value;
}
- return $data;
+ return $values;
}
}
diff --git a/core/Visualization/Chart.php b/core/Visualization/Chart.php
index c86e80a933..2f12137255 100644
--- a/core/Visualization/Chart.php
+++ b/core/Visualization/Chart.php
@@ -9,78 +9,160 @@
* @package Piwik_Visualization
*/
-require_once "Visualization/OpenFlashChart.php";
+require_once "libs/open-flash-chart/php-ofc-library/open-flash-chart.php";
+
/**
* Generates the data in the Open Flash Chart format, from the given data.
- * Uses Open flash chart PHP library @see Piwik_Visualization_OpenFlashChart
*
* @package Piwik_Visualization
*/
-abstract class Piwik_Visualization_Chart extends Piwik_Visualization_OpenFlashChart
+abstract class Piwik_Visualization_Chart implements Piwik_iView
{
- protected $dataGraph = array();
+ /**
+ * @var Piwik_Visualization_OpenFlashChart
+ */
+ protected $chart = null;
+
+ protected $xLabels = array();
+ protected $xOnClick = array();
+ protected $xSteps = 2;
+
+ protected $yLabels = array();
+ protected $yValues = array();
- function setData($data)
+ function __construct()
{
- $this->dataGraph = $data;
+ $this->chart = new open_flash_chart();
}
- function getCount()
+ public function setAxisXLabels($xLabels)
{
- return count($this->dataGraph);
+ $this->xLabels = $xLabels;
}
- function customizeGraph()
+ public function setAxisYValues($values)
{
- $this->set_num_decimals ( 0 );
- $this->set_is_decimal_separator_comma( false );
- $this->set_is_thousand_separator_disabled( true );
- $this->y_axis_colour = '#ffffff';
- $this->x_axis_colour = '#596171';
- $this->x_grid_colour = $this->y_grid_colour = '#E0E1E4';
-
- // approx 5 x labels on the graph
- $steps = ceil($this->getCount() / 5);
- $steps = $steps + $steps % 2; // make sure modulo 2
-
- $this->set_x_label_style( 10, $this->x_axis_colour, 0, $steps, $this->x_grid_colour );
- $this->set_x_axis_steps( $steps / 2 );
-
-
- $stepsY = ceil($this->getCount() / 4);
- $this->y_label_steps( $stepsY / 3 );
- $this->y_label_steps( 4 );
-
- $this->bg_colour = '#ffffff';
- $this->set_inner_background('#ffffff');
-
- $this->set_tool_tip( '#x_label# <br>#val# #key# ' );
+ $this->yValues = $values;
+ }
+
+ public function setAxisYLabels($labels)
+ {
+ $this->yLabels = $labels;
+ }
+
+ public function setAxisXOnClick($onClick)
+ {
+ $this->xOnClick = $onClick;
+ }
+
+ //TODO call + make sure matches beginning of period? (hard..)
+ // day -> every 7 days
+ // week & year -> 1, plot last
+ // month -> every 12 months, plot last 24
+ public function setXSteps($steps)
+ {
+ $this->xSteps = $steps;
+ }
+
+ protected function getDataSetsToDisplay()
+ {
+ if(empty($this->yValues)) {
+ return false;
+ }
+ return array_keys($this->yValues);
}
- function prepareData()
- {
- $label = $data = array();
- $max = 0;
- foreach($this->dataGraph as $row)
+ public function getMaxValue()
+ {
+ $datasetsIds = $this->getDataSetsToDisplay();
+ if($datasetsIds === false)
+ {
+ return 0;
+ }
+ $maxCrossDataSets = false;
+ foreach($datasetsIds as $dataset)
{
- $label[] = $row['label'];
- $data[] = $row['value'];
-
- if($row['value'] > $max)
+ $maxValue = max($this->yValues[$dataset]);
+ if($maxCrossDataSets === false
+ || $maxValue > $maxCrossDataSets)
{
- $max = $row['value'];
+ $maxCrossDataSets = $maxValue;
}
}
- $this->arrayData = $data;
- $this->arrayLabel = $label;
+ if($maxCrossDataSets > 10)
+ {
+ $maxCrossDataSets = $maxCrossDataSets + 10 - $maxCrossDataSets % 10;
+ }
+ return $maxCrossDataSets;
+ }
+
+ public function setTitle($text, $css)
+ {
+ $title = new title($text);
+ $title->set_style($css);
+ $this->chart->set_title($title);
+ }
+
+ public function render()
+ {
+ return $this->chart->toPrettyString();
+ }
+
+ function customizeGraph()
+ {
+ $this->chart->set_number_format($num_decimals = 0,
+ $is_fixed_num_decimals_forced = true,
+ $is_decimal_separator_comma = false,
+ $is_thousand_separator_disabled = false);
+
+ $gridColour = '#E0E1E4';
+ $countValues = count($this->xLabels);
+ $maxValue = $this->getMaxValue();
+ $minValue = 0;
- $this->arrayLabel = str_replace(","," -",$this->arrayLabel);
+ // X Axis
+ $this->x = new x_axis();
+ $this->x->set_colour( '#596171' );
+ $this->x->set_grid_colour( $gridColour );
+ $this->x->set_steps($this->xSteps);
- $this->maxData = $max;
- if($this->maxData > 10)
+ // X Axis Labels
+ $this->x_labels = new x_axis_labels();
+ $this->x_labels->set_size(11);
+ //manually fix the x labels step as this doesn't work in this OFC release..
+ $xLabelsStepped = $this->xLabels;
+ foreach($xLabelsStepped as $i => &$xLabel)
{
- $this->maxData = $max + 10 - $max % 10;
+ if(($i % $this->xSteps) != 0)
+ {
+ $xLabel = '';
+ }
}
+ $this->x_labels->set_labels($xLabelsStepped);
+ $this->x_labels->set_steps(2);
+ $this->x->set_labels($this->x_labels);
+
+ // Y Axis
+ $this->y = new y_axis();
+ $this->y->set_colour('#ffffff');
+ $this->y->set_grid_colour($gridColour);
+ $stepsCount = 2;
+ $stepsEveryNLabel = ceil(($maxValue - $minValue) / $stepsCount);
+ if($maxValue == 0)
+ {
+ $maxValue = 1;
+ }
+ $this->y->set_range( $minValue, $maxValue, $stepsEveryNLabel);
+
+ // Tooltip
+ $this->tooltip = new tooltip();
+ $this->tooltip->set_shadow( true );
+ $this->tooltip->set_stroke( 1 );
+
+ // Attach elements to the graph
+ $this->chart->set_x_axis($this->x);
+ $this->chart->set_y_axis($this->y);
+ $this->chart->set_tooltip($this->tooltip);
+ $this->chart->set_bg_colour('#ffffff');
}
-
}
diff --git a/core/Visualization/Chart/Evolution.php b/core/Visualization/Chart/Evolution.php
index 66005ca6a9..6cef02f6e0 100644
--- a/core/Visualization/Chart/Evolution.php
+++ b/core/Visualization/Chart/Evolution.php
@@ -16,94 +16,90 @@ require_once "Visualization/Chart.php";
*
* @package Piwik_Visualization
*/
-class Piwik_Visualization_Chart_Evolution extends Piwik_Visualization_Chart
+class Piwik_Visualization_Chart_Evolution extends Piwik_Visualization_Chart
{
+ protected $yValuesType = array();
+ function setAxisYValuesTypes($yValuesTypes)
+ {
+ $this->yValuesTypes = $yValuesTypes;
+ }
+
function customizeGraph()
{
parent::customizeGraph();
-
+ $dataSetsToDisplay = $this->getDataSetsToDisplay();
+ if($dataSetsToDisplay === false)
+ {
+ return;
+ }
+
$colors = array(
"0x3357A0",
- "0x9933CC",
"0xCC3399",
+ "0x9933CC",
"0x80a033",
"0xFD9816",
"0x246AD2",
"0xFD16EA",
"0x49C100",
- );
-
- // first row in array contains line labels (legend)
- $legendLabels = array_shift($this->dataGraph);
-
- $line = array();
-
- // define labels
- foreach($legendLabels as $nbLabel => $labelName)
- {
- $line[$nbLabel] = new line_hollow( 1, 3, $colors[$nbLabel] );
- $line[$nbLabel]->key( $labelName, 10 );
- }
-
- $maxData = 0;
- $xLabels = array();
- $cnt = count($this->dataGraph);
+ );
- // loop over data
- foreach($this->dataGraph as $values)
+ $i = 0;
+ foreach($dataSetsToDisplay as $dataSetToDisplay)
{
- // add x axis value (label)
- array_push($xLabels, $values['label']);
+ $color = $colors[$i];
+
+ $labelName = $this->yLabels[$dataSetToDisplay];
+ $d = new hollow_dot();
+ $d->size(3)->halo_size(0)->colour($color);
+
+ $line = new line();
+ $line->set_default_dot_style($d);
+ $line->set_key($labelName, 11);
+ $line->set_width( 1 );
+ $line->set_colour( $color );
- // loop over values for all lines (y axis values)
- for($j = 0; $j < count($legendLabels); $j++)
- {
- // get the y axis value for line $j
- $dotValue = $values['value'.$j];
+ // Line Values
+ // Note: we have to manually create the dot values as the steps feature doens't work on X axis
+ // when it's working again, we can remove code below and set generic tooltip above: // ->tooltip('#x_label#<br>#val# '.$labelName)
+ $yValues = $this->yValues[$dataSetToDisplay];
+ $labelName = $this->yLabels[$dataSetToDisplay];
+ $lineValues = array();
+ $j = 0;
+ foreach($this->xLabels as $label) {
+ $value = $yValues[$j];
+ $lineValue = new hollow_dot($value);
- // find maximum y axis value
- if( $dotValue > $maxData )
- {
- $maxData = $dotValue;
- }
-
- $link = null;
- if($this->isLinkEnabled())
+ $unit = '';
+ if(!empty($this->yValuesTypes[$dataSetToDisplay]))
{
- $spacePosition = strpos($values['label'],' ');
- if($spacePosition === false)
- {
- $spacePosition = strlen($values['label']);
- }
- $link = Piwik_Url::getCurrentScriptName() .
- Piwik_Url::getCurrentQueryStringWithParametersModified( array(
- 'date' => substr($values['label'],0,$spacePosition),
- 'module' => 'CoreHome',
- 'action' => 'index',
- 'viewDataTable' => null, // we reset the viewDataTable parameter (useless in the link)
- 'idGoal' => null, // we reset idGoal
- ));
- // add the dot on the chart and link it
- $line[$j]->add_link($dotValue, $link);
+ $unit = $this->yValuesTypes[$dataSetToDisplay];
}
- else
+ // set the Y Label to display the right unit
+ $this->y->set_label_text("#val#$unit");
+
+ $lineValue->tooltip("$label<br>$value$unit $labelName");
+ if(!empty($this->xOnClick))
{
- $line[$j]->add($dotValue);
+ $lineValue->on_click('redirectToUrl("'.$this->xOnClick[$j].'")');
}
+ $lineValues[] = $lineValue;
+ $j++;
}
+ $line->set_values( $lineValues );
+ $lines[] = $line;
+ $i++;
}
- $this->data_sets = $line;
- $this->set_y_max( $maxData );
- $this->set_x_labels( $xLabels );
- }
-
- private function isLinkEnabled()
- {
- static $linkEnabled;
- if(!isset($linkEnabled))
+ foreach($lines as $line)
+ {
+ $this->chart->add_element($line);
+ }
+ // if one column is a percentage we set the grid accordingly
+ // note: it is invalid to plot a percentage dataset along with a numeric dataset
+ //TODO only if the max was 100!!
+ if(array_search('%', $this->yValuesTypes) !== false)
{
- $linkEnabled = !Piwik_Common::getRequestVar('disableLink', 0, 'int');
+ $this->y->set_range( 0, 100, 50);
}
- return $linkEnabled;
}
}
diff --git a/core/Visualization/Chart/Pie.php b/core/Visualization/Chart/Pie.php
index 46b5aace60..8ea8e7e2ec 100644
--- a/core/Visualization/Chart/Pie.php
+++ b/core/Visualization/Chart/Pie.php
@@ -11,28 +11,61 @@
require_once "Visualization/Chart.php";
/**
- *
- * Customize the Pie chart style for the flash graph
+ * Customize & set values for the Flash Pie chart
*
* @package Piwik_Visualization
*/
class Piwik_Visualization_Chart_Pie extends Piwik_Visualization_Chart
{
+ // return the first dataset id from the list
+ protected function getDataSetsToDisplay()
+ {
+ $dataSetsToDisplay = parent::getDataSetsToDisplay();
+ if($dataSetsToDisplay === false)
+ {
+ return false;
+ }
+ return array_slice($dataSetsToDisplay, 0, 1);
+ }
+
function customizeGraph()
{
parent::customizeGraph();
- $this->prepareData();
-
- for($i = 0, $cnt = count($this->arrayLabel); $i < $cnt; $i++)
- {
- $label = $this->arrayLabel[$i];
- $this->arrayLabel[$i] = (strlen($label) > 20 ? substr($label, 0, 20).'...' : $label);
- }
- $this->set_x_label_style( 12, $this->x_axis_colour, 0, 2, $this->bg_colour );
- $this->pie(60,'#505050','{font-size: 12px; color: #142448}', true);
- $this->pie_values( $this->arrayData, $this->arrayLabel );
- $this->pie_slice_colours( array('#3C5A69','#679BB5','#695A3C','#B58E67','#969696') );
+ $dataSetsToDisplay = $this->getDataSetsToDisplay();
+ if($dataSetsToDisplay === false)
+ {
+ return;
+ }
+ $dataSetToDisplay = current($dataSetsToDisplay);
+
+ // create the Pie
+ $pie = new pie();
+ $pie->set_alpha(0.6);
+ $pie->set_start_angle( 35 );
+ $pie->add_animation( new pie_fade() );
+ $pie->set_label_colour('#142448');
+ $pie->set_colours( array('#3C5A69','#679BB5','#695A3C','#B58E67','#969696') );
+
+ // create the Pie values
+ $yValues = $this->yValues[$dataSetToDisplay];
+ $labelName = $this->yLabels[$dataSetToDisplay];
+ $sum = array_sum($yValues);
+ $pieValues = array();
+ $i = 0;
+ foreach($this->xLabels as $label) {
+ $value = $yValues[$i];
+ $i++;
+ // we never plot empty pie slices (eg. visits by server time pie chart)
+ if($value <= 0) {
+ continue;
+ }
+ $pieValue = new pie_value($value, $label);
+ $percentage = round(100 * $value / $sum);
+ $pieValue->set_tooltip("$label <br>$percentage% ($value $labelName)");
+ $pieValues[] = $pieValue;
+ }
+ $pie->set_values($pieValues);
- $this->set_tool_tip( '#x_label# <br>#val# ' );
+ $this->chart->add_element($pie);
}
}
diff --git a/core/Visualization/Chart/VerticalBar.php b/core/Visualization/Chart/VerticalBar.php
index d94272df9b..a87487bb51 100644
--- a/core/Visualization/Chart/VerticalBar.php
+++ b/core/Visualization/Chart/VerticalBar.php
@@ -12,25 +12,59 @@
require_once "Visualization/Chart.php";
/**
- *
- * Customize the Vertical bar chart style for the flash graph
+ * Customize & set values for the flash Vertical bar chart
*
* @package Piwik_Visualization
- *
*/
class Piwik_Visualization_Chart_VerticalBar extends Piwik_Visualization_Chart
{
+ // return the first dataset id from the list
+ protected function getDataSetsToDisplay()
+ {
+ $dataSetsToDisplay = parent::getDataSetsToDisplay();
+ if($dataSetsToDisplay === false)
+ {
+ return false;
+ }
+ return array_slice($dataSetsToDisplay, 0, 1);
+ }
+
function customizeGraph()
{
parent::customizeGraph();
- $this->prepareData();
- $this->set_data( $this->arrayData );
- $this->set_x_labels( $this->arrayLabel );
- $this->set_x_label_style( 12, $this->x_axis_colour, 0, 2, $this->bg_colour );
- $this->set_x_axis_steps( 2 );
- $this->set_y_max( $this->maxData );
- $this->y_label_steps( 2 );
- $this->bar_filled( 50, '#3B5AA9', '#063E7E', 'visits', 10 );
+ $dataSetsToDisplay = $this->getDataSetsToDisplay();
+ if($dataSetsToDisplay === false)
+ {
+ return;
+ }
+ $dataSetToDisplay = current($dataSetsToDisplay);
+
+ $this->x->set_grid_colour('#ffffff');
+ $this->x_labels->set_steps(2);
+ $this->x->set_stroke(1);
+
+ // create the Bar object
+ $bar = new bar_filled('#3B5AA9', '#063E7E');
+ $bar->set_alpha(0.5);
+ $bar->set_key($this->yLabels[$dataSetToDisplay], 12);
+ $bar->set_tooltip( '#val# #key#');
+
+ // create the bar values
+ $yValues = $this->yValues[$dataSetToDisplay];
+ $labelName = $this->yLabels[$dataSetToDisplay];
+ $sum = array_sum($yValues);
+ $barValues = array();
+ $i = 0;
+ foreach($this->xLabels as $label) {
+ $value = $yValues[$i];
+ $barValue = new bar_value($value);
+ $percentage = round(100 * $value / $sum);
+ $barValue->set_tooltip("$label <br>$value $labelName ($percentage%)");
+ $barValues[] = $barValue;
+ $i++;
+ }
+ $bar->set_values($barValues);
+ $this->chart->add_element($bar);
}
}
diff --git a/core/Visualization/OpenFlashChart.php b/core/Visualization/OpenFlashChart.php
deleted file mode 100644
index 1b65f3a0fa..0000000000
--- a/core/Visualization/OpenFlashChart.php
+++ /dev/null
@@ -1,1637 +0,0 @@
-<?php
-/**
- * Piwik - Open source web analytics
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
- * @version $Id: OpenFlashChart.php 566 2008-07-21 00:34:43Z matt $
- *
- * @package Piwik_Visualization
- * @subpackage OFC
- */
-
-require_once "iView.php";
-
-
-/**
- * Original class provided by Open Flash Chart
- *
- * @package Piwik_Visualization
- */
-abstract class Piwik_Visualization_OpenFlashChart implements Piwik_iView
-{
- function __construct()
- {
- $this->data_sets = array();
- $this->data = array();
- $this->links = array();
- $this->width = 250;
- $this->height = 200;
- $this->js_path = 'js/';
- $this->swf_path = '';
- $this->x_labels = array();
- $this->y_min = '';
- $this->y_max = '';
- $this->x_min = '';
- $this->x_max = '';
- $this->y_steps = '';
- $this->title = '';
- $this->title_style = '';
- $this->occurence = 0;
-
- $this->x_offset = '';
-
- $this->x_tick_size = -1;
-
- $this->y2_max = '';
- $this->y2_min = '';
-
- // GRID styles:
- $this->x_axis_colour = '';
- $this->x_axis_3d = '';
- $this->x_grid_colour = '';
- $this->x_axis_steps = 1;
- $this->y_axis_colour = '';
- $this->y_grid_colour = '';
- $this->y2_axis_colour = '';
-
- // AXIS LABEL styles:
- $this->x_label_style = '';
- $this->y_label_style = '';
- $this->y_label_style_right = '';
-
-
- // AXIS LEGEND styles:
- $this->x_legend = '';
- $this->x_legend_size = 20;
- $this->x_legend_colour = '#000000';
-
- $this->y_legend = '';
- $this->y_legend_right = '';
- //$this->y_legend_size = 20;
- //$this->y_legend_colour = '#000000';
-
- $this->lines = array();
- $this->line_default['type'] = 'line';
- $this->line_default['values'] = '3,#87421F';
- //$this->js_line_default = 'flashvars["line"] = "3,#87421F";';
-
- $this->bg_colour = '';
- $this->bg_image = '';
-
- $this->inner_bg_colour = '';
- $this->inner_bg_colour_2 = '';
- $this->inner_bg_angle = '';
-
- // PIE chart ------------
- $this->pie = '';
- $this->pie_values = '';
- $this->pie_colours = '';
- $this->pie_labels = '';
-
- $this->tool_tip = '';
-
- // which data lines are attached to the
- // right Y axis?
- $this->y2_lines = array();
-
- // Number formatting:
- $this->y_format='';
- $this->num_decimals='';
- $this->is_fixed_num_decimals_forced='';
- $this->is_decimal_separator_comma='';
- $this->is_thousand_separator_disabled='';
-
- $this->output_type = '';
-
- //
- // set some default value incase the user forgets
- // to set them, so at least they see *something*
- // even is it is only the axis and some ticks
- //
- $this->set_y_min( 0 );
- $this->set_y_max( 20 );
- $this->set_x_axis_steps( 1 );
- $this->y_label_steps( 5 );
- }
-
- /**
- * Set the unique_id to use for the flash object id.
- */
- function set_unique_id()
- {
- $this->unique_id = uniqid(rand(), true);
- }
-
- /**
- * Get the flash object ID for the last rendered object.
- */
- function get_unique_id()
- {
- return ($this->unique_id);
- }
-
- /**
- * Set the base path for the swfobject.js
- *
- * @param base_path a string argument.
- * The path to the swfobject.js file
- */
- function set_js_path($path)
- {
- $this->js_path = $path;
- }
-
- /**
- * Set the base path for the open-flash-chart.swf
- *
- * @param path a string argument.
- * The path to the open-flash-chart.swf file
- */
- function set_swf_path($path)
- {
- $this->swf_path = $path;
- }
-
- /**
- * Set the type of output data.
- *
- * @param type a string argument.
- * The type of data. Currently only type is js, or nothing.
- */
- function set_output_type($type)
- {
- $this->output_type = $type;
- }
-
- /**
- * returns the next line label for multiple lines.
- */
- function next_line()
- {
- $line_num = '';
- if( count( $this->lines ) > 0 )
- $line_num = '_'. (count( $this->lines )+1);
-
- return $line_num;
- }
-
- // escape commas (,)
- static function esc( $text )
- {
- // we replace the comma so it is not URL escaped
- // if it is, flash just thinks it is a comma
- // which is no good if we are splitting the
- // string on commas.
- $tmp = str_replace( ',', '#comma#', $text );
- //$tmp = utf8_encode( $tmp );
- // now we urlescape all dodgy characters (like & % $ etc..)
- return urlencode( $tmp );
- }
-
- /**
- * Format the text to the type of output.
- */
- function format_output($function,$values)
- {
- if($this->output_type == 'js')
- {
- $tmp = 'flashvars["' . $function . '"] = "' . $values . '";';
- }
- else
- {
- $tmp = '&'. $function .'='. $values .'&';
- }
-
- return $tmp;
- }
-
- /**
- * Set the text and style of the title.
- *
- * @param title a string argument.
- * The text of the title.
- * @param style a string.
- * CSS styling of the title.
- */
- function set_title( $title, $style='' )
- {
- $this->title = $this->esc( $title );
- if( strlen( $style ) > 0 )
- $this->title_style = $style;
- }
-
- /**
- * Set the width of the chart.
- *
- * @param width an int argument.
- * The width of the chart frame.
- */
- function set_width( $width )
- {
- $this->width = $width;
- }
-
- /**
- * Set the height of the chart.
- *
- * @param height an int argument.
- * The height of the chart frame.
- */
- function set_height( $height )
- {
- $this->height = $height;
- }
-
- /**
- * Set the base path of the swfobject.
- *
- * @param base a string argument.
- * The base path of the swfobject.
- */
- function set_base( $base='js/' )
- {
- $this->base = $base;
- }
-
- // Number formatting:
- function set_y_format( $val )
- {
- $this->y_format = $val;
- }
-
- function set_num_decimals( $val )
- {
- $this->num_decimals = $val;
- }
-
- function set_is_fixed_num_decimals_forced( $val )
- {
- $this->is_fixed_num_decimals_forced = $val?'true':'false';
- }
-
- function set_is_decimal_separator_comma( $val )
- {
- $this->is_decimal_separator_comma = $val?'true':'false';
- }
-
- function set_is_thousand_separator_disabled( $val )
- {
- $this->is_thousand_separator_disabled = $val?'true':'false';
- }
-
- /**
- * Set the data for the chart
- * @param a an array argument.
- * An array of the data to add to the chart.
- */
- function set_data( $a )
- {
- $this->data[] = implode(',',$a);
- }
-
- // UGH, these evil functions are making me fell ill
- function set_links( $links )
- {
- // TO DO escape commas:
- $this->links[] = implode(',',$links);
- }
-
- // $val is a boolean
- function set_x_offset( $val )
- {
- $this->x_offset = $val?'true':'false';
- }
-
- /**
- * Set the tooltip to be displayed on each chart item.\n
- * \n
- * Replaceable tokens that can be used in the string include: \n
- * #val# - The actual value of whatever the mouse is over. \n
- * #key# - The key string. \n
- * \<br> - New line. \n
- * #x_label# - The X label string. \n
- * #x_legend# - The X axis legend text. \n
- * Default string is: "#x_label#<br>#val#" \n
- *
- * @param tip a string argument.
- * A formatted string to show as the tooltip.
- */
- function set_tool_tip( $tip )
- {
- $this->tool_tip = $this->esc( $tip );
- }
-
- /**
- * Set the x axis labels
- *
- * @param a an array argument.
- * An array of the x axis labels.
- */
- function set_x_labels( $a )
- {
- $tmp = array();
- foreach( $a as $item )
- $tmp[] = $this->esc( $item );
- $this->x_labels = $tmp;
- }
-
- /**
- * Set the look and feel of the x axis labels
- *
- * @param font_size an int argument.
- * The font size.
- * @param colour a string argument.
- * The hex colour value.
- * @param orientation an int argument.
- * The orientation of the x-axis text.
- * 0 - Horizontal
- * 1 - Vertical
- * 2 - 45 degrees
- * @param step an int argument.
- * Show the label on every $step label.
- * @param grid_colour a string argument.
- */
- function set_x_label_style( $size, $colour='', $orientation=0, $step=-1, $grid_colour='' )
- {
- $this->x_label_style = $size;
-
- if( strlen( $colour ) > 0 )
- $this->x_label_style .= ','. $colour;
-
- if( $orientation > -1 )
- $this->x_label_style .= ','. $orientation;
-
- if( $step > 0 )
- $this->x_label_style .= ','. $step;
-
- if( strlen( $grid_colour ) > 0 )
- $this->x_label_style .= ','. $grid_colour;
- }
-
- /**
- * Set the background colour.
- * @param colour a string argument.
- * The hex colour value.
- */
- function set_bg_colour( $colour )
- {
- $this->bg_colour = $colour;
- }
-
- /**
- * Set a background image.
- * @param url a string argument.
- * The location of the image.
- * @param x a string argument.
- * The x location of the image. 'Right', 'Left', 'Center'
- * @param y a string argument.
- * The y location of the image. 'Top', 'Bottom', 'Middle'
- */
- function set_bg_image( $url, $x='center', $y='center' )
- {
- $this->bg_image = $url;
- $this->bg_image_x = $x;
- $this->bg_image_y = $y;
- }
-
- /**
- * Attach a set of data (a line, area or bar chart) to the right Y axis.
- * @param data_number an int argument.
- * The numbered order the data was attached using set_data.
- */
- function attach_to_y_right_axis( $data_number )
- {
- $this->y2_lines[] = $data_number;
- }
-
- /**
- * Set the background colour of the grid portion of the chart.
- * @param col a string argument.
- * The hex colour value of the background.
- * @param col2 a string argument.
- * The hex colour value of the second colour if you want a gradient.
- * @param angle an int argument.
- * The angle in degrees to make the gradient.
- */
- function set_inner_background( $col, $col2='', $angle=-1 )
- {
- $this->inner_bg_colour = $col;
-
- if( strlen($col2) > 0 )
- $this->inner_bg_colour_2 = $col2;
-
- if( $angle != -1 )
- $this->inner_bg_angle = $angle;
- }
-
- /**
- * Internal function to build the y label style for y and y2
- */
- function _set_y_label_style( $size, $colour )
- {
- $tmp = $size;
-
- if( strlen( $colour ) > 0 )
- $tmp .= ','. $colour;
- return $tmp;
- }
-
- /**
- * Set the look and feel of the y axis labels
- *
- * @param font_size an int argument.
- * The font size.
- * @param colour a string argument.
- * The hex colour value.
- */
- function set_y_label_style( $size, $colour='' )
- {
- $this->y_label_style = $this->_set_y_label_style( $size, $colour );
- }
-
- /**
- * Set the look and feel of the right y axis labels
- *
- * @param font_size an int argument.
- * The font size.
- * @param colour a string argument.
- * The hex colour value.
- */
- function set_y_right_label_style( $size, $colour='' )
- {
- $this->y_label_style_right = $this->_set_y_label_style( $size, $colour );
- }
-
- function set_x_max( $max )
- {
- $this->x_max = floatval( $max );
- }
-
- function set_x_min( $min )
- {
- $this->x_min = floatval( $min );
- }
-
- /**
- * Set the maximum value of the y axis.
- *
- * @param max an float argument.
- * The maximum value.
- */
- function set_y_max( $max )
- {
- $this->y_max = floatval( $max );
- }
-
- /**
- * Set the minimum value of the y axis.
- *
- * @param min an float argument.
- * The minimum value.
- */
- function set_y_min( $min )
- {
- $this->y_min = floatval( $min );
- }
-
- /**
- * Set the maximum value of the right y axis.
- *
- * @param max an float argument.
- * The maximum value.
- */
- function set_y_right_max( $max )
- {
- $this->y2_max = floatval($max);
- }
-
- /**
- * Set the minimum value of the right y axis.
- *
- * @param min an float argument.
- * The minimum value.
- */
- function set_y_right_min( $min )
- {
- $this->y2_min = floatval($min);
- }
-
- /**
- * Show the y label on every $step label.
- *
- * @param val an int argument.
- * Show the label on every $step label.
- */
- function y_label_steps( $val )
- {
- $this->y_steps = intval( $val );
- }
-
- function title( $title, $style='' )
- {
- $this->title = $this->esc( $title );
- if( strlen( $style ) > 0 )
- $this->title_style = $style;
- }
-
- /**
- * Set the parameters of the x legend.
- *
- * @param text a string argument.
- * The text of the x legend.
- * @param font_size an int argument.
- * The font size of the x legend text.
- * @param colour a string argument
- * The hex value of the font colour.
- */
- function set_x_legend( $text, $size=-1, $colour='' )
- {
- $this->x_legend = $this->esc( $text );
- if( $size > -1 )
- $this->x_legend_size = $size;
-
- if( strlen( $colour )>0 )
- $this->x_legend_colour = $colour;
- }
-
- /**
- * Set the size of the x label ticks.
- *
- * @param size an int argument.
- * The size of the ticks in pixels.
- */
- function set_x_tick_size( $size )
- {
- if( $size > 0 )
- $this->x_tick_size = $size;
- }
-
- /**
- * Set how often you would like to show a tick on the x axis.
- *
- * @param steps an int argument.
- * Show a tick ever $steps.
- */
- function set_x_axis_steps( $steps )
- {
- if ( $steps > 0 )
- $this->x_axis_steps = $steps;
- }
-
- /**
- * Set the depth in pixels of the 3D X axis slab.
- *
- * @param size an int argument.
- * The depth in pixels of the 3D X axis.
- */
- function set_x_axis_3d( $size )
- {
- if( $size > 0 )
- $this->x_axis_3d = intval($size);
- }
-
- /**
- * The private method of building the y legend output.
- */
- function _set_y_legend( $text, $size, $colour )
- {
- $tmp = $text;
-
- if( $size > -1 )
- $tmp .= ','. $size;
-
- if( strlen( $colour )>0 )
- $tmp .= ','. $colour;
-
- return $tmp;
- }
-
- /**
- * Set the parameters of the y legend.
- *
- * @param text a string argument.
- * The text of the y legend.
- * @param font_size an int argument.
- * The font size of the y legend text.
- * @param colour a string argument
- * The hex colour value of the font colour.
- */
- function set_y_legend( $text, $size=-1, $colour='' )
- {
- $this->y_legend = $this->_set_y_legend( $text, $size, $colour );
- }
-
- /**
- * Set the parameters of the right y legend.
- *
- * @param text a string argument.
- * The text of the right y legend.
- * @param font_size an int argument.
- * The font size of the right y legend text.
- * @param colour a string argument
- * The hex value of the font colour.
- */
- function set_y_right_legend( $text, $size=-1, $colour='' )
- {
- $this->y_legend_right = $this->_set_y_legend( $text, $size, $colour );
- }
-
- /**
- * Set the colour of the x axis line and grid.
- *
- * @param axis a string argument.
- * The hex colour value of the x axis line.
- * @param grid a string argument.
- * The hex colour value of the x axis grid.
- */
- function x_axis_colour( $axis, $grid='' )
- {
- $this->x_axis_colour = $axis;
- $this->x_grid_colour = $grid;
- }
-
- /**
- * Set the colour of the y axis line and grid.
- *
- * @param axis a string argument.
- * The hex colour value of the y axis line.
- * @param grid a string argument.
- * The hex colour value of the y axis grid.
- */
- function y_axis_colour( $axis, $grid='' )
- {
- $this->y_axis_colour = $axis;
-
- if( strlen( $grid ) > 0 )
- $this->y_grid_colour = $grid;
- }
-
- /**
- * Set the colour of the right y axis line.
- *
- * @param colour a string argument.
- * The hex colour value of the right y axis line.
- */
- function y_right_axis_colour( $colour )
- {
- $this->y2_axis_colour = $colour;
- }
-
- /**
- * Draw a line without markers on values.
- *
- * @param width an int argument.
- * The width of the line in pixels.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label
- * @param circles an int argument
- * Need to find out.
- */
- function line( $width, $colour='', $text='', $size=-1, $circles=-1 )
- {
- $type = 'line'. $this->next_line();
-
- $description = '';
- if( $width > 0 )
- {
- $description .= $width;
- $description .= ','. $colour;
- }
-
- if( strlen( $text ) > 0 )
- {
- $description.= ','. $text;
- $description .= ','. $size;
- }
-
- if( $circles > 0 )
- $description .= ','. $circles;
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw a line with solid dot markers on values.
- *
- * @param width an int argument.
- * The width of the line in pixels.
- * @param dot_size an int argument.
- * Size in pixels of the dot.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- */
- function line_dot( $width, $dot_size, $colour, $text='', $font_size='' )
- {
- $type = 'line_dot'. $this->next_line();
-
- $description = "$width,$colour,$text";
-
- if( strlen( $font_size ) > 0 )
- $description .= ",$font_size,$dot_size";
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw a line with hollow dot markers on values.
- *
- * @param width an int argument.
- * The width of the line in pixels.
- * @param dot_size an int argument.
- * Size in pixels of the dot.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- */
- function line_hollow( $width, $dot_size, $colour, $text='', $font_size='' )
- {
- $type = 'line_hollow'. $this->next_line();
-
- $description = "$width,$colour,$text";
-
- if( strlen( $font_size ) > 0 )
- $description .= ",$font_size,$dot_size";
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw an area chart.
- *
- * @param width an int argument.
- * The width of the line in pixels.
- * @param dot_size an int argument.
- * Size in pixels of the dot.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param alpha an int argument.
- * The percentage of transparency of the fill colour.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- * @param fill_colour a string argument.
- * The hex colour value of the fill colour.
- */
- function area_hollow( $width, $dot_size, $colour, $alpha, $text='', $font_size='', $fill_colour='' )
- {
- $type = 'area_hollow'. $this->next_line();
-
- $description = "$width,$dot_size,$colour,$alpha";
-
- if( strlen( $text ) > 0 )
- $description .= ",$text,$font_size";
-
- if( strlen( $fill_colour ) > 0 )
- $description .= ','. $fill_colour;
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw a bar chart.
- *
- * @param alpha an int argument.
- * The percentage of transparency of the bar colour.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- */
- function bar( $alpha, $colour='', $text='', $size=-1 )
- {
- $type = 'bar'. $this->next_line();
-
- $description = $alpha .','. $colour .','. $text .','. $size;
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw a bar chart with an outline.
- *
- * @param alpha an int argument.
- * The percentage of transparency of the bar colour.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param colour_outline a strng argument.
- * The hex colour value of the outline.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- */
- function bar_filled( $alpha, $colour, $colour_outline, $text='', $size=-1 )
- {
- $type = 'filled_bar'. $this->next_line();
-
- $description = "$alpha,$colour,$colour_outline,$text,$size";
-
- $this->lines[$type] = $description;
- }
-
- function bar_sketch( $alpha, $offset, $colour, $colour_outline, $text='', $size=-1 )
- {
- $type = 'bar_sketch'. $this->next_line();
-
- $description = "$alpha,$offset,$colour,$colour_outline,$text,$size";
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw a 3D bar chart.
- *
- * @param alpha an int argument.
- * The percentage of transparency of the bar colour.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- */
- function bar_3D( $alpha, $colour='', $text='', $size=-1 )
- {
- $type = 'bar_3d'. $this->next_line();
-
- $description = $alpha .','. $colour .','. $text .','. $size;
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw a 3D bar chart that looks like glass.
- *
- * @param alpha an int argument.
- * The percentage of transparency of the bar colour.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param outline_colour a string argument.
- * The hex colour value of the outline.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- */
- function bar_glass( $alpha, $colour, $outline_colour, $text='', $size=-1 )
- {
- $type = 'bar_glass'. $this->next_line();
-
- $description = $alpha .','. $colour .','. $outline_colour .','. $text .','. $size;
-
- $this->lines[$type] = $description;
- }
-
- /**
- * Draw a faded bar chart.
- *
- * @param alpha an int argument.
- * The percentage of transparency of the bar colour.
- * @param colour a string argument.
- * The hex colour value of the line.
- * @param text a string argument.
- * The label of the line.
- * @param font_size an int argument.
- * Font size of the label.
- */
- function bar_fade( $alpha, $colour='', $text='', $size=-1 )
- {
- $type = 'bar_fade'. $this->next_line();
-
- $description = $alpha .','. $colour .','. $text .','. $size;
-
- $this->lines[$type] = $description;
- }
-
- function candle( $data, $alpha, $line_width, $colour, $text='', $size=-1 )
- {
- $type = 'candle'. $this->next_line();
-
- $description = $alpha .','. $line_width .','. $colour .','. $text .','. $size;
-
- $this->lines[$type] = $description;
-
- $a = array();
- foreach( $data as $can )
- $a[] = $can->toString();
-
- $this->data[] = implode(',',$a);
- }
-
- function hlc( $data, $alpha, $line_width, $colour, $text='', $size=-1 )
- {
- $type = 'hlc'. $this->next_line();
-
- $description = $alpha .','. $line_width .','. $colour .','. $text .','. $size;
-
- $this->lines[$type] = $description;
-
- $a = array();
- foreach( $data as $can )
- $a[] = $can->toString();
-
- $this->data[] = implode(',',$a);
- }
-
- function scatter( $data, $line_width, $colour, $text='', $size=-1 )
- {
- $type = 'scatter'. $this->next_line();
-
- $description = $line_width .','. $colour .','. $text .','. $size;
-
- $this->lines[$type] = $description;
-
- $a = array();
- foreach( $data as $can )
- $a[] = $can->toString();
-
- $this->data[] = implode(',',$a);
- }
-
-
- //
- // Patch by, Jeremy Miller (14th Nov, 2007)
- //
- /**
- * Draw a pie chart.
- *
- * @param alpha an int argument.
- * The percentage of transparency of the pie colour.
- * @param $style a string argument.
- * CSS style string
- * @param label_colour a string argument.
- * The hex colour value of the label.
- * @param gradient a boolean argument.
- * Use a gradient true or false.
- * @param border_size an int argument.
- * Size of the border in pixels.
- */
- function pie( $alpha, $line_colour, $style, $gradient = true, $border_size = false )
- {
- $this->pie = $alpha.','.$line_colour.','.$style;
- if( !$gradient )
- {
- $this->pie .= ','.!$gradient;
- }
- if ($border_size)
- {
- if ($gradient === false)
- {
- $this->pie .= ',';
- }
- $this->pie .= ','.$border_size;
- }
- }
-
- /**
- * Set the values of the pie chart.
- *
- * @param values an array argument.
- * An array of the values for the pie chart.
- * @param labels an array argument.
- * An array of the labels for the pie pieces.
- * @param links an array argument.
- * An array of the links to the pie pieces.
- */
- function pie_values( $values, $labels=array(), $links=array() )
- {
- $this->pie_values = implode(',',$values);
- $this->pie_labels = implode(',',$labels);
- $this->pie_links = implode(",",$links);
- }
-
- /**
- * Set the pie slice colours.
- *
- * @param colours an array argument.
- * The hex colour values of the pie pieces.
- */
- function pie_slice_colours( $colours )
- {
- $this->pie_colours = implode(',',$colours);
- }
-
-
- /**
- * Render the output.
- */
- function render()
- {
- $tmp = array();
-
- //echo headers_sent() ?'yes':'no';
- if( !headers_sent() )
- header('content-type: text; charset: utf-8');
-
- if($this->output_type == 'js')
- {
- $this->set_unique_id();
-
- // alternate content (<p></p>) is empty for browsers without Flash
- $tmp[] = '<div id="' . $this->unique_id . '"><p></p></div>';
- $tmp[] = '<script type="text/javascript" src="' . $this->js_path . 'swfobject.js"></script>';
- $tmp[] = '<script type="text/javascript">';
- $tmp[] = 'var flashvars = [];';
- }
-
- if( strlen( $this->title ) > 0 )
- {
- $values = $this->title;
- $values .= ','. $this->title_style;
- $tmp[] = $this->format_output('title',$values);
- }
-
- if( strlen( $this->x_legend ) > 0 )
- {
- $values = $this->x_legend;
- $values .= ','. $this->x_legend_size;
- $values .= ','. $this->x_legend_colour;
- $tmp[] = $this->format_output('x_legend',$values);
- }
-
- if( strlen( $this->x_label_style ) > 0 )
- $tmp[] = $this->format_output('x_label_style',$this->x_label_style);
-
- if( $this->x_tick_size > 0 )
- $tmp[] = $this->format_output('x_ticks',$this->x_tick_size);
-
- if( $this->x_axis_steps > 0 )
- $tmp[] = $this->format_output('x_axis_steps',$this->x_axis_steps);
-
- if( strlen( $this->x_axis_3d ) > 0 )
- $tmp[] = $this->format_output('x_axis_3d',$this->x_axis_3d);
-
- if( strlen( $this->y_legend ) > 0 )
- $tmp[] = $this->format_output('y_legend',$this->y_legend);
-
- if( strlen( $this->y_legend_right ) > 0 )
- $tmp[] = $this->format_output('y2_legend',$this->y_legend_right);
-
- if( strlen( $this->y_label_style ) > 0 )
- $tmp[] = $this->format_output('y_label_style',$this->y_label_style);
-
- $values = '5,10,'. $this->y_steps;
- $tmp[] = $this->format_output('y_ticks',$values);
-
- if( count( $this->lines ) == 0 && count($this->data_sets)==0 )
- {
- $tmp[] = $this->format_output($this->line_default['type'],$this->line_default['values']);
- }
- else
- {
- foreach( $this->lines as $type=>$description )
- $tmp[] = $this->format_output($type,$description);
- }
-
- $num = 1;
- foreach( $this->data as $data )
- {
- if( $num==1 )
- {
- $tmp[] = $this->format_output( 'values', $data);
- }
- else
- {
- $tmp[] = $this->format_output('values_'. $num, $data);
- }
-
- $num++;
- }
-
- $num = 1;
- foreach( $this->links as $link )
- {
- if( $num==1 )
- {
- $tmp[] = $this->format_output( 'links', $link);
- }
- else
- {
- $tmp[] = $this->format_output('links_'. $num, $link);
- }
-
- $num++;
- }
-
- if( count( $this->y2_lines ) > 0 )
- {
- $tmp[] = $this->format_output('y2_lines',implode( ',', $this->y2_lines ));
- //
- // Should this be an option? I think so...
- //
- $tmp[] = $this->format_output('show_y2','true');
- }
-
- if( count( $this->x_labels ) > 0 )
- $tmp[] = $this->format_output('x_labels',implode(',',$this->x_labels));
- else
- {
- if( strlen($this->x_min) > 0 )
- $tmp[] = $this->format_output('x_min',$this->x_min);
-
- if( strlen($this->x_max) > 0 )
- $tmp[] = $this->format_output('x_max',$this->x_max);
- }
-
- $tmp[] = $this->format_output('y_min',$this->y_min);
- $tmp[] = $this->format_output('y_max',$this->y_max);
-
- if( strlen($this->y2_min) > 0 )
- $tmp[] = $this->format_output('y2_min',$this->y2_min);
-
- if( strlen($this->y2_max) > 0 )
- $tmp[] = $this->format_output('y2_max',$this->y2_max);
-
- if( strlen( $this->bg_colour ) > 0 )
- $tmp[] = $this->format_output('bg_colour',$this->bg_colour);
-
- if( strlen( $this->bg_image ) > 0 )
- {
- $tmp[] = $this->format_output('bg_image',$this->bg_image);
- $tmp[] = $this->format_output('bg_image_x',$this->bg_image_x);
- $tmp[] = $this->format_output('bg_image_y',$this->bg_image_y);
- }
-
- if( strlen( $this->x_axis_colour ) > 0 )
- {
- $tmp[] = $this->format_output('x_axis_colour',$this->x_axis_colour);
- $tmp[] = $this->format_output('x_grid_colour',$this->x_grid_colour);
- }
-
- if( strlen( $this->y_axis_colour ) > 0 )
- $tmp[] = $this->format_output('y_axis_colour',$this->y_axis_colour);
-
- if( strlen( $this->y_grid_colour ) > 0 )
- $tmp[] = $this->format_output('y_grid_colour',$this->y_grid_colour);
-
- if( strlen( $this->y2_axis_colour ) > 0 )
- $tmp[] = $this->format_output('y2_axis_colour',$this->y2_axis_colour);
-
- if( strlen( $this->x_offset ) > 0 )
- $tmp[] = $this->format_output('x_offset',$this->x_offset);
-
- if( strlen( $this->inner_bg_colour ) > 0 )
- {
- $values = $this->inner_bg_colour;
- if( strlen( $this->inner_bg_colour_2 ) > 0 )
- {
- $values .= ','. $this->inner_bg_colour_2;
- $values .= ','. $this->inner_bg_angle;
- }
- $tmp[] = $this->format_output('inner_background',$values);
- }
-
- if( strlen( $this->pie ) > 0 )
- {
- $tmp[] = $this->format_output('pie',$this->pie);
- $tmp[] = $this->format_output('values',$this->pie_values);
- $tmp[] = $this->format_output('pie_labels',$this->pie_labels);
- $tmp[] = $this->format_output('colours',$this->pie_colours);
- $tmp[] = $this->format_output('links',$this->pie_links);
- }
-
- if( strlen( $this->tool_tip ) > 0 )
- $tmp[] = $this->format_output('tool_tip',$this->tool_tip);
-
-
-
- if( strlen( $this->y_format ) > 0 )
- $tmp[] = $this->format_output('y_format',$this->y_format);
-
- if( strlen( $this->num_decimals ) > 0 )
- $tmp[] = $this->format_output('num_decimals',$this->num_decimals);
-
- if( strlen( $this->is_fixed_num_decimals_forced ) > 0 )
- $tmp[] = $this->format_output('is_fixed_num_decimals_forced',$this->is_fixed_num_decimals_forced);
-
- if( strlen( $this->is_decimal_separator_comma ) > 0 )
- $tmp[] = $this->format_output('is_decimal_separator_comma',$this->is_decimal_separator_comma);
-
- if( strlen( $this->is_thousand_separator_disabled ) > 0 )
- $tmp[] = $this->format_output('is_thousand_separator_disabled',$this->is_thousand_separator_disabled);
-
-
- $count = 1;
- foreach( $this->data_sets as $set )
- {
- $tmp[] = $set->toString( $this->output_type, $count>1?'_'.$count:'' );
- $count++;
- }
-
- if($this->output_type == 'js')
- {
- $tmp[] = 'swfobject.embedSWF("' . $this->swf_path . 'open-flash-chart.swf", "' . $this->unique_id . '", "'. $this->width . '", "' . $this->height . '", "9.0.0", false, flashvars, {bgcolor:"#FFFFFF"}, {id:"ofc",name:"ofc"});';
- $tmp[] = '</script>';
- }
-
- return implode("\r\n",$tmp);
- }
-}
-
-class line
-{
- var $line_width;
- var $colour;
- var $_key;
- var $key;
- var $key_size;
- // hold the data
- var $data;
- // extra tool tip info:
- var $tips;
-
- function line( $line_width, $colour )
- {
- $this->var = 'line';
-
- $this->line_width = $line_width;
- $this->colour = $colour;
- $this->data = array();
- $this->links = array();
- $this->tips = array();
- $this->_key = false;
- }
-
- function key( $key, $size )
- {
- $this->_key = true;
- $this->key = graph::esc( $key );
- $this->key_size = $size;
- }
-
- function add( $data )
- {
- $this->data[] = $data;
- }
-
- function add_link( $data, $link )
- {
- $this->data[] = $data;
- $this->links[] = graph::esc( $link );
- }
-
- function add_data_tip( $data, $tip )
- {
- $this->data[] = $data;
- $this->tips[] = graph::esc( $tip );
- }
-
- function add_data_link_tip( $data, $link, $tip )
- {
- $this->data[] = $data;
- $this->links[] = graph::esc( $link );
- $this->tips[] = graph::esc( $tip );
- }
-
- // return the variables for this chart
- function _get_variable_list()
- {
- $values = array();
- $values[] = $this->line_width;
- $values[] = $this->colour;
-
- if( $this->_key )
- {
- $values[] = $this->key;
- $values[] = $this->key_size;
- }
-
- return $values;
- }
-
- function toString( $output_type, $set_num )
- {
- $values = implode( ',', $this->_get_variable_list() );
-
- $tmp = array();
-
- if( $output_type == 'js' )
- {
- $tmp[] = 'flashvars["'. $this->var.$set_num .'"] = "'. $values .'";';
- $tmp[] = 'flashvars["values'. $set_num .'"] = "'. implode( ',', $this->data ) .'";';
- if( count( $this->links ) > 0 )
- $tmp[] = 'flashvars["links'. $set_num .'"] = "'. implode( ',', $this->links ) .'";';
- if( count( $this->tips ) > 0 )
- $tmp[] = 'flashvars["tool_tips_set'. $set_num .'"] = "'. implode( ',', $this->tips ) .'";';
- }
- else
- {
- $tmp[] = '&'. $this->var. $set_num .'='. $values .'&';
- $tmp[] = '&values'. $set_num .'='. implode( ',', $this->data ) .'&';
-
- if( count( $this->links ) > 0 )
- $tmp[] = '&links'. $set_num .'='. implode( ',', $this->links ) .'&';
-
- if( count( $this->tips ) > 0 )
- $tmp[] = '&tool_tips_set'. $set_num .'='. implode( ',', $this->tips ) .'&';
- }
-
- return implode( "\r\n", $tmp );
- }
-}
-
-class line_hollow extends line
-{
- var $dot_size;
-
- function line_hollow( $line_width, $dot_size, $colour )
- {
- parent::line( $line_width, $colour );
- $this->var = 'line_hollow';
- $this->dot_size = $dot_size;
- }
-
- // return the variables for this chart
- function _get_variable_list()
- {
- $values = array();
- $values[] = $this->line_width;
- $values[] = $this->colour;
-
- if( $this->_key )
- {
- $values[] = $this->key;
- $values[] = $this->key_size;
- }
- else
- {
- $values[] = '';
- $values[] = '';
- }
- $values[] = $this->dot_size;
-
- return $values;
- }
-}
-
-class line_dot extends line_hollow
-{
- function line_dot( $line_width, $dot_size, $colour )
- {
- parent::line_hollow( $line_width, $dot_size,$colour );
- $this->var = 'line_dot';
- }
-}
-
-class bar
-{
- var $colour;
- var $alpha;
- var $data;
- var $links;
- var $_key;
- var $key;
- var $key_size;
- var $var;
- // extra tool tip info:
- var $tips;
-
- function bar( $alpha, $colour )
- {
- $this->var = 'bar';
-
- $this->alpha = $alpha;
- $this->colour = $colour;
- $this->data = array();
- $this->links = array();
- $this->tips = array();
- $this->_key = false;
- }
-
- function key( $key, $size )
- {
- $this->_key = true;
- $this->key = graph::esc( $key );
- $this->key_size = $size;
- }
-
- function add( $data )
- {
- $this->data[] = $data;
- }
-
- function add_link( $data, $link )
- {
- $this->data[] = $data;
- $this->links[] = graph::esc( $link );
- }
-
- function add_data_tip( $data, $tip )
- {
- $this->data[] = $data;
- $this->tips[] = graph::esc( $tip );
- }
-
- // return the variables for this
- // bar chart
- function _get_variable_list()
- {
- $values = array();
- $values[] = $this->alpha;
- $values[] = $this->colour;
-
- if( $this->_key )
- {
- $values[] = $this->key;
- $values[] = $this->key_size;
- }
-
- return $values;
- }
-
- function toString( $output_type, $set_num )
- {
- $values = implode( ',', $this->_get_variable_list() );
-
- $tmp = array();
-
- if( $output_type == 'js' )
- {
- $tmp[] = 'flashvars["'. $this->var.$set_num .'"] = "'. $values . '";';
- $tmp[] = 'flashvars["values'. $set_num .'"] = "'. implode( ',', $this->data ) .'";';
-
- if( count( $this->links ) > 0 )
- $tmp[] = 'flashvars["links'. $set_num .'"] = "'. implode( ',', $this->links ) .'";';
-
- if( count( $this->tips ) > 0 )
- $tmp[] = 'flashvars["tool_tips_set'. $set_num .'"] = "'. implode( ',', $this->tips ) .'";';
- }
- else
- {
- $tmp[] = '&'. $this->var. $set_num .'='. $values .'&';
- $tmp[] = '&values'. $set_num .'='. implode( ',', $this->data ) .'&';
-
- if( count( $this->links ) > 0 )
- $tmp[] = '&links'. $set_num .'='. implode( ',', $this->links ) .'&';
-
- if( count( $this->tips ) > 0 )
- $tmp[] = '&tool_tips_set'. $set_num .'='. implode( ',', $this->tips ) .'&';
- }
-
- return implode( "\r\n", $tmp );
- }
-
-}
-
-class bar_3d extends bar
-{
- function bar_3d( $alpha, $colour )
- {
- parent::bar( $alpha, $colour );
- $this->var = 'bar_3d';
- }
-}
-
-class bar_fade extends bar
-{
- function bar_fade( $alpha, $colour )
- {
- parent::bar( $alpha, $colour );
- $this->var = 'bar_fade';
- }
-}
-
-class bar_outline extends bar
-{
- var $outline_colour;
-
- function bar_outline( $alpha, $colour, $outline_colour )
- {
- parent::bar( $alpha, $colour );
- $this->var = 'filled_bar';
- $this->outline_colour = $outline_colour;
- }
-
- // override the base method
- function _get_variable_list()
- {
- $values = array();
- $values[] = $this->alpha;
- $values[] = $this->colour;
- $values[] = $this->outline_colour;
-
- if( $this->_key )
- {
- $values[] = $this->key;
- $values[] = $this->key_size;
- }
-
- return $values;
- }
-}
-
-class bar_glass extends bar_outline
-{
- function bar_glass( $alpha, $colour, $outline_colour )
- {
- parent::bar_outline( $alpha, $colour, $outline_colour );
- $this->var = 'bar_glass';
- }
-}
-
-//
-// this has an outline colour and a 'jiggle' parameter
-// called offset
-//
-class bar_sketch extends bar_outline
-{
- var $offset;
-
- function bar_sketch( $alpha, $offset, $colour, $outline_colour )
- {
- parent::bar_outline( $alpha, $colour, $outline_colour );
- $this->var = 'bar_sketch';
- $this->offset = $offset;
- }
-
- // override the base method
- function _get_variable_list()
- {
- $values = array();
- $values[] = $this->alpha;
- $values[] = $this->offset;
- $values[] = $this->colour;
- $values[] = $this->outline_colour;
-
- if( $this->_key )
- {
- $values[] = $this->key;
- $values[] = $this->key_size;
- }
-
- return $values;
- }
-}
-
-class candle
-{
- var $out;
-
- function candle( $high, $open, $close, $low )
- {
- $this->out = array();
- $this->out[] = $high;
- $this->out[] = $open;
- $this->out[] = $close;
- $this->out[] = $low;
- }
-
- function toString()
- {
- return '['. implode( ',', $this->out ) .']';
- }
-}
-
-class hlc
-{
- var $out;
-
- function hlc( $high, $low, $close )
- {
- $this->out = array();
- $this->out[] = $high;
- $this->out[] = $low;
- $this->out[] = $close;
- }
-
- function toString()
- {
- return '['. implode( ',', $this->out ) .']';
- }
-}
-
-class point
-{
- var $out;
-
- function point( $x, $y, $size_px )
- {
- $this->out = array();
- $this->out[] = $x;
- $this->out[] = $y;
- $this->out[] = $size_px;
- }
-
- function toString()
- {
- return '['. implode( ',', $this->out ) .']';
- }
-}
-
-// PIWIK SPECIAL ALIAS HACK - when updating Open Flash Chart, leave this line unchanged
-class graph extends Piwik_Visualization_OpenFlashChart {}
diff --git a/core/Visualization/Sparkline.php b/core/Visualization/Sparkline.php
index b0e60dbcbd..5dba26696a 100644
--- a/core/Visualization/Sparkline.php
+++ b/core/Visualization/Sparkline.php
@@ -21,15 +21,12 @@ require_once 'sparkline/lib/Sparkline_Line.php';
class Piwik_Visualization_Sparkline implements Piwik_iView
{
/**
- * Sets data. Must have format: array( array('value' => X),array('value' =>Y ), ...)
- *
+ * Array with format: array( x, y, z, ... )
* @param array $data
*/
- function setData($data)
+ function setValues($data)
{
- $this->data = $data;
- $this->width = self::getWidth();
- $this->height = self::getHeight();
+ $this->values = $data;
}
static public function getWidth()
@@ -39,14 +36,17 @@ class Piwik_Visualization_Sparkline implements Piwik_iView
static public function getHeight()
{
- return 20;
+ return 25;
}
function main()
{
- $data = $this->data;
+ $width = self::getWidth();
+ $height = self::getHeight();
+
+ $data = $this->values;
$sparkline = new Sparkline_Line();
- $sparkline->SetColor('lineColor', 22,44,74); // dark blue
+ $sparkline->SetColor('lineColor', 22, 44, 74); // dark blue
$sparkline->SetColorHtml('red', '#FF7F7F');
$sparkline->SetColorHtml('blue', '#55AAFF');
$sparkline->SetColorHtml('green', '#75BF7C');
@@ -54,37 +54,31 @@ class Piwik_Visualization_Sparkline implements Piwik_iView
$data = array_reverse($data);
$min = $max = $last = null;
$i = 0;
-
- foreach($this->data as $row)
+ foreach($this->values as $value)
{
- $value = $row['value'];
$sparkline->SetData($i, $value);
if( null == $min || $value <= $min[1])
{
$min = array($i, $value);
}
-
if(null == $max || $value >= $max[1])
{
$max = array($i, $value);
}
-
$last = array($i, $value);
- $i++;
+ $i++;
}
-
$sparkline->SetYMin(0);
- $sparkline->SetPadding(2); // setpadding is additive
- $sparkline->SetPadding(0,//13 font height
- 3, //4 * (strlen("$last[1]")),
- 0, //imagefontheight(FONT_2),
- 0);
+ $sparkline->setYMax($max[1] + 1); // the +1 seems to be mandatory to not lose some pixels when value = max
+ $sparkline->SetPadding( 3, 0, 2, 0);
$font = FONT_2;
- $sparkline->SetFeaturePoint($min[0]-1, $min[1], 'red', 5);
- $sparkline->SetFeaturePoint($max[0]-1, $max[1], 'green', 5);
- $sparkline->SetFeaturePoint($last[0]-1, $last[1], 'blue',5);
+ // the -0.5 is a hack as the sparkline samping rendering is obviously slightly bugged
+ // (see also fix marked as //FIX FROM PIWIK in libs/sparkline/lib/Sparkline.php)
+ $sparkline->SetFeaturePoint($min[0] -0.5, $min[1], 'red', 5);
+ $sparkline->SetFeaturePoint($max[0] -0.5, $max[1], 'green', 5);
+ $sparkline->SetFeaturePoint($last[0] -0.5, $last[1], 'blue', 5);
$sparkline->SetLineSize(3); // for renderresampled, linesize is on virtual image
- $sparkline->RenderResampled($this->width, $this->height, 'lineColor');
+ $sparkline->RenderResampled($width, $height);
$this->sparkline = $sparkline;
}