areaChart.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import type {LineSeriesOption} from 'echarts';
  2. import {Series} from 'sentry/types/echarts';
  3. import AreaSeries from './series/areaSeries';
  4. import BaseChart from './baseChart';
  5. type ChartProps = Omit<React.ComponentProps<typeof BaseChart>, 'css'>;
  6. export type AreaChartSeries = Series & Omit<LineSeriesOption, 'data' | 'name'>;
  7. export interface AreaChartProps extends Omit<ChartProps, 'series'> {
  8. series: AreaChartSeries[];
  9. stacked?: boolean;
  10. }
  11. export function AreaChart({series, stacked, colors, ...props}: AreaChartProps) {
  12. return (
  13. <BaseChart
  14. {...props}
  15. data-test-id="area-chart"
  16. colors={colors}
  17. series={series.map(({seriesName, data, ...otherSeriesProps}, i) =>
  18. AreaSeries({
  19. stack: stacked ? 'area' : undefined,
  20. name: seriesName,
  21. data: data.map(({name, value}) => [name, value]),
  22. lineStyle: {
  23. color: colors?.[i],
  24. opacity: 1,
  25. width: 0.4,
  26. },
  27. areaStyle: {
  28. color: colors?.[i],
  29. opacity: 1.0,
  30. },
  31. animation: false,
  32. animationThreshold: 1,
  33. animationDuration: 0,
  34. ...otherSeriesProps,
  35. })
  36. )}
  37. />
  38. );
  39. }