groupChart.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import LazyLoad from 'react-lazyload';
  2. import MarkLine from 'sentry/components/charts/components/markLine';
  3. import MiniBarChart from 'sentry/components/charts/miniBarChart';
  4. import {t} from 'sentry/locale';
  5. import {Group, TimeseriesValue} from 'sentry/types';
  6. import {Series} from 'sentry/types/echarts';
  7. import {formatAbbreviatedNumber} from 'sentry/utils/formatters';
  8. import theme from 'sentry/utils/theme';
  9. type Props = {
  10. data: Group;
  11. statsPeriod: string;
  12. height?: number;
  13. showMarkLine?: boolean;
  14. showSecondaryPoints?: boolean;
  15. };
  16. function GroupChart({
  17. data,
  18. statsPeriod,
  19. showSecondaryPoints = false,
  20. height = 24,
  21. showMarkLine = false,
  22. }: Props) {
  23. const stats: TimeseriesValue[] = statsPeriod
  24. ? data.filtered
  25. ? data.filtered.stats[statsPeriod]
  26. : data.stats[statsPeriod]
  27. : [];
  28. const secondaryStats: TimeseriesValue[] | null =
  29. statsPeriod && data.filtered ? data.stats[statsPeriod] : null;
  30. if (!stats || !stats.length) {
  31. return null;
  32. }
  33. const markLinePoint = stats.map(point => point[1]);
  34. const formattedMarkLine = formatAbbreviatedNumber(Math.max(...markLinePoint));
  35. let colors: string[] | undefined = undefined;
  36. let emphasisColors: string[] | undefined = undefined;
  37. const series: Series[] = [];
  38. if (showSecondaryPoints && secondaryStats && secondaryStats.length) {
  39. series.push({
  40. seriesName: t('Total Events'),
  41. data: secondaryStats.map(point => ({name: point[0] * 1000, value: point[1]})),
  42. });
  43. series.push({
  44. seriesName: t('Matching Events'),
  45. data: stats.map(point => ({name: point[0] * 1000, value: point[1]})),
  46. });
  47. } else {
  48. // Colors are custom to preserve historical appearance where the single series is
  49. // considerably darker than the two series results.
  50. colors = [theme.gray300];
  51. emphasisColors = [theme.purple300];
  52. series.push({
  53. seriesName: t('Events'),
  54. data: stats.map(point => ({name: point[0] * 1000, value: point[1]})),
  55. markLine:
  56. showMarkLine && Math.max(...markLinePoint) > 0
  57. ? MarkLine({
  58. silent: true,
  59. lineStyle: {color: theme.gray200, type: 'dotted', width: 1},
  60. data: [
  61. {
  62. type: 'max',
  63. },
  64. ],
  65. label: {
  66. show: true,
  67. position: 'start',
  68. color: `${theme.gray200}`,
  69. fontFamily: 'Rubik',
  70. fontSize: 10,
  71. formatter: `${formattedMarkLine}`,
  72. },
  73. })
  74. : undefined,
  75. });
  76. }
  77. return (
  78. <LazyLoad debounce={50} height={showMarkLine ? 30 : height}>
  79. <MiniBarChart
  80. height={showMarkLine ? 36 : height}
  81. isGroupedByDate
  82. showTimeInTooltip
  83. series={series}
  84. colors={colors}
  85. emphasisColors={emphasisColors}
  86. hideDelay={50}
  87. showMarkLineLabel={showMarkLine}
  88. />
  89. </LazyLoad>
  90. );
  91. }
  92. export default GroupChart;