livebook-dev / vega_lite

Elixir bindings for Vega-Lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with vega-lite "labelExpr"

saurabh-ironman opened this issue · comments

Hi Team

Am working in Livebook and using vega-lite library for creating charts. I noticed one issue wherein when am using "labelExpr" atom for customizing my chart labels then it is not working. Opening my visualization chart from livebook to vega-lite editor shows me that it is converting "labelExpr" to lower case "labelexpr" and this is what the issue is.

Here is a sample example for my data from Livebook

data = [
%{"event" => "A1", "value" => 3, "quartile" => 3.5},
%{"event" => "A1", "value" => 4, "quartile" => 3.5},
%{"event" => "A1", "value" => 5, "quartile" => 3.5},
%{"event" => "B2", "value" => 1, "quartile" => 1.5},
%{"event" => "B2", "value" => 2, "quartile" => 1.5},
%{"event" => "B2", "value" => 3, "quartile" => 1.5},
%{"event" => "C3", "value" => 5, "quartile" => 5.5},
%{"event" => "C3", "value" => 6, "quartile" => 5.5},
%{"event" => "C3", "value" => 7, "quartile" => 5.5}
]

Vl.new()
|> Vl.data_from_values(data)
|> Vl.mark(:boxplot, orient: "horizontal", color: :orange, ticks: true)
|> Vl.encode_field(:x, "value")
|> Vl.encode_field(:y, "event",
axis: [labelExpr: "datum.label[0]"],
sort: [op: :q1, field: "value"]
)

I also tried to explore through the code and seem like below code is having the problem? May you pls check and confirm i can initiate a PR for the same ?

https://github.com/livebook-dev/vega_lite/blob/main/lib/vega_lite.ex#L1111

Hey @saurabh-ironman! To make the API more Elixir-ish we expect the options in snake_case and then automatically convert them to camelCase when exporting the Vega-Lite JSON, see the docs. So using label_expr: should do the job, let me know if it works as expected :)

yes @jonatanklosko this works as expected. Thank you for pointing to this solution.