mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Add tooltips to metrics in WebsiteMetricsBar and MetricCard components
This commit is contained in:
parent
860e6390f1
commit
552b7d5669
2 changed files with 26 additions and 3 deletions
|
|
@ -25,18 +25,21 @@ export function WebsiteMetricsBar({
|
||||||
label: formatMessage(labels.visitors),
|
label: formatMessage(labels.visitors),
|
||||||
change: visitors - comparison.visitors,
|
change: visitors - comparison.visitors,
|
||||||
formatValue: formatLongNumber,
|
formatValue: formatLongNumber,
|
||||||
|
tooltip: 'Number of unique visitors to your website',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: visits,
|
value: visits,
|
||||||
label: formatMessage(labels.visits),
|
label: formatMessage(labels.visits),
|
||||||
change: visits - comparison.visits,
|
change: visits - comparison.visits,
|
||||||
formatValue: formatLongNumber,
|
formatValue: formatLongNumber,
|
||||||
|
tooltip: 'Total number of sessions on your website',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
value: pageviews,
|
value: pageviews,
|
||||||
label: formatMessage(labels.views),
|
label: formatMessage(labels.views),
|
||||||
change: pageviews - comparison.pageviews,
|
change: pageviews - comparison.pageviews,
|
||||||
formatValue: formatLongNumber,
|
formatValue: formatLongNumber,
|
||||||
|
tooltip: 'Total number of pages viewed',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: formatMessage(labels.bounceRate),
|
label: formatMessage(labels.bounceRate),
|
||||||
|
|
@ -47,6 +50,7 @@ export function WebsiteMetricsBar({
|
||||||
(Math.min(comparison.visits, comparison.bounces) / comparison.visits) * 100,
|
(Math.min(comparison.visits, comparison.bounces) / comparison.visits) * 100,
|
||||||
formatValue: n => `${Math.round(+n)}%`,
|
formatValue: n => `${Math.round(+n)}%`,
|
||||||
reverseColors: true,
|
reverseColors: true,
|
||||||
|
tooltip: 'Percentage of visits that leave after viewing only one page',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: formatMessage(labels.visitDuration),
|
label: formatMessage(labels.visitDuration),
|
||||||
|
|
@ -55,6 +59,7 @@ export function WebsiteMetricsBar({
|
||||||
change: totaltime / visits - comparison.totaltime / comparison.visits,
|
change: totaltime / visits - comparison.totaltime / comparison.visits,
|
||||||
formatValue: n =>
|
formatValue: n =>
|
||||||
`${+n < 0 ? '-' : ''}${formatShortTime(Math.abs(~~n), ['m', 's'], ' ')}`,
|
`${+n < 0 ? '-' : ''}${formatShortTime(Math.abs(~~n), ['m', 's'], ' ')}`,
|
||||||
|
tooltip: 'Average time spent on your website per visit',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: null;
|
: null;
|
||||||
|
|
@ -68,7 +73,7 @@ export function WebsiteMetricsBar({
|
||||||
minHeight="136px"
|
minHeight="136px"
|
||||||
>
|
>
|
||||||
<MetricsBar>
|
<MetricsBar>
|
||||||
{metrics?.map(({ label, value, prev, change, formatValue, reverseColors }) => {
|
{metrics?.map(({ label, value, prev, change, formatValue, reverseColors, tooltip }) => {
|
||||||
return (
|
return (
|
||||||
<MetricCard
|
<MetricCard
|
||||||
key={label}
|
key={label}
|
||||||
|
|
@ -79,6 +84,7 @@ export function WebsiteMetricsBar({
|
||||||
formatValue={formatValue}
|
formatValue={formatValue}
|
||||||
reverseColors={reverseColors}
|
reverseColors={reverseColors}
|
||||||
showChange={!isAllTime}
|
showChange={!isAllTime}
|
||||||
|
tooltip={tooltip}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { useSpring } from '@react-spring/web';
|
import { useSpring } from '@react-spring/web';
|
||||||
import { Column, Text } from '@umami/react-zen';
|
import { Column, Focusable, Icon, Text, Tooltip, TooltipTrigger } from '@umami/react-zen';
|
||||||
|
import { Info } from 'lucide-react';
|
||||||
import { AnimatedDiv } from '@/components/common/AnimatedDiv';
|
import { AnimatedDiv } from '@/components/common/AnimatedDiv';
|
||||||
import { ChangeLabel } from '@/components/metrics/ChangeLabel';
|
import { ChangeLabel } from '@/components/metrics/ChangeLabel';
|
||||||
import { formatNumber } from '@/lib/format';
|
import { formatNumber } from '@/lib/format';
|
||||||
|
|
@ -13,6 +14,7 @@ export interface MetricCardProps {
|
||||||
formatValue?: (n: any) => string;
|
formatValue?: (n: any) => string;
|
||||||
showLabel?: boolean;
|
showLabel?: boolean;
|
||||||
showChange?: boolean;
|
showChange?: boolean;
|
||||||
|
tooltip?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MetricCard = ({
|
export const MetricCard = ({
|
||||||
|
|
@ -23,6 +25,7 @@ export const MetricCard = ({
|
||||||
formatValue = formatNumber,
|
formatValue = formatNumber,
|
||||||
showLabel = true,
|
showLabel = true,
|
||||||
showChange = false,
|
showChange = false,
|
||||||
|
tooltip,
|
||||||
}: MetricCardProps) => {
|
}: MetricCardProps) => {
|
||||||
const diff = value - change;
|
const diff = value - change;
|
||||||
const pct = ((value - diff) / diff) * 100;
|
const pct = ((value - diff) / diff) * 100;
|
||||||
|
|
@ -39,8 +42,22 @@ export const MetricCard = ({
|
||||||
border
|
border
|
||||||
>
|
>
|
||||||
{showLabel && (
|
{showLabel && (
|
||||||
<Text weight="bold" wrap="nowrap">
|
<Text
|
||||||
|
weight="bold"
|
||||||
|
wrap="nowrap"
|
||||||
|
style={{ display: 'flex', alignItems: 'center', gap: '4px' }}
|
||||||
|
>
|
||||||
{label}
|
{label}
|
||||||
|
{tooltip && (
|
||||||
|
<TooltipTrigger delay={0}>
|
||||||
|
<Focusable aria-label="More info">
|
||||||
|
<Icon size="xs" style={{ cursor: 'pointer' }}>
|
||||||
|
<Info />
|
||||||
|
</Icon>
|
||||||
|
</Focusable>
|
||||||
|
<Tooltip>{tooltip}</Tooltip>
|
||||||
|
</TooltipTrigger>
|
||||||
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<Text size="8" weight="bold" wrap="nowrap">
|
<Text size="8" weight="bold" wrap="nowrap">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue