@antv/gpt-vis 1.0.1 → 1.3.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 (172) hide show
  1. package/README.md +113 -36
  2. package/README.zh-CN.md +113 -36
  3. package/dist/cjs/index.d.ts +1 -1
  4. package/dist/cjs/theme/g2.d.ts +9 -0
  5. package/dist/cjs/theme/g2.js +605 -0
  6. package/dist/cjs/theme/g6.d.ts +28 -0
  7. package/dist/cjs/theme/g6.js +124 -0
  8. package/dist/cjs/theme/merge.d.ts +2 -0
  9. package/dist/cjs/theme/merge.js +49 -0
  10. package/dist/cjs/theme/resolve.d.ts +7 -0
  11. package/dist/cjs/theme/resolve.js +58 -0
  12. package/dist/cjs/theme/shared.d.ts +7 -0
  13. package/dist/cjs/theme/shared.js +61 -0
  14. package/dist/cjs/theme/summary.d.ts +11 -0
  15. package/dist/cjs/theme/summary.js +61 -0
  16. package/dist/cjs/theme/table.d.ts +13 -0
  17. package/dist/cjs/theme/table.js +121 -0
  18. package/dist/cjs/types/index.d.ts +8 -5
  19. package/dist/cjs/types/theme.d.ts +107 -0
  20. package/dist/cjs/types/theme.js +17 -0
  21. package/dist/cjs/util/animation.js +6 -1
  22. package/dist/cjs/util/components.d.ts +20 -0
  23. package/dist/cjs/util/components.js +40 -0
  24. package/dist/cjs/util/crosshair-axis-labels.d.ts +7 -2
  25. package/dist/cjs/util/crosshair-axis-labels.js +144 -30
  26. package/dist/cjs/util/html.d.ts +1 -0
  27. package/dist/cjs/util/html.js +29 -0
  28. package/dist/cjs/util/index.d.ts +0 -2
  29. package/dist/cjs/util/index.js +1 -5
  30. package/dist/cjs/util/interaction.d.ts +4 -3
  31. package/dist/cjs/util/interaction.js +14 -1
  32. package/dist/cjs/util/tokens.d.ts +4 -3
  33. package/dist/cjs/util/tokens.js +13 -10
  34. package/dist/cjs/vis/area/index.d.ts +3 -6
  35. package/dist/cjs/vis/area/index.js +43 -30
  36. package/dist/cjs/vis/bar/index.d.ts +5 -5
  37. package/dist/cjs/vis/bar/index.js +34 -20
  38. package/dist/cjs/vis/boxplot/index.d.ts +4 -5
  39. package/dist/cjs/vis/boxplot/index.js +36 -23
  40. package/dist/cjs/vis/column/index.d.ts +5 -5
  41. package/dist/cjs/vis/column/index.js +38 -26
  42. package/dist/cjs/vis/dual-axes/index.d.ts +3 -4
  43. package/dist/cjs/vis/dual-axes/index.js +87 -51
  44. package/dist/cjs/vis/fishbone-diagram/index.d.ts +4 -10
  45. package/dist/cjs/vis/fishbone-diagram/index.js +43 -28
  46. package/dist/cjs/vis/flow-diagram/index.d.ts +4 -6
  47. package/dist/cjs/vis/flow-diagram/index.js +21 -22
  48. package/dist/cjs/vis/funnel/index.d.ts +3 -6
  49. package/dist/cjs/vis/funnel/index.js +77 -58
  50. package/dist/cjs/vis/histogram/index.d.ts +4 -6
  51. package/dist/cjs/vis/histogram/index.js +17 -19
  52. package/dist/cjs/vis/indented-tree/index.d.ts +4 -6
  53. package/dist/cjs/vis/indented-tree/index.js +58 -34
  54. package/dist/cjs/vis/line/index.d.ts +3 -6
  55. package/dist/cjs/vis/line/index.js +43 -22
  56. package/dist/cjs/vis/liquid/index.d.ts +4 -6
  57. package/dist/cjs/vis/liquid/index.js +22 -17
  58. package/dist/cjs/vis/mindmap/index.d.ts +4 -6
  59. package/dist/cjs/vis/mindmap/index.js +43 -25
  60. package/dist/cjs/vis/network-graph/index.d.ts +4 -6
  61. package/dist/cjs/vis/network-graph/index.js +26 -20
  62. package/dist/cjs/vis/organization-chart/index.d.ts +4 -6
  63. package/dist/cjs/vis/organization-chart/index.js +39 -33
  64. package/dist/cjs/vis/pie/index.d.ts +3 -5
  65. package/dist/cjs/vis/pie/index.js +45 -26
  66. package/dist/cjs/vis/radar/index.d.ts +3 -6
  67. package/dist/cjs/vis/radar/index.js +32 -24
  68. package/dist/cjs/vis/sankey/index.d.ts +4 -6
  69. package/dist/cjs/vis/sankey/index.js +17 -7
  70. package/dist/cjs/vis/scatter/index.d.ts +3 -5
  71. package/dist/cjs/vis/scatter/index.js +32 -19
  72. package/dist/cjs/vis/summary/index.js +5 -6
  73. package/dist/cjs/vis/table/index.d.ts +4 -2
  74. package/dist/cjs/vis/table/index.js +56 -8
  75. package/dist/cjs/vis/treemap/index.d.ts +4 -6
  76. package/dist/cjs/vis/treemap/index.js +11 -7
  77. package/dist/cjs/vis/venn/index.d.ts +4 -6
  78. package/dist/cjs/vis/venn/index.js +18 -16
  79. package/dist/cjs/vis/violin/index.d.ts +4 -5
  80. package/dist/cjs/vis/violin/index.js +35 -27
  81. package/dist/cjs/vis/waterfall/index.d.ts +4 -4
  82. package/dist/cjs/vis/waterfall/index.js +48 -39
  83. package/dist/cjs/vis/word-cloud/index.d.ts +3 -5
  84. package/dist/cjs/vis/word-cloud/index.js +18 -12
  85. package/dist/esm/index.d.ts +1 -1
  86. package/dist/esm/theme/g2.d.ts +9 -0
  87. package/dist/esm/theme/g2.js +504 -0
  88. package/dist/esm/theme/g6.d.ts +28 -0
  89. package/dist/esm/theme/g6.js +84 -0
  90. package/dist/esm/theme/merge.d.ts +2 -0
  91. package/dist/esm/theme/merge.js +36 -0
  92. package/dist/esm/theme/resolve.d.ts +7 -0
  93. package/dist/esm/theme/resolve.js +27 -0
  94. package/dist/esm/theme/shared.d.ts +7 -0
  95. package/dist/esm/theme/shared.js +21 -0
  96. package/dist/esm/theme/summary.d.ts +11 -0
  97. package/dist/esm/theme/summary.js +45 -0
  98. package/dist/esm/theme/table.d.ts +13 -0
  99. package/dist/esm/theme/table.js +112 -0
  100. package/dist/esm/types/index.d.ts +8 -5
  101. package/dist/esm/types/theme.d.ts +107 -0
  102. package/dist/esm/types/theme.js +1 -0
  103. package/dist/esm/util/animation.js +12 -2
  104. package/dist/esm/util/components.d.ts +20 -0
  105. package/dist/esm/util/components.js +57 -1
  106. package/dist/esm/util/crosshair-axis-labels.d.ts +7 -2
  107. package/dist/esm/util/crosshair-axis-labels.js +156 -35
  108. package/dist/esm/util/html.d.ts +1 -0
  109. package/dist/esm/util/html.js +3 -0
  110. package/dist/esm/util/index.d.ts +0 -2
  111. package/dist/esm/util/index.js +1 -3
  112. package/dist/esm/util/interaction.d.ts +4 -3
  113. package/dist/esm/util/interaction.js +18 -1
  114. package/dist/esm/util/tokens.d.ts +4 -3
  115. package/dist/esm/util/tokens.js +13 -10
  116. package/dist/esm/vis/area/index.d.ts +3 -6
  117. package/dist/esm/vis/area/index.js +53 -45
  118. package/dist/esm/vis/bar/index.d.ts +5 -5
  119. package/dist/esm/vis/bar/index.js +38 -27
  120. package/dist/esm/vis/boxplot/index.d.ts +4 -5
  121. package/dist/esm/vis/boxplot/index.js +47 -29
  122. package/dist/esm/vis/column/index.d.ts +5 -5
  123. package/dist/esm/vis/column/index.js +46 -36
  124. package/dist/esm/vis/dual-axes/index.d.ts +3 -4
  125. package/dist/esm/vis/dual-axes/index.js +97 -57
  126. package/dist/esm/vis/fishbone-diagram/index.d.ts +4 -10
  127. package/dist/esm/vis/fishbone-diagram/index.js +52 -27
  128. package/dist/esm/vis/flow-diagram/index.d.ts +4 -6
  129. package/dist/esm/vis/flow-diagram/index.js +28 -23
  130. package/dist/esm/vis/funnel/index.d.ts +3 -6
  131. package/dist/esm/vis/funnel/index.js +78 -68
  132. package/dist/esm/vis/histogram/index.d.ts +4 -6
  133. package/dist/esm/vis/histogram/index.js +28 -21
  134. package/dist/esm/vis/indented-tree/index.d.ts +4 -6
  135. package/dist/esm/vis/indented-tree/index.js +59 -52
  136. package/dist/esm/vis/line/index.d.ts +3 -6
  137. package/dist/esm/vis/line/index.js +44 -32
  138. package/dist/esm/vis/liquid/index.d.ts +4 -6
  139. package/dist/esm/vis/liquid/index.js +28 -21
  140. package/dist/esm/vis/mindmap/index.d.ts +4 -6
  141. package/dist/esm/vis/mindmap/index.js +32 -28
  142. package/dist/esm/vis/network-graph/index.d.ts +4 -6
  143. package/dist/esm/vis/network-graph/index.js +37 -22
  144. package/dist/esm/vis/organization-chart/index.d.ts +4 -6
  145. package/dist/esm/vis/organization-chart/index.js +47 -36
  146. package/dist/esm/vis/pie/index.d.ts +3 -5
  147. package/dist/esm/vis/pie/index.js +42 -26
  148. package/dist/esm/vis/radar/index.d.ts +3 -6
  149. package/dist/esm/vis/radar/index.js +28 -20
  150. package/dist/esm/vis/sankey/index.d.ts +4 -6
  151. package/dist/esm/vis/sankey/index.js +20 -10
  152. package/dist/esm/vis/scatter/index.d.ts +3 -5
  153. package/dist/esm/vis/scatter/index.js +32 -21
  154. package/dist/esm/vis/summary/index.js +5 -7
  155. package/dist/esm/vis/table/index.d.ts +4 -2
  156. package/dist/esm/vis/table/index.js +48 -11
  157. package/dist/esm/vis/treemap/index.d.ts +4 -6
  158. package/dist/esm/vis/treemap/index.js +16 -11
  159. package/dist/esm/vis/venn/index.d.ts +4 -6
  160. package/dist/esm/vis/venn/index.js +24 -16
  161. package/dist/esm/vis/violin/index.d.ts +4 -5
  162. package/dist/esm/vis/violin/index.js +45 -37
  163. package/dist/esm/vis/waterfall/index.d.ts +4 -4
  164. package/dist/esm/vis/waterfall/index.js +46 -36
  165. package/dist/esm/vis/word-cloud/index.d.ts +3 -5
  166. package/dist/esm/vis/word-cloud/index.js +24 -17
  167. package/dist/umd/index.min.js +1 -1
  168. package/package.json +1 -1
  169. package/dist/cjs/util/theme.d.ts +0 -20
  170. package/dist/cjs/util/theme.js +0 -372
  171. package/dist/esm/util/theme.d.ts +0 -20
  172. package/dist/esm/util/theme.js +0 -326
@@ -23,7 +23,10 @@ __export(area_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(area_exports);
25
25
  var import_g2 = require("@antv/g2");
26
+ var import_g22 = require("../../theme/g2");
26
27
  var import_util = require("../../util");
28
+ var import_components = require("../../util/components");
29
+ var import_tokens = require("../../util/tokens");
27
30
  var getLinearGradientColor = (color, backgroundColor = "white") => `linear-gradient(-90deg, ${backgroundColor} 0%, ${color} 100%)`;
28
31
  var DEFAULT_COLOR = "#3A95FF";
29
32
  var Area = (options) => {
@@ -37,29 +40,48 @@ var Area = (options) => {
37
40
  data = [],
38
41
  theme = chartTheme,
39
42
  title,
43
+ subtitle,
40
44
  axisXTitle,
41
45
  axisYTitle,
42
46
  stack = false,
43
- style = {}
47
+ style: localStyle = {}
44
48
  } = config;
45
49
  if (chart) {
46
50
  cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
47
51
  cleanupCrosshairAxisLabels = null;
48
52
  chart.destroy();
49
53
  }
50
- const { lineWidth = import_util.CHART_STYLE_DEFAULTS.lineWidth } = style;
51
54
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
52
- const colors = (0, import_util.normalizePalette)(style.palette, theme);
53
- const backgroundColor = style.backgroundColor || (0, import_util.getBackgroundColor)(theme);
54
- const fillColor = getLinearGradientColor(colors[0] || DEFAULT_COLOR, backgroundColor);
55
- const areaOpacity = import_util.CHART_STYLE_DEFAULTS.areaOpacity;
56
- const lineOpacity = import_util.CHART_STYLE_DEFAULTS.lineOpacity;
57
55
  const cartesianAxisOptions = {
58
56
  axisXTitle,
59
57
  axisYTitle,
60
58
  xLabels: data.map(({ time }) => time),
61
59
  chartWidth: width
62
60
  };
61
+ const appearance = (0, import_g22.getThemeObject)("area", theme, localStyle);
62
+ const { theme: rendererTheme } = appearance;
63
+ const areaMark = {
64
+ fillOpacity: import_tokens.CHART_STYLE_DEFAULTS.areaOpacity,
65
+ ...appearance.mark.area
66
+ };
67
+ const lineMark = {
68
+ lineWidth: import_tokens.CHART_STYLE_DEFAULTS.lineWidth,
69
+ strokeOpacity: import_tokens.CHART_STYLE_DEFAULTS.lineOpacity,
70
+ ...appearance.mark.line
71
+ };
72
+ const pointStyle = {
73
+ shape: "point",
74
+ size: import_tokens.CHART_STYLE_DEFAULTS.pointSize,
75
+ lineWidth: import_tokens.CHART_STYLE_DEFAULTS.pointLineWidth,
76
+ stroke: rendererTheme.view.viewFill,
77
+ ...appearance.mark.point
78
+ };
79
+ const baseTheme = rendererTheme.type;
80
+ const lineWidth = lineMark.lineWidth;
81
+ const colors = rendererTheme.category10;
82
+ const backgroundColor = rendererTheme.view.viewFill;
83
+ const fillColor = getLinearGradientColor(colors[0] || DEFAULT_COLOR, backgroundColor);
84
+ const areaOpacity = areaMark.fillOpacity ?? import_tokens.CHART_STYLE_DEFAULTS.areaOpacity;
63
85
  const tooltip = {
64
86
  items: [
65
87
  (d) => ({
@@ -85,12 +107,9 @@ var Area = (options) => {
85
107
  children = [
86
108
  {
87
109
  type: "area",
88
- style: { fillOpacity: areaOpacity }
110
+ style: areaMark
89
111
  },
90
- {
91
- type: "line",
92
- style: { lineWidth, strokeOpacity: lineOpacity }
93
- }
112
+ { type: "line", style: lineMark }
94
113
  ];
95
114
  } else if (hasGroupField) {
96
115
  encode = { x: "time", y: "value", color: "group" };
@@ -98,12 +117,9 @@ var Area = (options) => {
98
117
  children = [
99
118
  {
100
119
  type: "area",
101
- style: { fillOpacity: areaOpacity }
120
+ style: areaMark
102
121
  },
103
- {
104
- type: "line",
105
- style: { lineWidth, strokeOpacity: lineOpacity }
106
- }
122
+ { type: "line", style: lineMark }
107
123
  ];
108
124
  } else {
109
125
  encode = { x: "time", y: "value" };
@@ -111,17 +127,16 @@ var Area = (options) => {
111
127
  {
112
128
  type: "area",
113
129
  style: {
114
- fillOpacity: areaOpacity,
130
+ ...areaMark,
115
131
  fill: fillColor
116
132
  }
117
133
  },
118
134
  {
119
135
  type: "line",
120
136
  style: {
121
- lineWidth,
122
- strokeOpacity: lineOpacity,
123
137
  lineCap: "round",
124
138
  lineJoin: "round",
139
+ ...lineMark,
125
140
  stroke: colors[0]
126
141
  }
127
142
  }
@@ -137,43 +152,41 @@ var Area = (options) => {
137
152
  } : (0, import_util.getLineHighlightState)(lineWidth) : void 0
138
153
  }));
139
154
  if (!hasGroupField && data.length <= 24) {
155
+ const { size: pointSize, ...pointMark } = pointStyle;
140
156
  children.push({
141
157
  type: "point",
142
158
  encode: {
143
159
  x: "time",
144
160
  y: "value",
145
- shape: "point",
146
- size: import_util.CHART_STYLE_DEFAULTS.pointSize
161
+ size: pointSize
147
162
  },
148
163
  animate: (0, import_util.getChartAnimation)(hasRendered, "fadeIn"),
149
164
  tooltip: false,
150
165
  style: {
151
- lineWidth: import_util.CHART_STYLE_DEFAULTS.pointLineWidth,
152
- fill: colors[0],
153
- stroke: backgroundColor
166
+ ...pointMark,
167
+ fill: colors[0]
154
168
  }
155
169
  });
156
170
  }
157
171
  const chartOptions = {
158
172
  type: "view",
159
173
  data,
160
- title: title || "",
174
+ title: title ? { title, subtitle } : "",
161
175
  encode,
162
176
  transform,
163
177
  children,
164
178
  scale: scaleConfig,
165
179
  ...(0, import_util.getCartesianLayout)(cartesianAxisOptions),
166
180
  axis: (0, import_util.getCartesianAxis)(cartesianAxisOptions),
167
- legend: (0, import_util.getColorLegend)(hasGroupField),
181
+ legend: (0, import_components.getColorLegend)(hasGroupField),
168
182
  interaction: {
169
183
  tooltip: (0, import_util.getSharedTooltipInteraction)({ crosshairs: true }),
170
184
  ...hasGroupField ? (0, import_util.getSeriesHighlightByColorInteraction)() : {}
171
185
  },
172
- viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
173
- theme: (0, import_util.getThemeObject)(theme)
186
+ theme: rendererTheme
174
187
  };
175
188
  chart.options(chartOptions);
176
- cleanupCrosshairAxisLabels = (0, import_util.bindCrosshairAxisLabels)(chart, theme);
189
+ cleanupCrosshairAxisLabels = (0, import_util.bindCrosshairAxisLabels)(chart, baseTheme);
177
190
  chart.render();
178
191
  hasRendered = true;
179
192
  };
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions, VisualizationTheme } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * BarDataItem is the type for each data item in the bar chart.
4
4
  */
@@ -16,13 +16,13 @@ export interface BarConfig {
16
16
  group?: boolean;
17
17
  stack?: boolean;
18
18
  title?: string;
19
+ subtitle?: string;
20
+ /** Show value labels. Defaults to `true`. */
21
+ label?: boolean;
19
22
  axisXTitle?: string;
20
23
  axisYTitle?: string;
21
24
  theme?: VisualizationTheme;
22
- style?: {
23
- backgroundColor?: string;
24
- palette?: string[];
25
- };
25
+ style?: ThemeStyle;
26
26
  }
27
27
  /**
28
28
  * BarInstance represents a bar chart instance with render and destroy methods.
@@ -23,28 +23,41 @@ __export(bar_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(bar_exports);
25
25
  var import_g2 = require("@antv/g2");
26
+ var import_g22 = require("../../theme/g2");
26
27
  var import_util = require("../../util");
28
+ var import_components = require("../../util/components");
29
+ var import_tokens = require("../../util/tokens");
27
30
  var Bar = (options) => {
28
31
  const { container, width, height, theme: chartTheme = "default" } = options;
29
32
  let chart = null;
30
- let hasRendered = false;
31
33
  const render = (config) => {
32
34
  var _a;
33
35
  const {
34
36
  data = [],
35
37
  theme = chartTheme,
36
38
  title,
39
+ subtitle,
40
+ label,
37
41
  axisXTitle,
38
42
  axisYTitle,
39
43
  group = false,
40
44
  stack = false,
41
- style = {}
45
+ style: localStyle = {}
42
46
  } = config;
43
47
  if (chart) {
44
48
  chart.destroy();
45
49
  }
46
50
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
47
- const colors = (0, import_util.normalizePalette)(style.palette, theme);
51
+ const appearance = (0, import_g22.getThemeObject)("bar", theme, localStyle);
52
+ const { theme: rendererTheme } = appearance;
53
+ const intervalMark = {
54
+ ...rendererTheme.type !== "academy" ? { radius: 4 } : {},
55
+ columnWidthRatio: import_tokens.CHART_STYLE_DEFAULTS.intervalWidthRatio,
56
+ ...!hasGroupField ? { fill: rendererTheme.category10[0] } : {},
57
+ ...appearance.mark.interval
58
+ };
59
+ const baseTheme = rendererTheme.type;
60
+ const colors = rendererTheme.category10;
48
61
  chart = new import_g2.Chart({
49
62
  container,
50
63
  width,
@@ -53,10 +66,6 @@ var Bar = (options) => {
53
66
  });
54
67
  let encode = {};
55
68
  let transform = [];
56
- let radiusStyle = {};
57
- if (theme !== "academy") {
58
- radiusStyle = { radius: 4 };
59
- }
60
69
  if (hasGroupField && group) {
61
70
  transform = [{ type: "dodgeX" }];
62
71
  }
@@ -73,16 +82,28 @@ var Bar = (options) => {
73
82
  ...hasGroupField ? { color: { range: colors } } : {}
74
83
  };
75
84
  const chartOptions = {
76
- animate: (0, import_util.getChartAnimation)(hasRendered, "growInX"),
85
+ // G2 growInX currently computes interval label bounds from the animated
86
+ // clip path, which leaves inside labels at the axis baseline. Keep the
87
+ // interval and its labels in sync until the upstream runtime is fixed.
88
+ animate: false,
77
89
  type: "interval",
78
90
  data,
79
- title: title || "",
91
+ title: title ? { title, subtitle } : "",
80
92
  encode,
81
93
  transform,
82
94
  coordinate: { transform: [{ type: "transpose" }] },
83
95
  scale: scaleConfig,
84
96
  axis: (0, import_util.getCartesianAxis)({ axisXTitle, axisYTitle }),
85
- legend: (0, import_util.getColorLegend)(hasGroupField),
97
+ legend: (0, import_components.getColorLegend)(hasGroupField),
98
+ labels: (0, import_components.getDataLabels)(rendererTheme, {
99
+ visible: label,
100
+ defaultVisible: true,
101
+ text: "value",
102
+ position: "right",
103
+ contrast: "inside",
104
+ dx: -4,
105
+ dy: 0
106
+ }),
86
107
  tooltip: {
87
108
  items: [
88
109
  (d) => ({
@@ -91,29 +112,22 @@ var Bar = (options) => {
91
112
  })
92
113
  ]
93
114
  },
94
- state: (0, import_util.getCategoryBackgroundHighlightState)(theme),
115
+ state: (0, import_util.getCategoryBackgroundHighlightState)(baseTheme),
95
116
  interaction: {
96
117
  tooltip: true,
97
118
  elementHighlight: (0, import_util.getCategoryHighlightInteraction)()
98
119
  },
99
- style: {
100
- ...radiusStyle,
101
- columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
102
- ...!hasGroupField ? { fill: colors[0] } : {}
103
- },
104
- viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
105
- theme: (0, import_util.getThemeObject)(theme)
120
+ style: intervalMark,
121
+ theme: rendererTheme
106
122
  };
107
123
  chart.options(chartOptions);
108
124
  chart.render();
109
- hasRendered = true;
110
125
  };
111
126
  const destroy = () => {
112
127
  if (chart) {
113
128
  chart.destroy();
114
129
  chart = null;
115
130
  }
116
- hasRendered = false;
117
131
  };
118
132
  return {
119
133
  render,
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * BoxplotDataItem is the type for each data item in the boxplot chart.
4
4
  */
@@ -13,13 +13,12 @@ export type BoxplotDataItem = {
13
13
  export interface BoxplotConfig {
14
14
  type?: 'boxplot';
15
15
  data: BoxplotDataItem[];
16
- theme?: 'default' | 'academy' | 'dark';
16
+ theme?: VisualizationTheme;
17
17
  title?: string;
18
+ subtitle?: string;
18
19
  axisXTitle?: string;
19
20
  axisYTitle?: string;
20
- style?: {
21
- backgroundColor?: string;
22
- palette?: string[];
21
+ style?: ThemeStyle & {
23
22
  startAtZero?: boolean;
24
23
  };
25
24
  }
@@ -23,19 +23,36 @@ __export(boxplot_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(boxplot_exports);
25
25
  var import_g2 = require("@antv/g2");
26
- var import_theme = require("../../util/theme");
26
+ var import_g22 = require("../../theme/g2");
27
+ var import_components = require("../../util/components");
28
+ var prefixMarkStyle = (prefix, style) => Object.fromEntries(
29
+ Object.entries(style ?? {}).map(([key, value]) => [
30
+ `${prefix}${key.charAt(0).toUpperCase()}${key.slice(1)}`,
31
+ value
32
+ ])
33
+ );
27
34
  var Boxplot = (options) => {
28
35
  const { container, width, height, theme: chartTheme = "default" } = options;
29
36
  let chart = null;
30
37
  const render = (config) => {
31
38
  var _a;
32
- const { data = [], theme = chartTheme, title, axisXTitle, axisYTitle, style = {} } = config;
39
+ const {
40
+ data = [],
41
+ theme = chartTheme,
42
+ title,
43
+ subtitle,
44
+ axisXTitle,
45
+ axisYTitle,
46
+ style: localStyle = {}
47
+ } = config;
33
48
  if (chart) {
34
49
  chart.destroy();
35
50
  }
36
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
37
- const startAtZero = style.startAtZero || false;
38
51
  const hasGroupField = ((_a = (data || [])[0]) == null ? void 0 : _a.group) !== void 0;
52
+ const appearance = (0, import_g22.getThemeObject)("boxplot", theme, localStyle);
53
+ const { theme: rendererTheme } = appearance;
54
+ const colors = rendererTheme.category10;
55
+ const startAtZero = localStyle.startAtZero || false;
39
56
  let encode = {};
40
57
  if (hasGroupField) {
41
58
  encode = {
@@ -51,6 +68,14 @@ var Boxplot = (options) => {
51
68
  color: "category"
52
69
  };
53
70
  }
71
+ const showPoints = !hasGroupField;
72
+ const boxStyle = appearance.mark.box;
73
+ const resolvedPointStyle = appearance.mark.point;
74
+ const markStyle = showPoints ? {
75
+ ...prefixMarkStyle("box", boxStyle),
76
+ ...prefixMarkStyle("point", resolvedPointStyle)
77
+ } : { ...boxStyle, point: false };
78
+ const legend = (0, import_components.getColorLegend)(hasGroupField);
54
79
  chart = new import_g2.Chart({
55
80
  container,
56
81
  width,
@@ -61,32 +86,20 @@ var Boxplot = (options) => {
61
86
  animate: false,
62
87
  type: "boxplot",
63
88
  data,
64
- title: title ?? "",
89
+ title: title ? { title, subtitle } : "",
65
90
  encode,
66
- axis: {
67
- x: {
68
- title: axisXTitle || false
69
- },
70
- y: {
71
- title: axisYTitle || false
72
- }
73
- },
91
+ axis: (0, import_components.getCartesianAxis)({ axisXTitle, axisYTitle }),
74
92
  scale: {
75
93
  x: { paddingInner: 0.6, paddingOuter: 0.3 },
76
94
  series: { paddingInner: 0.3, paddingOuter: 0.1 },
77
95
  y: { nice: true, zero: startAtZero },
78
96
  color: { range: colors }
79
97
  },
80
- // When hasGroupField is true, set point to false to prevent G2's Boxplot composite mark
81
- // from splitting into box + point child marks. The point child mark does not inherit
82
- // the `scale` config, causing legendFilter interaction to throw
83
- // "Cannot read properties of undefined (reading 'color')" when clicking legend items.
84
- style: { stroke: "black", ...hasGroupField ? { point: false } : {} },
85
- legend: {
86
- color: hasGroupField ? { position: "top" } : false
87
- },
88
- viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
89
- theme: (0, import_theme.getThemeObject)(theme)
98
+ // Grouped boxplots keep outliers disabled because G2's point child does
99
+ // not inherit the composite color scale used by legend filtering.
100
+ style: { stroke: "black", ...markStyle },
101
+ legend: legend === false ? { color: false } : { color: { position: "top", ...legend.color } },
102
+ theme: rendererTheme
90
103
  };
91
104
  chart.options(chartOptions);
92
105
  chart.render();
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions, VisualizationTheme } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * ColumnDataItem is the type for each data item in the column chart.
4
4
  */
@@ -16,13 +16,13 @@ export interface ColumnConfig {
16
16
  group?: boolean;
17
17
  stack?: boolean;
18
18
  title?: string;
19
+ subtitle?: string;
20
+ /** Show value labels. Defaults to `true`. */
21
+ label?: boolean;
19
22
  axisXTitle?: string;
20
23
  axisYTitle?: string;
21
24
  theme?: VisualizationTheme;
22
- style?: {
23
- backgroundColor?: string;
24
- palette?: string[];
25
- };
25
+ style?: ThemeStyle;
26
26
  }
27
27
  /**
28
28
  * ColumnInstance represents a column chart instance with render and destroy methods.
@@ -23,28 +23,47 @@ __export(column_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(column_exports);
25
25
  var import_g2 = require("@antv/g2");
26
+ var import_g22 = require("../../theme/g2");
26
27
  var import_util = require("../../util");
28
+ var import_components = require("../../util/components");
29
+ var import_tokens = require("../../util/tokens");
27
30
  var Column = (options) => {
28
31
  const { container, width, height, theme: chartTheme = "default" } = options;
29
32
  let chart = null;
30
- let hasRendered = false;
31
33
  const render = (config) => {
32
34
  var _a;
33
35
  const {
34
36
  data = [],
35
37
  theme = chartTheme,
36
38
  title,
39
+ subtitle,
40
+ label,
37
41
  axisXTitle,
38
42
  axisYTitle,
39
43
  group = false,
40
44
  stack = false,
41
- style = {}
45
+ style: localStyle = {}
42
46
  } = config;
43
47
  if (chart) {
44
48
  chart.destroy();
45
49
  }
46
50
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
47
- const colors = (0, import_util.normalizePalette)(style.palette, theme);
51
+ const cartesianAxisOptions = {
52
+ axisXTitle,
53
+ axisYTitle,
54
+ xLabels: data.map(({ category }) => category),
55
+ chartWidth: width
56
+ };
57
+ const appearance = (0, import_g22.getThemeObject)("column", theme, localStyle);
58
+ const { theme: rendererTheme } = appearance;
59
+ const intervalMark = {
60
+ ...rendererTheme.type !== "academy" && appearance.mark.interval.radius === void 0 ? { radiusTopLeft: 4, radiusTopRight: 4 } : {},
61
+ columnWidthRatio: import_tokens.CHART_STYLE_DEFAULTS.intervalWidthRatio,
62
+ ...!hasGroupField ? { fill: rendererTheme.category10[0] } : {},
63
+ ...appearance.mark.interval
64
+ };
65
+ const baseTheme = rendererTheme.type;
66
+ const colors = rendererTheme.category10;
48
67
  chart = new import_g2.Chart({
49
68
  container,
50
69
  width,
@@ -53,10 +72,6 @@ var Column = (options) => {
53
72
  });
54
73
  let encode = {};
55
74
  let transform = [];
56
- let radiusStyle = {};
57
- if (theme !== "academy") {
58
- radiusStyle = { radiusTopLeft: 4, radiusTopRight: 4 };
59
- }
60
75
  if (hasGroupField && group) {
61
76
  transform = [{ type: "dodgeX" }];
62
77
  }
@@ -72,23 +87,27 @@ var Column = (options) => {
72
87
  y: { nice: true },
73
88
  ...hasGroupField ? { color: { range: colors } } : {}
74
89
  };
75
- const cartesianAxisOptions = {
76
- axisXTitle,
77
- axisYTitle,
78
- xLabels: data.map(({ category }) => category),
79
- chartWidth: width
80
- };
81
90
  const chartOptions = {
82
- animate: (0, import_util.getChartAnimation)(hasRendered, "growInY"),
91
+ // G2 growInY currently computes interval label bounds from the animated
92
+ // clip path, which leaves inside labels at the axis baseline. Keep the
93
+ // interval and its labels in sync until the upstream runtime is fixed.
94
+ animate: false,
83
95
  type: "interval",
84
96
  data,
85
- title: title || "",
97
+ title: title ? { title, subtitle } : "",
86
98
  encode,
87
99
  transform,
88
100
  scale: scaleConfig,
89
101
  ...(0, import_util.getCartesianLayout)(cartesianAxisOptions),
90
102
  axis: (0, import_util.getCartesianAxis)(cartesianAxisOptions),
91
- legend: (0, import_util.getColorLegend)(hasGroupField),
103
+ legend: (0, import_components.getColorLegend)(hasGroupField),
104
+ labels: (0, import_components.getDataLabels)(rendererTheme, {
105
+ visible: label,
106
+ defaultVisible: true,
107
+ text: "value",
108
+ position: "inside",
109
+ contrast: "inside"
110
+ }),
92
111
  tooltip: {
93
112
  items: [
94
113
  (d) => ({
@@ -97,29 +116,22 @@ var Column = (options) => {
97
116
  })
98
117
  ]
99
118
  },
100
- state: (0, import_util.getCategoryBackgroundHighlightState)(theme),
119
+ state: (0, import_util.getCategoryBackgroundHighlightState)(baseTheme),
101
120
  interaction: {
102
121
  tooltip: true,
103
122
  elementHighlight: (0, import_util.getCategoryHighlightInteraction)()
104
123
  },
105
- style: {
106
- ...radiusStyle,
107
- columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
108
- ...!hasGroupField ? { fill: colors[0] } : {}
109
- },
110
- viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
111
- theme: (0, import_util.getThemeObject)(theme)
124
+ style: intervalMark,
125
+ theme: rendererTheme
112
126
  };
113
127
  chart.options(chartOptions);
114
128
  chart.render();
115
- hasRendered = true;
116
129
  };
117
130
  const destroy = () => {
118
131
  if (chart) {
119
132
  chart.destroy();
120
133
  chart = null;
121
134
  }
122
- hasRendered = false;
123
135
  };
124
136
  return {
125
137
  render,
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions, VisualizationTheme } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * DualAxesSeriesItem defines a single series in the dual-axes chart.
4
4
  */
@@ -15,11 +15,10 @@ export interface DualAxesConfig {
15
15
  categories: string[];
16
16
  series: DualAxesSeriesItem[];
17
17
  title?: string;
18
+ subtitle?: string;
18
19
  axisXTitle?: string;
19
20
  theme?: VisualizationTheme;
20
- style?: {
21
- backgroundColor?: string;
22
- palette?: string[];
21
+ style?: ThemeStyle & {
23
22
  startAtZero?: boolean;
24
23
  };
25
24
  }