Skip to content

Commit

Permalink
Put locale on options
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Jan 31, 2020
1 parent 0f9f1fa commit 9875651
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/core/core.scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class Scale extends Element {
let i, ilen, tick;
for (i = 0, ilen = ticks.length; i < ilen; i++) {
tick = ticks[i];
tick.label = call(tickOpts.callback, [tick.value, i, ticks], me);
tick.label = call(tickOpts.callback, [tick.value, i, ticks, me], me);
}
}
afterTickToLabelConversion() {
Expand Down
6 changes: 3 additions & 3 deletions src/core/core.ticks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import {isArray} from '../helpers/helpers.core';
import {log10} from '../helpers/helpers.math';
import Chart from './core.controller';

/**
* Namespace to hold static tick generation functions
Expand Down Expand Up @@ -30,9 +29,10 @@ export default {
* @param tickValue {number} the value to be formatted
* @param index {number} the position of the tickValue parameter in the ticks array
* @param ticks {object[]} the list of ticks being converted
* @param scale {Scale} the scale that these labels will be placed on
* @return {string} string representation of the tickValue parameter
*/
numeric: function(tickValue, index, ticks) {
numeric: function(tickValue, index, ticks, scale) {
if (tickValue === 0) {
return '0'; // never show decimal places for 0
}
Expand All @@ -49,7 +49,7 @@ export default {
const logDelta = log10(Math.abs(delta));

const maxTick = Math.max(Math.abs(ticks[0].value), Math.abs(ticks[ticks.length - 1].value));
const locale = Chart.platform.locale;
const locale = scale.chart.options.locale;
if (maxTick < 1e-4) { // all ticks are small numbers; use scientific notation
const logTick = log10(Math.abs(tickValue));
let numExponential = Math.floor(logTick) - Math.floor(logDelta);
Expand Down
3 changes: 1 addition & 2 deletions src/scales/scale.linearbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import helpers from '../helpers/index';
import {almostEquals, almostWhole, _decimalPlaces, _setMinAndMaxByKey, sign} from '../helpers/helpers.math';
import Chart from '../core/core.controller';
import Scale from '../core/core.scale';

const isNullOrUndef = helpers.isNullOrUndef;
Expand Down Expand Up @@ -245,7 +244,7 @@ class LinearScaleBase extends Scale {
}

getLabelForValue(value) {
return new Intl.NumberFormat(Chart.platform.locale).format(value);
return new Intl.NumberFormat(me.options.locale).format(value);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/scales/scale.logarithmic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {isFinite} from '../helpers/helpers.core';
import {_setMinAndMaxByKey, log10} from '../helpers/helpers.math';
import Scale from '../core/core.scale';
import LinearScaleBase from './scale.linearbase';
import Chart from '../core/core.controller';
import Ticks from '../core/core.ticks';

function isMajor(tickVal) {
Expand Down Expand Up @@ -137,7 +136,7 @@ class LogarithmicScale extends Scale {
}

getLabelForValue(value) {
return value === undefined ? 0 : new Intl.NumberFormat(Chart.platform.locale).format(value);
return value === undefined ? 0 : new Intl.NumberFormat(me.options.locale).format(value);
}

getPixelForTick(index) {
Expand Down
2 changes: 1 addition & 1 deletion src/scales/scale.time.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ class TimeScale extends Scale {
tickOpts.callback
]);

return formatter ? formatter(label, index, ticks) : label;
return formatter ? formatter(label, index, ticks, me) : label;
}

generateTickLabels(ticks) {
Expand Down
2 changes: 1 addition & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function acquireChart(config, options) {
var canvas = document.createElement('canvas');
var chart, key;

Chart.platform.locale = 'en-US';
config = config || {};
options = options || {};
options.canvas = options.canvas || {height: 512, width: 512};
Expand All @@ -57,6 +56,7 @@ function acquireChart(config, options) {
config.options.animation = config.options.animation === undefined ? false : config.options.animation;
config.options.responsive = config.options.responsive === undefined ? false : config.options.responsive;
config.options.fontFamily = config.options.fontFamily || 'Arial';
config.options.locale = config.options.locale || 'en-US';

wrapper.appendChild(canvas);
window.document.body.appendChild(wrapper);
Expand Down

0 comments on commit 9875651

Please sign in to comment.