This is an interface for dealing with different chart items, such as bars, dots, or groups of such, like bins or stacks. It comes in handy when dealing with events:
import Chart as C
import Chart.Events as CE
import Chart.Item as CI
C.chart
[ CE.onMouseMove OnHover (CE.getNearest CI.bars) ]
[ C.bars [ C.bar .x [] ] data ]Or when using functions like C.eachBar or C.eachBin:
import Chart as C
import Chart.Events as CE
import Chart.Item as CI
import Svg as S
C.chart
[ CE.onMouseMove OnHover (CE.getNearest CI.bars) ]
[ C.bars [ C.bar .x [] ] data
, C.eachBar <| \plane bar ->
[ C.label [] [ S.text (String.fromFloat (CI.getY bar)) ] (CI.getTop plane bar) ]
]Information about a dot or a bar.
Information about the configuration of a bar.
Information about the configuration of a dot.
Get the data the item was produced from.
Get the x value of the item.
Get the x1 value of the item.
Get the x2 value of the item.
Get the y value of the item.
Get the name of the series which produced the item.
Get the color of the item.
Get the size of a dot.
Get the formatted y value.
Is the item a representation of missing data? This may be
the case if you used e.g. C.scatterMaybe or C.barMaybe.
Is this item the exact same as the other?
Filter for a certain data type.
A collection of many items.
Many data Bar -- representation of several bars
Many data Dot -- representation of several dots
Many data Any -- representation of several dos or barsSometimes it's neccessary to work with a group of items, rather than a single. For example, if you'd like a tooltip to show up on top of a stacked bar, it's helpful to be able to treat all the pieces of that stack at the same time.
Get all members of the group.
Get the first members of the group.
This is useful when you know all members of the group share some of the same characteristics. For example, if you have a vertical stack of bars, they will all have the same x values. If you'd like to access those x values, it doesn't matter which one you pick as they are all the same, so the first one is thus fine.
Get the data from each member in the group.
Get the data from the first member in the group.
Remodeling offers a way to filter and group chart items. For example,
if you have a variable items of type List (One Data Any), you can
filter it such that it only contains bars:
CI.apply CI.bars items -- List (One Data Bar)This is the interface used in the events api too. If you'd like to get the nearest bar on mouse move, you'd say:
CE.onMouseMove OnHovering (CE.getNearest CI.bars)Apply a remodelling.
Chain a remodelling.
Keep anything.
Keep only dots.
Keep only bars.
Remove representations of missing data.
Keep only items coming from series with the names listed.
Group into bins. Items are in the same bin if they are produced from the same element and the same data point.
Group into bins. Items are in the same stack
if they are produced from the same C.stacked property.
Group into items with the same x value.
An "item" on the chart. A One Data Bar and Many Data Bar are both
instances on this type, so you can use all the fuctions below on those too.
In a few cases, a rendered item's "position" and "limits" aren't the same.
In the case of a bin, 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 default tooltip.
A representation containing information about a certain item on the chart, such as a bar or a dot.
It allows us to know e.g. the exact position of the item, the color, what data it was produced from, and whether it is a representation of missing data or not.