anomalyChart.tsx 2.0 KB

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