terezka/elm-plot/4.0.0

NOTE: this package is not compatible with Elm 0.19.1

Plot.Label

Attributes for altering the view of your labels.

Before you read any further, please note that when I speak of the label index, then I'm talking about how many labels that particular label is from the origin.

Ok, now you can go on!

Definition

type alias Attribute a msg =
Config a msg -> Config a msg

View options

view : List (StyleAttribute msg) -> Attribute a msg

Provide a list of style attributes to alter the view of the label.

myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.label
            [ Label.view
                [ Label.classes [ "label-class" ]
                , Label.displace ( 12, 0 )
                ]
            ]
        ]

Note: If you add another attribute altering the view like viewDynamic or viewCustom after this attribute, then this attribute will have no effect.

viewDynamic : (a -> List (StyleAttribute msg)) -> Attribute a msg

Alter the view of the label based on the label's value and index (amount of ticks from origin) by providing a function returning a list of style attributes.

toViewStyles : Int -> Float -> List Label.StyleAttribute a
toViewStyles index value =
    if isOdd index then
        [ Label.classes [ "label--odd" ]
        , Label.displace ( 12, 0 )
        ]
    else
        [ Label.classes [ "label--even" ]
        , Label.displace ( 16, 0 )
        ]


myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.label
            [ Label.viewDynamic toViewStyles ]
        ]

Note: If you add another attribute altering the view like view or viewCustom after this attribute, then this attribute will have no effect.

viewCustom : (a -> Svg msg) -> Attribute a msg

Define your own view for the labels. Your view will be passed label's value and index (amount of ticks from origin).

viewLabel : Int -> Float -> Svg.Svg a
viewLabel index value =
    let
        attrs =
            if isOdd index then oddAttrs else evenAttrs
    in
        text_ attrs (toString value)


myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.label
            [ Label.viewCustom viewLabel ]
        ]

Note: If you add another attribute altering the view like view or viewDynamic after this attribute, then this attribute will have no effect.

Style attributes

If these attributes do not forfill your needs, try out the viewCustom! If you have a suspicion that I have missed a very common configuration, then please let me know and I'll add it.

type alias StyleAttribute msg =
StyleConfig msg -> StyleConfig msg
classes : List String -> StyleAttribute msg

Adds classes to the label.

myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.label
            [ Label.view
                [ Label.classes [ "my-class" ] ]
            ]
        ]
displace : ( Int, Int ) -> StyleAttribute msg

Displaces the label.

myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.label
            [ Label.view
                [ Label.displace ( 12, 0 ) ]
            ]
        ]
stroke : String -> StyleAttribute msg

Set the stroke color.

strokeWidth : Int -> StyleAttribute msg

Set the stroke width (in pixels).

opacity : Float -> StyleAttribute msg

Set the opacity.

fill : String -> StyleAttribute msg

Set the fill color.

fontSize : Int -> StyleAttribute msg

Set the font size (in pixels).

customAttrs : List (Attribute msg) -> StyleAttribute msg

Add your own attributes. For events, see this example

Value formatting

format : (a -> String) -> Attribute a msg

Format the label based on its value and index.

formatter : Int -> Float -> String
formatter index value =
    if isDivisibleBy5 index then
        formatEveryFifth value
    else
        normalFormat value


myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.label
            [ Label.format formatter ]
        ]
formatFromList : List String -> Attribute a msg