-
Notifications
You must be signed in to change notification settings - Fork 31
feat(mcp-function) : add generateAreaChartTool to create area chart
#29
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
Open
joeycyhuang
wants to merge
4
commits into
hustcc:main
Choose a base branch
from
joeycyhuang:feature/area-chart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { generateAreaChartTool } from "../../src/tools/area"; | ||
| import "../utils/matcher"; | ||
|
|
||
| describe("Area Chart Tool", () => { | ||
| it("should generate a basic area chart", async () => { | ||
| const result = await generateAreaChartTool.run({ | ||
| data: [ | ||
| { time: "2015", value: 23 }, | ||
| { time: "2016", value: 32 }, | ||
| { time: "2017", value: 28 }, | ||
| { time: "2018", value: 45 }, | ||
| { time: "2019", value: 38 }, | ||
| { time: "2020", value: 52 }, | ||
| ], | ||
| title: "Basic Area Chart", | ||
| width: 600, | ||
| height: 400, | ||
| }); | ||
|
|
||
| await expect(result).toImageEqual("area-basic"); | ||
| }); | ||
|
|
||
| it("should generate a stacked area chart", async () => { | ||
| const result = await generateAreaChartTool.run({ | ||
| data: [ | ||
| { group: "Series A", time: "2015", value: 23 }, | ||
| { group: "Series A", time: "2016", value: 32 }, | ||
| { group: "Series A", time: "2017", value: 28 }, | ||
| { group: "Series B", time: "2015", value: 18 }, | ||
| { group: "Series B", time: "2016", value: 25 }, | ||
| { group: "Series B", time: "2017", value: 22 }, | ||
| ], | ||
| title: "Stacked Area Chart", | ||
| stack: true, | ||
| width: 600, | ||
| height: 400, | ||
| }); | ||
|
|
||
| await expect(result).toImageEqual("area-stacked"); | ||
| }); | ||
|
|
||
| it("should generate an area chart with custom styling", async () => { | ||
| const result = await generateAreaChartTool.run({ | ||
| data: [ | ||
| { time: "Q1", value: 100 }, | ||
| { time: "Q2", value: 150 }, | ||
| { time: "Q3", value: 120 }, | ||
| { time: "Q4", value: 180 }, | ||
| ], | ||
| title: "Custom Styled Area Chart", | ||
| width: 800, | ||
| height: 500, | ||
| theme: "dark", | ||
| style: { | ||
| backgroundColor: "#1a1a1a", | ||
| palette: ["#ff6b6b", "#4ecdc4", "#45b7d1"], | ||
| }, | ||
| }); | ||
|
|
||
| await expect(result).toImageEqual("area-custom"); | ||
| }); | ||
|
|
||
| it("should generate area chart with smooth curves", async () => { | ||
| const result = await generateAreaChartTool.run({ | ||
| data: [ | ||
| { time: "Jan", value: 10 }, | ||
| { time: "Feb", value: 25 }, | ||
| { time: "Mar", value: 15 }, | ||
| { time: "Apr", value: 35 }, | ||
| { time: "May", value: 20 }, | ||
| { time: "Jun", value: 40 }, | ||
| ], | ||
| title: "Smooth Area Chart", | ||
| smooth: true, | ||
| width: 600, | ||
| height: 400, | ||
| }); | ||
|
|
||
| await expect(result).toImageEqual("area-smooth"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { z } from "zod"; | ||
| import { generateLineChartTool } from "./line"; | ||
|
|
||
| // Extends generateLineChartTool implementation since area charts are line charts with area fill enabled | ||
| export const generateAreaChartTool = { | ||
| ...generateLineChartTool, | ||
| name: "generate_area_chart", | ||
| description: | ||
| "Generate an area chart to show data trends under continuous independent variables and observe the overall data trend, such as, displacement = velocity (average or instantaneous) × time: s = v × t. If the x-axis is time (t) and the y-axis is velocity (v) at each moment, an area chart allows you to observe the trend of velocity over time and infer the distance traveled by the area's size.", | ||
| inputSchema: generateLineChartTool.inputSchema.extend({ | ||
| data: z | ||
| .array( | ||
| z.object({ | ||
| group: z | ||
| .string() | ||
| .optional() | ||
| .describe( | ||
| "Group name for multiple series, required when stack is enabled", | ||
| ), | ||
| time: z.string(), | ||
| value: z.number(), | ||
| }), | ||
| ) | ||
| .describe( | ||
| "Data for area chart, such as, [{ time: '2015', value: 23 }, { time: '2016', value: 32 }]. For multiple series: [{ group: 'Series A', time: '2015', value: 23 }, { group: 'Series B', time: '2015', value: 18 }].", | ||
| ) | ||
| .nonempty({ message: "Area chart data cannot be empty." }), | ||
| }), | ||
| run: (params: { | ||
| axisXTitle?: string; | ||
| axisYTitle?: string; | ||
| data: Array<{ time: string; value: number; group?: string }>; | ||
| height: number; | ||
| showArea?: boolean; | ||
| showSymbol?: boolean; | ||
| smooth?: boolean; | ||
| stack?: boolean; | ||
| theme?: "default" | "dark"; | ||
| title?: string; | ||
| width: number; | ||
| outputType?: "png" | "svg" | "option"; | ||
| }) => { | ||
| // Force showArea to true for area chart | ||
| return generateLineChartTool.run({ | ||
| ...params, | ||
| showArea: true, | ||
| }); | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.