123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- import LazyLoad from 'react-lazyload';
- import MarkLine from 'sentry/components/charts/components/markLine';
- import MiniBarChart from 'sentry/components/charts/miniBarChart';
- import {t} from 'sentry/locale';
- import {Group, TimeseriesValue} from 'sentry/types';
- import {Series} from 'sentry/types/echarts';
- import {formatAbbreviatedNumber} from 'sentry/utils/formatters';
- import theme from 'sentry/utils/theme';
- type Props = {
- data: Group;
- statsPeriod: string;
- height?: number;
- showMarkLine?: boolean;
- showSecondaryPoints?: boolean;
- };
- function GroupChart({
- data,
- statsPeriod,
- showSecondaryPoints = false,
- height = 24,
- showMarkLine = false,
- }: Props) {
- const stats: TimeseriesValue[] = statsPeriod
- ? data.filtered
- ? data.filtered.stats[statsPeriod]
- : data.stats[statsPeriod]
- : [];
- const secondaryStats: TimeseriesValue[] | null =
- statsPeriod && data.filtered ? data.stats[statsPeriod] : null;
- if (!stats || !stats.length) {
- return null;
- }
- const markLinePoint = stats.map(point => point[1]);
- const formattedMarkLine = formatAbbreviatedNumber(Math.max(...markLinePoint));
- let colors: string[] | undefined = undefined;
- let emphasisColors: string[] | undefined = undefined;
- const series: Series[] = [];
- if (showSecondaryPoints && secondaryStats && secondaryStats.length) {
- series.push({
- seriesName: t('Total Events'),
- data: secondaryStats.map(point => ({name: point[0] * 1000, value: point[1]})),
- });
- series.push({
- seriesName: t('Matching Events'),
- data: stats.map(point => ({name: point[0] * 1000, value: point[1]})),
- });
- } else {
- // Colors are custom to preserve historical appearance where the single series is
- // considerably darker than the two series results.
- colors = [theme.gray300];
- emphasisColors = [theme.purple300];
- series.push({
- seriesName: t('Events'),
- data: stats.map(point => ({name: point[0] * 1000, value: point[1]})),
- markLine:
- showMarkLine && Math.max(...markLinePoint) > 0
- ? MarkLine({
- silent: true,
- lineStyle: {color: theme.gray200, type: 'dotted', width: 1},
- data: [
- {
- type: 'max',
- },
- ],
- label: {
- show: true,
- position: 'start',
- color: `${theme.gray200}`,
- fontFamily: 'Rubik',
- fontSize: 10,
- formatter: `${formattedMarkLine}`,
- },
- })
- : undefined,
- });
- }
- return (
- <LazyLoad debounce={50} height={showMarkLine ? 30 : height}>
- <MiniBarChart
- height={showMarkLine ? 36 : height}
- isGroupedByDate
- showTimeInTooltip
- series={series}
- colors={colors}
- emphasisColors={emphasisColors}
- hideDelay={50}
- showMarkLineLabel={showMarkLine}
- />
- </LazyLoad>
- );
- }
- export default GroupChart;
|