Files
o2o-castad-backend/app/backoffice/frontend/templates/sqladmin/traffic_base.html
T

72 lines
2.6 KiB
HTML

{% extends "sqladmin/layout.html" %}
{% block content_header %}
<div class="row align-items-center">
<div class="col">
<h2 class="page-title">{{ title }}</h2>
<div class="page-pretitle">{{ subtitle }}</div>
</div>
<div class="col-auto">
<div class="btn-group" role="group" aria-label="기간">
{% for d in days_options %}
<a href="?days={{ d }}" class="btn btn-sm {{ 'btn-primary' if d == period.days else 'btn-outline-primary' }}"
{% if d == period.days %}aria-current="page"{% endif %}>{{ d }}일</a>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% block tail %}
<style>
.traffic-chart { position: relative; height: 280px; }
.traffic-num { font-variant-numeric: tabular-nums; }
</style>
<script type="application/json" id="traffic-charts">{{ charts | tojson }}</script>
<script src="{{ chart_js_url }}"></script>
<script>
(function () {
var el = document.getElementById("traffic-charts");
if (!el || !window.Chart) return;
var charts = JSON.parse(el.textContent);
var ink = "#52514e", grid = "#e8e7e3", surface = "#ffffff";
Chart.defaults.color = ink;
Chart.defaults.font.family = getComputedStyle(document.body).fontFamily;
charts.forEach(function (c) {
var canvas = document.getElementById(c.id);
if (!canvas) return;
var stacked = c.type === "stacked";
var datasets = c.datasets.map(function (d) {
if (stacked) {
// 누적 막대: 조각 사이 2px 배경색 틈
return { label: d.label, data: d.data, backgroundColor: d.color, borderColor: surface,
borderWidth: { top: 2 }, borderSkipped: "bottom", maxBarThickness: 32 };
}
return { label: d.label, data: d.data, borderColor: d.color, backgroundColor: d.color,
borderWidth: 2, pointRadius: 0, pointHoverRadius: 4, pointHitRadius: 12, tension: 0 };
});
new Chart(canvas, {
type: stacked ? "bar" : "line",
data: { labels: c.labels, datasets: datasets },
options: {
responsive: true,
maintainAspectRatio: false,
interaction: { mode: "index", intersect: false },
plugins: {
// 범례 키: 선 그래프는 짧은 선, 막대는 사각형
legend: { position: "top", align: "start",
labels: { usePointStyle: true, pointStyle: stacked ? "rect" : "line", pointStyleWidth: 18 } },
tooltip: { mode: "index", intersect: false }
},
scales: {
x: { stacked: stacked, grid: { display: false } },
y: { stacked: stacked, beginAtZero: true, grid: { color: grid }, ticks: { precision: 0 } }
}
}
});
});
})();
</script>
{% endblock %}