chart.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {useMemo, useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import TransitionChart from 'sentry/components/charts/transitionChart';
  4. import {space} from 'sentry/styles/space';
  5. import type {MetricsQueryApiResponse} from 'sentry/types';
  6. import type {ReactEchartsRef} from 'sentry/types/echarts';
  7. import type {MetricDisplayType} from 'sentry/utils/metrics/types';
  8. import type {MetricsQueryApiQueryParams} from 'sentry/utils/metrics/useMetricsQuery';
  9. import {LoadingScreen} from 'sentry/views/dashboards/widgetCard/widgetCardChartContainer';
  10. import {MetricChart} from 'sentry/views/ddm/chart/chart';
  11. import {createChartPalette} from 'sentry/views/ddm/utils/metricsChartPalette';
  12. import {getChartTimeseries} from 'sentry/views/ddm/widget';
  13. import {DASHBOARD_CHART_GROUP} from '../dashboard';
  14. type MetricChartContainerProps = {
  15. displayType: MetricDisplayType;
  16. isLoading: boolean;
  17. metricQueries: MetricsQueryApiQueryParams[];
  18. chartHeight?: number;
  19. timeseriesData?: MetricsQueryApiResponse;
  20. };
  21. export function MetricChartContainer({
  22. timeseriesData,
  23. isLoading,
  24. metricQueries,
  25. chartHeight,
  26. displayType,
  27. }: MetricChartContainerProps) {
  28. const chartRef = useRef<ReactEchartsRef>(null);
  29. const chartSeries = useMemo(() => {
  30. return timeseriesData
  31. ? getChartTimeseries(timeseriesData, metricQueries, {
  32. getChartPalette: createChartPalette,
  33. })
  34. : [];
  35. }, [timeseriesData, metricQueries]);
  36. return (
  37. <MetricWidgetChartWrapper>
  38. <TransitionChart loading={isLoading} reloading={isLoading}>
  39. <LoadingScreen loading={isLoading} />
  40. <MetricChart
  41. ref={chartRef}
  42. series={chartSeries}
  43. displayType={displayType}
  44. group={DASHBOARD_CHART_GROUP}
  45. height={chartHeight}
  46. enableZoom
  47. />
  48. </TransitionChart>
  49. </MetricWidgetChartWrapper>
  50. );
  51. }
  52. const MetricWidgetChartWrapper = styled('div')`
  53. height: 100%;
  54. width: 100%;
  55. padding: ${space(3)};
  56. padding-top: ${space(2)};
  57. `;