Skip to content

Commit 08564a6

Browse files
committed
address review feedback on bounce rate / visit duration charts
- BarChart: add yMax and ySuggestedMax props that wire through to the Chart.js y scale, so consumers can actually cap or hint the axis. - MetricSeriesChart: pass yMax=100 to BarChart for the bouncerate kind so the axis is reliably bounded to 0-100 percent (previously yMax was attached to chartData and silently ignored by Chart.tsx). - MetricSeriesChart: drop locale from the chartData useMemo dependency array since only dateLocale is referenced inside the callback. - MetricSeriesChart: type the data prop as nullable to match the actual shape passed by WebsiteChart while loading.
1 parent c2ec74f commit 08564a6

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/components/charts/BarChart.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface BarChartProps extends ChartProps {
3131
renderTooltipValue?: (raw: { x: any; y: number }, datasetLabel: string) => string;
3232
XAxisType?: string;
3333
YAxisType?: string;
34+
yMax?: number;
35+
ySuggestedMax?: number;
3436
minDate?: Date;
3537
maxDate?: Date;
3638
}
@@ -49,6 +51,8 @@ function BarChartComponent({
4951
unit,
5052
XAxisType = 'timeseries',
5153
YAxisType = 'linear',
54+
yMax,
55+
ySuggestedMax,
5256
stacked = false,
5357
minDate,
5458
maxDate,
@@ -90,6 +94,8 @@ function BarChartComponent({
9094
type: YAxisType,
9195
min: 0,
9296
beginAtZero: true,
97+
...(yMax !== undefined && { max: yMax }),
98+
...(ySuggestedMax !== undefined && { suggestedMax: ySuggestedMax }),
9399
stacked: !!stacked,
94100
grid: {
95101
color: colors.chart.line,
@@ -115,6 +121,8 @@ function BarChartComponent({
115121
locale,
116122
XAxisType,
117123
YAxisType,
124+
yMax,
125+
ySuggestedMax,
118126
]);
119127

120128
const handleTooltip = useCallback(

src/components/metrics/MetricSeriesChart.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import { formatShortTime } from '@/lib/format';
1010
export type MetricSeriesKind = 'bouncerate' | 'visitduration';
1111

1212
export interface MetricSeriesChartProps extends BarChartProps {
13-
data: {
14-
series: { x: string; y: number }[];
15-
compare?: { x: string; y: number }[];
16-
};
13+
data:
14+
| {
15+
series: { x: string; y: number }[];
16+
compare?: { x: string; y: number }[];
17+
}
18+
| null;
1719
unit: string;
1820
kind: MetricSeriesKind;
1921
label: string;
@@ -43,11 +45,8 @@ export function MetricSeriesChart({
4345
const chartData: any = useMemo(() => {
4446
if (!data) return;
4547

46-
const yMaxBaseline = kind === 'bouncerate' ? 100 : undefined;
47-
4848
return {
4949
__id: Date.now(),
50-
yMax: yMaxBaseline,
5150
datasets: [
5251
{
5352
type: 'bar',
@@ -74,7 +73,7 @@ export function MetricSeriesChart({
7473
: []),
7574
],
7675
};
77-
}, [data, locale, kind, label, comparePreviousLabel, colors, minDate, maxDate, unit, dateLocale]);
76+
}, [data, kind, label, comparePreviousLabel, colors, minDate, maxDate, unit, dateLocale]);
7877

7978
const renderXLabel = useCallback(renderDateLabels(unit, locale), [unit, locale]);
8079
const renderYLabel = useCallback((value: any) => formatY(Number(value)), [formatY]);
@@ -83,6 +82,8 @@ export function MetricSeriesChart({
8382
[formatY],
8483
);
8584

85+
const yMax = kind === 'bouncerate' ? 100 : undefined;
86+
8687
return (
8788
<BarChart
8889
{...props}
@@ -93,6 +94,7 @@ export function MetricSeriesChart({
9394
renderXLabel={renderXLabel}
9495
renderYLabel={renderYLabel}
9596
renderTooltipValue={renderTooltipValue}
97+
yMax={yMax}
9698
height="400px"
9799
/>
98100
);

0 commit comments

Comments
 (0)