Skip to content

Commit 58d0d8e

Browse files
committed
Don't show the normal recharts legend
1 parent d347d72 commit 58d0d8e

File tree

6 files changed

+56
-73
lines changed

6 files changed

+56
-73
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -819,13 +819,13 @@ export const QueryResultsChart = memo(function QueryResultsChart({
819819
// This properly represents time gaps between data points
820820
const xAxisPropsForLine = isDateBased
821821
? {
822-
type: "number" as const,
823-
domain: timeDomain ?? (["auto", "auto"] as [string, string]),
824-
scale: "time" as const,
825-
// Explicitly specify tick positions so labels appear across the entire range
826-
ticks: timeTicks ?? undefined,
827-
...baseXAxisProps,
828-
}
822+
type: "number" as const,
823+
domain: timeDomain ?? (["auto", "auto"] as [string, string]),
824+
scale: "time" as const,
825+
// Explicitly specify tick positions so labels appear across the entire range
826+
ticks: timeTicks ?? undefined,
827+
...baseXAxisProps,
828+
}
829829
: baseXAxisProps;
830830

831831
// Bar charts always use categorical axis positioning
@@ -849,7 +849,7 @@ export const QueryResultsChart = memo(function QueryResultsChart({
849849
series={series}
850850
labelFormatter={legendLabelFormatter}
851851
showLegend={showLegend}
852-
maxLegendItems={6}
852+
maxLegendItems={5}
853853
minHeight="300px"
854854
>
855855
<Chart.Bar

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

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function ChartBarRenderer({
7575
width,
7676
height,
7777
}: ChartBarRendererProps) {
78-
const { config, data, dataKey, dataKeys, state, highlight, zoom } = useChartContext();
78+
const { config, data, dataKey, dataKeys, state, highlight, zoom, showLegend } = useChartContext();
7979
const hasNoData = useHasNoData();
8080
const zoomHandlers = useZoomHandlers();
8181
const enableZoom = zoom !== null;
@@ -162,23 +162,26 @@ export function ChartBarRenderer({
162162
domain={["auto", (dataMax: number) => dataMax * 1.15]}
163163
{...yAxisPropsProp}
164164
/>
165-
<ChartTooltip
166-
cursor={{ fill: "#2C3034" }}
167-
content={
168-
tooltipLabelFormatter ? (
169-
<ChartTooltipContent />
170-
) : (
171-
<ZoomTooltip
172-
isSelecting={zoom?.isSelecting}
173-
refAreaLeft={zoom?.refAreaLeft}
174-
refAreaRight={zoom?.refAreaRight}
175-
invalidSelection={zoom?.invalidSelection}
176-
/>
177-
)
178-
}
179-
labelFormatter={tooltipLabelFormatter}
180-
allowEscapeViewBox={{ x: false, y: true }}
181-
/>
165+
{/* Hide tooltip when legend is shown - legend displays hover data instead */}
166+
{!showLegend && (
167+
<ChartTooltip
168+
cursor={{ fill: "#2C3034" }}
169+
content={
170+
tooltipLabelFormatter ? (
171+
<ChartTooltipContent />
172+
) : (
173+
<ZoomTooltip
174+
isSelecting={zoom?.isSelecting}
175+
refAreaLeft={zoom?.refAreaLeft}
176+
refAreaRight={zoom?.refAreaRight}
177+
invalidSelection={zoom?.invalidSelection}
178+
/>
179+
)
180+
}
181+
labelFormatter={tooltipLabelFormatter}
182+
allowEscapeViewBox={{ x: false, y: true }}
183+
/>
184+
)}
182185

183186
{/* Zoom selection area - rendered before bars to appear behind them */}
184187
{enableZoom && zoom?.refAreaLeft && zoom?.refAreaRight && (
@@ -269,37 +272,3 @@ export function ChartBarRenderer({
269272
</BarChart>
270273
);
271274
}
272-
273-
// ============================================================================
274-
// LEGACY API (for backward compatibility)
275-
// ============================================================================
276-
277-
type LegacyChartBarProps = {
278-
config: ChartConfig;
279-
data: any[];
280-
dataKey: string;
281-
state?: ChartState;
282-
maxLegendItems?: number;
283-
referenceLine?: ReferenceLineProps;
284-
minHeight?: string;
285-
stackId?: string;
286-
/** Series keys to render (if not provided, derived from config keys) */
287-
series?: string[];
288-
/** Custom X-axis props to merge with defaults */
289-
xAxisProps?: Partial<XAxisProps>;
290-
/** Custom Y-axis props to merge with defaults */
291-
yAxisProps?: Partial<YAxisProps>;
292-
/** Show legend (default true) */
293-
showLegend?: boolean;
294-
/** Enable zoom selection (default true) */
295-
enableZoom?: boolean;
296-
/** Callback when zoom range changes */
297-
onZoomChange?: (range: ZoomRange) => void;
298-
/** Custom tooltip label formatter */
299-
tooltipLabelFormatter?: (label: string, payload: any[]) => string;
300-
/** Use simple inline legend instead of row-based legend */
301-
simpleLegend?: boolean;
302-
/** Additional className for the container */
303-
className?: string;
304-
};
305-

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export type ChartContextValue = {
3333

3434
// Zoom callback (only present when zoom is enabled)
3535
onZoomChange?: (range: ZoomRange) => void;
36+
37+
// Whether the compound legend is shown (disables tooltip when true)
38+
showLegend: boolean;
3639
};
3740

3841
const ChartCompoundContext = createContext<ChartContextValue | null>(null);
@@ -58,6 +61,8 @@ export type ChartProviderProps = {
5861
enableZoom?: boolean;
5962
/** Callback when zoom range changes */
6063
onZoomChange?: (range: ZoomRange) => void;
64+
/** Whether the compound legend is shown (disables tooltip when true) */
65+
showLegend?: boolean;
6166
children: React.ReactNode;
6267
};
6368

@@ -70,6 +75,7 @@ export function ChartProvider({
7075
labelFormatter,
7176
enableZoom = false,
7277
onZoomChange,
78+
showLegend = false,
7379
children,
7480
}: ChartProviderProps) {
7581
const highlight = useHighlightState();
@@ -92,8 +98,9 @@ export function ChartProvider({
9298
highlight,
9399
zoom: enableZoom ? zoomState : null,
94100
onZoomChange: enableZoom ? onZoomChange : undefined,
101+
showLegend,
95102
}),
96-
[config, data, dataKey, dataKeys, state, labelFormatter, highlight, zoomState, enableZoom, onZoomChange]
103+
[config, data, dataKey, dataKeys, state, labelFormatter, highlight, zoomState, enableZoom, onZoomChange, showLegend]
97104
);
98105

99106
return <ChartCompoundContext.Provider value={value}>{children}</ChartCompoundContext.Provider>;

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function ChartLineRenderer({
7878
width,
7979
height,
8080
}: ChartLineRendererProps) {
81-
const { config, data, dataKey, dataKeys, state, highlight } = useChartContext();
81+
const { config, data, dataKey, dataKeys, state, highlight, showLegend } = useChartContext();
8282
const hasNoData = useHasNoData();
8383

8484
// Render loading/error states
@@ -155,11 +155,14 @@ export function ChartLineRenderer({
155155
<CartesianGrid vertical={false} stroke="#272A2E" strokeDasharray="3 3" />
156156
<XAxis {...xAxisConfig} />
157157
<YAxis {...yAxisConfig} />
158-
<ChartTooltip
159-
cursor={false}
160-
content={<ChartTooltipContent indicator="line" />}
161-
labelFormatter={tooltipLabelFormatter}
162-
/>
158+
{/* Hide tooltip when legend is shown - legend displays hover data instead */}
159+
{!showLegend && (
160+
<ChartTooltip
161+
cursor={false}
162+
content={<ChartTooltipContent indicator="line" />}
163+
labelFormatter={tooltipLabelFormatter}
164+
/>
165+
)}
163166
{/* Note: Legend is now rendered by ChartRoot outside the chart container */}
164167
{dataKeys.map((key) => (
165168
<Area
@@ -202,11 +205,14 @@ export function ChartLineRenderer({
202205
<CartesianGrid vertical={false} stroke="#272A2E" strokeDasharray="3 3" />
203206
<XAxis {...xAxisConfig} />
204207
<YAxis {...yAxisConfig} />
205-
<ChartTooltip
206-
cursor={false}
207-
content={<ChartTooltipContent />}
208-
labelFormatter={tooltipLabelFormatter}
209-
/>
208+
{/* Hide tooltip when legend is shown - legend displays hover data instead */}
209+
{!showLegend && (
210+
<ChartTooltip
211+
cursor={false}
212+
content={<ChartTooltipContent />}
213+
labelFormatter={tooltipLabelFormatter}
214+
/>
215+
)}
210216
{/* Note: Legend is now rendered by ChartRoot outside the chart container */}
211217
{dataKeys.map((key) => (
212218
<Line

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function ChartRoot({
7979
labelFormatter={labelFormatter}
8080
enableZoom={enableZoom}
8181
onZoomChange={onZoomChange}
82+
showLegend={showLegend}
8283
>
8384
<ChartRootInner
8485
minHeight={minHeight}

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
@@ -721,7 +721,7 @@ export default function Page() {
721721
{results?.rows && results?.columns && results.rows.length > 0 ? (
722722
<ResizablePanelGroup className="h-full overflow-hidden">
723723
<ResizablePanel id="chart-results">
724-
<div className="h-full bg-charcoal-900 p-2">
724+
<div className="h-full bg-charcoal-900 p-2 overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600">
725725
<Card>
726726
<Card.Content>
727727
<QueryResultsChart

0 commit comments

Comments
 (0)