diff --git a/config/global.ini.php b/config/global.ini.php index c140cf21c9bc6ad117f0dcf18b0a6d0ae8d99d40..00596b39ec9199168fab339486e28399de0e96d4 100644 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -474,6 +474,10 @@ api_service_url = http://api.piwik.org ; eg. $period=range&date=previous10 becomes $period=day&date=previous10. Use this setting to override the $period value. graphs_default_period_to_plot_when_period_range = day +; When the ImageGraph plugin is activated, enabling this option causes the image graphs to show the evolution +; within the selected period instead of the evolution across the last n periods. +graphs_show_evolution_within_selected_period = 0 + ; The Overlay plugin shows the Top X following pages, Top X downloads and Top X outlinks which followed ; a view of the current page. The value X can be set here. overlay_following_pages_limit = 300 diff --git a/plugins/ImageGraph/ImageGraph.php b/plugins/ImageGraph/ImageGraph.php index 5bd61cc6a974f902fafc71e78c9a13423c21c925..d38aa8fddee5f7cfcf1d2ce6875febe718320e79 100644 --- a/plugins/ImageGraph/ImageGraph.php +++ b/plugins/ImageGraph/ImageGraph.php @@ -16,6 +16,7 @@ use Piwik\Period\Range; use Piwik\Site; use Piwik\TaskScheduler; use Piwik\Url; +use Piwik\Period\Factory as PeriodFactory; class ImageGraph extends \Piwik\Plugin { @@ -88,16 +89,27 @@ class ImageGraph extends \Piwik\Plugin $piwikSite = new Site($idSite); if ($periodForSinglePeriodGraph == 'range') { + // for period=range, show the configured sub-periods $periodForMultiplePeriodGraph = Config::getInstance()->General['graphs_default_period_to_plot_when_period_range']; $dateForMultiplePeriodGraph = $dateForSinglePeriodGraph; - } else { - $periodForMultiplePeriodGraph = $periodForSinglePeriodGraph; - $dateForMultiplePeriodGraph = Range::getRelativeToEndDate( - $periodForSinglePeriodGraph, - 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, - $dateForSinglePeriodGraph, - $piwikSite - ); + } else if ($info['period'] == 'day' || !Config::getInstance()->General['graphs_show_evolution_within_selected_period']) { + // for period=day, always show the last n days + // if graphs_show_evolution_within_selected_period=false, show the last n periods + $periodForMultiplePeriodGraph = $periodForSinglePeriodGraph; + $dateForMultiplePeriodGraph = Range::getRelativeToEndDate( + $periodForSinglePeriodGraph, + 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, + $dateForSinglePeriodGraph, + $piwikSite + ); + } else { + // if graphs_show_evolution_within_selected_period=true, show the days withing the period + // (except if the period is day, see above) + $periodForMultiplePeriodGraph = 'day'; + $period = PeriodFactory::build($info['period'], $info['date']); + $start = $period->getDateStart()->toString(); + $end = $period->getDateEnd()->toString(); + $dateForMultiplePeriodGraph = $start . ',' . $end; } }