@antv/gpt-vis 0.0.6 → 0.1.0

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.
Files changed (268) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +57 -60
  3. package/README.zh-CN.md +93 -0
  4. package/dist/cjs/Area/index.d.ts +8 -2
  5. package/dist/cjs/Area/index.js +17 -16
  6. package/dist/cjs/Bar/index.d.ts +11 -0
  7. package/dist/cjs/Bar/index.js +65 -0
  8. package/dist/cjs/ChartCodeRender/Loading.d.ts +3 -0
  9. package/dist/cjs/ChartCodeRender/Loading.js +54 -0
  10. package/dist/cjs/ChartCodeRender/VisChart.d.ts +11 -0
  11. package/dist/cjs/ChartCodeRender/VisChart.js +84 -0
  12. package/dist/cjs/ChartCodeRender/index.d.ts +3 -4
  13. package/dist/cjs/ChartCodeRender/index.js +24 -68
  14. package/dist/cjs/ChartCodeRender/type.d.ts +9 -11
  15. package/dist/cjs/Column/index.d.ts +8 -2
  16. package/dist/cjs/Column/index.js +19 -27
  17. package/dist/cjs/ConfigProvider/context.d.ts +3 -0
  18. package/dist/cjs/ConfigProvider/context.js +41 -0
  19. package/dist/cjs/ConfigProvider/hooks/index.d.ts +1 -0
  20. package/dist/cjs/ConfigProvider/hooks/index.js +23 -0
  21. package/dist/cjs/ConfigProvider/hooks/useConfig.d.ts +13 -0
  22. package/dist/cjs/ConfigProvider/hooks/useConfig.js +107 -0
  23. package/dist/cjs/ConfigProvider/index.d.ts +2 -5
  24. package/dist/cjs/ConfigProvider/index.js +15 -9
  25. package/dist/cjs/DualAxes/index.d.ts +15 -0
  26. package/dist/cjs/DualAxes/index.js +71 -0
  27. package/dist/cjs/DualAxes/util.d.ts +9 -0
  28. package/dist/cjs/DualAxes/util.js +73 -0
  29. package/dist/cjs/FlowDiagram/index.d.ts +6 -0
  30. package/dist/cjs/FlowDiagram/index.js +100 -0
  31. package/dist/cjs/GPTVis/index.d.ts +7 -7
  32. package/dist/cjs/GPTVis/index.js +13 -4
  33. package/dist/cjs/HeatMap/index.d.ts +7 -7
  34. package/dist/cjs/HeatMap/index.js +13 -26
  35. package/dist/cjs/Histogram/index.d.ts +10 -0
  36. package/dist/cjs/Histogram/index.js +51 -0
  37. package/dist/cjs/IndentedTree/index.d.ts +6 -0
  38. package/dist/cjs/IndentedTree/index.js +63 -0
  39. package/dist/cjs/Line/index.d.ts +8 -6
  40. package/dist/cjs/Line/index.js +15 -16
  41. package/dist/cjs/Map/data.json +305 -0
  42. package/dist/cjs/Map/index.d.ts +5 -0
  43. package/dist/cjs/Map/index.js +68 -0
  44. package/dist/cjs/MindMap/index.d.ts +6 -0
  45. package/dist/cjs/MindMap/index.js +64 -0
  46. package/dist/cjs/NetworkGraph/index.d.ts +6 -0
  47. package/dist/cjs/NetworkGraph/index.js +72 -0
  48. package/dist/cjs/OrganizationChart/index.d.ts +6 -0
  49. package/dist/cjs/OrganizationChart/index.js +93 -0
  50. package/dist/cjs/PathMap/index.d.ts +3 -9
  51. package/dist/cjs/PathMap/index.js +19 -109
  52. package/dist/cjs/Pie/index.d.ts +7 -5
  53. package/dist/cjs/Pie/index.js +17 -13
  54. package/dist/cjs/PinMap/index.d.ts +3 -9
  55. package/dist/cjs/PinMap/index.js +6 -85
  56. package/dist/cjs/Radar/index.d.ts +11 -0
  57. package/dist/cjs/Radar/index.js +84 -0
  58. package/dist/cjs/Scatter/index.d.ts +11 -0
  59. package/dist/cjs/Scatter/index.js +57 -0
  60. package/dist/cjs/Text/VisText.d.ts +4 -0
  61. package/dist/cjs/Text/VisText.js +71 -0
  62. package/dist/cjs/Text/config.d.ts +18 -0
  63. package/dist/cjs/Text/config.js +91 -0
  64. package/dist/cjs/Text/constants.d.ts +9 -0
  65. package/dist/cjs/Text/constants.js +37 -0
  66. package/dist/cjs/Text/custom-icons/index.d.ts +3 -0
  67. package/dist/cjs/Text/custom-icons/index.js +66 -0
  68. package/dist/cjs/Text/index.d.ts +3 -0
  69. package/dist/cjs/Text/index.js +42 -0
  70. package/dist/cjs/Text/mini-charts/hooks/getElementFontSize.d.ts +1 -0
  71. package/dist/cjs/Text/mini-charts/hooks/getElementFontSize.js +65 -0
  72. package/dist/cjs/Text/mini-charts/hooks/index.d.ts +1 -0
  73. package/dist/cjs/Text/mini-charts/hooks/index.js +29 -0
  74. package/dist/cjs/Text/mini-charts/hooks/useSvgWrapper.d.ts +5 -0
  75. package/dist/cjs/Text/mini-charts/hooks/useSvgWrapper.js +65 -0
  76. package/dist/cjs/Text/mini-charts/index.d.ts +2 -0
  77. package/dist/cjs/Text/mini-charts/index.js +25 -0
  78. package/dist/cjs/Text/mini-charts/line/SingleLineChart.d.ts +3 -0
  79. package/dist/cjs/Text/mini-charts/line/SingleLineChart.js +63 -0
  80. package/dist/cjs/Text/mini-charts/line/index.d.ts +1 -0
  81. package/dist/cjs/Text/mini-charts/line/index.js +29 -0
  82. package/dist/cjs/Text/mini-charts/line/scaleLinear.d.ts +4 -0
  83. package/dist/cjs/Text/mini-charts/line/scaleLinear.js +35 -0
  84. package/dist/cjs/Text/mini-charts/line/useLineCompute.d.ts +6 -0
  85. package/dist/cjs/Text/mini-charts/line/useLineCompute.js +103 -0
  86. package/dist/cjs/Text/mini-charts/proportion/getArcPath.d.ts +1 -0
  87. package/dist/cjs/Text/mini-charts/proportion/getArcPath.js +51 -0
  88. package/dist/cjs/Text/mini-charts/proportion/index.d.ts +3 -0
  89. package/dist/cjs/Text/mini-charts/proportion/index.js +72 -0
  90. package/dist/cjs/Text/types.d.ts +20 -0
  91. package/dist/cjs/Text/types.js +17 -0
  92. package/dist/cjs/Treemap/index.d.ts +11 -0
  93. package/dist/cjs/Treemap/index.js +73 -0
  94. package/dist/cjs/WordCloud/index.d.ts +4 -5
  95. package/dist/cjs/WordCloud/index.js +7 -15
  96. package/dist/cjs/constants/index.d.ts +1 -3
  97. package/dist/cjs/constants/index.js +4 -35
  98. package/dist/cjs/export.d.ts +25 -0
  99. package/dist/cjs/export.js +119 -0
  100. package/dist/cjs/index.d.ts +4 -10
  101. package/dist/cjs/index.js +5 -27
  102. package/dist/cjs/types/chart.d.ts +49 -14
  103. package/dist/cjs/types/chart.js +12 -0
  104. package/dist/cjs/types/config.d.ts +11 -0
  105. package/dist/cjs/types/index.d.ts +1 -1
  106. package/dist/cjs/types/index.js +0 -9
  107. package/dist/cjs/types/map.d.ts +242 -0
  108. package/dist/cjs/types/map.js +17 -0
  109. package/dist/cjs/utils/config.d.ts +5 -5
  110. package/dist/cjs/utils/config.js +41 -24
  111. package/dist/cjs/utils/graph.d.ts +18 -0
  112. package/dist/cjs/utils/graph.js +64 -0
  113. package/dist/cjs/utils/index.d.ts +1 -1
  114. package/dist/cjs/utils/index.js +3 -13
  115. package/dist/cjs/utils/map/context.d.ts +3 -0
  116. package/dist/cjs/utils/map/context.js +42 -0
  117. package/dist/cjs/utils/map/controls.d.ts +0 -0
  118. package/dist/cjs/utils/map/controls.js +0 -0
  119. package/dist/cjs/utils/map/index.d.ts +6 -0
  120. package/dist/cjs/utils/map/index.js +33 -0
  121. package/dist/cjs/utils/map/markers.d.ts +2 -0
  122. package/dist/cjs/utils/map/markers.js +88 -0
  123. package/dist/cjs/utils/map/polyline.d.ts +2 -0
  124. package/dist/cjs/utils/map/polyline.js +52 -0
  125. package/dist/cjs/utils/map/style.d.ts +45 -0
  126. package/dist/cjs/utils/map/style.js +112 -0
  127. package/dist/cjs/utils/map/util.d.ts +1 -0
  128. package/dist/cjs/utils/map/util.js +38 -0
  129. package/dist/cjs/utils/map/view.d.ts +3 -0
  130. package/dist/cjs/utils/map/view.js +93 -0
  131. package/dist/cjs/utils/plot.d.ts +4 -0
  132. package/dist/cjs/utils/plot.js +69 -0
  133. package/dist/cjs/version.d.ts +2 -0
  134. package/dist/cjs/version.js +25 -0
  135. package/dist/esm/Area/index.d.ts +8 -2
  136. package/dist/esm/Area/index.js +21 -27
  137. package/dist/esm/Bar/index.d.ts +11 -0
  138. package/dist/esm/Bar/index.js +35 -0
  139. package/dist/esm/ChartCodeRender/Loading.d.ts +3 -0
  140. package/dist/esm/ChartCodeRender/Loading.js +20 -0
  141. package/dist/esm/ChartCodeRender/VisChart.d.ts +11 -0
  142. package/dist/esm/ChartCodeRender/VisChart.js +65 -0
  143. package/dist/esm/ChartCodeRender/index.d.ts +3 -4
  144. package/dist/esm/ChartCodeRender/index.js +28 -84
  145. package/dist/esm/ChartCodeRender/type.d.ts +9 -11
  146. package/dist/esm/Column/index.d.ts +8 -2
  147. package/dist/esm/Column/index.js +22 -27
  148. package/dist/esm/ConfigProvider/context.d.ts +3 -0
  149. package/dist/esm/ConfigProvider/context.js +3 -0
  150. package/dist/esm/ConfigProvider/hooks/index.d.ts +1 -0
  151. package/dist/esm/ConfigProvider/hooks/index.js +1 -0
  152. package/dist/esm/ConfigProvider/hooks/useConfig.d.ts +13 -0
  153. package/dist/esm/ConfigProvider/hooks/useConfig.js +55 -0
  154. package/dist/esm/ConfigProvider/index.d.ts +2 -5
  155. package/dist/esm/ConfigProvider/index.js +9 -9
  156. package/dist/esm/DualAxes/index.d.ts +15 -0
  157. package/dist/esm/DualAxes/index.js +44 -0
  158. package/dist/esm/DualAxes/util.d.ts +9 -0
  159. package/dist/esm/DualAxes/util.js +61 -0
  160. package/dist/esm/FlowDiagram/index.d.ts +6 -0
  161. package/dist/esm/FlowDiagram/index.js +75 -0
  162. package/dist/esm/GPTVis/index.d.ts +7 -7
  163. package/dist/esm/GPTVis/index.js +9 -5
  164. package/dist/esm/HeatMap/index.d.ts +7 -7
  165. package/dist/esm/HeatMap/index.js +19 -27
  166. package/dist/esm/Histogram/index.d.ts +10 -0
  167. package/dist/esm/Histogram/index.js +25 -0
  168. package/dist/esm/IndentedTree/index.d.ts +6 -0
  169. package/dist/esm/IndentedTree/index.js +47 -0
  170. package/dist/esm/Line/index.d.ts +8 -6
  171. package/dist/esm/Line/index.js +17 -23
  172. package/dist/esm/Map/data.json +305 -0
  173. package/dist/esm/Map/index.d.ts +5 -0
  174. package/dist/esm/Map/index.js +60 -0
  175. package/dist/esm/MindMap/index.d.ts +6 -0
  176. package/dist/esm/MindMap/index.js +48 -0
  177. package/dist/esm/NetworkGraph/index.d.ts +6 -0
  178. package/dist/esm/NetworkGraph/index.js +57 -0
  179. package/dist/esm/OrganizationChart/index.d.ts +6 -0
  180. package/dist/esm/OrganizationChart/index.js +64 -0
  181. package/dist/esm/PathMap/index.d.ts +3 -9
  182. package/dist/esm/PathMap/index.js +32 -129
  183. package/dist/esm/Pie/index.d.ts +7 -5
  184. package/dist/esm/Pie/index.js +24 -20
  185. package/dist/esm/PinMap/index.d.ts +3 -9
  186. package/dist/esm/PinMap/index.js +18 -104
  187. package/dist/esm/Radar/index.d.ts +11 -0
  188. package/dist/esm/Radar/index.js +54 -0
  189. package/dist/esm/Scatter/index.d.ts +11 -0
  190. package/dist/esm/Scatter/index.js +30 -0
  191. package/dist/esm/Text/VisText.d.ts +4 -0
  192. package/dist/esm/Text/VisText.js +34 -0
  193. package/dist/esm/Text/config.d.ts +18 -0
  194. package/dist/esm/Text/config.js +79 -0
  195. package/dist/esm/Text/constants.d.ts +9 -0
  196. package/dist/esm/Text/constants.js +9 -0
  197. package/dist/esm/Text/custom-icons/index.d.ts +3 -0
  198. package/dist/esm/Text/custom-icons/index.js +37 -0
  199. package/dist/esm/Text/index.d.ts +3 -0
  200. package/dist/esm/Text/index.js +2 -0
  201. package/dist/esm/Text/mini-charts/hooks/getElementFontSize.d.ts +1 -0
  202. package/dist/esm/Text/mini-charts/hooks/getElementFontSize.js +32 -0
  203. package/dist/esm/Text/mini-charts/hooks/index.d.ts +1 -0
  204. package/dist/esm/Text/mini-charts/hooks/index.js +1 -0
  205. package/dist/esm/Text/mini-charts/hooks/useSvgWrapper.d.ts +5 -0
  206. package/dist/esm/Text/mini-charts/hooks/useSvgWrapper.js +31 -0
  207. package/dist/esm/Text/mini-charts/index.d.ts +2 -0
  208. package/dist/esm/Text/mini-charts/index.js +2 -0
  209. package/dist/esm/Text/mini-charts/line/SingleLineChart.d.ts +3 -0
  210. package/dist/esm/Text/mini-charts/line/SingleLineChart.js +57 -0
  211. package/dist/esm/Text/mini-charts/line/index.d.ts +1 -0
  212. package/dist/esm/Text/mini-charts/line/index.js +1 -0
  213. package/dist/esm/Text/mini-charts/line/scaleLinear.d.ts +4 -0
  214. package/dist/esm/Text/mini-charts/line/scaleLinear.js +14 -0
  215. package/dist/esm/Text/mini-charts/line/useLineCompute.d.ts +6 -0
  216. package/dist/esm/Text/mini-charts/line/useLineCompute.js +106 -0
  217. package/dist/esm/Text/mini-charts/proportion/getArcPath.d.ts +1 -0
  218. package/dist/esm/Text/mini-charts/proportion/getArcPath.js +19 -0
  219. package/dist/esm/Text/mini-charts/proportion/index.d.ts +3 -0
  220. package/dist/esm/Text/mini-charts/proportion/index.js +60 -0
  221. package/dist/esm/Text/types.d.ts +20 -0
  222. package/dist/esm/Text/types.js +1 -0
  223. package/dist/esm/Treemap/index.d.ts +11 -0
  224. package/dist/esm/Treemap/index.js +52 -0
  225. package/dist/esm/WordCloud/index.d.ts +4 -5
  226. package/dist/esm/WordCloud/index.js +8 -18
  227. package/dist/esm/constants/index.d.ts +1 -3
  228. package/dist/esm/constants/index.js +5 -14
  229. package/dist/esm/export.d.ts +25 -0
  230. package/dist/esm/export.js +27 -0
  231. package/dist/esm/index.d.ts +4 -10
  232. package/dist/esm/index.js +2 -9
  233. package/dist/esm/types/chart.d.ts +49 -14
  234. package/dist/esm/types/chart.js +12 -0
  235. package/dist/esm/types/config.d.ts +11 -0
  236. package/dist/esm/types/index.d.ts +1 -1
  237. package/dist/esm/types/index.js +1 -1
  238. package/dist/esm/types/map.d.ts +242 -0
  239. package/dist/esm/types/map.js +1 -0
  240. package/dist/esm/utils/config.d.ts +5 -5
  241. package/dist/esm/utils/config.js +40 -18
  242. package/dist/esm/utils/graph.d.ts +18 -0
  243. package/dist/esm/utils/graph.js +49 -0
  244. package/dist/esm/utils/index.d.ts +1 -1
  245. package/dist/esm/utils/index.js +1 -1
  246. package/dist/esm/utils/map/context.d.ts +3 -0
  247. package/dist/esm/utils/map/context.js +34 -0
  248. package/dist/esm/utils/map/controls.d.ts +0 -0
  249. package/dist/esm/utils/map/controls.js +0 -0
  250. package/dist/esm/utils/map/index.d.ts +6 -0
  251. package/dist/esm/utils/map/index.js +6 -0
  252. package/dist/esm/utils/map/markers.d.ts +2 -0
  253. package/dist/esm/utils/map/markers.js +64 -0
  254. package/dist/esm/utils/map/polyline.d.ts +2 -0
  255. package/dist/esm/utils/map/polyline.js +26 -0
  256. package/dist/esm/utils/map/style.d.ts +45 -0
  257. package/dist/esm/utils/map/style.js +76 -0
  258. package/dist/esm/utils/map/util.d.ts +1 -0
  259. package/dist/esm/utils/map/util.js +11 -0
  260. package/dist/esm/utils/map/view.d.ts +3 -0
  261. package/dist/esm/utils/map/view.js +81 -0
  262. package/dist/esm/utils/plot.d.ts +4 -0
  263. package/dist/esm/utils/plot.js +65 -0
  264. package/dist/esm/version.d.ts +2 -0
  265. package/dist/esm/version.js +1 -0
  266. package/dist/umd/861.async.js +1 -0
  267. package/dist/umd/index.min.js +1 -0
  268. package/package.json +97 -58
@@ -1,40 +1,34 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- // 引入必要的包
4
1
  import { Area as ADCArea } from '@ant-design/plots';
2
+ import { get } from 'lodash';
5
3
  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,
4
+ import { usePlotConfig } from "../ConfigProvider/hooks";
5
+ var defaultConfig = function defaultConfig(props) {
6
+ var data = props.data,
11
7
  _props$xField = props.xField,
12
- xField = _props$xField === void 0 ? 'x' : _props$xField,
8
+ xField = _props$xField === void 0 ? 'time' : _props$xField,
13
9
  _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,
10
+ yField = _props$yField === void 0 ? 'value' : _props$yField;
11
+ var hasGroupField = get(data, '[0].group') !== undefined;
12
+ var axisYTitle = get(props, 'axis.y.title');
13
+ var defalutStyle = hasGroupField ? {} : {
14
+ opacity: 0.6
15
+ };
16
+ return {
26
17
  xField: xField,
27
18
  yField: yField,
19
+ style: defalutStyle,
20
+ colorField: hasGroupField ? 'group' : undefined,
28
21
  tooltip: function tooltip(d) {
22
+ var tooltipName = axisYTitle || d[xField];
29
23
  return {
30
- name: d[xField],
24
+ name: tooltipName,
31
25
  value: d[yField]
32
26
  };
33
27
  }
34
- }, stackConfig);
35
- return /*#__PURE__*/React.createElement(ADCArea, _extends({
36
- className: className,
37
- containerStyle: _objectSpread({}, style)
38
- }, config));
28
+ };
29
+ };
30
+ var Area = function Area(props) {
31
+ var config = usePlotConfig('Area', defaultConfig, props);
32
+ return /*#__PURE__*/React.createElement(ADCArea, config);
39
33
  };
40
34
  export default Area;
@@ -0,0 +1,11 @@
1
+ import type { BarConfig } from '@ant-design/plots';
2
+ import React from 'react';
3
+ import type { BasePlotProps } from '../types';
4
+ type BarDataItem = {
5
+ category: string;
6
+ value: number;
7
+ [key: string]: string | number;
8
+ };
9
+ export type BarProps = BasePlotProps<BarDataItem> & Partial<BarConfig>;
10
+ declare const Bar: (props: BarProps) => React.JSX.Element;
11
+ export default Bar;
@@ -0,0 +1,35 @@
1
+ import { Bar as ADCBar } from '@ant-design/plots';
2
+ import { get } from 'lodash';
3
+ import React from 'react';
4
+ import { usePlotConfig } from "../ConfigProvider/hooks";
5
+ var defaultConfig = function defaultConfig(props) {
6
+ var data = props.data,
7
+ _props$xField = props.xField,
8
+ xField = _props$xField === void 0 ? 'category' : _props$xField,
9
+ _props$yField = props.yField,
10
+ yField = _props$yField === void 0 ? 'value' : _props$yField;
11
+ var hasGroupField = get(data, '[0].group') !== undefined;
12
+ var axisYTitle = get(props, 'axis.y.title');
13
+ return {
14
+ xField: xField,
15
+ yField: yField,
16
+ colorField: hasGroupField ? 'group' : undefined,
17
+ tooltip: function tooltip(d) {
18
+ var tooltipName = axisYTitle || d[xField];
19
+ return {
20
+ name: tooltipName,
21
+ value: d[yField]
22
+ };
23
+ },
24
+ style: {
25
+ // 圆角样式
26
+ radiusTopLeft: 5,
27
+ radiusTopRight: 5
28
+ }
29
+ };
30
+ };
31
+ var Bar = function Bar(props) {
32
+ var config = usePlotConfig('Bar', defaultConfig, props);
33
+ return /*#__PURE__*/React.createElement(ADCBar, config);
34
+ };
35
+ export default Bar;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const Loading: () => React.JSX.Element;
3
+ export default Loading;
@@ -0,0 +1,20 @@
1
+ import { LoadingOutlined } from '@ant-design/icons';
2
+ import React from 'react';
3
+ import styled from 'styled-components';
4
+ var StyledLoading = styled.div.withConfig({
5
+ displayName: "StyledLoading",
6
+ componentId: "gpt-vis-c7ef__sc-4x7w8p-0"
7
+ })(["display:flex;align-items:center;justify-content:center;flex-direction:column;height:300px;background-image:linear-gradient(135deg,#e3f3ff 0%,#f1eeff 100%);color:rgba(0,0,0,88%);&-icon{margin-bottom:6px;}"]);
8
+ var Loading = function Loading() {
9
+ return /*#__PURE__*/React.createElement(StyledLoading, {
10
+ className: "gpt-vis-loading"
11
+ }, /*#__PURE__*/React.createElement("div", {
12
+ className: "gpt-vis-loading-icon"
13
+ }, /*#__PURE__*/React.createElement(LoadingOutlined, {
14
+ style: {
15
+ fontSize: '24px',
16
+ color: 'rgb(56, 177, 246)'
17
+ }
18
+ })), /*#__PURE__*/React.createElement("p", null, "\u6570\u636E\u751F\u6210\u4E2D"));
19
+ };
20
+ export default Loading;
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import type { ChartComponents } from './type';
3
+ type RenderVisChartProps = {
4
+ content: string;
5
+ components: ChartComponents;
6
+ debug?: boolean;
7
+ loadingTimeout: number;
8
+ style?: React.CSSProperties;
9
+ };
10
+ export declare const RenderVisChart: React.FC<RenderVisChartProps>;
11
+ export {};
@@ -0,0 +1,65 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ var _excluded = ["type"];
4
+ import React, { memo, useRef, useState } from 'react';
5
+ import styled, { createGlobalStyle } from 'styled-components';
6
+ import Loading from "./Loading";
7
+ var StyledGPTVis = styled.div.withConfig({
8
+ displayName: "StyledGPTVis",
9
+ componentId: "gpt-vis-c7ef__sc-1f5p953-0"
10
+ })(["min-width:300px;height:300px;max-width:100%;"]);
11
+ var GlobalStyles = createGlobalStyle(["pre:has(.gpt-vis){overflow:hidden;}"]);
12
+ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
13
+ var style = _ref.style,
14
+ content = _ref.content,
15
+ components = _ref.components,
16
+ debug = _ref.debug,
17
+ loadingTimeout = _ref.loadingTimeout;
18
+ var timeoutRef = useRef();
19
+ var _useState = useState(true),
20
+ _useState2 = _slicedToArray(_useState, 2),
21
+ loading = _useState2[0],
22
+ setLoading = _useState2[1];
23
+ var chartJson;
24
+ try {
25
+ chartJson = JSON.parse(content);
26
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
27
+ } catch (e) {
28
+ if (timeoutRef.current) {
29
+ clearTimeout(timeoutRef.current);
30
+ if (debug) {
31
+ console.warn('GPT-Vis withChartCode parse content timeout');
32
+ }
33
+ }
34
+ timeoutRef.current = setTimeout(function () {
35
+ setLoading(false);
36
+ }, loadingTimeout);
37
+ if (loading) {
38
+ return /*#__PURE__*/React.createElement(StyledGPTVis, {
39
+ className: "gpt-vis",
40
+ style: style
41
+ }, /*#__PURE__*/React.createElement(Loading, null));
42
+ }
43
+ return /*#__PURE__*/React.createElement("p", null, "Chart generation timeout.");
44
+ }
45
+ var _chartJson = chartJson,
46
+ type = _chartJson.type,
47
+ chartProps = _objectWithoutProperties(_chartJson, _excluded);
48
+ var ChartComponent = components[type];
49
+
50
+ // debug mode print chartJson
51
+ if (debug) {
52
+ console.log('GPT-Vis withChartCode get chartJson parse from vis-chart code block', chartJson);
53
+ }
54
+
55
+ // If the chart type is not supported, display an error message
56
+ if (!ChartComponent) {
57
+ return /*#__PURE__*/React.createElement("p", null, "Chart type \"".concat(type, "\" is not supported."));
58
+ }
59
+
60
+ // Render the supported chart component with data
61
+ return /*#__PURE__*/React.createElement(StyledGPTVis, {
62
+ className: "gpt-vis",
63
+ style: style
64
+ }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ChartComponent, chartProps));
65
+ });
@@ -1,9 +1,8 @@
1
- import React from 'react';
2
- import { WithChartCodeOptions } from './type';
3
- 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;
1
+ import type { CodeBlockComponent, WithChartCodeOptions } from './type';
2
+ export declare const withChartCode: (options: WithChartCodeOptions) => CodeBlockComponent;
4
3
  /**
5
4
  * Includes built-in chart components such as line charts, pie charts, etc.
6
5
  * @param componentsArray
7
6
  * @returns
8
7
  */
9
- 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;
8
+ export declare const withDefaultChartCode: (options?: Partial<WithChartCodeOptions>) => CodeBlockComponent;
@@ -1,122 +1,66 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
2
  import _extends from "@babel/runtime/helpers/esm/extends";
4
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
4
  var _excluded = ["children", "className", "node"];
7
- import { LoadingOutlined } from '@ant-design/icons';
8
5
  import { get } from 'lodash';
9
- import React, { useRef, useState } from 'react';
10
- import styled from 'styled-components';
11
- import { DEFAULT_CHART_COMPONENTS } from "../constants";
12
- var StyledGPTVis = styled.div.withConfig({
13
- displayName: "StyledGPTVis",
14
- componentId: "gpt-vis-ed04__sc-1osp6pj-0"
15
- })(["min-width:600px;max-width:100%;"]);
16
- var StyledLoading = styled.div.withConfig({
17
- displayName: "StyledLoading",
18
- componentId: "gpt-vis-ed04__sc-1osp6pj-1"
19
- })(["display:flex;align-items:center;justify-content:center;flex-direction:column;width:400px;height:400px;background-image:linear-gradient(135deg,#e3f3ff 0%,#f1eeff 100%);color:rgba(0,0,0,88%);&-icon{margin-bottom:6px;}"]);
20
- var Loading = function Loading() {
21
- return /*#__PURE__*/React.createElement(StyledLoading, {
22
- className: "gpt-vis-loading"
23
- }, /*#__PURE__*/React.createElement("div", {
24
- className: "gpt-vis-loading-icon"
25
- }, /*#__PURE__*/React.createElement(LoadingOutlined, {
26
- style: {
27
- fontSize: '24px',
28
- color: 'rgb(56, 177, 246)'
29
- }
30
- })), /*#__PURE__*/React.createElement("p", null, "\u6570\u636E\u751F\u6210\u4E2D"));
6
+ import React from 'react';
7
+ import { DEFAULT_CHART_COMPONENTS } from "../export";
8
+ import { RenderVisChart } from "./VisChart";
9
+ var RenderDefaultCode = function RenderDefaultCode(props) {
10
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
+ var children = props.children,
12
+ _props$className = props.className,
13
+ className = _props$className === void 0 ? '' : _props$className,
14
+ node = props.node,
15
+ rest = _objectWithoutProperties(props, _excluded);
16
+ return /*#__PURE__*/React.createElement("code", _extends({}, rest, {
17
+ className: className
18
+ }), children);
31
19
  };
32
20
  var withCodeBlock = function withCodeBlock(options) {
33
21
  // Render code block component
34
22
  return function CodeBlock(props) {
35
23
  var _className$match;
36
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
24
  var children = props.children,
38
- _props$className = props.className,
39
- className = _props$className === void 0 ? '' : _props$className,
40
- node = props.node,
41
- rest = _objectWithoutProperties(props, _excluded);
25
+ _props$className2 = props.className,
26
+ className = _props$className2 === void 0 ? '' : _props$className2;
42
27
  var content = String(children).trim();
43
28
  var isVisChart = className.includes('language-vis-chart');
44
29
  var components = options.components,
45
- extraRenderers = options.extraRenderers,
46
30
  languageRenderers = options.languageRenderers,
47
31
  DefaultRenderer = options.defaultRenderer,
48
32
  debug = options.debug,
49
33
  _options$loadingTimeo = options.loadingTimeout,
50
- loadingTimeout = _options$loadingTimeo === void 0 ? 5000 : _options$loadingTimeo;
51
- var timeoutRef = useRef();
52
- var _useState = useState(true),
53
- _useState2 = _slicedToArray(_useState, 2),
54
- loading = _useState2[0],
55
- setLoading = _useState2[1];
34
+ loadingTimeout = _options$loadingTimeo === void 0 ? 5000 : _options$loadingTimeo,
35
+ style = options.style;
56
36
 
57
37
  // If the code block is a VisChart, render the corresponding chart component
58
38
  if (isVisChart) {
59
- var chartJson;
60
- try {
61
- chartJson = JSON.parse(content);
62
- } catch (e) {
63
- if (timeoutRef.current) {
64
- clearTimeout(timeoutRef.current);
65
- if (debug) {
66
- console.log('GPT-Vis withChartCode parse content timeout');
67
- }
68
- }
69
- timeoutRef.current = setTimeout(function () {
70
- setLoading(false);
71
- }, loadingTimeout);
72
- return loading ? /*#__PURE__*/React.createElement(Loading, null) : /*#__PURE__*/React.createElement("code", null, content.toString());
73
- }
74
- var _chartJson = chartJson,
75
- type = _chartJson.type;
76
- var ChartComponent = components[type];
77
-
78
- // debug mode print chartJson
79
- if (debug) {
80
- console.log('GPT-Vis withChartCode get chartJson parse from vis-chart code block', chartJson);
81
- }
82
-
83
- // If the chart type is not supported, display an error message
84
- if (!ChartComponent) {
85
- return /*#__PURE__*/React.createElement("code", null, "Chart type \"".concat(type, "\" is not supported."));
86
- }
87
-
88
- // Render the supported chart component with data
89
-
90
- return /*#__PURE__*/React.createElement(StyledGPTVis, {
91
- className: "gpt-vis"
92
- }, /*#__PURE__*/React.createElement(ChartComponent, chartJson));
39
+ return /*#__PURE__*/React.createElement(RenderVisChart, {
40
+ style: style,
41
+ content: content,
42
+ components: components,
43
+ debug: debug,
44
+ loadingTimeout: loadingTimeout
45
+ });
93
46
  }
94
47
 
95
48
  // If the code block math extraRenderer languageName, the corresponding extra languageRenderers component
96
49
  var languageName = ((_className$match = className.match(/language-(.*)/)) === null || _className$match === void 0 ? void 0 : _className$match[1]) || '';
97
- var extraLanguageRenderers = extraRenderers || languageRenderers;
50
+ var extraLanguageRenderers = languageRenderers;
98
51
  var ExtraRendererComponent = extraLanguageRenderers && extraLanguageRenderers[languageName];
99
52
  if (ExtraRendererComponent) {
100
53
  return /*#__PURE__*/React.createElement(ExtraRendererComponent, props);
101
54
  }
102
55
 
103
56
  // If the code block is not a VisChart, render plain code
104
- return DefaultRenderer ? /*#__PURE__*/React.createElement(DefaultRenderer, props) : /*#__PURE__*/React.createElement("code", _extends({}, rest, {
105
- className: className
106
- }), children);
57
+ return DefaultRenderer ? /*#__PURE__*/React.createElement(DefaultRenderer, props) : /*#__PURE__*/React.createElement(RenderDefaultCode, props);
107
58
  };
108
59
  };
109
60
 
110
61
  // Create a higher-order component (HOC) with chart code
111
62
  export var withChartCode = function withChartCode(options) {
112
- var _options$components;
113
- // Flatten the components array into a single object
114
- var components = ((_options$components = options.components) === null || _options$components === void 0 ? void 0 : _options$components.reduce(function (acc, obj) {
115
- return _objectSpread(_objectSpread({}, acc), obj);
116
- }, {})) || [];
117
- return withCodeBlock(_objectSpread(_objectSpread({}, options), {}, {
118
- components: components
119
- }));
63
+ return withCodeBlock(options);
120
64
  };
121
65
 
122
66
  /**
@@ -126,6 +70,6 @@ export var withChartCode = function withChartCode(options) {
126
70
  */
127
71
  export var withDefaultChartCode = function withDefaultChartCode(options) {
128
72
  return withChartCode(_objectSpread(_objectSpread({}, options), {}, {
129
- components: [DEFAULT_CHART_COMPONENTS].concat(_toConsumableArray(get(options, 'components', [])))
73
+ components: _objectSpread(_objectSpread({}, DEFAULT_CHART_COMPONENTS), get(options, 'components', {}))
130
74
  }));
131
75
  };
@@ -1,16 +1,10 @@
1
- import { FC } from 'react';
2
- import { Components, ExtraProps } from 'react-markdown';
3
- import { BaseChartProps } from '../types';
1
+ import type { FC } from 'react';
2
+ import type { Components, ExtraProps } from 'react-markdown';
4
3
  export type WithChartCodeOptions = {
5
4
  /**
6
5
  * 要额外加载的图表组件
7
6
  */
8
- components: ChartComponents[];
9
- /**
10
- * @deprecated
11
- * 请使用 languageRenderers
12
- */
13
- extraRenderers?: LanguageRenderers;
7
+ components: ChartComponents;
14
8
  /**
15
9
  * 自定义其它语言代码块渲染器
16
10
  */
@@ -27,19 +21,23 @@ export type WithChartCodeOptions = {
27
21
  * 设置loading动画的超时时间,默认为 5s
28
22
  */
29
23
  loadingTimeout?: number;
24
+ /**
25
+ * 图表样式,配置容器样式
26
+ */
27
+ style?: React.CSSProperties;
30
28
  };
31
29
  /**
32
30
  * 图表渲染数据接口,后续拓展,这里只是写个示例
33
31
  */
34
32
  export interface ChartJson {
35
33
  type: string;
36
- data: any[];
34
+ data: any;
37
35
  }
38
36
  /**
39
37
  * 图表组件字典
40
38
  */
41
39
  export interface ChartComponents {
42
- [key: string]: FC<BaseChartProps<any>>;
40
+ [key: string]: FC<any>;
43
41
  }
44
42
  /**
45
43
  * 代码块渲染器接口
@@ -1,5 +1,11 @@
1
+ import type { ColumnConfig } from '@ant-design/plots';
1
2
  import React from 'react';
2
- import { StackableChartProps } from '../types';
3
- export type ColumnProps = StackableChartProps;
3
+ import type { BasePlotProps } from '../types';
4
+ export type ColumnDataItem = {
5
+ category: string | number;
6
+ value: number;
7
+ [key: string]: string | number;
8
+ };
9
+ export type ColumnProps = BasePlotProps<ColumnDataItem> & Partial<ColumnConfig>;
4
10
  declare const Column: (props: ColumnProps) => React.JSX.Element;
5
11
  export default Column;
@@ -1,40 +1,35 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
1
  import { Column as ADCColumn } from '@ant-design/plots';
2
+ import { get } from 'lodash';
4
3
  import React from 'react';
5
- var Column = function Column(props) {
6
- var _props$data = props.data,
7
- data = _props$data === void 0 ? [] : _props$data,
4
+ import { usePlotConfig } from "../ConfigProvider/hooks";
5
+ var defaultConfig = function defaultConfig(props) {
6
+ var data = props.data,
8
7
  _props$xField = props.xField,
9
- xField = _props$xField === void 0 ? 'x' : _props$xField,
8
+ xField = _props$xField === void 0 ? 'category' : _props$xField,
10
9
  _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,
10
+ yField = _props$yField === void 0 ? 'value' : _props$yField;
11
+ var hasGroupField = get(data, '[0].group') !== undefined;
12
+ var axisYTitle = get(props, 'axis.y.title');
13
+ return {
21
14
  xField: xField,
22
15
  yField: yField,
23
- style: {
24
- // 圆角样式
25
- radiusTopLeft: 10,
26
- radiusTopRight: 10
27
- },
16
+ colorField: hasGroupField ? 'group' : undefined,
28
17
  tooltip: function tooltip(d) {
18
+ var tooltipName = axisYTitle || d[xField];
29
19
  return {
30
- name: d[xField],
20
+ name: tooltipName,
31
21
  value: d[yField]
32
22
  };
23
+ },
24
+ style: {
25
+ // 圆角样式
26
+ radiusTopLeft: 10,
27
+ radiusTopRight: 10
33
28
  }
34
- }, stackConfig);
35
- return /*#__PURE__*/React.createElement(ADCColumn, _extends({
36
- className: className,
37
- containerStyle: _objectSpread({}, style)
38
- }, config));
29
+ };
30
+ };
31
+ var Column = function Column(props) {
32
+ var config = usePlotConfig('Column', defaultConfig, props);
33
+ return /*#__PURE__*/React.createElement(ADCColumn, config);
39
34
  };
40
35
  export default Column;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { GlobalConfig } from '../types';
3
+ export declare const ConfigContext: React.Context<GlobalConfig>;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { DEFAULT_GLOBAL_CONFIG } from "../constants";
3
+ export var ConfigContext = /*#__PURE__*/React.createContext(DEFAULT_GLOBAL_CONFIG);
@@ -0,0 +1 @@
1
+ export * from './useConfig';
@@ -0,0 +1 @@
1
+ export * from "./useConfig";
@@ -0,0 +1,13 @@
1
+ import type { GraphOptions } from '@ant-design/graphs';
2
+ import type { CommonConfig } from '@ant-design/plots';
3
+ import type { MapProps } from '../../Map';
4
+ import type { Charts } from '../../types';
5
+ export declare function useComponentGlobalConfig(name: Charts): Record<string, any> | undefined;
6
+ export declare function usePlotConfig<T extends CommonConfig>(name: Charts, defaultConfig: Partial<T> | ((props: Partial<T>) => Partial<T>), props: Partial<T>): Partial<T>;
7
+ export declare function useMapConfig<T extends MapProps>(name: Charts, props: T): {
8
+ mapType: string | undefined;
9
+ token: string | undefined;
10
+ } & T;
11
+ export declare function useGraphConfig<T extends GraphOptions>(name: Charts, defaultConfig: T, props: T): {
12
+ [x: string]: any;
13
+ };
@@ -0,0 +1,55 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import React from 'react';
3
+ import { mergeGraphOptions } from "../../utils/config";
4
+ import { transform2ADCProps } from "../../utils/plot";
5
+ import { ConfigContext } from "../context";
6
+ function useConfig() {
7
+ var context = React.useContext(ConfigContext);
8
+ return context;
9
+ }
10
+ export function useComponentGlobalConfig(name) {
11
+ var globalConfig = useConfig();
12
+ var _globalConfig$compone = globalConfig.components,
13
+ components = _globalConfig$compone === void 0 ? {} : _globalConfig$compone;
14
+ var config = components === null || components === void 0 ? void 0 : components[name];
15
+ return config;
16
+ }
17
+ function usePlotGlobalConfig(name) {
18
+ var componentConfig = useComponentGlobalConfig(name);
19
+ var _useConfig = useConfig(),
20
+ plotConfig = _useConfig.plot;
21
+ var config = _objectSpread(_objectSpread({}, plotConfig), componentConfig);
22
+ return config;
23
+ }
24
+ export function usePlotConfig(name, defaultConfig, props) {
25
+ var transformedProps = transform2ADCProps(props);
26
+ var _defaultConfig = typeof defaultConfig === 'function' ? defaultConfig(transformedProps) : defaultConfig;
27
+ var globalConfig = usePlotGlobalConfig(name);
28
+ var config = _objectSpread(_objectSpread(_objectSpread({}, _defaultConfig), globalConfig), transformedProps);
29
+ return config;
30
+ }
31
+ function useMapGlobalConfig(name) {
32
+ var componentConfig = useComponentGlobalConfig(name);
33
+ var _useConfig2 = useConfig(),
34
+ mapConfig = _useConfig2.map;
35
+ var transformedProps = {
36
+ mapType: mapConfig === null || mapConfig === void 0 ? void 0 : mapConfig.style,
37
+ token: mapConfig === null || mapConfig === void 0 ? void 0 : mapConfig.token
38
+ };
39
+ var config = _objectSpread(_objectSpread({}, transformedProps), componentConfig);
40
+ return config;
41
+ }
42
+ export function useMapConfig(name, props) {
43
+ var globalConfig = useMapGlobalConfig(name);
44
+ var mapConfig = _objectSpread(_objectSpread({}, globalConfig), props);
45
+ return mapConfig;
46
+ }
47
+ function useGraphGlobalConfig(name) {
48
+ // TODO: global config
49
+ var componentConfig = useComponentGlobalConfig(name);
50
+ return componentConfig || {};
51
+ }
52
+ export function useGraphConfig(name, defaultConfig, props) {
53
+ var globalConfig = useGraphGlobalConfig(name);
54
+ return mergeGraphOptions(defaultConfig, globalConfig, props);
55
+ }
@@ -1,10 +1,7 @@
1
1
  import React from 'react';
2
- import { GlobalConfig } from '../types';
3
- import { setGlobalConfig } from '../utils';
2
+ import type { GlobalConfig } from '../types';
4
3
  export type ConfigProviderProps = {
5
4
  children?: React.ReactNode;
6
5
  } & GlobalConfig;
7
- declare const ConfigProvider: React.FC<ConfigProviderProps> & {
8
- config: typeof setGlobalConfig;
9
- };
6
+ declare const ConfigProvider: React.FC<ConfigProviderProps>;
10
7
  export default ConfigProvider;
@@ -1,16 +1,16 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  var _excluded = ["children"];
3
- import { useRef } from 'react';
4
- import { setGlobalConfig } from "../utils";
3
+ import React, { useMemo } from 'react';
4
+ import { mergeGlobalConfig } from "../utils/config";
5
+ import { ConfigContext } from "./context";
5
6
  var ConfigProvider = function ConfigProvider(props) {
6
7
  var children = props.children,
7
8
  config = _objectWithoutProperties(props, _excluded);
8
- var firstRef = useRef(true);
9
- if (firstRef.current) {
10
- setGlobalConfig(config);
11
- firstRef.current = false;
12
- }
13
- return children;
9
+ var contextValue = useMemo(function () {
10
+ return mergeGlobalConfig(config);
11
+ }, []);
12
+ return /*#__PURE__*/React.createElement(ConfigContext.Provider, {
13
+ value: contextValue
14
+ }, children);
14
15
  };
15
- ConfigProvider.config = setGlobalConfig;
16
16
  export default ConfigProvider;