2023-07-24 20:56:46 +02:00
|
|
|
{% import "includes/macros" as macros %}
|
|
|
|
|
|
|
|
{% extends "base" %}
|
|
|
|
|
|
|
|
{% block content %}
|
|
|
|
|
|
|
|
|
2023-07-30 14:33:50 +02:00
|
|
|
<div class="max-w-screen-lg w-full">
|
2023-09-27 15:36:07 +02:00
|
|
|
<h1 class="h1">Statistik</h1>
|
2023-09-28 11:52:14 +02:00
|
|
|
<div class="bg-gray-200 p-3 mt-4 rounded-t-md">
|
|
|
|
<label for="name" class="sr-only">Suche</label>
|
|
|
|
<input type="search" name="name" id="filter-js" class="w-full relative block rounded-md border-0 py-1.5 px-2 text-gray-900 ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-primary-600 sm:text-sm sm:leading-6 mb-2 md:mb-0" placeholder="Suchen nach Namen...">
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="filter-result-js" class="bg-gray-200 text-primary-950 pb-3 px-3 text-right"></div>
|
|
|
|
|
|
|
|
<div class="border-r border-l">
|
2023-09-28 09:26:30 +02:00
|
|
|
{% set_global km = 0 %}
|
2023-09-28 11:52:14 +02:00
|
|
|
{% set_global index = 1 %}
|
2023-07-30 14:33:50 +02:00
|
|
|
{% for s in stat %}
|
2023-09-28 11:52:14 +02:00
|
|
|
<div class="border-t {% if loop.last %} border-b {% endif %} bg-white flex justify-between items-center px-3 py-1" data-filterable="true" data-filter="{{ s.name }}">
|
|
|
|
<span class="text-sm text-gray-600 w-10">
|
|
|
|
{% if km != s.rowed_km %}
|
|
|
|
{{loop.index}}
|
|
|
|
{% set_global index = loop.index %}
|
|
|
|
{% else %}
|
|
|
|
{{ index }}
|
|
|
|
{% endif %}
|
|
|
|
</span>
|
|
|
|
<span class="grow">{{s.name}}</span>
|
2023-09-27 15:55:17 +02:00
|
|
|
<span>{{s.rowed_km}} km</span>
|
2023-09-28 11:52:14 +02:00
|
|
|
|
2023-09-28 09:26:30 +02:00
|
|
|
{% set_global km = s.rowed_km %}
|
2023-09-28 11:52:14 +02:00
|
|
|
</div>
|
2023-07-30 14:33:50 +02:00
|
|
|
{% endfor %}
|
2023-09-28 11:52:14 +02:00
|
|
|
</div>
|
2023-10-01 13:40:36 +02:00
|
|
|
<div id="container" class="w-full"></div>
|
2023-07-30 14:33:50 +02:00
|
|
|
</div>
|
2023-10-01 13:40:36 +02:00
|
|
|
|
|
|
|
<script type="module">
|
|
|
|
|
|
|
|
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
|
|
|
|
|
|
|
|
|
2023-10-01 14:19:23 +02:00
|
|
|
const data = [
|
|
|
|
{ date: '2023-01-01', km: 5 },
|
|
|
|
{ date: '2023-02-01', km: 24 },
|
|
|
|
{ date: '2023-08-30', km: 1340 },
|
|
|
|
];
|
2023-10-01 13:40:36 +02:00
|
|
|
|
2023-10-01 14:19:23 +02:00
|
|
|
const margin = { top: 20, right: 20, bottom: 50, left: 50 },
|
|
|
|
width = 960 - margin.left - margin.right,
|
|
|
|
height = 500 - margin.top - margin.bottom;
|
2023-10-01 13:40:36 +02:00
|
|
|
|
2023-10-01 14:19:23 +02:00
|
|
|
const parseTime = d3.timeParse('%Y-%m-%d');
|
2023-10-01 13:40:36 +02:00
|
|
|
|
2023-10-01 14:19:23 +02:00
|
|
|
data.forEach(d => {
|
|
|
|
d.date = parseTime(d.date);
|
|
|
|
d.km = +d.km;
|
2023-10-01 13:40:36 +02:00
|
|
|
});
|
|
|
|
|
2023-10-01 14:19:23 +02:00
|
|
|
const x = d3.scaleTime()
|
|
|
|
.domain(d3.extent(data, d => d.date))
|
|
|
|
.range([0, width]);
|
|
|
|
|
|
|
|
const y = d3.scaleLinear()
|
|
|
|
.domain([0, d3.max(data, d => d.km)])
|
|
|
|
.range([height, 0]);
|
|
|
|
|
|
|
|
const line = d3.line()
|
|
|
|
.x(d => x(d.date))
|
|
|
|
.y(d => y(d.km));
|
|
|
|
|
|
|
|
const svg = d3.select('#container')
|
|
|
|
.append('svg')
|
|
|
|
.attr('width', width + margin.left + margin.right)
|
|
|
|
.attr('height', height + margin.top + margin.bottom)
|
|
|
|
.append('g')
|
|
|
|
.attr('transform', `translate(${margin.left},${margin.top})`);
|
|
|
|
|
|
|
|
svg.append('path')
|
|
|
|
.data([data])
|
|
|
|
.attr('class', 'line')
|
|
|
|
.attr('d', line);
|
|
|
|
|
|
|
|
svg.append('g')
|
|
|
|
.attr('transform', `translate(0,${height})`)
|
|
|
|
.call(d3.axisBottom(x));
|
|
|
|
|
|
|
|
svg.append('g')
|
|
|
|
.call(d3.axisLeft(y));
|
2023-10-01 13:40:36 +02:00
|
|
|
</script>
|
2023-10-01 14:19:23 +02:00
|
|
|
<style>
|
|
|
|
.line {
|
|
|
|
fill: none;
|
|
|
|
stroke: steelblue;
|
|
|
|
stroke-width: 2px;
|
|
|
|
}
|
|
|
|
</style>
|
2023-07-24 20:56:46 +02:00
|
|
|
{% endblock content%}
|