diff --git a/admin/stats.php b/admin/stats.php index b992d7532..0db7e2f2a 100644 --- a/admin/stats.php +++ b/admin/stats.php @@ -116,9 +116,12 @@ ORDER BY $limit = ($last - 1)*12+$date->format('n') - 1; $query .= ' LIMIT '.$limit; + $result = query2array($query.';'); + $lastDate = $date->sub(new DateInterval('P'.($last - 1).'Y'.($date->format('n') - 1).'M')); + return set_missing_values('month', $result, false, $lastDate, new DateTime()); } - return query2array($query.';'); + return set_missing_values('month', query2array($query.';'), false); } function get_month_stats() @@ -155,12 +158,31 @@ ORDER BY foreach (query2array($query) as $value) { $date = get_date_object($value); - @$months[$date->format('Y-m')][] = $value; + @$months[$date->format('Y/m/1')][] = $value; + } + + $actual_date = new DateTime(); + if (!isset($months[$actual_date->format('Y/m/1')])) + { + @$months[$actual_date->format('Y/m/1')][] = array( + 'year' => $actual_date->format('Y'), + 'month'=> $actual_date->format('n'), + 'day'=> null, + 'hour'=> null, + 'nb_pages' => 0 + ); } foreach ($months as $key => $val) { - $result['month'][] = set_missing_values('day',$val, false); + $lastDate = new DateTime($key); + $lastDate = $lastDate->add(new DateInterval('P1M')); + $lastDate = $lastDate->sub(new DateInterval('P1D')); + if ($lastDate > new DateTime()) + { + $lastDate = new DateTime(); + } + $result['month'][] = set_missing_values('day',$val, false, new DateTime($key), $lastDate); } $query = ' @@ -190,6 +212,12 @@ ORDER BY check_status(ACCESS_ADMINISTRATOR); +// +-----------------------------------------------------------------------+ +// | Refresh summary from details | +// +-----------------------------------------------------------------------+ + +history_summarize(); + // +-----------------------------------------------------------------------+ // | Display statistics header | // +-----------------------------------------------------------------------+ @@ -212,11 +240,16 @@ $template->assign( // | Set missing rows to 0 | // +-----------------------------------------------------------------------+ -function set_missing_values($unit, $data, $keep_size=true) +function set_missing_values($unit, $data, $keep_size=true, $firstDate = null, $lastDate = null) { $limit = count($data); $result = array(); - $date = get_date_object($data[count($data) - 1]); + if ($firstDate == null) + { + $date = get_date_object($data[count($data) - 1]); + } else { + $date = $firstDate; + } //Declare variable according the unit if ($unit == 'year') @@ -249,7 +282,12 @@ function set_missing_values($unit, $data, $keep_size=true) $date->add(new DateInterval($date_add)); } } else { - $date_end = get_date_object($data[0]); + if ($lastDate == null) + { + $date_end = get_date_object($data[0]); + } else { + $date_end = $lastDate; + } while ($date <= $date_end) { $result[$date->format($date_format)] = 0; $date->add(new DateInterval($date_add)); @@ -297,7 +335,10 @@ function get_date_object($row) // | Send data to template | // +-----------------------------------------------------------------------+ -$template->append('compareYears', set_missing_values('month', get_month_of_last_years($conf['stat_compare_year_displayed']), false)); +$template->append( + 'compareYears', + get_month_of_last_years($conf['stat_compare_year_displayed']) +); $template->append('monthStats', get_month_stats()); $template->append('lastHours', set_missing_values('hour',get_last(72, 'hour'))); $template->append('lastDays', set_missing_values('day',get_last(90, 'day'))); diff --git a/admin/themes/default/js/stats.js b/admin/themes/default/js/stats.js index 0b0a4d3e5..a51862e8b 100644 --- a/admin/themes/default/js/stats.js +++ b/admin/themes/default/js/stats.js @@ -35,7 +35,6 @@ Chart.defaults.global.elements.point.radius = 0.1; Chart.defaults.global.elements.point.hitRadius = 10 Chart.defaults.global.defaultFontSize = 14; Chart.defaults.global.defaultFontColor = '#888'; -Chart.defaults.global.tooltips.mode = 'index'; Chart.defaults.global.tooltips.intersect = false; Chart.defaults.global.legend.onClick = null; @@ -74,6 +73,13 @@ function changeData(dataType, options = displayOptions) { }, legend: { display:false + }, + tooltips: { + mode: 'index' + }, + hover : + { + intersect : false, } } statGraph.options.scales.xAxes.forEach(axe => { @@ -84,6 +90,12 @@ function changeData(dataType, options = displayOptions) { statGraph.update(); } else { statGraph.options.legend.display = true; + statGraph.options.hover = { + intersect : true + } + statGraph.options.tooltips = { + mode : 'nearest' + } if (dataType == "years") { statGraph.data = { datasets: getComparedYearDataset() @@ -91,7 +103,16 @@ function changeData(dataType, options = displayOptions) { statGraph.options.scales = { xAxes: [{ type: 'category', - labels: str_months + labels: str_months, + gridLines: { + display: false + } + }], + yAxes: [{ + scaleLabel: { + display: true, + labelString: 'Page visited' + } }] } } else if (dataType == "months") { @@ -105,7 +126,16 @@ function changeData(dataType, options = displayOptions) { statGraph.options.scales = { xAxes: [{ type: 'category', - labels : days + labels : days, + gridLines: { + display: false + } + }], + yAxes: [{ + scaleLabel: { + display: true, + labelString: 'Page visited' + } }] } } @@ -141,7 +171,7 @@ function getComparedYearDataset() { Object.keys(values).forEach(function(key) { dataset.push({ - label : str_number_page_visited_with_year.replace('%s', key), + label : key, data : values[key], lineTension : 0.2, borderColor : colors[parseInt(key) % colors.length], @@ -164,9 +194,8 @@ function getMonthStatsDataset() { date = new Date(key) days_data[parseInt(date.getUTCDate()) - 1] = values[key]; }); - console.log(days_data); dataset.push({ - label : str_number_page_visited_with_year.replace('%s', str_months[date.getMonth()]+" "+date.getFullYear()), + label : str_months[date.getMonth()]+" "+date.getFullYear(), data : days_data, lineTension : 0.2, borderColor : colors[colorIndice % colors.length], diff --git a/admin/themes/default/template/stats.tpl b/admin/themes/default/template/stats.tpl index 97c65eeec..d97e5fe5a 100644 --- a/admin/themes/default/template/stats.tpl +++ b/admin/themes/default/template/stats.tpl @@ -57,5 +57,5 @@ moment.locale("{$langCode}");