Skip to content

Commit

Permalink
Improve metrics page chart sizing on Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Dec 30, 2024
1 parent 4acc91f commit dc91c25
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
*.untracked.*


*.cpuprofile



.vercel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function LineChartDisplay({
</CardDescription>
</CardHeader>
<CardContent>
<ChartContainer config={config.chart} className='w-full max-h-[300px] p-0 ml-[-30px]'>
<ChartContainer config={config.chart} className='w-full p-0 ml-[-30px]' maxHeight={300}>
<BarChart accessibilityLayer data={datapoints}>
<CartesianGrid
horizontal={true}
Expand Down Expand Up @@ -157,7 +157,7 @@ export function DonutChartDisplay({
</CardTitle>
</CardHeader>
<CardContent>
<ChartContainer config={BRAND_CONFIG} className='w-full max-h-[300px] p-4'>
<ChartContainer config={BRAND_CONFIG} className='w-full p-4' maxHeight={300}>
<PieChart>
<ChartTooltip
cursor={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ export default function PageClient() {
<CardTitle>Recent Sign Ups</CardTitle>
</CardHeader>
<CardContent>
{data.recently_registered.length === 0 && (
<Typography variant='secondary'>No recent sign ups</Typography>
)}
<Table>
<TableBody>
{data.recently_registered.map((user: any) => <TableRow key={user.id}>
Expand All @@ -77,6 +80,9 @@ export default function PageClient() {
<CardTitle>Recently Active Users</CardTitle>
</CardHeader>
<CardContent>
{data.recently_active.length === 0 && (
<Typography variant='secondary'>No recent active users</Typography>
)}
<Table>
<TableBody>
{data.recently_active.map((user: any) => <TableRow key={user.id}>
Expand Down
15 changes: 12 additions & 3 deletions apps/dashboard/src/components/ui/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ function useChart() {
const ChartContainer = React.forwardRef<
HTMLDivElement,
React.ComponentProps<"div"> & {
/**
* Some browsers follow the spec more closely and `height: 100%` does not inherit max-height (eg. Safari), so we
* need to set the maxHeight for both the outer container and the ResponsiveContainer.
*/
maxHeight?: number,
config: ChartConfig,
children: React.ComponentProps<
typeof RechartsPrimitive.ResponsiveContainer
>["children"],
}
>(({ id, className, children, config, ...props }, ref) => {
>(({ id, className, children, config, maxHeight, ...props }, ref) => {
const uniqueId = React.useId();
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;

Expand All @@ -56,16 +61,20 @@ const ChartContainer = React.forwardRef<
className
)}
{...props}
style={{
...props.style,
maxHeight,
}}
>
<ChartStyle id={chartId} config={config} />
<RechartsPrimitive.ResponsiveContainer>
<RechartsPrimitive.ResponsiveContainer maxHeight={maxHeight}>
{children}
</RechartsPrimitive.ResponsiveContainer>
</div>
</ChartContext.Provider>
);
});
ChartContainer.displayName = "Chart";
ChartContainer.displayName = "ChartContainer";

const ChartStyle = ({ id, config }: { id: string, config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter(
Expand Down
13 changes: 4 additions & 9 deletions packages/stack-ui/src/components/ui/table.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { forwardRefIfNeeded } from "@stackframe/stack-shared/dist/utils/react";
import React from "react";

import { cn } from "../../lib/utils";

Expand Down Expand Up @@ -111,12 +111,7 @@ const TableCaption = forwardRefIfNeeded<
TableCaption.displayName = "TableCaption";

export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
Table, TableBody, TableCaption, TableCell, TableFooter,
TableHead, TableHeader, TableRow
};

0 comments on commit dc91c25

Please sign in to comment.