-
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.
[APM] Chart units don't update when toggling the chart legends (#74931)
* changing unit when legend is disabled * changing unit when legend is disabled * show individual units in the tooltip * addressing PR comment * increasing duration threshold * change formatter based on available legends * addressing PR comment Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
aac57fb
commit 647f397
Showing
11 changed files
with
457 additions
and
205 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
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/apm/public/components/shared/charts/TransactionCharts/helper.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,69 @@ | ||
/* | ||
* 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 { | ||
getResponseTimeTickFormatter, | ||
getResponseTimeTooltipFormatter, | ||
getMaxY, | ||
} from './helper'; | ||
import { | ||
getDurationFormatter, | ||
toMicroseconds, | ||
} from '../../../../utils/formatters'; | ||
import { TimeSeries } from '../../../../../typings/timeseries'; | ||
|
||
describe('transaction chart helper', () => { | ||
describe('getResponseTimeTickFormatter', () => { | ||
it('formattes time tick in minutes', () => { | ||
const formatter = getDurationFormatter(toMicroseconds(11, 'minutes')); | ||
const timeTickFormatter = getResponseTimeTickFormatter(formatter); | ||
expect(timeTickFormatter(toMicroseconds(60, 'seconds'))).toEqual( | ||
'1.0 min' | ||
); | ||
}); | ||
it('formattes time tick in seconds', () => { | ||
const formatter = getDurationFormatter(toMicroseconds(11, 'seconds')); | ||
const timeTickFormatter = getResponseTimeTickFormatter(formatter); | ||
expect(timeTickFormatter(toMicroseconds(6, 'seconds'))).toEqual('6.0 s'); | ||
}); | ||
}); | ||
describe('getResponseTimeTooltipFormatter', () => { | ||
const formatter = getDurationFormatter(toMicroseconds(11, 'minutes')); | ||
const tooltipFormatter = getResponseTimeTooltipFormatter(formatter); | ||
it("doesn't format invalid y coordinate", () => { | ||
expect(tooltipFormatter({ x: 1, y: undefined })).toEqual('N/A'); | ||
expect(tooltipFormatter({ x: 1, y: null })).toEqual('N/A'); | ||
}); | ||
it('formattes tooltip in minutes', () => { | ||
expect( | ||
tooltipFormatter({ x: 1, y: toMicroseconds(60, 'seconds') }) | ||
).toEqual('1.0 min'); | ||
}); | ||
}); | ||
describe('getMaxY', () => { | ||
it('returns zero when empty time series', () => { | ||
expect(getMaxY([])).toEqual(0); | ||
}); | ||
it('returns zero for invalid y coordinate', () => { | ||
const timeSeries = ([ | ||
{ data: [{ x: 1 }, { x: 2 }, { x: 3, y: -1 }] }, | ||
] as unknown) as TimeSeries[]; | ||
expect(getMaxY(timeSeries)).toEqual(0); | ||
}); | ||
it('returns the max y coordinate', () => { | ||
const timeSeries = ([ | ||
{ | ||
data: [ | ||
{ x: 1, y: 10 }, | ||
{ x: 2, y: 5 }, | ||
{ x: 3, y: 1 }, | ||
], | ||
}, | ||
] as unknown) as TimeSeries[]; | ||
expect(getMaxY(timeSeries)).toEqual(10); | ||
}); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/apm/public/components/shared/charts/TransactionCharts/helper.tsx
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,35 @@ | ||
/* | ||
* 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 { flatten } from 'lodash'; | ||
import { NOT_AVAILABLE_LABEL } from '../../../../../common/i18n'; | ||
import { isValidCoordinateValue } from '../../../../utils/isValidCoordinateValue'; | ||
import { TimeSeries, Coordinate } from '../../../../../typings/timeseries'; | ||
import { TimeFormatter } from '../../../../utils/formatters'; | ||
|
||
export function getResponseTimeTickFormatter(formatter: TimeFormatter) { | ||
return (t: number) => { | ||
return formatter(t).formatted; | ||
}; | ||
} | ||
|
||
export function getResponseTimeTooltipFormatter(formatter: TimeFormatter) { | ||
return (coordinate: Coordinate) => { | ||
return isValidCoordinateValue(coordinate.y) | ||
? formatter(coordinate.y).formatted | ||
: NOT_AVAILABLE_LABEL; | ||
}; | ||
} | ||
|
||
export function getMaxY(timeSeries: TimeSeries[]) { | ||
const coordinates = flatten( | ||
timeSeries.map((serie: TimeSeries) => serie.data as Coordinate[]) | ||
); | ||
|
||
const numbers: number[] = coordinates.map((c: Coordinate) => (c.y ? c.y : 0)); | ||
|
||
return Math.max(...numbers, 0); | ||
} |
Oops, something went wrong.