terezka/elm-plot/4.1.0

NOTE: this package is not compatible with Elm 0.19.1

Plot.Tick

Attributes for altering the view of your axis' ticks.

Before you read any further, please note that when I speak of the tick index, then I'm talking about how many ticks that particular tick 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 tick.

myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.tick
            [ Tick.view
                [ Tick.stroke "deeppink"
                , Tick.length 5
                , Tick.width 2
                ]
            ]
        ]

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 tick based on the tick's value and index (amount of ticks from origin) by providing a function returning a list of style attributes.

toTickStyles : ( Int, Float ) -> List Tick.StyleAttribute
toTickStyles ( index, value ) =
    if isOdd index then
        [ Tick.length 7
        , Tick.stroke , "#e4e3e3"
        ]
    else
        [ Tick.length 10
        , Tick.stroke "#b9b9b9"
        ]


myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.tick
            [ Tick.viewDynamic toTickStyles ]
        ]

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).

viewTick : ( Int, Float ) -> Svg.Svg a
viewTick ( index, tick ) =
    text_
        [ transform "translate(-5, 10)"
        , Svg.Events.onClick (Custom MyTickClickMsg)
        ]
        [ tspan
            []
            [ text (if isOdd index then "🌟" else "⭐") ]
        ]


myXAxis : Plot.Element msg
myXAxis =
    Plot.xAxis
        [ Axis.tick
            [ Tick.viewCustom viewTick ]
        ]

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 fulfill 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

Add classes to the tick.

myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.tick
            [ Tick.view
                [ Tick.classes [ "my-tick" ] ]
            ]
        ]
width : Int -> StyleAttribute msg

Set the width of the tick (in pixels).

myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.tick
            [ Tick.view
                [ Tick.width 2 ]
            ]
        ]
length : Int -> StyleAttribute msg

Set the length of the tick (in pixels).

myYAxis : Plot.Element msg
myYAxis =
    Plot.yAxis
        [ Axis.tick
            [ Tick.view
                [ Tick.length 8 ]
            ]
        ]
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.

customAttrs : List (Attribute msg) -> StyleAttribute msg

Add your own attributes. For events, see this example