@antv/gpt-vis 1.0.0 → 1.0.2
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.
- package/README.md +153 -34
- package/README.zh-CN.md +153 -34
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/util/animation.d.ts +2 -0
- package/dist/cjs/util/animation.js +38 -0
- package/dist/cjs/util/components.d.ts +15 -0
- package/dist/cjs/util/components.js +94 -0
- package/dist/cjs/util/crosshair-axis-labels.d.ts +15 -0
- package/dist/cjs/util/crosshair-axis-labels.js +401 -0
- package/dist/cjs/util/html.d.ts +1 -0
- package/dist/cjs/util/html.js +29 -0
- package/dist/cjs/util/index.d.ts +6 -0
- package/dist/cjs/util/index.js +33 -0
- package/dist/cjs/util/interaction.d.ts +14 -0
- package/dist/cjs/util/interaction.js +89 -0
- package/dist/cjs/util/theme.d.ts +18 -24
- package/dist/cjs/util/theme.js +303 -120
- package/dist/cjs/util/tokens.d.ts +31 -0
- package/dist/cjs/util/tokens.js +98 -0
- package/dist/cjs/vis/area/index.d.ts +2 -2
- package/dist/cjs/vis/area/index.js +76 -31
- package/dist/cjs/vis/bar/index.d.ts +2 -2
- package/dist/cjs/vis/bar/index.js +22 -19
- package/dist/cjs/vis/boxplot/index.js +1 -4
- package/dist/cjs/vis/column/index.d.ts +2 -2
- package/dist/cjs/vis/column/index.js +28 -18
- package/dist/cjs/vis/dual-axes/index.d.ts +2 -2
- package/dist/cjs/vis/dual-axes/index.js +107 -34
- package/dist/cjs/vis/funnel/index.d.ts +3 -2
- package/dist/cjs/vis/funnel/index.js +171 -94
- package/dist/cjs/vis/histogram/index.js +1 -4
- package/dist/cjs/vis/line/index.d.ts +2 -2
- package/dist/cjs/vis/line/index.js +71 -31
- package/dist/cjs/vis/liquid/index.d.ts +2 -2
- package/dist/cjs/vis/liquid/index.js +41 -16
- package/dist/cjs/vis/pie/index.d.ts +2 -2
- package/dist/cjs/vis/pie/index.js +26 -16
- package/dist/cjs/vis/radar/index.d.ts +2 -2
- package/dist/cjs/vis/radar/index.js +21 -29
- package/dist/cjs/vis/sankey/index.js +1 -4
- package/dist/cjs/vis/scatter/index.d.ts +2 -2
- package/dist/cjs/vis/scatter/index.js +40 -17
- package/dist/cjs/vis/table/index.js +13 -5
- package/dist/cjs/vis/treemap/index.js +1 -4
- package/dist/cjs/vis/venn/index.js +1 -4
- package/dist/cjs/vis/violin/index.js +1 -1
- package/dist/cjs/vis/waterfall/index.js +1 -1
- package/dist/cjs/vis/word-cloud/index.d.ts +3 -2
- package/dist/cjs/vis/word-cloud/index.js +125 -10
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/util/animation.d.ts +2 -0
- package/dist/esm/util/animation.js +17 -0
- package/dist/esm/util/components.d.ts +15 -0
- package/dist/esm/util/components.js +67 -0
- package/dist/esm/util/crosshair-axis-labels.d.ts +15 -0
- package/dist/esm/util/crosshair-axis-labels.js +431 -0
- package/dist/esm/util/html.d.ts +1 -0
- package/dist/esm/util/html.js +3 -0
- package/dist/esm/util/index.d.ts +6 -0
- package/dist/esm/util/index.js +6 -0
- package/dist/esm/util/interaction.d.ts +14 -0
- package/dist/esm/util/interaction.js +73 -0
- package/dist/esm/util/theme.d.ts +18 -24
- package/dist/esm/util/theme.js +302 -126
- package/dist/esm/util/tokens.d.ts +31 -0
- package/dist/esm/util/tokens.js +64 -0
- package/dist/esm/vis/area/index.d.ts +2 -2
- package/dist/esm/vis/area/index.js +91 -41
- package/dist/esm/vis/bar/index.d.ts +2 -2
- package/dist/esm/vis/bar/index.js +28 -29
- package/dist/esm/vis/boxplot/index.js +4 -5
- package/dist/esm/vis/column/index.d.ts +2 -2
- package/dist/esm/vis/column/index.js +36 -29
- package/dist/esm/vis/dual-axes/index.d.ts +2 -2
- package/dist/esm/vis/dual-axes/index.js +145 -42
- package/dist/esm/vis/funnel/index.d.ts +3 -2
- package/dist/esm/vis/funnel/index.js +159 -85
- package/dist/esm/vis/histogram/index.js +4 -5
- package/dist/esm/vis/line/index.d.ts +2 -2
- package/dist/esm/vis/line/index.js +80 -37
- package/dist/esm/vis/liquid/index.d.ts +2 -2
- package/dist/esm/vis/liquid/index.js +41 -14
- package/dist/esm/vis/pie/index.d.ts +2 -2
- package/dist/esm/vis/pie/index.js +36 -16
- package/dist/esm/vis/radar/index.d.ts +2 -2
- package/dist/esm/vis/radar/index.js +21 -34
- package/dist/esm/vis/sankey/index.js +4 -5
- package/dist/esm/vis/scatter/index.d.ts +2 -2
- package/dist/esm/vis/scatter/index.js +41 -25
- package/dist/esm/vis/table/index.js +9 -9
- package/dist/esm/vis/treemap/index.js +4 -5
- package/dist/esm/vis/venn/index.js +4 -5
- package/dist/esm/vis/violin/index.js +5 -13
- package/dist/esm/vis/waterfall/index.js +5 -7
- package/dist/esm/vis/word-cloud/index.d.ts +3 -2
- package/dist/esm/vis/word-cloud/index.js +158 -10
- package/dist/umd/index.min.js +1 -1
- package/package.json +18 -15
|
@@ -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
|
|
27
|
-
var getLinearGradientColor = (color) => `linear-gradient(-90deg,
|
|
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 =
|
|
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,
|
|
49
|
-
const backgroundColor = style.backgroundColor || (0,
|
|
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:
|
|
88
|
+
style: { fillOpacity: areaOpacity }
|
|
69
89
|
},
|
|
70
90
|
{
|
|
71
91
|
type: "line",
|
|
72
|
-
style: { lineWidth, strokeOpacity:
|
|
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:
|
|
101
|
+
style: { fillOpacity: areaOpacity }
|
|
82
102
|
},
|
|
83
103
|
{
|
|
84
104
|
type: "line",
|
|
85
|
-
style: { lineWidth, strokeOpacity:
|
|
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:
|
|
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:
|
|
103
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
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?:
|
|
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
|
|
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,
|
|
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 = {
|
|
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"
|
|
69
|
+
encode = { x: "category", y: "value" };
|
|
70
70
|
}
|
|
71
71
|
const scaleConfig = {
|
|
72
72
|
y: { nice: true },
|
|
73
|
-
...
|
|
73
|
+
...hasGroupField ? { color: { range: colors } } : {}
|
|
74
74
|
};
|
|
75
75
|
const chartOptions = {
|
|
76
|
-
animate:
|
|
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
|
-
|
|
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:
|
|
100
|
-
|
|
101
|
-
viewStyle: {
|
|
102
|
-
viewFill: backgroundColor
|
|
101
|
+
columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
|
|
102
|
+
...!hasGroupField ? { fill: colors[0] } : {}
|
|
103
103
|
},
|
|
104
|
-
|
|
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?:
|
|
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
|
|
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,
|
|
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"
|
|
69
|
+
encode = { x: "category", y: "value" };
|
|
70
70
|
}
|
|
71
71
|
const scaleConfig = {
|
|
72
72
|
y: { nice: true },
|
|
73
|
-
...
|
|
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:
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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:
|
|
99
|
-
|
|
100
|
-
viewStyle: {
|
|
101
|
-
viewFill: backgroundColor
|
|
107
|
+
columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
|
|
108
|
+
...!hasGroupField ? { fill: colors[0] } : {}
|
|
102
109
|
},
|
|
103
|
-
|
|
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?:
|
|
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
|
|
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((
|
|
31
|
-
|
|
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,22 @@ 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;
|
|
41
|
+
let cleanupCrosshairAxisLabels = null;
|
|
40
42
|
const render = (config) => {
|
|
41
43
|
const { categories, series, theme = chartTheme, title, axisXTitle, style = {} } = config;
|
|
42
44
|
if (chart) {
|
|
45
|
+
cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
|
|
46
|
+
cleanupCrosshairAxisLabels = null;
|
|
43
47
|
chart.destroy();
|
|
44
48
|
}
|
|
45
49
|
const { startAtZero = false } = style;
|
|
46
|
-
const
|
|
47
|
-
const
|
|
50
|
+
const requestedColors = style.palette ? (0, import_util.normalizePalette)(style.palette, theme) : [];
|
|
51
|
+
const defaultColors = (0, import_util.normalizePalette)(void 0, theme);
|
|
52
|
+
const colors = [
|
|
53
|
+
...requestedColors,
|
|
54
|
+
...defaultColors.filter((color) => !requestedColors.includes(color))
|
|
55
|
+
];
|
|
48
56
|
const data = transformData(series, categories);
|
|
49
57
|
chart = new import_g2.Chart({
|
|
50
58
|
container,
|
|
@@ -52,13 +60,34 @@ var DualAxes = (options) => {
|
|
|
52
60
|
height,
|
|
53
61
|
autoFit: true
|
|
54
62
|
});
|
|
55
|
-
const sortedSeries =
|
|
63
|
+
const sortedSeries = series.map((item, originalIndex) => ({ item, originalIndex })).sort((a, b) => {
|
|
56
64
|
const order = ["column", "line"];
|
|
57
|
-
return order.indexOf(a.type) - order.indexOf(b.type);
|
|
65
|
+
return order.indexOf(a.item.type) - order.indexOf(b.item.type);
|
|
58
66
|
});
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
const seriesMeta = sortedSeries.map(({ item, originalIndex }, index) => ({
|
|
68
|
+
item,
|
|
69
|
+
yField: getSeriesField(originalIndex),
|
|
70
|
+
displayName: item.axisYTitle || getSeriesField(originalIndex),
|
|
71
|
+
color: colors[index % colors.length]
|
|
72
|
+
}));
|
|
73
|
+
const seriesByField = new Map(
|
|
74
|
+
seriesMeta.map(({ item, yField, displayName }) => [yField, { type: item.type, displayName }])
|
|
75
|
+
);
|
|
76
|
+
const cartesianAxisOptions = {
|
|
77
|
+
axisXTitle,
|
|
78
|
+
xLabels: categories,
|
|
79
|
+
chartWidth: width
|
|
80
|
+
};
|
|
81
|
+
const cartesianAxis = (0, import_util.getCartesianAxis)(cartesianAxisOptions);
|
|
82
|
+
const children = seriesMeta.map(({ item, yField, displayName, color }) => {
|
|
83
|
+
const tooltip = {
|
|
84
|
+
items: [
|
|
85
|
+
(datum) => ({
|
|
86
|
+
name: displayName,
|
|
87
|
+
value: datum[yField]
|
|
88
|
+
})
|
|
89
|
+
]
|
|
90
|
+
};
|
|
62
91
|
if (item.type === "column") {
|
|
63
92
|
return {
|
|
64
93
|
type: "interval",
|
|
@@ -68,16 +97,24 @@ var DualAxes = (options) => {
|
|
|
68
97
|
color: () => yField
|
|
69
98
|
},
|
|
70
99
|
scale: {
|
|
71
|
-
y: { nice: true, zero: startAtZero }
|
|
72
|
-
color: { range: [color] }
|
|
100
|
+
y: { nice: true, zero: startAtZero }
|
|
73
101
|
},
|
|
102
|
+
tooltip,
|
|
74
103
|
axis: {
|
|
75
|
-
y: {
|
|
104
|
+
y: {
|
|
105
|
+
...cartesianAxis.y,
|
|
106
|
+
title: item.axisYTitle || "",
|
|
107
|
+
titleFill: color,
|
|
108
|
+
titleFontWeight: 500
|
|
109
|
+
}
|
|
76
110
|
},
|
|
77
111
|
style: {
|
|
78
|
-
|
|
112
|
+
fill: color,
|
|
113
|
+
fillOpacity: 0.86,
|
|
114
|
+
columnWidthRatio: import_util.CHART_STYLE_DEFAULTS.intervalWidthRatio,
|
|
79
115
|
...theme !== "academy" ? { radiusTopLeft: 4, radiusTopRight: 4 } : {}
|
|
80
|
-
}
|
|
116
|
+
},
|
|
117
|
+
animate: (0, import_util.getChartAnimation)(hasRendered, "growInY")
|
|
81
118
|
};
|
|
82
119
|
} else {
|
|
83
120
|
return {
|
|
@@ -89,52 +126,88 @@ var DualAxes = (options) => {
|
|
|
89
126
|
color: () => yField
|
|
90
127
|
},
|
|
91
128
|
scale: {
|
|
92
|
-
y: { independent: true, zero: startAtZero }
|
|
93
|
-
color: { range: [color] }
|
|
129
|
+
y: { independent: true, zero: startAtZero }
|
|
94
130
|
},
|
|
131
|
+
tooltip,
|
|
95
132
|
axis: {
|
|
96
|
-
y: {
|
|
133
|
+
y: {
|
|
134
|
+
...cartesianAxis.y,
|
|
135
|
+
position: "right",
|
|
136
|
+
title: item.axisYTitle || "",
|
|
137
|
+
titleFill: color,
|
|
138
|
+
titleFontWeight: 500,
|
|
139
|
+
grid: false
|
|
140
|
+
}
|
|
97
141
|
},
|
|
98
142
|
style: {
|
|
99
|
-
|
|
100
|
-
|
|
143
|
+
stroke: color,
|
|
144
|
+
lineWidth: import_util.CHART_STYLE_DEFAULTS.lineWidth,
|
|
145
|
+
lineCap: "round",
|
|
146
|
+
lineJoin: "round"
|
|
147
|
+
},
|
|
148
|
+
state: (0, import_util.getLineHighlightState)(import_util.CHART_STYLE_DEFAULTS.lineWidth),
|
|
149
|
+
animate: (0, import_util.getChartAnimation)(hasRendered, "pathIn")
|
|
101
150
|
};
|
|
102
151
|
}
|
|
103
152
|
});
|
|
104
153
|
const chartOptions = {
|
|
105
|
-
animate: false,
|
|
106
154
|
type: "view",
|
|
107
155
|
data,
|
|
108
|
-
title: title
|
|
156
|
+
title: title || "",
|
|
109
157
|
children,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
},
|
|
158
|
+
...(0, import_util.getCartesianLayout)(cartesianAxisOptions),
|
|
159
|
+
axis: { x: cartesianAxis.x },
|
|
113
160
|
scale: {
|
|
114
|
-
y: { nice: true }
|
|
161
|
+
y: { nice: true },
|
|
162
|
+
color: {
|
|
163
|
+
domain: seriesMeta.map(({ yField }) => yField),
|
|
164
|
+
range: seriesMeta.map(({ color }) => color)
|
|
165
|
+
}
|
|
115
166
|
},
|
|
116
167
|
legend: {
|
|
117
168
|
color: {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
169
|
+
labelFormatter: (value) => {
|
|
170
|
+
var _a;
|
|
171
|
+
return ((_a = seriesByField.get(value)) == null ? void 0 : _a.displayName) || value;
|
|
172
|
+
},
|
|
173
|
+
itemMarker: (value) => {
|
|
174
|
+
var _a;
|
|
175
|
+
return ((_a = seriesByField.get(value)) == null ? void 0 : _a.type) === "line" ? "smooth" : "rect";
|
|
122
176
|
}
|
|
123
177
|
}
|
|
124
178
|
},
|
|
125
|
-
|
|
126
|
-
|
|
179
|
+
interaction: {
|
|
180
|
+
tooltip: (0, import_util.getSharedTooltipInteraction)({ crosshairs: true }),
|
|
181
|
+
...(0, import_util.getSeriesHighlightByColorInteraction)()
|
|
127
182
|
},
|
|
128
|
-
|
|
183
|
+
viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
|
|
184
|
+
theme: (0, import_util.getThemeObject)(theme)
|
|
129
185
|
};
|
|
130
186
|
chart.options(chartOptions);
|
|
187
|
+
const lineYFields = seriesMeta.filter(({ item }) => item.type === "line").map(({ yField }) => yField);
|
|
188
|
+
if (lineYFields.length) {
|
|
189
|
+
const currentChart = chart;
|
|
190
|
+
const cleanups = lineYFields.map(
|
|
191
|
+
(yField, index) => (0, import_util.bindCrosshairAxisLabels)(currentChart, theme, {
|
|
192
|
+
showXLabel: index === 0,
|
|
193
|
+
useStandaloneYLabel: true,
|
|
194
|
+
yAxisPosition: "right",
|
|
195
|
+
yField
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
cleanupCrosshairAxisLabels = () => cleanups.forEach((cleanup) => cleanup());
|
|
199
|
+
}
|
|
131
200
|
chart.render();
|
|
201
|
+
hasRendered = true;
|
|
132
202
|
};
|
|
133
203
|
const destroy = () => {
|
|
134
204
|
if (chart) {
|
|
205
|
+
cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
|
|
206
|
+
cleanupCrosshairAxisLabels = null;
|
|
135
207
|
chart.destroy();
|
|
136
208
|
chart = null;
|
|
137
209
|
}
|
|
210
|
+
hasRendered = false;
|
|
138
211
|
};
|
|
139
212
|
return {
|
|
140
213
|
render,
|