-
Notifications
You must be signed in to change notification settings - Fork 80
/
Page.fs
executable file
·75 lines (59 loc) · 2.54 KB
/
Page.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[<ReflectedDefinition>]
module Program
open FunScript
open FSharp.Data
// ------------------------------------------------------------------
// Initializataion
type WorldBank = WorldBankProvider<"World Development Indicators", Asynchronous=true>
type j = TypeScript.Api<"../Typings/jquery.d.ts">
type h = TypeScript.Api<"../Typings/highcharts.d.ts">
let jQuery (command:string) = j.jQuery.Invoke(command)
// ------------------------------------------------------------------
// World bank countries
let data = WorldBank.GetDataContext()
let countries () =
[| data.Countries.``Arab World``
data.Countries.``European Union``
data.Countries.Australia
data.Countries.Brazil
data.Countries.Canada
data.Countries.Chile
data.Countries.``Czech Republic``
data.Countries.Denmark
data.Countries.France
data.Countries.Greece
data.Countries.``Low income``
data.Countries.``High income``
data.Countries.``United Kingdom``
data.Countries.``United States`` |]
// ------------------------------------------------------------------
// Main function
let main() =
// Create check boxes for all countries
let infos = countries () |> Array.toList |> List.mapi (fun index country ->
let input = jQuery("<input>").attr("type", "checkbox")
let label = jQuery("<label>").append([| box input |]).append([| box country.Name |])
let panel = floor (index % 3) + 1
label.appendTo(jQuery("#countryList" + panel.ToString())) |> ignore
country, input )
// Render the chart based on checkboxes
let render () = async {
let opts = h.HighchartsOptions()
opts.chart <- h.HighchartsChartOptions'(renderTo = "chart", ``type`` = "line")
opts.title <- h.HighchartsTitleOptions'(text = "School enrollment, tertiary (% gross)")
opts.series <- [| |]
// Create series we want to render
let series = ref []
for country, check in infos do
if check.is(":checked") |> unbox then
let! vals = country.Indicators.``School enrollment, tertiary (% gross)``
let data = vals |> Seq.map (fun (k, v) -> [| number k; number v |]) |> Array.ofSeq
opts.series.push(h.HighchartsSeriesOptions'(data=data, name=country.Name))
h.Highcharts.Chart.``new``(opts) |> ignore }
// Register click handlers
render () |> Async.StartImmediate
for _, check in infos do
check.click(fun _ ->
render() |> Async.StartImmediate |> box) |> ignore
// ------------------------------------------------------------------
do Runtime.Run(components=FunScript.Data.Components.DataProviders, directory="Web")