Description
What problem does this feature solve?
I use time
axes. My datasets usually have a granularity of days. When there are only few entries in a dataset, the default axisPointer label apparently chooses the second
formatter for lack of a better range. That suggests to the viewer a higher granularity in the data than is actually present.
You currently have very nice functionality to specify the formatting of dates for axis ticks in axisLabel.formatter
. It would be great if there was a string-formatter way to use that syntax for the axisPointer.label.formatter
as well.
As it stands I think I would have to write a custom-code formatter to call TimeScale.getFormattedLabel()
myself.
What does the proposed API look like?
From a cursory glance through the source I think there are several ways to go about implementing somthing of sorts. Minimally, I think I might be satisfied with being able to specify the default granularity of the have TimeScale
:precision
percolate appropriately:
//...
getLabel(tick: TimeScaleTick, opt?: {precision?: string}): string {
const useUTC = this.getSetting('useUTC');
const chosenFormat = opt?.precision || getDefaultFormatPrecisionOfInterval(getPrimaryTimeUnit(this._minLevelUnit));
return format(
tick.value,
fullLeveledFormatter[chosenFormat] || fullLeveledFormatter.second,
useUTC,
this.getSetting('locale')
);
}
leading to
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
label: {
precision: "day"
}
}
},
xAxis: {
type: 'time',
},
//...
}
Ideally I could just use leveledFormat()
syntax in the axisPointer.label.formatter
, if the triggering axis was a time axis:
option = {
tooltip: {
trigger: 'axis',
axisPointer: {
label: {
formatter: "{yyyy}-{MM}-{dd}"
}
}
},
xAxis: {
type: 'time',
},
//...
}
Couldn't that be achieved by using makeLabelFormatter
in getValueLabel
, that seems to cover most of the functionality anyway?