anomalyChart.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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';
  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. import useRouter from 'sentry/utils/useRouter';
  13. type Props = {
  14. data: Series[];
  15. end: DateString;
  16. start: DateString;
  17. statsPeriod: string | undefined;
  18. height?: number;
  19. };
  20. export function AnomalyChart(props: Props) {
  21. const router = useRouter();
  22. const location = useLocation();
  23. const {data, statsPeriod, height, start: propsStart, end: propsEnd} = props;
  24. const start = propsStart ? getUtcToLocalDateObject(propsStart) : null;
  25. const end = propsEnd ? getUtcToLocalDateObject(propsEnd) : null;
  26. const {utc} = normalizeDateTimeParams(location.query);
  27. const chartOptions: Omit<LineChartProps, 'series'> = {
  28. legend: {
  29. right: 10,
  30. top: 5,
  31. data: [t('High Confidence'), t('Low Confidence')],
  32. },
  33. seriesOptions: {
  34. showSymbol: false,
  35. },
  36. height,
  37. tooltip: {
  38. trigger: 'axis',
  39. valueFormatter: (value, label) =>
  40. tooltipFormatter(value, aggregateOutputType(label)),
  41. },
  42. xAxis: undefined,
  43. yAxis: {
  44. axisLabel: {
  45. // Coerces the axis to be count based
  46. formatter: (value: number) => axisLabelFormatter(value, 'number'),
  47. },
  48. },
  49. };
  50. return (
  51. <ChartZoom
  52. router={router}
  53. period={statsPeriod}
  54. start={start}
  55. end={end}
  56. utc={utc === 'true'}
  57. >
  58. {zoomRenderProps => (
  59. <LineChart {...zoomRenderProps} series={data} {...chartOptions} />
  60. )}
  61. </ChartZoom>
  62. );
  63. }