@antv/gpt-vis 1.0.0-beta.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +282 -43
  2. package/README.zh-CN.md +286 -47
  3. package/dist/cjs/gpt-vis/index.js +1 -1
  4. package/dist/cjs/types/index.d.ts +2 -1
  5. package/dist/cjs/util/animation.d.ts +2 -0
  6. package/dist/cjs/util/animation.js +38 -0
  7. package/dist/cjs/util/components.d.ts +15 -0
  8. package/dist/cjs/util/components.js +94 -0
  9. package/dist/cjs/util/crosshair-axis-labels.d.ts +9 -0
  10. package/dist/cjs/util/crosshair-axis-labels.js +304 -0
  11. package/dist/cjs/util/index.d.ts +6 -0
  12. package/dist/cjs/util/index.js +33 -0
  13. package/dist/cjs/util/interaction.d.ts +14 -0
  14. package/dist/cjs/util/interaction.js +89 -0
  15. package/dist/cjs/util/theme.d.ts +18 -24
  16. package/dist/cjs/util/theme.js +303 -120
  17. package/dist/cjs/util/tokens.d.ts +31 -0
  18. package/dist/cjs/util/tokens.js +98 -0
  19. package/dist/cjs/vis/area/index.d.ts +2 -2
  20. package/dist/cjs/vis/area/index.js +76 -31
  21. package/dist/cjs/vis/bar/index.d.ts +2 -2
  22. package/dist/cjs/vis/bar/index.js +22 -19
  23. package/dist/cjs/vis/boxplot/index.js +1 -4
  24. package/dist/cjs/vis/column/index.d.ts +2 -2
  25. package/dist/cjs/vis/column/index.js +28 -18
  26. package/dist/cjs/vis/dual-axes/index.d.ts +2 -2
  27. package/dist/cjs/vis/dual-axes/index.js +90 -36
  28. package/dist/cjs/vis/fishbone-diagram/index.js +12 -4
  29. package/dist/cjs/vis/flow-diagram/index.js +27 -11
  30. package/dist/cjs/vis/funnel/index.d.ts +4 -2
  31. package/dist/cjs/vis/funnel/index.js +171 -92
  32. package/dist/cjs/vis/histogram/index.js +1 -4
  33. package/dist/cjs/vis/indented-tree/index.js +13 -3
  34. package/dist/cjs/vis/line/index.d.ts +2 -2
  35. package/dist/cjs/vis/line/index.js +71 -31
  36. package/dist/cjs/vis/liquid/index.d.ts +2 -2
  37. package/dist/cjs/vis/liquid/index.js +41 -16
  38. package/dist/cjs/vis/mindmap/index.js +12 -4
  39. package/dist/cjs/vis/network-graph/index.js +11 -2
  40. package/dist/cjs/vis/organization-chart/index.js +12 -3
  41. package/dist/cjs/vis/pie/index.d.ts +2 -2
  42. package/dist/cjs/vis/pie/index.js +26 -16
  43. package/dist/cjs/vis/radar/index.d.ts +2 -2
  44. package/dist/cjs/vis/radar/index.js +21 -29
  45. package/dist/cjs/vis/sankey/index.js +1 -4
  46. package/dist/cjs/vis/scatter/index.d.ts +4 -2
  47. package/dist/cjs/vis/scatter/index.js +43 -16
  48. package/dist/cjs/vis/treemap/index.js +1 -4
  49. package/dist/cjs/vis/venn/index.js +1 -4
  50. package/dist/cjs/vis/violin/index.js +1 -1
  51. package/dist/cjs/vis/waterfall/index.js +2 -2
  52. package/dist/cjs/vis/word-cloud/index.d.ts +3 -2
  53. package/dist/cjs/vis/word-cloud/index.js +125 -10
  54. package/dist/esm/gpt-vis/index.js +1 -1
  55. package/dist/esm/types/index.d.ts +2 -1
  56. package/dist/esm/util/animation.d.ts +2 -0
  57. package/dist/esm/util/animation.js +17 -0
  58. package/dist/esm/util/components.d.ts +15 -0
  59. package/dist/esm/util/components.js +67 -0
  60. package/dist/esm/util/crosshair-axis-labels.d.ts +9 -0
  61. package/dist/esm/util/crosshair-axis-labels.js +328 -0
  62. package/dist/esm/util/index.d.ts +6 -0
  63. package/dist/esm/util/index.js +6 -0
  64. package/dist/esm/util/interaction.d.ts +14 -0
  65. package/dist/esm/util/interaction.js +73 -0
  66. package/dist/esm/util/theme.d.ts +18 -24
  67. package/dist/esm/util/theme.js +302 -126
  68. package/dist/esm/util/tokens.d.ts +31 -0
  69. package/dist/esm/util/tokens.js +64 -0
  70. package/dist/esm/vis/area/index.d.ts +2 -2
  71. package/dist/esm/vis/area/index.js +91 -41
  72. package/dist/esm/vis/bar/index.d.ts +2 -2
  73. package/dist/esm/vis/bar/index.js +28 -29
  74. package/dist/esm/vis/boxplot/index.js +4 -5
  75. package/dist/esm/vis/column/index.d.ts +2 -2
  76. package/dist/esm/vis/column/index.js +36 -29
  77. package/dist/esm/vis/dual-axes/index.d.ts +2 -2
  78. package/dist/esm/vis/dual-axes/index.js +123 -43
  79. package/dist/esm/vis/fishbone-diagram/index.js +6 -5
  80. package/dist/esm/vis/flow-diagram/index.js +17 -10
  81. package/dist/esm/vis/funnel/index.d.ts +4 -2
  82. package/dist/esm/vis/funnel/index.js +156 -83
  83. package/dist/esm/vis/histogram/index.js +4 -5
  84. package/dist/esm/vis/indented-tree/index.js +9 -4
  85. package/dist/esm/vis/line/index.d.ts +2 -2
  86. package/dist/esm/vis/line/index.js +80 -37
  87. package/dist/esm/vis/liquid/index.d.ts +2 -2
  88. package/dist/esm/vis/liquid/index.js +41 -14
  89. package/dist/esm/vis/mindmap/index.js +6 -5
  90. package/dist/esm/vis/network-graph/index.js +5 -3
  91. package/dist/esm/vis/organization-chart/index.js +6 -4
  92. package/dist/esm/vis/pie/index.d.ts +2 -2
  93. package/dist/esm/vis/pie/index.js +36 -16
  94. package/dist/esm/vis/radar/index.d.ts +2 -2
  95. package/dist/esm/vis/radar/index.js +21 -34
  96. package/dist/esm/vis/sankey/index.js +4 -5
  97. package/dist/esm/vis/scatter/index.d.ts +4 -2
  98. package/dist/esm/vis/scatter/index.js +45 -19
  99. package/dist/esm/vis/treemap/index.js +4 -5
  100. package/dist/esm/vis/venn/index.js +4 -5
  101. package/dist/esm/vis/violin/index.js +5 -13
  102. package/dist/esm/vis/waterfall/index.js +11 -11
  103. package/dist/esm/vis/word-cloud/index.d.ts +3 -2
  104. package/dist/esm/vis/word-cloud/index.js +158 -10
  105. package/dist/umd/index.min.js +1 -1
  106. package/package.json +18 -19
@@ -23,12 +23,14 @@ __export(area_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(area_exports);
25
25
  var import_g2 = require("@antv/g2");
26
- var import_theme = require("../../util/theme");
27
- var getLinearGradientColor = (color) => `linear-gradient(-90deg, white 0%, ${color} 100%)`;
26
+ var import_util = require("../../util");
27
+ var getLinearGradientColor = (color, backgroundColor = "white") => `linear-gradient(-90deg, ${backgroundColor} 0%, ${color} 100%)`;
28
28
  var DEFAULT_COLOR = "#3A95FF";
29
29
  var Area = (options) => {
30
30
  const { container, width, height, theme: chartTheme = "default" } = options;
31
31
  let chart = null;
32
+ let hasRendered = false;
33
+ let cleanupCrosshairAxisLabels = null;
32
34
  const render = (config) => {
33
35
  var _a;
34
36
  const {
@@ -41,13 +43,31 @@ var Area = (options) => {
41
43
  style = {}
42
44
  } = config;
43
45
  if (chart) {
46
+ cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
47
+ cleanupCrosshairAxisLabels = null;
44
48
  chart.destroy();
45
49
  }
46
- const { lineWidth = 2 } = style;
50
+ const { lineWidth = import_util.CHART_STYLE_DEFAULTS.lineWidth } = style;
47
51
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
48
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
49
- const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
50
- const fillColor = getLinearGradientColor(colors[0] || DEFAULT_COLOR);
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
+ const cartesianAxisOptions = {
58
+ axisXTitle,
59
+ axisYTitle,
60
+ xLabels: data.map(({ time }) => time),
61
+ chartWidth: width
62
+ };
63
+ const tooltip = {
64
+ items: [
65
+ (d) => ({
66
+ name: hasGroupField ? d.group : axisYTitle || d.time,
67
+ value: d.value
68
+ })
69
+ ]
70
+ };
51
71
  chart = new import_g2.Chart({
52
72
  container,
53
73
  width,
@@ -65,11 +85,11 @@ var Area = (options) => {
65
85
  children = [
66
86
  {
67
87
  type: "area",
68
- style: { fillOpacity: 0.6 }
88
+ style: { fillOpacity: areaOpacity }
69
89
  },
70
90
  {
71
91
  type: "line",
72
- style: { lineWidth, strokeOpacity: 0.6 }
92
+ style: { lineWidth, strokeOpacity: lineOpacity }
73
93
  }
74
94
  ];
75
95
  } else if (hasGroupField) {
@@ -78,11 +98,11 @@ var Area = (options) => {
78
98
  children = [
79
99
  {
80
100
  type: "area",
81
- style: { fillOpacity: 0.6 }
101
+ style: { fillOpacity: areaOpacity }
82
102
  },
83
103
  {
84
104
  type: "line",
85
- style: { lineWidth, strokeOpacity: 0.6 }
105
+ style: { lineWidth, strokeOpacity: lineOpacity }
86
106
  }
87
107
  ];
88
108
  } else {
@@ -91,7 +111,7 @@ var Area = (options) => {
91
111
  {
92
112
  type: "area",
93
113
  style: {
94
- fillOpacity: 0.6,
114
+ fillOpacity: areaOpacity,
95
115
  fill: fillColor
96
116
  }
97
117
  },
@@ -99,47 +119,72 @@ var Area = (options) => {
99
119
  type: "line",
100
120
  style: {
101
121
  lineWidth,
102
- strokeOpacity: 0.6,
103
- ...style.palette ? { stroke: colors[0] } : {}
122
+ strokeOpacity: lineOpacity,
123
+ lineCap: "round",
124
+ lineJoin: "round",
125
+ stroke: colors[0]
104
126
  }
105
127
  }
106
128
  ];
107
129
  }
130
+ children = children.map((child) => ({
131
+ ...child,
132
+ animate: (0, import_util.getChartAnimation)(hasRendered, child.type === "line" ? "pathIn" : "fadeIn"),
133
+ tooltip: child.type === "line" ? tooltip : false,
134
+ state: hasGroupField ? child.type === "area" ? {
135
+ active: { fillOpacity: Math.min(areaOpacity + 0.1, 1) },
136
+ inactive: { fillOpacity: 0.07 }
137
+ } : (0, import_util.getLineHighlightState)(lineWidth) : void 0
138
+ }));
139
+ if (!hasGroupField && data.length <= 24) {
140
+ children.push({
141
+ type: "point",
142
+ encode: {
143
+ x: "time",
144
+ y: "value",
145
+ shape: "point",
146
+ size: import_util.CHART_STYLE_DEFAULTS.pointSize
147
+ },
148
+ animate: (0, import_util.getChartAnimation)(hasRendered, "fadeIn"),
149
+ tooltip: false,
150
+ style: {
151
+ lineWidth: import_util.CHART_STYLE_DEFAULTS.pointLineWidth,
152
+ fill: colors[0],
153
+ stroke: backgroundColor
154
+ }
155
+ });
156
+ }
108
157
  const chartOptions = {
109
- animate: false,
110
158
  type: "view",
111
159
  data,
112
- title: title ?? "",
160
+ title: title || "",
113
161
  encode,
114
162
  transform,
115
163
  children,
116
164
  scale: scaleConfig,
117
- axis: {
118
- x: { title: axisXTitle || false },
119
- y: { title: axisYTitle || false }
120
- },
121
- legend: hasGroupField ? { color: { position: "top" } } : false,
122
- tooltip: {
123
- items: [
124
- (d) => ({
125
- name: axisYTitle || d.time,
126
- value: d.value
127
- })
128
- ]
129
- },
130
- viewStyle: {
131
- viewFill: backgroundColor
165
+ ...(0, import_util.getCartesianLayout)(cartesianAxisOptions),
166
+ axis: (0, import_util.getCartesianAxis)(cartesianAxisOptions),
167
+ legend: (0, import_util.getColorLegend)(hasGroupField),
168
+ interaction: {
169
+ tooltip: (0, import_util.getSharedTooltipInteraction)({ crosshairs: true }),
170
+ ...hasGroupField ? (0, import_util.getSeriesHighlightByColorInteraction)() : {}
132
171
  },
133
- theme: (0, import_theme.getThemeObject)(theme)
172
+ viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
173
+ theme: (0, import_util.getThemeObject)(theme)
134
174
  };
135
175
  chart.options(chartOptions);
176
+ cleanupCrosshairAxisLabels = (0, import_util.bindCrosshairAxisLabels)(chart, theme);
136
177
  chart.render();
178
+ hasRendered = true;
137
179
  };
138
180
  const destroy = () => {
139
181
  if (chart) {
182
+ cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
183
+ cleanupCrosshairAxisLabels = null;
140
184
  chart.destroy();
141
185
  chart = null;
142
186
  }
187
+ hasRendered = false;
143
188
  };
144
189
  return {
145
190
  render,
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * BarDataItem is the type for each data item in the bar chart.
4
4
  */
@@ -18,7 +18,7 @@ export interface BarConfig {
18
18
  title?: string;
19
19
  axisXTitle?: string;
20
20
  axisYTitle?: string;
21
- theme?: 'default' | 'academy' | 'dark';
21
+ theme?: VisualizationTheme;
22
22
  style?: {
23
23
  backgroundColor?: string;
24
24
  palette?: string[];
@@ -23,10 +23,11 @@ __export(bar_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(bar_exports);
25
25
  var import_g2 = require("@antv/g2");
26
- var import_theme = require("../../util/theme");
26
+ var import_util = require("../../util");
27
27
  var Bar = (options) => {
28
28
  const { container, width, height, theme: chartTheme = "default" } = options;
29
29
  let chart = null;
30
+ let hasRendered = false;
30
31
  const render = (config) => {
31
32
  var _a;
32
33
  const {
@@ -43,8 +44,7 @@ var Bar = (options) => {
43
44
  chart.destroy();
44
45
  }
45
46
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
46
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
47
- const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
47
+ const colors = (0, import_util.normalizePalette)(style.palette, theme);
48
48
  chart = new import_g2.Chart({
49
49
  container,
50
50
  width,
@@ -55,7 +55,7 @@ var Bar = (options) => {
55
55
  let transform = [];
56
56
  let radiusStyle = {};
57
57
  if (theme !== "academy") {
58
- radiusStyle = { radiusTopLeft: 4, radiusTopRight: 4 };
58
+ radiusStyle = { radius: 4 };
59
59
  }
60
60
  if (hasGroupField && group) {
61
61
  transform = [{ type: "dodgeX" }];
@@ -66,51 +66,54 @@ var Bar = (options) => {
66
66
  if (hasGroupField) {
67
67
  encode = { x: "category", y: "value", color: "group" };
68
68
  } else {
69
- encode = { x: "category", y: "value", color: "category" };
69
+ encode = { x: "category", y: "value" };
70
70
  }
71
71
  const scaleConfig = {
72
72
  y: { nice: true },
73
- ...style.palette ? { color: { range: colors } } : {}
73
+ ...hasGroupField ? { color: { range: colors } } : {}
74
74
  };
75
75
  const chartOptions = {
76
- animate: false,
76
+ animate: (0, import_util.getChartAnimation)(hasRendered, "growInX"),
77
77
  type: "interval",
78
78
  data,
79
- title: title ?? "",
79
+ title: title || "",
80
80
  encode,
81
81
  transform,
82
82
  coordinate: { transform: [{ type: "transpose" }] },
83
83
  scale: scaleConfig,
84
- axis: {
85
- x: { title: axisXTitle || false },
86
- y: { title: axisYTitle || false }
87
- },
88
- legend: hasGroupField ? { color: { position: "top" } } : false,
84
+ axis: (0, import_util.getCartesianAxis)({ axisXTitle, axisYTitle }),
85
+ legend: (0, import_util.getColorLegend)(hasGroupField),
89
86
  tooltip: {
90
87
  items: [
91
88
  (d) => ({
92
- name: axisYTitle || d.category,
89
+ name: hasGroupField ? d.group : axisYTitle || d.category,
93
90
  value: d.value
94
91
  })
95
92
  ]
96
93
  },
94
+ state: (0, import_util.getCategoryBackgroundHighlightState)(theme),
95
+ interaction: {
96
+ tooltip: true,
97
+ elementHighlight: (0, import_util.getCategoryHighlightInteraction)()
98
+ },
97
99
  style: {
98
100
  ...radiusStyle,
99
- columnWidthRatio: 0.8
100
- },
101
- viewStyle: {
102
- viewFill: backgroundColor
101
+ columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
102
+ ...!hasGroupField ? { fill: colors[0] } : {}
103
103
  },
104
- theme: (0, import_theme.getThemeObject)(theme)
104
+ viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
105
+ theme: (0, import_util.getThemeObject)(theme)
105
106
  };
106
107
  chart.options(chartOptions);
107
108
  chart.render();
109
+ hasRendered = true;
108
110
  };
109
111
  const destroy = () => {
110
112
  if (chart) {
111
113
  chart.destroy();
112
114
  chart = null;
113
115
  }
116
+ hasRendered = false;
114
117
  };
115
118
  return {
116
119
  render,
@@ -34,7 +34,6 @@ var Boxplot = (options) => {
34
34
  chart.destroy();
35
35
  }
36
36
  const colors = (0, import_theme.normalizePalette)(style.palette, theme);
37
- const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
38
37
  const startAtZero = style.startAtZero || false;
39
38
  const hasGroupField = ((_a = (data || [])[0]) == null ? void 0 : _a.group) !== void 0;
40
39
  let encode = {};
@@ -86,9 +85,7 @@ var Boxplot = (options) => {
86
85
  legend: {
87
86
  color: hasGroupField ? { position: "top" } : false
88
87
  },
89
- viewStyle: {
90
- viewFill: backgroundColor
91
- },
88
+ viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
92
89
  theme: (0, import_theme.getThemeObject)(theme)
93
90
  };
94
91
  chart.options(chartOptions);
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * ColumnDataItem is the type for each data item in the column chart.
4
4
  */
@@ -18,7 +18,7 @@ export interface ColumnConfig {
18
18
  title?: string;
19
19
  axisXTitle?: string;
20
20
  axisYTitle?: string;
21
- theme?: 'default' | 'academy' | 'dark';
21
+ theme?: VisualizationTheme;
22
22
  style?: {
23
23
  backgroundColor?: string;
24
24
  palette?: string[];
@@ -23,10 +23,11 @@ __export(column_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(column_exports);
25
25
  var import_g2 = require("@antv/g2");
26
- var import_theme = require("../../util/theme");
26
+ var import_util = require("../../util");
27
27
  var Column = (options) => {
28
28
  const { container, width, height, theme: chartTheme = "default" } = options;
29
29
  let chart = null;
30
+ let hasRendered = false;
30
31
  const render = (config) => {
31
32
  var _a;
32
33
  const {
@@ -43,8 +44,7 @@ var Column = (options) => {
43
44
  chart.destroy();
44
45
  }
45
46
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
46
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
47
- const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
47
+ const colors = (0, import_util.normalizePalette)(style.palette, theme);
48
48
  chart = new import_g2.Chart({
49
49
  container,
50
50
  width,
@@ -66,50 +66,60 @@ var Column = (options) => {
66
66
  if (hasGroupField) {
67
67
  encode = { x: "category", y: "value", color: "group" };
68
68
  } else {
69
- encode = { x: "category", y: "value", color: "category" };
69
+ encode = { x: "category", y: "value" };
70
70
  }
71
71
  const scaleConfig = {
72
72
  y: { nice: true },
73
- ...style.palette ? { color: { range: colors } } : {}
73
+ ...hasGroupField ? { color: { range: colors } } : {}
74
+ };
75
+ const cartesianAxisOptions = {
76
+ axisXTitle,
77
+ axisYTitle,
78
+ xLabels: data.map(({ category }) => category),
79
+ chartWidth: width
74
80
  };
75
81
  const chartOptions = {
76
- animate: false,
82
+ animate: (0, import_util.getChartAnimation)(hasRendered, "growInY"),
77
83
  type: "interval",
78
84
  data,
79
- title: title ?? "",
85
+ title: title || "",
80
86
  encode,
81
87
  transform,
82
88
  scale: scaleConfig,
83
- axis: {
84
- x: { title: axisXTitle || false },
85
- y: { title: axisYTitle || false }
86
- },
87
- legend: hasGroupField ? { color: { position: "top" } } : false,
89
+ ...(0, import_util.getCartesianLayout)(cartesianAxisOptions),
90
+ axis: (0, import_util.getCartesianAxis)(cartesianAxisOptions),
91
+ legend: (0, import_util.getColorLegend)(hasGroupField),
88
92
  tooltip: {
89
93
  items: [
90
94
  (d) => ({
91
- name: axisYTitle || d.category,
95
+ name: hasGroupField ? d.group : axisYTitle || d.category,
92
96
  value: d.value
93
97
  })
94
98
  ]
95
99
  },
100
+ state: (0, import_util.getCategoryBackgroundHighlightState)(theme),
101
+ interaction: {
102
+ tooltip: true,
103
+ elementHighlight: (0, import_util.getCategoryHighlightInteraction)()
104
+ },
96
105
  style: {
97
106
  ...radiusStyle,
98
- columnWidthRatio: 0.8
99
- },
100
- viewStyle: {
101
- viewFill: backgroundColor
107
+ columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
108
+ ...!hasGroupField ? { fill: colors[0] } : {}
102
109
  },
103
- theme: (0, import_theme.getThemeObject)(theme)
110
+ viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
111
+ theme: (0, import_util.getThemeObject)(theme)
104
112
  };
105
113
  chart.options(chartOptions);
106
114
  chart.render();
115
+ hasRendered = true;
107
116
  };
108
117
  const destroy = () => {
109
118
  if (chart) {
110
119
  chart.destroy();
111
120
  chart = null;
112
121
  }
122
+ hasRendered = false;
113
123
  };
114
124
  return {
115
125
  render,
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions } from '../../types';
1
+ import type { VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * DualAxesSeriesItem defines a single series in the dual-axes chart.
4
4
  */
@@ -16,7 +16,7 @@ export interface DualAxesConfig {
16
16
  series: DualAxesSeriesItem[];
17
17
  title?: string;
18
18
  axisXTitle?: string;
19
- theme?: 'default' | 'academy' | 'dark';
19
+ theme?: VisualizationTheme;
20
20
  style?: {
21
21
  backgroundColor?: string;
22
22
  palette?: string[];
@@ -23,13 +23,13 @@ __export(dual_axes_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(dual_axes_exports);
25
25
  var import_g2 = require("@antv/g2");
26
- var import_theme = require("../../util/theme");
26
+ var import_util = require("../../util");
27
+ var getSeriesField = (index) => `value_${index + 1}`;
27
28
  function transformData(series, categories) {
28
29
  return categories.map((category, index) => {
29
30
  const dataPoint = { category };
30
- series.forEach((s, i) => {
31
- const yField = s.axisYTitle || `value_${i + 1}`;
32
- dataPoint[yField] = s.data[index];
31
+ series.forEach((item, seriesIndex) => {
32
+ dataPoint[getSeriesField(seriesIndex)] = item.data[index];
33
33
  });
34
34
  return dataPoint;
35
35
  });
@@ -37,14 +37,19 @@ function transformData(series, categories) {
37
37
  var DualAxes = (options) => {
38
38
  const { container, width, height, theme: chartTheme = "default" } = options;
39
39
  let chart = null;
40
+ let hasRendered = false;
40
41
  const render = (config) => {
41
42
  const { categories, series, theme = chartTheme, title, axisXTitle, style = {} } = config;
42
43
  if (chart) {
43
44
  chart.destroy();
44
45
  }
45
46
  const { startAtZero = false } = style;
46
- const colors = (0, import_theme.normalizePalette)(style.palette, theme);
47
- const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
47
+ const requestedColors = style.palette ? (0, import_util.normalizePalette)(style.palette, theme) : [];
48
+ const defaultColors = (0, import_util.normalizePalette)(void 0, theme);
49
+ const colors = [
50
+ ...requestedColors,
51
+ ...defaultColors.filter((color) => !requestedColors.includes(color))
52
+ ];
48
53
  const data = transformData(series, categories);
49
54
  chart = new import_g2.Chart({
50
55
  container,
@@ -52,13 +57,34 @@ var DualAxes = (options) => {
52
57
  height,
53
58
  autoFit: true
54
59
  });
55
- const sortedSeries = [...series].sort((a, b) => {
60
+ const sortedSeries = series.map((item, originalIndex) => ({ item, originalIndex })).sort((a, b) => {
56
61
  const order = ["column", "line"];
57
- return order.indexOf(a.type) - order.indexOf(b.type);
62
+ return order.indexOf(a.item.type) - order.indexOf(b.item.type);
58
63
  });
59
- const children = sortedSeries.map((item, index) => {
60
- const yField = item.axisYTitle || `value_${index + 1}`;
61
- const color = colors[index % colors.length];
64
+ const seriesMeta = sortedSeries.map(({ item, originalIndex }, index) => ({
65
+ item,
66
+ yField: getSeriesField(originalIndex),
67
+ displayName: item.axisYTitle || getSeriesField(originalIndex),
68
+ color: colors[index % colors.length]
69
+ }));
70
+ const seriesByField = new Map(
71
+ seriesMeta.map(({ item, yField, displayName }) => [yField, { type: item.type, displayName }])
72
+ );
73
+ const cartesianAxisOptions = {
74
+ axisXTitle,
75
+ xLabels: categories,
76
+ chartWidth: width
77
+ };
78
+ const cartesianAxis = (0, import_util.getCartesianAxis)(cartesianAxisOptions);
79
+ const children = seriesMeta.map(({ item, yField, displayName, color }) => {
80
+ const tooltip = {
81
+ items: [
82
+ (datum) => ({
83
+ name: displayName,
84
+ value: datum[yField]
85
+ })
86
+ ]
87
+ };
62
88
  if (item.type === "column") {
63
89
  return {
64
90
  type: "interval",
@@ -68,17 +94,24 @@ var DualAxes = (options) => {
68
94
  color: () => yField
69
95
  },
70
96
  scale: {
71
- y: { nice: true, zero: startAtZero },
72
- color: { range: [color] }
97
+ y: { nice: true, zero: startAtZero }
73
98
  },
99
+ tooltip,
74
100
  axis: {
75
- y: { title: item.axisYTitle || "" }
101
+ y: {
102
+ ...cartesianAxis.y,
103
+ title: item.axisYTitle || "",
104
+ titleFill: color,
105
+ titleFontWeight: 500
106
+ }
76
107
  },
77
108
  style: {
78
- columnWidthRatio: 0.8,
79
- radiusTopLeft: 4,
80
- radiusTopRight: 4
81
- }
109
+ fill: color,
110
+ fillOpacity: 0.86,
111
+ columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
112
+ ...theme !== "academy" ? { radiusTopLeft: 4, radiusTopRight: 4 } : {}
113
+ },
114
+ animate: (0, import_util.getChartAnimation)(hasRendered, "growInY")
82
115
  };
83
116
  } else {
84
117
  return {
@@ -90,52 +123,73 @@ var DualAxes = (options) => {
90
123
  color: () => yField
91
124
  },
92
125
  scale: {
93
- y: { independent: true, zero: startAtZero },
94
- color: { range: [color] }
126
+ y: { independent: true, zero: startAtZero }
95
127
  },
128
+ tooltip,
96
129
  axis: {
97
- y: { position: "right", title: item.axisYTitle || "" }
130
+ y: {
131
+ ...cartesianAxis.y,
132
+ position: "right",
133
+ title: item.axisYTitle || "",
134
+ titleFill: color,
135
+ titleFontWeight: 500,
136
+ grid: false
137
+ }
98
138
  },
99
139
  style: {
100
- lineWidth: 2
101
- }
140
+ stroke: color,
141
+ lineWidth: import_util.CHART_STYLE_DEFAULTS.lineWidth,
142
+ lineCap: "round",
143
+ lineJoin: "round"
144
+ },
145
+ state: (0, import_util.getLineHighlightState)(import_util.CHART_STYLE_DEFAULTS.lineWidth),
146
+ animate: (0, import_util.getChartAnimation)(hasRendered, "pathIn")
102
147
  };
103
148
  }
104
149
  });
105
150
  const chartOptions = {
106
- animate: false,
107
151
  type: "view",
108
152
  data,
109
- title: title ?? "",
153
+ title: title || "",
110
154
  children,
111
- axis: {
112
- x: { title: axisXTitle || false }
113
- },
155
+ ...(0, import_util.getCartesianLayout)(cartesianAxisOptions),
156
+ axis: { x: cartesianAxis.x },
114
157
  scale: {
115
- y: { nice: true }
158
+ y: { nice: true },
159
+ color: {
160
+ domain: seriesMeta.map(({ yField }) => yField),
161
+ range: seriesMeta.map(({ color }) => color)
162
+ }
116
163
  },
117
164
  legend: {
118
165
  color: {
119
- position: "top",
120
- itemMarker: (v, index) => {
121
- const seriesItem = series[index];
122
- return (seriesItem == null ? void 0 : seriesItem.type) === "line" ? "smooth" : "rect";
166
+ labelFormatter: (value) => {
167
+ var _a;
168
+ return ((_a = seriesByField.get(value)) == null ? void 0 : _a.displayName) || value;
169
+ },
170
+ itemMarker: (value) => {
171
+ var _a;
172
+ return ((_a = seriesByField.get(value)) == null ? void 0 : _a.type) === "line" ? "smooth" : "rect";
123
173
  }
124
174
  }
125
175
  },
126
- viewStyle: {
127
- viewFill: backgroundColor
176
+ interaction: {
177
+ tooltip: (0, import_util.getSharedTooltipInteraction)({ crosshairs: true }),
178
+ ...(0, import_util.getSeriesHighlightByColorInteraction)()
128
179
  },
129
- theme: (0, import_theme.getThemeObject)(theme)
180
+ viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
181
+ theme: (0, import_util.getThemeObject)(theme)
130
182
  };
131
183
  chart.options(chartOptions);
132
184
  chart.render();
185
+ hasRendered = true;
133
186
  };
134
187
  const destroy = () => {
135
188
  if (chart) {
136
189
  chart.destroy();
137
190
  chart = null;
138
191
  }
192
+ hasRendered = false;
139
193
  };
140
194
  return {
141
195
  render,
@@ -100,9 +100,17 @@ var FishboneDiagram = (options) => {
100
100
  height,
101
101
  autoFit: "view",
102
102
  autoResize: true,
103
- padding: 20,
104
- theme: chartTheme,
105
- plugins: title ? [{ key: "title", type: "title", title, titleFill: isDark ? "#e0e6ed" : "#1a1a2e" }] : [],
103
+ padding: title ? [46, 20, 20, 20] : 20,
104
+ theme: (0, import_theme.getTheme)(theme),
105
+ plugins: title ? [
106
+ {
107
+ key: "title",
108
+ type: "title",
109
+ title,
110
+ titleFill: isDark ? "#e0e6ed" : "#000",
111
+ titleFontFamily: "sans-serif"
112
+ }
113
+ ] : [],
106
114
  data: graphData,
107
115
  node: {
108
116
  type: "rect",
@@ -110,7 +118,7 @@ var FishboneDiagram = (options) => {
110
118
  var _a;
111
119
  const depth = d.depth ?? 0;
112
120
  const nodeStyle = {
113
- radius: 8,
121
+ radius: theme === "academy" ? 0 : 8,
114
122
  size: getNodeSize(String(d.id), depth),
115
123
  labelText: String(d.id),
116
124
  labelPlacement: "left",