import DatasetController from '../core/core.datasetController';
+import {formatNumber} from '../core/core.intl';
import {isArray, valueOrDefault} from '../helpers/helpers.core';
import {toRadians, PI, TAU, HALF_PI} from '../helpers/helpers.math';
const meta = me._cachedMeta;
const chart = me.chart;
const labels = chart.data.labels || [];
- const value = new Intl.NumberFormat(chart.options.locale).format(meta._parsed[index]);
+ const value = formatNumber(meta._parsed[index], chart.options.locale);
return {
label: labels[index] || '',
--- /dev/null
+
+const intlCache = new Map();
+
+export function getNumberFormat(locale, options) {
+ options = options || {};
+ const cacheKey = locale + JSON.stringify(options);
+ let formatter = intlCache.get(cacheKey);
+ if (!formatter) {
+ formatter = new Intl.NumberFormat(locale, options);
+ intlCache.set(cacheKey, formatter);
+ }
+ return formatter;
+}
+
+export function formatNumber(num, locale, options) {
+ return getNumberFormat(locale, options).format(num);
+}
import {isArray} from '../helpers/helpers.core';
import {log10} from '../helpers/helpers.math';
+import {formatNumber} from './core.intl';
-const intlCache = new Map();
/**
* Namespace to hold formatters for different types of ticks
* @namespace Chart.Ticks.formatters
const options = {notation, minimumFractionDigits: numDecimal, maximumFractionDigits: numDecimal};
Object.assign(options, this.options.ticks.format);
- const cacheKey = locale + JSON.stringify(options);
- let formatter = intlCache.get(cacheKey);
- if (!formatter) {
- formatter = new Intl.NumberFormat(locale, options);
- intlCache.set(cacheKey, formatter);
- }
-
- return formatter.format(tickValue);
+ return formatNumber(tickValue, locale, options);
}
};
import {isNullOrUndef, valueOrDefault} from '../helpers/helpers.core';
import {almostEquals, almostWhole, log10, _decimalPlaces, _setMinAndMaxByKey, sign} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
+import {formatNumber} from '../core/core.intl';
/**
* Implementation of the nice number algorithm used in determining where axis labels will go
}
getLabelForValue(value) {
- return new Intl.NumberFormat(this.options.locale).format(value);
+ return formatNumber(value, this.options.locale);
}
}
import Scale from '../core/core.scale';
import LinearScaleBase from './scale.linearbase';
import Ticks from '../core/core.ticks';
+import {formatNumber} from '../core/core.intl';
function isMajor(tickVal) {
const remain = tickVal / (Math.pow(10, Math.floor(log10(tickVal))));
* @return {string}
*/
getLabelForValue(value) {
- return value === undefined ? '0' : new Intl.NumberFormat(this.options.locale).format(value);
+ return value === undefined ? '0' : formatNumber(value, this.options.locale);
}
/**