discover.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import XAxis from 'app/components/charts/components/xAxis';
  2. import AreaSeries from 'app/components/charts/series/areaSeries';
  3. import BarSeries from 'app/components/charts/series/barSeries';
  4. import {EventsStats} from 'app/types';
  5. import {lightTheme as theme} from 'app/utils/theme';
  6. import {slackChartDefaults, slackChartSize} from './slack';
  7. import {ChartType, RenderDescriptor} from './types';
  8. const discoverxAxis = XAxis({
  9. theme,
  10. boundaryGap: true,
  11. splitNumber: 3,
  12. isGroupedByDate: true,
  13. axisLabel: {fontSize: 11},
  14. });
  15. export const discoverCharts: RenderDescriptor<ChartType>[] = [];
  16. discoverCharts.push({
  17. key: ChartType.SLACK_DISCOVER_TOTAL_PERIOD,
  18. getOption: (data: {seriesName: string; stats: EventsStats}) => {
  19. const color = theme.charts.getColorPalette(data.stats.data.length - 2);
  20. const areaSeries = AreaSeries({
  21. name: data.seriesName,
  22. data: data.stats.data.map(([timestamp, countsForTimestamp]) => [
  23. timestamp * 1000,
  24. countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
  25. ]),
  26. lineStyle: {color: color?.[0], opacity: 1, width: 0.4},
  27. areaStyle: {color: color?.[0], opacity: 1},
  28. });
  29. return {
  30. ...slackChartDefaults,
  31. useUTC: true,
  32. color,
  33. series: [areaSeries],
  34. };
  35. },
  36. ...slackChartSize,
  37. });
  38. discoverCharts.push({
  39. key: ChartType.SLACK_DISCOVER_TOTAL_DAILY,
  40. getOption: (data: {seriesName: string; stats: EventsStats}) => {
  41. const color = theme.charts.getColorPalette(data.stats.data.length - 2);
  42. const barSeries = BarSeries({
  43. name: data.seriesName,
  44. data: data.stats.data.map(([timestamp, countsForTimestamp]) => ({
  45. value: [
  46. timestamp * 1000,
  47. countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
  48. ],
  49. })),
  50. itemStyle: {color: color?.[0], opacity: 1},
  51. });
  52. return {
  53. ...slackChartDefaults,
  54. xAxis: discoverxAxis,
  55. useUTC: true,
  56. color,
  57. series: [barSeries],
  58. };
  59. },
  60. ...slackChartSize,
  61. });
  62. discoverCharts.push({
  63. key: ChartType.SLACK_DISCOVER_TOP5_PERIOD,
  64. getOption: (data: {stats: Record<string, EventsStats>}) => {
  65. const stats = Object.values(data.stats);
  66. const color = theme.charts.getColorPalette(stats.length - 2);
  67. const series = stats
  68. .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
  69. .map((topSeries, i) =>
  70. AreaSeries({
  71. stack: 'area',
  72. data: topSeries.data.map(([timestamp, countsForTimestamp]) => [
  73. timestamp * 1000,
  74. countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
  75. ]),
  76. lineStyle: {color: color?.[i], opacity: 1, width: 0.4},
  77. areaStyle: {color: color?.[i], opacity: 1},
  78. })
  79. );
  80. return {
  81. ...slackChartDefaults,
  82. xAxis: discoverxAxis,
  83. useUTC: true,
  84. color,
  85. series,
  86. };
  87. },
  88. ...slackChartSize,
  89. });
  90. discoverCharts.push({
  91. key: ChartType.SLACK_DISCOVER_TOP5_DAILY,
  92. getOption: (data: {stats: Record<string, EventsStats>}) => {
  93. const stats = Object.values(data.stats);
  94. const color = theme.charts.getColorPalette(stats.length - 2);
  95. const series = stats
  96. .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
  97. .map((topSeries, i) =>
  98. BarSeries({
  99. stack: 'area',
  100. data: topSeries.data.map(([timestamp, countsForTimestamp]) => [
  101. timestamp * 1000,
  102. countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
  103. ]),
  104. itemStyle: {color: color?.[i], opacity: 1},
  105. })
  106. );
  107. return {
  108. ...slackChartDefaults,
  109. xAxis: discoverxAxis,
  110. useUTC: true,
  111. color,
  112. series,
  113. };
  114. },
  115. ...slackChartSize,
  116. });