// eslint-disable-next-line no-restricted-imports import {browserHistory, withRouter, WithRouterProps} from 'react-router'; import {useTheme} from '@emotion/react'; import type {LegendComponentOption} from 'echarts'; import ChartZoom from 'sentry/components/charts/chartZoom'; import { LineChart, LineChartProps, LineChartSeries, } from 'sentry/components/charts/lineChart'; import TransitionChart from 'sentry/components/charts/transitionChart'; import TransparentLoadingMask from 'sentry/components/charts/transparentLoadingMask'; import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse'; import {t} from 'sentry/locale'; import {EventsStatsData, OrganizationSummary, Project} from 'sentry/types'; import {Series} from 'sentry/types/echarts'; import {getUtcToLocalDateObject} from 'sentry/utils/dates'; import { axisLabelFormatter, getDurationUnit, tooltipFormatter, } from 'sentry/utils/discover/charts'; import {aggregateOutputType} from 'sentry/utils/discover/fields'; import getDynamicText from 'sentry/utils/getDynamicText'; import {decodeList} from 'sentry/utils/queryString'; import {Theme} from 'sentry/utils/theme'; import {ViewProps} from '../types'; import { NormalizedTrendsTransaction, TrendChangeType, TrendFunctionField, TrendsStats, } from './types'; import { generateTrendFunctionAsString, getCurrentTrendFunction, getCurrentTrendParameter, getUnselectedSeries, transformEventStatsSmoothed, trendToColor, } from './utils'; type Props = WithRouterProps & ViewProps & { isLoading: boolean; location: Location; organization: OrganizationSummary; projects: Project[]; statsData: TrendsStats; trendChangeType: TrendChangeType; disableLegend?: boolean; disableXAxis?: boolean; grid?: LineChartProps['grid']; height?: number; transaction?: NormalizedTrendsTransaction; trendFunctionField?: TrendFunctionField; }; function transformEventStats(data: EventsStatsData, seriesName?: string): Series[] { return [ { seriesName: seriesName || 'Current', data: data.map(([timestamp, countsForTimestamp]) => ({ name: timestamp * 1000, value: countsForTimestamp.reduce((acc, {count}) => acc + count, 0), })), }, ]; } function getLegend(trendFunction: string): LegendComponentOption { return { right: 10, top: 0, itemGap: 12, align: 'left', data: [ { name: 'Baseline', icon: 'path://M180 1000 l0 -40 200 0 200 0 0 40 0 40 -200 0 -200 0 0 -40z, M810 1000 l0 -40 200 0 200 0 0 40 0 40 -200 0 -200 0 0 -40zm, M1440 1000 l0 -40 200 0 200 0 0 40 0 40 -200 0 -200 0 0 -40z', }, { name: 'Releases', }, { name: trendFunction, }, ], }; } function getIntervalLine( theme: Theme, series: Series[], intervalRatio: number, transaction?: NormalizedTrendsTransaction ): LineChartSeries[] { if (!transaction || !series.length || !series[0].data || !series[0].data.length) { return []; } const seriesStart = parseInt(series[0].data[0].name as string, 10); const seriesEnd = parseInt(series[0].data.slice(-1)[0].name as string, 10); if (seriesEnd < seriesStart) { return []; } const periodLine: LineChartSeries = { data: [], color: theme.textColor, markLine: { data: [], label: {}, lineStyle: { color: theme.textColor, type: 'dashed', width: 1, }, symbol: ['none', 'none'], tooltip: { show: false, }, }, seriesName: 'Baseline', }; const periodLineLabel = { fontSize: 11, show: true, color: theme.textColor, silent: true, }; const previousPeriod = { ...periodLine, markLine: {...periodLine.markLine}, seriesName: 'Baseline', }; const currentPeriod = { ...periodLine, markLine: {...periodLine.markLine}, seriesName: 'Baseline', }; const periodDividingLine = { ...periodLine, markLine: {...periodLine.markLine}, seriesName: 'Period split', }; const seriesDiff = seriesEnd - seriesStart; const seriesLine = seriesDiff * intervalRatio + seriesStart; previousPeriod.markLine.data = [ [ {value: 'Past', coord: [seriesStart, transaction.aggregate_range_1]}, {coord: [seriesLine, transaction.aggregate_range_1]}, ], ]; previousPeriod.markLine.tooltip = { formatter: () => { return [ '