Skip to content

Commit 3ec6d08

Browse files
authored
feat: add theme in chart schema (#57)
1 parent 18a3e8a commit 3ec6d08

31 files changed

+138
-8
lines changed

__tests__/charts/area.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
"default": false,
2525
"description": "Whether stacking is enabled. When enabled, area charts require a 'group' field in the data."
2626
},
27+
"theme": {
28+
"default": "default",
29+
"description": "Set the theme for the chart, optional, default is 'default'.",
30+
"enum": ["default", "academy"],
31+
"type": "string"
32+
},
2733
"width": {
2834
"type": "number",
2935
"description": "Set the width of chart, default is 600.",

__tests__/charts/bar.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
"default": true,
3030
"description": "Whether stacking is enabled. When enabled, bar charts require a 'group' field in the data. When `stack` is true, `group` should be false."
3131
},
32+
"theme": {
33+
"default": "default",
34+
"description": "Set the theme for the chart, optional, default is 'default'.",
35+
"enum": ["default", "academy"],
36+
"type": "string"
37+
},
3238
"width": {
3339
"type": "number",
3440
"description": "Set the width of chart, default is 600.",

__tests__/charts/column.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
"default": false,
3030
"description": "Whether stacking is enabled. When enabled, column charts require a 'group' field in the data. When `stack` is true, `group` should be false."
3131
},
32+
"theme": {
33+
"default": "default",
34+
"description": "Set the theme for the chart, optional, default is 'default'.",
35+
"enum": ["default", "academy"],
36+
"type": "string"
37+
},
3238
"width": {
3339
"type": "number",
3440
"description": "Set the width of chart, default is 600.",

__tests__/charts/dual-axes.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
"$schema": "http://json-schema.org/draft-07/schema#",
66
"type": "object",
77
"properties": {
8+
"theme": {
9+
"default": "default",
10+
"description": "Set the theme for the chart, optional, default is 'default'.",
11+
"enum": ["default", "academy"],
12+
"type": "string"
13+
},
814
"width": {
915
"type": "number",
1016
"description": "Set the width of chart, default is 600.",

__tests__/charts/fishbone-diagram.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
"required": ["name"],
3030
"description": "Data for fishbone diagram chart, such as, { name: 'main topic', children: [{ name: 'topic 1', children: [{ name: 'subtopic 1-1' }] }."
3131
},
32+
"theme": {
33+
"default": "default",
34+
"description": "Set the theme for the chart, optional, default is 'default'.",
35+
"enum": ["default", "academy"],
36+
"type": "string"
37+
},
3238
"width": {
3339
"type": "number",
3440
"description": "Set the width of chart, default is 600.",

__tests__/charts/flow-diagram.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
"required": ["nodes", "edges"],
3636
"description": "Data for flow diagram chart, such as, { nodes: [{ name: 'node1' }, { name: 'node2' }], edges: [{ source: 'node1', target: 'node2', name: 'edge1' }] }."
3737
},
38+
"theme": {
39+
"default": "default",
40+
"description": "Set the theme for the chart, optional, default is 'default'.",
41+
"enum": ["default", "academy"],
42+
"type": "string"
43+
},
3844
"width": {
3945
"type": "number",
4046
"description": "Set the width of chart, default is 600.",

__tests__/charts/histogram.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
"default": null,
2929
"description": "Number of intervals to define the number of intervals in a histogram."
3030
},
31+
"theme": {
32+
"default": "default",
33+
"description": "Set the theme for the chart, optional, default is 'default'.",
34+
"enum": ["default", "academy"],
35+
"type": "string"
36+
},
3137
"width": {
3238
"type": "number",
3339
"description": "Set the width of chart, default is 600.",

__tests__/charts/line.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"default": false,
2424
"description": "Whether stacking is enabled. When enabled, line charts require a 'group' field in the data."
2525
},
26+
"theme": {
27+
"default": "default",
28+
"description": "Set the theme for the chart, optional, default is 'default'.",
29+
"enum": ["default", "academy"],
30+
"type": "string"
31+
},
2632
"width": {
2733
"type": "number",
2834
"description": "Set the width of chart, default is 600.",

__tests__/charts/mind-map.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
"required": ["name"],
3232
"description": "Data for mind map chart, such as, { name: 'main topic', children: [{ name: 'topic 1', children: [{ name:'subtopic 1-1' }] }."
3333
},
34+
"theme": {
35+
"default": "default",
36+
"description": "Set the theme for the chart, optional, default is 'default'.",
37+
"enum": ["default", "academy"],
38+
"type": "string"
39+
},
3440
"width": {
3541
"type": "number",
3642
"description": "Set the width of chart, default is 600.",

__tests__/charts/network-graph.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
"required": ["nodes", "edges"],
3636
"description": "Data for network graph chart, such as, { nodes: [{ name: 'node1' }, { name: 'node2' }], edges: [{ source: 'node1', target: 'node2', name: 'edge1' }] }"
3737
},
38+
"theme": {
39+
"default": "default",
40+
"description": "Set the theme for the chart, optional, default is 'default'.",
41+
"enum": ["default", "academy"],
42+
"type": "string"
43+
},
3844
"width": {
3945
"type": "number",
4046
"description": "Set the width of chart, default is 600.",

__tests__/charts/pie.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"description": "Set the innerRadius of pie chart, the value between 0 and 1. Set the pie chart as a donut chart. Set the value to 0.6 or number in [0 ,1] to enable it.",
2424
"default": 0
2525
},
26+
"theme": {
27+
"default": "default",
28+
"description": "Set the theme for the chart, optional, default is 'default'.",
29+
"enum": ["default", "academy"],
30+
"type": "string"
31+
},
2632
"width": {
2733
"type": "number",
2834
"description": "Set the width of chart, default is 600.",

__tests__/charts/radar.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
},
2020
"description": "Data for radar chart, such as, [{ name: 'Design', value: 70 }]."
2121
},
22+
"theme": {
23+
"default": "default",
24+
"description": "Set the theme for the chart, optional, default is 'default'.",
25+
"enum": ["default", "academy"],
26+
"type": "string"
27+
},
2228
"width": {
2329
"type": "number",
2430
"description": "Set the width of chart, default is 600.",

__tests__/charts/scatter.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
},
1919
"description": "Data for scatter chart, such as, [{ x: 10, y: 15 }]."
2020
},
21+
"theme": {
22+
"default": "default",
23+
"description": "Set the theme for the chart, optional, default is 'default'.",
24+
"enum": ["default", "academy"],
25+
"type": "string"
26+
},
2127
"width": {
2228
"type": "number",
2329
"description": "Set the width of chart, default is 600.",

__tests__/charts/treemap.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
},
2323
"description": "Data for treemap chart, such as, [{ name: 'Design', value: 70, children: [{ name: 'Tech', value: 20 }] }]."
2424
},
25+
"theme": {
26+
"default": "default",
27+
"description": "Set the theme for the chart, optional, default is 'default'.",
28+
"enum": ["default", "academy"],
29+
"type": "string"
30+
},
2531
"width": {
2632
"type": "number",
2733
"description": "Set the width of chart, default is 600.",

__tests__/charts/word-cloud.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
},
1919
"description": "Data for word cloud chart, such as, [{ value: '4.272', text: '形成' }]."
2020
},
21+
"theme": {
22+
"default": "default",
23+
"description": "Set the theme for the chart, optional, default is 'default'.",
24+
"enum": ["default", "academy"],
25+
"type": "string"
26+
},
2127
"width": {
2228
"type": "number",
2329
"description": "Set the width of chart, default is 600.",

src/charts/area.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AxisXTitleSchema,
55
AxisYTitleSchema,
66
HeightSchema,
7+
ThemeSchema,
78
TitleSchema,
89
WidthSchema,
910
} from "./base";
@@ -28,6 +29,7 @@ const schema = z.object({
2829
.describe(
2930
"Whether stacking is enabled. When enabled, area charts require a 'group' field in the data.",
3031
),
32+
theme: ThemeSchema,
3133
width: WidthSchema,
3234
height: HeightSchema,
3335
title: TitleSchema,

src/charts/bar.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AxisXTitleSchema,
55
AxisYTitleSchema,
66
HeightSchema,
7+
ThemeSchema,
78
TitleSchema,
89
WidthSchema,
910
} from "./base";
@@ -37,6 +38,7 @@ const schema = z.object({
3738
.describe(
3839
"Whether stacking is enabled. When enabled, bar charts require a 'group' field in the data. When `stack` is true, `group` should be false.",
3940
),
41+
theme: ThemeSchema,
4042
width: WidthSchema,
4143
height: HeightSchema,
4244
title: TitleSchema,

src/charts/base.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { z } from "zod";
22

33
// Define Zod schemas for base configuration properties
4+
export const ThemeSchema = z
5+
.enum(["default", "academy"])
6+
.optional()
7+
.default("default")
8+
.describe("Set the theme for the chart, optional, default is 'default'.");
9+
410
export const WidthSchema = z
511
.number()
612
.optional()

src/charts/column.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AxisXTitleSchema,
55
AxisYTitleSchema,
66
HeightSchema,
7+
ThemeSchema,
78
TitleSchema,
89
WidthSchema,
910
} from "./base";
@@ -37,6 +38,7 @@ const schema = z.object({
3738
.describe(
3839
"Whether stacking is enabled. When enabled, column charts require a 'group' field in the data. When `stack` is true, `group` should be false.",
3940
),
41+
theme: ThemeSchema,
4042
width: WidthSchema,
4143
height: HeightSchema,
4244
title: TitleSchema,

src/charts/dual-axes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { zodToJsonSchema } from "../utils";
33
import {
44
AxisXTitleSchema,
55
HeightSchema,
6+
ThemeSchema,
67
TitleSchema,
78
WidthSchema,
89
} from "./base";
@@ -35,6 +36,7 @@ const schema = z.object({
3536
series: z
3637
.array(DualAxesSeriesSchema)
3738
.nonempty({ message: "Dual axes chart series cannot be empty." }),
39+
theme: ThemeSchema,
3840
width: WidthSchema,
3941
height: HeightSchema,
4042
title: TitleSchema,

src/charts/fishbone-diagram.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod";
22
import { zodToJsonSchema } from "../utils";
3-
import { HeightSchema, WidthSchema } from "./base";
3+
import { HeightSchema, ThemeSchema, WidthSchema } from "./base";
44

55
// Fishbone node schema
66
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -16,6 +16,7 @@ const schema = z.object({
1616
data: FishboneNodeSchema.describe(
1717
"Data for fishbone diagram chart, such as, { name: 'main topic', children: [{ name: 'topic 1', children: [{ name: 'subtopic 1-1' }] }.",
1818
),
19+
theme: ThemeSchema,
1920
width: WidthSchema,
2021
height: HeightSchema,
2122
});

src/charts/flow-diagram.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { z } from "zod";
22
import { zodToJsonSchema } from "../utils";
3-
import { EdgeSchema, HeightSchema, NodeSchema, WidthSchema } from "./base";
3+
import {
4+
EdgeSchema,
5+
HeightSchema,
6+
NodeSchema,
7+
ThemeSchema,
8+
WidthSchema,
9+
} from "./base";
410

511
// Flow diagram input schema
612
const schema = z.object({
@@ -14,6 +20,7 @@ const schema = z.object({
1420
.describe(
1521
"Data for flow diagram chart, such as, { nodes: [{ name: 'node1' }, { name: 'node2' }], edges: [{ source: 'node1', target: 'node2', name: 'edge1' }] }.",
1622
),
23+
theme: ThemeSchema,
1724
width: WidthSchema,
1825
height: HeightSchema,
1926
});

src/charts/histogram.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AxisXTitleSchema,
55
AxisYTitleSchema,
66
HeightSchema,
7+
ThemeSchema,
78
TitleSchema,
89
WidthSchema,
910
} from "./base";
@@ -21,6 +22,7 @@ const schema = z.object({
2122
.describe(
2223
"Number of intervals to define the number of intervals in a histogram.",
2324
),
25+
theme: ThemeSchema,
2426
width: WidthSchema,
2527
height: HeightSchema,
2628
title: TitleSchema,

src/charts/line.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
AxisXTitleSchema,
55
AxisYTitleSchema,
66
HeightSchema,
7+
ThemeSchema,
78
TitleSchema,
89
WidthSchema,
910
} from "./base";
@@ -27,6 +28,7 @@ const schema = z.object({
2728
.describe(
2829
"Whether stacking is enabled. When enabled, line charts require a 'group' field in the data.",
2930
),
31+
theme: ThemeSchema,
3032
width: WidthSchema,
3133
height: HeightSchema,
3234
title: TitleSchema,

src/charts/mind-map.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod";
22
import { zodToJsonSchema } from "../utils";
3-
import { HeightSchema, WidthSchema } from "./base";
3+
import { HeightSchema, ThemeSchema, WidthSchema } from "./base";
44

55
// Mind map node schema
66
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -16,6 +16,7 @@ const schema = z.object({
1616
data: MindMapNodeSchema.describe(
1717
"Data for mind map chart, such as, { name: 'main topic', children: [{ name: 'topic 1', children: [{ name:'subtopic 1-1' }] }.",
1818
),
19+
theme: ThemeSchema,
1920
width: WidthSchema,
2021
height: HeightSchema,
2122
});

src/charts/network-graph.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { z } from "zod";
22
import { zodToJsonSchema } from "../utils";
3-
import { EdgeSchema, HeightSchema, NodeSchema, WidthSchema } from "./base";
3+
import {
4+
EdgeSchema,
5+
HeightSchema,
6+
NodeSchema,
7+
ThemeSchema,
8+
WidthSchema,
9+
} from "./base";
410

511
// Network graph input schema
612
const schema = z.object({
@@ -14,6 +20,7 @@ const schema = z.object({
1420
.describe(
1521
"Data for network graph chart, such as, { nodes: [{ name: 'node1' }, { name: 'node2' }], edges: [{ source: 'node1', target: 'node2', name: 'edge1' }] }",
1622
),
23+
theme: ThemeSchema,
1724
width: WidthSchema,
1825
height: HeightSchema,
1926
});

src/charts/pie.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from "zod";
22
import { zodToJsonSchema } from "../utils";
3-
import { HeightSchema, TitleSchema, WidthSchema } from "./base";
3+
import { HeightSchema, ThemeSchema, TitleSchema, WidthSchema } from "./base";
44

55
// Pie chart data schema
66
const data = z.object({
@@ -22,6 +22,7 @@ const schema = z.object({
2222
.describe(
2323
"Set the innerRadius of pie chart, the value between 0 and 1. Set the pie chart as a donut chart. Set the value to 0.6 or number in [0 ,1] to enable it.",
2424
),
25+
theme: ThemeSchema,
2526
width: WidthSchema,
2627
height: HeightSchema,
2728
title: TitleSchema,

0 commit comments

Comments
 (0)