Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add y-axis label support to chart rendering #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions financial-data-analyst/app/api/finance/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const tools: ToolSchema[] = [
footer: { type: "string" as const },
totalLabel: { type: "string" as const },
xAxisKey: { type: "string" as const },
yAxisKey: { type: "string" as const },
},
required: ["title", "description"],
},
Expand Down Expand Up @@ -270,6 +271,7 @@ For Time-Series (Line/Bar/Area):
],
config: {
xAxisKey: "period",
yAxisKey: "sales",
title: "Quarterly Revenue",
description: "Revenue growth over time"
},
Expand All @@ -286,6 +288,7 @@ For Comparisons (MultiBar):
],
config: {
xAxisKey: "category",
yAxisKey: "sales",
title: "Product Performance",
description: "Sales vs Costs by Product"
},
Expand Down
45 changes: 45 additions & 0 deletions financial-data-analyst/components/ChartRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Pie,
PieChart,
XAxis,
YAxis
} from "recharts";
import {
ChartContainer,
Expand Down Expand Up @@ -54,6 +55,17 @@ function BarChartComponent({ data }: { data: ChartData }) {
: value;
}}
/>
<YAxis
dataKey={data.config.yAxisKey}
tickLine={false}
axisLine={false}
tickMargin={8}
tickFormatter={(value) => {
return value.length > 20
? `${value.substring(0, 17)}...`
: value;
}}
/>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent hideLabel />}
Expand Down Expand Up @@ -110,6 +122,17 @@ function MultiBarChartComponent({ data }: { data: ChartData }) {
: value;
}}
/>
<YAxis
dataKey={data.config.yAxisKey}
tickLine={false}
axisLine={false}
tickMargin={8}
tickFormatter={(value) => {
return value.length > 20
? `${value.substring(0, 17)}...`
: value;
}}
/>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent indicator="dashed" />}
Expand Down Expand Up @@ -176,6 +199,17 @@ function LineChartComponent({ data }: { data: ChartData }) {
: value;
}}
/>
<YAxis
dataKey={data.config.yAxisKey}
tickLine={false}
axisLine={false}
tickMargin={8}
tickFormatter={(value) => {
return value.length > 20
? `${value.substring(0, 17)}...`
: value;
}}
/>
<ChartTooltip
cursor={false}
content={<ChartTooltipContent hideLabel />}
Expand Down Expand Up @@ -342,6 +376,17 @@ function AreaChartComponent({
: value;
}}
/>
<YAxis
dataKey={data.config.yAxisKey}
tickLine={false}
axisLine={false}
tickMargin={8}
tickFormatter={(value) => {
return value.length > 20
? `${value.substring(0, 17)}...`
: value;
}}
/>
<ChartTooltip
cursor={false}
content={
Expand Down
1 change: 1 addition & 0 deletions financial-data-analyst/types/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ChartData {
footer?: string;
totalLabel?: string;
xAxisKey?: string;
yAxisKey?: string;
};
data: Array<Record<string, any>>;
chartConfig: ChartConfig;
Expand Down