Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Elastic chart issues #84238

Merged
merged 6 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ export function ErrorDistribution({ distribution, title }: Props) {
showOverlappingTicks
tickFormat={xFormatter}
/>
<Axis id="y-axis" position={Position.Left} ticks={2} showGridLines />
<Axis
id="y-axis"
position={Position.Left}
ticks={2}
gridLine={{ visible: true }}
/>
<HistogramBarSeries
minBarHeight={2}
id="errorOccurrences"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export function TransactionDistribution({
id="y-axis"
position={Position.Left}
ticks={3}
showGridLines
gridLine={{ visible: true }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

showGridLines is deprecated, changing all to use gridLine.

tickFormat={(value: number) => formatYShort(value)}
/>
<HistogramBarSeries
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,35 @@
*/

import {
AnnotationDomainTypes,
AreaSeries,
Axis,
Chart,
CurveType,
LegendItemListener,
LineAnnotation,
LineSeries,
niceTimeFormatter,
Placement,
Position,
ScaleType,
Settings,
YDomainRange,
} from '@elastic/charts';
import { EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import React, { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { useChartTheme } from '../../../../../observability/public';
import { asAbsoluteDateTime } from '../../../../common/utils/formatters';
import { TimeSeries } from '../../../../typings/timeseries';
import { FETCH_STATUS } from '../../../hooks/useFetcher';
import { useTheme } from '../../../hooks/useTheme';
import { useUrlParams } from '../../../hooks/useUrlParams';
import { useAnnotations } from '../../../hooks/use_annotations';
import { useChartsSync } from '../../../hooks/use_charts_sync';
import { unit } from '../../../style/variables';
import { Annotations } from './annotations';
import { ChartContainer } from './chart_container';
import { onBrushEnd } from './helper/helper';

Expand All @@ -45,6 +52,7 @@ interface Props {
*/
yTickFormat?: (y: number) => string;
showAnnotations?: boolean;
yDomain?: YDomainRange;
}

export function TimeseriesChart({
Expand All @@ -56,12 +64,16 @@ export function TimeseriesChart({
yLabelFormat,
yTickFormat,
showAnnotations = true,
yDomain,
}: Props) {
const history = useHistory();
const chartRef = React.createRef<Chart>();
const chartTheme = useChartTheme();
const { event, setEvent } = useChartsSync();
const { annotations } = useAnnotations();
const chartTheme = useChartTheme();
const { urlParams } = useUrlParams();
const theme = useTheme();

const { start, end } = urlParams;

useEffect(() => {
Expand All @@ -83,6 +95,8 @@ export function TimeseriesChart({
y === null || y === undefined
);

const annotationColor = theme.eui.euiColorSecondary;

return (
<ChartContainer hasData={!isEmpty} height={height} status={fetchStatus}>
<Chart ref={chartRef} id={id}>
Expand Down Expand Up @@ -110,17 +124,35 @@ export function TimeseriesChart({
position={Position.Bottom}
showOverlappingTicks
tickFormat={xFormatter}
gridLine={{ visible: false }}
/>
<Axis
domain={yDomain}
id="y-axis"
ticks={3}
position={Position.Left}
tickFormat={yTickFormat ? yTickFormat : yLabelFormat}
labelFormat={yLabelFormat}
showGridLines
/>

{showAnnotations && <Annotations />}
{showAnnotations && (
<LineAnnotation
id="annotations"
domainType={AnnotationDomainTypes.XDomain}
dataValues={annotations.map((annotation) => ({
dataValue: annotation['@timestamp'],
header: asAbsoluteDateTime(annotation['@timestamp']),
details: `${i18n.translate('xpack.apm.chart.annotation.version', {
defaultMessage: 'Version',
})} ${annotation.text}`,
}))}
style={{
line: { strokeWidth: 1, stroke: annotationColor, opacity: 1 },
}}
marker={<EuiIcon type="dot" color={annotationColor} />}
markerPosition={Position.Top}
/>
Copy link
Member

@sorenlouv sorenlouv Nov 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for this duplication? Wasn't it better to have it in a separate <Annotations /> component?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't it better to have it in a separate component?

Having it as a separate component is the reason the chart disappears after the annotations is rendered. It is a workaround until this issue gets fixed elastic/elastic-charts#914

)}

{timeseries.map((serie) => {
const Series = serie.type === 'area' ? AreaSeries : LineSeries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,35 @@
*/

import {
AnnotationDomainTypes,
AreaSeries,
Axis,
Chart,
CurveType,
LineAnnotation,
niceTimeFormatter,
Placement,
Position,
ScaleType,
Settings,
} from '@elastic/charts';
import { EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import React, { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import { useChartTheme } from '../../../../../../observability/public';
import { asPercent } from '../../../../../common/utils/formatters';
import {
asAbsoluteDateTime,
asPercent,
} from '../../../../../common/utils/formatters';
import { TimeSeries } from '../../../../../typings/timeseries';
import { FETCH_STATUS } from '../../../../hooks/useFetcher';
import { useTheme } from '../../../../hooks/useTheme';
import { useUrlParams } from '../../../../hooks/useUrlParams';
import { useChartsSync as useChartsSync2 } from '../../../../hooks/use_charts_sync';
sorenlouv marked this conversation as resolved.
Show resolved Hide resolved
import { useAnnotations } from '../../../../hooks/use_annotations';
import { useChartsSync } from '../../../../hooks/use_charts_sync';
import { unit } from '../../../../style/variables';
import { Annotations } from '../../charts/annotations';
import { ChartContainer } from '../../charts/chart_container';
import { onBrushEnd } from '../../charts/helper/helper';

Expand All @@ -44,9 +52,11 @@ export function TransactionBreakdownChartContents({
}: Props) {
const history = useHistory();
const chartRef = React.createRef<Chart>();
const { event, setEvent } = useChartsSync();
const { annotations } = useAnnotations();
const chartTheme = useChartTheme();
const { event, setEvent } = useChartsSync2();
const { urlParams } = useUrlParams();
const theme = useTheme();
const { start, end } = urlParams;

useEffect(() => {
Expand All @@ -60,6 +70,8 @@ export function TransactionBreakdownChartContents({

const xFormatter = niceTimeFormatter([min, max]);

const annotationColor = theme.eui.euiColorSecondary;

return (
<ChartContainer height={height} hasData={!!timeseries} status={fetchStatus}>
<Chart ref={chartRef} id="timeSpentBySpan">
Expand All @@ -83,6 +95,7 @@ export function TransactionBreakdownChartContents({
position={Position.Bottom}
showOverlappingTicks
tickFormat={xFormatter}
gridLine={{ visible: false }}
/>
<Axis
id="y-axis"
Expand All @@ -91,7 +104,24 @@ export function TransactionBreakdownChartContents({
tickFormat={(y: number) => asPercent(y ?? 0, 1)}
/>

{showAnnotations && <Annotations />}
{showAnnotations && (
<LineAnnotation
id="annotations"
domainType={AnnotationDomainTypes.XDomain}
dataValues={annotations.map((annotation) => ({
dataValue: annotation['@timestamp'],
header: asAbsoluteDateTime(annotation['@timestamp']),
details: `${i18n.translate('xpack.apm.chart.annotation.version', {
defaultMessage: 'Version',
})} ${annotation.text}`,
}))}
style={{
line: { strokeWidth: 1, stroke: annotationColor, opacity: 1 },
}}
marker={<EuiIcon type="dot" color={annotationColor} />}
markerPosition={Position.Top}
/>
)}

{timeseries?.length ? (
timeseries.map((serie) => {
Expand Down
Loading