livebook-dev / vega_lite

Elixir bindings for Vega-Lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keyword atom config should honor cases since config is case-sensitive

christhekeele opened this issue · comments

I noticed that this does not render as desired, with the x axis on top:

VegaLite.new
|> VegaLite.config(axisX: [orient: "top"])
|> VegaLite.mark(:square)
|> VegaLite.encode_field(:x, "x")
|> VegaLite.encode_field(:y, "y")
|> VegaLite.data_from_values([%{x: 0, y: 0}, %{x: 1, y: 1}])

VegaLite is downcasing the axisX atom in the config, becoming:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "config": {"axisx": {"orient": "top"}},
  "data": {"values": [{"x": 0, "y": 0}, {"x": 1, "y": 1}]},
  "encoding": {"x": {"field": "x"}, "y": {"field": "y"}},
  "mark": "square"
}

Which renders as:

Screen Shot 2021-12-29 at 9 58 53 PM

Using a two-tuple list preserves the casing and works, so this is only a minor wart on the DSL:

VegaLite.new
|> VegaLite.config([{"axisX", [orient: "top"]}])
|> VegaLite.mark(:square)
|> VegaLite.encode_field(:x, "x")
|> VegaLite.encode_field(:y, "y")
|> VegaLite.data_from_values([%{x: 0, y: 0}, %{x: 1, y: 1}])
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "config": {"axisX": {"orient": "top"}},
  "data": {"values": [{"x": 0, "y": 0}, {"x": 1, "y": 1}]},
  "encoding": {"x": {"field": "x"}, "y": {"field": "y"}},
  "mark": "square"
}

Screen Shot 2021-12-29 at 10 01 27 PM

Hey @christhekeele! The keys are automatically converted from snake_case to camelCase (as noted here), so if you do axis_x: [orient: "top"] it should work fine :)

Oh I totally missed that, thank you!