Sparkline view functions. There are two basic chart types:
These are conceptually very similar, except columns charts aggregate observations under a specified time interval, whereas line charts do not do any aggregation, but plot the observations according to a continuous time scale, and draw a line between them.
The data to be charted must be a List (Time.Posix, Float). For line charts,
in most cases the X values should be unique, i.e. there should one Y
for every X, but this is not enforced. For columns charts, this constraint is
enforced by aggregating Y values over each given time interval, using a
provided aggregation function (by default, List.sum). (If you want the same
behavior for line charts, i.e. aggregating over time intervals, use the
functions in the Timeseries module on your data first.)
There are also functions for scaling multiple data series together, i.e. for creating 'facet' charts from small multiples:
Please note that these functions do not themselves group your data into small multiples, nor do they position or label the series each chart represents. That is all up to you. The purpose of these chart functions is to render the charts scaling the X and Y dimensions of the series according to the parameters you specify.
Finally, a function to create a single line chart with multiple series (with both X and Y dimensions scaled together) is provided:
For any chart type you can define which observations are highlighted. Often this is the last observation, or the min and/or the max, but there are some more options as well (see Highlight). Highlighted observations are rendered as circles (points) with a configurable color.
For any chart type except multiple-lines charts, you can provide and configure a an elm-visualization Brush to allow interactive selection of observations. This can also be configured to display X and Y values at the start and end of the selection -- interactive axis labels.
In addition, functions are available that return charts together with the data that is currently highlighted and selected (brushed), to make it easy to build a separate view based on the current highlights/selections.
See the examples directory for all features in action.
Produce a multi-line chart, with all given series scaled together on both
X and Y dimensions, using the given list of color pairs for the line and
highlight colors respectively of each series. (Note that colors are specified
as TypedSvg.Types.Paint.)
Example:
chart : Svg msg
chart =
lines defaultColorPairs config [series1, series2, series3, ... ]Note that neither brushing nor returning highlighted data is implemented currently for multi-line charts.
Produce a columns chart, passing in an optional brush for interactive selection. (See Example/Brush for a full example of how to set up brushes).
Example:
chart : Svg msg
chart =
columns config (Just brush) seriesProduce a list of line charts, scaling the given timeseries data together as specified by a Facet.Scaling2d, and passing in an optional brush for synchronized brushing across all charts. (See Example/Brush for an example of this).
Example (fixed X and free Y scales):
charts : List (Svg msg)
charts =
lineFacets
{ x = Facet.Fixed, y = Facet.Free }
config
(Just brush)
[ series1, series2, series3, ... ]Produce a list of columns charts, scaling the given timeseries data together as specified by a Facet.Scaling2d, and passing in an optional brush for synchronized brushing across all charts. (See Example/Brush for an example of this).
Example (fixed X and free Y scales):
charts : List (Svg msg)
charts =
columnsFacets
{ x = Facet.Fixed, y = Facet.Free }
config
(Just brush)
[ series1, series2, series3, ... ]Data type for chart and selected and highlighted data returned by lineData, lineFacetsData, columnsData, and columnsFacetsData.
Same as lineFacets, but returning ChartData with highlighted and selected (brushed) data, in addition to the chart.
Same as columnsFacets, but returning ChartData with highlighted and selected (brushed) data, in addition to the chart.
Options for chart highlighting.
NoHighlight: Don't highlight anythingHighlightLast: Highlight the last observationHighlightNegative: Highlight all values less than 0HighlightMin: Highlight the minimum value in the seriesHighlightMax: Highlight the maximum value in the seriesHighlightMinMax: Highlight the minimum and maximum values in the seriesHighlightPeaks: Highlight positive peaks detected in the series, with
specified parameters.See elm-visualization's peaks function for details on that calculation and the parameters needed.
Example:
config : Config msg
config =
lineConfig Time.Day Time.utc 100 50
|> withHighlight HighlightMaxBasic line chart configuration, given a Time.Zone, width, and height of chart.
Basic columns chart configuration, given an aggregation function, a Time.Interval, a Time.Zone, the width, and the height of chart.
Example for a columns chart aggregating by the mean of observations over month intervals:
config : Config msg
config =
columnsConfig
(\ys -> List.sum ys / (List.length ys |> toFloat))
Time.Month
Time.utc
100
50Set padding (in pixels) around chart
Set CSS block name (default is "sparklines")
Set highlight to include in chart
Configure the band-scale used for columns charts. Refer to elm-visualization Scale.BandConfig for details.
A default set of color-pairs for multi-lines charts. Uses
elm-visualization category10 color scale, with line color at 70% alpha of
the highlight color. Need a better default.
Chart configuration. See above for usage examples.
Configure brushing in chart (with no labels)
Example:
type Msg
= UpdateBrush Brush.OnBrush
| ...
config : Config Msg
config =
lineConfig Time.utc 100 50
|> withBrush UpdateBrush defaultBrushingAppearanceConfigure brushing in chart with both X and Y labels
Example:
type Msg
= UpdateBrush Brush.OnBrush
| ...
config : Config Msg
config =
lineConfig Time.utc 100 50
|> withBrushLabels UpdateBrush defaultBrushingAppearanceConfigure brushing in chart with only X labels
Configure brushing in chart with only Y labels
Configuration for the appearance of the brush overlay. Note that
colors are specified using TypedSvg.Type.Paint.
area: the fill color of the brushed area (or bars) of the chartbounds: the stroke color of the bounds lines of the brushboundsDashed: True if you want dashed bounds lineshighlight: the color of bounds lines and labels when the observations are
highlightedConfiguration for the appearance of the brush overlay labels. Note that
color is specified using TypedSvg.Type.Paint, and size is specified using
TypedSvg.Type.Length.
color: the text color of labelssize: the size of label textlabelX: how to display X (time) valueslabelY: how to display Y (float) valuesNote labelX uses the time zone specified in top-level Config.
Default brushing appearance options. Yellow selection area, 70% black solid (non-dashed) bounds lines, red when highlighted.
Format time interval labels (x axis) with custom function.
Note: The time zone in top-level Config is used to render labels.
Most date/time formatting libraries should compose with this. Internally, ryannhg/date-format is used for default formats based on the given interval.
Example:
yyyymmdd : Time.Zone -> Time.Posix -> String
yyyymmdd =
DateFormat.format
[ DateFormat.yearNumber
, DateFormat.monthFixed
, DateFormat.dayOfMonthFixed
]
config : Config Msg
config =
lineConfig Time.utc 100 50
|> withBrushLabels UpdateBrush defaultBrushingAppearance
|> formattingLabelsX yyyymmddFormat labels for the y axis with custom function
Set label (background) color (in TypedSvg.Types.Paint).
Set label size (in TypedSvg.Types.Length).
Produce a line chart, passing in an optional brush for interactive selection. (See Example/Brush for a full example of how to set up brushes).
Example: