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

Reverted files and updated geochart chart window code #418

Open
wants to merge 32 commits into
base: horizon
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d4d4c34
Update chart.arr
Klu002 Jan 8, 2021
574f7ed
Update plot-list.arr
Klu002 Jan 8, 2021
9ab929e
Update plot.arr
Klu002 Jan 8, 2021
68a10e4
Update chart-lib.js
Klu002 Jan 8, 2021
e0da7b1
Add files via upload
Klu002 Jan 18, 2021
36fb256
Add files via upload
Klu002 Jan 18, 2021
47f0848
First commit
Jan 18, 2021
44456d8
Update chart-lib.js
Klu002 Jan 19, 2021
ac9fe04
Update plot-lib.js
Klu002 Jan 19, 2021
1c80a16
added geochart to values, changing all names to geochart
schornb Apr 28, 2021
b8e2ed7
added missing return sttatement in render function
Klu002 Apr 28, 2021
0db881f
chart lib fixed
schornb Apr 28, 2021
5022317
Merge branch 'master' of https://github.com/schornb/code.pyret.org in…
Klu002 Apr 28, 2021
63446d5
Merge branch 'horizon' of https://github.com/schornb/code.pyret.org i…
Klu002 Apr 28, 2021
f70bdc0
fixed merge conflicts
Klu002 Apr 29, 2021
25a950e
minor syntax fixes
schornb Apr 29, 2021
6897caf
editing chart.arr render-chart function for geomap
schornb May 4, 2021
f38ab61
reset plot js files
Klu002 May 4, 2021
731fae3
reset plot arr files
Klu002 May 4, 2021
173bf7e
reset plot arr files
Klu002 May 4, 2021
2ee2def
reset plot arr files
Klu002 May 4, 2021
1100700
basic functionality
Klu002 May 18, 2021
83a372e
geoChart now correctly uses data
Klu002 May 18, 2021
5cddc4b
added ability to change region
schornb May 23, 2021
51fb03e
changed type of region parameter
Klu002 May 23, 2021
59462a2
fixing change region
schornb May 23, 2021
5c5b092
change color to value
schornb May 23, 2021
aef5158
changed only files that needed changes
schornb Jan 19, 2022
e79dca9
reverted to current copy
schornb Jan 21, 2022
a28222f
add geochart functionality
schornb Jan 21, 2022
2e32236
edited package.json files
schornb Jan 21, 2022
e1fb6eb
added new line on json files
schornb Jan 27, 2022
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
48 changes: 47 additions & 1 deletion src/web/arr/trove/chart.arr
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,15 @@ default-function-plot-series = {
legend: '',
}

type GeoChartSeries = {
tab :: TableIntern,
region :: String,
}

default-geochart-series = {
region: "world",
}

###########

type ChartWindowObject = {
Expand Down Expand Up @@ -949,6 +958,15 @@ default-plot-chart-window-object :: PlotChartWindowObject = default-chart-window
num-samples: 1000,
}

type GeoChartWindowObject = {
title :: String,
width :: Number,
height :: Number,
render :: ( -> IM.Image),
}

default-geo-chart-window-object :: GeoChartWindowObject = default-chart-window-object

################################################################################
# DATA DEFINITIONS
################################################################################
Expand Down Expand Up @@ -1043,6 +1061,13 @@ data DataSeries:
max-num-bins: some(num-bins)
})
end,
| geochart-series(obj :: GeoChartSeries) with:
is-single: true,
contr: {(): geochart-series},
method region(self, region :: String):
geochart-series(self.obj.{
region: region})
end
sharing:
method _output(self):
cases (E.Either) run-task({(): get-vs-from-img("DataSeries", render-chart(self).get-image())}):
Expand Down Expand Up @@ -1098,6 +1123,8 @@ data ChartWindow:
end
plot-chart-window(self.obj.{num-samples: num-samples})
end,
| geochart-window(obj :: GeoChartWindowObject) with:
constr: {(): geochart-window},
sharing:
method display(self):
_ = check-chart-window(self.obj)
Expand Down Expand Up @@ -1481,6 +1508,19 @@ fun labeled-histogram-from-list(labels :: P.LoS, values :: P.LoN) -> DataSeries
} ^ histogram-series
end

fun geochart-from-list(
region-labels :: P.LoS,
values :: P.LoN) -> DataSeries block:
region-length = region-labels.length()
values-length = values.length()
when region-length <> values-length:
raise("geochart: region-labels and values should have the same length")
end
default-geochart-series.{
tab: to-table2(region-labels, values)
} ^ geochart-series
end

################################################################################
# PLOTS
################################################################################
Expand Down Expand Up @@ -1556,6 +1596,11 @@ fun render-chart(s :: DataSeries) -> ChartWindow:
P.histogram(self, obj)
end
} ^ histogram-chart-window
| geochart-series(obj) =>
default-geo-chart-window-object.{
method render(self):
P.geochart(self, obj) end
} ^ geochart-window
end
where:
render-now = {(x): render-chart(x).get-image()}
Expand Down Expand Up @@ -1952,4 +1997,5 @@ from-list = {
freq-bar-chart: freq-bar-chart-from-list,
labeled-box-plot: labeled-box-plot-from-list,
box-plot: box-plot-from-list,
}
geochart: geochart-from-list,
}
26 changes: 24 additions & 2 deletions src/web/js/trove/chart-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
'multi-bar-chart': "tany",
'histogram': "tany",
'box-plot': "tany",
'plot': "tany"
'plot': "tany",
'geochart': "tany"
}
},
theModule: function (RUNTIME, NAMESPACE, uri, IMAGELIB, jsnums , google) {
Expand Down Expand Up @@ -63,7 +64,7 @@
}
}

google.charts.load('current', {'packages' : ['corechart']});
google.charts.load('current', {'packages' : ['corechart', 'geochart']});

//////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -884,6 +885,26 @@
};
}

function geoChart(globalOptions, rawData) {
const table = get(rawData, 'tab');
const data = new google.visualization.DataTable();
const region = get(rawData, 'region');
data.addColumn('string', 'Region');
data.addColumn('number', "Value");
data.addRows(table.map(row => [row[0], toFixnum(row[1])]));
console.log("test123");
console.log(region);
const options = {region: region};

return {
data: data,
options: options,
chartType: google.visualization.GeoChart,
onExit: defaultImageReturn,
};
}


function plot(globalOptions, rawData) {
const scatters = get(rawData, 'scatters');
const lines = get(rawData, 'lines');
Expand Down Expand Up @@ -1245,6 +1266,7 @@ ${labelRow}`;
'histogram': makeFunction(histogram),
'box-plot': makeFunction(boxPlot),
'plot': makeFunction(plot),
'geochart': makeFunction(geoChart),
},
{
"LoC": ann("List<Color>", checkListWith(IMAGE.isColorOrColorString)),
Expand Down
2 changes: 1 addition & 1 deletion src/web/js/trove/cpo-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
theModule: function(runtime, namespace, _ /* intentionally unused */ ) {
return runtime.makeJSModuleReturn({cpoBuiltins: true});
}
}
}