Skip to content

Commit 25f37f1

Browse files
committed
Fit the chart in the container (inc legend)
1 parent 88a2895 commit 25f37f1

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

apps/webapp/app/components/code/QueryResultsChart.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
856856
showLegend={showLegend}
857857
maxLegendItems={fullLegend ? Infinity : 5}
858858
minHeight="300px"
859+
fillContainer
859860
onViewAllLegendItems={onViewAllLegendItems}
860861
>
861862
<Chart.Bar
@@ -879,6 +880,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
879880
showLegend={showLegend}
880881
maxLegendItems={fullLegend ? Infinity : 5}
881882
minHeight="300px"
883+
fillContainer
882884
onViewAllLegendItems={onViewAllLegendItems}
883885
>
884886
<Chart.Line

apps/webapp/app/components/primitives/charts/ChartRoot.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export type ChartRootProps = {
3131
legendTotalLabel?: string;
3232
/** Callback when "View all" legend button is clicked */
3333
onViewAllLegendItems?: () => void;
34+
/** When true, chart fills its parent container height and distributes space between chart and legend */
35+
fillContainer?: boolean;
3436
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
3537
};
3638

@@ -70,6 +72,7 @@ export function ChartRoot({
7072
maxLegendItems = 5,
7173
legendTotalLabel,
7274
onViewAllLegendItems,
75+
fillContainer = false,
7376
children,
7477
}: ChartRootProps) {
7578
return (
@@ -91,6 +94,7 @@ export function ChartRoot({
9194
maxLegendItems={maxLegendItems}
9295
legendTotalLabel={legendTotalLabel}
9396
onViewAllLegendItems={onViewAllLegendItems}
97+
fillContainer={fillContainer}
9498
>
9599
{children}
96100
</ChartRootInner>
@@ -105,6 +109,7 @@ type ChartRootInnerProps = {
105109
maxLegendItems?: number;
106110
legendTotalLabel?: string;
107111
onViewAllLegendItems?: () => void;
112+
fillContainer?: boolean;
108113
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
109114
};
110115

@@ -115,25 +120,36 @@ function ChartRootInner({
115120
maxLegendItems = 5,
116121
legendTotalLabel,
117122
onViewAllLegendItems,
123+
fillContainer = false,
118124
children,
119125
}: ChartRootInnerProps) {
120126
const { config, zoom } = useChartContext();
121127
const enableZoom = zoom !== null;
122128

123129
return (
124-
<div className={cn("relative flex w-full flex-col", className)}>
130+
<div
131+
className={cn(
132+
"relative flex w-full flex-col",
133+
fillContainer && "h-full",
134+
className
135+
)}
136+
>
125137
<div
126-
className={cn("h-full w-full", enableZoom && "mt-8 cursor-crosshair")}
138+
className={cn(
139+
fillContainer ? "min-h-0 flex-1" : "h-full w-full",
140+
enableZoom && "mt-8 cursor-crosshair"
141+
)}
127142
style={{ touchAction: "none", userSelect: "none" }}
128143
>
129144
<ChartContainer
130145
config={config}
131146
className={cn(
132147
"h-full w-full",
148+
fillContainer && "!aspect-auto",
133149
enableZoom &&
134150
"[&_.recharts-surface]:cursor-crosshair [&_.recharts-wrapper]:cursor-crosshair"
135151
)}
136-
style={minHeight ? { minHeight } : undefined}
152+
style={fillContainer ? undefined : minHeight ? { minHeight } : undefined}
137153
>
138154
{children}
139155
</ChartContainer>

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.query/route.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ function ResultsChart({
860860
return (
861861
<><ResizablePanelGroup className="h-full overflow-hidden">
862862
<ResizablePanel id="chart-results">
863-
<div className="h-full bg-charcoal-900 p-2 overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600">
864-
<Card>
863+
<div className="h-full bg-charcoal-900 p-2 overflow-hidden">
864+
<Card className="h-full">
865865
<Card.Header>
866866
<div className="flex items-center gap-1.5">
867867
<ArrowTrendingUpIcon className="size-5 text-indigo-500" />
@@ -871,7 +871,7 @@ function ResultsChart({
871871
<Button variant="minimal/small" LeadingIcon={ArrowsPointingOutIcon} onClick={() => setIsOpen(true)} />
872872
</Card.Accessory>
873873
</Card.Header>
874-
<Card.Content>
874+
<Card.Content className="h-full flex-1 min-h-0">
875875
<QueryResultsChart rows={rows} columns={columns} config={chartConfig} onViewAllLegendItems={() => setIsOpen(true)} />
876876
</Card.Content>
877877
</Card>
@@ -888,7 +888,7 @@ function ResultsChart({
888888
<DialogHeader>
889889
Chart
890890
</DialogHeader>
891-
<div className="overflow-hidden w-full">
891+
<div className="h-full min-h-0 flex-1 overflow-hidden w-full pt-4">
892892
<QueryResultsChart rows={rows} columns={columns} config={chartConfig} fullLegend={true} />
893893
</div>
894894
</DialogContent>

0 commit comments

Comments
 (0)