Proper syntax for performing a series of transform steps in VegaLite

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!

Can you share a little bit of the data you’re using for that?

That would help to try to play with it and try to get to what you want.

Sorry for the delay. Did not have an example on hand and such. But this came up again and I am still searching for the right way. Here is an example I would like to recreate in the VegaLite wrapper:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "values": [
      {"distance": 1},
      {"distance": 9},
      {"distance": 11},
      {"distance": 11},
      {"distance": 11},
      {"distance": 30},
      {"distance": 44}
      // Add more data points if available
    ]
  },
  "transform": [
    {
      "window": [{"op": "count", "field": "distance", "as": "cumulative_success"}],
      "frame": [0, null]
    },
    {
      "window": [{"op": "count", "field": "distance", "as": "total_success"}],
            "frame": [null, null]
    },
    {
      "calculate": "datum.cumulative_success / datum.total_success",
      "as": "cumulative_probability"
    },
    {
      "bin": true,
      "field": "distance",
      "extent": {"step": 10}
    }
  ],
  "encoding": {
    "x": {
      "bin": {"step": 10},
      "field": "distance",
      "type": "quantitative",
      "axis": {"title": "Distance (in 10-meter sets)"}
    },
    "y": {
      "field": "cumulative_probability",
      "type": "quantitative",
      "axis": {"title": "Cumulative Probability"},
      "scale": {"domain": [0, 1]},
      "aggregate":"average"
    }
  },
  "layer": [
    {
      "mark": "line",
      "encoding": {
        "y": {"field": "cumulative_probability", "title": "Cumulative Probability"},
        "color": {"value": "#1f77b4"}
      }
    },
    {
      "mark": {"type": "text", "align": "center", "dy": -5},
      "encoding": {
        "y": {"field": "cumulative_probability", "aggregate": "average"},
        "text": {"field": "cumulative_probability", "aggregate": "average", "format": ".2f"}
      }
    }
  ]
}


And answering my own question. Each of the transform steps just needs to be a separate call to VL.transform() and it works!