Skip to content

Commit

Permalink
[APM] Elastic chart issues (#84238)
Browse files Browse the repository at this point in the history
* fixing charts

* addressing pr comments
  • Loading branch information
cauemarcondes committed Nov 25, 2020
1 parent 9440389 commit 536891e
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 137 deletions.
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 }}
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 { useChartPointerEvent } from '../../../hooks/use_chart_pointer_event';
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 { annotations } = useAnnotations();
const chartTheme = useChartTheme();
const { pointerEvent, setPointerEvent } = useChartPointerEvent();
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 All @@ -108,17 +122,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}
/>
)}

{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 { useAnnotations } from '../../../../hooks/use_annotations';
import { useChartPointerEvent } from '../../../../hooks/use_chart_pointer_event';
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 { annotations } = useAnnotations();
const chartTheme = useChartTheme();
const { pointerEvent, setPointerEvent } = useChartPointerEvent();
const { urlParams } = useUrlParams();
const theme = useTheme();
const { start, end } = urlParams;

useEffect(() => {
Expand All @@ -64,6 +74,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 @@ -85,6 +97,7 @@ export function TransactionBreakdownChartContents({
position={Position.Bottom}
showOverlappingTicks
tickFormat={xFormatter}
gridLine={{ visible: false }}
/>
<Axis
id="y-axis"
Expand All @@ -93,7 +106,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

0 comments on commit 536891e

Please sign in to comment.