I would like to do something like:
|> VegaLite.transform([
# Calculate the week number of the year for each datetime
%{calculate: {:datetime, "datum.created * 1000"}, as: "datetime"},
%{calculate: {:week, "datum.datetime"}, as: "week_number"},
# Calculate the ratio of :up values to :up + :down for that week
%{calculate: {:if, "datum.thumb == 'up'", 1, 0}, as: "ratio"}
])
The above throws an error when trying to covert the list to a map. I am assuming the series of transforms must be done in a single transform step as when I try to run the transform as separate commands I get no result (but no error)
VegaLite.new()
|> VegaLite.data_from_values(data)
|> VegaLite.mark(:line)
|> VegaLite.transform(calculate: "datetime(datum.created * 1000)", as: "datetime")
|> VegaLite.transform(calculate: "week(datum.datetime)", as: "week_number")
|> VegaLite.transform(calculate: "if(datum.thumb == 'up', 1, 0)", as: "ratio")
|> VegaLite.encode(:x, field: "week_number", type: :quantitative)
|> VegaLite.encode(:y, field: "ratio", type: :quantitative)
I see lots of examples in javascript, but I have not found an example using the Elixir VegaLite library.
Thanks!