responsive chartjs elevation profile

This commit is contained in:
vcoppe
2024-04-20 23:17:11 +02:00
parent 1aa348266e
commit 1ee25c093c
7 changed files with 144 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
abstract getStartTimestamp(): Date;
abstract getEndTimestamp(): Date;
abstract getTrackPointsAndStatistics(): { points: TrackPoint[], statistics: TrackPointStatistics };
abstract toGeoJSON(): any;
}
@@ -70,6 +71,35 @@ abstract class GPXTreeNode<T extends GPXTreeElement<any>> 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",