Skip to content

Conversation

@Fil
Copy link
Contributor

@Fil Fil commented May 24, 2021

color: {type: "threshold", domain: [30, 50], range: ["red", "green", "blue"]}
closes #372

color: {type: "quantile", scheme: "blues", quantiles: 7}
closes #373

TODO

  • see bug below with ordinal schemes

(still needs a few test plots)

@Fil
Copy link
Contributor Author

Fil commented Jun 18, 2021

we'll use the test plot in #419

@Fil Fil marked this pull request as ready for review June 18, 2021 12:07
@Fil Fil mentioned this pull request Jul 5, 2021
@Fil
Copy link
Contributor Author

Fil commented Jul 20, 2021

I've added a build in https://observablehq.com/@fil/quantile-threshold-shaperendering-415-419

Here's a bug though: Threshold/quantile scales should accept ordinal schemes.

Plot.dot(data, { x: "bill_length", y: "species", fill: "body_mass" }).plot({
  color: {
    type: "threshold",
    domain: [2000, 3000],
    scheme: "dark2"
  }
})

gives TypeError: ordinalScheme(scheme === undefined ? "rdylbu" : scheme) is not a function. (In 'ordinalScheme(scheme === undefined ? "rdylbu" : scheme)({length: domain.length + 1})', 'ordinalScheme(scheme === undefined ? "rdylbu" : scheme)' is an instance of Array)

@Fil Fil marked this pull request as draft July 20, 2021 14:38
Fil added 3 commits August 2, 2021 15:09
`{type: "threshold", domain: [30, 50], range: ["red", "green", "blue"]}`
closes #372

`color: {type: "quantile", scheme: "blues", quantiles: 7}`
closes #373
It did not work, because:
- scaleThreshold relies on an ascending domain (and breaks if it's not ascending); let's check for this situation and reverse the scale if the domain is descending
- scaleQuantile ignores the domain order
@mbostock mbostock force-pushed the fil/color-threshold-quantile-scales branch from a975864 to a596be5 Compare August 2, 2021 22:11
@mbostock
Copy link
Member

mbostock commented Aug 2, 2021

For the diverging schemes (scheme11’s) you don’t get very good results with n = 2: you get the first two (red and gray in RdBu or red and yellow in RdYlBu).

Screen Shot 2021-08-02 at 3 23 20 PM

What you want is probably the outer two (red and blue).

Screen Shot 2021-08-02 at 3 23 28 PM

Maybe we can fix this in scheme11 for the n = 2 case.

n = n > 3 ? Math.floor(n) : 3;

@mbostock
Copy link
Member

mbostock commented Aug 2, 2021

The reason for the TypeError is that sometimes ordinalScheme returns an array (for the ordinal schemes) while other times it returns a function that will later be converted into an array when the domain is known:

// If the range is specified as a function, pass it the domain.
if (typeof range === "function") range = range(domain);

So we either need to make sure ordinalScheme always returns a function, or we need to handle a returned array when we call ordinalScheme. I can fix.

@mbostock mbostock marked this pull request as ready for review August 3, 2021 00:20
@mbostock mbostock merged commit 4b8b821 into main Aug 3, 2021
@mbostock mbostock deleted the fil/color-threshold-quantile-scales branch August 3, 2021 00:20
@mbostock mbostock mentioned this pull request Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quantile scales Threshold scales

3 participants