Skip to content

legend.type: "symbol" dropped from compiled Vega for discretizing color scales (threshold/quantize/quantile/bin) #9856

Description

@shenker

Vega-Lite: 6.4 (also repros on 5.x)
Vega: 6.2.0

Description

For a quantitative color encoding with a discretizing scale (threshold, quantize, quantile, or bin), legend.type: "symbol" is silently dropped during vega-lite to Vega compilation. The compiled Vega legend has no type, so Vega renders a gradient legend instead of the requested symbol legend.

A linear color scale with the same legend.type: "symbol" does propagate correctly — so the property is supported, just not applied for these scale types.

Reproduction

Paste into the Vega Editor:

{
  "$schema": "https://vega.github.io/schema/vega-lite/v6.4.1.json",
  "config": {
    "view": {
      "continuousHeight": 300,
      "continuousWidth": 300
    }
  },
  "data": {
    "format": {
      "feature": "counties",
      "type": "topojson"
    },
    "url": "https://cdn.jsdelivr.net/npm/vega-datasets@v3.2.1/data/us-10m.json"
  },
  "encoding": {
    "color": {
      "field": "rate",
      "legend": {
        "type": "symbol"
      },
      "scale": {
        "domain": [
          0.1,
          0.2,
          0.3
        ],
        "type": "threshold"
      },
      "type": "quantitative"
    }
  },
  "height": 300,
  "mark": {
    "type": "geoshape"
  },
  "projection": {
    "type": "albersUsa"
  },
  "transform": [
    {
      "from": {
        "data": {
          "url": "https://cdn.jsdelivr.net/npm/vega-datasets@v3.2.1/data/unemployment.tsv"
        },
        "fields": [
          "rate"
        ],
        "key": "id"
      },
      "lookup": "id"
    }
  ],
  "usermeta": {
    "embedOptions": {}
  },
  "width": 500
}

Expected vs. Actual (compiled Vega legend)

Expected: In the compiled Vega,

"legends": [
    {
      "fill": "color",
      "labelOverlap": "greedy",
      "symbolType": "circle",
      "title": "rate",
      "type": "symbol"
    }
  ],
Image

Actual:

"legends": [
    {
      "fill": "color",
      "labelOverlap": "greedy",
      "symbolType": "circle",
      "title": "rate"
    }
  ],
Image

Manually adding "type": "symbol" to this Vega legend produces the intended discrete legend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions