Skip to content

Commit

Permalink
#606: cleaned up SpreadChart.fs a little
Browse files Browse the repository at this point in the history
  • Loading branch information
breki committed Oct 12, 2020
1 parent c50833b commit 7d70424
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
6 changes: 1 addition & 5 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# TODO

- https://github.com/sledilnik/website/issues/593
- disclaimer for age groups
- can we extract only a part of it

- `charts.metricsComparison.show7DaysAverage`
- https://github.com/sledilnik/website/issues/606


## New countries chart
Expand Down
5 changes: 0 additions & 5 deletions src/visualizations/Highcharts.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ let shadedWeekendPlotBands =
let showDoublingTimeFeatures =
true

// if set to true:
// - SpreadChart will show exponential growth pages
let showExpGrowthFeatures =
false

let addContainmentMeasuresFlags
(startDate: JsTimestamp)
(endDate: JsTimestamp option) =
Expand Down
33 changes: 19 additions & 14 deletions src/visualizations/SpreadChart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ open Browser
open Types
open Highcharts

// if set to true:
// - SpreadChart will show exponential growth pages
let showExpGrowthFeatures = true

type Scale =
| Absolute
| Percentage
Expand All @@ -31,8 +35,8 @@ type Page =
| Explainer -> I18N.t "charts.spread.explainer"

type State = {
page: Page
data: StatsData
Page: Page
Data: StatsData
RangeSelectionButtonIndex: int
}

Expand All @@ -42,16 +46,16 @@ type Msg =

let init data : State * Cmd<Msg> =
let state = {
page = Chart Absolute
data = data
Page = Chart Absolute
Data = data
RangeSelectionButtonIndex = 0
}
state, Cmd.none

let update (msg: Msg) (state: State) : State * Cmd<Msg> =
match msg with
| ChangePage page ->
{ state with page = page }, Cmd.none
{ state with Page = page }, Cmd.none
| RangeSelectionChanged buttonIndex ->
{ state with RangeSelectionButtonIndex = buttonIndex }, Cmd.none

Expand All @@ -68,7 +72,7 @@ let inline yAxisBase () =
opposite = true
reversed = false
title = {| text = null |}
showFirstLabel = not Highcharts.showExpGrowthFeatures // need to hide negative label for addContainmentMeasuresFlags
showFirstLabel = not showExpGrowthFeatures // need to hide negative label for addContainmentMeasuresFlags
tickInterval = None
gridZIndex = -1
max = None
Expand All @@ -78,7 +82,7 @@ let inline yAxisBase () =

let inline legend title =
{|
enabled = Highcharts.showExpGrowthFeatures
enabled = showExpGrowthFeatures
title = {| text=title |}
align = "left"
verticalAlign = "middle"
Expand Down Expand Up @@ -178,12 +182,12 @@ let renderChartOptions scaleType state dispatch =
name = chartCfg.seriesLabel
dataLabels = pojo {| enabled = true |}
data =
state.data
state.Data
|> Seq.skipWhile (fun dp -> dp.Date < startDate)
|> Seq.map chartCfg.dataKey
|> Seq.toArray
|}
if Highcharts.showExpGrowthFeatures then
if showExpGrowthFeatures then
yield addContainmentMeasuresFlags startTime None |> pojo
|]

Expand Down Expand Up @@ -258,14 +262,14 @@ let renderChartContainer scaleType data dispatch =
prop.className "highcharts-wrapper"
prop.children [
renderChartOptions scaleType data dispatch
|> Highcharts.chartFromWindow
|> chartFromWindow
]
]

let renderScaleSelectors state dispatch =

let renderScaleSelector (page: Page) dispatch =
let isActive = state.page = page
let isActive = state.Page = page
let style =
if isActive
then [ style.backgroundColor "#808080" ]
Expand All @@ -292,15 +296,16 @@ let render (state: State) dispatch =
Html.div [
prop.style [ style.height 480; (Interop.mkStyle "width" "100%"); style.position.relative ]
prop.children [
match state.page with
match state.Page with
| Chart scale ->
yield renderChartContainer scale state dispatch
| Explainer ->
yield renderChartContainer DoublingRate state dispatch
yield renderExplainer state.data
yield renderExplainer state.Data
]
]
if Highcharts.showExpGrowthFeatures then

if showExpGrowthFeatures then
renderScaleSelectors state dispatch
]
]
Expand Down

0 comments on commit 7d70424

Please sign in to comment.