@antv/gpt-vis 1.0.0 → 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.
- package/README.md +66 -1
- package/README.zh-CN.md +66 -1
- 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 +9 -0
- package/dist/cjs/util/crosshair-axis-labels.js +304 -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 +89 -34
- package/dist/cjs/vis/funnel/index.d.ts +4 -2
- package/dist/cjs/vis/funnel/index.js +171 -92
- 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/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 +9 -0
- package/dist/esm/util/crosshair-axis-labels.js +328 -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 +115 -42
- package/dist/esm/vis/funnel/index.d.ts +4 -2
- package/dist/esm/vis/funnel/index.js +156 -83
- 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/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,20 +23,40 @@ __export(line_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(line_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
|
-
var
|
|
26
|
+
var import_util = require("../../util");
|
|
27
27
|
var Line = (options) => {
|
|
28
28
|
const { container, width, height, theme: chartTheme = "default" } = options;
|
|
29
29
|
let chart = null;
|
|
30
|
+
let hasRendered = false;
|
|
31
|
+
let cleanupCrosshairAxisLabels = null;
|
|
30
32
|
const render = (config) => {
|
|
31
33
|
var _a;
|
|
32
34
|
const { data = [], theme = chartTheme, title, axisXTitle, axisYTitle, style = {} } = config;
|
|
33
35
|
if (chart) {
|
|
36
|
+
cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
|
|
37
|
+
cleanupCrosshairAxisLabels = null;
|
|
34
38
|
chart.destroy();
|
|
35
39
|
}
|
|
36
|
-
const { lineWidth =
|
|
40
|
+
const { lineWidth = import_util.CHART_STYLE_DEFAULTS.lineWidth } = style;
|
|
37
41
|
const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
|
|
38
|
-
const colors = (0,
|
|
39
|
-
const backgroundColor = style.backgroundColor || (0,
|
|
42
|
+
const colors = (0, import_util.normalizePalette)(style.palette, theme);
|
|
43
|
+
const backgroundColor = style.backgroundColor || (0, import_util.getBackgroundColor)(theme);
|
|
44
|
+
const tooltip = {
|
|
45
|
+
items: [
|
|
46
|
+
(d) => ({
|
|
47
|
+
name: hasGroupField ? d.group : axisYTitle || d.time,
|
|
48
|
+
value: d.value
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
const lineAnimation = (0, import_util.getChartAnimation)(hasRendered, "pathIn");
|
|
53
|
+
const pointAnimation = (0, import_util.getChartAnimation)(hasRendered, "fadeIn");
|
|
54
|
+
const cartesianAxisOptions = {
|
|
55
|
+
axisXTitle,
|
|
56
|
+
axisYTitle,
|
|
57
|
+
xLabels: data.map(({ time }) => time),
|
|
58
|
+
chartWidth: width
|
|
59
|
+
};
|
|
40
60
|
chart = new import_g2.Chart({
|
|
41
61
|
container,
|
|
42
62
|
width,
|
|
@@ -51,48 +71,68 @@ var Line = (options) => {
|
|
|
51
71
|
} else {
|
|
52
72
|
encode = { x: "time", y: "value" };
|
|
53
73
|
}
|
|
74
|
+
const children = [
|
|
75
|
+
{
|
|
76
|
+
type: "line",
|
|
77
|
+
tooltip,
|
|
78
|
+
style: {
|
|
79
|
+
lineWidth,
|
|
80
|
+
lineCap: "round",
|
|
81
|
+
lineJoin: "round",
|
|
82
|
+
...!hasGroupField ? { stroke: colors[0] } : {}
|
|
83
|
+
},
|
|
84
|
+
animate: lineAnimation
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
const showPoints = data.length <= (hasGroupField ? 36 : 24);
|
|
88
|
+
if (showPoints) {
|
|
89
|
+
children.push({
|
|
90
|
+
type: "point",
|
|
91
|
+
encode: {
|
|
92
|
+
x: "time",
|
|
93
|
+
y: "value",
|
|
94
|
+
shape: "point",
|
|
95
|
+
size: import_util.CHART_STYLE_DEFAULTS.pointSize,
|
|
96
|
+
...hasGroupField ? { color: "group" } : {}
|
|
97
|
+
},
|
|
98
|
+
animate: pointAnimation,
|
|
99
|
+
tooltip: false,
|
|
100
|
+
style: {
|
|
101
|
+
lineWidth: import_util.CHART_STYLE_DEFAULTS.pointLineWidth,
|
|
102
|
+
stroke: backgroundColor,
|
|
103
|
+
...!hasGroupField ? { fill: colors[0] } : {}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
54
107
|
const chartOptions = {
|
|
55
|
-
animate: false,
|
|
56
108
|
type: "view",
|
|
57
109
|
data,
|
|
58
|
-
title: title
|
|
110
|
+
title: title || "",
|
|
59
111
|
encode,
|
|
60
|
-
children
|
|
61
|
-
{
|
|
62
|
-
type: "line",
|
|
63
|
-
style: {
|
|
64
|
-
lineWidth,
|
|
65
|
-
...!hasGroupField && style.palette ? { stroke: colors[0] } : {}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
],
|
|
112
|
+
children,
|
|
69
113
|
scale: scaleConfig,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
tooltip: {
|
|
76
|
-
items: [
|
|
77
|
-
(d) => ({
|
|
78
|
-
name: axisYTitle || d.time,
|
|
79
|
-
value: d.value
|
|
80
|
-
})
|
|
81
|
-
]
|
|
82
|
-
},
|
|
83
|
-
viewStyle: {
|
|
84
|
-
viewFill: backgroundColor
|
|
114
|
+
...(0, import_util.getCartesianLayout)(cartesianAxisOptions),
|
|
115
|
+
axis: (0, import_util.getCartesianAxis)(cartesianAxisOptions),
|
|
116
|
+
legend: (0, import_util.getColorLegend)(hasGroupField),
|
|
117
|
+
interaction: {
|
|
118
|
+
tooltip: (0, import_util.getSharedTooltipInteraction)({ crosshairs: true })
|
|
85
119
|
},
|
|
86
|
-
|
|
120
|
+
viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
|
|
121
|
+
theme: (0, import_util.getThemeObject)(theme)
|
|
87
122
|
};
|
|
88
123
|
chart.options(chartOptions);
|
|
124
|
+
cleanupCrosshairAxisLabels = (0, import_util.bindCrosshairAxisLabels)(chart, theme);
|
|
89
125
|
chart.render();
|
|
126
|
+
hasRendered = true;
|
|
90
127
|
};
|
|
91
128
|
const destroy = () => {
|
|
92
129
|
if (chart) {
|
|
130
|
+
cleanupCrosshairAxisLabels == null ? void 0 : cleanupCrosshairAxisLabels();
|
|
131
|
+
cleanupCrosshairAxisLabels = null;
|
|
93
132
|
chart.destroy();
|
|
94
133
|
chart = null;
|
|
95
134
|
}
|
|
135
|
+
hasRendered = false;
|
|
96
136
|
};
|
|
97
137
|
return {
|
|
98
138
|
render,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VisualizationOptions } from '../../types';
|
|
1
|
+
import type { VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* LiquidConfig defines the configuration for rendering the liquid chart.
|
|
4
4
|
*/
|
|
@@ -6,7 +6,7 @@ export interface LiquidConfig {
|
|
|
6
6
|
type?: 'liquid';
|
|
7
7
|
percent: number;
|
|
8
8
|
shape?: 'rect' | 'circle' | 'pin' | 'triangle';
|
|
9
|
-
theme?:
|
|
9
|
+
theme?: VisualizationTheme;
|
|
10
10
|
title?: string;
|
|
11
11
|
style?: {
|
|
12
12
|
backgroundColor?: string;
|
|
@@ -23,7 +23,7 @@ __export(liquid_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(liquid_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
|
-
var
|
|
26
|
+
var import_util = require("../../util");
|
|
27
27
|
var DEFAULT_WIDTH = 640;
|
|
28
28
|
var DEFAULT_HEIGHT = 480;
|
|
29
29
|
var Liquid = (options) => {
|
|
@@ -34,10 +34,18 @@ var Liquid = (options) => {
|
|
|
34
34
|
if (chart) {
|
|
35
35
|
chart.destroy();
|
|
36
36
|
}
|
|
37
|
-
const colors = (0,
|
|
38
|
-
const backgroundColor = style.backgroundColor || (0,
|
|
37
|
+
const colors = (0, import_util.normalizePalette)(style.palette, theme);
|
|
38
|
+
const backgroundColor = style.backgroundColor || (0, import_util.getBackgroundColor)(theme);
|
|
39
|
+
const tokens = (0, import_util.getChartVisualTokens)(theme);
|
|
40
|
+
const normalizedPercent = Number.isFinite(percent) ? Math.max(0, Math.min(1, percent)) : 0;
|
|
39
41
|
const inferFontSize = Math.min(width ?? DEFAULT_WIDTH, height ?? DEFAULT_HEIGHT) / 10;
|
|
40
42
|
const fontSize = Math.min(Math.max(inferFontSize, 24), 64);
|
|
43
|
+
const chartSize = Math.min(width ?? DEFAULT_WIDTH, height ?? DEFAULT_HEIGHT);
|
|
44
|
+
const waveLength = Math.min(Math.max(chartSize * 0.4, 96), 192);
|
|
45
|
+
const formattedPercent = `${Number((normalizedPercent * 100).toFixed(1))}%`;
|
|
46
|
+
const liquidColor = colors[0];
|
|
47
|
+
const isAcademy = theme === "academy";
|
|
48
|
+
const outlineShadowColor = theme === "dark" ? "rgba(0, 0, 0, 0.32)" : "rgba(15, 23, 42, 0.10)";
|
|
41
49
|
chart = new import_g2.Chart({
|
|
42
50
|
container,
|
|
43
51
|
width,
|
|
@@ -47,25 +55,42 @@ var Liquid = (options) => {
|
|
|
47
55
|
const chartOptions = {
|
|
48
56
|
animate: false,
|
|
49
57
|
type: "liquid",
|
|
50
|
-
data:
|
|
51
|
-
title: title
|
|
58
|
+
data: normalizedPercent,
|
|
59
|
+
title: title || "",
|
|
60
|
+
inset: 20,
|
|
52
61
|
style: {
|
|
53
62
|
shape,
|
|
63
|
+
contentText: formattedPercent,
|
|
54
64
|
contentFontSize: fontSize,
|
|
55
|
-
contentFill:
|
|
56
|
-
contentStroke:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
contentFill: tokens.textPrimary,
|
|
66
|
+
contentStroke: backgroundColor,
|
|
67
|
+
contentStrokeOpacity: 0.92,
|
|
68
|
+
contentLineWidth: theme === "dark" ? 3 : 2.5,
|
|
69
|
+
contentFontFamily: import_util.CHART_FONT_FAMILY,
|
|
70
|
+
contentFontWeight: 600,
|
|
71
|
+
contentLetterSpacing: -0.8,
|
|
72
|
+
contentFontVariantNumeric: "tabular-nums",
|
|
73
|
+
contentPaintOrder: "stroke",
|
|
74
|
+
backgroundFill: liquidColor,
|
|
75
|
+
backgroundFillOpacity: theme === "dark" ? 0.14 : isAcademy ? 0.06 : 0.08,
|
|
76
|
+
backgroundStroke: liquidColor,
|
|
77
|
+
backgroundStrokeOpacity: theme === "dark" ? 0.3 : 0.22,
|
|
78
|
+
backgroundLineWidth: 1,
|
|
79
|
+
outlineBorder: isAcademy ? 1.5 : 2,
|
|
80
|
+
outlineDistance: 0,
|
|
81
|
+
outlineStrokeOpacity: isAcademy ? 0.9 : 0.72,
|
|
82
|
+
outlineShadowColor: isAcademy ? "transparent" : outlineShadowColor,
|
|
83
|
+
outlineShadowBlur: isAcademy ? 0 : 6,
|
|
84
|
+
outlineShadowOffsetY: isAcademy ? 0 : 2,
|
|
85
|
+
waveLength,
|
|
86
|
+
waveCount: 2,
|
|
87
|
+
fillOpacity: isAcademy ? 0.9 : 0.88,
|
|
61
88
|
contentPointerEvents: "none",
|
|
62
89
|
// Use palette color if provided
|
|
63
|
-
...
|
|
90
|
+
...liquidColor ? { fill: liquidColor, outlineStroke: liquidColor } : {}
|
|
64
91
|
},
|
|
65
|
-
viewStyle: {
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
theme: (0, import_theme.getThemeObject)(theme),
|
|
92
|
+
viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
|
|
93
|
+
theme: (0, import_util.getThemeObject)(theme),
|
|
69
94
|
tooltip: false
|
|
70
95
|
};
|
|
71
96
|
chart.options(chartOptions);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VisualizationOptions } from '../../types';
|
|
1
|
+
import type { VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* PieDataItem is the type for each data item in the pie chart.
|
|
4
4
|
*/
|
|
@@ -13,7 +13,7 @@ export interface PieConfig {
|
|
|
13
13
|
type?: 'pie';
|
|
14
14
|
data: PieDataItem[];
|
|
15
15
|
innerRadius?: number;
|
|
16
|
-
theme?:
|
|
16
|
+
theme?: VisualizationTheme;
|
|
17
17
|
title?: string;
|
|
18
18
|
style?: {
|
|
19
19
|
backgroundColor?: string;
|
|
@@ -23,18 +23,19 @@ __export(pie_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(pie_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
|
-
var
|
|
26
|
+
var import_util = require("../../util");
|
|
27
27
|
var Pie = (options) => {
|
|
28
28
|
const { container, width, height, theme: chartTheme = "default" } = options;
|
|
29
29
|
let chart = null;
|
|
30
|
+
let hasRendered = false;
|
|
30
31
|
const PERCENTAGE_PRECISION_MULTIPLIER = 1e4;
|
|
31
32
|
const render = (config) => {
|
|
32
33
|
const { data = [], innerRadius = 0, theme = chartTheme, title, style = {} } = config;
|
|
33
34
|
if (chart) {
|
|
34
35
|
chart.destroy();
|
|
35
36
|
}
|
|
36
|
-
const colors = (0,
|
|
37
|
-
const
|
|
37
|
+
const colors = (0, import_util.normalizePalette)(style.palette, theme);
|
|
38
|
+
const tokens = (0, import_util.getChartVisualTokens)(theme);
|
|
38
39
|
const sumValue = data.reduce((sum, item) => sum + item.value, 0);
|
|
39
40
|
chart = new import_g2.Chart({
|
|
40
41
|
container,
|
|
@@ -43,10 +44,10 @@ var Pie = (options) => {
|
|
|
43
44
|
autoFit: true
|
|
44
45
|
});
|
|
45
46
|
const chartOptions = {
|
|
46
|
-
animate:
|
|
47
|
+
animate: (0, import_util.getChartAnimation)(hasRendered, "waveIn"),
|
|
47
48
|
type: "interval",
|
|
48
49
|
data,
|
|
49
|
-
title: title
|
|
50
|
+
title: title || "",
|
|
50
51
|
encode: {
|
|
51
52
|
y: "value",
|
|
52
53
|
color: "category"
|
|
@@ -56,14 +57,13 @@ var Pie = (options) => {
|
|
|
56
57
|
scale: {
|
|
57
58
|
color: { range: colors }
|
|
58
59
|
},
|
|
59
|
-
legend:
|
|
60
|
-
|
|
61
|
-
},
|
|
62
|
-
labels: [
|
|
60
|
+
legend: (0, import_util.getColorLegend)(true),
|
|
61
|
+
labels: data.length > 8 ? [] : [
|
|
63
62
|
{
|
|
64
63
|
text: (d) => {
|
|
65
|
-
const percentage = Math.round(d.value / sumValue * 100 * PERCENTAGE_PRECISION_MULTIPLIER) / PERCENTAGE_PRECISION_MULTIPLIER;
|
|
66
|
-
|
|
64
|
+
const percentage = sumValue ? Math.round(d.value / sumValue * 100 * PERCENTAGE_PRECISION_MULTIPLIER) / PERCENTAGE_PRECISION_MULTIPLIER : 0;
|
|
65
|
+
const formattedPercentage = Number(percentage.toFixed(1)).toString();
|
|
66
|
+
return `${d.category}: ${formattedPercentage}%`;
|
|
67
67
|
},
|
|
68
68
|
position: "outside",
|
|
69
69
|
transform: [{ type: "overlapHide" }]
|
|
@@ -78,24 +78,34 @@ var Pie = (options) => {
|
|
|
78
78
|
]
|
|
79
79
|
},
|
|
80
80
|
interaction: {
|
|
81
|
+
tooltip: true,
|
|
82
|
+
elementHighlight: true,
|
|
83
|
+
elementHoverScale: { shadow: false },
|
|
81
84
|
elementSelect: { single: true }
|
|
82
85
|
},
|
|
83
|
-
|
|
84
|
-
fillOpacity:
|
|
86
|
+
state: {
|
|
87
|
+
active: { fillOpacity: 1, lineWidth: 3 },
|
|
88
|
+
inactive: { fillOpacity: 0.3 },
|
|
89
|
+
selected: { fillOpacity: 1, lineWidth: 3 }
|
|
85
90
|
},
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
style: {
|
|
92
|
+
fillOpacity: 1,
|
|
93
|
+
stroke: tokens.separator,
|
|
94
|
+
lineWidth: 2
|
|
88
95
|
},
|
|
89
|
-
|
|
96
|
+
viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
|
|
97
|
+
theme: (0, import_util.getThemeObject)(theme)
|
|
90
98
|
};
|
|
91
99
|
chart.options(chartOptions);
|
|
92
100
|
chart.render();
|
|
101
|
+
hasRendered = true;
|
|
93
102
|
};
|
|
94
103
|
const destroy = () => {
|
|
95
104
|
if (chart) {
|
|
96
105
|
chart.destroy();
|
|
97
106
|
chart = null;
|
|
98
107
|
}
|
|
108
|
+
hasRendered = false;
|
|
99
109
|
};
|
|
100
110
|
return {
|
|
101
111
|
render,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VisualizationOptions } from '../../types';
|
|
1
|
+
import type { VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* RadarDataItem is the type for each data item in the radar chart.
|
|
4
4
|
*/
|
|
@@ -15,7 +15,7 @@ export interface RadarConfig {
|
|
|
15
15
|
data: RadarDataItem[];
|
|
16
16
|
title?: string;
|
|
17
17
|
align?: boolean;
|
|
18
|
-
theme?:
|
|
18
|
+
theme?: VisualizationTheme;
|
|
19
19
|
style?: {
|
|
20
20
|
backgroundColor?: string;
|
|
21
21
|
palette?: string[];
|
|
@@ -23,7 +23,7 @@ __export(radar_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(radar_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
|
-
var
|
|
26
|
+
var import_util = require("../../util");
|
|
27
27
|
function transformRadarToParallel(data) {
|
|
28
28
|
if (!data || data.length === 0) {
|
|
29
29
|
return [];
|
|
@@ -55,11 +55,12 @@ var Radar = (options) => {
|
|
|
55
55
|
if (chart) {
|
|
56
56
|
chart.destroy();
|
|
57
57
|
}
|
|
58
|
-
const { lineWidth =
|
|
59
|
-
const colors = (0,
|
|
60
|
-
const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
|
|
58
|
+
const { lineWidth = import_util.CHART_STYLE_DEFAULTS.lineWidth } = style;
|
|
59
|
+
const colors = (0, import_util.normalizePalette)(style.palette, theme);
|
|
61
60
|
const parallelData = transformRadarToParallel(data);
|
|
62
61
|
const position = Object.keys(parallelData[0] || {}).filter((key) => key !== "group");
|
|
62
|
+
const hasMultipleSeries = parallelData.length > 1;
|
|
63
|
+
const legend = (0, import_util.getColorLegend)(hasMultipleSeries);
|
|
63
64
|
chart = new import_g2.Chart({
|
|
64
65
|
container,
|
|
65
66
|
width,
|
|
@@ -70,9 +71,9 @@ var Radar = (options) => {
|
|
|
70
71
|
animate: false,
|
|
71
72
|
type: "line",
|
|
72
73
|
data: parallelData,
|
|
73
|
-
title: title
|
|
74
|
+
title: title || "",
|
|
74
75
|
coordinate: { type: "radar" },
|
|
75
|
-
inset:
|
|
76
|
+
inset: 24,
|
|
76
77
|
encode: {
|
|
77
78
|
position,
|
|
78
79
|
color: "group"
|
|
@@ -96,42 +97,33 @@ var Radar = (options) => {
|
|
|
96
97
|
Array.from({ length: position.length }, (_, i) => [
|
|
97
98
|
`position${i === 0 ? "" : i}`,
|
|
98
99
|
{
|
|
99
|
-
|
|
100
|
-
titleFontSize: 10,
|
|
101
|
-
titleSpacing: 8,
|
|
102
|
-
label: true,
|
|
103
|
-
labelFill: theme === "dark" ? "#fff" : "#000",
|
|
104
|
-
labelOpacity: 0.45,
|
|
105
|
-
labelFontSize: 10,
|
|
106
|
-
line: true,
|
|
107
|
-
lineFill: "#000",
|
|
108
|
-
lineStrokeOpacity: 0.25,
|
|
100
|
+
label: align ? i === 0 : true,
|
|
109
101
|
tickFilter: (_2, idx) => {
|
|
110
102
|
return !(i !== 0 && idx === 0);
|
|
111
103
|
},
|
|
112
|
-
|
|
113
|
-
gridStrokeOpacity: 0.45,
|
|
114
|
-
gridStroke: theme === "dark" ? "#fff" : "#000",
|
|
115
|
-
gridLineWidth: 1,
|
|
116
|
-
gridLineDash: [4, 4]
|
|
104
|
+
grid: i === 0
|
|
117
105
|
}
|
|
118
106
|
])
|
|
119
107
|
),
|
|
120
108
|
style: {
|
|
121
109
|
lineWidth,
|
|
122
110
|
lineCap: "round",
|
|
123
|
-
lineJoin: "round"
|
|
111
|
+
lineJoin: "round",
|
|
112
|
+
strokeOpacity: import_util.CHART_STYLE_DEFAULTS.lineOpacity
|
|
124
113
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
114
|
+
state: hasMultipleSeries ? (0, import_util.getLineHighlightState)(lineWidth) : void 0,
|
|
115
|
+
legend: legend === false ? false : {
|
|
116
|
+
color: {
|
|
117
|
+
...legend.color,
|
|
118
|
+
itemMarker: "smooth"
|
|
129
119
|
}
|
|
130
120
|
},
|
|
131
|
-
|
|
132
|
-
|
|
121
|
+
interaction: {
|
|
122
|
+
tooltip: true,
|
|
123
|
+
...hasMultipleSeries ? (0, import_util.getSeriesHighlightByColorInteraction)() : {}
|
|
133
124
|
},
|
|
134
|
-
|
|
125
|
+
viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
|
|
126
|
+
theme: (0, import_util.getThemeObject)(theme)
|
|
135
127
|
};
|
|
136
128
|
chart.options(chartOptions);
|
|
137
129
|
chart.render();
|
|
@@ -33,7 +33,6 @@ var Sankey = (options) => {
|
|
|
33
33
|
chart.destroy();
|
|
34
34
|
}
|
|
35
35
|
const colors = (0, import_theme.normalizePalette)(style.palette, theme);
|
|
36
|
-
const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
|
|
37
36
|
chart = new import_g2.Chart({
|
|
38
37
|
container,
|
|
39
38
|
width,
|
|
@@ -67,9 +66,7 @@ var Sankey = (options) => {
|
|
|
67
66
|
nodeLineWidth: 1,
|
|
68
67
|
linkFillOpacity: 0.3
|
|
69
68
|
},
|
|
70
|
-
viewStyle: {
|
|
71
|
-
viewFill: backgroundColor
|
|
72
|
-
},
|
|
69
|
+
viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
|
|
73
70
|
theme: (0, import_theme.getThemeObject)(theme),
|
|
74
71
|
legend: false,
|
|
75
72
|
tooltip: false
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VisualizationOptions } from '../../types';
|
|
1
|
+
import type { VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* ScatterDataItem is the type for each data item in the scatter chart.
|
|
4
4
|
*/
|
|
@@ -16,7 +16,7 @@ export interface ScatterConfig {
|
|
|
16
16
|
title?: string;
|
|
17
17
|
axisXTitle?: string;
|
|
18
18
|
axisYTitle?: string;
|
|
19
|
-
theme?:
|
|
19
|
+
theme?: VisualizationTheme;
|
|
20
20
|
style?: {
|
|
21
21
|
backgroundColor?: string;
|
|
22
22
|
palette?: string[];
|
|
@@ -23,18 +23,19 @@ __export(scatter_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(scatter_exports);
|
|
25
25
|
var import_g2 = require("@antv/g2");
|
|
26
|
-
var
|
|
26
|
+
var import_util = require("../../util");
|
|
27
27
|
var Scatter = (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 { data = [], theme = chartTheme, title, axisXTitle, axisYTitle, style = {} } = config;
|
|
33
34
|
if (chart) {
|
|
34
35
|
chart.destroy();
|
|
35
36
|
}
|
|
36
|
-
const colors = (0,
|
|
37
|
-
const backgroundColor = style.backgroundColor || (0,
|
|
37
|
+
const colors = (0, import_util.normalizePalette)(style.palette, theme);
|
|
38
|
+
const backgroundColor = style.backgroundColor || (0, import_util.getBackgroundColor)(theme);
|
|
38
39
|
const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
|
|
39
40
|
chart = new import_g2.Chart({
|
|
40
41
|
container,
|
|
@@ -44,29 +45,47 @@ var Scatter = (options) => {
|
|
|
44
45
|
});
|
|
45
46
|
let encode = {};
|
|
46
47
|
const scaleConfig = {
|
|
47
|
-
y: { nice: true }
|
|
48
|
+
y: { nice: true },
|
|
49
|
+
x: { nice: true }
|
|
48
50
|
};
|
|
49
51
|
if (hasGroupField) {
|
|
50
|
-
encode = {
|
|
52
|
+
encode = {
|
|
53
|
+
x: "x",
|
|
54
|
+
y: "y",
|
|
55
|
+
color: "group",
|
|
56
|
+
shape: "point",
|
|
57
|
+
size: import_util.CHART_STYLE_DEFAULTS.scatterPointSize
|
|
58
|
+
};
|
|
51
59
|
scaleConfig.color = { range: colors };
|
|
52
60
|
} else {
|
|
53
|
-
encode = {
|
|
61
|
+
encode = {
|
|
62
|
+
x: "x",
|
|
63
|
+
y: "y",
|
|
64
|
+
shape: "point",
|
|
65
|
+
size: import_util.CHART_STYLE_DEFAULTS.scatterPointSize
|
|
66
|
+
};
|
|
54
67
|
}
|
|
55
68
|
const chartOptions = {
|
|
56
|
-
animate:
|
|
69
|
+
animate: (0, import_util.getChartAnimation)(hasRendered, "fadeIn"),
|
|
57
70
|
type: "point",
|
|
58
71
|
data,
|
|
59
|
-
title: title
|
|
72
|
+
title: title || "",
|
|
60
73
|
encode,
|
|
61
|
-
legend: hasGroupField
|
|
74
|
+
legend: (0, import_util.getColorLegend)(hasGroupField),
|
|
62
75
|
scale: scaleConfig,
|
|
63
|
-
axis: {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
76
|
+
axis: (0, import_util.getCartesianAxis)({
|
|
77
|
+
axisXTitle,
|
|
78
|
+
axisYTitle
|
|
79
|
+
}),
|
|
67
80
|
style: {
|
|
68
|
-
lineWidth:
|
|
81
|
+
lineWidth: import_util.CHART_STYLE_DEFAULTS.pointLineWidth,
|
|
82
|
+
fillOpacity: 0.88,
|
|
83
|
+
stroke: backgroundColor,
|
|
84
|
+
...!hasGroupField ? { fill: colors[0] } : {}
|
|
69
85
|
},
|
|
86
|
+
// A same-color stroke enlarges the rendered path without changing its transform or
|
|
87
|
+
// hit area, so repeated pointer events cannot accumulate scale.
|
|
88
|
+
state: (0, import_util.getPointHighlightState)(),
|
|
70
89
|
tooltip: {
|
|
71
90
|
title: (d) => (d == null ? void 0 : d.group) ? d.group : false,
|
|
72
91
|
items: [
|
|
@@ -74,19 +93,23 @@ var Scatter = (options) => {
|
|
|
74
93
|
{ channel: "y", name: axisYTitle ?? "y" }
|
|
75
94
|
]
|
|
76
95
|
},
|
|
77
|
-
|
|
78
|
-
|
|
96
|
+
interaction: {
|
|
97
|
+
tooltip: true,
|
|
98
|
+
elementHighlight: true
|
|
79
99
|
},
|
|
80
|
-
|
|
100
|
+
viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
|
|
101
|
+
theme: (0, import_util.getThemeObject)(theme)
|
|
81
102
|
};
|
|
82
103
|
chart.options(chartOptions);
|
|
83
104
|
chart.render();
|
|
105
|
+
hasRendered = true;
|
|
84
106
|
};
|
|
85
107
|
const destroy = () => {
|
|
86
108
|
if (chart) {
|
|
87
109
|
chart.destroy();
|
|
88
110
|
chart = null;
|
|
89
111
|
}
|
|
112
|
+
hasRendered = false;
|
|
90
113
|
};
|
|
91
114
|
return {
|
|
92
115
|
render,
|
|
@@ -33,7 +33,6 @@ var Treemap = (options) => {
|
|
|
33
33
|
chart.destroy();
|
|
34
34
|
}
|
|
35
35
|
const colors = (0, import_theme.normalizePalette)(style.palette, theme);
|
|
36
|
-
const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
|
|
37
36
|
chart = new import_g2.Chart({
|
|
38
37
|
container,
|
|
39
38
|
width,
|
|
@@ -74,9 +73,7 @@ var Treemap = (options) => {
|
|
|
74
73
|
}
|
|
75
74
|
]
|
|
76
75
|
},
|
|
77
|
-
viewStyle: {
|
|
78
|
-
viewFill: backgroundColor
|
|
79
|
-
},
|
|
76
|
+
viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
|
|
80
77
|
theme: (0, import_theme.getThemeObject)(theme),
|
|
81
78
|
scale: {
|
|
82
79
|
...colors.length > 0 ? {
|
|
@@ -43,7 +43,6 @@ var Venn = (options) => {
|
|
|
43
43
|
chart.destroy();
|
|
44
44
|
}
|
|
45
45
|
const colors = (0, import_theme.normalizePalette)(style.palette, theme);
|
|
46
|
-
const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
|
|
47
46
|
const normalizedData = data.map((d) => ({
|
|
48
47
|
...d,
|
|
49
48
|
sets: normalizeVennSets(d.sets)
|
|
@@ -87,9 +86,7 @@ var Venn = (options) => {
|
|
|
87
86
|
fontSize: 10
|
|
88
87
|
}
|
|
89
88
|
],
|
|
90
|
-
viewStyle: {
|
|
91
|
-
viewFill: backgroundColor
|
|
92
|
-
},
|
|
89
|
+
viewStyle: style.backgroundColor ? { viewFill: style.backgroundColor } : void 0,
|
|
93
90
|
theme: (0, import_theme.getThemeObject)(theme),
|
|
94
91
|
legend: false,
|
|
95
92
|
axis: false,
|
|
@@ -133,7 +133,7 @@ var Violin = (options) => {
|
|
|
133
133
|
legend: {
|
|
134
134
|
color: hasGroupField ? { position: "top" } : false
|
|
135
135
|
},
|
|
136
|
-
|
|
136
|
+
viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
|
|
137
137
|
theme: (0, import_theme.getThemeObject)(theme)
|
|
138
138
|
};
|
|
139
139
|
chart.options(chartOptions);
|
|
@@ -172,7 +172,7 @@ var Waterfall = (options) => {
|
|
|
172
172
|
}
|
|
173
173
|
],
|
|
174
174
|
legend: false,
|
|
175
|
-
|
|
175
|
+
viewStyle: style.backgroundColor ? { viewFill: backgroundColor } : void 0,
|
|
176
176
|
theme: (0, import_theme.getThemeObject)(theme)
|
|
177
177
|
};
|
|
178
178
|
chart.options(chartOptions);
|