Skip to content

Commit 88a2895

Browse files
committed
Fullscreen from the legend
1 parent ce3026b commit 88a2895

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ interface QueryResultsChartProps {
2828
columns: OutputColumnMetadata[];
2929
config: ChartConfiguration;
3030
fullLegend?: boolean;
31+
/** Callback when "View all" legend button is clicked */
32+
onViewAllLegendItems?: () => void;
3133
}
3234

3335
interface TransformedData {
@@ -699,6 +701,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
699701
columns,
700702
config,
701703
fullLegend = false,
704+
onViewAllLegendItems,
702705
}: QueryResultsChartProps) {
703706
const {
704707
xAxisColumn,
@@ -853,6 +856,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
853856
showLegend={showLegend}
854857
maxLegendItems={fullLegend ? Infinity : 5}
855858
minHeight="300px"
859+
onViewAllLegendItems={onViewAllLegendItems}
856860
>
857861
<Chart.Bar
858862
xAxisProps={xAxisPropsForBar}
@@ -875,6 +879,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
875879
showLegend={showLegend}
876880
maxLegendItems={fullLegend ? Infinity : 5}
877881
minHeight="300px"
882+
onViewAllLegendItems={onViewAllLegendItems}
878883
>
879884
<Chart.Line
880885
xAxisProps={xAxisPropsForLine}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export type ChartLegendCompoundProps = {
1515
className?: string;
1616
/** Label for the total row */
1717
totalLabel?: string;
18+
/** Callback when "View all" button is clicked */
19+
onViewAllLegendItems?: () => void;
1820
};
1921

2022
/**
@@ -34,6 +36,7 @@ export function ChartLegendCompound({
3436
hidden = false,
3537
className,
3638
totalLabel = "Total",
39+
onViewAllLegendItems,
3740
}: ChartLegendCompoundProps) {
3841
const { config, dataKey, dataKeys, highlight, labelFormatter } = useChartContext();
3942
const totals = useSeriesTotal();
@@ -194,19 +197,26 @@ export function ChartLegendCompound({
194197
remainingCount={legendItems.remaining - 1}
195198
/>
196199
) : (
197-
<ViewAllDataRow remainingCount={legendItems.remaining} />
200+
<ViewAllDataRow remainingCount={legendItems.remaining} onViewAll={onViewAllLegendItems} />
198201
))}
199202
</div>
200203
);
201204
}
202205

203206
type ViewAllDataRowProps = {
204207
remainingCount: number;
208+
onViewAll?: () => void;
205209
};
206210

207-
function ViewAllDataRow({ remainingCount }: ViewAllDataRowProps) {
211+
function ViewAllDataRow({ remainingCount, onViewAll }: ViewAllDataRowProps) {
208212
return (
209-
<Button variant="minimal/small" fullWidth iconSpacing="justify-between" className="px-2 py-1">
213+
<Button
214+
variant="minimal/small"
215+
fullWidth
216+
iconSpacing="justify-between"
217+
className="px-2 py-1"
218+
onClick={onViewAll}
219+
>
210220
<div className="flex items-center gap-1.5 text-text-dimmed">
211221
<div className="h-3 w-1 rounded-[2px] border border-charcoal-600" />
212222
<Paragraph variant="extra-small" className="tabular-nums">

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export type ChartRootProps = {
2929
maxLegendItems?: number;
3030
/** Label for the total row in the legend */
3131
legendTotalLabel?: string;
32+
/** Callback when "View all" legend button is clicked */
33+
onViewAllLegendItems?: () => void;
3234
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
3335
};
3436

@@ -67,6 +69,7 @@ export function ChartRoot({
6769
showLegend = false,
6870
maxLegendItems = 5,
6971
legendTotalLabel,
72+
onViewAllLegendItems,
7073
children,
7174
}: ChartRootProps) {
7275
return (
@@ -87,6 +90,7 @@ export function ChartRoot({
8790
showLegend={showLegend}
8891
maxLegendItems={maxLegendItems}
8992
legendTotalLabel={legendTotalLabel}
93+
onViewAllLegendItems={onViewAllLegendItems}
9094
>
9195
{children}
9296
</ChartRootInner>
@@ -100,6 +104,7 @@ type ChartRootInnerProps = {
100104
showLegend?: boolean;
101105
maxLegendItems?: number;
102106
legendTotalLabel?: string;
107+
onViewAllLegendItems?: () => void;
103108
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
104109
};
105110

@@ -109,6 +114,7 @@ function ChartRootInner({
109114
showLegend = false,
110115
maxLegendItems = 5,
111116
legendTotalLabel,
117+
onViewAllLegendItems,
112118
children,
113119
}: ChartRootInnerProps) {
114120
const { config, zoom } = useChartContext();
@@ -134,7 +140,11 @@ function ChartRootInner({
134140
</div>
135141
{/* Legend rendered outside the chart container */}
136142
{showLegend && (
137-
<ChartLegendCompound maxItems={maxLegendItems} totalLabel={legendTotalLabel} />
143+
<ChartLegendCompound
144+
maxItems={maxLegendItems}
145+
totalLabel={legendTotalLabel}
146+
onViewAllLegendItems={onViewAllLegendItems}
147+
/>
138148
)}
139149
</div>
140150
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ function ResultsChart({
872872
</Card.Accessory>
873873
</Card.Header>
874874
<Card.Content>
875-
<QueryResultsChart rows={rows} columns={columns} config={chartConfig} />
875+
<QueryResultsChart rows={rows} columns={columns} config={chartConfig} onViewAllLegendItems={() => setIsOpen(true)} />
876876
</Card.Content>
877877
</Card>
878878

0 commit comments

Comments
 (0)