scalePow evenly spaced ticks?
#3771
-
|
Looking at the code and experimenting, it seems like I'm not exactly sure what this would look like at the moment, but I feel like it should be possible for I could do something like this: const min = 0;
const max = 100;
const power = 2;
const steps = 10;
const scale = d3.scalePow().domain([min, max]).range([min, max]).exponent(power);
const ticks = d3.range(scale.range()[0], scale.range()[1], steps).map((v) => scale.invert(v));
// or
const ticks = d3.ticks(scale.range()[0], scale.range()[1], steps).map((v) => scale.invert(v));But I believe in the linear and log versions, there is more "magic" happening behind the scenes to make it look nice? Actually it looks like d3-array has a ticks method that does some magic, but I'm still not sure integrating it into my example above is as good as linear/log's built-in ticking. Moreover, maybe this should be added regardless for convenience, so I don't have to do any of the work above. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Ticks are supposed to be "human readable", like 10, 20, 30, rather than arbitrary numbers such as 31.622776601683793, 44.721359549995796. A common use case is, say powers of 2, where you want the ticks to be 1, 2, 4, 8, 16, 32, 64β¦ and your method allows that. However it's not generic: if you add more ticks in-between you get multiples of sqrt(2), which are not "readable". |
Beta Was this translation helpful? Give feedback.
Ticks are supposed to be "human readable", like 10, 20, 30, rather than arbitrary numbers such as 31.622776601683793, 44.721359549995796.
A common use case is, say powers of 2, where you want the ticks to be 1, 2, 4, 8, 16, 32, 64β¦ and your method allows that. However it's not generic: if you add more ticks in-between you get multiples of sqrt(2), which are not "readable".