anomalyChart.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import ChartZoom from 'sentry/components/charts/chartZoom';
  2. import type {LineChartProps} from 'sentry/components/charts/lineChart';
  3. import {LineChart} from 'sentry/components/charts/lineChart';
  4. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  5. import {t} from 'sentry/locale';
  6. import type {DateString} from 'sentry/types/core';
  7. import type {Series} from 'sentry/types/echarts';
  8. import {getUtcToLocalDateObject} from 'sentry/utils/dates';
  9. import {axisLabelFormatter, tooltipFormatter} from 'sentry/utils/discover/charts';
  10. import {aggregateOutputType} from 'sentry/utils/discover/fields';
  11. import {useLocation} from 'sentry/utils/useLocation';
  12. type Props = {
  13. data: Series[];
  14. end: DateString;
  15. start: DateString;
  16. statsPeriod: string | undefined;
  17. height?: number;
  18. };
  19. export function AnomalyChart(props: Props) {
  20. const location = useLocation();
  21. const {data, statsPeriod, height, start: propsStart, end: propsEnd} = props;
  22. const start = propsStart ? getUtcToLocalDateObject(propsStart) : null;
  23. const end = propsEnd ? getUtcToLocalDateObject(propsEnd) : null;
  24. const {utc} = normalizeDateTimeParams(location.query);
  25. const chartOptions: Omit<LineChartProps, 'series'> = {
  26. legend: {
  27. right: 10,
  28. top: 5,
  29. data: [t('High Confidence'), t('Low Confidence')],
  30. },
  31. seriesOptions: {
  32. showSymbol: false,
  33. },
  34. height,
  35. tooltip: {
  36. trigger: 'axis',
  37. valueFormatter: (value, label) =>
  38. tooltipFormatter(value, aggregateOutputType(label)),
  39. },
  40. xAxis: undefined,
  41. yAxis: {
  42. axisLabel: {
  43. // Coerces the axis to be count based
  44. formatter: (value: number) => axisLabelFormatter(value, 'number'),
  45. },
  46. },
  47. };
  48. return (
  49. <ChartZoom period={statsPeriod} start={start} end={end} utc={utc === 'true'}>
  50. {zoomRenderProps => (
  51. <LineChart {...zoomRenderProps} series={data} {...chartOptions} />
  52. )}
  53. </ChartZoom>
  54. );
  55. }