Search code examples
vega-litedeneb

Reduce the density of axis & data labels (in sync)


Is it possible to manage density of data labels (text marks) similarly to what the labelOverlap setting does with the axis labels? Ideally, I'd like them to be in sync.

Visual in Deneb/PowerBI Dataset

{
  "data": {"name": "dataset"},
  "encoding": {
    "x": {
      "field": "Date",
      "type": "nominal",
      "axis": {"labelOverlap": true}
    },
    "y": {
      "aggregate": "sum",
      "field": "Sum of Value"
    }
  },
  "layer": [
    {"mark": {"type": "bar"}},
    {
      "mark": {
        "type": "text",
        "baseline": "top",
        "align": "left",
        "dx": 5,
        "dy": -3,
        "fontSize": 9,
        "angle": 270
      },
      "encoding": {
        "text": {"field": "Sum of Value"}
      }
    }
  ]
}

Solution

  • Here is a prototype solutions that I came up with.

    Within PowerBI, I'll simply use a hardcoded threshold like "if the number of bars is more than 100, then hide every other label". If will be sufficient for my use case.

    Vega-lite editor

    Stacked Bar Chart - All Labels Stacked Bar Chart - 1 out of 2 Stacked Bar Chart - 2 out of 3