anomalyChart.tsx 1.9 KB

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