vega-lite-api icon indicating copy to clipboard operation
vega-lite-api copied to clipboard

{empty: false} on selection throws Error: Unrecognized signal name:

Open john-guerra opened this issue 2 years ago • 0 comments

Adding .empty(false) to a selection throws "Error: Unrecognized signal name:"

See this example

{
  const highlight = vl.selectPoint("highlight").empty(false); //❌
  return vl
    .markRect({ strokeWidth: 2 })
    .select(highlight)
    .encode(
      vl.y().fieldN("actual"),
      vl.x().fieldN("predicted"),
      vl.fill().fieldQ("count"),
      vl.stroke().if(highlight, vl.value("black")).value(null)
    )
    .data(data)
    .config({
      scale: {
        bandPaddingInner: 0,
        bandPaddingOuter: 0
      },
      view: { step: 40 },
      range: {
        ramp: {
          scheme: "yellowgreenblue"
        }
      },
      axis: {
        domain: false
      }
    })
    .render();
}

With VegaLite API v4 one could use .empty("none") for setting the default value of the selection. I built an example for that which doesn't work with v5

Could be related to @arvind merge on Vega-Lite

Possible workaround: adding empty: false in the encoding and not in the selection definition, which was an idea I got reading this discussion between @kanitw and @domoritz. However, using the object there seems wrong...

{
  const highlight = vl.selectPoint("highlight");
  return vl
    .markRect({ strokeWidth: 2 })
    .select(highlight)
    .encode(
      vl.y().fieldN("actual"),
      vl.x().fieldN("predicted"),
      vl.fill().fieldQ("count"),
      vl
        .stroke()
        .condition({ param: "highlight", empty: false, value: "black" }) // ✅
        .value(null)
    )
    .data(data)
    .config({
      scale: {
        bandPaddingInner: 0,
        bandPaddingOuter: 0
      },
      view: { step: 40 },
      range: {
        ramp: {
          scheme: "yellowgreenblue"
        }
      },
      axis: {
        domain: false
      }
    })
    .render();
}

The reference documentation for Vega-Lite-API suggests that one should be able to use .empty(false) regardless of the location...

john-guerra avatar Jun 18 '22 23:06 john-guerra