commit b7344a68c6d4c4fab15b26afa4667f73ac634df7
parent 6ddd374a94796c1fc01e31aa3deeb6e75719e641
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 13 Nov 2024 00:16:50 +0000
set viewBox for graphs to show full time range
todo: also scale the y axis correctly
Diffstat:
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm
@@ -235,7 +235,9 @@ measureView fn allPoints =
string = String.concat (List.map coords filteredPoints)
in
svg
- [ ]
+ [ H.style "width" (px portalWidth)
+ , viewBox ("0 0 " ++ (String.fromFloat (Point.duration allPoints)) ++ " 150")
+ ]
[ g
[ fill "none"
, stroke "red"
diff --git a/frontend/src/Point.elm b/frontend/src/Point.elm
@@ -1,4 +1,4 @@
-module Point exposing(Pos, Point, decoder, downsample)
+module Point exposing(Pos, Point, decoder, downsample, duration)
import Json.Decode as D
@@ -33,10 +33,10 @@ decoder = D.map5 Point
(D.field "heartRate" (D.maybe D.int))
-llast x xs =
+last x xs =
case xs of
[] -> x
- (x_::xs_) -> llast x_ xs_
+ (x_::xs_) -> last x_ xs_
tracef x = Debug.log (String.fromFloat x) x
@@ -54,8 +54,11 @@ downsample n points =
in
case points of
(first::rest) ->
- let last = llast first rest
- duration = last.time - first.time
- step = duration / (toFloat n)
+ let step = (duration points) / (toFloat n)
in nextpoint step first rest
[] -> []
+
+duration points =
+ case points of
+ (p::ps) -> (last p ps).time - p.time
+ _ -> 0