-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
quantize scale #829
quantize scale #829
Conversation
4db2425
to
e9e5fd7
Compare
I've added a bit of documentation.
see #830
Since we're using d3.ticks, I don't think we can guarantee that the values will be "round". In that case, I think we should leave it to the user to analyze the domain, and return the appropriate threshold scale. It might help if we accepted a domain function as a scale option (independently of its type); the input would be the flattened set of channel values (or maybe just a nested array of values to make it more efficient, replacing flatMap by map): --- a/src/scales.js
+++ b/src/scales.js
@@ -133,6 +133,9 @@ export function normalizeScale(key, scale, hint) {
}
function Scale(key, channels = [], options = {}) {
+ if (typeof options.domain === "function") options.domain = options.domain(channels.flatMap(({value}) => value));
const type = inferScaleType(key, channels, options);
// Warn for common misuses of implicit ordinal scales. We disable this test if then in simpson-views.js we could specify: color: {
type: "threshold",
domain: (data) => [2, 7, 12, 20],
legend: true
},
Currently this works if the range's length is equal to the computed number of thresholds + 1 — otherwise we get blank values to the right; we could add this to remove the thresholds that have no matching color: if (range) thresholds = thresholds.slice(0, range.length - 1); but it would create a false impression of what the domain is (the last bin would be much larger than the previous ones), and it's probably better if the chart fails visibly in that case. And if we add the domain function of the previous item, it would still allow users to set the thresholds efficiently. |
* reverse and descending * tests for quantize scales * remove dead code * update test snapshot * handle non-array domain Co-authored-by: Mike Bostock <[email protected]>
I’ve now made it so you can pass an explicit range to a quantile or quantize scale, and it will infer a domain of the appropriate corresponding cardinality. |
Fixes #828.
TODO