NoRedInk/elm-plot-rouge/1.0.0

NOTE: the latest version is 1.0.1

Svg.Plot

Disclaimer: If you're looking for a plotting library, then please use elm-plot instead, as this library is not made to be user friendly. If you feel like you're missing something in elm-plot, you're welcome to open an issue in the repo and I'll see what I can do to accommodate your needs!


This module contains higher-level SVG plotting elements.

Series

Dots

type alias Dot msg =
{ view : Maybe (Float -> Float -> Svg msg)
, x : Float
, y : Float
}
dot : Svg msg -> Float -> Float -> Dot msg

An dot with a view which is wrapped in a g element and positioned with a transform.

clear : Float -> Float -> Dot msg

A dot without visual representation.

customDot : (Float -> Float -> Svg msg) -> Float -> Float -> Dot msg

An dot with a view where you control how it's positioned.

Interpolation

scatter : Plane -> List (Dot msg) -> Svg msg

Series with no interpolation.

linear : Plane -> List (Attribute msg) -> List (Dot msg) -> Svg msg

Series with linear interpolation.

monotone : Plane -> List (Attribute msg) -> List (Dot msg) -> Svg msg

Series with monotone interpolation.

linearArea : Plane -> List (Attribute msg) -> List (Dot msg) -> Svg msg

Area series with linear interpolation.

monotoneArea : Plane -> List (Attribute msg) -> List (Dot msg) -> Svg msg

Area series with monotone interpolation.

Note on usage

These elements render a line series if no fill attribute is added!

areaSeries : Svg msg
areaSeries =
    monotone plane [ fill "pink" ] dots


lineSeries : Svg msg
lineSeries =
    monotone plane [] dots

Bars

type alias Bar msg =
{ attributes : List (Attribute msg)
, y : Float
}

Groups

type alias Groups msg =
{ groups : List (List (Bar msg))
, width : Float
}
grouped : Plane -> Groups msg -> Svg msg

You can draw a bar chart like this:

group : List Float -> List (Bar msg)
group =
    List.map (Bar [ stroke "pink", fill "lightpink" ])


groups : Groups msg
groups =
    { groups = List.map group [ [ 2, 3, 1 ], [ 5, 1, 4 ], [ 1, 5, 3 ] ]
    , width = 0.8
    }


main : Svg msg
main =
    svg
        [ width (String.fromFloat plane.x.length)
        , height (String.fromFloat plane.y.length)
        ]
        [ grouped plane groups ]

Note on width: The width takes catersian units, however, should you have a width in SVG units, you can use Svg.Coordinates.scaleCartesian to translate it into cartesian units.

Histograms

type alias Histogram msg =
{ bars : List (Bar msg)
, interval : Float
, intervalBegin : Float
}

The bars are the class frequencies and the interval is the class interval's upper limit minus lower limit. Right now, you can only have equal class intervals, but I might add unequal support later!

What is going on with all these words?

histogram : Plane -> Histogram msg -> Svg msg
frequencies : List Float
frequencies =
    [ 1, 2, 3, 6, 8, 9, 6, 4, 2, 1 ]


testScores : Histogram msg
testScores =
    { bars = List.map (Bar [ stroke blueStroke, fill blueFill ]) frequencies
    , interval = 1
    }


main : Svg msg
main =
    svg
        [ width (String.fromFloat plane.x.length)
        , height (String.fromFloat plane.y.length)
        ]
        [ histogram plane testScores ]

Straight lines

Plane
-> List (Attribute msg)
-> Float
-> Float
-> Float
-> Float
-> Svg msg

Renders a line.

myLine : Svg msg
myLine =
    horizontal plane [ stroke "pink" ] x0 y0 x1 y1
fullHorizontal : Plane -> List (Attribute msg) -> Float -> Svg msg

Renders a horizontal line with the full length of the range.

myXAxisOrGridLine : Svg msg
myXAxisOrGridLine =
    fullHorizontal plane [] yPosition
fullVertical : Plane -> List (Attribute msg) -> Float -> Svg msg

Renders a vertical line with the full length of the domain.

myYAxisOrGridLine : Svg msg
myYAxisOrGridLine =
    fullVertical plane [] xPosition
horizontal : Plane -> List (Attribute msg) -> Float -> Float -> Float -> Svg msg

Renders a horizontal line.

myLine : Svg msg
myLine =
    horizontal plane [ stroke "pink" ] y x0 x1
vertical : Plane -> List (Attribute msg) -> Float -> Float -> Float -> Svg msg

Renders a vertical line.

myLine : Svg msg
myLine =
    vertical plane [ stroke "pink" ] x y0 y1

Ticks

ProTip: Passing a negative value as the height/width of a tick renders it mirrored on the other side of the axis!

xTick : Plane -> Int -> List (Attribute msg) -> Float -> Float -> Svg msg

Renders a single tick for the horizontal axis.

xTicks : Plane -> Int -> List (Attribute msg) -> Float -> List Float -> Svg msg

Renders ticks for the horizontal axis.

horizontalTicks : Svg msg
horizontalTicks =
    xTicks plane height [ stroke "pink" ] axisYCoordinate tickPositions
yTick : Plane -> Int -> List (Attribute msg) -> Float -> Float -> Svg msg

Renders a single tick for the vertical axis.

yTicks : Plane -> Int -> List (Attribute msg) -> Float -> List Float -> Svg msg

Renders ticks for the vertical axis.

verticalTicks : Svg msg
verticalTicks =
    yTicks plane width [ stroke "pink" ] axisXCoordinate tickPositions