jxxcarlson / elm-stat / StatChart

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 : Basics.Float
, xMax : Basics.Float
, yMin : Basics.Float
, yMax : Basics.Float 
}

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


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

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


type alias Graph =
{ graphType : GraphType
, r : Basics.Float
, g : Basics.Float
, b : Basics.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.


type GraphType
    = Line
    | Scatter
    | MeanLine


type alias StatChart =
{ boundingBox : BoundingBox
, confidence : Maybe Basics.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 -> Basics.Float -> Basics.Float -> Basics.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 -> TypedSvg.Core.Svg msg

Render graph data to SVG as a broken line.

meanLine : Format -> Graph -> TypedSvg.Core.Svg msg

Draw a line through mean values of the data.

scatter : Format -> Graph -> TypedSvg.Core.Svg msg

Render graph data to SVG as a scatter plot.

errorBars : Format -> Basics.Float -> Data -> TypedSvg.Core.Svg msg

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

Constructing and operating on charts

view : Format -> Maybe (TypedSvg.Core.Svg msg) -> StatChart -> TypedSvg.Core.Svg msg

Convert a chart to (typed) SVG. Parameters:

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

chart : Graph -> StatChart

Make a chart out of a graph

addGraph : Graph -> StatChart -> StatChart

Add a graph to an existing StatChart