Add events and interact with chart "items".
Add an mouse move event handler.
C.chart
[ CE.onMouseMove (CE.getNearest CE.bar) ]
[ .. ]See example at elm-charts.org.
Add an mouse leave event handler. See example at elm-charts.org.
Add an mouse up event handler. See example at elm-charts.org.
Add an mouse down event handler. See example at elm-charts.org.
Add an click event handler.
C.chart
[ CE.onClick Clicked C.getCoords ]
[ .. ]Add any event handler.
C.chart
[ CE.on "mousemove" <|
CE.map2 OnMouseMove
(CE.getNearest CE.bar)
(CE.getNearest CE.dot)
]
[ .. ]See example at elm-charts.org.
Decode to get the cartesian coordinates of the event.
Decode to get the nearest item to the event.
type alias Model =
{ hovering : List (CE.Product CE.Bar (Maybe Float) Datum) }
init : Model
init =
{ hovering = [] }
type Msg
= OnHover (List (CE.Product CE.Bar (Maybe Float) Datum))
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 CE.bar)
, 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.
Like getNearest, but only takes x coordiante into account
Decode to get the nearest item within certain radius to the event.
Like getWithin, but only takes x coordiante into account
An item is anything on the chart which is produced from data elements, that is bar, line, and scatter charts.
It may be a single one of such items (a Product), or a group of such items (a Group).
A product is an item produced by a bar series, or a dot series (line or scatter).
CE.Product CE.Any value data -- A product of either a bar or dot series
CE.Product CE.Dot value data -- A product of a dot series
CE.Product CE.Bar value data -- A product of a bar seriesYou may have used C.scatterMaybe or C.barMaybe to represent
missing data on your chart. The second type value represent
whether this product could be a representation of a missing data
point.
CE.Product CE.Any Float data
-- A product of a bar or dot series which is always
-- a real data point.
CE.Product CE.Any (Maybe Float) data
-- A product of a bar or dot series which may or
-- may not be a real data point.A group is a collection of products which have certain characteristics in common. For example, a stacked bar is produced from the same data point and has the same x value.
Group (Stack data) Bar value data -- representation of a stack of bars
Group (Bin data) Bar value data -- representation of a bin of barsSay we have an event handler like so:
CE.onMouseMove (CE.getNearest CE.bar)The function getNearest takes a Grouping as the first argument. A
Grouping is essentially a method for filtering or collecting items.
For example, the grouping bar takes a list of Product Any value data
and filters it, such that there are only bar products left, that is a
list of Product Bar value data.
On the other hand, the grouping bin takes a list of Product config value data
and bundles all the products made from the same data point together. This results
in a list of Group (Bin data) config value data.
If you'd like to combine the two and collect all bins of bars, you can do it like so.
CE.collect CE.bin CE.barThis will result in a list of Group (Bin data) Bar value data.
Check out the many examples on elm-charts.org.
Filter a set of products.
CE.keep CE.realValues CE.bar
-- Keeps all bars which are not a representation of missing data.The configuration of either a dot or a bar.
All products.
CE.getNearest CE.product
-- gets nearest product (bar or dot)The coniguration of a bar.
All bars.
CE.getNearest CE.bar
-- gets nearest barThe coniguration of a dot.
All dots.
CE.getNearest CE.dot
-- gets nearest dotAll real values. If you have used Chart.barMaybe or the like,
you may have representations of missing data in your chart. This can filter
those out.
CE.getNearest CE.realValues
-- gets nearest product which is not a representation of missing data.All values produced from a particular set of series.
CE.getNearest (CE.named [ "cats", "dogs" ])
-- gets nearest product from the cats or dogs series.Collect groups from a set of products.
CE.collect CE.bin CE.bar
-- collect all bars into bins.Collect values of the same bin into groups. Two products are in the same bin if
they are produced from the same data from your List data in your bar or dot series.
CE.getNearest CE.bin
-- gets nearest bin.Collect values of the same stack into groups. A stack is produced using C.stacked.
CE.getNearest CE.stack
-- gets nearest stack.All values with the same x values.
CE.getNearest CE.sameX
-- gets nearest set of products from any series, sharing the same x values.Low level api for applying a Grouping.
C.withProducts <| \p products ->
let grouping : Grouping (Product Any (Maybe Float) Datum) (Group (Bin Datum) Bar Float Datum)
grouping =
CE.bar
|> CE.keep CE.realValues
|> CE.collect CE.bin
toBinLabel : Group (Bin Datum) Bar Float Datum -> Element msg Datum
toBinLabel bin =
let datum = (CE.getCommonality bin).datum in
C.label [] [ S.text datum.country ] (CE.getTop p bin)
in
List.map toBinLabel (CE.group grouping products).Low level helper to applying a new grouping to a group. Same as saying:
CE.group (CE.getProducts myGroup)Get the dependent (y) value.
Get the independent (x) value.
Get the datum which produced this product.
Get the color of the product.
Get the name of the series which produced the product.
Is this product the exact same as this other one?
Get the size of the product (only if a dot).
Render the default tooltip of an item.
Get the center top of item.
Get the top left of item.
Get the top right of item.
Get the center bottom of item.
Get the bottom left of item.
Get the bottom right of item.
Get the center left of item.
Get the center right of item.
Get center of item.
Get full position of item.
In a few cases, an item's "position" and "limits" aren't the same.
In the case of bins, the "position" is the area which the bins bars take up, not inclusing any margin which may be around them. Its "limits" include the margin.
Get the products of a group.
Get the commonality of a group.
Keep products of certain data types.
An attribute for adding events.