Skip to content

Instantly share code, notes, and snippets.

@cjwebb

cjwebb/graph.elm

Created Dec 17, 2015
Embed
What would you like to do?
import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
main : Element
main =
collage 300 300
[ blueLine
, xAxis
, yAxis
]
xAxis : Form
xAxis =
traced (solid black) (path [(0,0),(0, 300)])
yAxis : Form
yAxis =
traced (solid black) (path [(0,0),(300, 0)])
blueLine : Form
blueLine =
traced (solid blue) line
transform : GraphData -> (Float, Float)
transform graphData =
(graphData.time * 10, graphData.value)
line : Path
line =
path (List.map transform data)
type alias GraphData =
{ time: Float
, value: Float
}
data: List GraphData
data =
[ { time = 1, value = 10 }
, { time = 2, value = 20 }
, { time = 3, value = 50 }
, { time = 4, value = 100 }
, { time = 5, value = 50 }
, { time = 6, value = 70 }
, { time = 7, value = 90 }
, { time = 8, value = 50 }
, { time = 9, value = 40 }
, { time = 10, value = 40 }
, { time = 11, value = 40 }
, { time = 12, value = 40 }
, { time = 13, value = 40 }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment