d3 / d3-axis

Human-readable reference marks for scales.

Home Page:https://d3js.org/d3-axis

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`axis.tickValues` could also return `values`?

alexlenail opened this issue · comments

axis.tickValues([values])

... If values is not specified, returns the current tick values, which defaults to null. ...

I would have expected, that once an axis is drawn (and has called scale.ticks()) calling axis.tickValues() would return me the cached continuous.ticks. However, since I did not previously set axis.tickValues(a_value), axis.tickValues() returns null. (I'm assuming that calling continuous.ticks() requires computation.)

I think this would involve changing this line to set tickValues as well as values

var values = tickValues == null ? (scale.ticks ? scale.ticks.apply(scale, tickArguments) : scale.domain()) : tickValues,

Or expose a new method to get the current values. In the meantime I'll just call continuous.ticks.


By the way, why doesn't continuous.ticks have a <> which links to some line of code in the source?

It could compute the tick values, but then you’d have no way of knowing whether the axis is configured to use the scale to compute the ticks, or whether the tick values are explicitly specified through axis.tickValues, and similarly there’d be no way to copy the settings from one axis to another.

There’s no link from continuous.ticks to the source because it’s an interface with multiple implementations. And I didn’t want to duplicate the methods for every scale type…

https://github.com/d3/d3-scale/blob/master/src/linear.js
https://github.com/d3/d3-scale/blob/master/src/log.js

@mbostock that's fair. So every time I want ticks from a scale for a given axis, I need to recompute the ticks? There's no method to access the cached ones?

Correct.