@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.
Files changed (98) hide show
  1. package/README.md +153 -34
  2. package/README.zh-CN.md +153 -34
  3. package/dist/cjs/types/index.d.ts +2 -1
  4. package/dist/cjs/util/animation.d.ts +2 -0
  5. package/dist/cjs/util/animation.js +38 -0
  6. package/dist/cjs/util/components.d.ts +15 -0
  7. package/dist/cjs/util/components.js +94 -0
  8. package/dist/cjs/util/crosshair-axis-labels.d.ts +15 -0
  9. package/dist/cjs/util/crosshair-axis-labels.js +401 -0
  10. package/dist/cjs/util/html.d.ts +1 -0
  11. package/dist/cjs/util/html.js +29 -0
  12. package/dist/cjs/util/index.d.ts +6 -0
  13. package/dist/cjs/util/index.js +33 -0
  14. package/dist/cjs/util/interaction.d.ts +14 -0
  15. package/dist/cjs/util/interaction.js +89 -0
  16. package/dist/cjs/util/theme.d.ts +18 -24
  17. package/dist/cjs/util/theme.js +303 -120
  18. package/dist/cjs/util/tokens.d.ts +31 -0
  19. package/dist/cjs/util/tokens.js +98 -0
  20. package/dist/cjs/vis/area/index.d.ts +2 -2
  21. package/dist/cjs/vis/area/index.js +76 -31
  22. package/dist/cjs/vis/bar/index.d.ts +2 -2
  23. package/dist/cjs/vis/bar/index.js +22 -19
  24. package/dist/cjs/vis/boxplot/index.js +1 -4
  25. package/dist/cjs/vis/column/index.d.ts +2 -2
  26. package/dist/cjs/vis/column/index.js +28 -18
  27. package/dist/cjs/vis/dual-axes/index.d.ts +2 -2
  28. package/dist/cjs/vis/dual-axes/index.js +107 -34
  29. package/dist/cjs/vis/funnel/index.d.ts +3 -2
  30. package/dist/cjs/vis/funnel/index.js +171 -94
  31. package/dist/cjs/vis/histogram/index.js +1 -4
  32. package/dist/cjs/vis/line/index.d.ts +2 -2
  33. package/dist/cjs/vis/line/index.js +71 -31
  34. package/dist/cjs/vis/liquid/index.d.ts +2 -2
  35. package/dist/cjs/vis/liquid/index.js +41 -16
  36. package/dist/cjs/vis/pie/index.d.ts +2 -2
  37. package/dist/cjs/vis/pie/index.js +26 -16
  38. package/dist/cjs/vis/radar/index.d.ts +2 -2
  39. package/dist/cjs/vis/radar/index.js +21 -29
  40. package/dist/cjs/vis/sankey/index.js +1 -4
  41. package/dist/cjs/vis/scatter/index.d.ts +2 -2
  42. package/dist/cjs/vis/scatter/index.js +40 -17
  43. package/dist/cjs/vis/table/index.js +13 -5
  44. package/dist/cjs/vis/treemap/index.js +1 -4
  45. package/dist/cjs/vis/venn/index.js +1 -4
  46. package/dist/cjs/vis/violin/index.js +1 -1
  47. package/dist/cjs/vis/waterfall/index.js +1 -1
  48. package/dist/cjs/vis/word-cloud/index.d.ts +3 -2
  49. package/dist/cjs/vis/word-cloud/index.js +125 -10
  50. package/dist/esm/types/index.d.ts +2 -1
  51. package/dist/esm/util/animation.d.ts +2 -0
  52. package/dist/esm/util/animation.js +17 -0
  53. package/dist/esm/util/components.d.ts +15 -0
  54. package/dist/esm/util/components.js +67 -0
  55. package/dist/esm/util/crosshair-axis-labels.d.ts +15 -0
  56. package/dist/esm/util/crosshair-axis-labels.js +431 -0
  57. package/dist/esm/util/html.d.ts +1 -0
  58. package/dist/esm/util/html.js +3 -0
  59. package/dist/esm/util/index.d.ts +6 -0
  60. package/dist/esm/util/index.js +6 -0
  61. package/dist/esm/util/interaction.d.ts +14 -0
  62. package/dist/esm/util/interaction.js +73 -0
  63. package/dist/esm/util/theme.d.ts +18 -24
  64. package/dist/esm/util/theme.js +302 -126
  65. package/dist/esm/util/tokens.d.ts +31 -0
  66. package/dist/esm/util/tokens.js +64 -0
  67. package/dist/esm/vis/area/index.d.ts +2 -2
  68. package/dist/esm/vis/area/index.js +91 -41
  69. package/dist/esm/vis/bar/index.d.ts +2 -2
  70. package/dist/esm/vis/bar/index.js +28 -29
  71. package/dist/esm/vis/boxplot/index.js +4 -5
  72. package/dist/esm/vis/column/index.d.ts +2 -2
  73. package/dist/esm/vis/column/index.js +36 -29
  74. package/dist/esm/vis/dual-axes/index.d.ts +2 -2
  75. package/dist/esm/vis/dual-axes/index.js +145 -42
  76. package/dist/esm/vis/funnel/index.d.ts +3 -2
  77. package/dist/esm/vis/funnel/index.js +159 -85
  78. package/dist/esm/vis/histogram/index.js +4 -5
  79. package/dist/esm/vis/line/index.d.ts +2 -2
  80. package/dist/esm/vis/line/index.js +80 -37
  81. package/dist/esm/vis/liquid/index.d.ts +2 -2
  82. package/dist/esm/vis/liquid/index.js +41 -14
  83. package/dist/esm/vis/pie/index.d.ts +2 -2
  84. package/dist/esm/vis/pie/index.js +36 -16
  85. package/dist/esm/vis/radar/index.d.ts +2 -2
  86. package/dist/esm/vis/radar/index.js +21 -34
  87. package/dist/esm/vis/sankey/index.js +4 -5
  88. package/dist/esm/vis/scatter/index.d.ts +2 -2
  89. package/dist/esm/vis/scatter/index.js +41 -25
  90. package/dist/esm/vis/table/index.js +9 -9
  91. package/dist/esm/vis/treemap/index.js +4 -5
  92. package/dist/esm/vis/venn/index.js +4 -5
  93. package/dist/esm/vis/violin/index.js +5 -13
  94. package/dist/esm/vis/waterfall/index.js +5 -7
  95. package/dist/esm/vis/word-cloud/index.d.ts +3 -2
  96. package/dist/esm/vis/word-cloud/index.js +158 -10
  97. package/dist/umd/index.min.js +1 -1
  98. package/package.json +18 -15
@@ -0,0 +1,17 @@
1
+ var prefersReducedMotion = function prefersReducedMotion() {
2
+ return typeof window !== 'undefined' && typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
3
+ };
4
+ export var getChartAnimation = function getChartAnimation(hasRendered, enterType) {
5
+ if (hasRendered || prefersReducedMotion()) return false;
6
+ return {
7
+ enter: enterType ? {
8
+ type: enterType
9
+ } : {},
10
+ update: {
11
+ type: null
12
+ },
13
+ exit: {
14
+ type: null
15
+ }
16
+ };
17
+ };
@@ -0,0 +1,15 @@
1
+ export type ChartLocale = 'en-US' | 'zh-CN';
2
+ export type CartesianXAxisOptions = {
3
+ xLabels?: unknown[];
4
+ chartWidth?: number;
5
+ };
6
+ export type CartesianAxisOptions = CartesianXAxisOptions & {
7
+ axisXTitle?: string | false;
8
+ axisYTitle?: string | false;
9
+ };
10
+ export declare const resolveChartLocale: (locale?: string) => ChartLocale;
11
+ export declare const getCartesianLayout: ({ xLabels, chartWidth, }: CartesianXAxisOptions) => Record<string, number>;
12
+ export declare const getCartesianAxis: ({ axisXTitle, axisYTitle, xLabels, chartWidth, }: CartesianAxisOptions) => Record<'x' | 'y', Record<string, unknown>>;
13
+ export declare const getColorLegend: (visible: boolean) => false | {
14
+ color: Record<string, never>;
15
+ };
@@ -0,0 +1,67 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
+ var DEFAULT_CHART_WIDTH = 640;
8
+ var AXIS_HORIZONTAL_PADDING = 96;
9
+ var ANGLED_LABEL_MARGIN_RIGHT_MIN = 32;
10
+ var ANGLED_LABEL_MARGIN_RIGHT_MAX = 64;
11
+ var ANGLED_LABEL_EDGE_GAP = 8;
12
+ var estimateLabelWidth = function estimateLabelWidth(value) {
13
+ return Array.from(String(value !== null && value !== void 0 ? value : '')).reduce(function (width, character) {
14
+ var _character$codePointA;
15
+ return width + (((_character$codePointA = character.codePointAt(0)) !== null && _character$codePointA !== void 0 ? _character$codePointA : 0) > 0xff ? 12 : 7);
16
+ }, 0);
17
+ };
18
+ var shouldUseAngledXAxisLabels = function shouldUseAngledXAxisLabels(labels) {
19
+ var chartWidth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_CHART_WIDTH;
20
+ if (!(labels !== null && labels !== void 0 && labels.length)) return false;
21
+ var uniqueLabels = Array.from(new Set(labels.map(function (label) {
22
+ return String(label !== null && label !== void 0 ? label : '');
23
+ })));
24
+ if (uniqueLabels.length <= 1) return false;
25
+ var availableWidth = Math.max(chartWidth - AXIS_HORIZONTAL_PADDING, 240);
26
+ var estimatedWidth = uniqueLabels.reduce(function (total, label) {
27
+ return total + Math.max(28, estimateLabelWidth(label) + 16);
28
+ }, 0);
29
+ return estimatedWidth > availableWidth;
30
+ };
31
+ export var resolveChartLocale = function resolveChartLocale(locale) {
32
+ return locale !== null && locale !== void 0 && locale.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en-US';
33
+ };
34
+ export var getCartesianLayout = function getCartesianLayout(_ref) {
35
+ var xLabels = _ref.xLabels,
36
+ chartWidth = _ref.chartWidth;
37
+ if (!shouldUseAngledXAxisLabels(xLabels, chartWidth)) return {};
38
+ var tailLabel = xLabels === null || xLabels === void 0 ? void 0 : xLabels[xLabels.length - 1];
39
+ var labelWidth = estimateLabelWidth(tailLabel);
40
+ var projectedHalfWidth = (labelWidth + 12) * Math.SQRT1_2 / 2;
41
+ return {
42
+ marginRight: Math.min(ANGLED_LABEL_MARGIN_RIGHT_MAX, Math.max(ANGLED_LABEL_MARGIN_RIGHT_MIN, Math.ceil(projectedHalfWidth + ANGLED_LABEL_EDGE_GAP)))
43
+ };
44
+ };
45
+ export var getCartesianAxis = function getCartesianAxis(_ref2) {
46
+ var axisXTitle = _ref2.axisXTitle,
47
+ axisYTitle = _ref2.axisYTitle,
48
+ xLabels = _ref2.xLabels,
49
+ chartWidth = _ref2.chartWidth;
50
+ var useAngledXAxisLabels = shouldUseAngledXAxisLabels(xLabels, chartWidth);
51
+ return {
52
+ x: _objectSpread({
53
+ title: axisXTitle || false
54
+ }, useAngledXAxisLabels ? {
55
+ labelTransform: 'rotate(45)',
56
+ labelAutoRotate: false
57
+ } : {}),
58
+ y: {
59
+ title: axisYTitle || false
60
+ }
61
+ };
62
+ };
63
+ export var getColorLegend = function getColorLegend(visible) {
64
+ return visible ? {
65
+ color: {}
66
+ } : false;
67
+ };
@@ -0,0 +1,15 @@
1
+ import { type Chart } from '@antv/g2';
2
+ import type { VisualizationTheme } from '../types';
3
+ export type CrosshairAxisLabelsOptions = {
4
+ showXLabel?: boolean;
5
+ useStandaloneYLabel?: boolean;
6
+ yAxisPosition?: 'left' | 'right';
7
+ yField?: string;
8
+ };
9
+ /**
10
+ * Bridges G2 tooltip crosshairs to axis value tags.
11
+ *
12
+ * G2 does not currently expose axis tags for tooltip crosshairs, so this adapter
13
+ * reads the rule geometry created by G2 5.4 and renders labels with LineCrosshair.
14
+ */
15
+ export declare const bindCrosshairAxisLabels: (chart: Chart, theme: VisualizationTheme, { showXLabel, useStandaloneYLabel, yAxisPosition, yField, }?: CrosshairAxisLabelsOptions) => (() => void);
@@ -0,0 +1,431 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ 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; } }
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+ import { LineCrosshair, Tag } from '@antv/component';
15
+ import { selectPlotArea } from '@antv/g2';
16
+ import { CHART_FONT_FAMILY, getChartVisualTokens } from "./tokens";
17
+ var MAX_CROSSHAIR_DECIMAL_PLACES = 6;
18
+ var formatCrosshairAxisValue = function formatCrosshairAxisValue(value, formatter, precision) {
19
+ if (value === undefined || value === null || value === '') return '';
20
+ var displayValue = value;
21
+ try {
22
+ var formatted = formatter === null || formatter === void 0 ? void 0 : formatter(value);
23
+ if (formatted !== undefined && formatted !== null) {
24
+ var numericFormatted = typeof formatted === 'number' || typeof formatted === 'string' && formatted.trim() !== '' && Number.isFinite(Number(formatted)) ? Number(formatted) : undefined;
25
+ if (numericFormatted === undefined) return String(formatted);
26
+ displayValue = numericFormatted;
27
+ }
28
+ } catch (_unused) {
29
+ // Fall back to the original value when a scale formatter rejects it.
30
+ }
31
+ if (displayValue instanceof Date) return displayValue.toLocaleString();
32
+ if (typeof displayValue === 'number' && Number.isFinite(displayValue)) {
33
+ if (displayValue !== 0 && Math.abs(displayValue) < Math.pow(10, -MAX_CROSSHAIR_DECIMAL_PLACES)) {
34
+ return Number(displayValue.toPrecision(4)).toString();
35
+ }
36
+ var decimalPlaces = Math.min(Math.max(precision !== null && precision !== void 0 ? precision : MAX_CROSSHAIR_DECIMAL_PLACES, 0), MAX_CROSSHAIR_DECIMAL_PLACES);
37
+ return Number(displayValue.toFixed(decimalPlaces)).toString();
38
+ }
39
+ return String(displayValue);
40
+ };
41
+ var getNumberPrecision = function getNumberPrecision(value) {
42
+ var _coefficient$split$;
43
+ if (!Number.isFinite(value) || value === 0) return 0;
44
+ var normalizedValue = Number(value.toPrecision(12));
45
+ var _Math$abs$toExponenti = Math.abs(normalizedValue).toExponential().split('e'),
46
+ _Math$abs$toExponenti2 = _slicedToArray(_Math$abs$toExponenti, 2),
47
+ coefficient = _Math$abs$toExponenti2[0],
48
+ _Math$abs$toExponenti3 = _Math$abs$toExponenti2[1],
49
+ exponentText = _Math$abs$toExponenti3 === void 0 ? '0' : _Math$abs$toExponenti3;
50
+ var coefficientPrecision = ((_coefficient$split$ = coefficient.split('.')[1]) === null || _coefficient$split$ === void 0 ? void 0 : _coefficient$split$.length) || 0;
51
+ return Math.max(0, coefficientPrecision - Number(exponentText));
52
+ };
53
+ var getCrosshairScalePrecision = function getCrosshairScalePrecision(scale) {
54
+ var _scale$getTicks;
55
+ var ticks = scale === null || scale === void 0 || (_scale$getTicks = scale.getTicks) === null || _scale$getTicks === void 0 ? void 0 : _scale$getTicks.call(scale);
56
+ if (!Array.isArray(ticks) || ticks.length < 2) return undefined;
57
+ var interval = Number.POSITIVE_INFINITY;
58
+ for (var index = 1; index < ticks.length; index += 1) {
59
+ var current = Number(ticks[index]);
60
+ var previous = Number(ticks[index - 1]);
61
+ var difference = Math.abs(current - previous);
62
+ if (Number.isFinite(difference) && difference > 0) interval = Math.min(interval, difference);
63
+ }
64
+ if (!Number.isFinite(interval)) return undefined;
65
+ return Math.min(getNumberPrecision(interval) + 2, MAX_CROSSHAIR_DECIMAL_PLACES);
66
+ };
67
+ var getCrosshairTagStyle = function getCrosshairTagStyle(theme, tokens) {
68
+ return {
69
+ lineLineWidth: 0,
70
+ lineStrokeOpacity: 0,
71
+ linePointerEvents: 'none',
72
+ tagPadding: [4, 7],
73
+ tagRadius: 6,
74
+ tagBackgroundFill: tokens.textPrimary,
75
+ tagBackgroundStroke: 'transparent',
76
+ tagBackgroundLineWidth: 0,
77
+ tagBackgroundShadowColor: theme === 'dark' ? 'rgba(0, 0, 0, 0.38)' : 'rgba(15, 23, 42, 0.18)',
78
+ tagBackgroundShadowBlur: 8,
79
+ tagBackgroundShadowOffsetY: 2,
80
+ tagLabelFill: tokens.background,
81
+ tagLabelFillOpacity: 1,
82
+ tagLabelFontFamily: CHART_FONT_FAMILY,
83
+ tagLabelFontSize: 11,
84
+ tagLabelFontWeight: 500,
85
+ tagLabelLineWidth: 0,
86
+ tagPointerEvents: 'none'
87
+ };
88
+ };
89
+ var getStandaloneTagStyle = function getStandaloneTagStyle(theme, tokens) {
90
+ return {
91
+ align: 'start',
92
+ verticalAlign: 'middle',
93
+ padding: [4, 7],
94
+ radius: 6,
95
+ backgroundFill: tokens.textPrimary,
96
+ backgroundStroke: 'transparent',
97
+ backgroundLineWidth: 0,
98
+ backgroundShadowColor: theme === 'dark' ? 'rgba(0, 0, 0, 0.38)' : 'rgba(15, 23, 42, 0.18)',
99
+ backgroundShadowBlur: 8,
100
+ backgroundShadowOffsetY: 2,
101
+ labelFill: tokens.background,
102
+ labelFillOpacity: 1,
103
+ labelFontFamily: CHART_FONT_FAMILY,
104
+ labelFontSize: 11,
105
+ labelFontWeight: 500,
106
+ labelLineWidth: 0,
107
+ pointerEvents: 'none'
108
+ };
109
+ };
110
+ var clamp = function clamp(value, min, max) {
111
+ return Math.min(Math.max(value, Math.min(min, max)), Math.max(min, max));
112
+ };
113
+ var invertCrosshairValue = function invertCrosshairValue(scale, value) {
114
+ if (!scale || typeof scale.invert !== 'function' || value === undefined) return undefined;
115
+ if (typeof scale.getBandWidth === 'function') {
116
+ var _scale$getOptions;
117
+ var domain = (_scale$getOptions = scale.getOptions) === null || _scale$getOptions === void 0 || (_scale$getOptions = _scale$getOptions.call(scale)) === null || _scale$getOptions === void 0 ? void 0 : _scale$getOptions.domain;
118
+ if (!Array.isArray(domain) || domain.length === 0 || !Number.isFinite(Number(value))) {
119
+ return undefined;
120
+ }
121
+ var nearestValue = domain[0];
122
+ var nearestDistance = Number.POSITIVE_INFINITY;
123
+ var _iterator = _createForOfIteratorHelper(domain),
124
+ _step;
125
+ try {
126
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
127
+ var _scale$map;
128
+ var domainValue = _step.value;
129
+ var start = Number((_scale$map = scale.map) === null || _scale$map === void 0 ? void 0 : _scale$map.call(scale, domainValue));
130
+ var bandWidth = Number(scale.getBandWidth(domainValue)) || 0;
131
+ var distance = Math.abs(start + bandWidth / 2 - Number(value));
132
+ if (Number.isFinite(distance) && distance < nearestDistance) {
133
+ nearestValue = domainValue;
134
+ nearestDistance = distance;
135
+ }
136
+ }
137
+ } catch (err) {
138
+ _iterator.e(err);
139
+ } finally {
140
+ _iterator.f();
141
+ }
142
+ return nearestValue;
143
+ }
144
+ try {
145
+ return scale.invert(value);
146
+ } catch (_unused2) {
147
+ return undefined;
148
+ }
149
+ };
150
+ var getTooltipPlot = function getTooltipPlot(context) {
151
+ var _context$canvas;
152
+ var root = (_context$canvas = context.canvas) === null || _context$canvas === void 0 ? void 0 : _context$canvas.getRoot();
153
+ if (!root) return undefined;
154
+
155
+ // G2 5.4 stores tooltip rules on the plot display object. Keep that version-specific
156
+ // detail isolated here while using the public plot selector for discovery.
157
+ return selectPlotArea(root);
158
+ };
159
+ var getScaleField = function getScaleField(scale) {
160
+ var _scale$getOptions2;
161
+ return scale === null || scale === void 0 || (_scale$getOptions2 = scale.getOptions) === null || _scale$getOptions2 === void 0 || (_scale$getOptions2 = _scale$getOptions2.call(scale)) === null || _scale$getOptions2 === void 0 ? void 0 : _scale$getOptions2.field;
162
+ };
163
+ var findYScaleByField = function findYScaleByField(view, yField) {
164
+ var _Object$entries$find;
165
+ return (_Object$entries$find = Object.entries(view.scale).find(function (_ref) {
166
+ var _ref2 = _slicedToArray(_ref, 2),
167
+ scaleName = _ref2[0],
168
+ scale = _ref2[1];
169
+ return /^y\d*$/.test(scaleName) && getScaleField(scale) === yField;
170
+ })) === null || _Object$entries$find === void 0 ? void 0 : _Object$entries$find[1];
171
+ };
172
+ var getYScale = function getYScale(view, yField) {
173
+ return yField ? findYScaleByField(view, yField) : view.scale.y;
174
+ };
175
+ var getCartesianView = function getCartesianView(context, yField) {
176
+ var _context$views;
177
+ return (_context$views = context.views) === null || _context$views === void 0 ? void 0 : _context$views.find(function (view) {
178
+ var _view$scale, _view$coordinate;
179
+ return Boolean(((_view$scale = view.scale) === null || _view$scale === void 0 ? void 0 : _view$scale.x) && getYScale(view, yField)) && typeof ((_view$coordinate = view.coordinate) === null || _view$coordinate === void 0 ? void 0 : _view$coordinate.invert) === 'function';
180
+ });
181
+ };
182
+ var hasAxisField = function hasAxisField(field, yField) {
183
+ return Array.isArray(field) ? field.includes(yField) : field === yField;
184
+ };
185
+ var getYAxisLinePosition = function getYAxisLinePosition(view, yField, position, fallback, plotX) {
186
+ var _view$components;
187
+ if (!yField) return fallback;
188
+ var axis = (_view$components = view.components) === null || _view$components === void 0 ? void 0 : _view$components.find(function (_ref3) {
189
+ var bbox = _ref3.bbox,
190
+ axisPosition = _ref3.position,
191
+ scales = _ref3.scales,
192
+ type = _ref3.type;
193
+ return type === 'axisY' && axisPosition === position && Number.isFinite(Number(bbox === null || bbox === void 0 ? void 0 : bbox.x)) && (scales === null || scales === void 0 ? void 0 : scales.some(function (scale) {
194
+ return hasAxisField(scale.field, yField);
195
+ }));
196
+ });
197
+ if (!(axis !== null && axis !== void 0 && axis.bbox)) return fallback;
198
+ var x = Number(axis.bbox.x);
199
+ var width = Number(axis.bbox.width);
200
+ var axisX = position === 'right' || !Number.isFinite(width) ? x : x + width;
201
+ return axisX - plotX;
202
+ };
203
+ var getRuleLine = function getRuleLine(rule) {
204
+ var _rule$style, _rule$style2, _rule$style3, _rule$style4;
205
+ var x1 = Number(rule === null || rule === void 0 || (_rule$style = rule.style) === null || _rule$style === void 0 ? void 0 : _rule$style.x1);
206
+ var x2 = Number(rule === null || rule === void 0 || (_rule$style2 = rule.style) === null || _rule$style2 === void 0 ? void 0 : _rule$style2.x2);
207
+ var y1 = Number(rule === null || rule === void 0 || (_rule$style3 = rule.style) === null || _rule$style3 === void 0 ? void 0 : _rule$style3.y1);
208
+ var y2 = Number(rule === null || rule === void 0 || (_rule$style4 = rule.style) === null || _rule$style4 === void 0 ? void 0 : _rule$style4.y2);
209
+ if (![x1, x2, y1, y2].every(Number.isFinite)) return undefined;
210
+ return {
211
+ x1: x1,
212
+ x2: x2,
213
+ y1: y1,
214
+ y2: y2
215
+ };
216
+ };
217
+ var getPlotOffset = function getPlotOffset(plot) {
218
+ var _plot$getLocalPositio;
219
+ var _ref4 = ((_plot$getLocalPositio = plot.getLocalPosition) === null || _plot$getLocalPositio === void 0 ? void 0 : _plot$getLocalPositio.call(plot)) || [],
220
+ _ref5 = _slicedToArray(_ref4, 2),
221
+ _ref5$ = _ref5[0],
222
+ x = _ref5$ === void 0 ? 0 : _ref5$,
223
+ _ref5$2 = _ref5[1],
224
+ y = _ref5$2 === void 0 ? 0 : _ref5$2;
225
+ return [Number.isFinite(Number(x)) ? Number(x) : 0, Number.isFinite(Number(y)) ? Number(y) : 0];
226
+ };
227
+ var invertCoordinate = function invertCoordinate(view, point) {
228
+ try {
229
+ var inverted = view.coordinate.invert(point);
230
+ if (!Array.isArray(inverted) || inverted.length < 2) return undefined;
231
+ var x = Number(inverted[0]);
232
+ var y = Number(inverted[1]);
233
+ return Number.isFinite(x) && Number.isFinite(y) ? [x, y] : undefined;
234
+ } catch (_unused3) {
235
+ return undefined;
236
+ }
237
+ };
238
+
239
+ /**
240
+ * Bridges G2 tooltip crosshairs to axis value tags.
241
+ *
242
+ * G2 does not currently expose axis tags for tooltip crosshairs, so this adapter
243
+ * reads the rule geometry created by G2 5.4 and renders labels with LineCrosshair.
244
+ */
245
+ export var bindCrosshairAxisLabels = function bindCrosshairAxisLabels(chart, theme) {
246
+ var _ref6 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
247
+ _ref6$showXLabel = _ref6.showXLabel,
248
+ showXLabel = _ref6$showXLabel === void 0 ? true : _ref6$showXLabel,
249
+ _ref6$useStandaloneYL = _ref6.useStandaloneYLabel,
250
+ useStandaloneYLabel = _ref6$useStandaloneYL === void 0 ? false : _ref6$useStandaloneYL,
251
+ _ref6$yAxisPosition = _ref6.yAxisPosition,
252
+ yAxisPosition = _ref6$yAxisPosition === void 0 ? 'left' : _ref6$yAxisPosition,
253
+ yField = _ref6.yField;
254
+ if (!chart || typeof chart.on !== 'function') return function () {
255
+ return undefined;
256
+ };
257
+ var tagStyle = getCrosshairTagStyle(theme, getChartVisualTokens(theme));
258
+ var standaloneTagStyle = getStandaloneTagStyle(theme, getChartVisualTokens(theme));
259
+ var boundPlot = null;
260
+ var xCrosshair = null;
261
+ var yCrosshair = null;
262
+ var standaloneYTag = null;
263
+ var latestPointerY = null;
264
+ var latestXValue;
265
+ var destroyCrosshairs = function destroyCrosshairs() {
266
+ var _xCrosshair, _yCrosshair, _standaloneYTag;
267
+ (_xCrosshair = xCrosshair) === null || _xCrosshair === void 0 || _xCrosshair.destroy();
268
+ (_yCrosshair = yCrosshair) === null || _yCrosshair === void 0 || _yCrosshair.destroy();
269
+ (_standaloneYTag = standaloneYTag) === null || _standaloneYTag === void 0 || _standaloneYTag.destroy();
270
+ xCrosshair = null;
271
+ yCrosshair = null;
272
+ standaloneYTag = null;
273
+ boundPlot = null;
274
+ };
275
+ var hideCrosshairs = function hideCrosshairs() {
276
+ for (var _i = 0, _arr = [xCrosshair, yCrosshair, standaloneYTag]; _i < _arr.length; _i++) {
277
+ var crosshair = _arr[_i];
278
+ if (crosshair) crosshair.style.visibility = 'hidden';
279
+ }
280
+ };
281
+ var resetCrosshairs = function resetCrosshairs() {
282
+ latestPointerY = null;
283
+ latestXValue = undefined;
284
+ hideCrosshairs();
285
+ };
286
+ var ensureCrosshairs = function ensureCrosshairs(plot, xLine, yLine, xText, yText) {
287
+ if (boundPlot !== plot) destroyCrosshairs();
288
+ if (xCrosshair && yCrosshair) return;
289
+ var layer = plot.parentNode || plot;
290
+ var _getPlotOffset = getPlotOffset(plot),
291
+ _getPlotOffset2 = _slicedToArray(_getPlotOffset, 2),
292
+ plotX = _getPlotOffset2[0],
293
+ plotY = _getPlotOffset2[1];
294
+ var xStart = [xLine.x1 + plotX, xLine.y1 + plotY];
295
+ var xEnd = [xLine.x2 + plotX, xLine.y2 + plotY];
296
+ var yStart = [yLine.x1 + plotX, yLine.y1 + plotY];
297
+ var yEnd = [yLine.x2 + plotX, yLine.y2 + plotY];
298
+ if (showXLabel && !xCrosshair) {
299
+ xCrosshair = new LineCrosshair({
300
+ style: _objectSpread(_objectSpread({}, tagStyle), {}, {
301
+ startPos: xStart,
302
+ endPos: xEnd,
303
+ tagText: xText,
304
+ tagPosition: 'end'
305
+ })
306
+ });
307
+ xCrosshair.style.zIndex = 7;
308
+ xCrosshair.style.pointerEvents = 'none';
309
+ layer.appendChild(xCrosshair);
310
+ }
311
+ if (showXLabel && !useStandaloneYLabel && !yCrosshair) {
312
+ yCrosshair = new LineCrosshair({
313
+ style: _objectSpread(_objectSpread({}, tagStyle), {}, {
314
+ startPos: yStart,
315
+ endPos: yEnd,
316
+ tagText: yText,
317
+ tagPosition: yAxisPosition === 'right' ? 'end' : 'start'
318
+ })
319
+ });
320
+ yCrosshair.style.zIndex = 7;
321
+ yCrosshair.style.pointerEvents = 'none';
322
+ layer.appendChild(yCrosshair);
323
+ }
324
+ if ((useStandaloneYLabel || !showXLabel) && !standaloneYTag) {
325
+ standaloneYTag = new Tag({
326
+ style: _objectSpread(_objectSpread({}, standaloneTagStyle), {}, {
327
+ text: yText
328
+ })
329
+ });
330
+ standaloneYTag.style.zIndex = 7;
331
+ standaloneYTag.style.pointerEvents = 'none';
332
+ layer.appendChild(standaloneYTag);
333
+ }
334
+ boundPlot = plot;
335
+ };
336
+ var updateCrosshairs = function updateCrosshairs(event) {
337
+ var _event$offsetY, _latestXValue, _invertCrosshairValue, _event$data, _view$scale$x$getForm, _view$scale$x, _yScale$getFormatter, _plot$ruleY, _plot$ruleX;
338
+ var context = chart.getContext();
339
+ var plot = getTooltipPlot(context);
340
+ var view = getCartesianView(context, yField);
341
+ if (!plot || !view) {
342
+ hideCrosshairs();
343
+ return;
344
+ }
345
+ var yScale = getYScale(view, yField);
346
+ var verticalRule = getRuleLine(plot.ruleY);
347
+ var horizontalRule = getRuleLine(plot.ruleX);
348
+ if (!verticalRule || !horizontalRule) {
349
+ hideCrosshairs();
350
+ return;
351
+ }
352
+ var _getPlotOffset3 = getPlotOffset(plot),
353
+ _getPlotOffset4 = _slicedToArray(_getPlotOffset3, 2),
354
+ plotX = _getPlotOffset4[0],
355
+ plotY = _getPlotOffset4[1];
356
+ var eventY = Number((_event$offsetY = event.offsetY) !== null && _event$offsetY !== void 0 ? _event$offsetY : event.canvasY);
357
+ var globalY = Number.isFinite(eventY) ? eventY : latestPointerY;
358
+ var pointerY = Number.isFinite(globalY) ? Number(globalY) - plotY : horizontalRule.y1;
359
+ var x = clamp(verticalRule.x1, horizontalRule.x1, horizontalRule.x2);
360
+ var y = clamp(pointerY, verticalRule.y1, verticalRule.y2);
361
+ var invertedPosition = invertCoordinate(view, [x, y]);
362
+ var xValue = (_latestXValue = latestXValue) !== null && _latestXValue !== void 0 ? _latestXValue : invertCrosshairValue(view.scale.x, invertedPosition === null || invertedPosition === void 0 ? void 0 : invertedPosition[0]);
363
+ var yValue = (_invertCrosshairValue = invertCrosshairValue(yScale, invertedPosition === null || invertedPosition === void 0 ? void 0 : invertedPosition[1])) !== null && _invertCrosshairValue !== void 0 ? _invertCrosshairValue : (_event$data = event.data) === null || _event$data === void 0 || (_event$data = _event$data.items) === null || _event$data === void 0 || (_event$data = _event$data[0]) === null || _event$data === void 0 ? void 0 : _event$data.value;
364
+ var xText = formatCrosshairAxisValue(xValue, (_view$scale$x$getForm = (_view$scale$x = view.scale.x).getFormatter) === null || _view$scale$x$getForm === void 0 ? void 0 : _view$scale$x$getForm.call(_view$scale$x));
365
+ var yText = formatCrosshairAxisValue(yValue, yScale === null || yScale === void 0 || (_yScale$getFormatter = yScale.getFormatter) === null || _yScale$getFormatter === void 0 ? void 0 : _yScale$getFormatter.call(yScale), getCrosshairScalePrecision(yScale));
366
+ if (!xText || !yText) {
367
+ hideCrosshairs();
368
+ return;
369
+ }
370
+ if ((_plot$ruleY = plot.ruleY) !== null && _plot$ruleY !== void 0 && _plot$ruleY.style) {
371
+ plot.ruleY.style.x1 = x;
372
+ plot.ruleY.style.x2 = x;
373
+ }
374
+ if ((_plot$ruleX = plot.ruleX) !== null && _plot$ruleX !== void 0 && _plot$ruleX.style) {
375
+ plot.ruleX.style.y1 = y;
376
+ plot.ruleX.style.y2 = y;
377
+ }
378
+ var displayVerticalRule = _objectSpread(_objectSpread({}, verticalRule), {}, {
379
+ x1: x,
380
+ x2: x
381
+ });
382
+ var displayHorizontalRule = _objectSpread(_objectSpread({}, horizontalRule), {}, {
383
+ y1: y,
384
+ y2: y
385
+ });
386
+ ensureCrosshairs(plot, displayVerticalRule, displayHorizontalRule, xText, yText);
387
+ if (showXLabel && !xCrosshair || (useStandaloneYLabel ? !standaloneYTag : !yCrosshair && !standaloneYTag)) return;
388
+ if (xCrosshair) {
389
+ xCrosshair.setText(xText);
390
+ xCrosshair.setPointer([x + plotX, verticalRule.y2 + plotY]);
391
+ xCrosshair.style.visibility = 'visible';
392
+ }
393
+ if (yCrosshair) {
394
+ yCrosshair.setText(yText);
395
+ yCrosshair.setPointer([(yAxisPosition === 'right' ? horizontalRule.x2 : horizontalRule.x1) + plotX, y + plotY]);
396
+ yCrosshair.style.visibility = 'visible';
397
+ }
398
+ if (standaloneYTag) {
399
+ var yAxisX = getYAxisLinePosition(view, yField, yAxisPosition, yAxisPosition === 'right' ? horizontalRule.x2 : horizontalRule.x1, plotX);
400
+ standaloneYTag.update({
401
+ text: yText
402
+ });
403
+ standaloneYTag.setLocalPosition([yAxisX + plotX, y + plotY]);
404
+ standaloneYTag.style.visibility = 'visible';
405
+ }
406
+ };
407
+ var onPointerMove = function onPointerMove(event) {
408
+ var _event$offsetY2;
409
+ var y = Number((_event$offsetY2 = event.offsetY) !== null && _event$offsetY2 !== void 0 ? _event$offsetY2 : event.canvasY);
410
+ if (Number.isFinite(y)) latestPointerY = y;
411
+ updateCrosshairs(event);
412
+ };
413
+ var onTooltipShow = function onTooltipShow(event) {
414
+ var _event$data2;
415
+ if (!event.nativeEvent) return;
416
+ if (((_event$data2 = event.data) === null || _event$data2 === void 0 || (_event$data2 = _event$data2.data) === null || _event$data2 === void 0 ? void 0 : _event$data2.x) !== undefined) latestXValue = event.data.data.x;
417
+ updateCrosshairs(event);
418
+ };
419
+ chart.on('tooltip:show', onTooltipShow);
420
+ chart.on('tooltip:hide', resetCrosshairs);
421
+ chart.on('plot:pointermove', onPointerMove);
422
+ chart.on('plot:pointerleave', resetCrosshairs);
423
+ return function () {
424
+ var _chart$off, _chart$off2, _chart$off3, _chart$off4;
425
+ (_chart$off = chart.off) === null || _chart$off === void 0 || _chart$off.call(chart, 'tooltip:show', onTooltipShow);
426
+ (_chart$off2 = chart.off) === null || _chart$off2 === void 0 || _chart$off2.call(chart, 'tooltip:hide', resetCrosshairs);
427
+ (_chart$off3 = chart.off) === null || _chart$off3 === void 0 || _chart$off3.call(chart, 'plot:pointermove', onPointerMove);
428
+ (_chart$off4 = chart.off) === null || _chart$off4 === void 0 || _chart$off4.call(chart, 'plot:pointerleave', resetCrosshairs);
429
+ destroyCrosshairs();
430
+ };
431
+ };
@@ -0,0 +1 @@
1
+ export declare const escapeHtml: (value: unknown) => string;
@@ -0,0 +1,3 @@
1
+ export var escapeHtml = function escapeHtml(value) {
2
+ return (value == null ? '' : String(value)).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
3
+ };
@@ -0,0 +1,6 @@
1
+ export * from './animation';
2
+ export * from './components';
3
+ export * from './crosshair-axis-labels';
4
+ export * from './interaction';
5
+ export * from './theme';
6
+ export * from './tokens';
@@ -0,0 +1,6 @@
1
+ export * from "./animation";
2
+ export * from "./components";
3
+ export * from "./crosshair-axis-labels";
4
+ export * from "./interaction";
5
+ export * from "./theme";
6
+ export * from "./tokens";
@@ -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>;