-
Notifications
You must be signed in to change notification settings - Fork 389
feat: add generate_spreadsheet #253
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
Merged
Changes from all 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
24 changes: 24 additions & 0 deletions
24
.skills/chart-visualization/references/generate_spreadsheet.md
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,24 @@ | ||
| # generate_spreadsheet — 电子表格/数据透视表 | ||
|
|
||
| ## 功能概述 | ||
| 生成电子表格或数据透视表,用于展示结构化的表格数据。当提供 `rows` 或 `values` 字段时,渲染为数据透视表(交叉表);否则渲染为常规表格。适合展示结构化数据、跨类别比较值以及创建数据汇总。 | ||
|
|
||
| ## 输入字段 | ||
| ### 必填 | ||
| - `data`: array<object>,表格数据数组,每个对象代表一行。键是列名,值可以是字符串、数字、null 或 undefined。例如:`[{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }]`。 | ||
|
|
||
| ### 可选 | ||
| - `rows`: array<string>,数据透视表的行标题字段。当提供 `rows` 或 `values` 时,电子表格将渲染为数据透视表。 | ||
| - `columns`: array<string>,列标题字段,用于指定列的顺序。对于常规表格,这决定列的顺序;对于数据透视表,用于列分组。 | ||
| - `values`: array<string>,数据透视表的值字段。当提供 `rows` 或 `values` 时,电子表格将渲染为数据透视表。 | ||
| - `theme`: string,默认 `default`,可选 `default`/`dark`。 | ||
| - `width`: number,默认 `600`。 | ||
| - `height`: number,默认 `400`。 | ||
|
|
||
| ## 使用建议 | ||
| - 对于常规表格,只需提供 `data` 和可选的 `columns` 来控制列的顺序。 | ||
| - 对于数据透视表(交叉表),提供 `rows` 用于行分组,`columns` 用于列分组,`values` 用于聚合的值字段。 | ||
| - 确保数据中的字段名与 `rows`、`columns`、`values` 中指定的字段名一致。 | ||
|
|
||
| ## 返回结果 | ||
| - 返回电子表格/数据透视表图片 URL,并附 `_meta.spec` 供后续编辑。 |
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 |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ describe("sdk API", () => { | |
| "violin", | ||
| "waterfall", | ||
| "word-cloud", | ||
| "spreadsheet", | ||
| ]); | ||
| }); | ||
|
|
||
|
|
||
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,76 @@ | ||
| { | ||
| "name": "generate_spreadsheet", | ||
| "description": "Generate a spreadsheet or pivot table for displaying tabular data. When 'rows' or 'values' fields are provided, it renders as a pivot table (cross-tabulation); otherwise, it renders as a regular table. Useful for displaying structured data, comparing values across categories, and creating data summaries.", | ||
| "inputSchema": { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "type": "object", | ||
| "properties": { | ||
| "data": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "additionalProperties": { | ||
| "anyOf": [ | ||
| { | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "type": "number" | ||
| }, | ||
| { | ||
| "type": "null" | ||
| }, | ||
| { | ||
| "not": {} | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "minItems": 1, | ||
| "description": "Data for spreadsheet, an array of objects where each object represents a row. Keys are column names and values can be string, number, null, or undefined. Such as, [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }]." | ||
| }, | ||
| "rows": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| }, | ||
| "description": "Row header fields for pivot table. When 'rows' or 'values' is provided, the spreadsheet will be rendered as a pivot table." | ||
| }, | ||
| "columns": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| }, | ||
| "description": "Column header fields, used to specify the order of columns. For regular tables, this determines column order; for pivot tables, this is used for column grouping." | ||
| }, | ||
| "values": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "string" | ||
| }, | ||
| "description": "Value fields for pivot table. When 'rows' or 'values' is provided, the spreadsheet will be rendered as a pivot table." | ||
| }, | ||
| "theme": { | ||
| "type": "string", | ||
| "enum": ["default", "dark"], | ||
| "default": "default", | ||
| "description": "Set the theme for the spreadsheet, optional, default is 'default'." | ||
| }, | ||
| "width": { | ||
| "type": "number", | ||
| "default": 600, | ||
| "description": "Set the width of chart, default is 600." | ||
| }, | ||
| "height": { | ||
| "type": "number", | ||
| "default": 400, | ||
| "description": "Set the height of chart, default is 400." | ||
| } | ||
| }, | ||
| "required": ["data"] | ||
| }, | ||
| "annotations": { | ||
| "title": "Generate Spreadsheet", | ||
| "readOnlyHint": 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
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,66 @@ | ||
| import { z } from "zod"; | ||
| import { zodToJsonSchema } from "../utils"; | ||
| import { HeightSchema, WidthSchema } from "./base"; | ||
|
|
||
| // Spreadsheet data schema - flexible record type | ||
| const data = z.record( | ||
| z.string(), | ||
| z.union([z.string(), z.number(), z.null(), z.undefined()]), | ||
| ); | ||
|
Alexzjt marked this conversation as resolved.
|
||
|
|
||
| // Spreadsheet theme schema | ||
| const SpreadsheetThemeSchema = z | ||
| .enum(["default", "dark"]) | ||
| .optional() | ||
| .default("default") | ||
| .describe( | ||
| "Set the theme for the spreadsheet, optional, default is 'default'.", | ||
| ); | ||
|
|
||
| // Spreadsheet input schema | ||
| const schema = { | ||
| data: z | ||
| .array(data) | ||
| .describe( | ||
| "Data for spreadsheet, an array of objects where each object represents a row. Keys are column names and values can be string, number, null, or undefined. Such as, [{ name: 'John', age: 30 }, { name: 'Jane', age: 25 }].", | ||
| ) | ||
|
Alexzjt marked this conversation as resolved.
|
||
| .nonempty({ message: "Spreadsheet data cannot be empty." }), | ||
| rows: z | ||
| .array(z.string()) | ||
| .optional() | ||
| .describe( | ||
| "Row header fields for pivot table. When 'rows' or 'values' is provided, the spreadsheet will be rendered as a pivot table.", | ||
| ), | ||
| columns: z | ||
| .array(z.string()) | ||
| .optional() | ||
| .describe( | ||
| "Column header fields, used to specify the order of columns. For regular tables, this determines column order; for pivot tables, this is used for column grouping.", | ||
| ), | ||
| values: z | ||
| .array(z.string()) | ||
| .optional() | ||
| .describe( | ||
| "Value fields for pivot table. When 'rows' or 'values' is provided, the spreadsheet will be rendered as a pivot table.", | ||
| ), | ||
| theme: SpreadsheetThemeSchema, | ||
| width: WidthSchema, | ||
| height: HeightSchema, | ||
| }; | ||
|
|
||
| // Spreadsheet tool descriptor | ||
| const tool = { | ||
| name: "generate_spreadsheet", | ||
| description: | ||
| "Generate a spreadsheet or pivot table for displaying tabular data. When 'rows' or 'values' fields are provided, it renders as a pivot table (cross-tabulation); otherwise, it renders as a regular table. Useful for displaying structured data, comparing values across categories, and creating data summaries.", | ||
| inputSchema: zodToJsonSchema(schema), | ||
| annotations: { | ||
| title: "Generate Spreadsheet", | ||
| readOnlyHint: true, | ||
| }, | ||
| }; | ||
|
|
||
| export const spreadsheet = { | ||
| schema, | ||
| tool, | ||
| }; | ||
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.