Skip to content

Spurious error when facet.data is missing #1520

Closed
@mbostock

Description

@mbostock

This Plot previously rendered successfully in Plot 0.6.5, but now crashes with an error:

TypeError: Cannot read properties of undefined (reading 'length')

untitled (72)

Plot.plot({
  y: {
    percent: true,
    label: "Utilization, %"
  },
  grid: true,
  x: {
    label: "Ceph pool"
  },
  facet: {
    x: "Ceph pools usage"
  },
  color: {
    range: ["#16b336", "#f9cb2a", "#b40b0b"],
    type: "quantile",
    domain: [0.3, 0.5, 0.8]
  },
  marks: [
    Plot.barY(percents_data, {
      x: "name",
      y: "value",
      fill: "value",
      sort: { x: "y", reverse: true }
    }),
    Plot.ruleY([0])
  ]
})

The crash is happening here dereferencing data.length:

  // Warn for the common pitfall of wanting to facet mapped data with the
  // top-level facet option.
  if (
    data.length > 0 &&
    (groups.size > 1 || (groups.size === 1 && channels.fx && channels.fy && [...groups][0][1].size > 1)) &&
    arrayify(mark.data)?.length === data.length
  ) {
    warn(
      `Warning: the ${mark.ariaLabel} mark appears to use faceted data, but isn’t faceted. The mark data has the same length as the facet data and the mark facet option is "auto", but the mark data and facet data are distinct. If this mark should be faceted, set the mark facet option to true; otherwise, suppress this warning by setting the mark facet option to false.`
    );
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn’t working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions