chart.tsx 2.1 KB

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