Skip to content

Commit e58fd00

Browse files
committed
feat: add boxplot
1 parent 82fa561 commit e58fd00

6 files changed

Lines changed: 122 additions & 0 deletions

File tree

__tests__/api.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe("sdk API", () => {
1111
expect(Object.keys(charts)).toEqual([
1212
"area",
1313
"bar",
14+
"boxplot",
1415
"column",
1516
"dual-axes",
1617
"fishbone-diagram",

__tests__/charts/boxplot.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "generate_boxplot_chart",
3+
"description": "Generate a boxplot chart to show data for statistical summaries among different categories, such as, comparing the distribution of data points across categories.",
4+
"inputSchema": {
5+
"type": "object",
6+
"properties": {
7+
"data": {
8+
"type": "array",
9+
"items": {
10+
"type": "object",
11+
"properties": {
12+
"category": {
13+
"type": "string",
14+
"description": "Category of the data point, such as '分类一'."
15+
},
16+
"value": {
17+
"type": "number",
18+
"description": "Value of the data point, such as 10."
19+
},
20+
"group": {
21+
"type": "string",
22+
"description": "Optional group for the data point, used for grouping in the boxplot."
23+
}
24+
},
25+
"required": ["category", "value"]
26+
},
27+
"minItems": 1,
28+
"description": "Data for boxplot chart, such as, [{ category: '分类一', value: 10 }] or [{ category: '分类二', value: 20, group: '组别一' }]."
29+
},
30+
"theme": {
31+
"type": "string",
32+
"enum": ["default", "academy"],
33+
"default": "default",
34+
"description": "Set the theme for the chart, optional, default is 'default'."
35+
},
36+
"width": {
37+
"type": "number",
38+
"default": 600,
39+
"description": "Set the width of chart, default is 600."
40+
},
41+
"height": {
42+
"type": "number",
43+
"default": 400,
44+
"description": "Set the height of chart, default is 400."
45+
},
46+
"title": {
47+
"type": "string",
48+
"default": "",
49+
"description": "Set the title of chart."
50+
},
51+
"axisXTitle": {
52+
"type": "string",
53+
"default": "",
54+
"description": "Set the x-axis title of chart."
55+
},
56+
"axisYTitle": {
57+
"type": "string",
58+
"default": "",
59+
"description": "Set the y-axis title of chart."
60+
}
61+
},
62+
"required": ["data"],
63+
"$schema": "http://json-schema.org/draft-07/schema#"
64+
}
65+
}

__tests__/charts/charts.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ describe("charts schema check", () => {
1212
const schema = actualCharts[chartName].tool;
1313
const rightChart = expectedCharts[chartName];
1414

15+
if (chartName === "boxplot") {
16+
console.log(`Boxplot chart schema: ${JSON.stringify(schema, null, 2)}`);
17+
}
18+
1519
expect(schema).toEqual(rightChart);
1620
});
1721
}

__tests__/charts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { default as area } from "./area.json";
22
export { default as bar } from "./bar.json";
3+
export { default as boxplot } from "./boxplot.json";
34
export { default as column } from "./column.json";
45
export { default as "dual-axes" } from "./dual-axes.json";
56
export { default as "fishbone-diagram" } from "./fishbone-diagram.json";

src/charts/boxplot.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { z } from "zod";
2+
import { zodToJsonSchema } from "../utils";
3+
import {
4+
AxisXTitleSchema,
5+
AxisYTitleSchema,
6+
HeightSchema,
7+
ThemeSchema,
8+
TitleSchema,
9+
WidthSchema,
10+
} from "./base";
11+
12+
const data = z.object({
13+
category: z
14+
.string()
15+
.describe("Category of the data point, such as '分类一'."),
16+
value: z.number().describe("Value of the data point, such as 10."),
17+
group: z
18+
.string()
19+
.optional()
20+
.describe(
21+
"Optional group for the data point, used for grouping in the boxplot.",
22+
),
23+
});
24+
25+
const schema = {
26+
data: z
27+
.array(data)
28+
.describe(
29+
"Data for boxplot chart, such as, [{ category: '分类一', value: 10 }] or [{ category: '分类二', value: 20, group: '组别一' }].",
30+
)
31+
.nonempty({ message: "Boxplot chart data cannot be empty." }),
32+
theme: ThemeSchema,
33+
width: WidthSchema,
34+
height: HeightSchema,
35+
title: TitleSchema,
36+
axisXTitle: AxisXTitleSchema,
37+
axisYTitle: AxisYTitleSchema,
38+
};
39+
40+
const tool = {
41+
name: "generate_boxplot_chart",
42+
description:
43+
"Generate a boxplot chart to show data for statistical summaries among different categories, such as, comparing the distribution of data points across categories.",
44+
inputSchema: zodToJsonSchema(schema),
45+
};
46+
47+
export const boxplot = {
48+
schema,
49+
tool,
50+
};

src/charts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
export { area } from "./area";
55
export { bar } from "./bar";
6+
export { boxplot } from "./boxplot";
67
export { column } from "./column";
78
export { dualAxes as "dual-axes" } from "./dual-axes";
89
export { fishboneDiagram as "fishbone-diagram" } from "./fishbone-diagram";

0 commit comments

Comments
 (0)