@antv/gpt-vis 1.0.2 → 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 (168) hide show
  1. package/README.md +29 -6
  2. package/README.zh-CN.md +32 -9
  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 +1 -2
  25. package/dist/cjs/util/crosshair-axis-labels.js +17 -0
  26. package/dist/cjs/util/index.d.ts +0 -2
  27. package/dist/cjs/util/index.js +1 -5
  28. package/dist/cjs/util/interaction.d.ts +4 -3
  29. package/dist/cjs/util/interaction.js +14 -1
  30. package/dist/cjs/util/tokens.d.ts +4 -3
  31. package/dist/cjs/util/tokens.js +9 -6
  32. package/dist/cjs/vis/area/index.d.ts +3 -6
  33. package/dist/cjs/vis/area/index.js +43 -30
  34. package/dist/cjs/vis/bar/index.d.ts +5 -5
  35. package/dist/cjs/vis/bar/index.js +34 -20
  36. package/dist/cjs/vis/boxplot/index.d.ts +4 -5
  37. package/dist/cjs/vis/boxplot/index.js +36 -23
  38. package/dist/cjs/vis/column/index.d.ts +5 -5
  39. package/dist/cjs/vis/column/index.js +38 -26
  40. package/dist/cjs/vis/dual-axes/index.d.ts +3 -4
  41. package/dist/cjs/vis/dual-axes/index.js +70 -52
  42. package/dist/cjs/vis/fishbone-diagram/index.d.ts +4 -10
  43. package/dist/cjs/vis/fishbone-diagram/index.js +43 -28
  44. package/dist/cjs/vis/flow-diagram/index.d.ts +4 -6
  45. package/dist/cjs/vis/flow-diagram/index.js +21 -22
  46. package/dist/cjs/vis/funnel/index.d.ts +3 -5
  47. package/dist/cjs/vis/funnel/index.js +63 -42
  48. package/dist/cjs/vis/histogram/index.d.ts +4 -6
  49. package/dist/cjs/vis/histogram/index.js +17 -19
  50. package/dist/cjs/vis/indented-tree/index.d.ts +4 -6
  51. package/dist/cjs/vis/indented-tree/index.js +58 -34
  52. package/dist/cjs/vis/line/index.d.ts +3 -6
  53. package/dist/cjs/vis/line/index.js +43 -22
  54. package/dist/cjs/vis/liquid/index.d.ts +4 -6
  55. package/dist/cjs/vis/liquid/index.js +22 -17
  56. package/dist/cjs/vis/mindmap/index.d.ts +4 -6
  57. package/dist/cjs/vis/mindmap/index.js +43 -25
  58. package/dist/cjs/vis/network-graph/index.d.ts +4 -6
  59. package/dist/cjs/vis/network-graph/index.js +26 -20
  60. package/dist/cjs/vis/organization-chart/index.d.ts +4 -6
  61. package/dist/cjs/vis/organization-chart/index.js +39 -33
  62. package/dist/cjs/vis/pie/index.d.ts +3 -5
  63. package/dist/cjs/vis/pie/index.js +45 -26
  64. package/dist/cjs/vis/radar/index.d.ts +3 -6
  65. package/dist/cjs/vis/radar/index.js +32 -24
  66. package/dist/cjs/vis/sankey/index.d.ts +4 -6
  67. package/dist/cjs/vis/sankey/index.js +17 -7
  68. package/dist/cjs/vis/scatter/index.d.ts +3 -5
  69. package/dist/cjs/vis/scatter/index.js +32 -19
  70. package/dist/cjs/vis/summary/index.js +5 -6
  71. package/dist/cjs/vis/table/index.d.ts +4 -2
  72. package/dist/cjs/vis/table/index.js +44 -4
  73. package/dist/cjs/vis/treemap/index.d.ts +4 -6
  74. package/dist/cjs/vis/treemap/index.js +11 -7
  75. package/dist/cjs/vis/venn/index.d.ts +4 -6
  76. package/dist/cjs/vis/venn/index.js +18 -16
  77. package/dist/cjs/vis/violin/index.d.ts +4 -5
  78. package/dist/cjs/vis/violin/index.js +35 -27
  79. package/dist/cjs/vis/waterfall/index.d.ts +4 -4
  80. package/dist/cjs/vis/waterfall/index.js +48 -39
  81. package/dist/cjs/vis/word-cloud/index.d.ts +3 -5
  82. package/dist/cjs/vis/word-cloud/index.js +18 -12
  83. package/dist/esm/index.d.ts +1 -1
  84. package/dist/esm/theme/g2.d.ts +9 -0
  85. package/dist/esm/theme/g2.js +504 -0
  86. package/dist/esm/theme/g6.d.ts +28 -0
  87. package/dist/esm/theme/g6.js +84 -0
  88. package/dist/esm/theme/merge.d.ts +2 -0
  89. package/dist/esm/theme/merge.js +36 -0
  90. package/dist/esm/theme/resolve.d.ts +7 -0
  91. package/dist/esm/theme/resolve.js +27 -0
  92. package/dist/esm/theme/shared.d.ts +7 -0
  93. package/dist/esm/theme/shared.js +21 -0
  94. package/dist/esm/theme/summary.d.ts +11 -0
  95. package/dist/esm/theme/summary.js +45 -0
  96. package/dist/esm/theme/table.d.ts +13 -0
  97. package/dist/esm/theme/table.js +112 -0
  98. package/dist/esm/types/index.d.ts +8 -5
  99. package/dist/esm/types/theme.d.ts +107 -0
  100. package/dist/esm/types/theme.js +1 -0
  101. package/dist/esm/util/animation.js +12 -2
  102. package/dist/esm/util/components.d.ts +20 -0
  103. package/dist/esm/util/components.js +57 -1
  104. package/dist/esm/util/crosshair-axis-labels.d.ts +1 -2
  105. package/dist/esm/util/crosshair-axis-labels.js +18 -0
  106. package/dist/esm/util/index.d.ts +0 -2
  107. package/dist/esm/util/index.js +1 -3
  108. package/dist/esm/util/interaction.d.ts +4 -3
  109. package/dist/esm/util/interaction.js +18 -1
  110. package/dist/esm/util/tokens.d.ts +4 -3
  111. package/dist/esm/util/tokens.js +9 -6
  112. package/dist/esm/vis/area/index.d.ts +3 -6
  113. package/dist/esm/vis/area/index.js +53 -45
  114. package/dist/esm/vis/bar/index.d.ts +5 -5
  115. package/dist/esm/vis/bar/index.js +38 -27
  116. package/dist/esm/vis/boxplot/index.d.ts +4 -5
  117. package/dist/esm/vis/boxplot/index.js +47 -29
  118. package/dist/esm/vis/column/index.d.ts +5 -5
  119. package/dist/esm/vis/column/index.js +46 -36
  120. package/dist/esm/vis/dual-axes/index.d.ts +3 -4
  121. package/dist/esm/vis/dual-axes/index.js +68 -58
  122. package/dist/esm/vis/fishbone-diagram/index.d.ts +4 -10
  123. package/dist/esm/vis/fishbone-diagram/index.js +52 -27
  124. package/dist/esm/vis/flow-diagram/index.d.ts +4 -6
  125. package/dist/esm/vis/flow-diagram/index.js +28 -23
  126. package/dist/esm/vis/funnel/index.d.ts +3 -5
  127. package/dist/esm/vis/funnel/index.js +63 -54
  128. package/dist/esm/vis/histogram/index.d.ts +4 -6
  129. package/dist/esm/vis/histogram/index.js +28 -21
  130. package/dist/esm/vis/indented-tree/index.d.ts +4 -6
  131. package/dist/esm/vis/indented-tree/index.js +59 -52
  132. package/dist/esm/vis/line/index.d.ts +3 -6
  133. package/dist/esm/vis/line/index.js +44 -32
  134. package/dist/esm/vis/liquid/index.d.ts +4 -6
  135. package/dist/esm/vis/liquid/index.js +28 -21
  136. package/dist/esm/vis/mindmap/index.d.ts +4 -6
  137. package/dist/esm/vis/mindmap/index.js +32 -28
  138. package/dist/esm/vis/network-graph/index.d.ts +4 -6
  139. package/dist/esm/vis/network-graph/index.js +37 -22
  140. package/dist/esm/vis/organization-chart/index.d.ts +4 -6
  141. package/dist/esm/vis/organization-chart/index.js +47 -36
  142. package/dist/esm/vis/pie/index.d.ts +3 -5
  143. package/dist/esm/vis/pie/index.js +42 -26
  144. package/dist/esm/vis/radar/index.d.ts +3 -6
  145. package/dist/esm/vis/radar/index.js +28 -20
  146. package/dist/esm/vis/sankey/index.d.ts +4 -6
  147. package/dist/esm/vis/sankey/index.js +20 -10
  148. package/dist/esm/vis/scatter/index.d.ts +3 -5
  149. package/dist/esm/vis/scatter/index.js +32 -21
  150. package/dist/esm/vis/summary/index.js +5 -7
  151. package/dist/esm/vis/table/index.d.ts +4 -2
  152. package/dist/esm/vis/table/index.js +41 -4
  153. package/dist/esm/vis/treemap/index.d.ts +4 -6
  154. package/dist/esm/vis/treemap/index.js +16 -11
  155. package/dist/esm/vis/venn/index.d.ts +4 -6
  156. package/dist/esm/vis/venn/index.js +24 -16
  157. package/dist/esm/vis/violin/index.d.ts +4 -5
  158. package/dist/esm/vis/violin/index.js +45 -37
  159. package/dist/esm/vis/waterfall/index.d.ts +4 -4
  160. package/dist/esm/vis/waterfall/index.js +46 -36
  161. package/dist/esm/vis/word-cloud/index.d.ts +3 -5
  162. package/dist/esm/vis/word-cloud/index.js +24 -17
  163. package/dist/umd/index.min.js +1 -1
  164. package/package.json +1 -1
  165. package/dist/cjs/util/theme.d.ts +0 -20
  166. package/dist/cjs/util/theme.js +0 -372
  167. package/dist/esm/util/theme.d.ts +0 -20
  168. package/dist/esm/util/theme.js +0 -326
@@ -24,6 +24,7 @@ __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");
27
28
  var import_html = require("../../util/html");
28
29
  var SCOPE_ID = "__gpt-vis-table__";
29
30
  var FONT_FAMILY = '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';
@@ -37,13 +38,22 @@ var TABLE_STYLES = `
37
38
  padding: 16px;
38
39
  }
39
40
 
41
+ .${SCOPE_ID} .table-heading {
42
+ margin-bottom: 12px;
43
+ }
44
+
40
45
  .${SCOPE_ID} .table-title {
41
46
  font-size: 16px;
42
47
  font-weight: 500;
43
- margin-bottom: 12px;
44
48
  color: #1d2129;
45
49
  }
46
50
 
51
+ .${SCOPE_ID} .table-subtitle {
52
+ margin-top: 4px;
53
+ font-size: 12px;
54
+ color: #667085;
55
+ }
56
+
47
57
  .${SCOPE_ID} .table-empty {
48
58
  padding: 20px;
49
59
  text-align: center;
@@ -102,6 +112,10 @@ var TABLE_STYLES = `
102
112
  color: #ffffffd9;
103
113
  }
104
114
 
115
+ .${SCOPE_ID}[data-theme="dark"] .table-subtitle {
116
+ color: #ffffffa6;
117
+ }
118
+
105
119
  .${SCOPE_ID}[data-theme="dark"] table {
106
120
  background: #141414;
107
121
  }
@@ -156,6 +170,23 @@ var injectStyles = () => {
156
170
  styleElement.textContent = TABLE_STYLES;
157
171
  document.head.appendChild(styleElement);
158
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
+ };
159
190
  var Table = (options) => {
160
191
  const { theme: chartTheme = "default" } = options;
161
192
  const container = typeof options.container === "string" ? document.querySelector(options.container) : options.container;
@@ -164,22 +195,30 @@ var Table = (options) => {
164
195
  }
165
196
  let tableWrapper = null;
166
197
  const render = (config) => {
167
- 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;
168
201
  injectStyles();
169
202
  if (tableWrapper) {
170
203
  tableWrapper.remove();
171
204
  }
172
205
  tableWrapper = document.createElement("div");
173
206
  tableWrapper.className = SCOPE_ID;
174
- if (theme === "dark") {
207
+ if (rendererTheme === "dark") {
175
208
  tableWrapper.setAttribute("data-theme", "dark");
176
209
  }
177
- const titleHTML = title ? `<div class="table-title">${(0, import_html.escapeHtml)(title)}</div>` : "";
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>` : "";
178
216
  if (data.length === 0) {
179
217
  tableWrapper.innerHTML = `
180
218
  ${titleHTML}
181
219
  <div class="table-empty">No data available</div>
182
220
  `;
221
+ applyResolvedTableStyle(tableWrapper, style);
183
222
  container.appendChild(tableWrapper);
184
223
  return;
185
224
  }
@@ -197,6 +236,7 @@ var Table = (options) => {
197
236
  <tbody>${bodyHTML}</tbody>
198
237
  </table>
199
238
  `;
239
+ applyResolvedTableStyle(tableWrapper, style);
200
240
  container.appendChild(tableWrapper);
201
241
  };
202
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.
@@ -23,8 +23,10 @@ __export(word_cloud_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(word_cloud_exports);
25
25
  var import_g2 = require("@antv/g2");
26
+ var import_g22 = require("../../theme/g2");
26
27
  var import_components = require("../../util/components");
27
- var import_theme = require("../../util/theme");
28
+ var import_interaction = require("../../util/interaction");
29
+ var import_tokens = require("../../util/tokens");
28
30
  var WORD_CLOUD_MAX_WORDS = 50;
29
31
  var WORD_CLOUD_FONT_FAMILY = "Impact";
30
32
  var WORD_CLOUD_ROTATIONS = [-90, -60, -30, 0, 30, 60];
@@ -61,7 +63,6 @@ var createSeededRandom = (seed) => {
61
63
  return ((value ^ value >>> 14) >>> 0) / 4294967296;
62
64
  };
63
65
  };
64
- var getWordCloudPalette = (palette, theme) => (0, import_theme.normalizePalette)(palette, theme);
65
66
  var prepareWordCloudData = (data, colors) => {
66
67
  const rankedData = data.map((item, index) => ({ item, index })).filter(
67
68
  ({ item }) => item.text.trim().length > 0 && Number.isFinite(item.value) && item.value > 0
@@ -97,8 +98,9 @@ var WordCloud = (options) => {
97
98
  data = [],
98
99
  theme = chartTheme,
99
100
  title,
101
+ subtitle,
100
102
  locale: renderLocale = locale,
101
- style = {}
103
+ style: localStyle = {}
102
104
  } = config;
103
105
  const chartLocale = (0, import_components.resolveChartLocale)(renderLocale);
104
106
  const labels = WORD_CLOUD_LABELS[chartLocale];
@@ -112,7 +114,11 @@ var WordCloud = (options) => {
112
114
  if (chart) {
113
115
  chart.destroy();
114
116
  }
115
- const colors = getWordCloudPalette(style.palette, theme);
117
+ const appearance = (0, import_g22.getThemeObject)("word-cloud", theme, localStyle);
118
+ const { theme: rendererTheme } = appearance;
119
+ const colors = rendererTheme.category10;
120
+ const wordCloudStyle = appearance.mark.wordCloud;
121
+ const fontFamily = wordCloudStyle.fontFamily ?? WORD_CLOUD_FONT_FAMILY;
116
122
  const preparedData = prepareWordCloudData(data, colors);
117
123
  const layoutSeed = hashWordCloudData(preparedData);
118
124
  const rotationRandom = createSeededRandom(layoutSeed ^ 2654435769);
@@ -126,9 +132,9 @@ var WordCloud = (options) => {
126
132
  animate: false,
127
133
  type: "wordCloud",
128
134
  data: preparedData,
129
- title: title ?? "",
135
+ title: title ? { title, subtitle } : "",
130
136
  layout: {
131
- font: WORD_CLOUD_FONT_FAMILY,
137
+ font: fontFamily,
132
138
  fontSize: [11, 44],
133
139
  fontWeight: (d) => d.fontWeight,
134
140
  padding: 2,
@@ -142,9 +148,10 @@ var WordCloud = (options) => {
142
148
  },
143
149
  style: {
144
150
  fill: (d) => d.wordColor,
145
- fontFamily: WORD_CLOUD_FONT_FAMILY,
151
+ fontFamily,
146
152
  fontWeight: (d) => d.weight ?? d.fontWeight,
147
- stroke: (d) => d.wordColor
153
+ stroke: (d) => d.wordColor,
154
+ ...wordCloudStyle
148
155
  },
149
156
  scale: {
150
157
  color: { range: colors }
@@ -179,11 +186,10 @@ var WordCloud = (options) => {
179
186
  },
180
187
  interaction: {
181
188
  tooltip: true,
182
- elementHighlight: true,
183
- elementHoverScale: true
189
+ elementHighlight: { delay: import_tokens.CHART_STYLE_DEFAULTS.interactionDelay },
190
+ elementHoverScale: (0, import_interaction.getElementHoverScaleInteraction)(rendererTheme.type)
184
191
  },
185
- viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
186
- theme: (0, import_theme.getThemeObject)(theme)
192
+ theme: rendererTheme
187
193
  };
188
194
  chart.options(chartOptions);
189
195
  chart.render();