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

[7.x] [Metrics UI] Change Metric Threshold Alert charts to use bar charts (#66672) #67062

Merged
merged 1 commit into from
May 19, 2020
Merged
Changes from all 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 @@ -12,6 +12,8 @@ import {
Settings,
TooltipValue,
RectAnnotation,
AnnotationDomainTypes,
LineAnnotation,
} from '@elastic/charts';
import { first, last } from 'lodash';
import moment from 'moment';
Expand Down Expand Up @@ -140,6 +142,7 @@ export const ExpressionChart: React.FC<Props> = ({
}

const isAbove = [Comparator.GT, Comparator.GT_OR_EQ].includes(expression.comparator);
const isBelow = [Comparator.LT, Comparator.LT_OR_EQ].includes(expression.comparator);
const opacity = 0.3;
const { timeSize, timeUnit } = expression;
const timeLabel = TIME_LABELS[timeUnit];
Expand All @@ -149,44 +152,49 @@ export const ExpressionChart: React.FC<Props> = ({
<ChartContainer>
<Chart>
<MetricExplorerSeriesChart
type={MetricsExplorerChartType.area}
type={MetricsExplorerChartType.bar}
metric={metric}
id="0"
series={series}
stack={false}
/>
{thresholds.length ? (
<MetricExplorerSeriesChart
type={isAbove ? MetricsExplorerChartType.line : MetricsExplorerChartType.area}
metric={{
...metric,
color: MetricsExplorerColor.color1,
label: i18n.translate('xpack.infra.metrics.alerts.thresholdLabel', {
defaultMessage: 'Threshold',
}),
}}
id={thresholds.map((t, i) => `threshold_${i}`)}
series={series}
stack={false}
opacity={opacity}
/>
) : null}
{thresholds.length && expression.comparator === Comparator.OUTSIDE_RANGE ? (
<LineAnnotation
id={`thresholds`}
domainType={AnnotationDomainTypes.YDomain}
dataValues={thresholds.map(threshold => ({
dataValue: threshold,
}))}
style={{
line: {
strokeWidth: 2,
stroke: colorTransformer(MetricsExplorerColor.color1),
opacity: 1,
},
}}
/>
{thresholds.length === 2 && expression.comparator === Comparator.BETWEEN ? (
<>
<MetricExplorerSeriesChart
type={MetricsExplorerChartType.line}
metric={{
...metric,
color: MetricsExplorerColor.color1,
label: i18n.translate('xpack.infra.metrics.alerts.thresholdLabel', {
defaultMessage: 'Threshold',
}),
<RectAnnotation
id="lower-threshold"
style={{
fill: colorTransformer(MetricsExplorerColor.color1),
opacity,
}}
id={thresholds.map((t, i) => `threshold_${i}`)}
series={series}
stack={false}
opacity={opacity}
dataValues={[
{
coordinates: {
x0: firstTimestamp,
x1: lastTimestamp,
y0: first(expression.threshold),
y1: last(expression.threshold),
},
},
]}
/>
</>
) : null}
{thresholds.length === 2 && expression.comparator === Comparator.OUTSIDE_RANGE ? (
<>
<RectAnnotation
id="lower-threshold"
style={{
Expand Down Expand Up @@ -223,6 +231,25 @@ export const ExpressionChart: React.FC<Props> = ({
/>
</>
) : null}
{isBelow && first(expression.threshold) != null ? (
<RectAnnotation
id="upper-threshold"
style={{
fill: colorTransformer(MetricsExplorerColor.color1),
opacity,
}}
dataValues={[
{
coordinates: {
x0: firstTimestamp,
x1: lastTimestamp,
y0: domain.min,
y1: first(expression.threshold),
},
},
]}
/>
) : null}
{isAbove && first(expression.threshold) != null ? (
<RectAnnotation
id="upper-threshold"
Expand Down