heatMapChart.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import './components/visualMap';
  2. import {forwardRef} from 'react';
  3. import type {HeatmapSeriesOption, VisualMapComponentOption} from 'echarts';
  4. import {ReactEchartsRef, Series} from 'sentry/types/echarts';
  5. import HeatMapSeries from './series/heatMapSeries';
  6. import BaseChart from './baseChart';
  7. type ChartProps = Omit<React.ComponentProps<typeof BaseChart>, 'css'>;
  8. export type HeatmapSeries = Series &
  9. Omit<HeatmapSeriesOption, 'data' | 'name'> & {
  10. dataArray?: HeatmapSeriesOption['data'];
  11. };
  12. type Props = Omit<ChartProps, 'series'> & {
  13. series: HeatmapSeries[];
  14. visualMaps: VisualMapComponentOption[];
  15. seriesOptions?: HeatmapSeriesOption;
  16. };
  17. export default forwardRef<ReactEchartsRef, Props>((props, ref) => {
  18. const {series, seriesOptions, visualMaps, ...otherProps} = props;
  19. return (
  20. <BaseChart
  21. ref={ref}
  22. options={{
  23. visualMap: visualMaps,
  24. }}
  25. {...otherProps}
  26. series={series.map(({seriesName, data, dataArray, ...options}) =>
  27. HeatMapSeries({
  28. ...seriesOptions,
  29. ...options,
  30. name: seriesName,
  31. data: dataArray || data.map(({value, name}) => [name, value]),
  32. })
  33. )}
  34. />
  35. );
  36. });