areaChart.tsx 1.3 KB

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