Файл: upload/core/functions/chart.php
Строк: 33
<?php
function renderDiagram($title, $footerText, $query, $start, $end)
{
// Получаем данные
$res = dbquery($query, [$start, $end]);
$total = DataNumRows($res);
// Определяем месяц
$year = date('Y');
$month = date('m');
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
// Массив под дни
$stats = array_fill(1, $daysInMonth, 0);
// Заполняем статистику
while ($row = FetchAssoc($res)) {
$ts = (int)$row[array_key_first($row)];
$day = (int)date('j', $ts);
if ($day >= 1 && $day <= $daysInMonth) {
$stats[$day]++;
}
}
// Максимум
$maxValue = max($stats);
if ($maxValue < 1) $maxValue = 1;
// Рендер
echo '<div class="diagram-info">
<div class="head_info-dia"><div class="title_dia">'.$title.'</div></div>
<div class="chart">';
// Сетка
$gridSteps = 4;
$offset = 40;
echo '<div class="axis-y"></div><div class="axis-x"></div>';
for ($i = 0; $i <= $gridSteps; $i++) {
$percent = ($i / $gridSteps) * 100;
$label = round($maxValue * ($i / $gridSteps));
echo '<div class="grid-line" style="bottom: calc('.$percent.'% + '.$offset.'px);"></div>';
echo '<div class="grid-label" style="bottom: calc('.$percent.'% + '.$offset.'px);">'.$label.'</div>';
}
// Столбцы
echo '<div class="bars">';
for ($day = 1; $day <= $daysInMonth; $day++) {
$value = $stats[$day];
$heightPercent = ($value / $maxValue) * 100;
echo '<div class="bargot">
<div class="bar-value">'.$value.'</div>
<div class="bar-inner">
<div class="bar-fill" style="height:'.$heightPercent.'%;"></div>
</div>
<div class="bar-day">'.$day.'</div>
</div>';
}
echo '</div></div>';
echo '<div class="footer_info-dia">
<div class="info_dia">'.$total.' '.$footerText.'</div>
</div>
</div>';
}
?>