anomalyChart.tsx 2.1 KB

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