@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
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/crosshair-axis-labels.ts
|
|
20
|
+
var crosshair_axis_labels_exports = {};
|
|
21
|
+
__export(crosshair_axis_labels_exports, {
|
|
22
|
+
bindCrosshairAxisLabels: () => bindCrosshairAxisLabels
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(crosshair_axis_labels_exports);
|
|
25
|
+
var import_component = require("@antv/component");
|
|
26
|
+
var import_g2 = require("@antv/g2");
|
|
27
|
+
var import_tokens = require("./tokens");
|
|
28
|
+
var MAX_CROSSHAIR_DECIMAL_PLACES = 6;
|
|
29
|
+
var formatCrosshairAxisValue = (value, formatter, precision) => {
|
|
30
|
+
if (value === void 0 || value === null || value === "")
|
|
31
|
+
return "";
|
|
32
|
+
let displayValue = value;
|
|
33
|
+
try {
|
|
34
|
+
const formatted = formatter == null ? void 0 : formatter(value);
|
|
35
|
+
if (formatted !== void 0 && formatted !== null) {
|
|
36
|
+
const numericFormatted = typeof formatted === "number" || typeof formatted === "string" && formatted.trim() !== "" && Number.isFinite(Number(formatted)) ? Number(formatted) : void 0;
|
|
37
|
+
if (numericFormatted === void 0)
|
|
38
|
+
return String(formatted);
|
|
39
|
+
displayValue = numericFormatted;
|
|
40
|
+
}
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
if (displayValue instanceof Date)
|
|
44
|
+
return displayValue.toLocaleString();
|
|
45
|
+
if (typeof displayValue === "number" && Number.isFinite(displayValue)) {
|
|
46
|
+
if (displayValue !== 0 && Math.abs(displayValue) < 10 ** -MAX_CROSSHAIR_DECIMAL_PLACES) {
|
|
47
|
+
return Number(displayValue.toPrecision(4)).toString();
|
|
48
|
+
}
|
|
49
|
+
const decimalPlaces = Math.min(
|
|
50
|
+
Math.max(precision ?? MAX_CROSSHAIR_DECIMAL_PLACES, 0),
|
|
51
|
+
MAX_CROSSHAIR_DECIMAL_PLACES
|
|
52
|
+
);
|
|
53
|
+
return Number(displayValue.toFixed(decimalPlaces)).toString();
|
|
54
|
+
}
|
|
55
|
+
return String(displayValue);
|
|
56
|
+
};
|
|
57
|
+
var getNumberPrecision = (value) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!Number.isFinite(value) || value === 0)
|
|
60
|
+
return 0;
|
|
61
|
+
const normalizedValue = Number(value.toPrecision(12));
|
|
62
|
+
const [coefficient, exponentText = "0"] = Math.abs(normalizedValue).toExponential().split("e");
|
|
63
|
+
const coefficientPrecision = ((_a = coefficient.split(".")[1]) == null ? void 0 : _a.length) || 0;
|
|
64
|
+
return Math.max(0, coefficientPrecision - Number(exponentText));
|
|
65
|
+
};
|
|
66
|
+
var getCrosshairScalePrecision = (scale) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const ticks = (_a = scale == null ? void 0 : scale.getTicks) == null ? void 0 : _a.call(scale);
|
|
69
|
+
if (!Array.isArray(ticks) || ticks.length < 2)
|
|
70
|
+
return void 0;
|
|
71
|
+
let interval = Number.POSITIVE_INFINITY;
|
|
72
|
+
for (let index = 1; index < ticks.length; index += 1) {
|
|
73
|
+
const current = Number(ticks[index]);
|
|
74
|
+
const previous = Number(ticks[index - 1]);
|
|
75
|
+
const difference = Math.abs(current - previous);
|
|
76
|
+
if (Number.isFinite(difference) && difference > 0)
|
|
77
|
+
interval = Math.min(interval, difference);
|
|
78
|
+
}
|
|
79
|
+
if (!Number.isFinite(interval))
|
|
80
|
+
return void 0;
|
|
81
|
+
return Math.min(getNumberPrecision(interval) + 2, MAX_CROSSHAIR_DECIMAL_PLACES);
|
|
82
|
+
};
|
|
83
|
+
var getCrosshairTagStyle = (theme, tokens) => ({
|
|
84
|
+
lineLineWidth: 0,
|
|
85
|
+
lineStrokeOpacity: 0,
|
|
86
|
+
linePointerEvents: "none",
|
|
87
|
+
tagPadding: [4, 7],
|
|
88
|
+
tagRadius: 6,
|
|
89
|
+
tagBackgroundFill: tokens.textPrimary,
|
|
90
|
+
tagBackgroundStroke: "transparent",
|
|
91
|
+
tagBackgroundLineWidth: 0,
|
|
92
|
+
tagBackgroundShadowColor: theme === "dark" ? "rgba(0, 0, 0, 0.38)" : "rgba(15, 23, 42, 0.18)",
|
|
93
|
+
tagBackgroundShadowBlur: 8,
|
|
94
|
+
tagBackgroundShadowOffsetY: 2,
|
|
95
|
+
tagLabelFill: tokens.background,
|
|
96
|
+
tagLabelFillOpacity: 1,
|
|
97
|
+
tagLabelFontFamily: import_tokens.CHART_FONT_FAMILY,
|
|
98
|
+
tagLabelFontSize: 11,
|
|
99
|
+
tagLabelFontWeight: 500,
|
|
100
|
+
tagLabelLineWidth: 0,
|
|
101
|
+
tagPointerEvents: "none"
|
|
102
|
+
});
|
|
103
|
+
var getStandaloneTagStyle = (theme, tokens) => ({
|
|
104
|
+
align: "start",
|
|
105
|
+
verticalAlign: "middle",
|
|
106
|
+
padding: [4, 7],
|
|
107
|
+
radius: 6,
|
|
108
|
+
backgroundFill: tokens.textPrimary,
|
|
109
|
+
backgroundStroke: "transparent",
|
|
110
|
+
backgroundLineWidth: 0,
|
|
111
|
+
backgroundShadowColor: theme === "dark" ? "rgba(0, 0, 0, 0.38)" : "rgba(15, 23, 42, 0.18)",
|
|
112
|
+
backgroundShadowBlur: 8,
|
|
113
|
+
backgroundShadowOffsetY: 2,
|
|
114
|
+
labelFill: tokens.background,
|
|
115
|
+
labelFillOpacity: 1,
|
|
116
|
+
labelFontFamily: import_tokens.CHART_FONT_FAMILY,
|
|
117
|
+
labelFontSize: 11,
|
|
118
|
+
labelFontWeight: 500,
|
|
119
|
+
labelLineWidth: 0,
|
|
120
|
+
pointerEvents: "none"
|
|
121
|
+
});
|
|
122
|
+
var clamp = (value, min, max) => Math.min(Math.max(value, Math.min(min, max)), Math.max(min, max));
|
|
123
|
+
var invertCrosshairValue = (scale, value) => {
|
|
124
|
+
var _a, _b, _c;
|
|
125
|
+
if (!scale || typeof scale.invert !== "function" || value === void 0)
|
|
126
|
+
return void 0;
|
|
127
|
+
if (typeof scale.getBandWidth === "function") {
|
|
128
|
+
const domain = (_b = (_a = scale.getOptions) == null ? void 0 : _a.call(scale)) == null ? void 0 : _b.domain;
|
|
129
|
+
if (!Array.isArray(domain) || domain.length === 0 || !Number.isFinite(Number(value))) {
|
|
130
|
+
return void 0;
|
|
131
|
+
}
|
|
132
|
+
let nearestValue = domain[0];
|
|
133
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
134
|
+
for (const domainValue of domain) {
|
|
135
|
+
const start = Number((_c = scale.map) == null ? void 0 : _c.call(scale, domainValue));
|
|
136
|
+
const bandWidth = Number(scale.getBandWidth(domainValue)) || 0;
|
|
137
|
+
const distance = Math.abs(start + bandWidth / 2 - Number(value));
|
|
138
|
+
if (Number.isFinite(distance) && distance < nearestDistance) {
|
|
139
|
+
nearestValue = domainValue;
|
|
140
|
+
nearestDistance = distance;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return nearestValue;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
return scale.invert(value);
|
|
147
|
+
} catch {
|
|
148
|
+
return void 0;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var getTooltipPlot = (context) => {
|
|
152
|
+
var _a;
|
|
153
|
+
const root = (_a = context.canvas) == null ? void 0 : _a.getRoot();
|
|
154
|
+
if (!root)
|
|
155
|
+
return void 0;
|
|
156
|
+
return (0, import_g2.selectPlotArea)(root);
|
|
157
|
+
};
|
|
158
|
+
var getScaleField = (scale) => {
|
|
159
|
+
var _a, _b;
|
|
160
|
+
return (_b = (_a = scale == null ? void 0 : scale.getOptions) == null ? void 0 : _a.call(scale)) == null ? void 0 : _b.field;
|
|
161
|
+
};
|
|
162
|
+
var findYScaleByField = (view, yField) => {
|
|
163
|
+
var _a;
|
|
164
|
+
return (_a = Object.entries(view.scale).find(
|
|
165
|
+
([scaleName, scale]) => /^y\d*$/.test(scaleName) && getScaleField(scale) === yField
|
|
166
|
+
)) == null ? void 0 : _a[1];
|
|
167
|
+
};
|
|
168
|
+
var getYScale = (view, yField) => yField ? findYScaleByField(view, yField) : view.scale.y;
|
|
169
|
+
var getCartesianView = (context, yField) => {
|
|
170
|
+
var _a;
|
|
171
|
+
return (_a = context.views) == null ? void 0 : _a.find(
|
|
172
|
+
(view) => {
|
|
173
|
+
var _a2, _b;
|
|
174
|
+
return Boolean(((_a2 = view.scale) == null ? void 0 : _a2.x) && getYScale(view, yField)) && typeof ((_b = view.coordinate) == null ? void 0 : _b.invert) === "function";
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
var hasAxisField = (field, yField) => Array.isArray(field) ? field.includes(yField) : field === yField;
|
|
179
|
+
var getYAxisLinePosition = (view, yField, position, fallback, plotX) => {
|
|
180
|
+
var _a;
|
|
181
|
+
if (!yField)
|
|
182
|
+
return fallback;
|
|
183
|
+
const axis = (_a = view.components) == null ? void 0 : _a.find(
|
|
184
|
+
({ bbox, position: axisPosition, scales, type }) => type === "axisY" && axisPosition === position && Number.isFinite(Number(bbox == null ? void 0 : bbox.x)) && (scales == null ? void 0 : scales.some((scale) => hasAxisField(scale.field, yField)))
|
|
185
|
+
);
|
|
186
|
+
if (!(axis == null ? void 0 : axis.bbox))
|
|
187
|
+
return fallback;
|
|
188
|
+
const x = Number(axis.bbox.x);
|
|
189
|
+
const width = Number(axis.bbox.width);
|
|
190
|
+
const axisX = position === "right" || !Number.isFinite(width) ? x : x + width;
|
|
191
|
+
return axisX - plotX;
|
|
192
|
+
};
|
|
193
|
+
var getRuleLine = (rule) => {
|
|
194
|
+
var _a, _b, _c, _d;
|
|
195
|
+
const x1 = Number((_a = rule == null ? void 0 : rule.style) == null ? void 0 : _a.x1);
|
|
196
|
+
const x2 = Number((_b = rule == null ? void 0 : rule.style) == null ? void 0 : _b.x2);
|
|
197
|
+
const y1 = Number((_c = rule == null ? void 0 : rule.style) == null ? void 0 : _c.y1);
|
|
198
|
+
const y2 = Number((_d = rule == null ? void 0 : rule.style) == null ? void 0 : _d.y2);
|
|
199
|
+
if (![x1, x2, y1, y2].every(Number.isFinite))
|
|
200
|
+
return void 0;
|
|
201
|
+
return { x1, x2, y1, y2 };
|
|
202
|
+
};
|
|
203
|
+
var getPlotOffset = (plot) => {
|
|
204
|
+
var _a;
|
|
205
|
+
const [x = 0, y = 0] = ((_a = plot.getLocalPosition) == null ? void 0 : _a.call(plot)) || [];
|
|
206
|
+
return [Number.isFinite(Number(x)) ? Number(x) : 0, Number.isFinite(Number(y)) ? Number(y) : 0];
|
|
207
|
+
};
|
|
208
|
+
var invertCoordinate = (view, point) => {
|
|
209
|
+
try {
|
|
210
|
+
const inverted = view.coordinate.invert(point);
|
|
211
|
+
if (!Array.isArray(inverted) || inverted.length < 2)
|
|
212
|
+
return void 0;
|
|
213
|
+
const x = Number(inverted[0]);
|
|
214
|
+
const y = Number(inverted[1]);
|
|
215
|
+
return Number.isFinite(x) && Number.isFinite(y) ? [x, y] : void 0;
|
|
216
|
+
} catch {
|
|
217
|
+
return void 0;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
var bindCrosshairAxisLabels = (chart, theme, {
|
|
221
|
+
showXLabel = true,
|
|
222
|
+
useStandaloneYLabel = false,
|
|
223
|
+
yAxisPosition = "left",
|
|
224
|
+
yField
|
|
225
|
+
} = {}) => {
|
|
226
|
+
if (!chart || typeof chart.on !== "function")
|
|
227
|
+
return () => void 0;
|
|
228
|
+
const tagStyle = getCrosshairTagStyle(theme, (0, import_tokens.getChartVisualTokens)(theme));
|
|
229
|
+
const standaloneTagStyle = getStandaloneTagStyle(theme, (0, import_tokens.getChartVisualTokens)(theme));
|
|
230
|
+
let boundPlot = null;
|
|
231
|
+
let xCrosshair = null;
|
|
232
|
+
let yCrosshair = null;
|
|
233
|
+
let standaloneYTag = null;
|
|
234
|
+
let latestPointerY = null;
|
|
235
|
+
let latestXValue;
|
|
236
|
+
const destroyCrosshairs = () => {
|
|
237
|
+
xCrosshair == null ? void 0 : xCrosshair.destroy();
|
|
238
|
+
yCrosshair == null ? void 0 : yCrosshair.destroy();
|
|
239
|
+
standaloneYTag == null ? void 0 : standaloneYTag.destroy();
|
|
240
|
+
xCrosshair = null;
|
|
241
|
+
yCrosshair = null;
|
|
242
|
+
standaloneYTag = null;
|
|
243
|
+
boundPlot = null;
|
|
244
|
+
};
|
|
245
|
+
const hideCrosshairs = () => {
|
|
246
|
+
for (const crosshair of [xCrosshair, yCrosshair, standaloneYTag]) {
|
|
247
|
+
if (crosshair)
|
|
248
|
+
crosshair.style.visibility = "hidden";
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
const resetCrosshairs = () => {
|
|
252
|
+
latestPointerY = null;
|
|
253
|
+
latestXValue = void 0;
|
|
254
|
+
hideCrosshairs();
|
|
255
|
+
};
|
|
256
|
+
const ensureCrosshairs = (plot, xLine, yLine, xText, yText) => {
|
|
257
|
+
if (boundPlot !== plot)
|
|
258
|
+
destroyCrosshairs();
|
|
259
|
+
if (xCrosshair && yCrosshair)
|
|
260
|
+
return;
|
|
261
|
+
const layer = plot.parentNode || plot;
|
|
262
|
+
const [plotX, plotY] = getPlotOffset(plot);
|
|
263
|
+
const xStart = [xLine.x1 + plotX, xLine.y1 + plotY];
|
|
264
|
+
const xEnd = [xLine.x2 + plotX, xLine.y2 + plotY];
|
|
265
|
+
const yStart = [yLine.x1 + plotX, yLine.y1 + plotY];
|
|
266
|
+
const yEnd = [yLine.x2 + plotX, yLine.y2 + plotY];
|
|
267
|
+
if (showXLabel && !xCrosshair) {
|
|
268
|
+
xCrosshair = new import_component.LineCrosshair({
|
|
269
|
+
style: { ...tagStyle, startPos: xStart, endPos: xEnd, tagText: xText, tagPosition: "end" }
|
|
270
|
+
});
|
|
271
|
+
xCrosshair.style.zIndex = 7;
|
|
272
|
+
xCrosshair.style.pointerEvents = "none";
|
|
273
|
+
layer.appendChild(xCrosshair);
|
|
274
|
+
}
|
|
275
|
+
if (showXLabel && !useStandaloneYLabel && !yCrosshair) {
|
|
276
|
+
yCrosshair = new import_component.LineCrosshair({
|
|
277
|
+
style: {
|
|
278
|
+
...tagStyle,
|
|
279
|
+
startPos: yStart,
|
|
280
|
+
endPos: yEnd,
|
|
281
|
+
tagText: yText,
|
|
282
|
+
tagPosition: yAxisPosition === "right" ? "end" : "start"
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
yCrosshair.style.zIndex = 7;
|
|
286
|
+
yCrosshair.style.pointerEvents = "none";
|
|
287
|
+
layer.appendChild(yCrosshair);
|
|
288
|
+
}
|
|
289
|
+
if ((useStandaloneYLabel || !showXLabel) && !standaloneYTag) {
|
|
290
|
+
standaloneYTag = new import_component.Tag({ style: { ...standaloneTagStyle, text: yText } });
|
|
291
|
+
standaloneYTag.style.zIndex = 7;
|
|
292
|
+
standaloneYTag.style.pointerEvents = "none";
|
|
293
|
+
layer.appendChild(standaloneYTag);
|
|
294
|
+
}
|
|
295
|
+
boundPlot = plot;
|
|
296
|
+
};
|
|
297
|
+
const updateCrosshairs = (event) => {
|
|
298
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
299
|
+
const context = chart.getContext();
|
|
300
|
+
const plot = getTooltipPlot(context);
|
|
301
|
+
const view = getCartesianView(context, yField);
|
|
302
|
+
if (!plot || !view) {
|
|
303
|
+
hideCrosshairs();
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const yScale = getYScale(view, yField);
|
|
307
|
+
const verticalRule = getRuleLine(plot.ruleY);
|
|
308
|
+
const horizontalRule = getRuleLine(plot.ruleX);
|
|
309
|
+
if (!verticalRule || !horizontalRule) {
|
|
310
|
+
hideCrosshairs();
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const [plotX, plotY] = getPlotOffset(plot);
|
|
314
|
+
const eventY = Number(event.offsetY ?? event.canvasY);
|
|
315
|
+
const globalY = Number.isFinite(eventY) ? eventY : latestPointerY;
|
|
316
|
+
const pointerY = Number.isFinite(globalY) ? Number(globalY) - plotY : horizontalRule.y1;
|
|
317
|
+
const x = clamp(verticalRule.x1, horizontalRule.x1, horizontalRule.x2);
|
|
318
|
+
const y = clamp(pointerY, verticalRule.y1, verticalRule.y2);
|
|
319
|
+
const invertedPosition = invertCoordinate(view, [x, y]);
|
|
320
|
+
const xValue = latestXValue ?? invertCrosshairValue(view.scale.x, invertedPosition == null ? void 0 : invertedPosition[0]);
|
|
321
|
+
const yValue = invertCrosshairValue(yScale, invertedPosition == null ? void 0 : invertedPosition[1]) ?? ((_c = (_b = (_a = event.data) == null ? void 0 : _a.items) == null ? void 0 : _b[0]) == null ? void 0 : _c.value);
|
|
322
|
+
const xText = formatCrosshairAxisValue(xValue, (_e = (_d = view.scale.x).getFormatter) == null ? void 0 : _e.call(_d));
|
|
323
|
+
const yText = formatCrosshairAxisValue(
|
|
324
|
+
yValue,
|
|
325
|
+
(_f = yScale == null ? void 0 : yScale.getFormatter) == null ? void 0 : _f.call(yScale),
|
|
326
|
+
getCrosshairScalePrecision(yScale)
|
|
327
|
+
);
|
|
328
|
+
if (!xText || !yText) {
|
|
329
|
+
hideCrosshairs();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if ((_g = plot.ruleY) == null ? void 0 : _g.style) {
|
|
333
|
+
plot.ruleY.style.x1 = x;
|
|
334
|
+
plot.ruleY.style.x2 = x;
|
|
335
|
+
}
|
|
336
|
+
if ((_h = plot.ruleX) == null ? void 0 : _h.style) {
|
|
337
|
+
plot.ruleX.style.y1 = y;
|
|
338
|
+
plot.ruleX.style.y2 = y;
|
|
339
|
+
}
|
|
340
|
+
const displayVerticalRule = { ...verticalRule, x1: x, x2: x };
|
|
341
|
+
const displayHorizontalRule = { ...horizontalRule, y1: y, y2: y };
|
|
342
|
+
ensureCrosshairs(plot, displayVerticalRule, displayHorizontalRule, xText, yText);
|
|
343
|
+
if (showXLabel && !xCrosshair || (useStandaloneYLabel ? !standaloneYTag : !yCrosshair && !standaloneYTag))
|
|
344
|
+
return;
|
|
345
|
+
if (xCrosshair) {
|
|
346
|
+
xCrosshair.setText(xText);
|
|
347
|
+
xCrosshair.setPointer([x + plotX, verticalRule.y2 + plotY]);
|
|
348
|
+
xCrosshair.style.visibility = "visible";
|
|
349
|
+
}
|
|
350
|
+
if (yCrosshair) {
|
|
351
|
+
yCrosshair.setText(yText);
|
|
352
|
+
yCrosshair.setPointer([
|
|
353
|
+
(yAxisPosition === "right" ? horizontalRule.x2 : horizontalRule.x1) + plotX,
|
|
354
|
+
y + plotY
|
|
355
|
+
]);
|
|
356
|
+
yCrosshair.style.visibility = "visible";
|
|
357
|
+
}
|
|
358
|
+
if (standaloneYTag) {
|
|
359
|
+
const yAxisX = getYAxisLinePosition(
|
|
360
|
+
view,
|
|
361
|
+
yField,
|
|
362
|
+
yAxisPosition,
|
|
363
|
+
yAxisPosition === "right" ? horizontalRule.x2 : horizontalRule.x1,
|
|
364
|
+
plotX
|
|
365
|
+
);
|
|
366
|
+
standaloneYTag.update({ text: yText });
|
|
367
|
+
standaloneYTag.setLocalPosition([yAxisX + plotX, y + plotY]);
|
|
368
|
+
standaloneYTag.style.visibility = "visible";
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
const onPointerMove = (event) => {
|
|
372
|
+
const y = Number(event.offsetY ?? event.canvasY);
|
|
373
|
+
if (Number.isFinite(y))
|
|
374
|
+
latestPointerY = y;
|
|
375
|
+
updateCrosshairs(event);
|
|
376
|
+
};
|
|
377
|
+
const onTooltipShow = (event) => {
|
|
378
|
+
var _a, _b;
|
|
379
|
+
if (!event.nativeEvent)
|
|
380
|
+
return;
|
|
381
|
+
if (((_b = (_a = event.data) == null ? void 0 : _a.data) == null ? void 0 : _b.x) !== void 0)
|
|
382
|
+
latestXValue = event.data.data.x;
|
|
383
|
+
updateCrosshairs(event);
|
|
384
|
+
};
|
|
385
|
+
chart.on("tooltip:show", onTooltipShow);
|
|
386
|
+
chart.on("tooltip:hide", resetCrosshairs);
|
|
387
|
+
chart.on("plot:pointermove", onPointerMove);
|
|
388
|
+
chart.on("plot:pointerleave", resetCrosshairs);
|
|
389
|
+
return () => {
|
|
390
|
+
var _a, _b, _c, _d;
|
|
391
|
+
(_a = chart.off) == null ? void 0 : _a.call(chart, "tooltip:show", onTooltipShow);
|
|
392
|
+
(_b = chart.off) == null ? void 0 : _b.call(chart, "tooltip:hide", resetCrosshairs);
|
|
393
|
+
(_c = chart.off) == null ? void 0 : _c.call(chart, "plot:pointermove", onPointerMove);
|
|
394
|
+
(_d = chart.off) == null ? void 0 : _d.call(chart, "plot:pointerleave", resetCrosshairs);
|
|
395
|
+
destroyCrosshairs();
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
399
|
+
0 && (module.exports = {
|
|
400
|
+
bindCrosshairAxisLabels
|
|
401
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const escapeHtml: (value: unknown) => string;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/html.ts
|
|
20
|
+
var html_exports = {};
|
|
21
|
+
__export(html_exports, {
|
|
22
|
+
escapeHtml: () => escapeHtml
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(html_exports);
|
|
25
|
+
var escapeHtml = (value) => (value == null ? "" : String(value)).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
escapeHtml
|
|
29
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/util/index.ts
|
|
17
|
+
var util_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(util_exports);
|
|
19
|
+
__reExport(util_exports, require("./animation"), module.exports);
|
|
20
|
+
__reExport(util_exports, require("./components"), module.exports);
|
|
21
|
+
__reExport(util_exports, require("./crosshair-axis-labels"), module.exports);
|
|
22
|
+
__reExport(util_exports, require("./interaction"), module.exports);
|
|
23
|
+
__reExport(util_exports, require("./theme"), module.exports);
|
|
24
|
+
__reExport(util_exports, require("./tokens"), module.exports);
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
...require("./animation"),
|
|
28
|
+
...require("./components"),
|
|
29
|
+
...require("./crosshair-axis-labels"),
|
|
30
|
+
...require("./interaction"),
|
|
31
|
+
...require("./theme"),
|
|
32
|
+
...require("./tokens")
|
|
33
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { VisualizationTheme } from '../types';
|
|
2
|
+
export type SharedTooltipInteractionOptions = {
|
|
3
|
+
crosshairs?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type PointHighlightStateOptions = {
|
|
6
|
+
activeLineWidth?: number;
|
|
7
|
+
inactiveOpacity?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const getSharedTooltipInteraction: ({ crosshairs, }?: SharedTooltipInteractionOptions) => Record<string, boolean>;
|
|
10
|
+
export declare const getCategoryBackgroundHighlightState: (theme: VisualizationTheme) => Record<string, any>;
|
|
11
|
+
export declare const getCategoryHighlightInteraction: () => Record<string, any>;
|
|
12
|
+
export declare const getPointHighlightState: ({ activeLineWidth, inactiveOpacity, }?: PointHighlightStateOptions) => Record<string, any>;
|
|
13
|
+
export declare const getSeriesHighlightByColorInteraction: () => Record<string, boolean>;
|
|
14
|
+
export declare const getLineHighlightState: (lineWidth: number) => Record<string, any>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/util/interaction.ts
|
|
20
|
+
var interaction_exports = {};
|
|
21
|
+
__export(interaction_exports, {
|
|
22
|
+
getCategoryBackgroundHighlightState: () => getCategoryBackgroundHighlightState,
|
|
23
|
+
getCategoryHighlightInteraction: () => getCategoryHighlightInteraction,
|
|
24
|
+
getLineHighlightState: () => getLineHighlightState,
|
|
25
|
+
getPointHighlightState: () => getPointHighlightState,
|
|
26
|
+
getSeriesHighlightByColorInteraction: () => getSeriesHighlightByColorInteraction,
|
|
27
|
+
getSharedTooltipInteraction: () => getSharedTooltipInteraction
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(interaction_exports);
|
|
30
|
+
var import_tokens = require("./tokens");
|
|
31
|
+
var getSharedTooltipInteraction = ({
|
|
32
|
+
crosshairs = false
|
|
33
|
+
} = {}) => ({
|
|
34
|
+
shared: true,
|
|
35
|
+
series: true,
|
|
36
|
+
crosshairs
|
|
37
|
+
});
|
|
38
|
+
var getCategoryBackgroundHighlightState = (theme) => {
|
|
39
|
+
const tokens = (0, import_tokens.getChartVisualTokens)(theme);
|
|
40
|
+
return {
|
|
41
|
+
active: {
|
|
42
|
+
backgroundFill: tokens.grid,
|
|
43
|
+
backgroundFillOpacity: theme === "dark" ? 0.56 : 0.58,
|
|
44
|
+
backgroundLineWidth: 0,
|
|
45
|
+
backgroundPadding: 0.08,
|
|
46
|
+
backgroundRadius: 4
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
var getCategoryHighlightInteraction = () => ({
|
|
51
|
+
background: true,
|
|
52
|
+
region: true
|
|
53
|
+
});
|
|
54
|
+
var getPointHighlightState = ({
|
|
55
|
+
activeLineWidth = import_tokens.CHART_STYLE_DEFAULTS.pointActiveLineWidth,
|
|
56
|
+
inactiveOpacity
|
|
57
|
+
} = {}) => ({
|
|
58
|
+
active: {
|
|
59
|
+
lineWidth: activeLineWidth,
|
|
60
|
+
stroke: (_datum, _index, _data, element) => {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
return ((_a = element == null ? void 0 : element.style) == null ? void 0 : _a.fill) || ((_b = element == null ? void 0 : element.style) == null ? void 0 : _b.stroke);
|
|
63
|
+
},
|
|
64
|
+
fillOpacity: 1,
|
|
65
|
+
zIndex: 10
|
|
66
|
+
},
|
|
67
|
+
...inactiveOpacity === void 0 ? {} : {
|
|
68
|
+
inactive: {
|
|
69
|
+
fillOpacity: inactiveOpacity,
|
|
70
|
+
strokeOpacity: inactiveOpacity
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
var getSeriesHighlightByColorInteraction = () => ({
|
|
75
|
+
elementHighlightByColor: true
|
|
76
|
+
});
|
|
77
|
+
var getLineHighlightState = (lineWidth) => ({
|
|
78
|
+
active: { lineWidth: lineWidth + 1, strokeOpacity: 1 },
|
|
79
|
+
inactive: { strokeOpacity: import_tokens.CHART_STYLE_DEFAULTS.inactiveOpacity }
|
|
80
|
+
});
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
getCategoryBackgroundHighlightState,
|
|
84
|
+
getCategoryHighlightInteraction,
|
|
85
|
+
getLineHighlightState,
|
|
86
|
+
getPointHighlightState,
|
|
87
|
+
getSeriesHighlightByColorInteraction,
|
|
88
|
+
getSharedTooltipInteraction
|
|
89
|
+
});
|
package/dist/cjs/util/theme.d.ts
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
+
import type { Theme } from '@antv/g2';
|
|
2
|
+
import type { VisualizationTheme } from '../types';
|
|
1
3
|
export declare const DEFAULT_COLOR_PALETTE: string[];
|
|
2
4
|
export declare const ACADEMY_COLOR_PALETTE: string[];
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export declare const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export declare const
|
|
18
|
-
|
|
19
|
-
* Get background color based on theme.
|
|
20
|
-
*/
|
|
21
|
-
export declare const getBackgroundColor: (theme: string) => string;
|
|
22
|
-
/**
|
|
23
|
-
* Normalize palette to always return an array.
|
|
24
|
-
* Handles the case where a single color is parsed as a string instead of an array.
|
|
25
|
-
*/
|
|
26
|
-
export declare const normalizePalette: (palette: string | string[] | undefined, theme: string) => string[];
|
|
5
|
+
type G2ThemeType = 'light' | 'dark' | 'academy';
|
|
6
|
+
type ChartTheme = Theme & {
|
|
7
|
+
enter?: {
|
|
8
|
+
duration?: number;
|
|
9
|
+
easing?: string;
|
|
10
|
+
};
|
|
11
|
+
elementHighlightByColor?: Record<string, unknown>;
|
|
12
|
+
elementHoverScale?: Record<string, unknown>;
|
|
13
|
+
};
|
|
14
|
+
export declare const THEME_MAP: Record<VisualizationTheme, ChartTheme>;
|
|
15
|
+
export declare const getTheme: (theme: VisualizationTheme) => G2ThemeType;
|
|
16
|
+
export declare const getThemeObject: (theme: VisualizationTheme) => ChartTheme;
|
|
17
|
+
export declare const getThemeColors: (theme: VisualizationTheme) => string[];
|
|
18
|
+
export declare const getBackgroundColor: (theme: VisualizationTheme) => string;
|
|
19
|
+
export declare const normalizePalette: (palette: string | string[] | undefined, theme: VisualizationTheme) => string[];
|
|
20
|
+
export {};
|