use Float for time consistently
This commit is contained in:
parent
f17332a047
commit
70a654c472
@ -21,12 +21,11 @@ import Svg.Attributes as S exposing
|
||||
, x1, y1 , x2, y2
|
||||
, fill
|
||||
, stroke, strokeWidth, strokeOpacity)
|
||||
import Time -- exposing(Posix)
|
||||
import Time
|
||||
import Url.Parser exposing (Parser, (<?>), int, map, s, string)
|
||||
import Url.Parser.Query as Query
|
||||
import Url exposing (Url)
|
||||
|
||||
|
||||
type Route = Timeline (Maybe Int) (Maybe Int)
|
||||
|
||||
routeParser : Parser (Route -> a) a
|
||||
@ -147,20 +146,20 @@ type alias Model =
|
||||
{ centre: Coord
|
||||
, zoom: FineZoomLevel
|
||||
, drag: Drag
|
||||
, startTime : Int
|
||||
, duration : Int
|
||||
, startTime : Float
|
||||
, duration : Float
|
||||
, track: TrackState }
|
||||
|
||||
init : () -> Url -> Nav.Key -> (Model, Cmd Msg)
|
||||
init _ url navKey =
|
||||
let (start, duration) =
|
||||
case Url.Parser.parse routeParser url of
|
||||
Just (Timeline (Just s) (Just d)) -> (s, d)
|
||||
Just (Timeline (Just s) (Just d)) -> (toFloat s, toFloat d)
|
||||
_ -> (10,10)
|
||||
in
|
||||
((Model
|
||||
(toCoord (Pos 0 0 Nothing))
|
||||
(FineZoomLevel (1*8)) None 0 0 Loading),
|
||||
(FineZoomLevel (1*8)) None 0 0 Nothing Loading),
|
||||
(fetchTrack start duration))
|
||||
|
||||
-- SUBSCRIPTIONS
|
||||
@ -171,9 +170,9 @@ subscriptions model = Sub.none
|
||||
|
||||
fetchTrack start duration = Http.get
|
||||
{ url = ("http://localhost:3000/points?start=" ++
|
||||
String.fromInt start ++
|
||||
String.fromInt (floor start) ++
|
||||
"&duration=" ++
|
||||
String.fromInt duration)
|
||||
String.fromInt (ceiling duration))
|
||||
, expect = Http.expectJson Loaded (D.list Point.decoder)
|
||||
}
|
||||
|
||||
@ -219,14 +218,14 @@ updateModel msg model =
|
||||
drag = None,
|
||||
startTime =
|
||||
let (delta, _) = subTuple start end
|
||||
in model.startTime + delta * model.duration // portalWidth
|
||||
in model.startTime + toFloat delta * model.duration / portalWidth
|
||||
}
|
||||
_ -> model
|
||||
TimeScale factor ->
|
||||
let fudge = factor
|
||||
len = model.duration - floor(fudge)
|
||||
len = model.duration - fudge
|
||||
in { model |
|
||||
startTime = model.startTime + floor(fudge / 2)
|
||||
startTime = model.startTime + fudge / 2
|
||||
, duration = len
|
||||
}
|
||||
|
||||
@ -240,8 +239,9 @@ updateModel msg model =
|
||||
| track = Present trk
|
||||
, centre = toCoord (Point.centre trk)
|
||||
, zoom = FineZoomLevel ( 13 * 8)
|
||||
, startTime = floor start
|
||||
, duration = ceiling duration
|
||||
, startTime = start
|
||||
, duration = duration
|
||||
-- , markedTime = Just (start + 300, duration - 600)
|
||||
}
|
||||
Err (Http.BadBody e) -> { model | track = Debug.log e (Failure "e") }
|
||||
Err e -> { model | track = Debug.log "unknown error" (Failure "e") }
|
||||
@ -521,9 +521,9 @@ ifTrack model content =
|
||||
case model.track of
|
||||
Present t ->
|
||||
let (dt, _) = dragDelta Graph model.drag
|
||||
dpix = dt * model.duration // portalWidth
|
||||
start = toFloat (model.startTime + dpix)
|
||||
points = Point.subseq t start (toFloat model.duration) |>
|
||||
dpix = toFloat dt * model.duration / portalWidth
|
||||
start = model.startTime + dpix
|
||||
points = Point.subseq t start model.duration |>
|
||||
Point.downsample 300
|
||||
in content points
|
||||
Failure f -> Debug.log f (div [] [ Html.text "failure", Html.text f])
|
||||
|
Loading…
Reference in New Issue
Block a user