Splits: descent column and a header row; Tracks & Points: clicking a name shows the item and zooms to it
This commit is contained in:
1 parent
07e22a87af
commit
e3f08f2267
3 files changed
+33
-6
No files matched your search
@@ -2150,11 +2150,18 @@ html, body {
|
|||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
}
|
}
|
||||||
|
|
||||||
.profile-stats td {
|
.profile-stats td,
|
||||||
|
.profile-stats th {
|
||||||
padding: 1px 10px 1px 0;
|
padding: 1px 10px 1px 0;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.profile-stats th {
|
||||||
|
text-align: left;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
.profile-chart__trails {
|
.profile-chart__trails {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
+19
-1
@@ -1,4 +1,4 @@
|
|||||||
import { Popup } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
import { Popup, LngLatBounds } from "/vendor/maplibre-gl/maplibre-gl.mjs";
|
||||||
import {
|
import {
|
||||||
GPX_ICON,
|
GPX_ICON,
|
||||||
NEW_FOLDER_ICON,
|
NEW_FOLDER_ICON,
|
||||||
@@ -328,6 +328,16 @@ export class GpxPanelControl {
|
|||||||
label.appendChild(checkbox);
|
label.appendChild(checkbox);
|
||||||
(file.kinds || []).forEach((kind) => label.appendChild(this._kindIcon(kind)));
|
(file.kinds || []).forEach((kind) => label.appendChild(this._kindIcon(kind)));
|
||||||
label.appendChild(name);
|
label.appendChild(name);
|
||||||
|
// The name zooms to it (showing it first if needed); the checkbox
|
||||||
|
// alone shows/hides.
|
||||||
|
name.addEventListener("click", async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!checkbox.checked) {
|
||||||
|
checkbox.checked = true;
|
||||||
|
await this._toggleFile(file.path, true, checkbox);
|
||||||
|
}
|
||||||
|
if (checkbox.checked) this._zoomTo(file.path);
|
||||||
|
});
|
||||||
row.appendChild(label);
|
row.appendChild(label);
|
||||||
// Delete/download require login (app.rb); shown only once logged in
|
// Delete/download require login (app.rb); shown only once logged in
|
||||||
// rather than shown-but-failing-on-click.
|
// rather than shown-but-failing-on-click.
|
||||||
@@ -544,6 +554,14 @@ export class GpxPanelControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _zoomTo(path) {
|
||||||
|
const sources = [linesSourceId(path), pointsSourceId(path)].map((id) => this._map.getSource(id)).filter(Boolean);
|
||||||
|
const bounds = new LngLatBounds();
|
||||||
|
const extend = (c) => (typeof c[0] === "number" ? bounds.extend([c[0], c[1]]) : c.forEach(extend));
|
||||||
|
for (const source of sources) (await source.getData()).features.forEach((f) => f.geometry && extend(f.geometry.coordinates));
|
||||||
|
if (!bounds.isEmpty()) this._map.fitBounds(bounds, { padding: 60, maxZoom: 15 });
|
||||||
|
}
|
||||||
|
|
||||||
// Fetches the file's GeoJSON itself (rather than handing maplibre a URL
|
// Fetches the file's GeoJSON itself (rather than handing maplibre a URL
|
||||||
// to fetch internally) so a parse failure — a real GPX a device/app
|
// to fetch internally) so a parse failure — a real GPX a device/app
|
||||||
// wrote in some way REXML doesn't like, say — surfaces as an alert
|
// wrote in some way REXML doesn't like, say — surfaces as an alert
|
||||||
|
|||||||
@@ -264,9 +264,9 @@ function statsTables(profile, activityType) {
|
|||||||
if (timed.length > 1) {
|
if (timed.length > 1) {
|
||||||
const step = ride || total > 50000 ? 5000 : 1000;
|
const step = ride || total > 50000 ? 5000 : 1000;
|
||||||
const rows = splits(timed, step).map(
|
const rows = splits(timed, step).map(
|
||||||
(s) => `<tr><td>${(s.to / 1000).toFixed(s.to % 1000 ? 1 : 0)} km</td><td>${formatDuration(s.secs)}</td><td>${pace(s.secs, s.meters)}</td><td>↑ ${Math.round(s.gain)} m</td>${hasHr ? `<td>${s.hr ? `${Math.round(s.hr)} bpm` : ""}</td>` : ""}${hasPower ? `<td>${s.power ? `${Math.round(s.power)} W` : ""}</td>` : ""}</tr>`,
|
(s) => `<tr><td>${(s.to / 1000).toFixed(s.to % 1000 ? 1 : 0)} km</td><td>${formatDuration(s.secs)}</td><td>${pace(s.secs, s.meters)}</td><td>↑ ${Math.round(s.gain)} m</td><td>↓ ${Math.round(s.loss)} m</td>${hasHr ? `<td>${s.hr ? `${Math.round(s.hr)} bpm` : ""}</td>` : ""}${hasPower ? `<td>${s.power ? `${Math.round(s.power)} W` : ""}</td>` : ""}</tr>`,
|
||||||
);
|
);
|
||||||
html += `<details class="profile-stats"><summary>Splits (${step / 1000} km)</summary><table>${rows.join("")}</table></details>`;
|
html += `<details class="profile-stats"><summary>Splits (${step / 1000} km)</summary><table><thead><tr><th>At</th><th>Time</th><th>${ride ? "Speed" : "Pace"}</th><th>Ascent</th><th>Descent</th>${hasHr ? "<th>Avg HR</th>" : ""}${hasPower ? "<th>Avg power</th>" : ""}</tr></thead><tbody>${rows.join("")}</tbody></table></details>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const best = [];
|
const best = [];
|
||||||
@@ -288,7 +288,7 @@ function statsTables(profile, activityType) {
|
|||||||
return html;
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Every `step` meters: time, gain and average heart rate/power, the last
|
// Every `step` meters: time, ascent/descent and average heart rate/power, the last
|
||||||
// split shorter. Points are the first at/after each boundary.
|
// split shorter. Points are the first at/after each boundary.
|
||||||
function splits(profile, step) {
|
function splits(profile, step) {
|
||||||
const out = [];
|
const out = [];
|
||||||
@@ -298,13 +298,15 @@ function splits(profile, step) {
|
|||||||
if (!last && profile[i].distance_meters < (out.length + 1) * step) continue;
|
if (!last && profile[i].distance_meters < (out.length + 1) * step) continue;
|
||||||
const part = profile.slice(start, i + 1);
|
const part = profile.slice(start, i + 1);
|
||||||
let gain = 0;
|
let gain = 0;
|
||||||
|
let loss = 0;
|
||||||
part.forEach((p, j) => {
|
part.forEach((p, j) => {
|
||||||
const climb = j > 0 && p.elevation_meters != null && part[j - 1].elevation_meters != null ? p.elevation_meters - part[j - 1].elevation_meters : 0;
|
const climb = j > 0 && p.elevation_meters != null && part[j - 1].elevation_meters != null ? p.elevation_meters - part[j - 1].elevation_meters : 0;
|
||||||
if (climb > 0) gain += climb;
|
if (climb > 0) gain += climb;
|
||||||
|
else loss -= climb;
|
||||||
});
|
});
|
||||||
const meters = profile[i].distance_meters - profile[start].distance_meters;
|
const meters = profile[i].distance_meters - profile[start].distance_meters;
|
||||||
const secs = profile[i].elapsed_secs - profile[start].elapsed_secs;
|
const secs = profile[i].elapsed_secs - profile[start].elapsed_secs;
|
||||||
if (meters > 0 && secs > 0) out.push({ to: profile[i].distance_meters, meters, secs, gain, hr: average(part, "heart_rate_bpm"), power: average(part, "power_w") });
|
if (meters > 0 && secs > 0) out.push({ to: profile[i].distance_meters, meters, secs, gain, loss, hr: average(part, "heart_rate_bpm"), power: average(part, "power_w") });
|
||||||
start = i;
|
start = i;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
|||||||
Reference in new issue
Block a user