diff --git a/maquettes/accueil-carte/index.html b/maquettes/accueil-carte/index.html index 989f899..ec9fd9f 100644 --- a/maquettes/accueil-carte/index.html +++ b/maquettes/accueil-carte/index.html @@ -175,7 +175,26 @@ a{color:inherit} .plein-onglets{display:flex;gap:6px;overflow-x:auto} .plein-onglets button{font:inherit;font-size:12px;font-weight:600;border:1px solid var(--roche);background:#faf9f5;color:var(--roche);border-radius:0;padding:6px 9px;cursor:pointer;white-space:nowrap} .plein-onglets button.on{background:var(--roche);color:#fff} -.plein-corps{max-width:980px;margin:0 auto;padding:20px 16px 64px} +.plein-corps{max-width:1200px;margin:0 auto;padding:20px 16px 64px} +[data-aff=acces] .plein-corps{max-width:1480px} +.plein-periode{display:flex;gap:8px;margin-top:16px} +.plein-periode button{font:inherit;font-weight:600;color:var(--sapin);background:none;border:1px solid var(--sapin);padding:7px 12px;cursor:pointer} +.plein-periode button[aria-pressed=true]{background:var(--sapin);color:#fff} +[data-aff=acces] .plein-periode button{min-height:44px} +.plein-lacune{margin:16px 0 0;color:var(--roche)} +.plein-fiche{margin-top:32px;padding-top:18px;border-top:1px solid var(--roche)} +.plein-fiche h3{margin:0;font-family:var(--titre);font-weight:600;font-size:20px;color:var(--sapin)} +.plein-fiche dl{display:grid;grid-template-columns:max-content 1fr;gap:6px 16px;margin:12px 0 0;font-size:14px} +.plein-fiche dt{color:var(--gris)}.plein-fiche dd{margin:0;min-width:0;overflow-wrap:anywhere} +.plein-fiche a{color:var(--sapin);text-underline-offset:2px} +.fiche-photos{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin:16px 0 0;max-width:720px} +.fiche-photos img{display:block;width:100%;aspect-ratio:4/3;object-fit:cover;border:1px solid var(--pierre)} +.fiche-forum{display:inline-block;margin-top:14px;font-weight:600;color:var(--sapin);border:1px solid var(--sapin);padding:8px 12px;text-decoration:none} +.fiche-forum:hover{background:var(--sapin);color:#fff} +.fiche-bientot{margin:14px 0 0;font-size:13px;color:var(--gris)} +[data-aff=acces] .plein-fiche dl{font-size:16px}[data-aff=acces] .fiche-bientot{font-size:15px;color:var(--roche)} +[data-aff=acces] .fiche-forum{min-height:44px} +@media (max-width:520px){.plein-fiche dl{grid-template-columns:1fr;gap:0}.plein-fiche dd{margin-bottom:8px}} .plein-corps h2{margin:0;font-family:var(--titre);font-weight:600;font-size:26px;line-height:1.15;color:var(--sapin)} .origine{display:inline-flex;flex-direction:column;vertical-align:middle;margin-left:12px;padding:3px 9px;border:1px solid var(--glacier);background:rgba(110,181,189,.14);color:#2f6f78;font-family:var(--texte,inherit);font-size:12px;font-weight:500;line-height:1.25} .origine small{font-size:11px;font-weight:400;color:var(--gris)} @@ -698,7 +717,12 @@ const I18N = { 'plein.charge': 'Chargement des courbes…', 'plein.vide': 'Pas encore de courbes pour cette station.', 'g.t': 'Température', 'g.h': 'Humidité', 'g.v': 'Vent moyen', 'g.r': 'Pluie (par heure)', 'g.gel': 'gel', 'g.mm': (a, b) => `mini ${a} · maxi ${b}`, - 'g.note': (j, depuis) => `Relevés toutes les 10 minutes, courbes sur ${j} jour${j > 1 ? 's' : ''}${depuis ? ` · archive depuis le ${depuis}` : ''}. Le zéro est marqué « gel ».`, + 'g.periode': 'Période des courbes', 'g.jour': '24 h', 'g.semaine': '7 jours', + 'g.lacune': 'Courbe de température : des relevés manquent pendant au moins 3 h sur cette période.', 'g.lacune.lans': 'À Lans village, la réception des relevés est parfois difficile.', 'g.lacune.geve': 'À Gêve, une coupure de la Livebox peut interrompre les relevés.', + 'g.note': (j, depuis, min) => `Courbes par pas de ${min} minutes sur ${j} jour${j > 1 ? 's' : ''}${depuis ? ` · archive depuis le ${depuis}` : ''}. Le zéro est marqué « gel ».`, + 'fiche.titre': 'Fiche de la station', 'fiche.alt': 'Altitude', 'fiche.proprio': 'Propriétaires', 'fiche.source': 'Source des relevés', 'fiche.voir': 'Ailleurs', + 'fiche.bientot': 'Photos et sujet de la station sur le forum : bientôt.', 'fiche.sujet': 'Voir le sujet de la station · Poster une photo', + 'fiche.forum': 'Aller au forum', 'fiche.photo': a => `Photo de la station, publiée par ${a}`, 'type.station': 'station', 'type.commune': 'commune', 'type.sommet': 'sommet', 'cookie.titre': 'Non, désolé, je ne veux pas de cookie,
Je n\'ai pas faim, ni envie de me faire traquer.', 'cookie.txt': 'Ici, rien à accepter : ni cookie de suivi, ni publicité.', @@ -772,7 +796,12 @@ const I18N = { 'plein.charge': 'Loading the charts…', 'plein.vide': 'No charts for this station yet.', 'g.t': 'Temperature', 'g.h': 'Humidity', 'g.v': 'Average wind', 'g.r': 'Rain (per hour)', 'g.gel': 'frost', 'g.mm': (a, b) => `min ${a} · max ${b}`, - 'g.note': (j, depuis) => `Readings every 10 minutes, charts over ${j} day${j > 1 ? 's' : ''}${depuis ? ` · archive since ${depuis}` : ''}. Zero is marked “frost”.`, + 'g.periode': 'Chart time range', 'g.jour': '24 hours', 'g.semaine': '7 days', + 'g.lacune': 'Temperature chart: readings are missing for at least 3 hours in this range.', 'g.lacune.lans': 'At Lans village, reception can be unreliable.', 'g.lacune.geve': 'At Gêve, a Livebox outage can interrupt readings.', + 'g.note': (j, depuis, min) => `Charts in ${min}-minute steps over ${j} day${j > 1 ? 's' : ''}${depuis ? ` · archive since ${depuis}` : ''}. Zero is marked “frost”.`, + 'fiche.titre': 'Station profile', 'fiche.alt': 'Altitude', 'fiche.proprio': 'Owners', 'fiche.source': 'Data source', 'fiche.voir': 'Elsewhere', + 'fiche.bientot': 'Photos and the station’s forum thread: coming soon.', 'fiche.sujet': 'See the station’s thread · Post a photo', + 'fiche.forum': 'Go to the forum', 'fiche.photo': a => `Photo of the station, posted by ${a}`, 'type.station': 'station', 'type.commune': 'village', 'type.sommet': 'summit', 'cookie.titre': 'No, sorry, I don’t want a cookie,
I’m not hungry, and I don’t want to be tracked.', 'cookie.txt': 'Nothing to accept here: no tracking cookies, no ads.', @@ -843,7 +872,12 @@ const I18N = { 'plein.charge': 'Kurven werden geladen…', 'plein.vide': 'Für diese Station gibt es noch keine Kurven.', 'g.t': 'Temperatur', 'g.h': 'Luftfeuchtigkeit', 'g.v': 'Mittlerer Wind', 'g.r': 'Regen (pro Stunde)', 'g.gel': 'Frost', 'g.mm': (a, b) => `min. ${a} · max. ${b}`, - 'g.note': (j, depuis) => `Messwerte alle 10 Minuten, Kurven über ${j} Tag${j > 1 ? 'e' : ''}${depuis ? ` · Archiv seit ${depuis}` : ''}. Null ist mit „Frost“ markiert.`, + 'g.periode': 'Zeitraum der Diagramme', 'g.jour': '24 Stunden', 'g.semaine': '7 Tage', + 'g.lacune': 'Temperaturkurve: In diesem Zeitraum fehlen Messwerte für mindestens 3 Stunden.', 'g.lacune.lans': 'In Lans Village ist der Empfang mitunter unzuverlässig.', 'g.lacune.geve': 'In Gêve kann ein Ausfall der Livebox die Messdatenübertragung unterbrechen.', + 'g.note': (j, depuis, min) => `Kurven im ${min}-Minuten-Raster über ${j} Tag${j > 1 ? 'e' : ''}${depuis ? ` · Archiv seit ${depuis}` : ''}. Null ist mit „Frost“ markiert.`, + 'fiche.titre': 'Steckbrief der Station', 'fiche.alt': 'Höhe', 'fiche.proprio': 'Eigentümer', 'fiche.source': 'Datenquelle', 'fiche.voir': 'Anderswo', + 'fiche.bientot': 'Fotos und Forumsthema der Station: demnächst.', 'fiche.sujet': 'Thema der Station ansehen · Foto posten', + 'fiche.forum': 'Zum Forum', 'fiche.photo': a => `Foto der Station, gepostet von ${a}`, 'type.station': 'Station', 'type.commune': 'Gemeinde', 'type.sommet': 'Gipfel', 'cookie.titre': 'Nein danke, ich will keinen Cookie,
ich habe keinen Hunger und will nicht verfolgt werden.', 'cookie.txt': 'Hier gibt es nichts zu akzeptieren: keine Tracking-Cookies, keine Werbung.', @@ -1828,7 +1862,7 @@ plein.id = 'plein'; plein.hidden = true; plein.setAttribute('role', 'dialog'); plein.setAttribute('aria-modal', 'true'); plein.setAttribute('aria-label', t('plein.aria')); plein.innerHTML = '
'; document.body.appendChild(plein); -let pleinIds = [], pleinId = null, pleinDonnees = null; +let pleinIds = [], pleinId = null, pleinDonnees = null, pleinJours = 7; let fmtJH, fmtMinuit; function formatsDates(){ fmtJH = new Intl.DateTimeFormat(LOC[L], {weekday: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hourCycle: 'h23', timeZone: 'Europe/Paris'}); @@ -1840,6 +1874,7 @@ const fmtHM = new Intl.DateTimeFormat('en-GB', {hour: '2-digit', minute: '2-digi function ouvrirPlein(ids, id = ids[0]){ pleinIds = ids.slice(); pleinId = id; const deja = !plein.hidden; + if (!deja) pleinJours = 7; plein.hidden = false; document.documentElement.style.overflow = 'hidden'; if (!deja) { history.pushState({plein: 1}, '', '#station=' + id); requestAnimationFrame(() => plein.classList.add('vu')); } @@ -1869,7 +1904,13 @@ function rendrePlein(){

${s.alt} m · ${s.src}${s.licence ? ` (${s.licence})` : ''}

${fmt(s.t)}${etat}
-

${t('plein.charge')}

`; +
+ + +
+

${t('plein.charge')}

+ ${ficheStation(id)}`; + if (FORUM_OUVERT) chargerFicheForum(id); pleinDonnees = null; fetch(`data/semaine/${id}.json?${Math.floor(Date.now() / 300000)}`).then(r => r.json()).then(d => { if (id !== pleinId) return; @@ -1878,9 +1919,42 @@ function rendrePlein(){ if (id === pleinId) plein.querySelector('.graphes').innerHTML = `

${t('plein.vide')}

`; }); } +// Fiche de la station : sobre (altitude, propriétaires, sources) ; photos épinglées et lien du sujet viennent du forum. +const FORUM = '/forum'; +const echapper = x => String(x).replace(/[&<>"']/g, c => ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''})[c]); +function ficheStation(id){ + const s = STATIONS[id], p = PROPRIO[id], l = liens(id); + const ligne = (k, v) => v ? `
${t(k)}
${v}
` : ''; + return `

${t('fiche.titre')}

+ ${ligne('fiche.alt', s.alt + ' m')} + ${ligne('fiche.proprio', p && p.map(n => PROPRIO_LIEN[n] ? `${n}` : n).join(' · '))} + ${ligne('fiche.source', (s.src || '') + (s.licence ? ` (${s.licence})` : ''))} + ${ligne('fiche.voir', l)}
+
${FORUM_OUVERT ? '' : `

${t('fiche.bientot')}

`}
`; +} +function chargerFicheForum(id){ + fetch(`${FORUM}/api/station/${encodeURIComponent(id)}.json?${Math.floor(Date.now() / 300000)}`).then(r => r.ok ? r.json() : null).then(d => { + const zone = plein.querySelector('.fiche-forum-zone'); + if (!d || id !== pleinId || !zone) return; + const lien = d.sujet && d.sujet.startsWith(FORUM + '/') ? d.sujet : FORUM + '/'; + const photos = (d.photos || []).filter(x => typeof x.url === 'string' && x.url.startsWith(FORUM + '/photo/')).slice(0, 3); + zone.innerHTML = (photos.length ? `
${photos.map(x => + `${echapper(t('fiche.photo', x.auteur || ''))}`).join('')}
` : '') + + `${t(d.sujet ? 'fiche.sujet' : 'fiche.forum')}`; + }).catch(() => {}); +} plein.addEventListener('click', ev => { const o = ev.target.closest('.plein-onglets button'); if (o) { pleinId = o.dataset.id; rendrePlein(); return; } + const periode = ev.target.closest('.plein-periode button'); + if (periode) { + pleinJours = Number(periode.dataset.jours); + plein.querySelectorAll('.plein-periode button').forEach(bouton => { + bouton.setAttribute('aria-pressed', Number(bouton.dataset.jours) === pleinJours); + }); + if (pleinDonnees) dessinerGraphes(); + return; + } if (ev.target.closest('.plein-carte')) { const ids = pleinIds.slice(); fermerPlein(); @@ -1898,27 +1972,64 @@ function graduations(bas, haut, n = 4){ return out; } +function cadrerCourbes(d, jours){ + const cles = ['t', 'h', 'v', 'r']; + // Écarter le remplissage avant le début de l'archive, puis limiter à la période choisie. + const archive = d.archive_depuis == null + ? d.t.findIndex((_, i) => cles.some(cle => d[cle][i] != null)) + : Math.floor((d.archive_depuis - d.debut) / d.pas); + const periode = d.t.length - 1 - Math.floor(jours * 86400 / d.pas); + const i0 = Math.min(Math.max(0, archive, periode), Math.max(0, d.t.length - 2)); + const vue = {...d, debut: d.debut + i0 * d.pas}; + for (const cle of cles) vue[cle] = d[cle].slice(i0); + return vue; +} + +function lacuneTemperature(temperatures, pas){ + // La pluie a des cases vides prévues entre ses mesures horaires. + let duree = 0; + return temperatures.some(valeur => { + duree = valeur == null ? duree + pas : 0; + return duree >= 3 * 3600; + }); +} + function dessinerGraphes(){ - let d = pleinDonnees; const zone = plein.querySelector('.graphes'); - if (!d || !zone) return; - // on cadre sur ce que l'archive contient (elle se remplit jour après jour) - const tout = ['t', 'h', 'v', 'r'].map(k => d[k]); - let i0 = 0; - while (i0 < d.t.length - 2 && tout.every(a => a[i0] == null)) i0++; - if (i0 > 0) { d = {...d, debut: d.debut + i0 * d.pas, t: d.t.slice(i0), h: d.h.slice(i0), v: d.v.slice(i0), r: d.r.slice(i0)}; } + if (!pleinDonnees || !zone) return; + zone.onpointermove = zone.onpointerdown = zone.onpointerleave = null; + const d = cadrerCourbes(pleinDonnees, pleinJours); const n = d.t.length; + if (n < 2) { + zone.innerHTML = `

${t('plein.vide')}

`; + return; + } + const infoStation = pleinId === 'lans' || pleinId === 'geve' ? ' ' + t('g.lacune.' + pleinId) : ''; + const lacune = pleinDonnees.t.some(valeur => valeur != null) && lacuneTemperature(d.t, d.pas) + ? `

${t('g.lacune')}${infoStation}

` + : ''; const hum = d.h.map(v => v != null && v >= 3 ? v : null); // hygromètre défaillant (1 %) : ignoré - const defs = [{cle: 't', titre: t('g.t'), v: d.t, f: fmt, ligne: true, couleurs: couleur}]; + const defs = []; + if (d.t.some(v => v != null)) defs.push({cle: 't', titre: t('g.t'), v: d.t, f: fmt, ligne: true, couleurs: couleur}); if (d.capteurs.humidite && hum.some(v => v != null)) defs.push({cle: 'h', titre: t('g.h'), v: hum, f: v => Math.round(v) + ' %', ligne: true, c: '#3f8c97', borne: [0, 100]}); - if (d.capteurs.vent) defs.push({cle: 'v', titre: t('g.v'), v: d.v, f: v => Math.round(v) + ' km/h', ligne: true, c: '#c99700', zero: true, icone: IC_EOLIENNE}); - if (d.capteurs.pluie) defs.push({cle: 'r', titre: t('g.r'), v: d.r, f: v => dec(v.toFixed(1)) + ' mm', ligne: false, c: '#2f7fc1', zero: true, icone: IC_GOUTTE}); - const W = Math.max(280, zone.clientWidth), H = 150, ml = 40, mr = 10, mt = 8, mb = 22, pw = W - ml - mr; + if (d.capteurs.vent && d.v.some(v => v != null)) defs.push({cle: 'v', titre: t('g.v'), v: d.v, f: v => Math.round(v) + ' km/h', ligne: true, c: '#c99700', zero: true, icone: IC_EOLIENNE}); + if (d.capteurs.pluie && d.r.some(v => v != null)) defs.push({cle: 'r', titre: t('g.r'), v: d.r, f: v => dec(v.toFixed(1)) + ' mm', ligne: false, c: '#2f7fc1', zero: true, icone: IC_GOUTTE}); + if (!defs.length) { + zone.innerHTML = lacune + `

${t('plein.vide')}

`; + return; + } + const W = Math.max(160, zone.clientWidth), H = 150, ml = 40, mr = 10, mt = 8, mb = 22, pw = W - ml - mr; const X = i => ml + i / (n - 1) * pw; - // repères des jours : minuit, heure de Paris - const jours = []; - for (let i = 0; i < n; i++) { const t = new Date((d.debut + i * d.pas) * 1000); if (fmtHM.format(t) === '00:00') jours.push([i, fmtMinuit.format(t)]); } - zone.innerHTML = defs.map((g, k) => { + // Repères en heure de Paris : toutes les 6 h sur 24 h, à minuit sur 7 jours. + const reperesTemps = []; + for (let i = 0; i < n; i++) { + const date = new Date((d.debut + i * d.pas) * 1000); + const heure = fmtHM.format(date); + if (pleinJours === 1 ? ['00:00', '06:00', '12:00', '18:00'].includes(heure) : heure === '00:00') { + reperesTemps.push([i, pleinJours === 1 ? heure : fmtMinuit.format(date)]); + } + } + zone.innerHTML = lacune + defs.map((g, k) => { const vals = g.v.filter(v => v != null); let bas = Math.min(...vals), haut = Math.max(...vals); if (g.borne) { bas = g.borne[0]; haut = g.borne[1]; } @@ -1943,12 +2054,12 @@ function dessinerGraphes(){ } const zero = g.cle === 't' && bas < 0 && haut > 0 ? `${t('g.gel')}` : ''; const grille = grad.map(v => `${g.cle === 't' ? Math.round(v) + '°' : Math.round(v * 10) / 10}`).join(''); - const reperes = jours.map(([i, nom]) => `${nom}`).join(''); + const reperes = reperesTemps.map(([i, nom]) => `${nom}`).join(''); const mm = vals.length ? t('g.mm', g.f(Math.min(...vals)), g.f(Math.max(...vals))) : ''; return `

${g.titre}${g.icone || ''}

${mm}
${reperes}${grille}${zero}${trace}
`; - }).join('') + `

${t('g.note', Math.min(7, Math.max(1, Math.round(n * d.pas / 86400))), d.archive_depuis ? new Intl.DateTimeFormat(LOC[L], {day: 'numeric', month: 'long', timeZone: 'Europe/Paris'}).format(new Date(d.archive_depuis * 1000)) : '')}

`; + }).join('') + `

${t('g.note', Math.min(7, Math.max(1, Math.round(n * d.pas / 86400))), d.archive_depuis ? new Intl.DateTimeFormat(LOC[L], {day: 'numeric', month: 'long', timeZone: 'Europe/Paris'}).format(new Date(d.archive_depuis * 1000)) : '', d.pas / 60)}

`; // curseur partagé : le doigt ou la souris lit la même heure sur toutes les courbes const gr = [...zone.querySelectorAll('.graphe')]; @@ -1979,11 +2090,11 @@ function dessinerGraphes(){ const i = Math.max(0, Math.min(n - 1, Math.round((ev.clientX - r.left - ml) / pw * (n - 1)))); gr.forEach((el, k) => { const v = defs[k].v[i]; if (v != null && defs[k].ligne) el.querySelector('.point').setAttribute('cy', defs[k].Y(v)); }); }; - zone.addEventListener('pointermove', poserPoint); - zone.addEventListener('pointerdown', poserPoint); - zone.addEventListener('pointerleave', () => gr.forEach(el => { + zone.onpointermove = poserPoint; + zone.onpointerdown = poserPoint; + zone.onpointerleave = () => gr.forEach(el => { el.querySelector('.curseur').setAttribute('visibility', 'hidden'); el.querySelector('.point').setAttribute('visibility', 'hidden'); el.querySelector('.g-lect').textContent = ''; - })); + }); } const lire = async f => { try { return await (await fetch(`data/${f}?${Date.now()}`)).json(); } catch (e) { return null; } }; diff --git a/maquettes/accueil-carte/modele.html b/maquettes/accueil-carte/modele.html index f8b0862..e0f18fb 100644 --- a/maquettes/accueil-carte/modele.html +++ b/maquettes/accueil-carte/modele.html @@ -175,7 +175,26 @@ a{color:inherit} .plein-onglets{display:flex;gap:6px;overflow-x:auto} .plein-onglets button{font:inherit;font-size:12px;font-weight:600;border:1px solid var(--roche);background:#faf9f5;color:var(--roche);border-radius:0;padding:6px 9px;cursor:pointer;white-space:nowrap} .plein-onglets button.on{background:var(--roche);color:#fff} -.plein-corps{max-width:980px;margin:0 auto;padding:20px 16px 64px} +.plein-corps{max-width:1200px;margin:0 auto;padding:20px 16px 64px} +[data-aff=acces] .plein-corps{max-width:1480px} +.plein-periode{display:flex;gap:8px;margin-top:16px} +.plein-periode button{font:inherit;font-weight:600;color:var(--sapin);background:none;border:1px solid var(--sapin);padding:7px 12px;cursor:pointer} +.plein-periode button[aria-pressed=true]{background:var(--sapin);color:#fff} +[data-aff=acces] .plein-periode button{min-height:44px} +.plein-lacune{margin:16px 0 0;color:var(--roche)} +.plein-fiche{margin-top:32px;padding-top:18px;border-top:1px solid var(--roche)} +.plein-fiche h3{margin:0;font-family:var(--titre);font-weight:600;font-size:20px;color:var(--sapin)} +.plein-fiche dl{display:grid;grid-template-columns:max-content 1fr;gap:6px 16px;margin:12px 0 0;font-size:14px} +.plein-fiche dt{color:var(--gris)}.plein-fiche dd{margin:0;min-width:0;overflow-wrap:anywhere} +.plein-fiche a{color:var(--sapin);text-underline-offset:2px} +.fiche-photos{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px;margin:16px 0 0;max-width:720px} +.fiche-photos img{display:block;width:100%;aspect-ratio:4/3;object-fit:cover;border:1px solid var(--pierre)} +.fiche-forum{display:inline-block;margin-top:14px;font-weight:600;color:var(--sapin);border:1px solid var(--sapin);padding:8px 12px;text-decoration:none} +.fiche-forum:hover{background:var(--sapin);color:#fff} +.fiche-bientot{margin:14px 0 0;font-size:13px;color:var(--gris)} +[data-aff=acces] .plein-fiche dl{font-size:16px}[data-aff=acces] .fiche-bientot{font-size:15px;color:var(--roche)} +[data-aff=acces] .fiche-forum{min-height:44px} +@media (max-width:520px){.plein-fiche dl{grid-template-columns:1fr;gap:0}.plein-fiche dd{margin-bottom:8px}} .plein-corps h2{margin:0;font-family:var(--titre);font-weight:600;font-size:26px;line-height:1.15;color:var(--sapin)} .origine{display:inline-flex;flex-direction:column;vertical-align:middle;margin-left:12px;padding:3px 9px;border:1px solid var(--glacier);background:rgba(110,181,189,.14);color:#2f6f78;font-family:var(--texte,inherit);font-size:12px;font-weight:500;line-height:1.25} .origine small{font-size:11px;font-weight:400;color:var(--gris)} @@ -698,7 +717,12 @@ const I18N = { 'plein.charge': 'Chargement des courbes…', 'plein.vide': 'Pas encore de courbes pour cette station.', 'g.t': 'Température', 'g.h': 'Humidité', 'g.v': 'Vent moyen', 'g.r': 'Pluie (par heure)', 'g.gel': 'gel', 'g.mm': (a, b) => `mini ${a} · maxi ${b}`, - 'g.note': (j, depuis) => `Relevés toutes les 10 minutes, courbes sur ${j} jour${j > 1 ? 's' : ''}${depuis ? ` · archive depuis le ${depuis}` : ''}. Le zéro est marqué « gel ».`, + 'g.periode': 'Période des courbes', 'g.jour': '24 h', 'g.semaine': '7 jours', + 'g.lacune': 'Courbe de température : des relevés manquent pendant au moins 3 h sur cette période.', 'g.lacune.lans': 'À Lans village, la réception des relevés est parfois difficile.', 'g.lacune.geve': 'À Gêve, une coupure de la Livebox peut interrompre les relevés.', + 'g.note': (j, depuis, min) => `Courbes par pas de ${min} minutes sur ${j} jour${j > 1 ? 's' : ''}${depuis ? ` · archive depuis le ${depuis}` : ''}. Le zéro est marqué « gel ».`, + 'fiche.titre': 'Fiche de la station', 'fiche.alt': 'Altitude', 'fiche.proprio': 'Propriétaires', 'fiche.source': 'Source des relevés', 'fiche.voir': 'Ailleurs', + 'fiche.bientot': 'Photos et sujet de la station sur le forum : bientôt.', 'fiche.sujet': 'Voir le sujet de la station · Poster une photo', + 'fiche.forum': 'Aller au forum', 'fiche.photo': a => `Photo de la station, publiée par ${a}`, 'type.station': 'station', 'type.commune': 'commune', 'type.sommet': 'sommet', 'cookie.titre': 'Non, désolé, je ne veux pas de cookie,
Je n\'ai pas faim, ni envie de me faire traquer.', 'cookie.txt': 'Ici, rien à accepter : ni cookie de suivi, ni publicité.', @@ -772,7 +796,12 @@ const I18N = { 'plein.charge': 'Loading the charts…', 'plein.vide': 'No charts for this station yet.', 'g.t': 'Temperature', 'g.h': 'Humidity', 'g.v': 'Average wind', 'g.r': 'Rain (per hour)', 'g.gel': 'frost', 'g.mm': (a, b) => `min ${a} · max ${b}`, - 'g.note': (j, depuis) => `Readings every 10 minutes, charts over ${j} day${j > 1 ? 's' : ''}${depuis ? ` · archive since ${depuis}` : ''}. Zero is marked “frost”.`, + 'g.periode': 'Chart time range', 'g.jour': '24 hours', 'g.semaine': '7 days', + 'g.lacune': 'Temperature chart: readings are missing for at least 3 hours in this range.', 'g.lacune.lans': 'At Lans village, reception can be unreliable.', 'g.lacune.geve': 'At Gêve, a Livebox outage can interrupt readings.', + 'g.note': (j, depuis, min) => `Charts in ${min}-minute steps over ${j} day${j > 1 ? 's' : ''}${depuis ? ` · archive since ${depuis}` : ''}. Zero is marked “frost”.`, + 'fiche.titre': 'Station profile', 'fiche.alt': 'Altitude', 'fiche.proprio': 'Owners', 'fiche.source': 'Data source', 'fiche.voir': 'Elsewhere', + 'fiche.bientot': 'Photos and the station’s forum thread: coming soon.', 'fiche.sujet': 'See the station’s thread · Post a photo', + 'fiche.forum': 'Go to the forum', 'fiche.photo': a => `Photo of the station, posted by ${a}`, 'type.station': 'station', 'type.commune': 'village', 'type.sommet': 'summit', 'cookie.titre': 'No, sorry, I don’t want a cookie,
I’m not hungry, and I don’t want to be tracked.', 'cookie.txt': 'Nothing to accept here: no tracking cookies, no ads.', @@ -843,7 +872,12 @@ const I18N = { 'plein.charge': 'Kurven werden geladen…', 'plein.vide': 'Für diese Station gibt es noch keine Kurven.', 'g.t': 'Temperatur', 'g.h': 'Luftfeuchtigkeit', 'g.v': 'Mittlerer Wind', 'g.r': 'Regen (pro Stunde)', 'g.gel': 'Frost', 'g.mm': (a, b) => `min. ${a} · max. ${b}`, - 'g.note': (j, depuis) => `Messwerte alle 10 Minuten, Kurven über ${j} Tag${j > 1 ? 'e' : ''}${depuis ? ` · Archiv seit ${depuis}` : ''}. Null ist mit „Frost“ markiert.`, + 'g.periode': 'Zeitraum der Diagramme', 'g.jour': '24 Stunden', 'g.semaine': '7 Tage', + 'g.lacune': 'Temperaturkurve: In diesem Zeitraum fehlen Messwerte für mindestens 3 Stunden.', 'g.lacune.lans': 'In Lans Village ist der Empfang mitunter unzuverlässig.', 'g.lacune.geve': 'In Gêve kann ein Ausfall der Livebox die Messdatenübertragung unterbrechen.', + 'g.note': (j, depuis, min) => `Kurven im ${min}-Minuten-Raster über ${j} Tag${j > 1 ? 'e' : ''}${depuis ? ` · Archiv seit ${depuis}` : ''}. Null ist mit „Frost“ markiert.`, + 'fiche.titre': 'Steckbrief der Station', 'fiche.alt': 'Höhe', 'fiche.proprio': 'Eigentümer', 'fiche.source': 'Datenquelle', 'fiche.voir': 'Anderswo', + 'fiche.bientot': 'Fotos und Forumsthema der Station: demnächst.', 'fiche.sujet': 'Thema der Station ansehen · Foto posten', + 'fiche.forum': 'Zum Forum', 'fiche.photo': a => `Foto der Station, gepostet von ${a}`, 'type.station': 'Station', 'type.commune': 'Gemeinde', 'type.sommet': 'Gipfel', 'cookie.titre': 'Nein danke, ich will keinen Cookie,
ich habe keinen Hunger und will nicht verfolgt werden.', 'cookie.txt': 'Hier gibt es nichts zu akzeptieren: keine Tracking-Cookies, keine Werbung.', @@ -1828,7 +1862,7 @@ plein.id = 'plein'; plein.hidden = true; plein.setAttribute('role', 'dialog'); plein.setAttribute('aria-modal', 'true'); plein.setAttribute('aria-label', t('plein.aria')); plein.innerHTML = '
'; document.body.appendChild(plein); -let pleinIds = [], pleinId = null, pleinDonnees = null; +let pleinIds = [], pleinId = null, pleinDonnees = null, pleinJours = 7; let fmtJH, fmtMinuit; function formatsDates(){ fmtJH = new Intl.DateTimeFormat(LOC[L], {weekday: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', hourCycle: 'h23', timeZone: 'Europe/Paris'}); @@ -1840,6 +1874,7 @@ const fmtHM = new Intl.DateTimeFormat('en-GB', {hour: '2-digit', minute: '2-digi function ouvrirPlein(ids, id = ids[0]){ pleinIds = ids.slice(); pleinId = id; const deja = !plein.hidden; + if (!deja) pleinJours = 7; plein.hidden = false; document.documentElement.style.overflow = 'hidden'; if (!deja) { history.pushState({plein: 1}, '', '#station=' + id); requestAnimationFrame(() => plein.classList.add('vu')); } @@ -1869,7 +1904,13 @@ function rendrePlein(){

${s.alt} m · ${s.src}${s.licence ? ` (${s.licence})` : ''}

${fmt(s.t)}${etat}
-

${t('plein.charge')}

`; +
+ + +
+

${t('plein.charge')}

+ ${ficheStation(id)}`; + if (FORUM_OUVERT) chargerFicheForum(id); pleinDonnees = null; fetch(`data/semaine/${id}.json?${Math.floor(Date.now() / 300000)}`).then(r => r.json()).then(d => { if (id !== pleinId) return; @@ -1878,9 +1919,42 @@ function rendrePlein(){ if (id === pleinId) plein.querySelector('.graphes').innerHTML = `

${t('plein.vide')}

`; }); } +// Fiche de la station : sobre (altitude, propriétaires, sources) ; photos épinglées et lien du sujet viennent du forum. +const FORUM = '/forum'; +const echapper = x => String(x).replace(/[&<>"']/g, c => ({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''})[c]); +function ficheStation(id){ + const s = STATIONS[id], p = PROPRIO[id], l = liens(id); + const ligne = (k, v) => v ? `
${t(k)}
${v}
` : ''; + return `

${t('fiche.titre')}

+ ${ligne('fiche.alt', s.alt + ' m')} + ${ligne('fiche.proprio', p && p.map(n => PROPRIO_LIEN[n] ? `${n}` : n).join(' · '))} + ${ligne('fiche.source', (s.src || '') + (s.licence ? ` (${s.licence})` : ''))} + ${ligne('fiche.voir', l)}
+
${FORUM_OUVERT ? '' : `

${t('fiche.bientot')}

`}
`; +} +function chargerFicheForum(id){ + fetch(`${FORUM}/api/station/${encodeURIComponent(id)}.json?${Math.floor(Date.now() / 300000)}`).then(r => r.ok ? r.json() : null).then(d => { + const zone = plein.querySelector('.fiche-forum-zone'); + if (!d || id !== pleinId || !zone) return; + const lien = d.sujet && d.sujet.startsWith(FORUM + '/') ? d.sujet : FORUM + '/'; + const photos = (d.photos || []).filter(x => typeof x.url === 'string' && x.url.startsWith(FORUM + '/photo/')).slice(0, 3); + zone.innerHTML = (photos.length ? `
${photos.map(x => + `${echapper(t('fiche.photo', x.auteur || ''))}`).join('')}
` : '') + + `${t(d.sujet ? 'fiche.sujet' : 'fiche.forum')}`; + }).catch(() => {}); +} plein.addEventListener('click', ev => { const o = ev.target.closest('.plein-onglets button'); if (o) { pleinId = o.dataset.id; rendrePlein(); return; } + const periode = ev.target.closest('.plein-periode button'); + if (periode) { + pleinJours = Number(periode.dataset.jours); + plein.querySelectorAll('.plein-periode button').forEach(bouton => { + bouton.setAttribute('aria-pressed', Number(bouton.dataset.jours) === pleinJours); + }); + if (pleinDonnees) dessinerGraphes(); + return; + } if (ev.target.closest('.plein-carte')) { const ids = pleinIds.slice(); fermerPlein(); @@ -1898,27 +1972,64 @@ function graduations(bas, haut, n = 4){ return out; } +function cadrerCourbes(d, jours){ + const cles = ['t', 'h', 'v', 'r']; + // Écarter le remplissage avant le début de l'archive, puis limiter à la période choisie. + const archive = d.archive_depuis == null + ? d.t.findIndex((_, i) => cles.some(cle => d[cle][i] != null)) + : Math.floor((d.archive_depuis - d.debut) / d.pas); + const periode = d.t.length - 1 - Math.floor(jours * 86400 / d.pas); + const i0 = Math.min(Math.max(0, archive, periode), Math.max(0, d.t.length - 2)); + const vue = {...d, debut: d.debut + i0 * d.pas}; + for (const cle of cles) vue[cle] = d[cle].slice(i0); + return vue; +} + +function lacuneTemperature(temperatures, pas){ + // La pluie a des cases vides prévues entre ses mesures horaires. + let duree = 0; + return temperatures.some(valeur => { + duree = valeur == null ? duree + pas : 0; + return duree >= 3 * 3600; + }); +} + function dessinerGraphes(){ - let d = pleinDonnees; const zone = plein.querySelector('.graphes'); - if (!d || !zone) return; - // on cadre sur ce que l'archive contient (elle se remplit jour après jour) - const tout = ['t', 'h', 'v', 'r'].map(k => d[k]); - let i0 = 0; - while (i0 < d.t.length - 2 && tout.every(a => a[i0] == null)) i0++; - if (i0 > 0) { d = {...d, debut: d.debut + i0 * d.pas, t: d.t.slice(i0), h: d.h.slice(i0), v: d.v.slice(i0), r: d.r.slice(i0)}; } + if (!pleinDonnees || !zone) return; + zone.onpointermove = zone.onpointerdown = zone.onpointerleave = null; + const d = cadrerCourbes(pleinDonnees, pleinJours); const n = d.t.length; + if (n < 2) { + zone.innerHTML = `

${t('plein.vide')}

`; + return; + } + const infoStation = pleinId === 'lans' || pleinId === 'geve' ? ' ' + t('g.lacune.' + pleinId) : ''; + const lacune = pleinDonnees.t.some(valeur => valeur != null) && lacuneTemperature(d.t, d.pas) + ? `

${t('g.lacune')}${infoStation}

` + : ''; const hum = d.h.map(v => v != null && v >= 3 ? v : null); // hygromètre défaillant (1 %) : ignoré - const defs = [{cle: 't', titre: t('g.t'), v: d.t, f: fmt, ligne: true, couleurs: couleur}]; + const defs = []; + if (d.t.some(v => v != null)) defs.push({cle: 't', titre: t('g.t'), v: d.t, f: fmt, ligne: true, couleurs: couleur}); if (d.capteurs.humidite && hum.some(v => v != null)) defs.push({cle: 'h', titre: t('g.h'), v: hum, f: v => Math.round(v) + ' %', ligne: true, c: '#3f8c97', borne: [0, 100]}); - if (d.capteurs.vent) defs.push({cle: 'v', titre: t('g.v'), v: d.v, f: v => Math.round(v) + ' km/h', ligne: true, c: '#c99700', zero: true, icone: IC_EOLIENNE}); - if (d.capteurs.pluie) defs.push({cle: 'r', titre: t('g.r'), v: d.r, f: v => dec(v.toFixed(1)) + ' mm', ligne: false, c: '#2f7fc1', zero: true, icone: IC_GOUTTE}); - const W = Math.max(280, zone.clientWidth), H = 150, ml = 40, mr = 10, mt = 8, mb = 22, pw = W - ml - mr; + if (d.capteurs.vent && d.v.some(v => v != null)) defs.push({cle: 'v', titre: t('g.v'), v: d.v, f: v => Math.round(v) + ' km/h', ligne: true, c: '#c99700', zero: true, icone: IC_EOLIENNE}); + if (d.capteurs.pluie && d.r.some(v => v != null)) defs.push({cle: 'r', titre: t('g.r'), v: d.r, f: v => dec(v.toFixed(1)) + ' mm', ligne: false, c: '#2f7fc1', zero: true, icone: IC_GOUTTE}); + if (!defs.length) { + zone.innerHTML = lacune + `

${t('plein.vide')}

`; + return; + } + const W = Math.max(160, zone.clientWidth), H = 150, ml = 40, mr = 10, mt = 8, mb = 22, pw = W - ml - mr; const X = i => ml + i / (n - 1) * pw; - // repères des jours : minuit, heure de Paris - const jours = []; - for (let i = 0; i < n; i++) { const t = new Date((d.debut + i * d.pas) * 1000); if (fmtHM.format(t) === '00:00') jours.push([i, fmtMinuit.format(t)]); } - zone.innerHTML = defs.map((g, k) => { + // Repères en heure de Paris : toutes les 6 h sur 24 h, à minuit sur 7 jours. + const reperesTemps = []; + for (let i = 0; i < n; i++) { + const date = new Date((d.debut + i * d.pas) * 1000); + const heure = fmtHM.format(date); + if (pleinJours === 1 ? ['00:00', '06:00', '12:00', '18:00'].includes(heure) : heure === '00:00') { + reperesTemps.push([i, pleinJours === 1 ? heure : fmtMinuit.format(date)]); + } + } + zone.innerHTML = lacune + defs.map((g, k) => { const vals = g.v.filter(v => v != null); let bas = Math.min(...vals), haut = Math.max(...vals); if (g.borne) { bas = g.borne[0]; haut = g.borne[1]; } @@ -1943,12 +2054,12 @@ function dessinerGraphes(){ } const zero = g.cle === 't' && bas < 0 && haut > 0 ? `${t('g.gel')}` : ''; const grille = grad.map(v => `${g.cle === 't' ? Math.round(v) + '°' : Math.round(v * 10) / 10}`).join(''); - const reperes = jours.map(([i, nom]) => `${nom}`).join(''); + const reperes = reperesTemps.map(([i, nom]) => `${nom}`).join(''); const mm = vals.length ? t('g.mm', g.f(Math.min(...vals)), g.f(Math.max(...vals))) : ''; return `

${g.titre}${g.icone || ''}

${mm}
${reperes}${grille}${zero}${trace}
`; - }).join('') + `

${t('g.note', Math.min(7, Math.max(1, Math.round(n * d.pas / 86400))), d.archive_depuis ? new Intl.DateTimeFormat(LOC[L], {day: 'numeric', month: 'long', timeZone: 'Europe/Paris'}).format(new Date(d.archive_depuis * 1000)) : '')}

`; + }).join('') + `

${t('g.note', Math.min(7, Math.max(1, Math.round(n * d.pas / 86400))), d.archive_depuis ? new Intl.DateTimeFormat(LOC[L], {day: 'numeric', month: 'long', timeZone: 'Europe/Paris'}).format(new Date(d.archive_depuis * 1000)) : '', d.pas / 60)}

`; // curseur partagé : le doigt ou la souris lit la même heure sur toutes les courbes const gr = [...zone.querySelectorAll('.graphe')]; @@ -1979,11 +2090,11 @@ function dessinerGraphes(){ const i = Math.max(0, Math.min(n - 1, Math.round((ev.clientX - r.left - ml) / pw * (n - 1)))); gr.forEach((el, k) => { const v = defs[k].v[i]; if (v != null && defs[k].ligne) el.querySelector('.point').setAttribute('cy', defs[k].Y(v)); }); }; - zone.addEventListener('pointermove', poserPoint); - zone.addEventListener('pointerdown', poserPoint); - zone.addEventListener('pointerleave', () => gr.forEach(el => { + zone.onpointermove = poserPoint; + zone.onpointerdown = poserPoint; + zone.onpointerleave = () => gr.forEach(el => { el.querySelector('.curseur').setAttribute('visibility', 'hidden'); el.querySelector('.point').setAttribute('visibility', 'hidden'); el.querySelector('.g-lect').textContent = ''; - })); + }); } const lire = async f => { try { return await (await fetch(`data/${f}?${Date.now()}`)).json(); } catch (e) { return null; } };