feat(slo): Synchronize cursor on SLO charts (#155560)

This commit is contained in:
Kevin Delemme 2023-04-23 13:01:19 -04:00 committed by GitHub
parent 68719bdb07
commit 158ea85468
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View file

@ -15,10 +15,11 @@ import {
ScaleType,
Settings,
} from '@elastic/charts';
import React from 'react';
import React, { useRef } from 'react';
import { EuiIcon, EuiLoadingChart, useEuiTheme } from '@elastic/eui';
import numeral from '@elastic/numeral';
import moment from 'moment';
import { useActiveCursor } from '@kbn/charts-plugin/public';
import { ChartData } from '../../../typings';
import { useKibana } from '../../../utils/kibana_react';
@ -45,18 +46,29 @@ export function WideChart({ chart, data, id, isLoading, state }: Props) {
const color = state === 'error' ? euiTheme.colors.danger : euiTheme.colors.success;
const ChartComponent = chart === 'area' ? AreaSeries : LineSeries;
const chartRef = useRef(null);
const handleCursorUpdate = useActiveCursor(charts.activeCursor, chartRef, {
isDateHistogram: true,
});
if (isLoading) {
return <EuiLoadingChart size="m" mono data-test-subj="wideChartLoading" />;
}
return (
<Chart size={{ height: 150, width: '100%' }}>
<Chart size={{ height: 150, width: '100%' }} ref={chartRef}>
<Settings
baseTheme={baseTheme}
showLegend={false}
theme={[theme]}
tooltip="vertical"
noResults={<EuiIcon type="visualizeApp" size="l" color="subdued" title="no results" />}
onPointerUpdate={handleCursorUpdate}
externalPointerEvents={{
tooltip: { visible: true },
}}
pointerUpdateDebounce={0}
pointerUpdateTrigger={'x'}
/>
<Axis
id="bottom"

View file

@ -54,7 +54,7 @@ const mockKibana = () => {
useKibanaMock.mockReturnValue({
services: {
application: { navigateToUrl: mockNavigate },
charts: chartPluginMock.createSetupContract(),
charts: chartPluginMock.createStartContract(),
http: {
basePath: {
prepend: mockBasePathPrepend,

View file

@ -65,6 +65,7 @@ export function KibanaReactStorybookDecorator(Story: ComponentType) {
useChartsBaseTheme: () => {},
useChartsTheme: () => {},
},
activeCursor: () => {},
},
data: {},
dataViews: {