diff --git a/gpx/src/gpx.ts b/gpx/src/gpx.ts index 71488455..9fe03916 100644 --- a/gpx/src/gpx.ts +++ b/gpx/src/gpx.ts @@ -19,6 +19,7 @@ abstract class GPXTreeElement> { abstract getStartTimestamp(): Date; abstract getEndTimestamp(): Date; + abstract getTrackPointsAndStatistics(): { points: TrackPoint[], statistics: TrackPointStatistics }; abstract toGeoJSON(): any; } @@ -70,6 +71,35 @@ abstract class GPXTreeNode> extends GPXTreeElement getEndTimestamp(): Date { return this.getChildren()[this.getChildren().length - 1].getEndTimestamp(); } + + getTrackPointsAndStatistics(): { points: TrackPoint[]; statistics: TrackPointStatistics; } { + let points: TrackPoint[] = []; + let statistics: TrackPointStatistics = { + distance: [], + time: [], + speed: [], + elevation: { + smoothed: [], + gain: [], + loss: [], + }, + slope: [], + }; + + for (let child of this.getChildren()) { + let childData = child.getTrackPointsAndStatistics(); + points = points.concat(childData.points); + statistics.distance = statistics.distance.concat(childData.statistics.distance); + statistics.time = statistics.time.concat(childData.statistics.time); + statistics.speed = statistics.speed.concat(childData.statistics.speed); + statistics.elevation.smoothed = statistics.elevation.smoothed.concat(childData.statistics.elevation.smoothed); + statistics.elevation.gain = statistics.elevation.gain.concat(childData.statistics.elevation.gain); + statistics.elevation.loss = statistics.elevation.loss.concat(childData.statistics.elevation.loss); + statistics.slope = statistics.slope.concat(childData.statistics.slope); + } + + return { points, statistics }; + } } // An abstract class that TrackSegment extends to implement the GPXTreeElement interface @@ -351,6 +381,13 @@ export class TrackSegment extends GPXTreeLeaf { return this.trkpt[this.trkpt.length - 1].time; } + getTrackPointsAndStatistics(): { points: TrackPoint[], statistics: TrackPointStatistics } { + return { + points: this.trkpt, + statistics: this.trkptStatistics + }; + } + toGeoJSON(): any { return { type: "Feature", diff --git a/website/package-lock.json b/website/package-lock.json index 1a8223fb..d1835620 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@mapbox/mapbox-gl-geocoder": "^5.0.2", "bits-ui": "^0.21.3", + "chart.js": "^4.4.2", "clsx": "^2.1.0", "gpx": "file:../gpx", "lucide-svelte": "^0.365.0", @@ -801,6 +802,11 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@kurkle/color": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.2.tgz", + "integrity": "sha512-fuscdXJ9G1qb7W8VdHi+IwRqij3lBkosAm4ydQtEmbY58OzHXqQhvlxqEkoz0yssNVn38bcpRWgA9PP+OGoisw==" + }, "node_modules/@mapbox/fusspot": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/@mapbox/fusspot/-/fusspot-0.4.0.tgz", @@ -2038,6 +2044,17 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/chart.js": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.4.2.tgz", + "integrity": "sha512-6GD7iKwFpP5kbSD4MeRRRlTnQvxfQREy36uEtm1hzHzcOqwWx0YEHuspuoNlslu+nciLIB7fjjsHkUv/FzFcOg==", + "dependencies": { + "@kurkle/color": "^0.3.0" + }, + "engines": { + "pnpm": ">=8" + } + }, "node_modules/cheap-ruler": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/cheap-ruler/-/cheap-ruler-3.0.2.tgz", diff --git a/website/package.json b/website/package.json index 1282b9c0..14fd0817 100644 --- a/website/package.json +++ b/website/package.json @@ -43,6 +43,7 @@ "dependencies": { "@mapbox/mapbox-gl-geocoder": "^5.0.2", "bits-ui": "^0.21.3", + "chart.js": "^4.4.2", "clsx": "^2.1.0", "gpx": "file:../gpx", "lucide-svelte": "^0.365.0", diff --git a/website/src/lib/components/ElevationProfile.svelte b/website/src/lib/components/ElevationProfile.svelte new file mode 100644 index 00000000..5213e789 --- /dev/null +++ b/website/src/lib/components/ElevationProfile.svelte @@ -0,0 +1,84 @@ + + +
+ +
diff --git a/website/src/lib/components/GPXData.svelte b/website/src/lib/components/GPXData.svelte index 2b348f30..3e795bef 100644 --- a/website/src/lib/components/GPXData.svelte +++ b/website/src/lib/components/GPXData.svelte @@ -29,7 +29,7 @@ - + diff --git a/website/src/lib/components/Menu.svelte b/website/src/lib/components/Menu.svelte index 84633658..d728ca75 100644 --- a/website/src/lib/components/Menu.svelte +++ b/website/src/lib/components/Menu.svelte @@ -35,7 +35,7 @@
diff --git a/website/src/routes/+page.svelte b/website/src/routes/+page.svelte index dd31bef0..a12b1f2c 100644 --- a/website/src/routes/+page.svelte +++ b/website/src/routes/+page.svelte @@ -1,5 +1,6 @@