@antv/gpt-vis 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # GPT-Vis
2
+
3
+ 为各种 LLM Agent 提供卡片服务的可视化资产和协议。
4
+
5
+ ## ⏬ 安装
6
+
7
+ ```shell
8
+ $ npm install @antv/gpt-vis@0.x --save
9
+ ```
10
+
11
+ ## 🌰 示例
12
+
13
+ ### 📦 组件中使用
14
+
15
+ ```tsx | pure
16
+ import React from 'react';
17
+ import { Pie } from '@antv/gpt-vis';
18
+
19
+ const data = [
20
+ { name: '分类一', value: 27 },
21
+ { name: '分类二', value: 25 },
22
+ { name: '分类三', value: 18 },
23
+ { name: '分类四', value: 15 },
24
+ { name: '分类五', value: 10 },
25
+ { name: '其他', value: 5 },
26
+ ];
27
+
28
+ export default () => {
29
+ return <Pie data={data} />;
30
+ };
31
+ ```
32
+
33
+ ### 📝 Markdown 中使用
34
+
35
+ #### 方式一:使用 MarkdownVis 组件
36
+
37
+ ```tsx | pure
38
+ import React from 'react';
39
+ import { MarkdownVis } from '@antv/gpt-vis';
40
+
41
+ const markdownContent = `
42
+ # GPT-VIS \n\nComponents for GPTs, generative AI, and LLM projects. Not only UI Components.
43
+
44
+ \`\`\`vis-chart
45
+ {
46
+ "type": "pie",
47
+ "data": [
48
+ { "name": "分类一", "value": 27 },
49
+ { "name": "分类二", "value": 25 },
50
+ { "name": "分类三", "value": 18 },
51
+ { "name": "分类四", "value": 15 },
52
+ { "name": "分类五", "value": 10 },
53
+ { "name": "其他", "value": 5 }
54
+ ]
55
+ }
56
+ \`\`\`
57
+ `;
58
+
59
+ export default () => {
60
+ return <MarkdownVis>{markdownContent}</MarkdownVis>;
61
+ };
62
+ ```
63
+
64
+ #### 方式二:扩展 react-markdown 使用
65
+
66
+ ```tsx | pure
67
+ import React from 'react';
68
+ import Markdown from 'react-markdown';
69
+ import { withDefaultChartCode } from '@antv/gpt-vis';
70
+
71
+ const markdownContent = `
72
+ # GPT-VIS \n\nComponents for GPTs, generative AI, and LLM projects. Not only UI Components.
73
+
74
+ \`\`\`vis-chart
75
+ {
76
+ "type": "pie",
77
+ "data": [
78
+ { "name": "分类一", "value": 27 },
79
+ { "name": "分类二", "value": 25 },
80
+ { "name": "分类三", "value": 18 },
81
+ { "name": "分类四", "value": 15 },
82
+ { "name": "分类五", "value": 10 },
83
+ { "name": "其他", "value": 5 }
84
+ ]
85
+ }
86
+ \`\`\`
87
+ `;
88
+
89
+ const CodeBlock = withDefaultChartCode();
90
+
91
+ export default () => {
92
+ return (
93
+ <Markdown components={{ code: CodeBlock }}>{markdownContent}</Markdown>
94
+ );
95
+ };
96
+ ```
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { StackableChartProps } from '../types';
3
+ export type AreaProps = StackableChartProps;
4
+ declare const Area: (props: AreaProps) => React.JSX.Element;
5
+ export default Area;
@@ -0,0 +1,40 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ // 引入必要的包
4
+ import { Area as ADCArea } from '@ant-design/plots';
5
+ import React from 'react';
6
+ // 假如你有类型需要引入
7
+
8
+ var Area = function Area(props) {
9
+ var _props$data = props.data,
10
+ data = _props$data === void 0 ? [] : _props$data,
11
+ _props$xField = props.xField,
12
+ xField = _props$xField === void 0 ? 'x' : _props$xField,
13
+ _props$yField = props.yField,
14
+ yField = _props$yField === void 0 ? 'y' : _props$yField,
15
+ stackField = props.stackField,
16
+ className = props.className,
17
+ style = props.style;
18
+
19
+ // 如果有 stackField,则使用 seriesField 进行分组显示,否则不分组
20
+ var stackConfig = stackField ? {
21
+ colorField: stackField,
22
+ isStack: true
23
+ } : {};
24
+ var config = _objectSpread({
25
+ data: data,
26
+ xField: xField,
27
+ yField: yField,
28
+ tooltip: function tooltip(d) {
29
+ return {
30
+ name: d[xField],
31
+ value: d[yField]
32
+ };
33
+ }
34
+ }, stackConfig);
35
+ return /*#__PURE__*/React.createElement(ADCArea, _extends({
36
+ className: className,
37
+ containerStyle: _objectSpread({}, style)
38
+ }, config));
39
+ };
40
+ export default Area;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import './index.less';
3
+ import { ChartComponents, CodeBlockComponent, ExtraRenderers, WithChartCodeOptions } from './type';
4
+ export declare const withCodeBlock: (options: {
5
+ components: ChartComponents;
6
+ extraRenderers?: ExtraRenderers;
7
+ debug?: boolean;
8
+ loadingTimeout?: number;
9
+ }) => CodeBlockComponent;
10
+ export declare const withChartCode: (options: WithChartCodeOptions) => keyof JSX.IntrinsicElements | import("hast-util-to-jsx-runtime/lib/components").Component<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & import("hast-util-to-jsx-runtime/lib/components").ExtraProps> | undefined;
11
+ /**
12
+ * Includes built-in chart components such as line charts, pie charts, etc.
13
+ * @param componentsArray
14
+ * @returns
15
+ */
16
+ export declare const withDefaultChartCode: (options?: Partial<WithChartCodeOptions>) => keyof JSX.IntrinsicElements | import("hast-util-to-jsx-runtime/lib/components").Component<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & import("hast-util-to-jsx-runtime/lib/components").ExtraProps> | undefined;
@@ -0,0 +1,120 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
+ var _excluded = ["children", "className", "node"];
7
+ import { LoadingOutlined } from '@ant-design/icons';
8
+ import { get } from 'lodash-es';
9
+ import React, { useRef, useState } from 'react';
10
+ import { DEFAULT_CHART_COMPONENTS } from "../constants";
11
+ import "./index.less";
12
+ var Loading = function Loading() {
13
+ return /*#__PURE__*/React.createElement("div", {
14
+ className: "gpt-vis-loading"
15
+ }, /*#__PURE__*/React.createElement("div", {
16
+ className: "gpt-vis-loading-icon"
17
+ }, /*#__PURE__*/React.createElement(LoadingOutlined, {
18
+ style: {
19
+ fontSize: '24px',
20
+ color: 'rgb(56, 177, 246)'
21
+ }
22
+ })), /*#__PURE__*/React.createElement("p", null, "\u6570\u636E\u751F\u6210\u4E2D"));
23
+ };
24
+ export var withCodeBlock = function withCodeBlock(options) {
25
+ // Render code block component
26
+ return function CodeBlock(props) {
27
+ var _className$match;
28
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
+ var children = props.children,
30
+ _props$className = props.className,
31
+ className = _props$className === void 0 ? '' : _props$className,
32
+ node = props.node,
33
+ rest = _objectWithoutProperties(props, _excluded);
34
+ var content = String(children).trim();
35
+ var isVisChart = className.includes('language-vis-chart');
36
+ var components = options.components,
37
+ extraRenderers = options.extraRenderers,
38
+ debug = options.debug,
39
+ _options$loadingTimeo = options.loadingTimeout,
40
+ loadingTimeout = _options$loadingTimeo === void 0 ? 5000 : _options$loadingTimeo;
41
+ var timeoutRef = useRef();
42
+ var _useState = useState(true),
43
+ _useState2 = _slicedToArray(_useState, 2),
44
+ loading = _useState2[0],
45
+ setLoading = _useState2[1];
46
+
47
+ // If the code block is a VisChart, render the corresponding chart component
48
+ if (isVisChart) {
49
+ var chartJson;
50
+ try {
51
+ chartJson = JSON.parse(content);
52
+ } catch (e) {
53
+ if (timeoutRef.current) {
54
+ clearTimeout(timeoutRef.current);
55
+ if (debug) {
56
+ console.log('GPT-Vis withChartCode parse content timeout');
57
+ }
58
+ }
59
+ timeoutRef.current = setTimeout(function () {
60
+ setLoading(false);
61
+ }, loadingTimeout);
62
+ return loading ? /*#__PURE__*/React.createElement(Loading, null) : /*#__PURE__*/React.createElement("code", null, content.toString());
63
+ }
64
+ var _chartJson = chartJson,
65
+ type = _chartJson.type;
66
+ var ChartComponent = components[type];
67
+
68
+ // debug mode print chartJson
69
+ if (debug) {
70
+ console.log('GPT-Vis withChartCode get chartJson parse from vis-chart code block', chartJson);
71
+ }
72
+
73
+ // If the chart type is not supported, display an error message
74
+ if (!ChartComponent) {
75
+ return /*#__PURE__*/React.createElement("code", null, "Chart type \"".concat(type, "\" is not supported."));
76
+ }
77
+
78
+ // Render the supported chart component with data
79
+
80
+ return /*#__PURE__*/React.createElement("div", {
81
+ className: "gpt-vis"
82
+ }, /*#__PURE__*/React.createElement(ChartComponent, chartJson));
83
+ }
84
+
85
+ // If the code block math extraRenderer languageName, the corresponding extraRenderers component
86
+ var languageName = ((_className$match = className.match(/language-(.*)/)) === null || _className$match === void 0 ? void 0 : _className$match[1]) || '';
87
+ var ExtraRendererComponent = extraRenderers && extraRenderers[languageName];
88
+ if (ExtraRendererComponent) {
89
+ return /*#__PURE__*/React.createElement(ExtraRendererComponent, props);
90
+ }
91
+
92
+ // If the code block is not a VisChart, render plain code
93
+ return /*#__PURE__*/React.createElement("code", _extends({}, rest, {
94
+ className: className
95
+ }), children);
96
+ };
97
+ };
98
+
99
+ // Create a higher-order component (HOC) with chart code
100
+ export var withChartCode = function withChartCode(options) {
101
+ var _options$components;
102
+ // Flatten the components array into a single object
103
+ var components = ((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.reduce(function (acc, obj) {
104
+ return _objectSpread(_objectSpread({}, acc), obj);
105
+ }, {})) || [];
106
+ return withCodeBlock(_objectSpread(_objectSpread({}, options), {}, {
107
+ components: components
108
+ }));
109
+ };
110
+
111
+ /**
112
+ * Includes built-in chart components such as line charts, pie charts, etc.
113
+ * @param componentsArray
114
+ * @returns
115
+ */
116
+ export var withDefaultChartCode = function withDefaultChartCode(options) {
117
+ return withChartCode(_objectSpread(_objectSpread({}, options), {}, {
118
+ components: [DEFAULT_CHART_COMPONENTS].concat(_toConsumableArray(get(options, 'components', [])))
119
+ }));
120
+ };
@@ -0,0 +1,19 @@
1
+ .gpt-vis {
2
+ min-width: 600px;
3
+ max-width: 100%;
4
+ }
5
+
6
+ .gpt-vis-loading {
7
+ display: flex;
8
+ align-items: center;
9
+ justify-content: center;
10
+ flex-direction: column;
11
+ width: 400px;
12
+ height: 400px;
13
+ background-image: linear-gradient(135deg, #e3f3ff 0%, #f1eeff 100%);
14
+ color: rgba(0, 0, 0, 88%);
15
+
16
+ &-icon {
17
+ margin-bottom: 6px;
18
+ }
19
+ }
@@ -0,0 +1,30 @@
1
+ import { FC } from 'react';
2
+ import { Components, ExtraProps } from 'react-markdown';
3
+ import { BaseChartProps } from '../types';
4
+ export type WithChartCodeOptions = {
5
+ components: ChartComponents[];
6
+ extraRenderers?: ExtraRenderers;
7
+ debug?: boolean;
8
+ loadingTimeout?: number;
9
+ };
10
+ /**
11
+ * 图表渲染数据接口,后续拓展,这里只是写个示例
12
+ */
13
+ export interface ChartJson {
14
+ type: string;
15
+ data: any[];
16
+ }
17
+ /**
18
+ * 图表组件字典
19
+ */
20
+ export interface ChartComponents {
21
+ [key: string]: FC<BaseChartProps<any>>;
22
+ }
23
+ /**
24
+ * 代码块渲染器接口
25
+ */
26
+ export type CodeBlockComponent = Components['code'];
27
+ /** 额外的渲染器选项 */
28
+ export interface ExtraRenderers {
29
+ [key: string]: FC<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & ExtraProps>;
30
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { StackableChartProps } from '../types';
3
+ export type ColumnProps = StackableChartProps;
4
+ declare const Column: (props: ColumnProps) => React.JSX.Element;
5
+ export default Column;
@@ -0,0 +1,40 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import { Column as ADCColumn } from '@ant-design/plots';
4
+ import React from 'react';
5
+ var Column = function Column(props) {
6
+ var _props$data = props.data,
7
+ data = _props$data === void 0 ? [] : _props$data,
8
+ _props$xField = props.xField,
9
+ xField = _props$xField === void 0 ? 'x' : _props$xField,
10
+ _props$yField = props.yField,
11
+ yField = _props$yField === void 0 ? 'y' : _props$yField,
12
+ stackField = props.stackField,
13
+ style = props.style,
14
+ className = props.className;
15
+ var stackConfig = stackField ? {
16
+ colorField: stackField,
17
+ stack: true
18
+ } : {};
19
+ var config = _objectSpread({
20
+ data: data,
21
+ xField: xField || 'x',
22
+ yField: yField || 'y',
23
+ style: {
24
+ // 圆角样式
25
+ radiusTopLeft: 10,
26
+ radiusTopRight: 10
27
+ },
28
+ tooltip: function tooltip(d) {
29
+ return {
30
+ name: d[xField],
31
+ value: d[yField]
32
+ };
33
+ }
34
+ }, stackConfig);
35
+ return /*#__PURE__*/React.createElement(ADCColumn, _extends({
36
+ className: className,
37
+ containerStyle: _objectSpread({}, style)
38
+ }, config));
39
+ };
40
+ export default Column;
@@ -0,0 +1,12 @@
1
+ import { type FC } from 'react';
2
+ import { BaseChartProps } from '../types';
3
+ type GeoData = {
4
+ lng: number;
5
+ lat: number;
6
+ size: number;
7
+ };
8
+ export interface HeatMapProps extends BaseChartProps<GeoData> {
9
+ className?: string;
10
+ }
11
+ declare const HeatMap: FC<HeatMapProps>;
12
+ export default HeatMap;
@@ -0,0 +1,60 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import { HeatmapLayer, LarkMap } from '@antv/larkmap';
5
+ import React, { useState } from 'react';
6
+ window._AMapSecurityConfig = {
7
+ securityJsCode: '8803c38931b6fddc9bbfeee69df8824d'
8
+ };
9
+ var CONFIG = {
10
+ mapType: 'Gaode',
11
+ mapOptions: {
12
+ style: 'normal',
13
+ center: [120.210792, 30.246026],
14
+ zoom: 12,
15
+ maxZoom: 18,
16
+ token: 'f0230f884bbd54e2913c890cdf45aa7e'
17
+ }
18
+ };
19
+ var heapLayerOptions = {
20
+ autoFit: true,
21
+ shape: 'heatmap',
22
+ size: {
23
+ field: 'size',
24
+ value: [0, 1]
25
+ },
26
+ style: {
27
+ intensity: 3,
28
+ radius: 20,
29
+ opacity: 1,
30
+ rampColors: {
31
+ colors: ['#FF4818', '#F7B74A', '#FFF598', '#F27DEB', '#8C1EB2', '#421EB2'],
32
+ positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0]
33
+ }
34
+ }
35
+ };
36
+ var HeatMap = function HeatMap(props) {
37
+ var className = props.className,
38
+ style = props.style,
39
+ _props$data = props.data,
40
+ data = _props$data === void 0 ? [] : _props$data;
41
+ var _useState = useState({
42
+ data: data,
43
+ parser: {
44
+ type: 'json',
45
+ x: 'lng',
46
+ y: 'lat'
47
+ }
48
+ }),
49
+ _useState2 = _slicedToArray(_useState, 1),
50
+ heapSource = _useState2[0];
51
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LarkMap, _extends({
52
+ className: className,
53
+ style: _objectSpread({
54
+ height: '300px'
55
+ }, style)
56
+ }, CONFIG), /*#__PURE__*/React.createElement(HeatmapLayer, _extends({}, heapLayerOptions, {
57
+ source: heapSource
58
+ }))));
59
+ };
60
+ export default HeatMap;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { StackableChartProps } from '../types';
3
+ export type LineProps = StackableChartProps;
4
+ declare const Line: (props: LineProps) => React.JSX.Element;
5
+ export default Line;
@@ -0,0 +1,37 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import { Line as ADCLine } from '@ant-design/plots';
4
+ import React from 'react';
5
+ var Line = function Line(props) {
6
+ var _props$data = props.data,
7
+ data = _props$data === void 0 ? [] : _props$data,
8
+ _props$xField = props.xField,
9
+ xField = _props$xField === void 0 ? 'x' : _props$xField,
10
+ _props$yField = props.yField,
11
+ yField = _props$yField === void 0 ? 'y' : _props$yField,
12
+ stackField = props.stackField,
13
+ className = props.className,
14
+ style = props.style;
15
+
16
+ // 如果有 stackField,则使用 seriesField 进行分组显示,否则不分组
17
+ var stackConfig = stackField ? {
18
+ colorField: stackField
19
+ } : {};
20
+ var config = _objectSpread({
21
+ data: data,
22
+ xField: xField,
23
+ yField: yField,
24
+ tooltip: function tooltip(d) {
25
+ return {
26
+ name: d[xField],
27
+ value: d[yField]
28
+ };
29
+ },
30
+ smooth: true
31
+ }, stackConfig);
32
+ return /*#__PURE__*/React.createElement(ADCLine, _extends({
33
+ className: className,
34
+ containerStyle: _objectSpread({}, style)
35
+ }, config));
36
+ };
37
+ export default Line;
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { Options } from 'react-markdown';
3
+ export type MarkdownVisProps = {
4
+ /**
5
+ * 需要被渲染的 markdown 字符串
6
+ */
7
+ children: string;
8
+ /**
9
+ * 注册的组件
10
+ */
11
+ components?: Options['components'];
12
+ /**
13
+ * 注册的 rehype 插件
14
+ */
15
+ rehypePlugins: Options['rehypePlugins'];
16
+ /**
17
+ * CSS Properties
18
+ */
19
+ style?: React.CSSProperties;
20
+ };
21
+ declare const MarkdownVis: React.FC<MarkdownVisProps>;
22
+ export default MarkdownVis;
@@ -0,0 +1,19 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import React from 'react';
4
+ import Markdown from 'react-markdown';
5
+ import rehypeRaw from 'rehype-raw';
6
+ import { withDefaultChartCode } from "../ChartCodeRender";
7
+ var MarkdownVis = function MarkdownVis(_ref) {
8
+ var children = _ref.children,
9
+ components = _ref.components,
10
+ rehypePlugins = _ref.rehypePlugins;
11
+ var CodeBlock = withDefaultChartCode();
12
+ return /*#__PURE__*/React.createElement(Markdown, {
13
+ components: _objectSpread({
14
+ code: CodeBlock
15
+ }, components),
16
+ rehypePlugins: [rehypeRaw].concat(_toConsumableArray(rehypePlugins || []))
17
+ }, children);
18
+ };
19
+ export default MarkdownVis;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { Options } from 'react-markdown';
3
+ export type MessageProps = {
4
+ /**
5
+ * 需要被渲染的 markdown 字符串
6
+ */
7
+ children: string;
8
+ /**
9
+ * 注册的组件
10
+ */
11
+ components?: Options['components'];
12
+ /**
13
+ * 注册的 rehype 插件
14
+ */
15
+ rehypePlugins?: Options['rehypePlugins'];
16
+ };
17
+ declare const Message: React.FC<MessageProps>;
18
+ export default Message;
@@ -0,0 +1,14 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import React from 'react';
3
+ import Markdown from 'react-markdown';
4
+ import rehypeRaw from 'rehype-raw';
5
+ var Message = function Message(_ref) {
6
+ var children = _ref.children,
7
+ components = _ref.components,
8
+ rehypePlugins = _ref.rehypePlugins;
9
+ return /*#__PURE__*/React.createElement(Markdown, {
10
+ components: components,
11
+ rehypePlugins: [rehypeRaw].concat(_toConsumableArray(rehypePlugins || []))
12
+ }, children);
13
+ };
14
+ export default Message;
@@ -0,0 +1,12 @@
1
+ import { type FC } from 'react';
2
+ import { BaseChartProps } from '../types';
3
+ type GeoData = {
4
+ originName?: string;
5
+ destinationName?: string;
6
+ coordinates: [number, number][];
7
+ };
8
+ export interface PathMapProps extends BaseChartProps<GeoData> {
9
+ className?: string;
10
+ }
11
+ declare const PathMap: FC<PathMapProps>;
12
+ export default PathMap;
@@ -0,0 +1,140 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import { LarkMap, LineLayer, PointLayer, TextLayer } from '@antv/larkmap';
5
+ import React, { useState } from 'react';
6
+ window._AMapSecurityConfig = {
7
+ securityJsCode: '8803c38931b6fddc9bbfeee69df8824d'
8
+ };
9
+ var CONFIG = {
10
+ mapType: 'Gaode',
11
+ mapOptions: {
12
+ style: 'normal',
13
+ center: [120.210792, 30.246026],
14
+ zoom: 12,
15
+ maxZoom: 18,
16
+ token: 'f0230f884bbd54e2913c890cdf45aa7e'
17
+ }
18
+ };
19
+ var lineLayerOptions = {
20
+ autoFit: false,
21
+ shape: 'line',
22
+ size: 3,
23
+ color: '#6808fed1',
24
+ style: {
25
+ opacity: 1,
26
+ lineType: 'solid',
27
+ stroke: '#6808FE',
28
+ strokeWidth: 1
29
+ }
30
+ };
31
+ var makerLayerOptions = {
32
+ autoFit: false,
33
+ shape: 'circle',
34
+ color: '#fff',
35
+ size: 4,
36
+ style: {
37
+ stroke: '#6808FE',
38
+ strokeWidth: 3
39
+ }
40
+ };
41
+ var labelLayerOptions = {
42
+ autoFit: false,
43
+ field: 'address',
44
+ style: {
45
+ fill: '#fff',
46
+ opacity: 1,
47
+ fontSize: 16,
48
+ fontWeight: 'bold',
49
+ stroke: '#6808FE',
50
+ strokeWidth: 8,
51
+ textAllowOverlap: false,
52
+ padding: [5, 5],
53
+ textOffset: [0, 30]
54
+ }
55
+ };
56
+ function bbox(data) {
57
+ var bounds = [Infinity, Infinity, -Infinity, -Infinity];
58
+ data.forEach(function (_ref) {
59
+ var coordinates = _ref.coordinates;
60
+ coordinates.forEach(function (_ref2) {
61
+ var _ref3 = _slicedToArray(_ref2, 2),
62
+ lng = _ref3[0],
63
+ lat = _ref3[1];
64
+ if (bounds[0] > lng) {
65
+ bounds[0] = lng;
66
+ }
67
+ if (bounds[1] > lat) {
68
+ bounds[1] = lat;
69
+ }
70
+ if (bounds[2] < lng) {
71
+ bounds[2] = lng;
72
+ }
73
+ if (bounds[3] < lat) {
74
+ bounds[3] = lat;
75
+ }
76
+ });
77
+ });
78
+ return bounds;
79
+ }
80
+ var PathMap = function PathMap(props) {
81
+ var className = props.className,
82
+ style = props.style,
83
+ _props$data = props.data,
84
+ data = _props$data === void 0 ? [] : _props$data;
85
+ var _useState = useState({
86
+ data: data,
87
+ parser: {
88
+ type: 'json',
89
+ coordinates: 'coordinates'
90
+ }
91
+ }),
92
+ _useState2 = _slicedToArray(_useState, 1),
93
+ lineSource = _useState2[0];
94
+ var _useState3 = useState(function () {
95
+ return {
96
+ data: data.map(function (item) {
97
+ return [{
98
+ lngLat: item.coordinates[0],
99
+ address: item === null || item === void 0 ? void 0 : item.originName
100
+ }, {
101
+ lngLat: item.coordinates[item.coordinates.length - 1],
102
+ address: item === null || item === void 0 ? void 0 : item.destinationName
103
+ }];
104
+ }).flat().filter(function (item) {
105
+ return item.address;
106
+ }),
107
+ parser: {
108
+ type: 'json',
109
+ coordinates: 'lngLat'
110
+ }
111
+ };
112
+ }),
113
+ _useState4 = _slicedToArray(_useState3, 1),
114
+ dotSource = _useState4[0];
115
+ var onSceneLoaded = function onSceneLoaded(scene) {
116
+ if (!data.length) return;
117
+ var bounds = bbox(data);
118
+ if (scene.getType() === 'amap') {
119
+ var _scene$map;
120
+ (_scene$map = scene.map) === null || _scene$map === void 0 || _scene$map.setBounds(bounds, true, [60, 60, 60, 60]);
121
+ } else {
122
+ scene.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]]);
123
+ }
124
+ };
125
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LarkMap, _extends({
126
+ className: className,
127
+ style: _objectSpread({
128
+ height: 300
129
+ }, style)
130
+ }, CONFIG, {
131
+ onSceneLoaded: onSceneLoaded
132
+ }), /*#__PURE__*/React.createElement(LineLayer, _extends({}, lineLayerOptions, {
133
+ source: lineSource
134
+ })), /*#__PURE__*/React.createElement(PointLayer, _extends({}, makerLayerOptions, {
135
+ source: dotSource
136
+ })), /*#__PURE__*/React.createElement(TextLayer, _extends({}, labelLayerOptions, {
137
+ source: dotSource
138
+ }))));
139
+ };
140
+ export default PathMap;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { BaseChartProps } from '../types';
3
+ /**
4
+ * PieDataItem is the type for each data item in the pie chart.
5
+ * It includes the name of the sector and its corresponding value.
6
+ * @param name The name of the sector.
7
+ * @param value The value of the sector.
8
+ */
9
+ export type PieDataItem = {
10
+ name: string;
11
+ value: number;
12
+ };
13
+ /**
14
+ * the props for the Pie
15
+ * @param data pie data
16
+ */
17
+ export type PieProps = BaseChartProps<PieDataItem>;
18
+ declare const Pie: (props: PieProps) => React.JSX.Element;
19
+ export default Pie;
@@ -0,0 +1,60 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import { Pie as ADCPie } from '@ant-design/plots';
4
+ import React from 'react';
5
+
6
+ /**
7
+ * PieDataItem is the type for each data item in the pie chart.
8
+ * It includes the name of the sector and its corresponding value.
9
+ * @param name The name of the sector.
10
+ * @param value The value of the sector.
11
+ */
12
+
13
+ /**
14
+ * the props for the Pie
15
+ * @param data pie data
16
+ */
17
+
18
+ var Pie = function Pie(props) {
19
+ var data = props.data,
20
+ className = props.className,
21
+ style = props.style;
22
+ var config = {
23
+ data: data,
24
+ angleField: 'value',
25
+ colorField: 'name',
26
+ state: {
27
+ selected: {
28
+ offset: 8
29
+ }
30
+ },
31
+ tooltip: function tooltip(d) {
32
+ return {
33
+ name: d.name,
34
+ value: d.value
35
+ };
36
+ },
37
+ label: {
38
+ text: 'value',
39
+ style: {
40
+ fontWeight: 'bold'
41
+ }
42
+ },
43
+ legend: {
44
+ color: {
45
+ title: false,
46
+ position: 'top'
47
+ }
48
+ },
49
+ interaction: {
50
+ elementSelect: {
51
+ single: true
52
+ }
53
+ }
54
+ };
55
+ return /*#__PURE__*/React.createElement(ADCPie, _extends({
56
+ className: className,
57
+ containerStyle: _objectSpread({}, style)
58
+ }, config));
59
+ };
60
+ export default Pie;
File without changes
File without changes
@@ -0,0 +1,12 @@
1
+ import { type FC } from 'react';
2
+ import { BaseChartProps } from '../types';
3
+ type GeoData = {
4
+ address: string;
5
+ lng: number;
6
+ lat: number;
7
+ };
8
+ export interface PinMapProps extends BaseChartProps<GeoData> {
9
+ className?: string;
10
+ }
11
+ declare const PinMap: FC<PinMapProps>;
12
+ export default PinMap;
@@ -0,0 +1,114 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import { LarkMap, PointLayer, TextLayer } from '@antv/larkmap';
5
+ import React, { useState } from 'react';
6
+ window._AMapSecurityConfig = {
7
+ securityJsCode: '8803c38931b6fddc9bbfeee69df8824d'
8
+ };
9
+ var CONFIG = {
10
+ mapType: 'Gaode',
11
+ mapOptions: {
12
+ style: 'normal',
13
+ center: [120.210792, 30.246026],
14
+ zoom: 12,
15
+ maxZoom: 18,
16
+ token: 'f0230f884bbd54e2913c890cdf45aa7e'
17
+ }
18
+ };
19
+
20
+ // const SVG_BLOB = new Blob(
21
+ // [
22
+ // `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="48px" width="48px" viewBox="0 0 1024 1024"><path d="M512 490.666667C453.12 490.666667 405.333333 442.88 405.333333 384 405.333333 325.12 453.12 277.333333 512 277.333333 570.88 277.333333 618.666667 325.12 618.666667 384 618.666667 442.88 570.88 490.666667 512 490.666667M512 85.333333C346.88 85.333333 213.333333 218.88 213.333333 384 213.333333 608 512 938.666667 512 938.666667 512 938.666667 810.666667 608 810.666667 384 810.666667 218.88 677.12 85.333333 512 85.333333Z" fill="#6808FE"></path></svg>`,
23
+ // ],
24
+ // { type: 'image/svg+xml;charset=utf-8' },
25
+ // );
26
+ // const SVG_URL = URL.createObjectURL(SVG_BLOB);
27
+ var SVG_URL = 'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*yVhwTrhcKZAAAAAAAAAAAAAADmJ7AQ/original';
28
+ var makerLayerOptions = {
29
+ autoFit: false,
30
+ shape: 'marker',
31
+ size: 22,
32
+ style: {}
33
+ };
34
+ var labelLayerOptions = {
35
+ autoFit: false,
36
+ field: 'address',
37
+ style: {
38
+ fill: '#fff',
39
+ opacity: 1,
40
+ fontSize: 16,
41
+ fontWeight: 'bold',
42
+ stroke: '#6808FE',
43
+ strokeWidth: 8,
44
+ textAllowOverlap: false,
45
+ padding: [2, 2],
46
+ textOffset: [0, 50]
47
+ }
48
+ };
49
+ function bbox(data) {
50
+ var bounds = [Infinity, Infinity, -Infinity, -Infinity];
51
+ data.forEach(function (_ref) {
52
+ var lng = _ref.lng,
53
+ lat = _ref.lat;
54
+ if (bounds[0] > lng) {
55
+ bounds[0] = lng;
56
+ }
57
+ if (bounds[1] > lat) {
58
+ bounds[1] = lat;
59
+ }
60
+ if (bounds[2] < lng) {
61
+ bounds[2] = lng;
62
+ }
63
+ if (bounds[3] < lat) {
64
+ bounds[3] = lat;
65
+ }
66
+ });
67
+ return bounds;
68
+ }
69
+ var PinMap = function PinMap(props) {
70
+ var className = props.className,
71
+ style = props.style,
72
+ _props$data = props.data,
73
+ data = _props$data === void 0 ? [] : _props$data;
74
+ var _useState = useState(false),
75
+ _useState2 = _slicedToArray(_useState, 2),
76
+ loadedImages = _useState2[0],
77
+ setLoadedImages = _useState2[1];
78
+ var _useState3 = useState({
79
+ data: data,
80
+ parser: {
81
+ type: 'json',
82
+ x: 'lng',
83
+ y: 'lat'
84
+ }
85
+ }),
86
+ _useState4 = _slicedToArray(_useState3, 1),
87
+ source = _useState4[0];
88
+ var onSceneLoaded = function onSceneLoaded(scene) {
89
+ scene.addImage('marker', SVG_URL).then(function () {
90
+ setLoadedImages(true);
91
+ });
92
+ if (!data.length) return;
93
+ var bounds = bbox(data);
94
+ if (scene.getType() === 'amap') {
95
+ var _scene$map;
96
+ (_scene$map = scene.map) === null || _scene$map === void 0 || _scene$map.setBounds(bounds, true, [50, 50, 50, 50]);
97
+ } else {
98
+ scene.fitBounds([[bounds[0], bounds[1]], [bounds[2], bounds[3]]]);
99
+ }
100
+ };
101
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(LarkMap, _extends({
102
+ className: className,
103
+ style: _objectSpread({
104
+ height: 300
105
+ }, style)
106
+ }, CONFIG, {
107
+ onSceneLoaded: onSceneLoaded
108
+ }), loadedImages && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PointLayer, _extends({}, makerLayerOptions, {
109
+ source: source
110
+ })), /*#__PURE__*/React.createElement(TextLayer, _extends({}, labelLayerOptions, {
111
+ source: source
112
+ })))));
113
+ };
114
+ export default PinMap;
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="48px" width="48px" viewBox="0 0 1024 1024"><path d="M512 490.666667C453.12 490.666667 405.333333 442.88 405.333333 384 405.333333 325.12 453.12 277.333333 512 277.333333 570.88 277.333333 618.666667 325.12 618.666667 384 618.666667 442.88 570.88 490.666667 512 490.666667M512 85.333333C346.88 85.333333 213.333333 218.88 213.333333 384 213.333333 608 512 938.666667 512 938.666667 512 938.666667 810.666667 608 810.666667 384 810.666667 218.88 677.12 85.333333 512 85.333333Z" fill="#6808FE"></path></svg>
@@ -0,0 +1,11 @@
1
+ import { type FC } from 'react';
2
+ import { BaseChartProps } from '../types';
3
+ type PlotData = {
4
+ text: string;
5
+ value: number;
6
+ };
7
+ export interface WordCloudProps extends BaseChartProps<PlotData> {
8
+ className?: string;
9
+ }
10
+ declare const WordCloud: FC<WordCloudProps>;
11
+ export default WordCloud;
@@ -0,0 +1,27 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
+ import { WordCloud as WordCloudPlot } from '@ant-design/plots';
4
+ import React from 'react';
5
+ var config = {
6
+ autoFit: true,
7
+ layout: {
8
+ fontSize: [20, 100]
9
+ },
10
+ encode: {
11
+ color: 'text'
12
+ },
13
+ legend: false
14
+ };
15
+ var WordCloud = function WordCloud(props) {
16
+ var className = props.className,
17
+ style = props.style,
18
+ _props$data = props.data,
19
+ data = _props$data === void 0 ? [] : _props$data;
20
+ return /*#__PURE__*/React.createElement(WordCloudPlot, _extends({
21
+ className: className,
22
+ containerStyle: _objectSpread({}, style)
23
+ }, config, {
24
+ data: data
25
+ }));
26
+ };
27
+ export default WordCloud;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const DEFAULT_CHART_COMPONENTS: Record<string, React.FC<any>>;
@@ -0,0 +1,11 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import Area from "../Area";
3
+ import Line from "../Line";
4
+ import HeatMap from "../HeatMap";
5
+ import PathMap from "../PathMap";
6
+ import Pie from "../Pie";
7
+ import PinMap from "../PinMap";
8
+ import WordCloud from "../WordCloud";
9
+ import Column from "../Column";
10
+ import { ChartType } from "../types";
11
+ export var DEFAULT_CHART_COMPONENTS = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, ChartType.Pie, Pie), ChartType.Area, Area), ChartType.Column, Column), ChartType.Line, Line), ChartType.WordCloud, WordCloud), ChartType.PinMap, PinMap), ChartType.PathMap, PathMap), ChartType.HeatMap, HeatMap);
@@ -0,0 +1,12 @@
1
+ export { default as HeatMap } from './HeatMap';
2
+ export { default as MarkdownVis } from './MarkdownVis';
3
+ export { default as Message } from './Message';
4
+ export { default as PathMap } from './PathMap';
5
+ export { default as Pie } from './Pie';
6
+ export { default as PinMap } from './PinMap';
7
+ export { default as WordCloud } from './WordCloud';
8
+ export { withChartCode, withDefaultChartCode } from './ChartCodeRender';
9
+ export * from './types';
10
+ export { default as Column, type ColumnProps } from './Column';
11
+ export { default as Line, type LineProps } from './Line';
12
+ export { default as Area, type AreaProps } from './Area';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export { default as HeatMap } from "./HeatMap";
2
+ export { default as MarkdownVis } from "./MarkdownVis";
3
+ export { default as Message } from "./Message";
4
+ export { default as PathMap } from "./PathMap";
5
+ export { default as Pie } from "./Pie";
6
+ export { default as PinMap } from "./PinMap";
7
+ export { default as WordCloud } from "./WordCloud";
8
+ export { withChartCode, withDefaultChartCode } from "./ChartCodeRender";
9
+ export * from "./types";
10
+ export { default as Column } from "./Column";
11
+ export { default as Line } from "./Line";
12
+ export { default as Area } from "./Area";
@@ -0,0 +1,26 @@
1
+ import { type CSSProperties } from 'react';
2
+ export declare enum ChartType {
3
+ Pie = "pie",
4
+ Column = "column",
5
+ Line = "line",
6
+ Area = "area",
7
+ WordCloud = "word-cloud",
8
+ PinMap = "pin-map",
9
+ PathMap = "path-map",
10
+ HeatMap = "heat-map"
11
+ }
12
+ export interface BaseChartProps<T> {
13
+ data: T[];
14
+ style?: CSSProperties;
15
+ className?: string;
16
+ }
17
+ export interface XYAxis {
18
+ x: string | number;
19
+ y: number;
20
+ [key: string]: string | number;
21
+ }
22
+ export interface StackableChartProps extends BaseChartProps<XYAxis> {
23
+ xField?: string;
24
+ yField?: string;
25
+ stackField?: string;
26
+ }
@@ -0,0 +1,11 @@
1
+ export var ChartType = /*#__PURE__*/function (ChartType) {
2
+ ChartType["Pie"] = "pie";
3
+ ChartType["Column"] = "column";
4
+ ChartType["Line"] = "line";
5
+ ChartType["Area"] = "area";
6
+ ChartType["WordCloud"] = "word-cloud";
7
+ ChartType["PinMap"] = "pin-map";
8
+ ChartType["PathMap"] = "path-map";
9
+ ChartType["HeatMap"] = "heat-map";
10
+ return ChartType;
11
+ }({});
package/package.json ADDED
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "@antv/gpt-vis",
3
+ "version": "0.0.1",
4
+ "description": "A chart library for LLM Agent",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/antvis/gpt-vis"
8
+ },
9
+ "author": "antvis",
10
+ "sideEffects": [
11
+ "**/*.less"
12
+ ],
13
+ "module": "dist/index.js",
14
+ "typings": "dist/index.d.ts",
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "bigfish-lib build",
21
+ "build:watch": "bigfish-lib build -w",
22
+ "ci": "tnpm run lint && jest --coverage",
23
+ "cov": "jest --coverage",
24
+ "create": "bigfish-lib create",
25
+ "deploy": "bigfish-lib deploy",
26
+ "dev": "bigfish-lib doc dev",
27
+ "doctor": "bigfish-lib doctor",
28
+ "lint": "bigfish-lib lint",
29
+ "pull": "bigfish-lib pull",
30
+ "start": "tnpm run dev",
31
+ "test": "jest"
32
+ },
33
+ "commitlint": {
34
+ "extends": [
35
+ "@commitlint/config-conventional"
36
+ ]
37
+ },
38
+ "lint-staged": {
39
+ "*.{md,json}": [
40
+ "prettier --cache --write --no-error-on-unmatched-pattern"
41
+ ],
42
+ "*.{js,jsx}": [
43
+ "bigfish-lib lint --fix --eslint-only",
44
+ "prettier --cache --write"
45
+ ],
46
+ "*.{css,less}": [
47
+ "bigfish-lib lint --fix --stylelint-only",
48
+ "prettier --cache --write"
49
+ ],
50
+ "*.{ts,tsx}": [
51
+ "bigfish-lib lint --fix --eslint-only",
52
+ "prettier --cache --parser=typescript --write"
53
+ ]
54
+ },
55
+ "dependencies": {
56
+ "@ant-design/icons": "^5.4.0",
57
+ "@ant-design/plots": "^2.2.5",
58
+ "@antv/l7": "^2.22.0",
59
+ "@antv/larkmap": "^1.4.17",
60
+ "@babel/runtime": "^7.18.0",
61
+ "lodash-es": "^4.17.21",
62
+ "react-markdown": "^9.0.1",
63
+ "rehype-raw": "^7.0.0",
64
+ "styled-components": "^6.0.7"
65
+ },
66
+ "devDependencies": {
67
+ "@ali/ci": "^4.26.0",
68
+ "@alipay/bigfish-library": "^4.0.0",
69
+ "@alipay/chat-design": "^1.3.9",
70
+ "@commitlint/cli": "^17.3.0",
71
+ "@commitlint/config-conventional": "^17.3.0",
72
+ "@testing-library/jest-dom": "^5.1.1",
73
+ "@testing-library/react": "^15.0.0",
74
+ "@types/jest": "^29.4.0",
75
+ "@types/lodash-es": "^4.17.12",
76
+ "@types/react": "^18.0.0",
77
+ "antd": "^5.0.0",
78
+ "husky": "^8.0.0",
79
+ "jest": "^29.4.3",
80
+ "jest-environment-jsdom": "^29.4.3",
81
+ "lint-staged": "^13.0.0",
82
+ "prettier": "^2.0.0",
83
+ "react": "^18.0.0",
84
+ "react-dom": "^18.0.0"
85
+ },
86
+ "peerDependencies": {
87
+ "react": ">=16.9.0"
88
+ },
89
+ "publishConfig": {
90
+ "access": "public",
91
+ "registry": "https://registry.npmjs.org"
92
+ }
93
+ }