Compare commits

...

4 Commits

Author SHA1 Message Date
12a547c7aa drag time graphs left/right 2024-11-16 18:11:21 +00:00
5f02b5b992 rename messages for map dragging 2024-11-16 00:03:55 +00:00
7fe09053e3 remove MapZoom{In,Out} messages
they can both be replaced with MapScale
2024-11-16 00:00:16 +00:00
8c1eb9f77f remove scroll buttons and message
no need for it, dragging works fine
2024-11-15 23:43:56 +00:00

View File

@ -144,6 +144,7 @@ type alias Model =
{ centre: Coord
, zoom: FineZoomLevel
, drag: Drag
, timeDrag: Drag
, startTime : Int
, duration : Int
, track: TrackState }
@ -155,7 +156,7 @@ init _ url navKey =
Just (Timeline (Just s) (Just d)) -> (s, d)
_ -> (10,10)
in
((Model (toCoord 51.60 -0.01) (FineZoomLevel (13*8)) None start duration Empty),
((Model (toCoord 51.60 -0.01) (FineZoomLevel (13*8)) None None start duration Empty),
(fetchTrack start duration))
-- SUBSCRIPTIONS
@ -177,14 +178,14 @@ fetchTrack start duration = Http.get
-- UPDATE
type Msg
= MapZoomIn
| MapZoomOut
| MapScale Float
| Scroll Int Int
| PointerDown (Int, Int)
| PointerMove (Int, Int)
| PointerUp (Int, Int)
= MapScale Int
| MapDragStart (Int, Int)
| MapDrag (Int, Int)
| MapDragFinish (Int, Int)
| TimeScale (Float)
| TimeDragStart (Int, Int)
| TimeDrag (Int, Int)
| TimeDragFinish (Int, Int)
| Loaded (Result Http.Error (List Point))
| NewUrlRequest
| UrlChanged
@ -196,25 +197,16 @@ update msg model = (newModel msg model, Cmd.none)
newModel msg model =
case msg of
MapZoomIn ->
{ model | zoom = incZoom model.zoom zoomStep }
MapZoomOut ->
{ model | zoom = incZoom model.zoom -zoomStep }
MapScale y ->
let dir = floor(abs(y)/y)
in { model | zoom = incZoom model.zoom dir }
Scroll x y ->
{ model | centre = translatePixels model.centre (toZoom model.zoom) (x,y) }
{ model | zoom = incZoom model.zoom y }
PointerDown (x,y) ->
MapDragStart (x,y) ->
{ model | drag = Dragging (x,y) (x,y) }
PointerMove (x,y) ->
MapDrag (x,y) ->
{ model | drag = dragTo model.drag (x,y) }
PointerUp (x,y) ->
MapDragFinish (x,y) ->
{ model | drag = None,
centre = translatePixels model.centre (toZoom model.zoom) (dragDelta model.drag) }
@ -226,7 +218,18 @@ newModel msg model =
, duration = len
}
TimeDragStart (x,y) ->
{ model | timeDrag = Dragging (x,y) (x,y) }
TimeDrag (x,y) ->
{ model | timeDrag = dragTo model.timeDrag (x,y) }
TimeDragFinish (x,y) ->
{ model | timeDrag = None,
startTime =
let (delta, _) = dragDelta model.timeDrag
in model.startTime + delta * model.duration // portalWidth
}
Loaded result ->
case result of
Ok trk -> { model | track = Present trk }
@ -379,7 +382,10 @@ ifTrack : Model -> (List Point -> Html msg) -> Html msg
ifTrack model content =
case model.track of
Present t ->
let points = Point.subseq t (toFloat model.startTime) (toFloat model.duration)
let (dt, _) = dragDelta model.timeDrag
dpix = dt * model.duration // portalWidth
start = toFloat (model.startTime + dpix)
points = Point.subseq t start (toFloat model.duration)
in content points
Failure f -> Debug.log f (div [] [ Html.text "failure", Html.text f])
Loading -> div [] [Html.text "loading"]
@ -407,9 +413,9 @@ canvas centre zoom width height model =
,style "left" (px -offsetX)
,style "top" (px -offsetY)
,style "lineHeight" (px 0)
,Pointer.onUp (\e -> PointerUp (epos e))
,Pointer.onMove (\e -> PointerMove (epos e))
,Pointer.onDown (\e -> PointerDown (epos e)) ]
,Pointer.onUp (\e -> MapDragFinish (epos e))
,Pointer.onMove (\e -> MapDrag (epos e))
,Pointer.onDown (\e -> MapDragStart (epos e)) ]
(tv :: tiles xs ys zoom)
portalWidth = 600
@ -423,7 +429,8 @@ withSwallowing m =
-- FIXME should do something useful with deltaMode as well as deltaY
mapWheelDecoder =
D.map (withSwallowing << MapScale) (D.field "deltaY" D.float)
let sgn x = floor((abs x)/x)
in D.map (withSwallowing << MapScale << sgn) (D.field "deltaY" D.float)
timeWheelDecoder =
D.map (withSwallowing << TimeScale) (D.field "deltaY" D.float)
@ -432,6 +439,7 @@ viewDiv : Model -> Html Msg
viewDiv model =
let coord = translate model.centre (pixelsToCoord (toZoom model.zoom) (dragDelta model.drag))
canvasV = canvas coord (toZoom model.zoom) portalWidth portalHeight model
epos e = Tuple.mapBoth floor floor e.pointer.clientPos
in div [ style "display" "flex"
, style "column-gap" "15px"
]
@ -446,16 +454,15 @@ viewDiv model =
[canvasV]
, text ("Zoom level " ++ (String.fromInt (toZoom model.zoom)))
, span []
[ button [ onClick MapZoomOut ] [ text "-" ]
, button [ onClick MapZoomIn ] [ text "+" ]
, button [ onClick (Scroll 0 -10) ] [ text "^" ]
, button [ onClick (Scroll 0 10) ] [ text "V" ]
, button [ onClick (Scroll -10 0) ] [ text "<" ]
, button [ onClick (Scroll 10 0) ] [ text ">" ]
[ button [ onClick (MapScale -zoomStep) ] [ text "-" ]
, button [ onClick (MapScale zoomStep) ] [ text "+" ]
]
]
, div [ style "display" "flex"
, Html.Events.custom "wheel" timeWheelDecoder
, Pointer.onUp (\e -> TimeDragFinish (epos e))
, Pointer.onMove (\e -> TimeDrag (epos e))
, Pointer.onDown (\e -> TimeDragStart (epos e))
, style "flex-direction" "column"
, style "row-gap" "10px"
]