livebook-dev / vega_lite

Elixir bindings for Vega-Lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

joinaggregate question

jjwAmtelco opened this issue · comments

This elixir code I have seems ok but does not produce a chart. I have commented out the line that causes the issue; The joinaggregate line.
it is not clear to me why that line causes a blank chart. My goal is to produce a chart like what is shown in the editor...not sure its a bug but can transform be used some other way?

`data = skill_stats

fit_bars = Enum.count(get_skills(skill_stats)) * 22

# will never be smaller than 200 but expand depending
# on data [ for each skill ] and overflow to a scroll
width = max(fit_bars - rem(fit_bars, 100), 200)

Vl.new(title: "Service Level By Skill", description: "")
|> Vl.data_from_values(data)
|> Vl.concat(
  [
    Vl.new(width: width, height: 200)
    |> Vl.encode_field(:x, "skill",
      type: :nominal,
      title: "",
      axis: [label_angle: -45, label_font_size: 15])


    |> Vl.encode_field(:y, "value",
      type: :quantitative,
      aggregate: :sum,
      stack: "normalize",
      title: "percentage of calls",
      axis: [format: ".0%"],
      sort: [field: "value"]
    )
    |> Vl.encode_field(:color, "series", scale: [scheme: "spectral"], legend: [orient: "left"])
    |> Vl.encode(:order, aggregate: "sum", field: "value")
    #|> Vl.transform(joinaggregate: "value", op: :sum, groupby: "skill", as: "TotalCount")
    |> Vl.transform(calculate: "datum.value/datum.TotalCount * 100", as: "PercentOfTotal")
    |> Vl.encode(:tooltip, [
      [field: "skill", type: :nominal],
      [field: "series", type: :nominal, title: "category"],
      [field: "value", type: :quantitative, title: "count"],
      [field: "sl_percentage", type: :quantitative, title: "Service Level %"],
      [field: "abandon_percentage", type: :quantitative, title: "abandon %"],
      [field: "PercentOfTotal", title: "% of Calls per skill", type: :quantitative, format: "0.2f"]
    ])
    |> Vl.mark(:bar)
  ],
  :horizontal
)
|> Vl.to_spec()
|> Jason.encode!()`

chart in editor

Do you get an error? Maybe it is joinAggregate, no?

Open the Chart in the Vega Editor

this is the chart without the line, in the past when something is just wrong with the case it has still shown up in the editor...

This would match the chart definition you have in the Vega Editor:

|> Vl.transform(
  joinaggregate: [[field: "value", op: :sum, as: "TotalCount"]],
  groupby: ["skill"]
)

Tried joinAggregate no joy

I did not notice that the joinagreggate was a list in the json
Thanks