-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Elastic chart issues #84238
Changes from 5 commits
c069d57
a99d89f
68490ee
2ae7df5
13fac2e
77e97c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
||
|
@@ -45,6 +52,7 @@ interface Props { | |
*/ | ||
yTickFormat?: (y: number) => string; | ||
showAnnotations?: boolean; | ||
yDomain?: YDomainRange; | ||
} | ||
|
||
export function TimeseriesChart({ | ||
|
@@ -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(() => { | ||
|
@@ -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}> | ||
|
@@ -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} | ||
/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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; | ||
|
There was a problem hiding this comment.
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.