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