Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let formatFn: (n: number) => string;
let specifier: d3Format.FormatSpecifier;
let localeDef: d3Format.FormatLocaleDefinition;
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;
function getWidthBasedResolutionText(
zoomLevel, maxWidth, binsPerDimension, maxZoom
) {
const resolution = maxWidth / ((2 ** zoomLevel) * binsPerDimension);
// we can't display a NaN resolution
if (!Number.isNaN(resolution)) {
// what is the maximum possible resolution?
// this will determine how we format the lower resolutions
const maxResolutionSize = maxWidth / ((2 ** maxZoom) * binsPerDimension);
const pp = precisionPrefix(maxResolutionSize, resolution);
const f = formatPrefix(`.${pp}`, resolution);
const formattedResolution = f(resolution);
return formattedResolution;
}
console.warn('NaN resolution, screen is probably too small.');
return '';
}
function formatResolutionText(resolution, maxResolutionSize) {
const pp = precisionPrefix(maxResolutionSize, resolution);
const f = formatPrefix(`.${pp}`, resolution);
const formattedResolution = f(resolution);
return formattedResolution;
}
if (track.maxZoom) {
let formatter = format('.0s');
let inlineOptions = [];
for (let i = 0; i <= track.maxZoom; i++) {
let maxWidth = track.maxWidth;
let binsPerDimension = track.binsPerDimension;
let maxZoom = track.maxZoom;
let resolution = track.maxWidth / (2 ** i * track.binsPerDimension)
let maxResolutionSize = maxWidth / (2 ** maxZoom * binsPerDimension);
let minResolution = maxWidth / binsPerDimension;
let pp = precisionPrefix(maxResolutionSize, resolution);
let f = formatPrefix('.' + pp, resolution);
let formattedResolution = f(resolution);
//let formattedName = ;
inlineOptions.push({
'name': formattedResolution,
value: i.toString()
});
//
}
return inlineOptions;
} else
return [];
}
}
linkLabelText: (link, graph, props) => {
const linkValue = link.value || 0;
const valueText = formatPrefix('.1~f', linkValue)(linkValue);
const sourceText = getValue(
props.nodeLabelText,
link.source,
graph,
props,
);
const targetText = getValue(
props.nodeLabelText,
link.target,
graph,
props,
);
return `${sourceText}→${targetText}: ${valueText}`;
},
linkLabelClassName: '',
export default function(start, stop, count, specifier) {
var step = tickStep(start, stop, count),
precision;
specifier = formatSpecifier(specifier == null ? ",f" : specifier);
switch (specifier.type) {
case "s": {
var value = Math.max(Math.abs(start), Math.abs(stop));
if (specifier.precision == null && !isNaN(precision = precisionPrefix(step, value))) specifier.precision = precision;
return formatPrefix(specifier, value);
}
case "":
case "e":
case "g":
case "p":
case "r": {
if (specifier.precision == null && !isNaN(precision = precisionRound(step, Math.max(Math.abs(start), Math.abs(stop))))) specifier.precision = precision - (specifier.type === "e");
break;
}
case "f":
case "%": {
if (specifier.precision == null && !isNaN(precision = precisionFixed(step))) specifier.precision = precision - (specifier.type === "%") * 2;
break;
}
}
return format(specifier);
return '-';
}
if (typeof value !== 'number') {
return value;
}
let maximumFractionDigits = NUM_DECIMALS_DEFAULT;
const dimensionNameLower = dimensionName.toLowerCase();
if (NUM_DECIMALS[dimensionNameLower] !== undefined) {
maximumFractionDigits = NUM_DECIMALS[dimensionNameLower];
}
const exponentToRoundTo = NUM_EXPONENT_ROUNDING[dimensionNameLower];
if (exponentToRoundTo) {
return formatPrefix(',.0', parseFloat(`1e${exponentToRoundTo}`))(value);
}
if (maximumFractionDigits === 0 && value < 1 && value > 0) {
return '< 1';
}
return value.toLocaleString('en', {
minimumFractionDigits: 0,
maximumFractionDigits
});
};
numeric: number => {
const step = number / 7;
const formatNumber =
number > 10
? formatPrefix(`.${precisionPrefix(step, number)}`, number)
: format(`.${precisionFixed(step)}f`);
return n => {
if (n === null) return '---';
if (n === 0) return '0';
return formatNumber(n);
};
},
percent: () => {