Skip to content

Commit 3334b3a

Browse files
committed
feat: add sankey
1 parent 70d7df3 commit 3334b3a

5 files changed

Lines changed: 102 additions & 0 deletions

File tree

__tests__/api.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ describe("sdk API", () => {
2424
"organization-chart",
2525
"pie",
2626
"radar",
27+
"sankey",
2728
"scatter",
2829
"treemap",
2930
"word-cloud",

__tests__/charts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export { default as "network-graph" } from "./network-graph.json";
1313
export { default as "organization-chart" } from "./organization-chart.json";
1414
export { default as pie } from "./pie.json";
1515
export { default as radar } from "./radar.json";
16+
export { default as sankey } from "./sankey.json";
1617
export { default as scatter } from "./scatter.json";
1718
export { default as treemap } from "./treemap.json";
1819
export { default as "word-cloud" } from "./word-cloud.json";

__tests__/charts/sankey.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "generate_sankey_chart",
3+
"description": "Generate a sankey chart to visualize the flow of data between different stages or categories, such as, the user journey from landing on a page to completing a purchase.",
4+
"inputSchema": {
5+
"type": "object",
6+
"properties": {
7+
"data": {
8+
"type": "array",
9+
"items": {
10+
"type": "object",
11+
"properties": {
12+
"source": {
13+
"type": "string"
14+
},
15+
"target": {
16+
"type": "string"
17+
},
18+
"value": {
19+
"type": "number"
20+
}
21+
},
22+
"required": ["source", "target", "value"]
23+
},
24+
"minItems": 1,
25+
"description": "Date for sankey chart, such as, [{ source: 'Landing Page', target: 'Product Page', value: 50000 }, { source: 'Product Page', target: 'Add to Cart', value: 35000 }, { source: 'Add to Cart', target: 'Checkout', value: 25000 }, { source: 'Checkout', target: 'Payment', value: 15000 }, { source: 'Payment', target: 'Purchase Completed', value: 8000 }]."
26+
},
27+
"nodeAlign": {
28+
"type": "string",
29+
"enum": ["left", "right", "justify", "center"],
30+
"default": "center",
31+
"description": "Alignment of nodes in the sankey chart, such as, 'left', 'right', 'justify', or 'center'."
32+
},
33+
"theme": {
34+
"type": "string",
35+
"enum": ["default", "academy"],
36+
"default": "default",
37+
"description": "Set the theme for the chart, optional, default is 'default'."
38+
},
39+
"width": {
40+
"type": "number",
41+
"default": 600,
42+
"description": "Set the width of chart, default is 600."
43+
},
44+
"height": {
45+
"type": "number",
46+
"default": 400,
47+
"description": "Set the height of chart, default is 400."
48+
},
49+
"title": {
50+
"type": "string",
51+
"default": "",
52+
"description": "Set the title of chart."
53+
}
54+
},
55+
"required": ["data"],
56+
"$schema": "http://json-schema.org/draft-07/schema#"
57+
}
58+
}

src/charts/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export { networkGraph as "network-graph" } from "./network-graph";
1616
export { organizationChart as "organization-chart" } from "./organization-chart";
1717
export { pie } from "./pie";
1818
export { radar } from "./radar";
19+
export { sankey } from "./sankey";
1920
export { scatter } from "./scatter";
2021
export { treemap } from "./treemap";
2122
export { wordCloud as "word-cloud" } from "./word-cloud";

src/charts/sankey.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { z } from "zod";
2+
import { zodToJsonSchema } from "../utils";
3+
import { HeightSchema, ThemeSchema, TitleSchema, WidthSchema } from "./base";
4+
5+
const data = z.object({
6+
source: z.string(),
7+
target: z.string(),
8+
value: z.number(),
9+
});
10+
11+
const schema = {
12+
data: z
13+
.array(data)
14+
.describe(
15+
"Date for sankey chart, such as, [{ source: 'Landing Page', target: 'Product Page', value: 50000 }, { source: 'Product Page', target: 'Add to Cart', value: 35000 }, { source: 'Add to Cart', target: 'Checkout', value: 25000 }, { source: 'Checkout', target: 'Payment', value: 15000 }, { source: 'Payment', target: 'Purchase Completed', value: 8000 }].",
16+
)
17+
.nonempty({ message: "Sankey chart data cannot be empty." }),
18+
nodeAlign: z
19+
.enum(["left", "right", "justify", "center"])
20+
.optional()
21+
.default("center")
22+
.describe(
23+
"Alignment of nodes in the sankey chart, such as, 'left', 'right', 'justify', or 'center'.",
24+
),
25+
theme: ThemeSchema,
26+
width: WidthSchema,
27+
height: HeightSchema,
28+
title: TitleSchema,
29+
};
30+
31+
const tool = {
32+
name: "generate_sankey_chart",
33+
description:
34+
"Generate a sankey chart to visualize the flow of data between different stages or categories, such as, the user journey from landing on a page to completing a purchase.",
35+
inputSchema: zodToJsonSchema(schema),
36+
};
37+
38+
export const sankey = {
39+
schema,
40+
tool,
41+
};

0 commit comments

Comments
 (0)