-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Don't set the timezone anywhere in APM since it's already set in autoload For the chart X-axes: * Create nice ticks for the configured timezone (ie at 1w, 1d, 12hrs interval) by offsetting the xMin/xMax * Explicitly pass those tick values to the x-axis * When formatting, use scaleUtc to format everything as UTC, and offset the time again with the configured timezone. Fixes #47832 Fixes #48355
- Loading branch information
Showing
9 changed files
with
186 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...gacy/plugins/apm/public/components/shared/charts/CustomPlot/getTimezoneOffsetInMs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { getTimezoneOffsetInMs } from './getTimezoneOffsetInMs'; | ||
import moment from 'moment-timezone'; | ||
|
||
describe('getTimezoneOffsetInMs', () => { | ||
describe('when no default timezone is set', () => { | ||
it('guesses the timezone', () => { | ||
const guess = jest.fn(() => 'Etc/UTC'); | ||
jest.spyOn(moment.tz, 'guess').mockImplementationOnce(guess); | ||
|
||
getTimezoneOffsetInMs(Date.now()); | ||
|
||
expect(guess).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('when a default timezone is set', () => { | ||
let originalTimezone: moment.MomentZone | null; | ||
|
||
beforeAll(() => { | ||
// @ts-ignore moment types do not define defaultZone but it's there | ||
originalTimezone = moment.defaultZone; | ||
moment.tz.setDefault('America/Denver'); | ||
}); | ||
|
||
afterAll(() => { | ||
moment.tz.setDefault(originalTimezone ? originalTimezone.name : ''); | ||
}); | ||
|
||
it('returns the time in milliseconds', () => { | ||
expect(getTimezoneOffsetInMs(Date.now())).toEqual(21600000); | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
...ck/legacy/plugins/apm/public/components/shared/charts/CustomPlot/getTimezoneOffsetInMs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import moment from 'moment-timezone'; | ||
|
||
export function getTimezoneOffsetInMs(time: number) { | ||
// @ts-ignore moment types don't define defaultZone but it's there | ||
const zone = moment.defaultZone ? moment.defaultZone.name : moment.tz.guess(); | ||
|
||
// @ts-ignore | ||
return moment.tz.zone(zone).parse(time) * 60000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
x-pack/legacy/plugins/apm/public/components/shared/charts/CustomPlot/plotUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// @ts-ignore | ||
import * as plotUtils from './plotUtils'; | ||
|
||
describe('plotUtils', () => { | ||
describe('getPlotValues', () => { | ||
describe('with empty arguments', () => { | ||
it('returns plotvalues', () => { | ||
expect( | ||
plotUtils.getPlotValues([], [], { height: 1, width: 1 }) | ||
).toMatchObject({ | ||
XY_HEIGHT: 1, | ||
XY_WIDTH: 1 | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when yMin is given', () => { | ||
it('uses the yMin in the scale', () => { | ||
expect( | ||
plotUtils | ||
.getPlotValues([], [], { height: 1, width: 1, yMin: 100 }) | ||
.y.domain()[0] | ||
).toEqual(100); | ||
}); | ||
|
||
describe('when yMin is "min"', () => { | ||
it('uses minimum y from the series', () => { | ||
expect( | ||
plotUtils | ||
.getPlotValues( | ||
[{ data: { x: 0, y: 200 } }, { data: { x: 0, y: 300 } }], | ||
[], | ||
{ | ||
height: 1, | ||
width: 1, | ||
yMin: 'min' | ||
} | ||
) | ||
.y.domain()[0] | ||
).toEqual(200); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when yMax given', () => { | ||
it('uses yMax', () => { | ||
expect( | ||
plotUtils | ||
.getPlotValues([], [], { | ||
height: 1, | ||
width: 1, | ||
yMax: 500 | ||
}) | ||
.y.domain()[1] | ||
).toEqual(500); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.