barChart.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type {BarSeriesOption} from 'echarts';
  2. import {Series} from 'sentry/types/echarts';
  3. import BarSeries from './series/barSeries';
  4. import BaseChart from './baseChart';
  5. type ChartProps = Omit<React.ComponentProps<typeof BaseChart>, 'css'>;
  6. export type BarChartSeries = Series & Omit<BarSeriesOption, 'data' | 'name'>;
  7. export interface BarChartProps extends Omit<ChartProps, 'series'> {
  8. series: BarChartSeries[];
  9. animation?: boolean;
  10. stacked?: boolean;
  11. }
  12. export function BarChart({series, stacked, xAxis, animation, ...props}: BarChartProps) {
  13. return (
  14. <BaseChart
  15. {...props}
  16. xAxis={xAxis !== null ? {...(xAxis || {})} : null}
  17. series={series.map(({seriesName, data, ...options}) =>
  18. BarSeries({
  19. name: seriesName,
  20. stack: stacked ? 'stack1' : undefined,
  21. data: data.map(({value, name, itemStyle}) => {
  22. if (itemStyle === undefined) {
  23. return [name, value];
  24. }
  25. return {value: [name, value], itemStyle};
  26. }),
  27. animation,
  28. ...options,
  29. })
  30. )}
  31. />
  32. );
  33. }