Client - fix units when ascent and descent are displayed on chart
This commit is contained in:
parent
2d1b166d77
commit
8e1c470169
@ -55,6 +55,11 @@
|
|||||||
function getSum(total: any, value: any): number {
|
function getSum(total: any, value: any): number {
|
||||||
return getNumber(total) + getNumber(value)
|
return getNumber(total) + getNumber(value)
|
||||||
}
|
}
|
||||||
|
function getUnit(displayedData: string) {
|
||||||
|
return ['total_ascent', 'total_descent'].includes(displayedData)
|
||||||
|
? 'm'
|
||||||
|
: 'km'
|
||||||
|
}
|
||||||
const chartData: ComputedRef<ChartData<'bar'>> = computed(() => ({
|
const chartData: ComputedRef<ChartData<'bar'>> = computed(() => ({
|
||||||
labels: props.labels,
|
labels: props.labels,
|
||||||
// workaround to avoid dataset modification
|
// workaround to avoid dataset modification
|
||||||
@ -88,7 +93,8 @@
|
|||||||
props.displayedData,
|
props.displayedData,
|
||||||
+value,
|
+value,
|
||||||
props.useImperialUnits,
|
props.useImperialUnits,
|
||||||
false
|
false,
|
||||||
|
getUnit(props.displayedData)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -137,9 +143,6 @@
|
|||||||
const total: number = context.chart.data.datasets
|
const total: number = context.chart.data.datasets
|
||||||
.map((d) => d.data[context.dataIndex])
|
.map((d) => d.data[context.dataIndex])
|
||||||
.reduce((total, value) => getSum(total, value), 0)
|
.reduce((total, value) => getSum(total, value), 0)
|
||||||
let unitFrom = 'km'
|
|
||||||
if (props.displayedData === 'total_ascent' || props.displayedData === 'total_descent')
|
|
||||||
unitFrom = 'm'
|
|
||||||
return context.datasetIndex ===
|
return context.datasetIndex ===
|
||||||
props.displayedSportIds.length - 1 && total > 0
|
props.displayedSportIds.length - 1 && total > 0
|
||||||
? formatTooltipValue(
|
? formatTooltipValue(
|
||||||
@ -147,7 +150,7 @@
|
|||||||
total,
|
total,
|
||||||
props.useImperialUnits,
|
props.useImperialUnits,
|
||||||
false,
|
false,
|
||||||
unitFrom
|
getUnit(props.displayedData)
|
||||||
)
|
)
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
@ -176,7 +179,9 @@
|
|||||||
label += formatTooltipValue(
|
label += formatTooltipValue(
|
||||||
props.displayedData,
|
props.displayedData,
|
||||||
context.parsed.y,
|
context.parsed.y,
|
||||||
props.useImperialUnits
|
props.useImperialUnits,
|
||||||
|
true,
|
||||||
|
getUnit(props.displayedData)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return label
|
return label
|
||||||
@ -194,7 +199,9 @@
|
|||||||
formatTooltipValue(
|
formatTooltipValue(
|
||||||
props.displayedData,
|
props.displayedData,
|
||||||
sum,
|
sum,
|
||||||
props.useImperialUnits
|
props.useImperialUnits,
|
||||||
|
true,
|
||||||
|
getUnit(props.displayedData)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user