import network from "../data/network.json"; const timeFormat = new Intl.DateTimeFormat("fr-FR", { timeZone: "Europe/Paris", timeStyle: "medium", }); const timeToHTML = time => { const delta = Math.ceil((time - Date.now()) / 1000); if (delta <= 0) { return `Imminent`; } else if (delta < 60) { return `${delta} s`; } else { return `${Math.floor(delta / 60)} min ${delta % 60} s`; } }; /** * Update the contents of the side panel with course information. * @param {HTMLElement} target The panel element. * @param {Object} courses Active courses. * @param {string?} showCourse The ID of a course to show. */ export const updatePanel = (target, courses, showCourse) => { const vehicleCount = Object.values(courses).length; const movingVehicles = Object.values(courses).filter( course => course.properties.speed > 0 ).length; let html = `
Heure locale
${timeFormat.format(Date.now())}
Véhicules sur la carte
${movingVehicles} en mouvement, ${vehicleCount - movingVehicles} à l’arrêt
`; if (showCourse !== null && showCourse in courses) { const course = courses[showCourse].properties; const stopToHTML = stopId => stopId in network.stops ? network.stops[stopId].properties.name : 'Arrêt inconnu'; const passingsToHTML = passings => passings.map(([stopId, time]) => ` ${stopToHTML(stopId)} ${timeFormat.format(time)} `).join("\n"); const state = ( course.traveledDistance === 0 && course.speed === 0 ? "stopped" : "moving" ); let prevPassings = course.prevPassings; if (state === "moving") { prevPassings = prevPassings.concat([[ course.departureStop, course.departureTime ]]); } html += `

Véhicule

ID
${showCourse}
Ligne
${course.line}
Destination
${stopToHTML(course.finalStop)}
État
${state === "moving" ? `Entre ${stopToHTML(course.departureStop)} et ${stopToHTML(course.arrivalStop)}` : `À l’arrêt ${stopToHTML(course.departureStop)}`}
${state === "moving" ? `
Arrivée dans
${timeToHTML(course.arrivalTime - 10000)}
Distance parcourue
${Math.ceil(course.traveledDistance)} m
Vitesse
${Math.ceil(course.speed * 3600)} km/h
` : `
Départ dans
${timeToHTML(course.departureTime)}
`}

Arrêts précédents

${passingsToHTML(prevPassings)}

Arrêts suivants

${passingsToHTML(course.nextPassings)}
`; } target.innerHTML = html; };