Add activity type and a click-to-open track profile panel
CI / check (push) Successful in 41s
CI / deploy (push) Successful in 15s

Track properties gain activity_type (FIT: sport enum from the
session/sport message, Garmin's own table; GPX: <trk><type> passed
through as-is) alongside the existing distance/elevation/duration.

Clicking a track line now opens a bottom panel with a chart per
metric the track actually has (elevation always; speed/cadence/heart
rate only when present — FIT's record fields or GPX's device
extensions). TrackStats.build_profile computes cumulative distance
the same way for both formats so they're directly comparable. One
pointermove listener drives a synchronized crosshair across every
chart, a single tooltip listing all series, and a map marker at the
hovered point's position — hovering the chart shows where on the
track that moment was.
This commit is contained in:
randy committed 2026-09-07 13:38:49 +02:00
1 parent cd4eef342b
commit 105651f005
14 files changed
+655 -42

No files matched your search

+23 -2
View File
@@ -54,6 +54,7 @@ module Maptool
lines = []
all_points = []
times = []
extras = []
trk.each_element("trkseg") do |seg|
points = []
seg.each_element("trkpt") do |pt|
@@ -61,6 +62,7 @@ module Maptool
points << point
all_points << point
times << parse_time(child_text(pt, "time"))
extras << point_extensions(pt)
end
lines << points unless points.empty?
end
@@ -68,12 +70,31 @@ module Maptool
{
"type" => "Feature",
"geometry" => { "type" => "MultiLineString", "coordinates" => lines },
"properties" => { "kind" => "track", "name" => child_text(trk, "name") }
.merge(TrackStats.compute(all_points, times: times)),
"properties" => { "kind" => "track", "name" => child_text(trk, "name"), "activity_type" => child_text(trk, "type") }
.merge(TrackStats.compute(all_points, times: times))
.merge("profile" => TrackStats.build_profile(all_points, extras: extras)),
}
end
private_class_method :track_feature
# Heart rate/cadence/speed live in a device-specific <extensions> block
# (usually Garmin's own TrackPointExtension) — matched by local element
# name only (`Element#name` already strips the namespace prefix), so
# this doesn't care which extension schema a given file actually
# declares, as long as it names its elements the same way Garmin's does.
def self.point_extensions(point_el)
values = {}
point_el.elements.each("extensions//*") do |el|
case el.name
when "hr" then values[:heart_rate_bpm] = el.text&.strip&.to_i
when "cad" then values[:cadence_rpm] = el.text&.strip&.to_i
when "speed" then values[:speed_mps] = el.text&.strip&.to_f
end
end
values
end
private_class_method :point_extensions
def self.parse_time(text)
text && Time.parse(text)
rescue ArgumentError