@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
|
@@ -5,7 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import { Chart } from '@antv/g2';
|
|
8
|
-
import { getBackgroundColor, getThemeObject, normalizePalette } from "../../util
|
|
8
|
+
import { CHART_STYLE_DEFAULTS, bindCrosshairAxisLabels, getBackgroundColor, getCartesianAxis, getCartesianLayout, getChartAnimation, getColorLegend, getSharedTooltipInteraction, getThemeObject, normalizePalette } from "../../util";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* LineDataItem is the type for each data item in the line chart.
|
|
@@ -52,6 +52,8 @@ export var Line = function Line(options) {
|
|
|
52
52
|
_options$theme = options.theme,
|
|
53
53
|
chartTheme = _options$theme === void 0 ? 'default' : _options$theme;
|
|
54
54
|
var chart = null;
|
|
55
|
+
var hasRendered = false;
|
|
56
|
+
var cleanupCrosshairAxisLabels = null;
|
|
55
57
|
|
|
56
58
|
/**
|
|
57
59
|
* Render the line chart with the given configuration.
|
|
@@ -70,13 +72,35 @@ export var Line = function Line(options) {
|
|
|
70
72
|
|
|
71
73
|
// Clean up previous chart if exists
|
|
72
74
|
if (chart) {
|
|
75
|
+
var _cleanupCrosshairAxis;
|
|
76
|
+
(_cleanupCrosshairAxis = cleanupCrosshairAxisLabels) === null || _cleanupCrosshairAxis === void 0 || _cleanupCrosshairAxis();
|
|
77
|
+
cleanupCrosshairAxisLabels = null;
|
|
73
78
|
chart.destroy();
|
|
74
79
|
}
|
|
75
80
|
var _style$lineWidth = style.lineWidth,
|
|
76
|
-
lineWidth = _style$lineWidth === void 0 ?
|
|
81
|
+
lineWidth = _style$lineWidth === void 0 ? CHART_STYLE_DEFAULTS.lineWidth : _style$lineWidth;
|
|
77
82
|
var hasGroupField = data.length > 0 && ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.group) !== undefined;
|
|
78
83
|
var colors = normalizePalette(style.palette, theme);
|
|
79
84
|
var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
85
|
+
var tooltip = {
|
|
86
|
+
items: [function (d) {
|
|
87
|
+
return {
|
|
88
|
+
name: hasGroupField ? d.group : axisYTitle || d.time,
|
|
89
|
+
value: d.value
|
|
90
|
+
};
|
|
91
|
+
}]
|
|
92
|
+
};
|
|
93
|
+
var lineAnimation = getChartAnimation(hasRendered, 'pathIn');
|
|
94
|
+
var pointAnimation = getChartAnimation(hasRendered, 'fadeIn');
|
|
95
|
+
var cartesianAxisOptions = {
|
|
96
|
+
axisXTitle: axisXTitle,
|
|
97
|
+
axisYTitle: axisYTitle,
|
|
98
|
+
xLabels: data.map(function (_ref) {
|
|
99
|
+
var time = _ref.time;
|
|
100
|
+
return time;
|
|
101
|
+
}),
|
|
102
|
+
chartWidth: width
|
|
103
|
+
};
|
|
80
104
|
|
|
81
105
|
// Create chart
|
|
82
106
|
chart = new Chart({
|
|
@@ -108,53 +132,68 @@ export var Line = function Line(options) {
|
|
|
108
132
|
y: 'value'
|
|
109
133
|
};
|
|
110
134
|
}
|
|
135
|
+
var children = [{
|
|
136
|
+
type: 'line',
|
|
137
|
+
tooltip: tooltip,
|
|
138
|
+
style: _objectSpread({
|
|
139
|
+
lineWidth: lineWidth,
|
|
140
|
+
lineCap: 'round',
|
|
141
|
+
lineJoin: 'round'
|
|
142
|
+
}, !hasGroupField ? {
|
|
143
|
+
stroke: colors[0]
|
|
144
|
+
} : {}),
|
|
145
|
+
animate: lineAnimation
|
|
146
|
+
}];
|
|
147
|
+
var showPoints = data.length <= (hasGroupField ? 36 : 24);
|
|
148
|
+
if (showPoints) {
|
|
149
|
+
children.push({
|
|
150
|
+
type: 'point',
|
|
151
|
+
encode: _objectSpread({
|
|
152
|
+
x: 'time',
|
|
153
|
+
y: 'value',
|
|
154
|
+
shape: 'point',
|
|
155
|
+
size: CHART_STYLE_DEFAULTS.pointSize
|
|
156
|
+
}, hasGroupField ? {
|
|
157
|
+
color: 'group'
|
|
158
|
+
} : {}),
|
|
159
|
+
animate: pointAnimation,
|
|
160
|
+
tooltip: false,
|
|
161
|
+
style: _objectSpread({
|
|
162
|
+
lineWidth: CHART_STYLE_DEFAULTS.pointLineWidth,
|
|
163
|
+
stroke: backgroundColor
|
|
164
|
+
}, !hasGroupField ? {
|
|
165
|
+
fill: colors[0]
|
|
166
|
+
} : {})
|
|
167
|
+
});
|
|
168
|
+
}
|
|
111
169
|
|
|
112
170
|
// Configure chart options
|
|
113
171
|
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
114
172
|
// This is consistent with how G2 5.0 is used elsewhere in the codebase
|
|
115
|
-
var chartOptions = {
|
|
116
|
-
animate: false,
|
|
173
|
+
var chartOptions = _objectSpread(_objectSpread({
|
|
117
174
|
type: 'view',
|
|
118
175
|
data: data,
|
|
119
|
-
title: title
|
|
176
|
+
title: title || '',
|
|
120
177
|
encode: encode,
|
|
121
|
-
children:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
axis: {
|
|
131
|
-
x: {
|
|
132
|
-
title: axisXTitle || false
|
|
133
|
-
},
|
|
134
|
-
y: {
|
|
135
|
-
title: axisYTitle || false
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
legend: hasGroupField ? {
|
|
139
|
-
color: {
|
|
140
|
-
position: 'top'
|
|
141
|
-
}
|
|
142
|
-
} : false,
|
|
143
|
-
tooltip: {
|
|
144
|
-
items: [function (d) {
|
|
145
|
-
return {
|
|
146
|
-
name: axisYTitle || d.time,
|
|
147
|
-
value: d.value
|
|
148
|
-
};
|
|
149
|
-
}]
|
|
178
|
+
children: children,
|
|
179
|
+
scale: scaleConfig
|
|
180
|
+
}, getCartesianLayout(cartesianAxisOptions)), {}, {
|
|
181
|
+
axis: getCartesianAxis(cartesianAxisOptions),
|
|
182
|
+
legend: getColorLegend(hasGroupField),
|
|
183
|
+
interaction: {
|
|
184
|
+
tooltip: getSharedTooltipInteraction({
|
|
185
|
+
crosshairs: true
|
|
186
|
+
})
|
|
150
187
|
},
|
|
151
|
-
viewStyle: {
|
|
188
|
+
viewStyle: style.backgroundColor ? {
|
|
152
189
|
viewFill: backgroundColor
|
|
153
|
-
},
|
|
190
|
+
} : undefined,
|
|
154
191
|
theme: getThemeObject(theme)
|
|
155
|
-
};
|
|
192
|
+
});
|
|
156
193
|
chart.options(chartOptions);
|
|
194
|
+
cleanupCrosshairAxisLabels = bindCrosshairAxisLabels(chart, theme);
|
|
157
195
|
chart.render();
|
|
196
|
+
hasRendered = true;
|
|
158
197
|
};
|
|
159
198
|
|
|
160
199
|
/**
|
|
@@ -162,9 +201,13 @@ export var Line = function Line(options) {
|
|
|
162
201
|
*/
|
|
163
202
|
var destroy = function destroy() {
|
|
164
203
|
if (chart) {
|
|
204
|
+
var _cleanupCrosshairAxis2;
|
|
205
|
+
(_cleanupCrosshairAxis2 = cleanupCrosshairAxisLabels) === null || _cleanupCrosshairAxis2 === void 0 || _cleanupCrosshairAxis2();
|
|
206
|
+
cleanupCrosshairAxisLabels = null;
|
|
165
207
|
chart.destroy();
|
|
166
208
|
chart = null;
|
|
167
209
|
}
|
|
210
|
+
hasRendered = false;
|
|
168
211
|
};
|
|
169
212
|
return {
|
|
170
213
|
render: 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;
|
|
@@ -5,7 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import { Chart } from '@antv/g2';
|
|
8
|
-
import { getBackgroundColor, getThemeObject, normalizePalette } from "../../util
|
|
8
|
+
import { CHART_FONT_FAMILY, getBackgroundColor, getChartVisualTokens, getThemeObject, normalizePalette } from "../../util";
|
|
9
9
|
|
|
10
10
|
// Default dimensions used for font size calculation when not explicitly provided
|
|
11
11
|
var DEFAULT_WIDTH = 640;
|
|
@@ -69,11 +69,19 @@ export var Liquid = function Liquid(options) {
|
|
|
69
69
|
// Get colors from style.palette or theme defaults
|
|
70
70
|
var colors = normalizePalette(style.palette, theme);
|
|
71
71
|
var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
72
|
+
var tokens = getChartVisualTokens(theme);
|
|
73
|
+
var normalizedPercent = Number.isFinite(percent) ? Math.max(0, Math.min(1, percent)) : 0;
|
|
72
74
|
|
|
73
75
|
// Calculate dynamic font size based on chart dimensions
|
|
74
76
|
// Use default dimensions for font size calculation when not provided
|
|
75
77
|
var inferFontSize = Math.min(width !== null && width !== void 0 ? width : DEFAULT_WIDTH, height !== null && height !== void 0 ? height : DEFAULT_HEIGHT) / 10;
|
|
76
78
|
var fontSize = Math.min(Math.max(inferFontSize, 24), 64);
|
|
79
|
+
var chartSize = Math.min(width !== null && width !== void 0 ? width : DEFAULT_WIDTH, height !== null && height !== void 0 ? height : DEFAULT_HEIGHT);
|
|
80
|
+
var waveLength = Math.min(Math.max(chartSize * 0.4, 96), 192);
|
|
81
|
+
var formattedPercent = "".concat(Number((normalizedPercent * 100).toFixed(1)), "%");
|
|
82
|
+
var liquidColor = colors[0];
|
|
83
|
+
var isAcademy = theme === 'academy';
|
|
84
|
+
var outlineShadowColor = theme === 'dark' ? 'rgba(0, 0, 0, 0.32)' : 'rgba(15, 23, 42, 0.10)';
|
|
77
85
|
|
|
78
86
|
// Create chart
|
|
79
87
|
chart = new Chart({
|
|
@@ -89,25 +97,44 @@ export var Liquid = function Liquid(options) {
|
|
|
89
97
|
var chartOptions = {
|
|
90
98
|
animate: false,
|
|
91
99
|
type: 'liquid',
|
|
92
|
-
data:
|
|
93
|
-
title: title
|
|
100
|
+
data: normalizedPercent,
|
|
101
|
+
title: title || '',
|
|
102
|
+
inset: 20,
|
|
94
103
|
style: _objectSpread({
|
|
95
104
|
shape: shape,
|
|
105
|
+
contentText: formattedPercent,
|
|
96
106
|
contentFontSize: fontSize,
|
|
97
|
-
contentFill:
|
|
98
|
-
contentStroke:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
107
|
+
contentFill: tokens.textPrimary,
|
|
108
|
+
contentStroke: backgroundColor,
|
|
109
|
+
contentStrokeOpacity: 0.92,
|
|
110
|
+
contentLineWidth: theme === 'dark' ? 3 : 2.5,
|
|
111
|
+
contentFontFamily: CHART_FONT_FAMILY,
|
|
112
|
+
contentFontWeight: 600,
|
|
113
|
+
contentLetterSpacing: -0.8,
|
|
114
|
+
contentFontVariantNumeric: 'tabular-nums',
|
|
115
|
+
contentPaintOrder: 'stroke',
|
|
116
|
+
backgroundFill: liquidColor,
|
|
117
|
+
backgroundFillOpacity: theme === 'dark' ? 0.14 : isAcademy ? 0.06 : 0.08,
|
|
118
|
+
backgroundStroke: liquidColor,
|
|
119
|
+
backgroundStrokeOpacity: theme === 'dark' ? 0.3 : 0.22,
|
|
120
|
+
backgroundLineWidth: 1,
|
|
121
|
+
outlineBorder: isAcademy ? 1.5 : 2,
|
|
122
|
+
outlineDistance: 0,
|
|
123
|
+
outlineStrokeOpacity: isAcademy ? 0.9 : 0.72,
|
|
124
|
+
outlineShadowColor: isAcademy ? 'transparent' : outlineShadowColor,
|
|
125
|
+
outlineShadowBlur: isAcademy ? 0 : 6,
|
|
126
|
+
outlineShadowOffsetY: isAcademy ? 0 : 2,
|
|
127
|
+
waveLength: waveLength,
|
|
128
|
+
waveCount: 2,
|
|
129
|
+
fillOpacity: isAcademy ? 0.9 : 0.88,
|
|
103
130
|
contentPointerEvents: 'none'
|
|
104
|
-
},
|
|
105
|
-
fill:
|
|
106
|
-
outlineStroke:
|
|
131
|
+
}, liquidColor ? {
|
|
132
|
+
fill: liquidColor,
|
|
133
|
+
outlineStroke: liquidColor
|
|
107
134
|
} : {}),
|
|
108
|
-
viewStyle: {
|
|
135
|
+
viewStyle: style.backgroundColor ? {
|
|
109
136
|
viewFill: backgroundColor
|
|
110
|
-
},
|
|
137
|
+
} : undefined,
|
|
111
138
|
theme: getThemeObject(theme),
|
|
112
139
|
tooltip: false
|
|
113
140
|
};
|
|
@@ -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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chart } from '@antv/g2';
|
|
2
|
-
import {
|
|
2
|
+
import { getChartAnimation, getChartVisualTokens, getColorLegend, getThemeObject, normalizePalette } from "../../util";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* PieDataItem is the type for each data item in the pie chart.
|
|
@@ -44,6 +44,7 @@ export var Pie = function Pie(options) {
|
|
|
44
44
|
_options$theme = options.theme,
|
|
45
45
|
chartTheme = _options$theme === void 0 ? 'default' : _options$theme;
|
|
46
46
|
var chart = null;
|
|
47
|
+
var hasRendered = false;
|
|
47
48
|
|
|
48
49
|
// Precision multiplier for rounding percentages to 4 decimal places
|
|
49
50
|
var PERCENTAGE_PRECISION_MULTIPLIER = 10000;
|
|
@@ -69,7 +70,7 @@ export var Pie = function Pie(options) {
|
|
|
69
70
|
|
|
70
71
|
// Get colors from style.palette or theme defaults
|
|
71
72
|
var colors = normalizePalette(style.palette, theme);
|
|
72
|
-
var
|
|
73
|
+
var tokens = getChartVisualTokens(theme);
|
|
73
74
|
|
|
74
75
|
// Calculate sum for percentage labels
|
|
75
76
|
var sumValue = data.reduce(function (sum, item) {
|
|
@@ -88,10 +89,10 @@ export var Pie = function Pie(options) {
|
|
|
88
89
|
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
89
90
|
// This is consistent with how G2 5.0 is used elsewhere in the codebase (e.g., Radar component)
|
|
90
91
|
var chartOptions = {
|
|
91
|
-
animate:
|
|
92
|
+
animate: getChartAnimation(hasRendered, 'waveIn'),
|
|
92
93
|
type: 'interval',
|
|
93
94
|
data: data,
|
|
94
|
-
title: title
|
|
95
|
+
title: title || '',
|
|
95
96
|
encode: {
|
|
96
97
|
y: 'value',
|
|
97
98
|
color: 'category'
|
|
@@ -108,15 +109,12 @@ export var Pie = function Pie(options) {
|
|
|
108
109
|
range: colors
|
|
109
110
|
}
|
|
110
111
|
},
|
|
111
|
-
legend:
|
|
112
|
-
|
|
113
|
-
position: 'top'
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
labels: [{
|
|
112
|
+
legend: getColorLegend(true),
|
|
113
|
+
labels: data.length > 8 ? [] : [{
|
|
117
114
|
text: function text(d) {
|
|
118
|
-
var percentage = Math.round(d.value / sumValue * 100 * PERCENTAGE_PRECISION_MULTIPLIER) / PERCENTAGE_PRECISION_MULTIPLIER;
|
|
119
|
-
|
|
115
|
+
var percentage = sumValue ? Math.round(d.value / sumValue * 100 * PERCENTAGE_PRECISION_MULTIPLIER) / PERCENTAGE_PRECISION_MULTIPLIER : 0;
|
|
116
|
+
var formattedPercentage = Number(percentage.toFixed(1)).toString();
|
|
117
|
+
return "".concat(d.category, ": ").concat(formattedPercentage, "%");
|
|
120
118
|
},
|
|
121
119
|
position: 'outside',
|
|
122
120
|
transform: [{
|
|
@@ -132,20 +130,41 @@ export var Pie = function Pie(options) {
|
|
|
132
130
|
}]
|
|
133
131
|
},
|
|
134
132
|
interaction: {
|
|
133
|
+
tooltip: true,
|
|
134
|
+
elementHighlight: true,
|
|
135
|
+
elementHoverScale: {
|
|
136
|
+
shadow: false
|
|
137
|
+
},
|
|
135
138
|
elementSelect: {
|
|
136
139
|
single: true
|
|
137
140
|
}
|
|
138
141
|
},
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
state: {
|
|
143
|
+
active: {
|
|
144
|
+
fillOpacity: 1,
|
|
145
|
+
lineWidth: 3
|
|
146
|
+
},
|
|
147
|
+
inactive: {
|
|
148
|
+
fillOpacity: 0.3
|
|
149
|
+
},
|
|
150
|
+
selected: {
|
|
151
|
+
fillOpacity: 1,
|
|
152
|
+
lineWidth: 3
|
|
153
|
+
}
|
|
141
154
|
},
|
|
142
|
-
|
|
143
|
-
|
|
155
|
+
style: {
|
|
156
|
+
fillOpacity: 1,
|
|
157
|
+
stroke: tokens.separator,
|
|
158
|
+
lineWidth: 2
|
|
144
159
|
},
|
|
160
|
+
viewStyle: style.backgroundColor ? {
|
|
161
|
+
viewFill: style.backgroundColor
|
|
162
|
+
} : undefined,
|
|
145
163
|
theme: getThemeObject(theme)
|
|
146
164
|
};
|
|
147
165
|
chart.options(chartOptions);
|
|
148
166
|
chart.render();
|
|
167
|
+
hasRendered = true;
|
|
149
168
|
};
|
|
150
169
|
|
|
151
170
|
/**
|
|
@@ -156,6 +175,7 @@ export var Pie = function Pie(options) {
|
|
|
156
175
|
chart.destroy();
|
|
157
176
|
chart = null;
|
|
158
177
|
}
|
|
178
|
+
hasRendered = false;
|
|
159
179
|
};
|
|
160
180
|
return {
|
|
161
181
|
render: 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[];
|
|
@@ -15,7 +15,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
15
15
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
16
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
17
|
import { Chart } from '@antv/g2';
|
|
18
|
-
import {
|
|
18
|
+
import { CHART_STYLE_DEFAULTS, getColorLegend, getLineHighlightState, getSeriesHighlightByColorInteraction, getThemeObject, normalizePalette } from "../../util";
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* RadarDataItem is the type for each data item in the radar chart.
|
|
@@ -118,15 +118,16 @@ export var Radar = function Radar(options) {
|
|
|
118
118
|
chart.destroy();
|
|
119
119
|
}
|
|
120
120
|
var _style$lineWidth = style.lineWidth,
|
|
121
|
-
lineWidth = _style$lineWidth === void 0 ?
|
|
121
|
+
lineWidth = _style$lineWidth === void 0 ? CHART_STYLE_DEFAULTS.lineWidth : _style$lineWidth;
|
|
122
122
|
var colors = normalizePalette(style.palette, theme);
|
|
123
|
-
var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
124
123
|
|
|
125
124
|
// Transform data to parallel format
|
|
126
125
|
var parallelData = transformRadarToParallel(data);
|
|
127
126
|
var position = Object.keys(parallelData[0] || {}).filter(function (key) {
|
|
128
127
|
return key !== 'group';
|
|
129
128
|
});
|
|
129
|
+
var hasMultipleSeries = parallelData.length > 1;
|
|
130
|
+
var legend = getColorLegend(hasMultipleSeries);
|
|
130
131
|
|
|
131
132
|
// Create chart
|
|
132
133
|
chart = new Chart({
|
|
@@ -143,11 +144,11 @@ export var Radar = function Radar(options) {
|
|
|
143
144
|
animate: false,
|
|
144
145
|
type: 'line',
|
|
145
146
|
data: parallelData,
|
|
146
|
-
title: title
|
|
147
|
+
title: title || '',
|
|
147
148
|
coordinate: {
|
|
148
149
|
type: 'radar'
|
|
149
150
|
},
|
|
150
|
-
inset:
|
|
151
|
+
inset: 24,
|
|
151
152
|
encode: {
|
|
152
153
|
position: position,
|
|
153
154
|
color: 'group'
|
|
@@ -177,45 +178,31 @@ export var Radar = function Radar(options) {
|
|
|
177
178
|
length: position.length
|
|
178
179
|
}, function (_, i) {
|
|
179
180
|
return ["position".concat(i === 0 ? '' : i), {
|
|
180
|
-
|
|
181
|
-
titleFontSize: 10,
|
|
182
|
-
titleSpacing: 8,
|
|
183
|
-
label: true,
|
|
184
|
-
labelFill: theme === 'dark' ? '#fff' : '#000',
|
|
185
|
-
labelOpacity: 0.45,
|
|
186
|
-
labelFontSize: 10,
|
|
187
|
-
line: true,
|
|
188
|
-
lineFill: '#000',
|
|
189
|
-
lineStrokeOpacity: 0.25,
|
|
181
|
+
label: align ? i === 0 : true,
|
|
190
182
|
tickFilter: function tickFilter(_, idx) {
|
|
191
183
|
return !(i !== 0 && idx === 0);
|
|
192
184
|
},
|
|
193
|
-
|
|
194
|
-
gridStrokeOpacity: 0.45,
|
|
195
|
-
gridStroke: theme === 'dark' ? '#fff' : '#000',
|
|
196
|
-
gridLineWidth: 1,
|
|
197
|
-
gridLineDash: [4, 4]
|
|
185
|
+
grid: i === 0
|
|
198
186
|
}];
|
|
199
187
|
})),
|
|
200
188
|
style: {
|
|
201
189
|
lineWidth: lineWidth,
|
|
202
190
|
lineCap: 'round',
|
|
203
|
-
lineJoin: 'round'
|
|
191
|
+
lineJoin: 'round',
|
|
192
|
+
strokeOpacity: CHART_STYLE_DEFAULTS.lineOpacity
|
|
204
193
|
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
itemMarker: '
|
|
209
|
-
}
|
|
210
|
-
} : false,
|
|
211
|
-
interaction: {
|
|
212
|
-
tooltip: {
|
|
213
|
-
series: false
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
viewStyle: {
|
|
217
|
-
viewFill: backgroundColor
|
|
194
|
+
state: hasMultipleSeries ? getLineHighlightState(lineWidth) : undefined,
|
|
195
|
+
legend: legend === false ? false : {
|
|
196
|
+
color: _objectSpread(_objectSpread({}, legend.color), {}, {
|
|
197
|
+
itemMarker: 'smooth'
|
|
198
|
+
})
|
|
218
199
|
},
|
|
200
|
+
interaction: _objectSpread({
|
|
201
|
+
tooltip: true
|
|
202
|
+
}, hasMultipleSeries ? getSeriesHighlightByColorInteraction() : {}),
|
|
203
|
+
viewStyle: style.backgroundColor ? {
|
|
204
|
+
viewFill: style.backgroundColor
|
|
205
|
+
} : undefined,
|
|
219
206
|
theme: getThemeObject(theme)
|
|
220
207
|
};
|
|
221
208
|
chart.options(chartOptions);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chart } from '@antv/g2';
|
|
2
|
-
import {
|
|
2
|
+
import { getThemeObject, normalizePalette } from "../../util/theme";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* SankeyDataItem is the type for each data item in the sankey chart.
|
|
@@ -67,7 +67,6 @@ export var Sankey = function Sankey(options) {
|
|
|
67
67
|
|
|
68
68
|
// Get colors from style.palette or theme defaults
|
|
69
69
|
var colors = normalizePalette(style.palette, theme);
|
|
70
|
-
var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
71
70
|
|
|
72
71
|
// Create chart
|
|
73
72
|
chart = new Chart({
|
|
@@ -109,9 +108,9 @@ export var Sankey = function Sankey(options) {
|
|
|
109
108
|
nodeLineWidth: 1,
|
|
110
109
|
linkFillOpacity: 0.3
|
|
111
110
|
},
|
|
112
|
-
viewStyle: {
|
|
113
|
-
viewFill: backgroundColor
|
|
114
|
-
},
|
|
111
|
+
viewStyle: style.backgroundColor ? {
|
|
112
|
+
viewFill: style.backgroundColor
|
|
113
|
+
} : undefined,
|
|
115
114
|
theme: getThemeObject(theme),
|
|
116
115
|
legend: false,
|
|
117
116
|
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[];
|