Skip to content

Can't set unknown domain in colour scale #446

Closed

Description

@rossburton

I'm using the color scale with explicit domain/range to associate status names with colours:

  color: {
    type: "categorical",
    domain: ["success", "failed"],
    range: ["green", "red"]
  },

But status names I forgot to list come out invisible. A way of setting the unknown() value would be useful, it looks like it is hardcoded to undefined at

return ScaleO(scaleOrdinal().unknown(undefined), channels, {range, ...options});
.

Activity

  1. added
    enhancement
    on Jun 30, 2021
  2. mbostock commented on Jun 30, 2021

    @mbostock
    Member

    Anything outside the domain will not be plotted; we need the “other” transform for this use case.

  3. zanarmstrong commented on Jul 29, 2021

    @zanarmstrong

    I ran into something that seems similar related to NAs when plotting height / weight the Olympics dataset. Example here.

  4. Fil commented on Sep 14, 2021

    @Fil
    Contributor

    Another use-case (very similar to Zan's) can be found in https://observablehq.com/@rcatlord/spine-charts; for some of the areas (try "Rother" in the select), the value comes in as "NA" instead of a number, and the x axis switches to a categorical scale.

    Capture d’écran 2021-09-14 à 09 03 15

  5. Fil commented on Sep 27, 2021

    @Fil
    Contributor

    With this feature:

    • In Zan's example the N/A can be shown by applying
      x: { unknown: 45 },
      y: { unknown: 10 }
    
    • In rcatlord's example, the fix is a bit more complicated, since we need to coerce the scale to be quantitative:
    x: {
      axis: "top",
      label: null,
      type: "linear",
      unknown: 650
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions