souplesse

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 20c287378ad93f08b3f2aef63719e3986e5c488a
parent affe6cdc56cb48b897061222b4d071d2b3c07c4f
Author: Daniel Barlow <dan@telent.net>
Date:   Fri, 22 Nov 2024 17:43:33 +0000

extract function for drag finish

Diffstat:
Mfrontend/src/Main.elm | 64++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 34 insertions(+), 30 deletions(-)

diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm @@ -138,7 +138,7 @@ dragDelta target d = else (0, 0) _ -> (0, 0) -subTuple (fx,fy) (tx,ty) = (fx-tx, fy-ty) +subtractTuple (fx,fy) (tx,ty) = (fx-tx, fy-ty) type TrackState = Empty | Loading | Failure String | Present (List Point) @@ -197,6 +197,37 @@ update : Msg -> Model -> (Model, Cmd Msg) update msg model = (updateModel msg model, Cmd.none) +secondsFromPixels model seconds = + (toFloat seconds) * model.duration / portalWidth + +handleDragFinish model target (x, y) = + case target of + Map -> + { model | + centre = translatePixels model.centre (toZoom model.zoom) (x, y) + } + Graph -> + { model | + startTime = + model.startTime + secondsFromPixels model x + } + StartMark -> + { model | + markedTime = + let deltat = secondsFromPixels model x + (s, d) = model.markedTime + in (s - deltat, d + deltat) + } + EndMark -> + { model | + markedTime = + let deltat = secondsFromPixels model x + (s, d) = model.markedTime + in (s, d - deltat) + } + NoTarget -> model + + updateModel msg model = case msg of MapScale y -> @@ -210,35 +241,8 @@ updateModel msg model = DragFinish (x,y) -> case model.drag of - Dragging Map start end -> - { model | - drag = None, - centre = translatePixels model.centre (toZoom model.zoom) (subTuple start end) } - Dragging Graph start end -> - { model | - drag = None, - startTime = - let (delta, _) = subTuple start end - in model.startTime + toFloat delta * model.duration / portalWidth - } - Dragging StartMark start end -> - { model | - drag = None, - markedTime = - let delta = Tuple.first (subTuple start end) - deltat = toFloat delta * model.duration / portalWidth - (s, d) = model.markedTime - in (s - deltat, d + deltat) - } - Dragging EndMark start end -> - { model | - drag = None, - markedTime = - let delta = Tuple.first (subTuple start end) - deltat = toFloat delta * model.duration / portalWidth - (s, d) = model.markedTime - in (s, d - deltat) - } + Dragging target start end -> + handleDragFinish { model | drag = None } target (subtractTuple start end) _ -> model TimeScale factor ->