-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPoint.elm
69 lines (56 loc) · 1.73 KB
/
Point.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Point
exposing
( Point
, updatePosition
, updateStyles
, animateElement
, init
, renderPoints
)
import Svg exposing (svg, rect)
import Svg.Attributes exposing (height, width, x, fill, y)
import Html exposing (h3, text, Html)
import Html.Attributes exposing (style)
import Color
import Animation exposing (px)
type alias Point =
{ value : Int, xPosition : Int, style : Animation.State }
init : List Int -> List Point
init xs =
List.indexedMap
(\i x ->
Point
x
(20 * i)
(Animation.style
[ Animation.x (toFloat (20 * i))
, Animation.y (toFloat (100 - x))
, Animation.fill (Color.hsl ((toFloat x) * 0.05) 20.0 20.0)
, Animation.height (px (toFloat x))
]
)
)
xs
animateElement : Animation.Msg -> Point -> Point
animateElement time element =
{ element | style = Animation.update time element.style }
updatePosition : Int -> Point -> Point
updatePosition newPosition point =
{ point | xPosition = newPosition * 20 }
updateStyles : Point -> Point
updateStyles element =
{ element
| style =
Animation.interrupt
[ Animation.to
[ Animation.x (toFloat element.xPosition) ]
]
element.style
}
renderPoints : String -> List Point -> List (Html msg)
renderPoints label list =
[ (svg [ height "100", width "320" ]
(List.map (\element -> rect (Animation.render element.style ++ [ width "10" ]) []) list)
)
, (h3 [ style [ ( "textAlign", "center" ) ] ] [ text label ])
]