performance.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import type {LineChartProps} from 'sentry/components/charts/lineChart';
  2. import {transformToLineSeries} from 'sentry/components/charts/lineChart';
  3. import getBreakpointChartOptionsFromData, {
  4. type EventBreakpointChartData,
  5. } from 'sentry/components/events/eventStatisticalDetector/breakpointChartOptions';
  6. import type {EventsStatsSeries} from 'sentry/types/organization';
  7. import {transformStatsResponse} from 'sentry/utils/profiling/hooks/utils';
  8. import {lightTheme as theme} from 'sentry/utils/theme';
  9. import type {NormalizedTrendsTransaction} from 'sentry/views/performance/trends/types';
  10. import {DEFAULT_FONT_FAMILY, slackChartDefaults, slackChartSize} from './slack';
  11. import type {RenderDescriptor} from './types';
  12. import {ChartType} from './types';
  13. export const performanceCharts: RenderDescriptor<ChartType>[] = [];
  14. export type FunctionRegressionPercentileData = {
  15. data: EventsStatsSeries<'p95()'>;
  16. };
  17. function modifyOptionsForSlack(options: Omit<LineChartProps, 'series'>) {
  18. options.legend = options.legend || {};
  19. options.legend.icon = 'none';
  20. options.legend.left = '25';
  21. options.legend.top = '20';
  22. options.grid = slackChartDefaults.grid;
  23. options.yAxis = options.yAxis || {};
  24. options.yAxis.axisLabel = options.yAxis.axisLabel || {};
  25. options.yAxis.axisLabel.fontFamily = DEFAULT_FONT_FAMILY;
  26. options.xAxis = options.xAxis || {};
  27. options.xAxis.axisLabel = options.xAxis.axisLabel || {};
  28. options.xAxis.axisLabel.fontFamily = DEFAULT_FONT_FAMILY;
  29. return {
  30. ...options,
  31. grid: slackChartDefaults.grid,
  32. visualMap: options.options?.visualMap,
  33. };
  34. }
  35. type FunctionRegressionChartData = {
  36. evidenceData: NormalizedTrendsTransaction;
  37. rawResponse: any;
  38. };
  39. performanceCharts.push({
  40. key: ChartType.SLACK_PERFORMANCE_ENDPOINT_REGRESSION,
  41. getOption: (data: EventBreakpointChartData) => {
  42. const {chartOptions, series} = getBreakpointChartOptionsFromData(
  43. data,
  44. ChartType.SLACK_PERFORMANCE_ENDPOINT_REGRESSION,
  45. theme
  46. );
  47. const transformedSeries = transformToLineSeries({series});
  48. const modifiedOptions = modifyOptionsForSlack(chartOptions);
  49. return {
  50. ...modifiedOptions,
  51. backgroundColor: theme.background,
  52. series: transformedSeries,
  53. grid: slackChartDefaults.grid,
  54. visualMap: modifiedOptions.options?.visualMap,
  55. };
  56. },
  57. ...slackChartSize,
  58. });
  59. performanceCharts.push({
  60. key: ChartType.SLACK_PERFORMANCE_FUNCTION_REGRESSION,
  61. getOption: (data: FunctionRegressionChartData) => {
  62. const transformed = transformStatsResponse(
  63. 'profileFunctions',
  64. ['p95()'],
  65. data.rawResponse
  66. );
  67. const percentileData = {
  68. data: transformed,
  69. };
  70. const param = {
  71. percentileData: percentileData as FunctionRegressionPercentileData,
  72. evidenceData: data.evidenceData,
  73. };
  74. const {chartOptions, series} = getBreakpointChartOptionsFromData(
  75. param,
  76. ChartType.SLACK_PERFORMANCE_FUNCTION_REGRESSION,
  77. theme
  78. );
  79. const transformedSeries = transformToLineSeries({series});
  80. const modifiedOptions = modifyOptionsForSlack(chartOptions);
  81. return {
  82. ...modifiedOptions,
  83. backgroundColor: theme.background,
  84. series: transformedSeries,
  85. grid: slackChartDefaults.grid,
  86. visualMap: modifiedOptions.options?.visualMap,
  87. };
  88. },
  89. ...slackChartSize,
  90. });