Skip to content

Commit dc37258

Browse files
committed
Another fix for statistics chart labels
1 parent ce9bfbc commit dc37258

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

Tevling/Pages/Statistics.razor.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private Dictionary<string, float[]> GetAggregatedMeasurementData(Func<Activity,
2626
DateTimeOffset now = DateTimeOffset.Now;
2727

2828
Dictionary<string, float[]> aggregatedData = _activities
29-
.GroupBy(a => a.Details.Type)
29+
.GroupBy(a => ActivityTypeExt.ToString(a.Details.Type))
3030
.ToDictionary(
3131
g => g.Key.ToString(),
3232
g => Enumerable.Range(-monthCount + 1, monthCount)
@@ -81,19 +81,22 @@ await _module.InvokeVoidAsync(
8181
distanceLastThreeMonths,
8282
lastThreeMonths,
8383
"totalDistanceChart",
84-
"Total Distance [km]");
84+
"Total Distance [km]",
85+
"km");
8586
await _module.InvokeVoidAsync(
8687
"drawChart",
8788
elevationLastThreeMonths,
8889
lastThreeMonths,
8990
"totalElevationChart",
90-
"Total Elevation [m]");
91+
"Total Elevation [m]",
92+
"m");
9193
await _module.InvokeVoidAsync(
9294
"drawChart",
9395
timeLastThreeMonths,
9496
lastThreeMonths,
9597
"totalTimeChart",
96-
"Total Time [h]");
98+
"Total Time [h]",
99+
"h");
97100
}
98101

99102
public async ValueTask DisposeAsync()

Tevling/Pages/Statistics.razor.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function drawChart(activityData, labels, chartName, chartTitle) {
1+
export function drawChart(activityData, labels, chartName, chartTitle, unit) {
22
var ctx = document.getElementById(chartName).getContext("2d");
33

44
// Destroy existing chart instance if it exists
@@ -33,10 +33,25 @@ export function drawChart(activityData, labels, chartName, chartTitle) {
3333
},
3434
tooltip: {
3535
callbacks: {
36-
label: (ctx) =>
37-
Number.isInteger(ctx.parsed.y)
38-
? ctx.parsed.y
39-
: ctx.parsed.y.toFixed(1),
36+
label: (context) => {
37+
let label = context.dataset.label || "";
38+
39+
if (label) {
40+
label += ": ";
41+
}
42+
43+
if (context.parsed.y !== null) {
44+
label += Number.isInteger(context.parsed.y)
45+
? context.parsed.y
46+
: context.parsed.y.toFixed(1);
47+
}
48+
49+
if (unit) {
50+
label += " " + unit;
51+
}
52+
53+
return label;
54+
},
4055
},
4156
},
4257
},

0 commit comments

Comments
 (0)