Add a Distance/Time toggle to the profile chart's x-axis
TrackStats.build_profile now also computes elapsed_secs per point (relative to the first known timestamp), alongside the existing cumulative distance. Point x-positions stay distance-based either way — only the shared axis strip's 5 tick labels (and the tooltip) switch between the two, so toggling is a cheap re-render rather than rebuilding the charts. The toggle only appears when a track actually has elapsed-time data to switch to.
This commit is contained in:
1 parent
4f7fe3c2a4
commit
a0476f1204
7 files changed
+138
-14
No files matched your search
@@ -54,4 +54,20 @@ class TrackStatsTest < Minitest::Test
|
||||
assert_nil profile[0]["heart_rate_bpm"]
|
||||
assert_nil profile[1]["speed_mps"]
|
||||
end
|
||||
|
||||
def test_build_profile_elapsed_secs_is_relative_to_the_first_known_timestamp
|
||||
points = [[17.0, 48.0], [17.001, 48.0], [17.002, 48.0]]
|
||||
times = [nil, Time.utc(2026, 1, 1, 0, 0, 0), Time.utc(2026, 1, 1, 0, 5, 0)]
|
||||
|
||||
profile = Maptool::TrackStats.build_profile(points, times: times)
|
||||
|
||||
assert_nil profile[0]["elapsed_secs"], "no timestamp yet at the first point"
|
||||
assert_equal 0, profile[1]["elapsed_secs"], "first known timestamp is the zero point"
|
||||
assert_equal 300, profile[2]["elapsed_secs"]
|
||||
end
|
||||
|
||||
def test_build_profile_elapsed_secs_is_nil_without_any_times
|
||||
profile = Maptool::TrackStats.build_profile([[17.0, 48.0]], times: [])
|
||||
assert_nil profile[0]["elapsed_secs"]
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user