From 3044a714eebd8cb152cd19a6046954bfe0b43ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=81=87=E8=A7=81=E5=90=8C=E5=AD=A6?= <1875694521@qq.com> Date: Wed, 13 Aug 2025 11:13:51 +0800 Subject: [PATCH 1/4] feat: add all chart outputType schame --- __tests__/schema/bar.json | 6 ++++++ __tests__/schema/boxplot.json | 6 ++++++ __tests__/schema/candlestick.json | 6 ++++++ __tests__/schema/funnel.json | 6 ++++++ __tests__/schema/gauge.json | 6 ++++++ __tests__/schema/graph.json | 6 ++++++ __tests__/schema/heatmap.json | 6 ++++++ __tests__/schema/line.json | 6 ++++++ __tests__/schema/parallel.json | 6 ++++++ __tests__/schema/pie.json | 6 ++++++ __tests__/schema/radar.json | 6 ++++++ __tests__/schema/sankey.json | 6 ++++++ __tests__/schema/scatter.json | 6 ++++++ __tests__/schema/sunburst.json | 6 ++++++ __tests__/schema/tree.json | 6 ++++++ __tests__/schema/treemap.json | 6 ++++++ src/tools/bar.ts | 6 +++++- src/tools/boxplot.ts | 17 ++++++++++++++--- src/tools/candlestick.ts | 15 +++++++++++++-- src/tools/funnel.ts | 7 +++++-- src/tools/gauge.ts | 16 ++++++++++++++-- src/tools/graph.ts | 15 +++++++++++++-- src/tools/heatmap.ts | 17 ++++++++++++++--- src/tools/line.ts | 6 +++++- src/tools/parallel.ts | 8 ++++++-- src/tools/pie.ts | 15 +++++++++++++-- src/tools/radar.ts | 7 +++++-- src/tools/sankey.ts | 15 +++++++++++++-- src/tools/scatter.ts | 17 ++++++++++++++--- src/tools/sunburst.ts | 7 +++++-- src/tools/tree.ts | 6 +++++- src/tools/treemap.ts | 7 +++++-- src/utils/schema.ts | 8 ++++++++ 33 files changed, 253 insertions(+), 32 deletions(-) diff --git a/__tests__/schema/bar.json b/__tests__/schema/bar.json index 56e043a..f5bf0c1 100644 --- a/__tests__/schema/bar.json +++ b/__tests__/schema/bar.json @@ -68,6 +68,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/boxplot.json b/__tests__/schema/boxplot.json index cf61fa9..32a7a87 100644 --- a/__tests__/schema/boxplot.json +++ b/__tests__/schema/boxplot.json @@ -58,6 +58,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/candlestick.json b/__tests__/schema/candlestick.json index cbcd950..aaba6d4 100644 --- a/__tests__/schema/candlestick.json +++ b/__tests__/schema/candlestick.json @@ -65,6 +65,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/funnel.json b/__tests__/schema/funnel.json index abd2e31..2b8bca0 100644 --- a/__tests__/schema/funnel.json +++ b/__tests__/schema/funnel.json @@ -44,6 +44,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/gauge.json b/__tests__/schema/gauge.json index 9d50d8c..3127d35 100644 --- a/__tests__/schema/gauge.json +++ b/__tests__/schema/gauge.json @@ -54,6 +54,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/graph.json b/__tests__/schema/graph.json index 9ad0374..960bcce 100644 --- a/__tests__/schema/graph.json +++ b/__tests__/schema/graph.json @@ -88,6 +88,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/heatmap.json b/__tests__/schema/heatmap.json index 411e820..37c0bb8 100644 --- a/__tests__/schema/heatmap.json +++ b/__tests__/schema/heatmap.json @@ -58,6 +58,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/line.json b/__tests__/schema/line.json index 19faba4..b0722fe 100644 --- a/__tests__/schema/line.json +++ b/__tests__/schema/line.json @@ -76,6 +76,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/parallel.json b/__tests__/schema/parallel.json index b2806a9..842841e 100644 --- a/__tests__/schema/parallel.json +++ b/__tests__/schema/parallel.json @@ -55,6 +55,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data", "dimensions"], diff --git a/__tests__/schema/pie.json b/__tests__/schema/pie.json index 3b1e04d..9554327 100644 --- a/__tests__/schema/pie.json +++ b/__tests__/schema/pie.json @@ -49,6 +49,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/radar.json b/__tests__/schema/radar.json index 736ac19..7c69511 100644 --- a/__tests__/schema/radar.json +++ b/__tests__/schema/radar.json @@ -48,6 +48,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/sankey.json b/__tests__/schema/sankey.json index a63e936..a1dc0d1 100644 --- a/__tests__/schema/sankey.json +++ b/__tests__/schema/sankey.json @@ -54,6 +54,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/scatter.json b/__tests__/schema/scatter.json index 2b8a93f..9b01856 100644 --- a/__tests__/schema/scatter.json +++ b/__tests__/schema/scatter.json @@ -54,6 +54,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/sunburst.json b/__tests__/schema/sunburst.json index ec81bc4..b357788 100644 --- a/__tests__/schema/sunburst.json +++ b/__tests__/schema/sunburst.json @@ -51,6 +51,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/tree.json b/__tests__/schema/tree.json index 1189e8b..a501eb3 100644 --- a/__tests__/schema/tree.json +++ b/__tests__/schema/tree.json @@ -77,6 +77,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/__tests__/schema/treemap.json b/__tests__/schema/treemap.json index d358bcf..c4aad9d 100644 --- a/__tests__/schema/treemap.json +++ b/__tests__/schema/treemap.json @@ -51,6 +51,12 @@ "exclusiveMinimum": 0, "default": 800, "description": "Set the width of the chart, default is 800px." + }, + "outputType": { + "type": "string", + "enum": ["png", "svg", "option"], + "default": "png", + "description": "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option." } }, "required": ["data"], diff --git a/src/tools/bar.ts b/src/tools/bar.ts index cf92b67..824c2cf 100644 --- a/src/tools/bar.ts +++ b/src/tools/bar.ts @@ -5,6 +5,7 @@ import { AxisXTitleSchema, AxisYTitleSchema, HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -54,6 +55,7 @@ export const generateBarChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { axisXTitle?: string; @@ -65,6 +67,7 @@ export const generateBarChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { const { axisXTitle, @@ -76,6 +79,7 @@ export const generateBarChartTool = { theme, title, width, + outputType, } = params; // Check if data has group field for multiple series @@ -169,7 +173,7 @@ export const generateBarChartTool = { width, height, theme, - "png", + outputType, "generate_bar_chart", ); }, diff --git a/src/tools/boxplot.ts b/src/tools/boxplot.ts index 06aaeff..b7c08a7 100644 --- a/src/tools/boxplot.ts +++ b/src/tools/boxplot.ts @@ -5,6 +5,7 @@ import { AxisXTitleSchema, AxisYTitleSchema, HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -41,6 +42,7 @@ export const generateBoxplotChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { axisXTitle?: string; @@ -50,9 +52,18 @@ export const generateBoxplotChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { axisXTitle, axisYTitle, data, height, theme, title, width } = - params; + const { + axisXTitle, + axisYTitle, + data, + height, + theme, + title, + width, + outputType, + } = params; // Group data by category and optional group const hasGroups = data.some((item) => item.group); @@ -186,7 +197,7 @@ export const generateBoxplotChartTool = { width, height, theme, - "png", + outputType, "generate_boxplot_chart", ); }, diff --git a/src/tools/candlestick.ts b/src/tools/candlestick.ts index 6d1896a..f54f51a 100644 --- a/src/tools/candlestick.ts +++ b/src/tools/candlestick.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -40,6 +41,7 @@ export const generateCandlestickChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array<{ @@ -55,8 +57,17 @@ export const generateCandlestickChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, showVolume = false, theme, title, width } = params; + const { + data, + height, + showVolume = false, + theme, + title, + width, + outputType, + } = params; // Sort data by date const sortedData = [...data].sort( @@ -216,7 +227,7 @@ export const generateCandlestickChartTool = { width, height, theme, - "png", + outputType, "generate_candlestick_chart", ); }, diff --git a/src/tools/funnel.ts b/src/tools/funnel.ts index 81050e8..7a7656c 100644 --- a/src/tools/funnel.ts +++ b/src/tools/funnel.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -31,6 +32,7 @@ export const generateFunnelChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array<{ category: string; value: number }>; @@ -38,8 +40,9 @@ export const generateFunnelChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, theme, title, width } = params; + const { data, height, theme, title, width, outputType } = params; // Transform data for ECharts funnel chart const funnelData = data.map((item) => ({ @@ -108,7 +111,7 @@ export const generateFunnelChartTool = { width, height, theme, - "png", + outputType, "generate_funnel_chart", ); }, diff --git a/src/tools/gauge.ts b/src/tools/gauge.ts index c5b2723..e782243 100644 --- a/src/tools/gauge.ts +++ b/src/tools/gauge.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -39,6 +40,7 @@ export const generateGaugeChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array<{ name: string; value: number }>; @@ -48,8 +50,18 @@ export const generateGaugeChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, max = 100, min = 0, theme, title, width } = params; + const { + data, + height, + max = 100, + min = 0, + theme, + title, + width, + outputType, + } = params; // For multiple gauges, arrange them horizontally const series: Array = data.map((item, index) => { @@ -140,7 +152,7 @@ export const generateGaugeChartTool = { width, height, theme, - "png", + outputType, "generate_gauge_chart", ); }, diff --git a/src/tools/graph.ts b/src/tools/graph.ts index b7ca3d2..80d1b3f 100644 --- a/src/tools/graph.ts +++ b/src/tools/graph.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -58,6 +59,7 @@ export const generateGraphChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: { @@ -74,8 +76,17 @@ export const generateGraphChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, layout = "force", theme, title, width } = params; + const { + data, + height, + layout = "force", + theme, + title, + width, + outputType, + } = params; // Validate that all edge nodes exist in nodes array const nodeIds = new Set(data.nodes.map((node) => node.id)); @@ -168,7 +179,7 @@ export const generateGraphChartTool = { width, height, theme, - "png", + outputType, "generate_graph_chart", ); }, diff --git a/src/tools/heatmap.ts b/src/tools/heatmap.ts index 11741bf..21bb023 100644 --- a/src/tools/heatmap.ts +++ b/src/tools/heatmap.ts @@ -5,6 +5,7 @@ import { AxisXTitleSchema, AxisYTitleSchema, HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -38,6 +39,7 @@ export const generateHeatmapChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { axisXTitle?: string; @@ -47,9 +49,18 @@ export const generateHeatmapChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { axisXTitle, axisYTitle, data, height, theme, title, width } = - params; + const { + axisXTitle, + axisYTitle, + data, + height, + theme, + title, + width, + outputType, + } = params; // Extract unique x and y values const xValues = Array.from(new Set(data.map((item) => item.x))).sort(); @@ -154,7 +165,7 @@ export const generateHeatmapChartTool = { width, height, theme, - "png", + outputType, "generate_heatmap_chart", ); }, diff --git a/src/tools/line.ts b/src/tools/line.ts index c2959c5..8076a2f 100644 --- a/src/tools/line.ts +++ b/src/tools/line.ts @@ -5,6 +5,7 @@ import { AxisXTitleSchema, AxisYTitleSchema, HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -59,6 +60,7 @@ export const generateLineChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: (params: { axisXTitle?: string; @@ -72,6 +74,7 @@ export const generateLineChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { const { axisXTitle, @@ -85,6 +88,7 @@ export const generateLineChartTool = { theme, title, width, + outputType, } = params; // Check if data has group field for multiple series @@ -186,7 +190,7 @@ export const generateLineChartTool = { width, height, theme, - "png", + outputType, "generate_line_chart", ); }, diff --git a/src/tools/parallel.ts b/src/tools/parallel.ts index e37d387..70e34b8 100644 --- a/src/tools/parallel.ts +++ b/src/tools/parallel.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -35,6 +36,7 @@ export const generateParallelChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array<{ name: string; values: number[] }>; @@ -43,8 +45,10 @@ export const generateParallelChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, dimensions, height, theme, title, width } = params; + const { data, dimensions, height, theme, title, width, outputType } = + params; // Calculate min/max for each dimension const parallelAxis = dimensions.map((dim, index) => { @@ -138,7 +142,7 @@ export const generateParallelChartTool = { width, height, theme, - "png", + outputType, "generate_parallel_chart", ); }, diff --git a/src/tools/pie.ts b/src/tools/pie.ts index d23d6f8..fb481aa 100644 --- a/src/tools/pie.ts +++ b/src/tools/pie.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -37,6 +38,7 @@ export const generatePieChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array<{ category: string; value: number }>; @@ -45,8 +47,17 @@ export const generatePieChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, innerRadius = 0, theme, title, width } = params; + const { + data, + height, + innerRadius = 0, + theme, + title, + width, + outputType, + } = params; // Transform data for ECharts const pieData = data.map((item) => ({ @@ -91,7 +102,7 @@ export const generatePieChartTool = { width, height, theme, - "png", + outputType, "generate_pie_chart", ); }, diff --git a/src/tools/radar.ts b/src/tools/radar.ts index 089781e..7267013 100644 --- a/src/tools/radar.ts +++ b/src/tools/radar.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -35,6 +36,7 @@ export const generateRadarChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array<{ name: string; value: number; group?: string }>; @@ -42,8 +44,9 @@ export const generateRadarChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, theme, title, width } = params; + const { data, height, theme, title, width, outputType } = params; // Check if data has group field for multiple series const hasGroups = data.some((item) => item.group); @@ -167,7 +170,7 @@ export const generateRadarChartTool = { width, height, theme, - "png", + outputType, "generate_radar_chart", ); }, diff --git a/src/tools/sankey.ts b/src/tools/sankey.ts index 2dca93f..0acf2e1 100644 --- a/src/tools/sankey.ts +++ b/src/tools/sankey.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -39,6 +40,7 @@ export const generateSankeyChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array<{ source: string; target: string; value: number }>; @@ -47,8 +49,17 @@ export const generateSankeyChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, nodeAlign = "justify", theme, title, width } = params; + const { + data, + height, + nodeAlign = "justify", + theme, + title, + width, + outputType, + } = params; // Extract unique nodes from data const nodeSet = new Set(); @@ -108,7 +119,7 @@ export const generateSankeyChartTool = { width, height, theme, - "png", + outputType, "generate_sankey_chart", ); }, diff --git a/src/tools/scatter.ts b/src/tools/scatter.ts index 941e8ab..cbc1135 100644 --- a/src/tools/scatter.ts +++ b/src/tools/scatter.ts @@ -5,6 +5,7 @@ import { AxisXTitleSchema, AxisYTitleSchema, HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -33,6 +34,7 @@ export const generateScatterChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { axisXTitle?: string; @@ -42,9 +44,18 @@ export const generateScatterChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { axisXTitle, axisYTitle, data, height, theme, title, width } = - params; + const { + axisXTitle, + axisYTitle, + data, + height, + theme, + title, + width, + outputType, + } = params; // Transform data for ECharts scatter chart const scatterData = data.map((item) => [item.x, item.y]); @@ -91,7 +102,7 @@ export const generateScatterChartTool = { width, height, theme, - "png", + outputType, "generate_scatter_chart", ); }, diff --git a/src/tools/sunburst.ts b/src/tools/sunburst.ts index fff48ab..e79d29b 100644 --- a/src/tools/sunburst.ts +++ b/src/tools/sunburst.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -42,6 +43,7 @@ export const generateSunburstChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array; @@ -49,8 +51,9 @@ export const generateSunburstChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, theme, title, width } = params; + const { data, height, theme, title, width, outputType } = params; const series: Array = [ { @@ -124,7 +127,7 @@ export const generateSunburstChartTool = { width, height, theme, - "png", + outputType, "generate_sunburst_chart", ); }, diff --git a/src/tools/tree.ts b/src/tools/tree.ts index 2a6d248..db1f1ce 100644 --- a/src/tools/tree.ts +++ b/src/tools/tree.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -51,6 +52,7 @@ export const generateTreeChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: TreeDataType; @@ -60,6 +62,7 @@ export const generateTreeChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { const { data, @@ -69,6 +72,7 @@ export const generateTreeChartTool = { theme, title, width, + outputType, } = params; const series: Array = [ @@ -160,7 +164,7 @@ export const generateTreeChartTool = { width, height, theme, - "png", + outputType, "generate_tree_chart", ); }, diff --git a/src/tools/treemap.ts b/src/tools/treemap.ts index 44f8e21..d7f9037 100644 --- a/src/tools/treemap.ts +++ b/src/tools/treemap.ts @@ -3,6 +3,7 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; import { HeightSchema, + OutputTypeSchema, ThemeSchema, TitleSchema, WidthSchema, @@ -42,6 +43,7 @@ export const generateTreemapChartTool = { theme: ThemeSchema, title: TitleSchema, width: WidthSchema, + outputType: OutputTypeSchema, }), run: async (params: { data: Array; @@ -49,8 +51,9 @@ export const generateTreemapChartTool = { theme?: "default" | "dark"; title?: string; width: number; + outputType?: "png" | "svg" | "option"; }) => { - const { data, height, theme, title, width } = params; + const { data, height, theme, title, width, outputType } = params; const series: Array = [ { @@ -125,7 +128,7 @@ export const generateTreemapChartTool = { width, height, theme, - "png", + outputType, "generate_treemap_chart", ); }, diff --git a/src/utils/schema.ts b/src/utils/schema.ts index fdfd0d3..3052829 100644 --- a/src/utils/schema.ts +++ b/src/utils/schema.ts @@ -27,6 +27,14 @@ export const ThemeSchema = z .default("default") .describe("Set the theme for the chart, optional, default is 'default'."); +export const OutputTypeSchema = z + .enum(["png", "svg", "option"]) + .optional() + .default("png") + .describe( + "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option.", + ); + export const TitleSchema = z .string() .optional() From 8e43f23e732d1ec5e6c813258422f787108330da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=81=87=E8=A7=81=E5=90=8C=E5=AD=A6?= <1875694521@qq.com> Date: Wed, 13 Aug 2025 15:44:00 +0800 Subject: [PATCH 2/4] feat: update code schema --- src/tools/echarts.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/tools/echarts.ts b/src/tools/echarts.ts index bfaaf90..2854b0c 100644 --- a/src/tools/echarts.ts +++ b/src/tools/echarts.ts @@ -1,5 +1,6 @@ import { z } from "zod"; import { generateChartImage } from "../utils"; +import { OutputTypeSchema } from "../utils/schema"; function isValidEChartsOption(option: string): boolean { try { @@ -89,13 +90,7 @@ ATTENTION: A valid ECharts option must be a valid JSON string, and cannot be emp .describe("ECharts theme, optional. Default is 'default'.") .optional() .default("default"), - outputType: z - .enum(["png", "svg", "option"]) - .describe( - "The output type of the diagram. Can be 'png', 'svg' or 'option'. Default is 'png', 'png' will return the rendered PNG image, 'svg' will return the rendered SVG string, and 'option' will return the valid ECharts option.", - ) - .optional() - .default("png"), + outputType: OutputTypeSchema, }), run: async (params: { echartsOption: string; From 0ef1080e08e6c876456a8ad66ed252d3a392c851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=81=87=E8=A7=81=E5=90=8C=E5=AD=A6?= <1875694521@qq.com> Date: Wed, 13 Aug 2025 15:47:42 +0800 Subject: [PATCH 3/4] chore: update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dba0cdd..7f9e178 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ npm run start - [2niuhe](https://github.com/2niuhe): Support MCP with SSE and Streaming HTTP. [#17](https://github.com/hustcc/mcp-echarts/issues/17) - [susuperli](https://github.com/susuperli): Use `MinIO` to save the chart image base64 and return the url. [#10](https://github.com/hustcc/mcp-echarts/issues/10) - [BQXBQX](https://github.com/BQXBQX): Use `@napi-rs/canvas` instead node-canvas. [#3](https://github.com/hustcc/mcp-echarts/issues/3) +- [Meet-student](https://github.com/Meet-student): Add `outputType` schema for all chart tools. [#24](https://github.com/hustcc/mcp-echarts/issues/24) - [hustcc](https://github.com/hustcc): Initial the repo. From 01cb99517a2992de8b30c135080fb5e12505f818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=81=87=E8=A7=81=E5=90=8C=E5=AD=A6?= <1875694521@qq.com> Date: Wed, 13 Aug 2025 15:48:52 +0800 Subject: [PATCH 4/4] chore: bump version 0.6.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 76d6aea..b9abb20 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "mcp-echarts", "description": "❤️ Generate visual charts using Apache ECharts with AI MCP dynamically.", - "version": "0.5.0", + "version": "0.6.0", "main": "build/index.js", "scripts": { "test": "vitest",