chart.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 {MetricsQueryApiRequestQuery} 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: MetricsQueryApiRequestQuery[];
  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. />
  47. </TransitionChart>
  48. </MetricWidgetChartWrapper>
  49. );
  50. }
  51. const MetricWidgetChartWrapper = styled('div')`
  52. height: 100%;
  53. width: 100%;
  54. padding: ${space(3)};
  55. padding-top: ${space(2)};
  56. `;