Skip to content

Commit ca5abee

Browse files
fix using global format in chart axis
1 parent 5536804 commit ca5abee

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

packages/devextreme/js/__internal/viz/axes/smart_formatter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
isDefined, isExponential, isFunction, isObject,
2222
} from '@js/core/utils/type';
2323
import formatHelper from '@js/format_helper';
24+
import { getGlobalFormatByDataType } from '@ts/core/m_global_format_config';
2425
import { getAdjustedLog10 as log10 } from '@ts/viz/core/utils';
2526

2627
const _format = formatHelper.format;
@@ -294,6 +295,7 @@ export function smartFormatter(tick, options) {
294295
let { format } = options.labelOptions;
295296
const { ticks } = options;
296297
const isLogarithmic = options.type === 'logarithmic';
298+
const globalFormatDataType = options.dataType === 'datetime' ? 'datetime' : 'number';
297299

298300
if (ticks.length === 1 && ticks.indexOf(tick) === 0 && !isDefined(tickInterval)) {
299301
tickInterval = abs(tick) >= 1 ? 1 : adjust(1 - abs(tick), tick);
@@ -303,6 +305,10 @@ export function smartFormatter(tick, options) {
303305
tick = 0;
304306
}
305307

308+
if (!isDefined(format)) {
309+
format = getGlobalFormatByDataType(globalFormatDataType);
310+
}
311+
306312
if (!isDefined(format) && options.type !== 'discrete' && tick && (options.logarithmBase === 10 || !isLogarithmic)) {
307313
if (options.dataType !== 'datetime' && isDefined(tickInterval)) {
308314
if (ticks.length && ticks.indexOf(tick) === -1) {

packages/devextreme/testing/tests/DevExpress.viz.core/axisFormatting.tests.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import $ from 'jquery';
2+
import config from 'core/config';
23
import translator2DModule from 'viz/translators/translator2d';
34
import { Range } from 'viz/translators/range';
45
import tickGeneratorModule from 'viz/axes/tick_generator';
@@ -140,6 +141,56 @@ const environment = {
140141
}
141142
};
142143

144+
const globalConfigEnvironment = $.extend({}, environment, {
145+
beforeEach: function() {
146+
environment.beforeEach.call(this);
147+
this.savedConfig = { ...config() };
148+
},
149+
afterEach: function() {
150+
config(this.savedConfig);
151+
environment.afterEach.call(this);
152+
}
153+
});
154+
155+
QUnit.module('Global formatting config. Axis labels', globalConfigEnvironment);
156+
157+
QUnit.test('value axis labels use global numberFormat when label.format is not set', function(assert) {
158+
config({
159+
...config(),
160+
numberFormat: { type: 'fixedPoint', precision: 2 }
161+
});
162+
163+
this.testTickLabelFormat(assert, [1500], 100, ['1500.00']);
164+
});
165+
166+
QUnit.test('local axis label.format keeps priority over global numberFormat', function(assert) {
167+
config({
168+
...config(),
169+
numberFormat: { type: 'fixedPoint', precision: 2 }
170+
});
171+
172+
this.testFormat(assert, {
173+
label: {
174+
visible: true,
175+
format: 'thousands'
176+
}
177+
}, [1500], 100, ['1.5K']);
178+
});
179+
180+
QUnit.test('datetime axis labels use global dateTimeFormat when label.format is not set', function(assert) {
181+
config({
182+
...config(),
183+
dateTimeFormat: 'yyyy-MM-dd'
184+
});
185+
186+
this.testFormat(assert, {
187+
argumentType: 'datetime',
188+
label: {
189+
visible: true
190+
}
191+
}, [new Date(2020, 0, 2)], 'day', ['2020-01-02']);
192+
});
193+
143194
QUnit.module('Auto formatting. Tick labels. Numeric.', environment);
144195

145196
QUnit.test('formatter should support short notations of numbers', function(assert) {

0 commit comments

Comments
 (0)