avoid performing a get on unit stores for each point

This commit is contained in:
vcoppe
2026-01-04 19:52:25 +01:00
parent 5dcb93ca5d
commit 9cd87742f0
2 changed files with 42 additions and 12 deletions

View File

@@ -405,12 +405,17 @@ export class ElevationProfile {
return; return;
} }
const data = get(this._gpxStatistics); const data = get(this._gpxStatistics);
const units = {
distance: get(distanceUnits),
velocity: get(velocityUnits),
temperature: get(temperatureUnits),
};
this._chart.data.datasets[0] = { this._chart.data.datasets[0] = {
label: i18n._('quantities.elevation'), label: i18n._('quantities.elevation'),
data: data.local.points.map((point, index) => { data: data.local.points.map((point, index) => {
return { return {
x: getConvertedDistance(data.local.distance.total[index]), x: getConvertedDistance(data.local.distance.total[index], units.distance),
y: point.ele ? getConvertedElevation(point.ele) : 0, y: point.ele ? getConvertedElevation(point.ele, units.distance) : 0,
time: point.time, time: point.time,
slope: { slope: {
at: data.local.slope.at[index], at: data.local.slope.at[index],
@@ -432,8 +437,15 @@ export class ElevationProfile {
data.global.time.total > 0 data.global.time.total > 0
? data.local.points.map((point, index) => { ? data.local.points.map((point, index) => {
return { return {
x: getConvertedDistance(data.local.distance.total[index]), x: getConvertedDistance(
y: getConvertedVelocity(data.local.speed[index]), data.local.distance.total[index],
units.distance
),
y: getConvertedVelocity(
data.local.speed[index],
units.velocity,
units.distance
),
index: index, index: index,
}; };
}) })
@@ -446,7 +458,10 @@ export class ElevationProfile {
data.global.hr.count > 0 data.global.hr.count > 0
? data.local.points.map((point, index) => { ? data.local.points.map((point, index) => {
return { return {
x: getConvertedDistance(data.local.distance.total[index]), x: getConvertedDistance(
data.local.distance.total[index],
units.distance
),
y: point.getHeartRate(), y: point.getHeartRate(),
index: index, index: index,
}; };
@@ -460,7 +475,10 @@ export class ElevationProfile {
data.global.cad.count > 0 data.global.cad.count > 0
? data.local.points.map((point, index) => { ? data.local.points.map((point, index) => {
return { return {
x: getConvertedDistance(data.local.distance.total[index]), x: getConvertedDistance(
data.local.distance.total[index],
units.distance
),
y: point.getCadence(), y: point.getCadence(),
index: index, index: index,
}; };
@@ -474,8 +492,11 @@ export class ElevationProfile {
data.global.atemp.count > 0 data.global.atemp.count > 0
? data.local.points.map((point, index) => { ? data.local.points.map((point, index) => {
return { return {
x: getConvertedDistance(data.local.distance.total[index]), x: getConvertedDistance(
y: getConvertedTemperature(point.getTemperature()), data.local.distance.total[index],
units.distance
),
y: getConvertedTemperature(point.getTemperature(), units.temperature),
index: index, index: index,
}; };
}) })
@@ -488,7 +509,10 @@ export class ElevationProfile {
data.global.power.count > 0 data.global.power.count > 0
? data.local.points.map((point, index) => { ? data.local.points.map((point, index) => {
return { return {
x: getConvertedDistance(data.local.distance.total[index]), x: getConvertedDistance(
data.local.distance.total[index],
units.distance
),
y: point.getPower(), y: point.getPower(),
index: index, index: index,
}; };
@@ -498,7 +522,10 @@ export class ElevationProfile {
yAxisID: 'ypower', yAxisID: 'ypower',
}; };
this._chart.options.scales!.x!['min'] = 0; this._chart.options.scales!.x!['min'] = 0;
this._chart.options.scales!.x!['max'] = getConvertedDistance(data.global.distance.total); this._chart.options.scales!.x!['max'] = getConvertedDistance(
data.global.distance.total,
units.distance
);
this.setVisibility(); this.setVisibility();
this.setFill(); this.setFill();

View File

@@ -229,6 +229,9 @@ export function getConvertedVelocity(
} }
} }
export function getConvertedTemperature(value: number) { export function getConvertedTemperature(
return get(temperatureUnits) === 'celsius' ? value : celsiusToFahrenheit(value); value: number,
targetTemperatureUnits = get(temperatureUnits)
) {
return targetTemperatureUnits === 'celsius' ? value : celsiusToFahrenheit(value);
} }