Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elm Europe 2017 - Elm Plot: The big picture

Elm Europe 2017 - Elm Plot: The big picture

Tereza Sokol

June 09, 2017
Tweet

More Decks by Tereza Sokol

Other Decks in Programming

Transcript

  1. type alias PlotConfig data = { height : Int ,

    width : Int , series : List (SeriesConfig data) } type alias SeriesConfig data = { color : String , colorArea : String , toX : data -> List Int , toY : data -> List Int }
  2. config : PlotConfig Data config = { height = 300

    , width = 500 , series = seriesConfigs } seriesConfigs : SeriesConfig Data seriesConfigs = [ { color = “pink” , colorArea = “lightpink” , toX = .x , toY = .y } ] main = plot config data
  3. main = plot [ width 800, height 500 ] [

    area [ stroke “pink” , fill “lightpink” ] data , xAxis [ tick myCustomTick ] , yAxis [] ]
  4. type Element msg = Axis (AxisConfig msg) | Area AreaConfig

    | Line LineConfig plot : List PlotAttr -> List (Element msg) -> Svg msg
  5. type alias AreaConfig = { fill : String , stroke

    : String } fill : String -> AreaConfig -> AreaConfig stroke : String -> AreaConfig -> AreaConfig area : List (AreaConfig -> AreaConfig) -> List Point -> Element msg
  6. main = plot [ dimensions (800, 500) ] [ area

    [ stroke “pink” , fill “lightpink” ] data ] config = { name = “yay plots” , width = 800 , height = 500 , series = seriesConfigs } seriesConfigs = [ { color = “pink” , colorArea = “lightpink” , toX = .x , toY = .y } ] main = plot config data vs.
  7. main = plot [ dimensions (800, 500) ] [ area

    [ stroke “pink” , fill “lightpink” ] data ] config = { name = “yay plots” , width = 800 , height = 500 , series = seriesConfigs } seriesConfigs = [ { color = “pink” , colorArea = “lightpink” , toX = .x , toY = .y } ] main = plot config data vs. ¯\_(ツ)_/¯
  8. fill : String -> AreaConfig -> AreaConfig stroke : String

    -> AreaConfig -> AreaConfig strokeWidth : Int-> AreaConfig -> AreaConfig dashed : AreaConfig -> AreaConfig …
  9. fill : String -> AreaConfig -> AreaConfig stroke : String

    -> AreaConfig -> AreaConfig strokeWidth : Int-> AreaConfig -> AreaConfig dashed : AreaConfig -> AreaConfig … nah
  10. main = plot [ areaSerie Bezier [ stroke “pink”, fill

    “lightpink” ] data1 , lineSerie Linear [ stroke “lightskyblue” ] data2 ]
  11. main = [ areaSerie Bezier [ stroke “pink”, fill “lightpink”

    ] data1 , lineSerie Linear [ stroke “lightskyblue” ] data2 , xAxis closestToZero [ axisLine [ stroke “grey” ] , ticks [ stroke skinStroke, length 15 ] (fromDelta 0.5) , ticks [ stroke blueStroke, length 10, strokeWidth “2px” ] (fromDelta 1) , labels [ fill pinkStroke ] toString (fromDelta 1) ] , yAxis lowest [ axisLine [ fill blueStroke, stroke skinStroke ] , ticks [ stroke blueStroke, length 4, strokeWidth “2px” ] (fromDelta 1) , labels [ fill pinkStroke ] toString (fromDelta 1) ] , yAxis closestToZero [ axisLine [ fill blueStroke, stroke skinStroke ] , ticks [ stroke blueStroke, length 4, strokeWidth “2px” ] (fromDelta 1) , labels [ fill pinkStroke ] toString (fromDelta 1) ] , verticalGrid [ stroke skinStroke ] (fromDelta 1) ]
  12. main = [ lineSerie Linear [] data , xAxis atZero

    [] , yAxis atLowest [] , yAxis atZero [] ]
  13. type alias Series data msg = { axis : Axis

    , interpolation : Interpolation , toDataPoints : data -> List (DataPoint msg) }
  14. dots : (data -> List (DataPoint msg)) -> Series data

    msg line : (data -> List (DataPoint msg)) -> Series data msg area : (data -> List (DataPoint msg)) -> Series data msg custom : Axis -> Interpolation -> (data -> List (DataPoint msg)) -> Series data msg