haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
6.06k stars 1.13k forks source link

Support header attribute on facet / row / column encoding channels #763

Closed markuspeters closed 7 months ago

markuspeters commented 7 months ago

When creating a faceted Vega Lite plot using the Scala library, I would like to be able to set the facets' header and sort properties to control the title and sort attributes of the facets.

For example, the following plot:

VegaLite.facet(
      jsan"""
      [
        {"class": "square", "color": "red", "v": 28},
        {"class": "square", "color": "green", "v": 55},
        {"class": "round", "color": "green", "v": 17},
        {"class": "round", "color": "blue", "v": 43}
      ]""").
    column(field = "class", `type` = "nominal").
    mark("bar").
    x(field = "color", `type` = "nominal").
    y(field = "v", `type` = "quantitative")

translates to the following column encoding channel:

    "column": {
      "field": "class",
      "center": false,
      "type": "nominal",
      "align": "all"
    }

What I am missing is the ability to additionally express:

    "column": {
      ...
      "align": "all",
      "sort": ["Lesson (regular)", "Lesson (other)"],
      "header": {"title": "Data Class","labelAngle": -90, "labelAlign": "right"}
    }

The Vega Lite page is silent on the availability of the header and sort properties on the facet/row/column encoding channels though at least the header property is later used in the Grid Facet example on the same page, and the Vega Editor interprets both correctly.

I'll be happy to submit a PR if that seems useful.

haifengl commented 7 months ago

Added. All changes are in master branch now.

markuspeters commented 7 months ago

Looks great! Thank you once more for handling this yourself.