{# # ============================================================================ # ORGANISM: ECO FOOTPRINT # ============================================================================ # # Section empreinte écologique du dashboard. # Affiche 3 métriques (énergie, CO2, eau) + graphique barres hebdomadaire. # # ============================================================================ # COMPOSITION (Molécules/Atomes utilisés) # ============================================================================ # # - _atoms/icon/icon.html.twig # # ============================================================================ # PARAMÈTRES # ============================================================================ # # | Paramètre | Type | Défaut | Description | # |-----------------|---------|------------|------------------------------------| # | totalWh | float | 0 | Énergie totale en Wh | # | weeklyData | array | [] | Données hebdo [{day, val}] | # | weekDelta | string | null | Variation vs semaine passée | # | period | string | null | Période affichée (ex: 'Fév. 2026')| # | class | string | '' | Classes additionnelles | # # ============================================================================ # EXEMPLES D'UTILISATION # ============================================================================ # # {% include '_organisms/eco-footprint/eco-footprint.html.twig' with { # totalWh: 152.4, # weeklyData: [ # { day: 'Lun', val: 18.4 }, # { day: 'Mar', val: 31.2 }, # { day: 'Mer', val: 12.7 }, # { day: 'Jeu', val: 44.9 }, # { day: 'Ven', val: 34.7 }, # { day: 'Sam', val: 8.3 }, # { day: 'Dim', val: 2.1 } # ], # weekDelta: '-12%', # period: 'Fevrier 2026' # } only %} # # ============================================================================ #} {# ============================================================================ CONFIGURATION DES VALEURS PAR DÉFAUT ============================================================================ #} {% set totalWh = totalWh ?? 0 %} {% set weeklyData = weeklyData ?? [] %} {% set weekDelta = weekDelta ?? null %} {% set period = period ?? null %} {% set class = class ?? '' %} {# Calculs derives (sources : IEA 2024, Google Environmental Report 2024) #} {% set co2 = totalWh * 0.590 %} {% set water = totalWh * 0.00216 %} {# Max pour normaliser les barres #} {% set maxWeekVal = 1 %} {% for d in weeklyData %} {% if d.val > maxWeekVal %}{% set maxWeekVal = d.val %}{% endif %} {% endfor %} {# ============================================================================ RENDU HTML ============================================================================ #}
{# ===== METRIQUES (gauche) ===== #}
{# Energie #}
{% include '_atoms/icon/icon.html.twig' with { name: 'bolt', size: 'lg', color: 'success' } only %}
Énergie consommée
{{ totalWh|number_format(1, ',', ' ') }} Wh
{# 1 recherche Google ≈ 0.3 Wh (source : IEA 2024) #}
{# CO₂ #}
{% include '_atoms/icon/icon.html.twig' with { name: 'cloud', size: 'lg', color: 'warning' } only %}
CO₂ émis
{{ co2|number_format(1, ',', ' ') }} g
{# 1 km en voiture ≈ 122 g CO₂ (source : ADEME 2023, véhicule moyen FR) #}
{# Eau #}
{% include '_atoms/icon/icon.html.twig' with { name: 'earth', size: 'lg', color: 'info' } only %}
Eau (refroidissement)
{% if water >= 1 %} {{ water|number_format(1, ',', ' ') }} L {% else %} {{ (water * 1000)|number_format(0) }} mL {% endif %}
{# 1 verre d'eau = 0.25 L #}
{# Séparateur : horizontal sur mobile, vertical sur desktop #}
{# ===== GRAPHIQUE HEBDOMADAIRE (droite) ===== #}
Énergie cette semaine Wh / jour
{% if weekDelta %} {% set deltaIsDown = weekDelta starts with '-' %} {{ deltaIsDown ? '↓' : '↑' }} {{ weekDelta }} vs sem. passée {% endif %}
{% for d in weeklyData %} {% set barHeight = maxWeekVal > 0 ? (d.val / maxWeekVal * 110) : 0 %} {# Dégradé vertical : vert (bas) → orange (moyen) → rouge (haut) selon intensité #} {% set ratio = maxWeekVal > 0 ? d.val / maxWeekVal : 0 %} {% if ratio > 0.7 %} {% set gradientStyle = 'background: linear-gradient(to top, #D97706, #DC2626)' %} {% set glowStyle = 'box-shadow: 0 4px 16px rgba(220, 38, 38, 0.2)' %} {% elseif ratio > 0.35 %} {% set gradientStyle = 'background: linear-gradient(to top, #F59E0B, #EA580C)' %} {% set glowStyle = 'box-shadow: 0 4px 16px rgba(245, 158, 11, 0.2)' %} {% else %} {% set gradientStyle = 'background: linear-gradient(to top, #34D399, #309344)' %} {% set glowStyle = 'box-shadow: 0 4px 16px rgba(48, 147, 68, 0.15)' %} {% endif %}
{# Valeur au-dessus #} {% if d.val > 0 %}{{ d.val|number_format(1, ',', ' ') }}{% endif %} {# Barre avec dégradé vertical #}
{# Jour #} {{ d.day }}
{% endfor %} {% if weeklyData|length == 0 %} {# Barres vides si aucune donnée #} {% for day in ['Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam', 'Dim'] %}
{{ day }}
{% endfor %} {% endif %}