anomalyChart.tsx 2.0 KB

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