Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(barchart): adjust y axis formatting #838

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/elm/Components/BarChart.elm
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ view (BarChartConfig { title, width, height, padding, data, maybeMaxY, unit }) =
let
maxY =
case maybeMaxY of
Just max ->
max
Just max_ ->
max_

Nothing ->
List.maximum (List.map Tuple.second data)
|> Maybe.withDefault 0
max 1
(List.maximum (List.map Tuple.second data)
|> Maybe.withDefault 1
)

xScale : List ( Time.Posix, Float ) -> Scale.BandScale Time.Posix
xScale m =
Expand All @@ -202,7 +204,7 @@ view (BarChartConfig { title, width, height, padding, data, maybeMaxY, unit }) =

yAxis : Svg msg
yAxis =
Axis.left [ Axis.tickCount 5 ] yScale
Axis.left [ Axis.tickCount 5, Axis.tickFormat (Float.Extra.toFixedDecimalPlaces 1) ] yScale

column : Scale.BandScale Time.Posix -> ( Time.Posix, Float ) -> Svg msg
column scale ( date, value ) =
Expand Down Expand Up @@ -232,13 +234,13 @@ view (BarChartConfig { title, width, height, padding, data, maybeMaxY, unit }) =
[ div [ class "chart-header" ] [ text title ]
, TypedSvg.svg [ TypedSvg.Attributes.viewBox 0 0 width height ]
[ TypedSvg.g
[ TypedSvg.Attributes.transform [ Translate (padding - 1) (height - padding) ]
[ TypedSvg.Attributes.transform [ Translate (padding + 20) (height - padding) ]
, TypedSvg.Attributes.InPx.strokeWidth 2
, TypedSvg.Attributes.class [ "axis" ]
]
[ xAxis data ]
, TypedSvg.g
[ TypedSvg.Attributes.transform [ Translate (padding - 1) padding ]
[ TypedSvg.Attributes.transform [ Translate (padding + 20) padding ]
, TypedSvg.Attributes.InPx.strokeWidth 2
, TypedSvg.Attributes.class [ "axis" ]
]
Expand Down
Loading