Skip to content

Commit f95da05

Browse files
committed
[APM] Don't show annotations on charts with no data (#68829)
Hide the annotations plot and legend when a chart has annotations but doesn't have any values in the series. Fixes #66981.
1 parent 29380dc commit f95da05

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { storiesOf } from '@storybook/react';
7+
import React from 'react';
8+
// @ts-ignore
9+
import CustomPlot from './';
10+
11+
storiesOf('shared/charts/CustomPlot', module).add(
12+
'with annotations but no data',
13+
() => {
14+
const annotations = [
15+
{
16+
type: 'version',
17+
id: '2020-06-10 04:36:31',
18+
'@timestamp': 1591763925012,
19+
text: '2020-06-10 04:36:31',
20+
},
21+
{
22+
type: 'version',
23+
id: '2020-06-10 15:23:01',
24+
'@timestamp': 1591802689233,
25+
text: '2020-06-10 15:23:01',
26+
},
27+
];
28+
return <CustomPlot annotations={annotations} series={[]} />;
29+
},
30+
{
31+
info: {
32+
source: false,
33+
text:
34+
"When a chart has no data but does have annotations, the annotations shouldn't show up at all.",
35+
},
36+
}
37+
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class InnerCustomPlot extends PureComponent {
168168
tickFormatX={this.props.tickFormatX}
169169
/>
170170

171-
{this.state.showAnnotations && !isEmpty(annotations) && (
171+
{this.state.showAnnotations && !isEmpty(annotations) && !noHits && (
172172
<AnnotationsPlot
173173
plotValues={plotValues}
174174
width={width}
@@ -202,7 +202,7 @@ export class InnerCustomPlot extends PureComponent {
202202
hiddenSeriesCount={hiddenSeriesCount}
203203
clickLegend={this.clickLegend}
204204
seriesEnabledState={this.state.seriesEnabledState}
205-
hasAnnotations={!isEmpty(annotations)}
205+
hasAnnotations={!isEmpty(annotations) && !noHits}
206206
showAnnotations={this.state.showAnnotations}
207207
onAnnotationsToggle={() => {
208208
this.setState(({ showAnnotations }) => ({

x-pack/plugins/apm/public/components/shared/charts/CustomPlot/test/CustomPlot.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,28 @@ describe('when response has no data', () => {
255255
const onHover = jest.fn();
256256
const onMouseLeave = jest.fn();
257257
const onSelectionEnd = jest.fn();
258+
const annotations = [
259+
{
260+
type: 'version',
261+
id: '2020-06-10 04:36:31',
262+
'@timestamp': 1591763925012,
263+
text: '2020-06-10 04:36:31',
264+
},
265+
{
266+
type: 'version',
267+
id: '2020-06-10 15:23:01',
268+
'@timestamp': 1591802689233,
269+
text: '2020-06-10 15:23:01',
270+
},
271+
];
272+
258273
let wrapper;
259274
beforeEach(() => {
260275
const series = getEmptySeries(1451606400000, 1451610000000);
261276

262277
wrapper = mount(
263278
<InnerCustomPlot
279+
annotations={annotations}
264280
series={series}
265281
onHover={onHover}
266282
onMouseLeave={onMouseLeave}
@@ -294,6 +310,10 @@ describe('when response has no data', () => {
294310
expect(wrapper.find('Tooltip').length).toEqual(0);
295311
});
296312

313+
it('should not show annotations', () => {
314+
expect(wrapper.find('AnnotationsPlot')).toHaveLength(0);
315+
});
316+
297317
it('should have correct markup', () => {
298318
expect(toJson(wrapper)).toMatchSnapshot();
299319
});

0 commit comments

Comments
 (0)