123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import type {LineSeriesOption, YAXisComponentOption} from 'echarts';
- import type {AreaChartSeries} from 'sentry/components/charts/areaChart';
- import XAxis from 'sentry/components/charts/components/xAxis';
- import AreaSeries from 'sentry/components/charts/series/areaSeries';
- import type {SessionApiResponse} from 'sentry/types';
- import {lightTheme as theme} from 'sentry/utils/theme';
- import type {MetricChartData} from 'sentry/views/alerts/rules/metric/details/metricChartOption';
- import {
- getMetricAlertChartOption,
- transformSessionResponseToSeries,
- } from 'sentry/views/alerts/rules/metric/details/metricChartOption';
- import {DEFAULT_FONT_FAMILY, slackChartDefaults, slackChartSize} from './slack';
- import type {RenderDescriptor} from './types';
- import {ChartType} from './types';
- const metricAlertXaxis = XAxis({
- theme,
- splitNumber: 3,
- isGroupedByDate: true,
- axisLabel: {fontSize: 11, fontFamily: DEFAULT_FONT_FAMILY},
- });
- const metricAlertYaxis: YAXisComponentOption = {
- axisLabel: {fontSize: 11, fontFamily: DEFAULT_FONT_FAMILY},
- splitLine: {
- lineStyle: {
- color: theme.chartLineColor,
- opacity: 0.3,
- },
- },
- };
- function transformAreaSeries(series: AreaChartSeries[]): LineSeriesOption[] {
- return series.map(({seriesName, data, ...otherSeriesProps}) => {
- const areaSeries = AreaSeries({
- name: seriesName,
- data: data.map(({name, value}) => [name, value]),
- lineStyle: {
- opacity: 1,
- width: 0.4,
- },
- areaStyle: {
- opacity: 1.0,
- },
- animation: false,
- animationThreshold: 1,
- animationDuration: 0,
- ...otherSeriesProps,
- });
- // Fix incident label font family, cannot use Rubik
- if (areaSeries.markLine?.label) {
- areaSeries.markLine.label.fontFamily = DEFAULT_FONT_FAMILY;
- }
- return areaSeries;
- });
- }
- export const metricAlertCharts: RenderDescriptor<ChartType>[] = [];
- metricAlertCharts.push({
- key: ChartType.SLACK_METRIC_ALERT_EVENTS,
- getOption: (data: MetricChartData) => {
- const {chartOption} = getMetricAlertChartOption(data);
- return {
- ...chartOption,
- backgroundColor: theme.background,
- series: transformAreaSeries(chartOption.series),
- xAxis: metricAlertXaxis,
- yAxis: {
- ...chartOption.yAxis,
- ...metricAlertYaxis,
- axisLabel: {
- ...chartOption.yAxis!.axisLabel,
- ...metricAlertYaxis.axisLabel,
- },
- },
- grid: slackChartDefaults.grid,
- };
- },
- ...slackChartSize,
- });
- interface MetricAlertSessionData extends Omit<MetricChartData, 'timeseriesData'> {
- sessionResponse: SessionApiResponse;
- }
- metricAlertCharts.push({
- key: ChartType.SLACK_METRIC_ALERT_SESSIONS,
- getOption: (data: MetricAlertSessionData) => {
- const {sessionResponse, rule, ...rest} = data;
- const {chartOption} = getMetricAlertChartOption({
- ...rest,
- rule,
- timeseriesData: transformSessionResponseToSeries(sessionResponse, rule),
- });
- return {
- ...chartOption,
- backgroundColor: theme.background,
- series: transformAreaSeries(chartOption.series),
- xAxis: metricAlertXaxis,
- yAxis: {
- ...chartOption.yAxis,
- ...metricAlertYaxis,
- axisLabel: {
- ...chartOption.yAxis!.axisLabel,
- ...metricAlertYaxis.axisLabel,
- },
- },
- grid: slackChartDefaults.grid,
- };
- },
- ...slackChartSize,
- });
|