commit cdfc56d7fe6b39a50ceeec912ef82f2893b4f85a
parent b7344a68c6d4c4fab15b26afa4667f73ac634df7
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 13 Nov 2024 20:38:47 +0000
fix scaling for time graphs
Diffstat:
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm
@@ -13,6 +13,8 @@ import Point exposing(Point, Pos ,decoder)
import Svg exposing (Svg, svg, rect, circle, g, polyline)
import Svg.Attributes as S exposing
( viewBox
+ , preserveAspectRatio
+ , transform
, x, y
, r, rx, ry
, cx, cy
@@ -232,20 +234,26 @@ measureView fn allPoints =
(String.fromFloat (p.time - startTime)) ++ "," ++
(String.fromFloat c) ++ ", "
Nothing -> ""
+ maxY = String.fromFloat (List.foldr max 0 (List.filterMap fn filteredPoints))
string = String.concat (List.map coords filteredPoints)
in
svg
- [ H.style "width" (px portalWidth)
- , viewBox ("0 0 " ++ (String.fromFloat (Point.duration allPoints)) ++ " 150")
+ [ width portalWidth
+ , height 200
+ , preserveAspectRatio "none"
+ , viewBox ("0 0 " ++
+ (String.fromFloat (Point.duration allPoints)) ++
+ " " ++ maxY)
]
[ g
- [ fill "none"
- , stroke "red"
- , strokeWidth "3"
+ [ stroke "#ee4444"
+ , strokeWidth "2"
+ , transform ("translate(0, " ++ maxY ++") scale(1, -1)")
]
[
polyline
[ fill "none"
+ , style "vector-effect" "non-scaling-stroke"
, S.points string
] []
]