singleAxisChart.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import type {Location} from 'history';
  2. import type {Organization} from 'sentry/types';
  3. import type EventView from 'sentry/utils/discover/eventView';
  4. import _Footer from '../../charts/footer';
  5. import type {AxisOption} from '../../data';
  6. import DurationChart from '../chart/durationChart';
  7. import HistogramChart from '../chart/histogramChart';
  8. import {getAxisOrBackupAxis, getBackupField} from './utils';
  9. type DisplayProps = {
  10. axis: AxisOption;
  11. eventView: EventView;
  12. location: Location;
  13. onFilterChange: (minValue: number, maxValue: number) => void;
  14. organization: Organization;
  15. usingBackupAxis: boolean;
  16. // only used for distribution graphs
  17. didReceiveMultiAxis?: (useBackup: boolean) => void;
  18. };
  19. export function SingleAxisChart(props: DisplayProps) {
  20. const {
  21. axis,
  22. onFilterChange,
  23. eventView,
  24. organization,
  25. location,
  26. didReceiveMultiAxis,
  27. usingBackupAxis,
  28. } = props;
  29. const backupField = getBackupField(axis);
  30. function didReceiveMulti(dataCounts: Record<string, number>) {
  31. if (!didReceiveMultiAxis) {
  32. return;
  33. }
  34. if (dataCounts[axis.field]) {
  35. didReceiveMultiAxis(false);
  36. return;
  37. }
  38. if (backupField && dataCounts[backupField]) {
  39. didReceiveMultiAxis(true);
  40. return;
  41. }
  42. }
  43. const axisOrBackup = getAxisOrBackupAxis(axis, usingBackupAxis);
  44. return axis.isDistribution ? (
  45. <HistogramChart
  46. field={axis.field}
  47. eventView={eventView}
  48. organization={organization}
  49. location={location}
  50. onFilterChange={onFilterChange}
  51. title={axisOrBackup.label}
  52. titleTooltip={axisOrBackup.tooltip}
  53. didReceiveMultiAxis={didReceiveMulti}
  54. usingBackupAxis={usingBackupAxis}
  55. backupField={backupField}
  56. />
  57. ) : (
  58. <DurationChart
  59. field={axis.field}
  60. eventView={eventView}
  61. organization={organization}
  62. title={axisOrBackup.label}
  63. titleTooltip={axisOrBackup.tooltip}
  64. usingBackupAxis={usingBackupAxis}
  65. backupField={backupField}
  66. />
  67. );
  68. }