Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: route segment personal trend chart #273

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ all: clean install-deps test build
install-dev-deps:
go install github.com/swaggo/swag/cmd/swag@latest
go install github.com/air-verse/air@latest
go install github.com/vorlif/xspreak@latest

install-deps:
npm install
Expand Down
32 changes: 32 additions & 0 deletions assets/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,14 @@ table {
max-height: 12rem;
}

.max-h-\[300px\] {
max-height: 300px;
}

.max-h-\[340px\] {
max-height: 340px;
}

.min-h-\[450px\] {
min-height: 450px;
}
Expand Down Expand Up @@ -3026,6 +3034,14 @@ table {
height: 400px;
}

.sm\:max-h-\[400px\] {
max-height: 400px;
}

.sm\:max-h-\[440px\] {
max-height: 440px;
}

.sm\:w-\[300px\] {
width: 300px;
}
Expand Down Expand Up @@ -3080,6 +3096,14 @@ table {
height: 600px;
}

.md\:max-h-\[600px\] {
max-height: 600px;
}

.md\:max-h-\[640px\] {
max-height: 640px;
}

.md\:basis-1\/2 {
flex-basis: 50%;
}
Expand Down Expand Up @@ -3169,6 +3193,14 @@ table {
height: 600px;
}

.print\:max-h-\[600px\] {
max-height: 600px;
}

.print\:max-h-\[640px\] {
max-height: 640px;
}

.print\:w-full {
width: 100%;
}
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"Other users": "Other users",
"Password": "Password",
"Per": "Per",
"Personal trend": "Personal trend",
"Please help translate via Weblate": "Please help translate via Weblate",
"Preferred units": "Preferred units",
"Profile updated": "Profile updated",
Expand Down
72 changes: 72 additions & 0 deletions views/partials/route_segment_show_stats.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{{ define "route_segment_show_stats" }}
<div id="routeSegmentChart"></div>

<script>
// Determine theme
let theme = "light";
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
theme = "dark";
}

const rootElement = document.getElementById("routeSegmentChart");
const data = [
{{ range .RouteSegmentMatches }}
{{ if eq CurrentUser.ID .Workout.UserID }}
{ "x": new Date({{ .Workout.Date }}) , "y": {{ .AverageSpeed | HumanSpeed }} },
{{ end }}
{{ end }}
];

const numberFormatter = new Intl.NumberFormat({ maximumFractionDigits: 2, minimumFractionDigits: 2 });

// Build chart
const options = {
theme: { mode: theme },
chart: {
height: 400,
animations: { enabled: false }
},
legend: {
position: 'top',
formatter: (seriesName, opts)=>{
if(opts.seriesIndex>3) return '';
return seriesName;
},
markers: { width: [12] }
},
tooltip: {
x: { format: 'dd-MM-yyyy', },
y: [
{ formatter: function (val, opts) { return numberFormatter.format(val) + " {{ CurrentUser.PreferredUnits.Speed }}"; } },
],
},
markers: {
size: 2,
},
xaxis: { type: "datetime" },
yaxis: [
{
labels: {
formatter: (val) => {
return numberFormatter.format(val) + " {{ CurrentUser.PreferredUnits.Speed }}";
},
},
}
],
series: [
{
name: "{{ i18n `Average speed` }}",
type: "scatter",
data
}
]
};

const chart = new ApexCharts(rootElement, options);
chart.render();
</script>

{{ end }}
23 changes: 19 additions & 4 deletions views/route_segments/route_segments_show.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
{{ template "head" }}
<script src="{{ RouteFor `assets` }}/dist/leaflet.js"></script>
<script src="{{ RouteFor `assets` }}/dist/apexcharts.min.js"></script>
<link href="{{ RouteFor `assets` }}/dist/leaflet.css" rel="stylesheet" />
</head>
<body>
Expand All @@ -28,13 +29,17 @@ <h2 class="{{ IconFor `route-segment` }}">{{ .Name }}</h2>
<div class="inner-form">{{ template "route_segment_details" . }}</div>
</div>
<div class="basis-1/2 2xl:basis-1/3">
<div class="inner-form">
<div
class="inner-form overflow-y-auto max-h-[340px] sm:max-h-[440px] md:max-h-[640px] print:max-h-[640px]"
>
<table>
<thead>
<tr>
<th>{{ i18n "User" }}</th>
<th class="{{ IconFor `user` }}">&nbsp;</th>
<th>{{ i18n "Workout" }}</th>
<th>{{ i18n "Distance" }}</th>
<th class="lg:hidden 3xl:table-cell">
{{ i18n "Distance" }}
</th>
<th>{{ i18n "Duration" }}</th>
<th>{{ i18n "Tempo" }}</th>
</tr>
Expand All @@ -52,7 +57,9 @@ <h2 class="{{ IconFor `route-segment` }}">{{ .Name }}</h2>
>{{ .Workout.Name }}</a
>
</td>
<td class="whitespace-nowrap font-mono">
<td
class="whitespace-nowrap font-mono lg:hidden 3xl:table-cell"
>
{{ .Distance | HumanDistance }} {{
CurrentUser.PreferredUnits.Distance }}
</td>
Expand All @@ -70,6 +77,14 @@ <h2 class="{{ IconFor `route-segment` }}">{{ .Name }}</h2>
</div>
</div>
</div>

<div class="inner-form h-[300px] md:h-[500px] print:hidden">
<h3>
<span>{{ i18n "Personal trend" }}</span>
pixelspark marked this conversation as resolved.
Show resolved Hide resolved
</h3>
{{ template "route_segment_show_stats" . }}
</div>

<div class="pagebreak">
{{ if .Notes }}
<div class="inner-form">
Expand Down
4 changes: 3 additions & 1 deletion views/workouts/workouts_show.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ <h2 class="{{ IconFor .Type.String }}">{{ .Name }}</h2>
<div class="basis-1/2 2xl:basis-1/3">
{{ if and .Type.IsDistance .Type.IsDuration .Data.Details }}
<div class="inner-form">
<div class="print:w-full overflow-y-auto">
<div
class="print:w-full overflow-y-auto max-h-[300px] sm:max-h-[400px] md:max-h-[600px] print:max-h-[600px]"
>
{{ template "workout_breakdown" (.StatisticsPer 1
CurrentUser.PreferredUnits.Distance) }}
</div>
Expand Down
Loading