echarts
echarts copied to clipboard
[Feature] Forward the axis object to formatter functions
What problem does this feature solve?
In a formatter callback function, it is currently not possible to change the returned format depending on the axis' state, since it is not known for which axis the formatting is requested. Use case: Only show mSecs on a date/time axis if the axis is zoomed in enough (i.e. the range is below a certain threshold).
What does the proposed API look like?
The solution would simply be to let getFormattedLabel forward "this" (= the axis to label) through leveledformat to the user's callback function.
Do you mean time axis?
Yes, my use case was a time axis. But I guess this feature could be useful for other axis types as well?
I think maybe listening to dataZoom changes and call setOption may be a better idea. Even if the axis is provided in the label formatter, it will not be called when dataZoom changes.
OK, but that would still leave me the problem that in the formatter callback itself, I would neither know which axis is being labelled, nor what the current state of the axis is. Or do you mean I should set a different callback function to the chart's option each time dataZoom changes?
I definitely agree that this would offer a lot of flexibility, I've tried using 'time' axis but ran into a few issues (#14305, #16685) where it made sense to change back to 'category'
I am once again confronted with the issue that I do not know which axis is being labelled in the formatter function. Is there any news/workaround for this?
From the current codebase, it looks to be totally easy and also no compatibility issue to simply add the axis to the parameters given to the callback function in makeLabelFormatter(), where the axis in question is already present as input parameter.