Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let localeObj: d3Format.FormatLocaleObject;
// ----------------------------------------------------------------------
// Test Format and FormatPrefix
// ----------------------------------------------------------------------
formatFn = d3Format.format('.0%');
formatFn = d3Format.formatPrefix(',.0', 1e-6);
// ----------------------------------------------------------------------
// Test Format Specifier
// ----------------------------------------------------------------------
specifier = d3Format.formatSpecifier('.0%');
let fill: string = specifier.fill;
let align: '>' | '<' | '^' | '=' = specifier.align;
let sign: '-' | '+' | '(' | ' ' = specifier.sign;
let symbol: '$' | '#' | '' = specifier.symbol;
let zero: boolean = specifier.zero;
let width: number | undefined = specifier.width;
let comma: boolean = specifier.comma;
let precision: number = specifier.precision;
let type: 'e' | 'f' | 'g' | 'r' | 's' | '%' | 'p' | 'b' | 'o' | 'd' | 'x' | 'X' | 'c' | '' | 'n' = specifier.type;
let formatString: string = specifier.toString();
// ----------------------------------------------------------------------
// Test Precision Suggestors
let localeObj: d3Format.FormatLocaleObject;
// ----------------------------------------------------------------------
// Test Format and FormatPrefix
// ----------------------------------------------------------------------
formatFn = d3Format.format('.0%');
formatFn = d3Format.formatPrefix(',.0', 1e-6);
// ----------------------------------------------------------------------
// Test Format Specifier
// ----------------------------------------------------------------------
specifier = d3Format.formatSpecifier('.0%');
let fill: string = specifier.fill;
let align: '>' | '<' | '^' | '=' = specifier.align;
let sign: '-' | '+' | '(' | ' ' = specifier.sign;
let symbol: '$' | '#' | '' = specifier.symbol;
let zero: boolean = specifier.zero;
let width: number | undefined = specifier.width;
let comma: boolean = specifier.comma;
let precision: number = specifier.precision;
let type: 'e' | 'f' | 'g' | 'r' | 's' | '%' | 'p' | 'b' | 'o' | 'd' | 'x' | 'X' | 'c' | '' | 'n' = specifier.type;
let formatString: string = specifier.toString();
// ----------------------------------------------------------------------
// Test Precision Suggestors
// ----------------------------------------------------------------------
function variablePrecision(specifier) {
var s = formatSpecifier(specifier || ',');
if (s.precision == null) {
s.precision = 12;
switch (s.type) {
case '%': s.precision -= 2; break;
case 'e': s.precision -= 1; break;
}
return trimZeroes(
numberFormat(s), // number format
numberFormat('.1f')(1)[1] // decimal point character
);
} else {
return numberFormat(s);
}
}
x.fields.forEach(field => {
if (field.result === enums.FieldExtResultEnum.Number) {
if (
typeof field.format_number === 'undefined' ||
field.format_number === null
) {
// set default
field.format_number = '';
field.format_number_line_num = 0;
} else {
try {
let fs = formatSpecifier(field.format_number);
} catch (e) {
ErrorsCollector.addError(
new AmError({
title: `wrong format_number`,
message: `format_number value "${
field.format_number
}" is not valid`,
lines: [
{
line: field.format_number_line_num,
name: x.file,
path: x.path
}
]
})
);
legend.labelFormat = function (_) {
if (!arguments.length) return legend.locale().format(specifier);
specifier = formatSpecifier(_);
return legend;
};
export const getFormat = (numberFormat, tLabel) => {
const specifier = formatSpecifier(numberFormat)
if (specifier.type === 's') {
return sFormat(tLabel, specifier.precision)
}
return swissNumbers.format(specifier)
}
function linearNumberFormat(domain, count, f) {
var range = linearRange(domain, count);
if (f == null) f = ',f';
switch (f = d3_numberF.formatSpecifier(f), f.type) {
case 's': {
var value = Math.max(Math.abs(range[0]), Math.abs(range[1]));
if (f.precision == null) f.precision = d3_numberF.precisionPrefix(range[2], value);
return numberF.formatPrefix(f, value);
}
case '':
case 'e':
case 'g':
case 'p':
case 'r': {
if (f.precision == null) f.precision = d3_numberF.precisionRound(range[2], Math.max(Math.abs(range[0]), Math.abs(range[1]))) - (f.type === 'e');
break;
}
case 'f':
case '%': {
if (f.precision == null) f.precision = d3_numberF.precisionFixed(range[2]) - 2 * (f.type === '%');
legend.labelFormat = function(_) {
if (!arguments.length) return legend.locale().format(specifier)
specifier = formatSpecifier(_)
return legend
}
legend.labelFormat = function(_) {
if (!arguments.length) return legend.locale().format(specifier)
specifier = formatSpecifier(_)
return legend
}
numberFormat,
tLabel,
domain,
unit = '',
{ ticks: predefinedTicks } = {}
) => {
const [min, max] = domain
const step = (max - min) / 2
const ticks = predefinedTicks || [
min,
min < 0 && max > 0 ? 0 : min + step,
max
]
const format = swissNumbers.format
const specifier = formatSpecifier(numberFormat)
let formatter = getFormat(numberFormat, tLabel)
let regularFormat
let lastFormat
if (specifier.type === '%') {
let fullStep = +(step * 100).toFixed(specifier.precision)
let fullMax = +(max * 100).toFixed(specifier.precision)
specifier.precision = precisionFixed(
fullStep - Math.floor(fullStep) || fullMax - Math.floor(fullMax)
)
lastFormat = format(specifier.toString())
specifier.type = 'f'
const regularFormatInner = format(specifier.toString())
regularFormat = value => regularFormatInner(value * 100)
} else if (specifier.type === 's') {
const magnitude = d3Max([max - (min > 0 ? min : 0), min].map(Math.abs))
let pow = formatPow(tLabel, Math.max(0, min) + magnitude / 2)