terezka/elm-plot/3.0.1

NOTE: this package is not compatible with Elm 0.19.1

Plot.Tick

Attributes for altering the values and 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 msg =
Config msg -> Config msg

Styling

type alias StyleAttribute msg =
StyleConfig msg -> StyleConfig msg
view : List (StyleAttribute msg) -> Attribute 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.style
                    [ ( "stroke", "deeppink" ) ]
                , Tick.length 5
                , Tick.width 2
                ]
            ]
        ]

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

viewDynamic : (( Int, Float ) -> List (StyleAttribute msg)) -> Attribute 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.style [ ( "stroke", "#e4e3e3" ) ]
        ]
    else
        [ Tick.length 10
        , Tick.style [ ( "stroke", "#b9b9b9" ) ]
        ]


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

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

viewCustom : (( Int, Float ) -> Svg msg) -> Attribute 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 msgltering 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.

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

Values

values : List Float -> Attribute msg

Specify what values will be added a tick.

myXAxis : Plot.Element msg
myXAxis =
    Plot.xAxis
        [ Axis.tick
            [ Tick.values [ 0, 1, 2, 4, 8 ] ]
        ]

Note: If you add another attribute msgltering the values like delta after this attribute, then this attribute will have no effect.

delta : Float -> Attribute msg

Specify what values will be added a tick by specifying the space between each tick.

myXAxis : Plot.Element msg
myXAxis =
    Plot.xAxis
        [ Axis.tick
            [ Tick.delta 4 ]
        ]

Note: If you add another attribute msgltering the values like values after this attribute, then this attribute will have no effect.