terezka/charts/16.0.0

NOTE: the latest version is 20.0.1

Chart.Events

Add events.

Event handlers

type alias Attribute x data msg =
{ x | events : List (Event data msg) }
-> { x | events : List (Event data msg) }

An attribute for adding events.

type alias Event data msg =
Event data msg
onMouseMove : (a -> msg) -> Decoder data a -> Attribute x data msg

Add an mouse move event handler.

C.chart
  [ CE.onMouseMove (CE.getNearest CI.bars) ]
  [ .. ]

See example at elm-charts.org.

onMouseLeave : msg -> Attribute x data msg

Add an mouse leave event handler. See example at elm-charts.org.

onMouseUp : (a -> msg) -> Decoder data a -> Attribute x data msg

Add an mouse up event handler. See example at elm-charts.org.

onMouseDown : (a -> msg) -> Decoder data a -> Attribute x data msg

Add an mouse down event handler. See example at elm-charts.org.

onClick : (a -> msg) -> Decoder data a -> Attribute x data msg

Add an click event handler.

C.chart
  [ CE.onClick Clicked C.getCoords ]
  [ .. ]
on : String -> Decoder data msg -> Attribute x data msg

Add any event handler.

C.chart
  [ CE.on "mousemove" <|
      CE.map2 OnMouseMove
        (CE.getNearest CI.bars)
        (CE.getNearest CI.dots)


  ]
  [ .. ]

See example at elm-charts.org.

Decoders

type alias Decoder data msg =
Decoder data msg
type alias Point =
{ x : Float
, y : Float
}
getCoords : Decoder data Point

Decode to get the cartesian coordinates of the event.

Remodel (One data Any) (Item result)
-> Decoder data (List (Item result))

Decode to get the nearest item to the event. Use the Remodel functions in Chart.Item to filter down what items or groups of items you will be searching for.

import Chart as C
import Chart.Attributes as CA
import Chart.Events as CE
import Chart.Item as CI


type alias Model =
  { hovering : List (CI.One Datum CI.Bar) }


init : Model
init =
  { hovering = [] }


type Msg
  = OnHover (List (CI.One Datum CI.Bar))


update : Msg -> Model -> Model
update msg model =
  case msg of
    OnHover hovering ->
      { model | hovering = hovering }


view : Model -> H.Html Msg
view model =
  C.chart
    [ CA.height 300
    , CA.width 300
    , CE.onMouseMove OnHover (CE.getNearest CI.bars)
    , CE.onMouseLeave (OnHover [])
    ]
    [ C.xLabels []
    , C.yLabels []
    , C.bars []
        [ C.bar .z []
        , C.bar .y []
        ]
        data


    , C.each model.hovering <| \p bar ->
        [ C.tooltip bar [] [] [] ]
    ]

See example at elm-charts.org.

Remodel (One data Any) (Item result)
-> Decoder data (List (Item result))

Like getNearest, but only takes x coordiante into account. Use the Remodel functions in Chart.Item to filter down what items or groups of items you will be searching for.

Float
-> Remodel (One data Any) (Item result)
-> Decoder data (List (Item result))

Decode to get the nearest item within certain radius to the event. Use the Remodel functions in Chart.Item to filter down what items or groups of items you will be searching for.

Float
-> Remodel (One data Any) (Item result)
-> Decoder data (List (Item result))

Like getWithin, but only takes x coordiante into account. Use the Remodel functions in Chart.Item to filter down what items or groups of items you will be searching for.

map : (a -> msg) -> Decoder data a -> Decoder data msg
map2 : (a -> b -> msg) -> Decoder data a -> Decoder data b -> Decoder data msg
(a -> b -> c -> msg)
-> Decoder data a
-> Decoder data b
-> Decoder data c
-> Decoder data msg
(a -> b -> c -> d -> msg)
-> Decoder data a
-> Decoder data b
-> Decoder data c
-> Decoder data d
-> Decoder data msg