in src/visualComponent/axes/helpers/axisHelper.ts [254:326]
export function createFormatter(
scaleDomain: any[],
dataDomain: any[],
dataType: any,
isScalar: boolean,
formatString: string,
bestTickCount: number,
tickValues: any[],
getValueFn: any,
useTickIntervalForDisplayUnits: boolean = false,
axisDisplayUnits?: number,
axisPrecision?: number): valueFormatter.IValueFormatter {
let formatter: valueFormatter.IValueFormatter;
if (dataType.dateTime) {
if (isScalar) {
let value: Date = new Date(scaleDomain[0]);
let value2: Date = new Date(scaleDomain[1]);
// datetime with only one value needs to pass the same value
// (from the original dataDomain value, not the adjusted scaleDomain)
// so formatting works correctly.
if (bestTickCount === 1) {
value = value2 = new Date(dataDomain[0]);
}
// this will ignore the formatString and create one based on the smallest non-zero portion of the values supplied.
formatter = valueFormatter.valueFormatter.create({
format: formatString,
tickCount: bestTickCount,
value,
value2,
});
}
else {
// Use the model formatString for ordinal datetime
formatter = valueFormatter.valueFormatter.createDefaultFormatter(formatString, true);
}
}
else {
if (useTickIntervalForDisplayUnits && isScalar && tickValues.length > 1) {
const value1: number = axisDisplayUnits
? axisDisplayUnits
: tickValues[1] - tickValues[0];
const options: valueFormatter.ValueFormatterOptions = {
allowFormatBeautification: true,
format: formatString,
value: value1,
value2: 0, // force tickInterval or display unit to be used
};
if (axisPrecision) {
options.precision = axisPrecision;
} else {
options.precision = axisModule.calculateAxisPrecision(
tickValues[0],
tickValues[1],
axisDisplayUnits,
formatString,
);
}
formatter = valueFormatter.valueFormatter.create(options);
}
else {
// do not use display units, just the basic value formatter
// datetime is handled above, so we are ordinal and either boolean, numeric, or text.
formatter = valueFormatter.valueFormatter.createDefaultFormatter(formatString, true);
}
}
return formatter;
}