improve(dashboard): add settings to conversions and add average line
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
|||||||
import { createChartTooltip } from '@/components/charts/chart-tooltip';
|
import { createChartTooltip } from '@/components/charts/chart-tooltip';
|
||||||
import { useFormatDateInterval } from '@/hooks/useFormatDateInterval';
|
import { useFormatDateInterval } from '@/hooks/useFormatDateInterval';
|
||||||
import { useNumber } from '@/hooks/useNumerFormatter';
|
import { useNumber } from '@/hooks/useNumerFormatter';
|
||||||
import { getPreviousMetric } from '@openpanel/common';
|
import { average, getPreviousMetric, round } from '@openpanel/common';
|
||||||
import type { IInterval } from '@openpanel/validation';
|
import type { IInterval } from '@openpanel/validation';
|
||||||
import { Fragment } from 'react';
|
import { Fragment } from 'react';
|
||||||
import { useXAxisProps, useYAxisProps } from '../common/axis';
|
import { useXAxisProps, useYAxisProps } from '../common/axis';
|
||||||
@@ -61,6 +61,12 @@ export function Chart({ data }: Props) {
|
|||||||
hide: hideYAxis,
|
hide: hideYAxis,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const averageConversionRate = average(
|
||||||
|
data.current.map((serie) => {
|
||||||
|
return average(serie.data.map((item) => item.rate));
|
||||||
|
}, 0),
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipProvider conversion={data} interval={interval}>
|
<TooltipProvider conversion={data} interval={interval}>
|
||||||
<div className={cn('h-full w-full', isEditMode && 'card p-4')}>
|
<div className={cn('h-full w-full', isEditMode && 'card p-4')}>
|
||||||
@@ -118,6 +124,23 @@ export function Chart({ data }: Props) {
|
|||||||
</Fragment>
|
</Fragment>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
{typeof averageConversionRate === 'number' &&
|
||||||
|
averageConversionRate && (
|
||||||
|
<ReferenceLine
|
||||||
|
y={averageConversionRate}
|
||||||
|
stroke={getChartColor(1)}
|
||||||
|
strokeWidth={2}
|
||||||
|
strokeDasharray="3 3"
|
||||||
|
strokeOpacity={0.5}
|
||||||
|
strokeLinecap="round"
|
||||||
|
label={{
|
||||||
|
value: `Average (${round(averageConversionRate, 2)} %)`,
|
||||||
|
fill: getChartColor(1),
|
||||||
|
position: 'insideBottomRight',
|
||||||
|
fontSize: 12,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</LineChart>
|
</LineChart>
|
||||||
</ResponsiveContainer>
|
</ResponsiveContainer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export function ReportSettings() {
|
|||||||
fields.push('unit');
|
fields.push('unit');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chartType === 'funnel') {
|
if (chartType === 'funnel' || chartType === 'conversion') {
|
||||||
fields.push('funnelGroup');
|
fields.push('funnelGroup');
|
||||||
fields.push('funnelWindow');
|
fields.push('funnelWindow');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user