mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-01-15 14:18:41 +00:00
avoid performing a get on unit stores for each point
This commit is contained in:
@@ -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();
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user