souplesse

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

Model.elm (1595B)


      1 module Model exposing
      2     (
      3       Model
      4     , TrackState(..)
      5     , DragState(..)
      6     , empty
      7     , isMarkActive
      8     , marks
      9     )
     10 import TileMap exposing (ZoomLevel(..), Coord, toCoord)
     11 import Point exposing (Point)
     12 import Pos exposing (Pos)
     13 
     14 type DragState =
     15     DragMap (Int, Int) Coord
     16   | DragGraph (Int, Int) Float
     17   | DragLeftMark (Int, Int) Float
     18   | DragRightMark (Int, Int) Float
     19 
     20 
     21 type GraphToggle = Hidden | Overlay | Solo
     22 
     23 type alias TimeGraph =
     24     { title: String
     25     , id: String
     26     , colour: String
     27     , extractor: Point -> Maybe Float
     28     , toggle : GraphToggle
     29     , threshold : Float
     30     }
     31 
     32 type TrackState = Empty | Loading | Failure String | Present (List Point)
     33 
     34 type alias Model =
     35     { centre: Coord
     36     , zoom: ZoomLevel
     37     , drag: Maybe DragState
     38     , startTime : Float
     39     , duration : Float
     40     , leftMark : Float
     41     , rightMark : Float
     42     , graphs : List TimeGraph
     43     , track: TrackState }
     44 
     45 empty = Model
     46         (toCoord (Pos 0 0 Nothing))
     47         (ZoomLevel 0)
     48         Nothing
     49         0 0
     50         0 0
     51         [
     52          TimeGraph "Cadence" "cadence" "#44ee44" (.cadence >> Maybe.map toFloat)
     53              Solo 90
     54         , TimeGraph "Power" "power"  "#994444" (.power >> Maybe.map toFloat)
     55              Solo 100
     56         , TimeGraph "Elevation" "elevation"  "#4444ee" (.pos >> .ele)
     57              Solo 0
     58         ]
     59         Loading
     60 
     61 isMarkActive model =
     62     model.leftMark > model.startTime ||
     63         model.rightMark < (model.startTime + model.duration)
     64 
     65 marks model =
     66     if isMarkActive model
     67     then Just (model.leftMark, model.rightMark)
     68     else Nothing