areaChart.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. additionalSeries?: LineSeriesOption[];
  10. stacked?: boolean;
  11. }
  12. export function AreaChart({series, stacked, colors, ...props}: AreaChartProps) {
  13. return (
  14. <BaseChart
  15. {...props}
  16. data-test-id="area-chart"
  17. colors={colors}
  18. series={series.map(({seriesName, data, ...otherSeriesProps}, i) =>
  19. AreaSeries({
  20. stack: stacked ? 'area' : undefined,
  21. name: seriesName,
  22. data: data.map(({name, value}) => [name, value]),
  23. lineStyle: {
  24. color: colors?.[i],
  25. opacity: 1,
  26. width: 0.4,
  27. },
  28. areaStyle: {
  29. color: colors?.[i],
  30. opacity: 1.0,
  31. },
  32. animation: false,
  33. animationThreshold: 1,
  34. animationDuration: 0,
  35. ...otherSeriesProps,
  36. })
  37. )}
  38. />
  39. );
  40. }