Skip to content

Commit ead25c3

Browse files
committed
adjusting x-axis to use kibana timezone
1 parent 3466afa commit ead25c3

File tree

2 files changed

+30
-11
lines changed
  • x-pack/legacy/plugins/apm/public/components

2 files changed

+30
-11
lines changed

x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/Distribution/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import { EuiTitle } from '@elastic/eui';
88
import { i18n } from '@kbn/i18n';
99
import { scaleUtc } from 'd3-scale';
10+
import d3 from 'd3';
1011
import React from 'react';
1112
import { asRelativeDateTimeRange } from '../../../../utils/formatters';
1213
import { getTimezoneOffsetInMs } from '../../../shared/charts/CustomPlot/getTimezoneOffsetInMs';
@@ -82,14 +83,13 @@ export function ErrorDistribution({ distribution, title }: Props) {
8283
tooltipHeader={tooltipHeader}
8384
verticalLineHover={(bucket: FormattedBucket) => bucket.x}
8485
xType="time-utc"
85-
formatX={(value: any) => {
86-
if (value && 'getTime' in value) {
87-
const time = value.getTime();
88-
return scaleUtc().tickFormat()(
89-
new Date(time - getTimezoneOffsetInMs(time))
90-
);
91-
}
92-
return value;
86+
formatX={(value: Date) => {
87+
const time = value.getTime();
88+
const xMin = d3.min(buckets, d => d.x0);
89+
const xMax = d3.max(buckets, d => d.x);
90+
return scaleUtc()
91+
.domain([xMin, xMax])
92+
.tickFormat()(new Date(time - getTimezoneOffsetInMs(time)));
9393
}}
9494
buckets={buckets}
9595
bucketSize={distribution.bucketSize}

x-pack/legacy/plugins/apm/public/components/shared/charts/Histogram/index.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { unit } from '../../../../style/variables';
2525
import Tooltip from '../Tooltip';
2626
import theme from '@elastic/eui/dist/eui_theme_light.json';
2727
import { tint } from 'polished';
28+
import { getTimezoneOffsetInMs } from '../CustomPlot/getTimezoneOffsetInMs';
2829

2930
const XY_HEIGHT = unit * 10;
3031
const XY_MARGIN = {
@@ -104,6 +105,9 @@ export class HistogramInner extends PureComponent {
104105
return null;
105106
}
106107

108+
const isTimeSeries =
109+
this.props.xType === 'time' || this.props.xType === 'time-utc';
110+
107111
const xMin = d3.min(buckets, d => d.x0);
108112
const xMax = d3.max(buckets, d => d.x);
109113
const yMin = 0;
@@ -120,11 +124,25 @@ export class HistogramInner extends PureComponent {
120124
.range([XY_HEIGHT, 0])
121125
.nice();
122126

127+
const [xMinZone, xMaxZone] = [xMin, xMax].map(x => {
128+
return x - getTimezoneOffsetInMs(x);
129+
});
130+
131+
const xTickValues = isTimeSeries
132+
? d3.time.scale
133+
.utc()
134+
.domain([xMinZone, xMaxZone])
135+
.range([0, XY_WIDTH])
136+
.ticks(X_TICK_TOTAL)
137+
.map(x => {
138+
const time = x.getTime();
139+
return new Date(time + getTimezoneOffsetInMs(time));
140+
})
141+
: undefined;
142+
123143
const xDomain = x.domain();
124144
const yDomain = y.domain();
125145
const yTickValues = [0, yDomain[1] / 2, yDomain[1]];
126-
const isTimeSeries =
127-
this.props.xType === 'time' || this.props.xType === 'time-utc';
128146
const shouldShowTooltip =
129147
hoveredBucket.x > 0 && (hoveredBucket.y > 0 || isTimeSeries);
130148

@@ -150,6 +168,7 @@ export class HistogramInner extends PureComponent {
150168
tickSizeInner={0}
151169
tickTotal={X_TICK_TOTAL}
152170
tickFormat={formatX}
171+
tickValues={xTickValues}
153172
/>
154173
<YAxis
155174
tickSize={0}
@@ -213,7 +232,7 @@ export class HistogramInner extends PureComponent {
213232
[XY_MARGIN.left, XY_MARGIN.top],
214233
[XY_WIDTH, XY_HEIGHT]
215234
]}
216-
nodes={this.props.buckets.map(bucket => {
235+
nodes={buckets.map(bucket => {
217236
return {
218237
...bucket,
219238
xCenter: (bucket.x0 + bucket.x) / 2

0 commit comments

Comments
 (0)