-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
8157930
commit dd688f5
Showing
24 changed files
with
781 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
112 changes: 112 additions & 0 deletions
112
x-pack/plugins/apm/public/components/alerting/chart_preview/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
AnnotationDomainTypes, | ||
Axis, | ||
BarSeries, | ||
Chart, | ||
LineAnnotation, | ||
niceTimeFormatter, | ||
Position, | ||
RectAnnotation, | ||
RectAnnotationDatum, | ||
ScaleType, | ||
Settings, | ||
TickFormatter, | ||
} from '@elastic/charts'; | ||
import { EuiSpacer } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { Coordinate } from '../../../../typings/timeseries'; | ||
import { useTheme } from '../../../hooks/use_theme'; | ||
|
||
interface ChartPreviewProps { | ||
yTickFormat?: TickFormatter; | ||
data?: Coordinate[]; | ||
threshold: number; | ||
} | ||
|
||
export function ChartPreview({ | ||
data = [], | ||
yTickFormat, | ||
threshold, | ||
}: ChartPreviewProps) { | ||
const theme = useTheme(); | ||
const thresholdOpacity = 0.3; | ||
const timestamps = data.map((d) => d.x); | ||
const xMin = Math.min(...timestamps); | ||
const xMax = Math.max(...timestamps); | ||
const xFormatter = niceTimeFormatter([xMin, xMax]); | ||
|
||
// Make the maximum Y value either the actual max or 20% more than the threshold | ||
const values = data.map((d) => d.y ?? 0); | ||
const yMax = Math.max(...values, threshold * 1.2); | ||
|
||
const style = { | ||
fill: theme.eui.euiColorVis9, | ||
line: { | ||
strokeWidth: 2, | ||
stroke: theme.eui.euiColorVis9, | ||
opacity: 1, | ||
}, | ||
opacity: thresholdOpacity, | ||
}; | ||
|
||
const rectDataValues: RectAnnotationDatum[] = [ | ||
{ | ||
coordinates: { | ||
x0: null, | ||
x1: null, | ||
y0: threshold, | ||
y1: null, | ||
}, | ||
}, | ||
]; | ||
|
||
return ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
<Chart size={{ height: 150 }} data-test-subj="ChartPreview"> | ||
<Settings tooltip="none" /> | ||
<LineAnnotation | ||
dataValues={[{ dataValue: threshold }]} | ||
domainType={AnnotationDomainTypes.YDomain} | ||
id="chart_preview_line_annotation" | ||
markerPosition="left" | ||
style={style} | ||
/> | ||
<RectAnnotation | ||
dataValues={rectDataValues} | ||
hideTooltips={true} | ||
id="chart_preview_rect_annotation" | ||
style={style} | ||
/> | ||
<Axis | ||
id="chart_preview_x_axis" | ||
position={Position.Bottom} | ||
showOverlappingTicks | ||
tickFormat={xFormatter} | ||
/> | ||
<Axis | ||
id="chart_preview_y_axis" | ||
position={Position.Left} | ||
tickFormat={yTickFormat} | ||
ticks={5} | ||
domain={{ max: yMax }} | ||
/> | ||
<BarSeries | ||
color={theme.eui.euiColorVis1} | ||
data={data} | ||
id="chart_preview_bar_series" | ||
xAccessor="x" | ||
xScaleType={ScaleType.Linear} | ||
yAccessors={['y']} | ||
yScaleType={ScaleType.Linear} | ||
/> | ||
</Chart> | ||
</> | ||
); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import datemath from '@elastic/datemath'; | ||
|
||
export function getAbsoluteTimeRange(windowSize: number, windowUnit: string) { | ||
const now = new Date().toISOString(); | ||
|
||
return { | ||
start: | ||
datemath.parse(`now-${windowSize}${windowUnit}`)?.toISOString() ?? now, | ||
end: now, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
...ugins/apm/public/components/alerting/service_alert_trigger/service_alert_trigger.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { render } from '@testing-library/react'; | ||
import React, { ReactNode } from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { ServiceAlertTrigger } from './'; | ||
|
||
function Wrapper({ children }: { children?: ReactNode }) { | ||
return <MemoryRouter>{children}</MemoryRouter>; | ||
} | ||
|
||
describe('ServiceAlertTrigger', () => { | ||
it('renders', () => { | ||
expect(() => | ||
render( | ||
<ServiceAlertTrigger | ||
alertTypeName="test alert type name" | ||
defaults={{}} | ||
fields={[null]} | ||
setAlertParams={() => {}} | ||
setAlertProperty={() => {}} | ||
/>, | ||
{ | ||
wrapper: Wrapper, | ||
} | ||
) | ||
).not.toThrowError(); | ||
}); | ||
}); |
File renamed without changes.
Oops, something went wrong.