jxxcarlson/elm-stat/5.0.1

NOTE: the latest version is 6.0.3

Chart

Functions for building graphs and charts. A chart consists of one more graphs. Graphs come in various flavors, notably line and scatter.

In this module, Svg means TypedSvg.Core.Svg

Types

type alias BoundingBox =
{ xMin : Float
, xMax : Float
, yMin : Float
, yMax : Float
}

A box containing data of the form List (Float, Float)

type alias Format =
{ width : Float
, height : Float
, padding : Float
}

Format determines the height, width, and appearance of the rendered chart

type alias Graph =
{ graphType : GraphType
, r : Float
, g : Float
, b : Float
, boundingBox : BoundingBox
, data : Data
}

A Graph consists of data in the form of List (Float, Float), a bounding box, a choice of color, and a GraphType, e.g, Line or Scatter.

= Line
| Scatter
| MeanLine
type alias Chart =
{ boundingBox : BoundingBox
, confidence : Maybe Float
, data : List Graph
}

A chart consists of a boundig box and a list of Graphs. A chart is rendered to SVG by the view function.

Constructing and operating on graphs

boundingBox : Data -> BoundingBox

Compute a bounding box from data, where

type alias Data =
    List ( Float, Float )
emptyGraph : Graph
graph : GraphType -> Float -> Float -> Float -> Data -> Graph

Make a graph of given GraphType and given color r, g, b from the given data. where

type alias Data =
    List ( Float, Float )
lineGraph : Format -> Graph -> Svg msg

Render graph data to SVG as a broken line.

meanLine : Format -> Graph -> Svg msg

Draw a line through mean values of the data.

scatter : Format -> Graph -> Svg msg

Render graph data to SVG as a scatter plot.

errorBars : Format -> Float -> Data -> Svg msg

Render error bars with given confidence level for the given data as SVG

Constructing and operating on charts

view : Format -> Maybe (Svg msg) -> Chart -> Svg msg

Convert a chart to (typed) SVG. Parameters:

  • Format: determines the dimensions and appearance of the output

  • Maybe (Svg mg): this is an "annotation," which maybeNothingorJust svgValue, wheresvgValueis any value of typeSvg msg. HereSvgmeand TypedSvg.Core.Svg.

  • Chart: the chart to be rendered

One use of annotations is to add error bars to a chart. See ./examples/src/Hubble.elm

chart : Graph -> Chart

Make a chart out of a graph

addGraph : Graph -> Chart -> Chart

Add a graph to an existing Chart