@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
@@ -24,6 +24,8 @@ __export(table_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(table_exports);
26
26
  var import_measury = require("measury");
27
+ var import_table = require("../../theme/table");
28
+ var import_html = require("../../util/html");
27
29
  var SCOPE_ID = "__gpt-vis-table__";
28
30
  var FONT_FAMILY = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
29
31
  var CELL_PADDING = 16;
@@ -36,13 +38,28 @@ var TABLE_STYLES = `
36
38
  padding: 16px;
37
39
  }
38
40
 
41
+ .${SCOPE_ID} .table-heading {
42
+ margin-bottom: 12px;
43
+ }
44
+
39
45
  .${SCOPE_ID} .table-title {
40
46
  font-size: 16px;
41
47
  font-weight: 500;
42
- margin-bottom: 12px;
43
48
  color: #1d2129;
44
49
  }
45
50
 
51
+ .${SCOPE_ID} .table-subtitle {
52
+ margin-top: 4px;
53
+ font-size: 12px;
54
+ color: #667085;
55
+ }
56
+
57
+ .${SCOPE_ID} .table-empty {
58
+ padding: 20px;
59
+ text-align: center;
60
+ color: #999;
61
+ }
62
+
46
63
  .${SCOPE_ID} table {
47
64
  border-collapse: separate;
48
65
  border-spacing: 0;
@@ -95,6 +112,10 @@ var TABLE_STYLES = `
95
112
  color: #ffffffd9;
96
113
  }
97
114
 
115
+ .${SCOPE_ID}[data-theme="dark"] .table-subtitle {
116
+ color: #ffffffa6;
117
+ }
118
+
98
119
  .${SCOPE_ID}[data-theme="dark"] table {
99
120
  background: #141414;
100
121
  }
@@ -149,6 +170,23 @@ var injectStyles = () => {
149
170
  styleElement.textContent = TABLE_STYLES;
150
171
  document.head.appendChild(styleElement);
151
172
  };
173
+ var applyDomStyle = (elements, style) => {
174
+ if (!elements)
175
+ return;
176
+ const targets = elements instanceof Element ? [elements] : elements;
177
+ for (const target of targets) {
178
+ Object.assign(target.style, style);
179
+ }
180
+ };
181
+ var applyResolvedTableStyle = (wrapper, style) => {
182
+ applyDomStyle(wrapper.querySelector(".table-title"), style.title);
183
+ applyDomStyle(wrapper.querySelector(".table-subtitle"), style.subtitle);
184
+ applyDomStyle(wrapper.querySelectorAll("th"), style.header);
185
+ applyDomStyle(wrapper.querySelectorAll("td"), style.cell);
186
+ const borderStyle = style.border;
187
+ applyDomStyle(wrapper.querySelector("table"), borderStyle.table);
188
+ applyDomStyle(wrapper.querySelectorAll("th, td"), borderStyle.cell);
189
+ };
152
190
  var Table = (options) => {
153
191
  const { theme: chartTheme = "default" } = options;
154
192
  const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
@@ -157,38 +195,48 @@ var Table = (options) => {
157
195
  }
158
196
  let tableWrapper = null;
159
197
  const render = (config) => {
160
- const { data = [], title, theme = chartTheme } = config;
198
+ const { data = [], title, subtitle, theme = chartTheme, style: localStyle = {} } = config;
199
+ const style = (0, import_table.getThemeObject)("table", theme, localStyle);
200
+ const { theme: rendererTheme } = style;
161
201
  injectStyles();
162
202
  if (tableWrapper) {
163
203
  tableWrapper.remove();
164
204
  }
165
205
  tableWrapper = document.createElement("div");
166
206
  tableWrapper.className = SCOPE_ID;
167
- if (theme === "dark") {
207
+ if (rendererTheme === "dark") {
168
208
  tableWrapper.setAttribute("data-theme", "dark");
169
209
  }
210
+ if (style.backgroundColor)
211
+ tableWrapper.style.backgroundColor = style.backgroundColor;
212
+ const titleHTML = title || subtitle ? `<div class="table-heading">
213
+ ${title ? `<div class="table-title">${(0, import_html.escapeHtml)(title)}</div>` : ""}
214
+ ${subtitle ? `<div class="table-subtitle">${(0, import_html.escapeHtml)(subtitle)}</div>` : ""}
215
+ </div>` : "";
170
216
  if (data.length === 0) {
171
217
  tableWrapper.innerHTML = `
172
- ${title ? `<div class="table-title">${title}</div>` : ""}
173
- <div style="padding: 20px; text-align: center; color: #999;">No data available</div>
218
+ ${titleHTML}
219
+ <div class="table-empty">No data available</div>
174
220
  `;
221
+ applyResolvedTableStyle(tableWrapper, style);
175
222
  container.appendChild(tableWrapper);
176
223
  return;
177
224
  }
178
225
  const columns = Object.keys(data[0]);
179
226
  let minWidth = calculateTableMinWidth(data, columns);
180
227
  minWidth = Math.max(minWidth, columns.length * 100);
181
- const headerHTML = columns.map((col) => `<th>${col}</th>`).join("");
228
+ const headerHTML = columns.map((column) => `<th>${(0, import_html.escapeHtml)(column)}</th>`).join("");
182
229
  const bodyHTML = data.map(
183
- (row) => `<tr>${columns.map((col) => `<td>${row[col] != null ? row[col] : ""}</td>`).join("")}</tr>`
230
+ (row) => `<tr>${columns.map((column) => `<td>${(0, import_html.escapeHtml)(row[column])}</td>`).join("")}</tr>`
184
231
  ).join("");
185
232
  tableWrapper.innerHTML = `
186
- ${title ? `<div class="table-title">${title}</div>` : ""}
233
+ ${titleHTML}
187
234
  <table style="min-width: ${minWidth}px;">
188
235
  <thead><tr>${headerHTML}</tr></thead>
189
236
  <tbody>${bodyHTML}</tbody>
190
237
  </table>
191
238
  `;
239
+ applyResolvedTableStyle(tableWrapper, style);
192
240
  container.appendChild(tableWrapper);
193
241
  };
194
242
  const destroy = () => {
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * TreemapDataItem is the type for each data item in the treemap chart.
4
4
  */
@@ -13,12 +13,10 @@ export type TreemapDataItem = {
13
13
  export interface TreemapConfig {
14
14
  type?: 'treemap';
15
15
  data: TreemapDataItem[];
16
- theme?: 'default' | 'academy' | 'dark';
16
+ theme?: VisualizationTheme;
17
17
  title?: string;
18
- style?: {
19
- backgroundColor?: string;
20
- palette?: string[];
21
- };
18
+ subtitle?: string;
19
+ style?: ThemeStyle;
22
20
  }
23
21
  /**
24
22
  * TreemapInstance represents a treemap chart instance with render and destroy methods.
@@ -23,16 +23,19 @@ __export(treemap_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(treemap_exports);
25
25
  var import_g2 = require("@antv/g2");
26
- var import_theme = require("../../util/theme");
26
+ var import_g22 = require("../../theme/g2");
27
27
  var Treemap = (options) => {
28
28
  const { container, width, height, theme: chartTheme = "default" } = options;
29
29
  let chart = null;
30
30
  const render = (config) => {
31
- const { data = [], theme = chartTheme, title, style = {} } = config;
31
+ const { data = [], theme = chartTheme, title, subtitle, style: localStyle = {} } = config;
32
32
  if (chart) {
33
33
  chart.destroy();
34
34
  }
35
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
35
+ const appearance = (0, import_g22.getThemeObject)("treemap", theme, localStyle);
36
+ const { theme: rendererTheme } = appearance;
37
+ const colors = rendererTheme.category10;
38
+ const treemapStyle = appearance.mark.treemap;
36
39
  chart = new import_g2.Chart({
37
40
  container,
38
41
  width,
@@ -49,7 +52,7 @@ var Treemap = (options) => {
49
52
  children: data
50
53
  }
51
54
  },
52
- title: title ?? "",
55
+ title: title ? { title, subtitle } : "",
53
56
  layout: {
54
57
  tile: "treemapBinary",
55
58
  paddingInner: 2
@@ -59,7 +62,9 @@ var Treemap = (options) => {
59
62
  },
60
63
  style: {
61
64
  fillOpacity: 0.8,
62
- labelFontSize: 10
65
+ labelFontSize: 10,
66
+ labelFill: rendererTheme.label.fill,
67
+ ...treemapStyle
63
68
  },
64
69
  legend: false,
65
70
  tooltip: {
@@ -73,8 +78,7 @@ var Treemap = (options) => {
73
78
  }
74
79
  ]
75
80
  },
76
- viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
77
- theme: (0, import_theme.getThemeObject)(theme),
81
+ theme: rendererTheme,
78
82
  scale: {
79
83
  ...colors.length > 0 ? {
80
84
  color: {
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * VennDataItem is the type for each data item in the venn chart.
4
4
  */
@@ -14,12 +14,10 @@ export type VennDataItem = {
14
14
  export interface VennConfig {
15
15
  type?: 'venn';
16
16
  data: VennDataItem[];
17
- theme?: 'default' | 'academy' | 'dark';
17
+ theme?: VisualizationTheme;
18
18
  title?: string;
19
- style?: {
20
- backgroundColor?: string;
21
- palette?: string[];
22
- };
19
+ subtitle?: string;
20
+ style?: ThemeStyle;
23
21
  }
24
22
  /**
25
23
  * VennInstance represents a venn chart instance with render and destroy methods.
@@ -23,7 +23,8 @@ __export(venn_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(venn_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");
27
28
  function normalizeVennSets(sets) {
28
29
  if (Array.isArray(sets))
29
30
  return sets.map((s) => String(s));
@@ -38,11 +39,14 @@ var Venn = (options) => {
38
39
  const { container, width, height, theme: chartTheme = "default" } = options;
39
40
  let chart = null;
40
41
  const render = (config) => {
41
- const { data = [], theme = chartTheme, title, style = {} } = config;
42
+ const { data = [], theme = chartTheme, title, subtitle, style: localStyle = {} } = config;
42
43
  if (chart) {
43
44
  chart.destroy();
44
45
  }
45
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
46
+ const appearance = (0, import_g22.getThemeObject)("venn", theme, localStyle);
47
+ const { theme: rendererTheme } = appearance;
48
+ const colors = rendererTheme.category10;
49
+ const pathMark = appearance.mark.path;
46
50
  const normalizedData = data.map((d) => ({
47
51
  ...d,
48
52
  sets: normalizeVennSets(d.sets)
@@ -68,26 +72,24 @@ var Venn = (options) => {
68
72
  }
69
73
  ]
70
74
  },
71
- title: title ?? "",
75
+ title: title ? { title, subtitle } : "",
72
76
  encode: { d: "path", color: "key" },
73
77
  scale: {
74
78
  color: { range: colors }
75
79
  },
76
80
  style: {
77
81
  // Set opacity: intersections (sets.length > 1) are nearly transparent, single sets are more opaque
78
- opacity: (d) => normalizeVennSets(d.sets).length > 1 ? 1e-3 : 0.65
82
+ opacity: (d) => normalizeVennSets(d.sets).length > 1 ? 1e-3 : 0.65,
83
+ ...pathMark
79
84
  },
80
- labels: [
81
- {
82
- position: "inside",
83
- text: (d) => d.label || "",
84
- fill: "#000",
85
- fillOpacity: 0.85,
86
- fontSize: 10
87
- }
88
- ],
89
- viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
90
- theme: (0, import_theme.getThemeObject)(theme),
85
+ labels: (0, import_components.getDataLabels)(rendererTheme, {
86
+ style: { fillOpacity: 0.85, fontSize: 10 },
87
+ defaultVisible: true,
88
+ position: "inside",
89
+ contrast: "inside",
90
+ text: (d) => d.label || ""
91
+ }),
92
+ theme: rendererTheme,
91
93
  legend: false,
92
94
  axis: false,
93
95
  tooltip: false
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * ViolinDataItem is the type for each data item in the violin chart.
4
4
  */
@@ -13,13 +13,12 @@ export type ViolinDataItem = {
13
13
  export interface ViolinConfig {
14
14
  type?: 'violin';
15
15
  data: ViolinDataItem[];
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,20 +23,38 @@ __export(violin_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(violin_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");
27
28
  var Violin = (options) => {
28
29
  const { container, width, height, theme: chartTheme = "default" } = options;
29
30
  let chart = null;
30
31
  const render = (config) => {
31
32
  var _a;
32
- const { data = [], theme = chartTheme, title, axisXTitle, axisYTitle, style = {} } = config;
33
+ const {
34
+ data = [],
35
+ theme = chartTheme,
36
+ title,
37
+ subtitle,
38
+ axisXTitle,
39
+ axisYTitle,
40
+ style: localStyle = {}
41
+ } = config;
33
42
  if (chart) {
34
43
  chart.destroy();
35
44
  }
36
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
37
- const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
38
- const startAtZero = style.startAtZero || false;
39
45
  const hasGroupField = ((_a = (data || [])[0]) == null ? void 0 : _a.group) !== void 0;
46
+ const appearance = (0, import_g22.getThemeObject)("violin", theme, localStyle);
47
+ const { theme: rendererTheme } = appearance;
48
+ const boxMark = {
49
+ shape: "violin",
50
+ opacity: 0.5,
51
+ strokeOpacity: 0.5,
52
+ ...appearance.mark.box
53
+ };
54
+ const colors = rendererTheme.category10;
55
+ const startAtZero = localStyle.startAtZero || false;
56
+ const densityStyle = appearance.mark.density;
57
+ const legend = (0, import_components.getColorLegend)(hasGroupField);
40
58
  chart = new import_g2.Chart({
41
59
  container,
42
60
  width,
@@ -61,7 +79,8 @@ var Violin = (options) => {
61
79
  scale: {
62
80
  y: { nice: true },
63
81
  color: { range: colors }
64
- }
82
+ },
83
+ style: densityStyle
65
84
  },
66
85
  {
67
86
  type: "boxplot",
@@ -69,10 +88,9 @@ var Violin = (options) => {
69
88
  x: "category",
70
89
  y: "value",
71
90
  series: "group",
72
- color: "group",
73
- shape: "violin"
91
+ color: "group"
74
92
  },
75
- style: { opacity: 0.5, strokeOpacity: 0.5, point: false },
93
+ style: { ...boxMark, point: false },
76
94
  scale: {
77
95
  y: { nice: true },
78
96
  color: { range: colors }
@@ -95,17 +113,17 @@ var Violin = (options) => {
95
113
  scale: {
96
114
  y: { nice: true },
97
115
  color: { range: colors }
98
- }
116
+ },
117
+ style: densityStyle
99
118
  },
100
119
  {
101
120
  type: "boxplot",
102
121
  encode: {
103
122
  x: "category",
104
123
  y: "value",
105
- color: "category",
106
- shape: "violin"
124
+ color: "category"
107
125
  },
108
- style: { opacity: 0.5, strokeOpacity: 0.5, point: false },
126
+ style: { ...boxMark, point: false },
109
127
  scale: {
110
128
  y: { nice: true },
111
129
  color: { range: colors }
@@ -117,24 +135,14 @@ var Violin = (options) => {
117
135
  animate: false,
118
136
  type: "view",
119
137
  data,
120
- title: title ?? "",
121
- axis: {
122
- x: {
123
- title: axisXTitle || false
124
- },
125
- y: {
126
- title: axisYTitle || false
127
- }
128
- },
138
+ title: title ? { title, subtitle } : "",
139
+ axis: (0, import_components.getCartesianAxis)({ axisXTitle, axisYTitle }),
129
140
  scale: {
130
141
  y: { nice: true, zero: startAtZero }
131
142
  },
132
143
  children,
133
- legend: {
134
- color: hasGroupField ? { position: "top" } : false
135
- },
136
- viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
137
- theme: (0, import_theme.getThemeObject)(theme)
144
+ legend: legend === false ? { color: false } : { color: { position: "top", ...legend.color } },
145
+ theme: rendererTheme
138
146
  };
139
147
  chart.options(chartOptions);
140
148
  chart.render();
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * WaterfallDataItem is the type for each data item in the waterfall chart.
4
4
  */
@@ -14,12 +14,12 @@ export type WaterfallDataItem = {
14
14
  export interface WaterfallConfig {
15
15
  type?: 'waterfall';
16
16
  data: WaterfallDataItem[];
17
- theme?: 'default' | 'academy' | 'dark';
17
+ theme?: VisualizationTheme;
18
18
  title?: string;
19
+ subtitle?: string;
19
20
  axisXTitle?: string;
20
21
  axisYTitle?: string;
21
- style?: {
22
- backgroundColor?: string;
22
+ style?: ThemeStyle & {
23
23
  /**
24
24
  * Custom color palette for waterfall bars.
25
25
  * Array order: [0] positive color, [1] negative color, [2] total/intermediate-total color.
@@ -23,10 +23,8 @@ __export(waterfall_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(waterfall_exports);
25
25
  var import_g2 = require("@antv/g2");
26
- var import_theme = require("../../util/theme");
27
- var DEFAULT_POSITIVE_COLOR = "#FF4D4F";
28
- var DEFAULT_NEGATIVE_COLOR = "#2EBB59";
29
- var DEFAULT_TOTAL_COLOR = "#1783FF";
26
+ var import_g22 = require("../../theme/g2");
27
+ var import_components = require("../../util/components");
30
28
  function transformWaterfallData(data) {
31
29
  let cumulative = 0;
32
30
  let lastIntermediateTotalEnd = 0;
@@ -72,15 +70,33 @@ var Waterfall = (options) => {
72
70
  const { container, width, height, theme: chartTheme = "default" } = options;
73
71
  let chart = null;
74
72
  const render = (config) => {
75
- const { data = [], theme = chartTheme, title, axisXTitle, axisYTitle, style = {} } = config;
73
+ const {
74
+ data = [],
75
+ theme = chartTheme,
76
+ title,
77
+ subtitle,
78
+ axisXTitle,
79
+ axisYTitle,
80
+ style: localStyle = {}
81
+ } = config;
76
82
  if (chart) {
77
83
  chart.destroy();
78
84
  }
79
- const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
80
- const palette = style.palette || [];
81
- const positiveColor = palette[0] || DEFAULT_POSITIVE_COLOR;
82
- const negativeColor = palette[1] || DEFAULT_NEGATIVE_COLOR;
83
- const totalColor = palette[2] || DEFAULT_TOTAL_COLOR;
85
+ const appearance = (0, import_g22.getThemeObject)("waterfall", theme, localStyle);
86
+ const { theme: rendererTheme } = appearance;
87
+ const intervalMark = {
88
+ maxWidth: 60,
89
+ stroke: "#666",
90
+ ...rendererTheme.type !== "academy" ? { radius: 4 } : {},
91
+ ...appearance.mark.interval
92
+ };
93
+ const linkMark = {
94
+ stroke: "#ccc",
95
+ lineDash: [4, 2],
96
+ lineWidth: 1,
97
+ ...appearance.mark.link
98
+ };
99
+ const [positiveColor, negativeColor, totalColor] = rendererTheme.category10;
84
100
  const transformedData = transformWaterfallData(data);
85
101
  const linkData = generateLinkData(transformedData);
86
102
  chart = new import_g2.Chart({
@@ -93,16 +109,11 @@ var Waterfall = (options) => {
93
109
  animate: false,
94
110
  type: "view",
95
111
  data: transformedData,
96
- title: title ?? "",
112
+ title: title ? { title, subtitle } : "",
97
113
  marginRight: 28,
98
114
  axis: {
99
- x: {
100
- title: axisXTitle || false
101
- },
102
- y: {
103
- title: axisYTitle || false,
104
- labelFormatter: "~s"
105
- }
115
+ x: { title: axisXTitle || false },
116
+ y: { title: axisYTitle || false, labelFormatter: "~s" }
106
117
  },
107
118
  scale: {
108
119
  y: { nice: true }
@@ -112,27 +123,30 @@ var Waterfall = (options) => {
112
123
  type: "interval",
113
124
  animate: false,
114
125
  data: transformedData,
115
- encode: { x: "category", y: ["__start__", "__end__"], color: "category" },
126
+ encode: {
127
+ x: "category",
128
+ y: ["__start__", "__end__"],
129
+ color: "category"
130
+ },
116
131
  style: {
117
- maxWidth: 60,
118
- stroke: "#666",
119
- ...theme !== "academy" ? { radius: 4 } : {},
120
132
  fill: (d) => {
121
133
  return d.isTotal || d.isIntermediateTotal ? totalColor : d.__value__ > 0 ? positiveColor : negativeColor;
122
- }
134
+ },
135
+ ...intervalMark
123
136
  },
124
- labels: [
125
- {
126
- text: "__value__",
127
- position: "inside",
137
+ labels: (0, import_components.getDataLabels)(rendererTheme, {
138
+ style: {
128
139
  fontSize: 10,
129
- transform: [{ type: "overflowHide" }],
130
- formatter: "~s",
131
- fill: "#000",
132
140
  fontWeight: 600,
133
141
  stroke: "#fff"
134
- }
135
- ],
142
+ },
143
+ defaultVisible: true,
144
+ text: "__value__",
145
+ position: "inside",
146
+ contrast: "inside",
147
+ transform: [{ type: "overflowHide" }],
148
+ formatter: "~s"
149
+ }),
136
150
  tooltip: {
137
151
  title: (d) => d.category,
138
152
  items: [
@@ -163,17 +177,12 @@ var Waterfall = (options) => {
163
177
  y: "y"
164
178
  },
165
179
  zIndex: -1,
166
- style: {
167
- stroke: "#ccc",
168
- lineDash: [4, 2],
169
- lineWidth: 1
170
- },
180
+ style: linkMark,
171
181
  tooltip: false
172
182
  }
173
183
  ],
174
184
  legend: false,
175
- viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
176
- theme: (0, import_theme.getThemeObject)(theme)
185
+ theme: rendererTheme
177
186
  };
178
187
  chart.options(chartOptions);
179
188
  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
  * WordCloudDataItem is the type for each data item in the word cloud chart.
4
4
  */
@@ -14,11 +14,9 @@ export interface WordCloudConfig {
14
14
  data: WordCloudDataItem[];
15
15
  theme?: VisualizationTheme;
16
16
  title?: string;
17
+ subtitle?: string;
17
18
  locale?: string;
18
- style?: {
19
- backgroundColor?: string;
20
- palette?: string[];
21
- };
19
+ style?: ThemeStyle;
22
20
  }
23
21
  /**
24
22
  * WordCloudInstance represents a word cloud chart instance with render and destroy methods.