extract function for drag finish
This commit is contained in:
parent
affe6cdc56
commit
20c287378a
@ -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 ->
|
||||
|
Loading…
Reference in New Issue
Block a user