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

fix(ui): Adjust metric alert chart rule change gray area boundaries #29727

Merged
merged 5 commits into from
Nov 10, 2021
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
52 changes: 18 additions & 34 deletions static/app/views/alerts/rules/details/metricChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {Client} from 'app/api';
import Feature from 'app/components/acl/feature';
import Button from 'app/components/button';
import ChartZoom from 'app/components/charts/chartZoom';
import Graphic from 'app/components/charts/components/graphic';
import MarkArea from 'app/components/charts/components/markArea';
import MarkLine from 'app/components/charts/components/markLine';
import EventsRequest from 'app/components/charts/eventsRequest';
Expand Down Expand Up @@ -57,9 +56,6 @@ import {

import {TimePeriodType} from './constants';

const X_AXIS_BOUNDARY_GAP = 20;
const VERTICAL_PADDING = 22;

type Props = WithRouterProps & {
api: Client;
rule: IncidentRule;
Expand Down Expand Up @@ -226,8 +222,7 @@ class MetricChart extends React.PureComponent<Props, State> {
}
};

getRuleChangeThresholdElements = (data: LineChartSeries[]): any[] => {
const {height, width} = this.state;
getRuleChangeSeries = (data: LineChartSeries[]): any[] => {
const {dateModified} = this.props.rule || {};

if (!data.length || !data[0].data.length || !dateModified) {
Expand All @@ -236,40 +231,31 @@ class MetricChart extends React.PureComponent<Props, State> {

const seriesData = data[0].data;
const seriesStart = moment(seriesData[0].name).valueOf();
const seriesEnd = moment(seriesData[seriesData.length - 1].name).valueOf();
const ruleChanged = moment(dateModified).valueOf();

if (ruleChanged < seriesStart) {
return [];
}

const chartWidth = width - X_AXIS_BOUNDARY_GAP;
const position =
X_AXIS_BOUNDARY_GAP +
Math.round((chartWidth * (ruleChanged - seriesStart)) / (seriesEnd - seriesStart));

return [
{
type: 'line',
draggable: false,
position: [position, 0],
shape: {y1: 0, y2: height - VERTICAL_PADDING, x1: 1, x2: 1},
style: {
stroke: theme.gray200,
},
},
{
type: 'rect',
draggable: false,
position: [X_AXIS_BOUNDARY_GAP, 0],
shape: {
// +1 makes the gray area go midway onto the dashed line above
width: position - X_AXIS_BOUNDARY_GAP + 1,
height: height - VERTICAL_PADDING,
},
style: {
fill: color(theme.gray100).alpha(0.42).rgb().string(),
},
markLine: MarkLine({
silent: true,
lineStyle: {color: theme.gray200, type: 'solid', width: 1},
data: [{xAxis: ruleChanged} as any],
label: {
show: false,
},
}),
markArea: MarkArea({
silent: true,
itemStyle: {
color: color(theme.gray100).alpha(0.42).rgb().string(),
},
data: [[{xAxis: seriesStart}, {xAxis: ruleChanged}]] as any,
}),
data: [],
},
];
};
Expand Down Expand Up @@ -591,10 +577,8 @@ class MetricChart extends React.PureComponent<Props, State> {
...otherSeriesProps,
})
),
...this.getRuleChangeSeries(timeseriesData),
]}
graphic={Graphic({
elements: this.getRuleChangeThresholdElements(timeseriesData),
})}
tooltip={{
formatter: seriesParams => {
// seriesParams can be object instead of array
Expand Down