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!
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.
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.
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.
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.
Adds classes to the label.
myYAxis : Plot.Element msg
myYAxis =
Plot.yAxis
[ Axis.label
[ Label.view
[ Label.classes [ "my-class" ] ]
]
]Displaces the label.
myYAxis : Plot.Element msg
myYAxis =
Plot.yAxis
[ Axis.label
[ Label.view
[ Label.displace ( 12, 0 ) ]
]
]Set the stroke color.
Set the stroke width (in pixels).
Set the opacity.
Set the fill color.
Set the font size (in pixels).
Add your own attributes. For events, see this example
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 ]
]