Skip to content

Commit

Permalink
fixed maximum option
Browse files Browse the repository at this point in the history
some charts might not have the desired max value in their series
  • Loading branch information
benjajaja committed Jun 5, 2020
1 parent 61c176d commit 4fa1568
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "gipsy-king/radar-chart",
"summary": "An SVG radar chart",
"license": "BSD-3-Clause",
"version": "1.0.1",
"version": "2.0.0",
"exposed-modules": [
"RadarChart"
],
Expand Down
3 changes: 2 additions & 1 deletion examples/Default.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ main =
[ { color = "#333333", data = List.take 6 someData } ]
, Html.div [] [ Html.text "Minimal axis, filled area:" ]
, RadarChart.view
{ fontSize = 2.0
{ maximum = RadarChart.FixedMax 500
, fontSize = 2.0
, margin = 0.333
, strokeWidth = 1
, axisColor = "lightgrey"
Expand Down
31 changes: 23 additions & 8 deletions src/RadarChart.elm
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module RadarChart exposing
( Options, AxisStyle(..), LineStyle(..), defaultOptions
, view, DatumSeries
( Options, AxisStyle(..), LineStyle(..), DatumSeries, Maximum(..)
, view, defaultOptions
)

{-|
# Customize a chart a little bit, or use defaults
@docs Options, AxisStyle, LineStyle, defaultOptions
@docs Options, AxisStyle, LineStyle, DatumSeries, Maximum
# Show a radar chart
@docs view, DatumSeries
@docs view, defaultOptions
-}

Expand Down Expand Up @@ -42,7 +42,13 @@ view options labels series =
axisCount
color
data
(Maybe.withDefault 1 <| List.maximum <| data)
(case options.maximum of
FixedMax n ->
n

Infer ->
Maybe.withDefault 1 <| List.maximum data
)
[]
)
series
Expand All @@ -58,7 +64,7 @@ type alias DatumSeries =
}


{-| Chart styling options:
{-| Chart options:
- `fontSize` See <https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/font-size>
- `margin` Between 0 and 1, to leave some space for labels
Expand All @@ -69,7 +75,8 @@ type alias DatumSeries =
-}
type alias Options =
{ fontSize : Float
{ maximum : Maximum
, fontSize : Float
, margin : Float
, strokeWidth : Float
, axisColor : String
Expand All @@ -96,11 +103,19 @@ type LineStyle
| Filled Float


{-| Fixed axis maximum or use highest data point of series
-}
type Maximum
= FixedMax Float
| Infer


{-| Get a default options object.
-}
defaultOptions : Options
defaultOptions =
{ fontSize = 3.0
{ maximum = Infer
, fontSize = 3.0
, margin = 0.333
, strokeWidth = 0.5
, axisColor = "darkgrey"
Expand Down

0 comments on commit 4fa1568

Please sign in to comment.