Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional expression to labelColor in header is not translated to Vega correctly #9283

Open
1 task done
joelostblom opened this issue Mar 13, 2024 · 0 comments
Open
1 task done
Labels

Comments

@joelostblom
Copy link
Contributor

In this spec, I'm setting up conditional color encoding in the same manner for both axis labels and header labels:

  "encoding": {
    "column": {
      "field": "c",
      "header": {
        "labelExpr": "datum.value === \"One\" ? \"ONE\" : \"TWO\"",
        "labelColor": { "expr": "datum.value === \"One\" ? \"green\" : \"purple\""}
      },
      "type": "nominal"
    },
    "x": {
      "axis": {
        "labelExpr": "datum.value === \"A\" ? \"AA\" : \"BB\"",
        "labelColor": {"expr": "datum.value === \"A\" ? \"blue\" : \"red\""}
      },
      "field": "a",
      "type": "nominal"
    },
    "y": {"field": "b", "type": "quantitative"}
  }

However, it only works for the axis labels as can be seen in this screenshot:

image
Open the Chart in the Vega Editor

Looking at the Vega spec, it seems like VegaLite has translated the labelExpr and labelColor differently

      "title": {
        "text": {"signal": "parent[\"c\"] === \"One\" ? \"ONE\" : \"TWO\""},
        "style": "guide-label",
        "frame": "group",
        "color": {"signal": "datum.value === \"One\" ? \"green\" : \"purple\""},
        "offset": 10
      }

If I manually change datum.value to parent[\"c\"] for the "color" key, the header labels are colored as expected. If this is a simple case of duplicated some logic from labelExpr into labelColor, then I might be able to take a stab at a PR (although it might be a while until I get to it). Any pointers if that's the case and where this is handled in the code base?

A couple of other things I noted when working on this:

  • datum.label and datum.value works for the axis config, but for the header config only datum.value works
  • labelExpr takes an expression as a string but not as an expr object whereas labelColor does the opposite; it would be helpful for harmonize if possible.

Checklist

  • I checked for duplicate issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant