422 lines
No EOL
16 KiB
Twig
422 lines
No EOL
16 KiB
Twig
{% extends 'base_embed.html.twig' %}
|
|
|
|
{% block title %}Graphique {{ theme_label }} - {{ stats.name }}{% endblock %}
|
|
|
|
{% block stylesheets %}
|
|
{{ parent() }}
|
|
<link href='{{ asset('js/maplibre/maplibre-gl.css') }}' rel='stylesheet'/>
|
|
<style>
|
|
.chart-container {
|
|
width: 100%;
|
|
height: 400px;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.stats-header {
|
|
background: #f8f9fa;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.action-bar {
|
|
background: white;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
border: 1px solid #dee2e6;
|
|
margin-bottom: 20px;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 10px;
|
|
align-items: center;
|
|
}
|
|
|
|
.action-bar .btn {
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.stats-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 15px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.stat-card {
|
|
background: white;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
border: 1px solid #dee2e6;
|
|
text-align: center;
|
|
}
|
|
|
|
.stat-value {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
color: #0d6efd;
|
|
}
|
|
|
|
.stat-label {
|
|
font-size: 14px;
|
|
color: #6c757d;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
.chart-tabs {
|
|
display: flex;
|
|
margin-bottom: 20px;
|
|
border-bottom: 1px solid #dee2e6;
|
|
}
|
|
|
|
.chart-tab {
|
|
padding: 10px 20px;
|
|
background: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
border-bottom: 3px solid transparent;
|
|
}
|
|
|
|
.chart-tab.active {
|
|
border-bottom-color: #0d6efd;
|
|
color: #0d6efd;
|
|
}
|
|
|
|
.chart-content {
|
|
display: none;
|
|
}
|
|
|
|
.chart-content.active {
|
|
display: block;
|
|
}
|
|
|
|
#themeMap {
|
|
height: 400px;
|
|
width: 100%;
|
|
border-radius: 8px;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
.maplibregl-popup-content {
|
|
font-size: 0.95em;
|
|
}
|
|
.btn-josm {
|
|
margin-bottom: 1rem;
|
|
}
|
|
</style>
|
|
{% endblock %}
|
|
|
|
{% block body %}
|
|
<div class="container-fluid">
|
|
{# DEBUG : Affichage des objets Place trouvés pour cette ville #}
|
|
{% if places is defined %}
|
|
<div class="alert alert-warning" style="font-size:0.95em;">
|
|
<b>DEBUG : Objets Place trouvés pour cette ville (avant filtrage)</b><br>
|
|
<table class="table table-sm table-bordered mt-2 mb-0">
|
|
<thead><tr>
|
|
<th>#</th><th>id</th><th>main_tag</th><th>osm_kind</th><th>nom</th><th>lat</th><th>lon</th>
|
|
</tr></thead>
|
|
<tbody>
|
|
{% for p in places %}
|
|
<tr>
|
|
<td>{{ loop.index }}</td>
|
|
<td>{{ p.getOsmId() }}</td>
|
|
<td>{{ p.getMainTag() }}</td>
|
|
<td>{{ p.getOsmKind() }}</td>
|
|
<td>{{ p.getName() }}</td>
|
|
<td>{{ p.getLat() }}</td>
|
|
<td>{{ p.getLon() }}</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{% endif %}
|
|
<div class="stats-header">
|
|
<div class="d-flex justify-content-between align-items-start">
|
|
<div>
|
|
<h2>
|
|
<i class="bi {{ icons[theme]|default('bi-question-circle') }}"></i>
|
|
{{ theme_label }} - {{ stats.name }}
|
|
</h2>
|
|
<p class="mb-0">Code INSEE: {{ stats.zone }}</p>
|
|
</div>
|
|
<a href="{{ path('app_admin_stats', {'insee_code': stats.zone}) }}" class="btn btn-outline-secondary">
|
|
<i class="bi bi-arrow-left"></i> Retour aux stats
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="action-bar">
|
|
<a href="{{ path('app_admin_stats', {'insee_code': stats.zone}) }}" class="btn btn-primary">
|
|
<i class="bi bi-bar-chart"></i> Stats de la ville
|
|
</a>
|
|
<a href="{{ path('app_admin_labourer', {'insee_code': stats.zone}) }}" class="btn btn-warning">
|
|
<i class="bi bi-arrow-clockwise"></i> Labourer la ville
|
|
</a>
|
|
<a href="{{ path('admin_followup_graph', {'insee_code': stats.zone}) }}" class="btn btn-info">
|
|
<i class="bi bi-graph-up"></i> Suivi OSM (graphes)
|
|
</a>
|
|
<a href="{{ path('admin_followup_embed_graph', {'insee_code': stats.zone, 'theme': theme}) }}" class="btn btn-success" target="_blank">
|
|
<i class="bi bi-box-arrow-up-right"></i> Graphe embedded
|
|
</a>
|
|
<a href="{{ path('app_admin') }}" class="btn btn-secondary">
|
|
<i class="bi bi-house"></i> Accueil admin
|
|
</a>
|
|
</div>
|
|
|
|
{% if josm_url %}
|
|
<a href="{{ josm_url }}" class="btn btn-outline-dark btn-josm" target="_blank">
|
|
<i class="bi bi-box-arrow-up-right"></i> Ouvrir tous les objets dans JOSM
|
|
</a>
|
|
{% else %}
|
|
<div class="alert alert-info mb-3">Aucun objet sélectionné pour ce thème, rien à charger dans JOSM.</div>
|
|
{% endif %}
|
|
<div id="themeMap"></div>
|
|
|
|
<div class="stats-grid">
|
|
<div class="stat-card">
|
|
<div class="stat-value" id="currentCount">-</div>
|
|
<div class="stat-label">Nombre actuel</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" id="currentCompletion">-</div>
|
|
<div class="stat-label">Complétion actuelle</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" id="dataPoints">-</div>
|
|
<div class="stat-label">Points de données</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" id="lastUpdate">-</div>
|
|
<div class="stat-label">Dernière mise à jour</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chart-tabs">
|
|
<button class="chart-tab active" data-chart="count">Nombre d'objets</button>
|
|
<button class="chart-tab" data-chart="completion">Pourcentage de complétion</button>
|
|
</div>
|
|
|
|
<div class="chart-content active" id="count-chart">
|
|
<div class="chart-container">
|
|
<canvas id="countChart"></canvas>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chart-content" id="completion-chart">
|
|
<div class="chart-container">
|
|
<canvas id="completionChart"></canvas>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block javascripts %}
|
|
{{ parent() }}
|
|
<script src='{{ asset('js/maplibre/maplibre-gl.js') }}'></script>
|
|
<script>
|
|
const geojson = {{ geojson|raw }};
|
|
const mapToken = '{{ maptiler_token }}';
|
|
const mapCenter = {{ center|json_encode|raw }};
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
console.log('[DEBUG] mapToken:', mapToken);
|
|
console.log('[DEBUG] geojson:', geojson);
|
|
console.log('[DEBUG] geojson.features:', geojson ? geojson.features : undefined);
|
|
console.log('[DEBUG] mapCenter:', mapCenter);
|
|
if (mapToken && geojson && geojson.features && geojson.features.length > 0) {
|
|
console.log('[DEBUG] Initialisation de la carte Maplibre...');
|
|
const map = new maplibregl.Map({
|
|
container: 'themeMap',
|
|
style: `https://api.maptiler.com/maps/streets/style.json?key=${mapToken}`,
|
|
center: mapCenter || geojson.features[0].geometry.coordinates,
|
|
zoom: 13
|
|
});
|
|
map.addControl(new maplibregl.NavigationControl());
|
|
geojson.features.forEach(f => {
|
|
let color = f.properties.is_complete ? '#198754' : '#adb5bd';
|
|
if (!f.properties.is_complete && (f.properties.tags && (f.properties.tags.name || f.properties.tags.operator))) {
|
|
color = '#ffc107'; // partiel
|
|
}
|
|
const marker = new maplibregl.Marker({ color: color })
|
|
.setLngLat(f.geometry.coordinates)
|
|
.setPopup(new maplibregl.Popup({ offset: 18 })
|
|
.setHTML(`
|
|
<div style='min-width:180px'>
|
|
<strong>${f.properties.name || '(sans nom)'}</strong><br>
|
|
<span class='text-muted'>${f.properties.osm_kind} ${f.properties.id}</span><br>
|
|
<span style='font-size:0.95em;'>
|
|
${Object.entries(f.properties.tags).map(([k,v]) => `<span><b>${k}</b>: ${v}</span>`).join('<br>')}
|
|
</span>
|
|
<a href='${f.properties.osm_url}' target='_blank'>Voir sur OSM</a>
|
|
</div>
|
|
`)
|
|
)
|
|
.addTo(map);
|
|
});
|
|
} else {
|
|
console.warn('[DEBUG] Carte non initialisée : conditions non remplies.');
|
|
if (!mapToken) {
|
|
console.warn('[DEBUG] mapToken manquant ou vide');
|
|
}
|
|
if (!geojson) {
|
|
console.warn('[DEBUG] geojson manquant ou vide');
|
|
}
|
|
if (!geojson || !geojson.features || geojson.features.length === 0) {
|
|
console.warn('[DEBUG] geojson.features vide ou non défini');
|
|
}
|
|
// Affichage d'un message dans la page
|
|
const mapDiv = document.getElementById('themeMap');
|
|
if (mapDiv) {
|
|
mapDiv.innerHTML = '<div style="color:red;font-weight:bold;padding:2em;text-align:center;">Carte non initialisée : données manquantes ou incomplètes (voir console pour debug)</div>';
|
|
}
|
|
}
|
|
});
|
|
</script>
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
|
|
|
|
<script>
|
|
const countData = {{ count_data|raw }};
|
|
const completionData = {{ completion_data|raw }};
|
|
|
|
// Mettre à jour les statistiques
|
|
function updateStats() {
|
|
if (countData.length > 0) {
|
|
const latestCount = countData[countData.length - 1];
|
|
document.getElementById('currentCount').textContent = latestCount.value;
|
|
document.getElementById('lastUpdate').textContent = new Date(latestCount.date).toLocaleDateString('fr-FR');
|
|
}
|
|
|
|
if (completionData.length > 0) {
|
|
const latestCompletion = completionData[completionData.length - 1];
|
|
document.getElementById('currentCompletion').textContent = latestCompletion.value + '%';
|
|
}
|
|
|
|
document.getElementById('dataPoints').textContent = Math.max(countData.length, completionData.length);
|
|
}
|
|
|
|
// Configuration commune pour les graphiques
|
|
const commonOptions = {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
plugins: {
|
|
legend: {
|
|
display: false
|
|
},
|
|
tooltip: {
|
|
mode: 'index',
|
|
intersect: false,
|
|
}
|
|
},
|
|
scales: {
|
|
x: {
|
|
type: 'time',
|
|
time: {
|
|
unit: 'day',
|
|
displayFormats: {
|
|
day: 'dd/MM/yyyy'
|
|
}
|
|
},
|
|
title: {
|
|
display: true,
|
|
text: 'Date'
|
|
}
|
|
},
|
|
y: {
|
|
beginAtZero: true,
|
|
title: {
|
|
display: true
|
|
}
|
|
}
|
|
},
|
|
interaction: {
|
|
mode: 'nearest',
|
|
axis: 'x',
|
|
intersect: false
|
|
}
|
|
};
|
|
|
|
// Graphique du nombre d'objets
|
|
const countCtx = document.getElementById('countChart').getContext('2d');
|
|
const countChart = new Chart(countCtx, {
|
|
type: 'line',
|
|
data: {
|
|
datasets: [{
|
|
label: 'Nombre d\'objets',
|
|
data: countData.map(d => ({
|
|
x: new Date(d.date),
|
|
y: d.value
|
|
})),
|
|
borderColor: '#0d6efd',
|
|
backgroundColor: 'rgba(13, 110, 253, 0.1)',
|
|
borderWidth: 2,
|
|
fill: true,
|
|
tension: 0.1
|
|
}]
|
|
},
|
|
options: {
|
|
...commonOptions,
|
|
scales: {
|
|
...commonOptions.scales,
|
|
y: {
|
|
...commonOptions.scales.y,
|
|
title: {
|
|
display: true,
|
|
text: 'Nombre d\'objets'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// Graphique de la complétion
|
|
const completionCtx = document.getElementById('completionChart').getContext('2d');
|
|
const completionChart = new Chart(completionCtx, {
|
|
type: 'line',
|
|
data: {
|
|
datasets: [{
|
|
label: 'Pourcentage de complétion',
|
|
data: completionData.map(d => ({
|
|
x: new Date(d.date),
|
|
y: d.value
|
|
})),
|
|
borderColor: '#198754',
|
|
backgroundColor: 'rgba(25, 135, 84, 0.1)',
|
|
borderWidth: 2,
|
|
fill: true,
|
|
tension: 0.1
|
|
}]
|
|
},
|
|
options: {
|
|
...commonOptions,
|
|
scales: {
|
|
...commonOptions.scales,
|
|
y: {
|
|
...commonOptions.scales.y,
|
|
max: 100,
|
|
title: {
|
|
display: true,
|
|
text: 'Pourcentage de complétion (%)'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// Gestion des onglets
|
|
document.querySelectorAll('.chart-tab').forEach(tab => {
|
|
tab.addEventListener('click', function() {
|
|
// Retirer la classe active de tous les onglets
|
|
document.querySelectorAll('.chart-tab').forEach(t => t.classList.remove('active'));
|
|
document.querySelectorAll('.chart-content').forEach(c => c.classList.remove('active'));
|
|
|
|
// Ajouter la classe active à l'onglet cliqué
|
|
this.classList.add('active');
|
|
const chartId = this.getAttribute('data-chart') + '-chart';
|
|
document.getElementById(chartId).classList.add('active');
|
|
});
|
|
});
|
|
|
|
// Initialiser les statistiques
|
|
updateStats();
|
|
</script>
|
|
{% endblock %} |