Commit 42b544df authored by Miguel Rincon's avatar Miguel Rincon

Merge branch 'astoicescu/adaptDateFormatOnTimeSeries' into 'master'

Add date to timestamps on x-axes of time series charts

See merge request gitlab-org/gitlab!36675
parents fbf7282c 4d959b02
...@@ -48,7 +48,10 @@ export default { ...@@ -48,7 +48,10 @@ export default {
return this.result.values.map(val => { return this.result.values.map(val => {
const [yLabel] = val; const [yLabel] = val;
return formatDate(new Date(yLabel), { format: formats.shortTime, timezone: this.timezone }); return formatDate(new Date(yLabel), {
format: formats.shortTime,
timezone: this.timezone,
});
}); });
}, },
result() { result() {
......
...@@ -76,11 +76,14 @@ export const getYAxisOptions = ({ ...@@ -76,11 +76,14 @@ export const getYAxisOptions = ({
}; };
}; };
export const getTimeAxisOptions = ({ timezone = timezones.LOCAL } = {}) => ({ export const getTimeAxisOptions = ({
timezone = timezones.LOCAL,
format = formats.shortDateTime,
} = {}) => ({
name: __('Time'), name: __('Time'),
type: axisTypes.time, type: axisTypes.time,
axisLabel: { axisLabel: {
formatter: date => formatDate(date, { format: formats.shortTime, timezone }), formatter: date => formatDate(date, { format, timezone }),
}, },
axisPointer: { axisPointer: {
snap: false, snap: false,
......
...@@ -6,7 +6,7 @@ import { chartHeight, legendLayoutTypes } from '../../constants'; ...@@ -6,7 +6,7 @@ import { chartHeight, legendLayoutTypes } from '../../constants';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { graphDataValidatorForValues } from '../../utils'; import { graphDataValidatorForValues } from '../../utils';
import { getTimeAxisOptions, axisTypes } from './options'; import { getTimeAxisOptions, axisTypes } from './options';
import { timezones } from '../../format_date'; import { formats, timezones } from '../../format_date';
export default { export default {
components: { components: {
...@@ -97,7 +97,7 @@ export default { ...@@ -97,7 +97,7 @@ export default {
chartOptions() { chartOptions() {
return { return {
xAxis: { xAxis: {
...getTimeAxisOptions({ timezone: this.timezone }), ...getTimeAxisOptions({ timezone: this.timezone, format: formats.shortTime }),
type: this.xAxisType, type: this.xAxisType,
}, },
dataZoom: [this.dataZoomConfig], dataZoom: [this.dataZoomConfig],
......
...@@ -14,6 +14,7 @@ export const timezones = { ...@@ -14,6 +14,7 @@ export const timezones = {
export const formats = { export const formats = {
shortTime: 'h:MM TT', shortTime: 'h:MM TT',
shortDateTime: 'm/d h:MM TT',
default: 'dd mmm yyyy, h:MMTT (Z)', default: 'dd mmm yyyy, h:MMTT (Z)',
}; };
......
---
title: Add date to x-axes timestamps
merge_request: 36675
author:
type: changed
...@@ -63,8 +63,8 @@ describe('Column component', () => { ...@@ -63,8 +63,8 @@ describe('Column component', () => {
return formatter(date); return formatter(date);
}; };
it('x-axis is formatted correctly in AM/PM format', () => { it('x-axis is formatted correctly in m/d h:MM TT format', () => {
expect(useXAxisFormatter(mockDate)).toEqual('8:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 8:00 PM');
}); });
describe('when in PT timezone', () => { describe('when in PT timezone', () => {
...@@ -78,17 +78,17 @@ describe('Column component', () => { ...@@ -78,17 +78,17 @@ describe('Column component', () => {
it('by default, values are formatted in PT', () => { it('by default, values are formatted in PT', () => {
createWrapper(); createWrapper();
expect(useXAxisFormatter(mockDate)).toEqual('1:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 1:00 PM');
}); });
it('when the chart uses local timezone, y-axis is formatted in PT', () => { it('when the chart uses local timezone, y-axis is formatted in PT', () => {
createWrapper({ timezone: 'LOCAL' }); createWrapper({ timezone: 'LOCAL' });
expect(useXAxisFormatter(mockDate)).toEqual('1:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 1:00 PM');
}); });
it('when the chart uses UTC, y-axis is formatted in UTC', () => { it('when the chart uses UTC, y-axis is formatted in UTC', () => {
createWrapper({ timezone: 'UTC' }); createWrapper({ timezone: 'UTC' });
expect(useXAxisFormatter(mockDate)).toEqual('8:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 8:00 PM');
}); });
}); });
}); });
......
...@@ -527,8 +527,8 @@ describe('Time series component', () => { ...@@ -527,8 +527,8 @@ describe('Time series component', () => {
return formatter(date); return formatter(date);
}; };
it('x-axis is formatted correctly in AM/PM format', () => { it('x-axis is formatted correctly in m/d h:MM TT format', () => {
expect(useXAxisFormatter(mockDate)).toEqual('8:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 8:00 PM');
}); });
describe('when in PT timezone', () => { describe('when in PT timezone', () => {
...@@ -542,17 +542,17 @@ describe('Time series component', () => { ...@@ -542,17 +542,17 @@ describe('Time series component', () => {
it('by default, values are formatted in PT', () => { it('by default, values are formatted in PT', () => {
createWrapper(); createWrapper();
expect(useXAxisFormatter(mockDate)).toEqual('1:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 1:00 PM');
}); });
it('when the chart uses local timezone, y-axis is formatted in PT', () => { it('when the chart uses local timezone, y-axis is formatted in PT', () => {
createWrapper({ timezone: 'LOCAL' }); createWrapper({ timezone: 'LOCAL' });
expect(useXAxisFormatter(mockDate)).toEqual('1:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 1:00 PM');
}); });
it('when the chart uses UTC, y-axis is formatted in UTC', () => { it('when the chart uses UTC, y-axis is formatted in UTC', () => {
createWrapper({ timezone: 'UTC' }); createWrapper({ timezone: 'UTC' });
expect(useXAxisFormatter(mockDate)).toEqual('8:00 PM'); expect(useXAxisFormatter(mockDate)).toEqual('5/26 8:00 PM');
}); });
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment