Skip to content
Binary file added src/trove/chart-images/geochart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 58 additions & 3 deletions src/trove/chart.js.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
(fun-spec (name "from-list.exploding-pie-chart") (arity 3))
(fun-spec (name "from-list.histogram") (arity 2))
(fun-spec (name "from-list.labeled-histogram") (arity 3))
(fun-spec (name "from-list.geochart") (arity 3))
(fun-spec (name "render-chart") (arity 1))
(fun-spec (name "render-charts") (arity 1))
(constr-spec
Expand All @@ -203,16 +204,19 @@
(name "histogram-series")
(with-members (,bin-width-meth ,max-num-bins-meth ,min-num-bins-meth
,num-bins-meth)))
(constr-spec
(name "geochart-series")
(with-members ()))
(data-spec
(name "DataSeries")
(type-vars ())
(variants ("function-plot-series" "line-plot-series" "scatter-plot-series"
"bar-chart-series" "pie-chart-series" "histogram-series"))
"bar-chart-series" "pie-chart-series" "histogram-series" "geochart-series"))
(shared))
(data-spec
(name "ChartWindow")
(type-vars ())
(variants ("bar-chart-window"))
(variants ("bar-chart-window" "plot-chart-window" "histogram-chart-window" "pie-chart-window" "geochart-window"))
(shared
((method-spec
(name "title")
Expand Down Expand Up @@ -271,6 +275,9 @@
(constr-spec
(name "pie-chart-window")
(with-members ()))
(constr-spec
(name "geochart-window")
(with-members ()))
))

@docmodule["chart"]{
Expand Down Expand Up @@ -591,6 +598,26 @@ a-series = from-list.labeled-histogram(
}
}

@function["from-list.geochart"
#:contract (a-arrow (L-of S) (L-of N) DataSeries)
#:args '(("region-labels" #f) ("values" #f))
#:return (a-pred DataSeries (in-link "geochart-series"))
]{
Constructing a geochart series, which makes a map of the world and highlights @pyret{region-labels} on the map
in a range according to its @pyret{value}. Note that a given region-labels and value have the same index number in their respective lists.
The geochart will also show the range of values on the various regions, which higher values having a different color than lower values.
Note that the @pyret{region-labels} and @pyret{value} must be the same length. See more details at @(in-link "geochart-series").

A list of all the valid @pyret{region-labels} and their locations on the geochart can be found @link["https://developers.google.com/chart/interactive/docs/gallery/geochart#continent-hierarchy-and-codes" "here from Google Charts"].
For example, adding "US" as a region label would color the United States of America, while "ZA" would color the region of South Africa.

@examples{
an-example-geochart-series = from-list.geochart(
[list: "US", "India","Pakistan", "Philippines", "Nigeria"],
[list: 251388301, 125344736, 110041604, 89800800, 79000000])
}
}

@;############################################################################
@section{DataSeries}

Expand All @@ -601,6 +628,7 @@ a-series = from-list.labeled-histogram(
@constructor-spec["DataSeries" "bar-chart-series" opaque]
@constructor-spec["DataSeries" "pie-chart-series" opaque]
@constructor-spec["DataSeries" "histogram-series" opaque]
@constructor-spec["DataSeries" "geochart-series" opaque]
)]

@;################################
Expand Down Expand Up @@ -738,6 +766,23 @@ render-chart(a-series).display()
}
@(in-image "labeled-histogram")

@;################################
@subsection{GeoChart Series}

@constructor-doc["DataSeries" "geochart-series" opaque DataSeries]{
A geochart series.
}

@examples{
an-example-geochart-series = from-list.geochart(
[list: "US", "India","Pakistan", "Philippines", "Nigeria"],
[list: 251388301, 125344736, 110041604, 89800800, 79000000])


render-chart(an-example-geochart-series).display()
}
@(in-image "geochart")

@;############################################################################
@section{Renderers}

Expand All @@ -755,6 +800,7 @@ render-chart(a-series).display()
@item{@in-link{bar-chart-series} creates a @in-link{bar-chart-window}}
@item{@in-link{pie-chart-series} creates a @in-link{pie-chart-window}}
@item{@in-link{histogram-series} creates a @in-link{histogram-chart-window}}
@item{@in-link{geochart-series} creates a @in-link{geochart-window}}
]

@examples{
Expand Down Expand Up @@ -792,6 +838,7 @@ a-chart-window = render-charts([list: series-1, series-2])
@constructor-spec["ChartWindow" "bar-chart-window" opaque]
@constructor-spec["ChartWindow" "histogram-chart-window" opaque]
@constructor-spec["ChartWindow" "plot-chart-window" opaque]
@constructor-spec["ChartWindow" "geochart-window" opaque]
)]

@;################################
Expand Down Expand Up @@ -848,4 +895,12 @@ a-chart-window = render-charts([list: series-1, series-2])
@method-doc["ChartWindow" "histogram-chart-window" "y-max"]
@method-doc["ChartWindow" "histogram-chart-window" "x-axis"]
@method-doc["ChartWindow" "histogram-chart-window" "y-axis"]
}

@;################################
@subsection{Geochart Chart Window}

@constructor-doc["ChartWindow" "geochart-window" opaque ChartWindow]{
A geochart chart window.
}

}