@antv/gpt-vis 1.0.1 → 1.3.0

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 (172) hide show
  1. package/README.md +113 -36
  2. package/README.zh-CN.md +113 -36
  3. package/dist/cjs/index.d.ts +1 -1
  4. package/dist/cjs/theme/g2.d.ts +9 -0
  5. package/dist/cjs/theme/g2.js +605 -0
  6. package/dist/cjs/theme/g6.d.ts +28 -0
  7. package/dist/cjs/theme/g6.js +124 -0
  8. package/dist/cjs/theme/merge.d.ts +2 -0
  9. package/dist/cjs/theme/merge.js +49 -0
  10. package/dist/cjs/theme/resolve.d.ts +7 -0
  11. package/dist/cjs/theme/resolve.js +58 -0
  12. package/dist/cjs/theme/shared.d.ts +7 -0
  13. package/dist/cjs/theme/shared.js +61 -0
  14. package/dist/cjs/theme/summary.d.ts +11 -0
  15. package/dist/cjs/theme/summary.js +61 -0
  16. package/dist/cjs/theme/table.d.ts +13 -0
  17. package/dist/cjs/theme/table.js +121 -0
  18. package/dist/cjs/types/index.d.ts +8 -5
  19. package/dist/cjs/types/theme.d.ts +107 -0
  20. package/dist/cjs/types/theme.js +17 -0
  21. package/dist/cjs/util/animation.js +6 -1
  22. package/dist/cjs/util/components.d.ts +20 -0
  23. package/dist/cjs/util/components.js +40 -0
  24. package/dist/cjs/util/crosshair-axis-labels.d.ts +7 -2
  25. package/dist/cjs/util/crosshair-axis-labels.js +144 -30
  26. package/dist/cjs/util/html.d.ts +1 -0
  27. package/dist/cjs/util/html.js +29 -0
  28. package/dist/cjs/util/index.d.ts +0 -2
  29. package/dist/cjs/util/index.js +1 -5
  30. package/dist/cjs/util/interaction.d.ts +4 -3
  31. package/dist/cjs/util/interaction.js +14 -1
  32. package/dist/cjs/util/tokens.d.ts +4 -3
  33. package/dist/cjs/util/tokens.js +13 -10
  34. package/dist/cjs/vis/area/index.d.ts +3 -6
  35. package/dist/cjs/vis/area/index.js +43 -30
  36. package/dist/cjs/vis/bar/index.d.ts +5 -5
  37. package/dist/cjs/vis/bar/index.js +34 -20
  38. package/dist/cjs/vis/boxplot/index.d.ts +4 -5
  39. package/dist/cjs/vis/boxplot/index.js +36 -23
  40. package/dist/cjs/vis/column/index.d.ts +5 -5
  41. package/dist/cjs/vis/column/index.js +38 -26
  42. package/dist/cjs/vis/dual-axes/index.d.ts +3 -4
  43. package/dist/cjs/vis/dual-axes/index.js +87 -51
  44. package/dist/cjs/vis/fishbone-diagram/index.d.ts +4 -10
  45. package/dist/cjs/vis/fishbone-diagram/index.js +43 -28
  46. package/dist/cjs/vis/flow-diagram/index.d.ts +4 -6
  47. package/dist/cjs/vis/flow-diagram/index.js +21 -22
  48. package/dist/cjs/vis/funnel/index.d.ts +3 -6
  49. package/dist/cjs/vis/funnel/index.js +77 -58
  50. package/dist/cjs/vis/histogram/index.d.ts +4 -6
  51. package/dist/cjs/vis/histogram/index.js +17 -19
  52. package/dist/cjs/vis/indented-tree/index.d.ts +4 -6
  53. package/dist/cjs/vis/indented-tree/index.js +58 -34
  54. package/dist/cjs/vis/line/index.d.ts +3 -6
  55. package/dist/cjs/vis/line/index.js +43 -22
  56. package/dist/cjs/vis/liquid/index.d.ts +4 -6
  57. package/dist/cjs/vis/liquid/index.js +22 -17
  58. package/dist/cjs/vis/mindmap/index.d.ts +4 -6
  59. package/dist/cjs/vis/mindmap/index.js +43 -25
  60. package/dist/cjs/vis/network-graph/index.d.ts +4 -6
  61. package/dist/cjs/vis/network-graph/index.js +26 -20
  62. package/dist/cjs/vis/organization-chart/index.d.ts +4 -6
  63. package/dist/cjs/vis/organization-chart/index.js +39 -33
  64. package/dist/cjs/vis/pie/index.d.ts +3 -5
  65. package/dist/cjs/vis/pie/index.js +45 -26
  66. package/dist/cjs/vis/radar/index.d.ts +3 -6
  67. package/dist/cjs/vis/radar/index.js +32 -24
  68. package/dist/cjs/vis/sankey/index.d.ts +4 -6
  69. package/dist/cjs/vis/sankey/index.js +17 -7
  70. package/dist/cjs/vis/scatter/index.d.ts +3 -5
  71. package/dist/cjs/vis/scatter/index.js +32 -19
  72. package/dist/cjs/vis/summary/index.js +5 -6
  73. package/dist/cjs/vis/table/index.d.ts +4 -2
  74. package/dist/cjs/vis/table/index.js +56 -8
  75. package/dist/cjs/vis/treemap/index.d.ts +4 -6
  76. package/dist/cjs/vis/treemap/index.js +11 -7
  77. package/dist/cjs/vis/venn/index.d.ts +4 -6
  78. package/dist/cjs/vis/venn/index.js +18 -16
  79. package/dist/cjs/vis/violin/index.d.ts +4 -5
  80. package/dist/cjs/vis/violin/index.js +35 -27
  81. package/dist/cjs/vis/waterfall/index.d.ts +4 -4
  82. package/dist/cjs/vis/waterfall/index.js +48 -39
  83. package/dist/cjs/vis/word-cloud/index.d.ts +3 -5
  84. package/dist/cjs/vis/word-cloud/index.js +18 -12
  85. package/dist/esm/index.d.ts +1 -1
  86. package/dist/esm/theme/g2.d.ts +9 -0
  87. package/dist/esm/theme/g2.js +504 -0
  88. package/dist/esm/theme/g6.d.ts +28 -0
  89. package/dist/esm/theme/g6.js +84 -0
  90. package/dist/esm/theme/merge.d.ts +2 -0
  91. package/dist/esm/theme/merge.js +36 -0
  92. package/dist/esm/theme/resolve.d.ts +7 -0
  93. package/dist/esm/theme/resolve.js +27 -0
  94. package/dist/esm/theme/shared.d.ts +7 -0
  95. package/dist/esm/theme/shared.js +21 -0
  96. package/dist/esm/theme/summary.d.ts +11 -0
  97. package/dist/esm/theme/summary.js +45 -0
  98. package/dist/esm/theme/table.d.ts +13 -0
  99. package/dist/esm/theme/table.js +112 -0
  100. package/dist/esm/types/index.d.ts +8 -5
  101. package/dist/esm/types/theme.d.ts +107 -0
  102. package/dist/esm/types/theme.js +1 -0
  103. package/dist/esm/util/animation.js +12 -2
  104. package/dist/esm/util/components.d.ts +20 -0
  105. package/dist/esm/util/components.js +57 -1
  106. package/dist/esm/util/crosshair-axis-labels.d.ts +7 -2
  107. package/dist/esm/util/crosshair-axis-labels.js +156 -35
  108. package/dist/esm/util/html.d.ts +1 -0
  109. package/dist/esm/util/html.js +3 -0
  110. package/dist/esm/util/index.d.ts +0 -2
  111. package/dist/esm/util/index.js +1 -3
  112. package/dist/esm/util/interaction.d.ts +4 -3
  113. package/dist/esm/util/interaction.js +18 -1
  114. package/dist/esm/util/tokens.d.ts +4 -3
  115. package/dist/esm/util/tokens.js +13 -10
  116. package/dist/esm/vis/area/index.d.ts +3 -6
  117. package/dist/esm/vis/area/index.js +53 -45
  118. package/dist/esm/vis/bar/index.d.ts +5 -5
  119. package/dist/esm/vis/bar/index.js +38 -27
  120. package/dist/esm/vis/boxplot/index.d.ts +4 -5
  121. package/dist/esm/vis/boxplot/index.js +47 -29
  122. package/dist/esm/vis/column/index.d.ts +5 -5
  123. package/dist/esm/vis/column/index.js +46 -36
  124. package/dist/esm/vis/dual-axes/index.d.ts +3 -4
  125. package/dist/esm/vis/dual-axes/index.js +97 -57
  126. package/dist/esm/vis/fishbone-diagram/index.d.ts +4 -10
  127. package/dist/esm/vis/fishbone-diagram/index.js +52 -27
  128. package/dist/esm/vis/flow-diagram/index.d.ts +4 -6
  129. package/dist/esm/vis/flow-diagram/index.js +28 -23
  130. package/dist/esm/vis/funnel/index.d.ts +3 -6
  131. package/dist/esm/vis/funnel/index.js +78 -68
  132. package/dist/esm/vis/histogram/index.d.ts +4 -6
  133. package/dist/esm/vis/histogram/index.js +28 -21
  134. package/dist/esm/vis/indented-tree/index.d.ts +4 -6
  135. package/dist/esm/vis/indented-tree/index.js +59 -52
  136. package/dist/esm/vis/line/index.d.ts +3 -6
  137. package/dist/esm/vis/line/index.js +44 -32
  138. package/dist/esm/vis/liquid/index.d.ts +4 -6
  139. package/dist/esm/vis/liquid/index.js +28 -21
  140. package/dist/esm/vis/mindmap/index.d.ts +4 -6
  141. package/dist/esm/vis/mindmap/index.js +32 -28
  142. package/dist/esm/vis/network-graph/index.d.ts +4 -6
  143. package/dist/esm/vis/network-graph/index.js +37 -22
  144. package/dist/esm/vis/organization-chart/index.d.ts +4 -6
  145. package/dist/esm/vis/organization-chart/index.js +47 -36
  146. package/dist/esm/vis/pie/index.d.ts +3 -5
  147. package/dist/esm/vis/pie/index.js +42 -26
  148. package/dist/esm/vis/radar/index.d.ts +3 -6
  149. package/dist/esm/vis/radar/index.js +28 -20
  150. package/dist/esm/vis/sankey/index.d.ts +4 -6
  151. package/dist/esm/vis/sankey/index.js +20 -10
  152. package/dist/esm/vis/scatter/index.d.ts +3 -5
  153. package/dist/esm/vis/scatter/index.js +32 -21
  154. package/dist/esm/vis/summary/index.js +5 -7
  155. package/dist/esm/vis/table/index.d.ts +4 -2
  156. package/dist/esm/vis/table/index.js +48 -11
  157. package/dist/esm/vis/treemap/index.d.ts +4 -6
  158. package/dist/esm/vis/treemap/index.js +16 -11
  159. package/dist/esm/vis/venn/index.d.ts +4 -6
  160. package/dist/esm/vis/venn/index.js +24 -16
  161. package/dist/esm/vis/violin/index.d.ts +4 -5
  162. package/dist/esm/vis/violin/index.js +45 -37
  163. package/dist/esm/vis/waterfall/index.d.ts +4 -4
  164. package/dist/esm/vis/waterfall/index.js +46 -36
  165. package/dist/esm/vis/word-cloud/index.d.ts +3 -5
  166. package/dist/esm/vis/word-cloud/index.js +24 -17
  167. package/dist/umd/index.min.js +1 -1
  168. package/package.json +1 -1
  169. package/dist/cjs/util/theme.d.ts +0 -20
  170. package/dist/cjs/util/theme.js +0 -372
  171. package/dist/esm/util/theme.d.ts +0 -20
  172. package/dist/esm/util/theme.js +0 -326
@@ -22,12 +22,17 @@ __export(animation_exports, {
22
22
  getChartAnimation: () => getChartAnimation
23
23
  });
24
24
  module.exports = __toCommonJS(animation_exports);
25
+ var import_tokens = require("./tokens");
25
26
  var prefersReducedMotion = () => typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
26
27
  var getChartAnimation = (hasRendered, enterType) => {
27
28
  if (hasRendered || prefersReducedMotion())
28
29
  return false;
29
30
  return {
30
- enter: enterType ? { type: enterType } : {},
31
+ enter: {
32
+ ...enterType ? { type: enterType } : {},
33
+ duration: import_tokens.CHART_STYLE_DEFAULTS.animationDuration,
34
+ easing: "ease-out"
35
+ },
31
36
  update: { type: null },
32
37
  exit: { type: null }
33
38
  };
@@ -1,3 +1,5 @@
1
+ import type { Theme } from '@antv/g2';
2
+ import type { PluginOptions } from '@antv/g6';
1
3
  export type ChartLocale = 'en-US' | 'zh-CN';
2
4
  export type CartesianXAxisOptions = {
3
5
  xLabels?: unknown[];
@@ -13,3 +15,21 @@ export declare const getCartesianAxis: ({ axisXTitle, axisYTitle, xLabels, chart
13
15
  export declare const getColorLegend: (visible: boolean) => false | {
14
16
  color: Record<string, never>;
15
17
  };
18
+ /** Label content and placement belong to the chart; paint comes from the native theme. */
19
+ export declare function getDataLabels(theme: Theme, { visible, defaultVisible, contrast, style, transform, ...content }: {
20
+ visible?: boolean;
21
+ defaultVisible?: boolean;
22
+ contrast?: 'inside' | 'outside';
23
+ style?: Record<string, unknown>;
24
+ transform?: Record<string, unknown>[];
25
+ text: unknown;
26
+ position?: string;
27
+ dx?: number;
28
+ dy?: number;
29
+ formatter?: string;
30
+ }): Record<string, unknown>[] | undefined;
31
+ /** Keep the title plugin's canvas and graph padding in step with its typography. */
32
+ export declare function getGraphTitle(title?: string, subtitle?: string, style?: Record<string, any>): {
33
+ plugins: PluginOptions;
34
+ padding: number | [number, number, number, number];
35
+ };
@@ -22,6 +22,8 @@ __export(components_exports, {
22
22
  getCartesianAxis: () => getCartesianAxis,
23
23
  getCartesianLayout: () => getCartesianLayout,
24
24
  getColorLegend: () => getColorLegend,
25
+ getDataLabels: () => getDataLabels,
26
+ getGraphTitle: () => getGraphTitle,
25
27
  resolveChartLocale: () => resolveChartLocale
26
28
  });
27
29
  module.exports = __toCommonJS(components_exports);
@@ -85,10 +87,48 @@ var getCartesianAxis = ({
85
87
  };
86
88
  };
87
89
  var getColorLegend = (visible) => visible ? { color: {} } : false;
90
+ function getDataLabels(theme, {
91
+ visible,
92
+ defaultVisible = false,
93
+ contrast,
94
+ style,
95
+ transform,
96
+ ...content
97
+ }) {
98
+ var _a, _b;
99
+ if (visible === false)
100
+ return [];
101
+ if (visible !== true && !defaultVisible)
102
+ return void 0;
103
+ const paint = contrast === "inside" ? theme.innerLabel : theme.label;
104
+ const textColor = (_a = theme.label) == null ? void 0 : _a.fill;
105
+ const inverseColor = (_b = theme.innerLabel) == null ? void 0 : _b.fill;
106
+ const contrastTransform = contrast === "inside" && textColor !== inverseColor ? [{ type: "contrastReverse", palette: [textColor, inverseColor] }] : [];
107
+ const transforms = [...contrastTransform, ...transform ?? []];
108
+ return [
109
+ { ...content, ...transforms.length ? { transform: transforms } : {}, ...style, ...paint }
110
+ ];
111
+ }
112
+ function getGraphTitle(title, subtitle, style = {}) {
113
+ if (!title)
114
+ return {
115
+ plugins: [],
116
+ padding: 20
117
+ };
118
+ const contentHeight = Math.ceil((style.titleFontSize ?? 16) * 1.2) + (subtitle ? (style.spacing ?? 8) + Math.ceil((style.subtitleFontSize ?? 12) * 1.2) : 0);
119
+ return {
120
+ plugins: [
121
+ { key: "title", type: "title", title, subtitle, ...style, size: Math.max(44, contentHeight) }
122
+ ],
123
+ padding: [Math.max(46, Math.ceil(contentHeight + 24)), 20, 20, 20]
124
+ };
125
+ }
88
126
  // Annotate the CommonJS export names for ESM import in node:
89
127
  0 && (module.exports = {
90
128
  getCartesianAxis,
91
129
  getCartesianLayout,
92
130
  getColorLegend,
131
+ getDataLabels,
132
+ getGraphTitle,
93
133
  resolveChartLocale
94
134
  });
@@ -1,9 +1,14 @@
1
1
  import { type Chart } from '@antv/g2';
2
- import type { VisualizationTheme } from '../types';
2
+ export type CrosshairAxisLabelsOptions = {
3
+ showXLabel?: boolean;
4
+ useStandaloneYLabel?: boolean;
5
+ yAxisPosition?: 'left' | 'right';
6
+ yField?: string;
7
+ };
3
8
  /**
4
9
  * Bridges G2 tooltip crosshairs to axis value tags.
5
10
  *
6
11
  * G2 does not currently expose axis tags for tooltip crosshairs, so this adapter
7
12
  * reads the rule geometry created by G2 5.4 and renders labels with LineCrosshair.
8
13
  */
9
- export declare const bindCrosshairAxisLabels: (chart: Chart, theme: VisualizationTheme) => (() => void);
14
+ export declare const bindCrosshairAxisLabels: (chart: Chart, theme: string, { showXLabel, useStandaloneYLabel, yAxisPosition, yField, }?: CrosshairAxisLabelsOptions) => (() => void);
@@ -25,27 +25,42 @@ module.exports = __toCommonJS(crosshair_axis_labels_exports);
25
25
  var import_component = require("@antv/component");
26
26
  var import_g2 = require("@antv/g2");
27
27
  var import_tokens = require("./tokens");
28
+ var MAX_CROSSHAIR_DECIMAL_PLACES = 6;
29
+ var CROSSHAIR_LABEL_MARGIN = 4;
28
30
  var formatCrosshairAxisValue = (value, formatter, precision) => {
29
31
  if (value === void 0 || value === null || value === "")
30
32
  return "";
33
+ let displayValue = value;
31
34
  try {
32
35
  const formatted = formatter == null ? void 0 : formatter(value);
33
- if (formatted !== void 0 && formatted !== null)
34
- return String(formatted);
36
+ if (formatted !== void 0 && formatted !== null) {
37
+ const numericFormatted = typeof formatted === "number" || typeof formatted === "string" && formatted.trim() !== "" && Number.isFinite(Number(formatted)) ? Number(formatted) : void 0;
38
+ if (numericFormatted === void 0)
39
+ return String(formatted);
40
+ displayValue = numericFormatted;
41
+ }
35
42
  } catch {
36
43
  }
37
- if (value instanceof Date)
38
- return value.toLocaleString();
39
- if (typeof value === "number" && Number.isFinite(value) && precision !== void 0) {
40
- return value.toFixed(precision);
44
+ if (displayValue instanceof Date)
45
+ return displayValue.toLocaleString();
46
+ if (typeof displayValue === "number" && Number.isFinite(displayValue)) {
47
+ if (displayValue !== 0 && Math.abs(displayValue) < 10 ** -MAX_CROSSHAIR_DECIMAL_PLACES) {
48
+ return Number(displayValue.toPrecision(4)).toString();
49
+ }
50
+ const decimalPlaces = Math.min(
51
+ Math.max(precision ?? MAX_CROSSHAIR_DECIMAL_PLACES, 0),
52
+ MAX_CROSSHAIR_DECIMAL_PLACES
53
+ );
54
+ return Number(displayValue.toFixed(decimalPlaces)).toString();
41
55
  }
42
- return String(value);
56
+ return String(displayValue);
43
57
  };
44
58
  var getNumberPrecision = (value) => {
45
59
  var _a;
46
60
  if (!Number.isFinite(value) || value === 0)
47
61
  return 0;
48
- const [coefficient, exponentText = "0"] = Math.abs(value).toExponential().split("e");
62
+ const normalizedValue = Number(value.toPrecision(12));
63
+ const [coefficient, exponentText = "0"] = Math.abs(normalizedValue).toExponential().split("e");
49
64
  const coefficientPrecision = ((_a = coefficient.split(".")[1]) == null ? void 0 : _a.length) || 0;
50
65
  return Math.max(0, coefficientPrecision - Number(exponentText));
51
66
  };
@@ -64,7 +79,7 @@ var getCrosshairScalePrecision = (scale) => {
64
79
  }
65
80
  if (!Number.isFinite(interval))
66
81
  return void 0;
67
- return Math.min(getNumberPrecision(interval) + 2, 20);
82
+ return Math.min(getNumberPrecision(interval) + 2, MAX_CROSSHAIR_DECIMAL_PLACES);
68
83
  };
69
84
  var getCrosshairTagStyle = (theme, tokens) => ({
70
85
  lineLineWidth: 0,
@@ -86,7 +101,39 @@ var getCrosshairTagStyle = (theme, tokens) => ({
86
101
  tagLabelLineWidth: 0,
87
102
  tagPointerEvents: "none"
88
103
  });
104
+ var getStandaloneTagStyle = (theme, tokens) => ({
105
+ align: "start",
106
+ verticalAlign: "middle",
107
+ padding: [4, 7],
108
+ radius: 6,
109
+ backgroundFill: tokens.textPrimary,
110
+ backgroundStroke: "transparent",
111
+ backgroundLineWidth: 0,
112
+ backgroundShadowColor: theme === "dark" ? "rgba(0, 0, 0, 0.38)" : "rgba(15, 23, 42, 0.18)",
113
+ backgroundShadowBlur: 8,
114
+ backgroundShadowOffsetY: 2,
115
+ labelFill: tokens.background,
116
+ labelFillOpacity: 1,
117
+ labelFontFamily: import_tokens.CHART_FONT_FAMILY,
118
+ labelFontSize: 11,
119
+ labelFontWeight: 500,
120
+ labelLineWidth: 0,
121
+ pointerEvents: "none"
122
+ });
89
123
  var clamp = (value, min, max) => Math.min(Math.max(value, Math.min(min, max)), Math.max(min, max));
124
+ var keepTagInCanvas = (tag, canvas) => {
125
+ if (!tag || !canvas)
126
+ return;
127
+ const { width, height } = canvas.getConfig();
128
+ if (width === void 0 || height === void 0)
129
+ return;
130
+ const { min, max } = tag.getBounds();
131
+ const margin = CROSSHAIR_LABEL_MARGIN;
132
+ const dx = Math.max(margin - min[0], Math.min(0, width - margin - max[0]));
133
+ const dy = Math.max(margin - min[1], Math.min(0, height - margin - max[1]));
134
+ if (dx || dy)
135
+ tag.translate(dx, dy);
136
+ };
90
137
  var invertCrosshairValue = (scale, value) => {
91
138
  var _a, _b, _c;
92
139
  if (!scale || typeof scale.invert !== "function" || value === void 0)
@@ -122,11 +169,40 @@ var getTooltipPlot = (context) => {
122
169
  return void 0;
123
170
  return (0, import_g2.selectPlotArea)(root);
124
171
  };
125
- var getCartesianView = (context) => {
172
+ var getScaleField = (scale) => {
173
+ var _a, _b;
174
+ return (_b = (_a = scale == null ? void 0 : scale.getOptions) == null ? void 0 : _a.call(scale)) == null ? void 0 : _b.field;
175
+ };
176
+ var findYScaleByField = (view, yField) => {
177
+ var _a;
178
+ return (_a = Object.entries(view.scale).find(
179
+ ([scaleName, scale]) => /^y\d*$/.test(scaleName) && getScaleField(scale) === yField
180
+ )) == null ? void 0 : _a[1];
181
+ };
182
+ var getYScale = (view, yField) => yField ? findYScaleByField(view, yField) : view.scale.y;
183
+ var getCartesianView = (context, yField) => {
126
184
  var _a;
127
185
  return (_a = context.views) == null ? void 0 : _a.find(
128
- ({ coordinate, scale }) => Boolean((scale == null ? void 0 : scale.x) && (scale == null ? void 0 : scale.y)) && typeof (coordinate == null ? void 0 : coordinate.invert) === "function"
186
+ (view) => {
187
+ var _a2, _b;
188
+ return Boolean(((_a2 = view.scale) == null ? void 0 : _a2.x) && getYScale(view, yField)) && typeof ((_b = view.coordinate) == null ? void 0 : _b.invert) === "function";
189
+ }
190
+ );
191
+ };
192
+ var hasAxisField = (field, yField) => Array.isArray(field) ? field.includes(yField) : field === yField;
193
+ var getYAxisLinePosition = (view, yField, position, fallback, plotX) => {
194
+ var _a;
195
+ if (!yField)
196
+ return fallback;
197
+ const axis = (_a = view.components) == null ? void 0 : _a.find(
198
+ ({ 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)))
129
199
  );
200
+ if (!(axis == null ? void 0 : axis.bbox))
201
+ return fallback;
202
+ const x = Number(axis.bbox.x);
203
+ const width = Number(axis.bbox.width);
204
+ const axisX = position === "right" || !Number.isFinite(width) ? x : x + width;
205
+ return axisX - plotX;
130
206
  };
131
207
  var getRuleLine = (rule) => {
132
208
  var _a, _b, _c, _d;
@@ -155,24 +231,33 @@ var invertCoordinate = (view, point) => {
155
231
  return void 0;
156
232
  }
157
233
  };
158
- var bindCrosshairAxisLabels = (chart, theme) => {
234
+ var bindCrosshairAxisLabels = (chart, theme, {
235
+ showXLabel = true,
236
+ useStandaloneYLabel = false,
237
+ yAxisPosition = "left",
238
+ yField
239
+ } = {}) => {
159
240
  if (!chart || typeof chart.on !== "function")
160
241
  return () => void 0;
161
242
  const tagStyle = getCrosshairTagStyle(theme, (0, import_tokens.getChartVisualTokens)(theme));
243
+ const standaloneTagStyle = getStandaloneTagStyle(theme, (0, import_tokens.getChartVisualTokens)(theme));
162
244
  let boundPlot = null;
163
245
  let xCrosshair = null;
164
246
  let yCrosshair = null;
247
+ let standaloneYTag = null;
165
248
  let latestPointerY = null;
166
249
  let latestXValue;
167
250
  const destroyCrosshairs = () => {
168
251
  xCrosshair == null ? void 0 : xCrosshair.destroy();
169
252
  yCrosshair == null ? void 0 : yCrosshair.destroy();
253
+ standaloneYTag == null ? void 0 : standaloneYTag.destroy();
170
254
  xCrosshair = null;
171
255
  yCrosshair = null;
256
+ standaloneYTag = null;
172
257
  boundPlot = null;
173
258
  };
174
259
  const hideCrosshairs = () => {
175
- for (const crosshair of [xCrosshair, yCrosshair]) {
260
+ for (const crosshair of [xCrosshair, yCrosshair, standaloneYTag]) {
176
261
  if (crosshair)
177
262
  crosshair.style.visibility = "hidden";
178
263
  }
@@ -193,7 +278,7 @@ var bindCrosshairAxisLabels = (chart, theme) => {
193
278
  const xEnd = [xLine.x2 + plotX, xLine.y2 + plotY];
194
279
  const yStart = [yLine.x1 + plotX, yLine.y1 + plotY];
195
280
  const yEnd = [yLine.x2 + plotX, yLine.y2 + plotY];
196
- if (!xCrosshair) {
281
+ if (showXLabel && !xCrosshair) {
197
282
  xCrosshair = new import_component.LineCrosshair({
198
283
  style: { ...tagStyle, startPos: xStart, endPos: xEnd, tagText: xText, tagPosition: "end" }
199
284
  });
@@ -201,31 +286,38 @@ var bindCrosshairAxisLabels = (chart, theme) => {
201
286
  xCrosshair.style.pointerEvents = "none";
202
287
  layer.appendChild(xCrosshair);
203
288
  }
204
- if (!yCrosshair) {
289
+ if (showXLabel && !useStandaloneYLabel && !yCrosshair) {
205
290
  yCrosshair = new import_component.LineCrosshair({
206
291
  style: {
207
292
  ...tagStyle,
208
293
  startPos: yStart,
209
294
  endPos: yEnd,
210
295
  tagText: yText,
211
- tagPosition: "start"
296
+ tagPosition: yAxisPosition === "right" ? "end" : "start"
212
297
  }
213
298
  });
214
299
  yCrosshair.style.zIndex = 7;
215
300
  yCrosshair.style.pointerEvents = "none";
216
301
  layer.appendChild(yCrosshair);
217
302
  }
303
+ if ((useStandaloneYLabel || !showXLabel) && !standaloneYTag) {
304
+ standaloneYTag = new import_component.Tag({ style: { ...standaloneTagStyle, text: yText } });
305
+ standaloneYTag.style.zIndex = 7;
306
+ standaloneYTag.style.pointerEvents = "none";
307
+ layer.appendChild(standaloneYTag);
308
+ }
218
309
  boundPlot = plot;
219
310
  };
220
311
  const updateCrosshairs = (event) => {
221
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
312
+ var _a, _b, _c, _d, _e, _f, _g, _h;
222
313
  const context = chart.getContext();
223
314
  const plot = getTooltipPlot(context);
224
- const view = getCartesianView(context);
315
+ const view = getCartesianView(context, yField);
225
316
  if (!plot || !view) {
226
317
  hideCrosshairs();
227
318
  return;
228
319
  }
320
+ const yScale = getYScale(view, yField);
229
321
  const verticalRule = getRuleLine(plot.ruleY);
230
322
  const horizontalRule = getRuleLine(plot.ruleX);
231
323
  if (!verticalRule || !horizontalRule) {
@@ -240,36 +332,58 @@ var bindCrosshairAxisLabels = (chart, theme) => {
240
332
  const y = clamp(pointerY, verticalRule.y1, verticalRule.y2);
241
333
  const invertedPosition = invertCoordinate(view, [x, y]);
242
334
  const xValue = latestXValue ?? invertCrosshairValue(view.scale.x, invertedPosition == null ? void 0 : invertedPosition[0]);
243
- const yValue = invertCrosshairValue(view.scale.y, 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);
335
+ 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);
244
336
  const xText = formatCrosshairAxisValue(xValue, (_e = (_d = view.scale.x).getFormatter) == null ? void 0 : _e.call(_d));
245
337
  const yText = formatCrosshairAxisValue(
246
338
  yValue,
247
- (_g = (_f = view.scale.y).getFormatter) == null ? void 0 : _g.call(_f),
248
- getCrosshairScalePrecision(view.scale.y)
339
+ (_f = yScale == null ? void 0 : yScale.getFormatter) == null ? void 0 : _f.call(yScale),
340
+ getCrosshairScalePrecision(yScale)
249
341
  );
250
342
  if (!xText || !yText) {
251
343
  hideCrosshairs();
252
344
  return;
253
345
  }
254
- if ((_h = plot.ruleY) == null ? void 0 : _h.style) {
346
+ if ((_g = plot.ruleY) == null ? void 0 : _g.style) {
255
347
  plot.ruleY.style.x1 = x;
256
348
  plot.ruleY.style.x2 = x;
257
349
  }
258
- if ((_i = plot.ruleX) == null ? void 0 : _i.style) {
350
+ if ((_h = plot.ruleX) == null ? void 0 : _h.style) {
259
351
  plot.ruleX.style.y1 = y;
260
352
  plot.ruleX.style.y2 = y;
261
353
  }
262
354
  const displayVerticalRule = { ...verticalRule, x1: x, x2: x };
263
355
  const displayHorizontalRule = { ...horizontalRule, y1: y, y2: y };
264
356
  ensureCrosshairs(plot, displayVerticalRule, displayHorizontalRule, xText, yText);
265
- if (!xCrosshair || !yCrosshair)
357
+ if (showXLabel && !xCrosshair || (useStandaloneYLabel ? !standaloneYTag : !yCrosshair && !standaloneYTag))
266
358
  return;
267
- xCrosshair.setText(xText);
268
- xCrosshair.setPointer([x + plotX, verticalRule.y2 + plotY]);
269
- xCrosshair.style.visibility = "visible";
270
- yCrosshair.setText(yText);
271
- yCrosshair.setPointer([horizontalRule.x1 + plotX, y + plotY]);
272
- yCrosshair.style.visibility = "visible";
359
+ if (xCrosshair) {
360
+ xCrosshair.setText(xText);
361
+ xCrosshair.setPointer([x + plotX, verticalRule.y2 + plotY]);
362
+ xCrosshair.style.visibility = "visible";
363
+ keepTagInCanvas(xCrosshair.querySelector(".crosshair-tag"), context.canvas);
364
+ }
365
+ if (yCrosshair) {
366
+ yCrosshair.setText(yText);
367
+ yCrosshair.setPointer([
368
+ (yAxisPosition === "right" ? horizontalRule.x2 : horizontalRule.x1) + plotX,
369
+ y + plotY
370
+ ]);
371
+ yCrosshair.style.visibility = "visible";
372
+ keepTagInCanvas(yCrosshair.querySelector(".crosshair-tag"), context.canvas);
373
+ }
374
+ if (standaloneYTag) {
375
+ const yAxisX = getYAxisLinePosition(
376
+ view,
377
+ yField,
378
+ yAxisPosition,
379
+ yAxisPosition === "right" ? horizontalRule.x2 : horizontalRule.x1,
380
+ plotX
381
+ );
382
+ standaloneYTag.update({ text: yText });
383
+ standaloneYTag.setLocalPosition([yAxisX + plotX, y + plotY]);
384
+ standaloneYTag.style.visibility = "visible";
385
+ keepTagInCanvas(standaloneYTag, context.canvas);
386
+ }
273
387
  };
274
388
  const onPointerMove = (event) => {
275
389
  const y = Number(event.offsetY ?? event.canvasY);
@@ -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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ escapeHtml
29
+ });
@@ -2,5 +2,3 @@ export * from './animation';
2
2
  export * from './components';
3
3
  export * from './crosshair-axis-labels';
4
4
  export * from './interaction';
5
- export * from './theme';
6
- export * from './tokens';
@@ -20,14 +20,10 @@ __reExport(util_exports, require("./animation"), module.exports);
20
20
  __reExport(util_exports, require("./components"), module.exports);
21
21
  __reExport(util_exports, require("./crosshair-axis-labels"), module.exports);
22
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
23
  // Annotate the CommonJS export names for ESM import in node:
26
24
  0 && (module.exports = {
27
25
  ...require("./animation"),
28
26
  ...require("./components"),
29
27
  ...require("./crosshair-axis-labels"),
30
- ...require("./interaction"),
31
- ...require("./theme"),
32
- ...require("./tokens")
28
+ ...require("./interaction")
33
29
  });
@@ -1,4 +1,3 @@
1
- import type { VisualizationTheme } from '../types';
2
1
  export type SharedTooltipInteractionOptions = {
3
2
  crosshairs?: boolean;
4
3
  };
@@ -7,8 +6,10 @@ export type PointHighlightStateOptions = {
7
6
  inactiveOpacity?: number;
8
7
  };
9
8
  export declare const getSharedTooltipInteraction: ({ crosshairs, }?: SharedTooltipInteractionOptions) => Record<string, boolean>;
10
- export declare const getCategoryBackgroundHighlightState: (theme: VisualizationTheme) => Record<string, any>;
9
+ export declare const getCategoryBackgroundHighlightState: (theme: string) => Record<string, any>;
11
10
  export declare const getCategoryHighlightInteraction: () => Record<string, any>;
12
11
  export declare const getPointHighlightState: ({ activeLineWidth, inactiveOpacity, }?: PointHighlightStateOptions) => Record<string, any>;
13
- export declare const getSeriesHighlightByColorInteraction: () => Record<string, boolean>;
12
+ export declare const getSeriesHighlightByColorInteraction: () => Record<string, any>;
14
13
  export declare const getLineHighlightState: (lineWidth: number) => Record<string, any>;
14
+ /** Preserve GPT-Vis hover feedback independently of the visual theme. */
15
+ export declare const getElementHoverScaleInteraction: (theme: string) => Record<string, unknown>;
@@ -21,6 +21,7 @@ var interaction_exports = {};
21
21
  __export(interaction_exports, {
22
22
  getCategoryBackgroundHighlightState: () => getCategoryBackgroundHighlightState,
23
23
  getCategoryHighlightInteraction: () => getCategoryHighlightInteraction,
24
+ getElementHoverScaleInteraction: () => getElementHoverScaleInteraction,
24
25
  getLineHighlightState: () => getLineHighlightState,
25
26
  getPointHighlightState: () => getPointHighlightState,
26
27
  getSeriesHighlightByColorInteraction: () => getSeriesHighlightByColorInteraction,
@@ -48,6 +49,7 @@ var getCategoryBackgroundHighlightState = (theme) => {
48
49
  };
49
50
  };
50
51
  var getCategoryHighlightInteraction = () => ({
52
+ delay: import_tokens.CHART_STYLE_DEFAULTS.interactionDelay,
51
53
  background: true,
52
54
  region: true
53
55
  });
@@ -72,16 +74,27 @@ var getPointHighlightState = ({
72
74
  }
73
75
  });
74
76
  var getSeriesHighlightByColorInteraction = () => ({
75
- elementHighlightByColor: true
77
+ elementHighlightByColor: { delay: import_tokens.CHART_STYLE_DEFAULTS.interactionDelay }
76
78
  });
77
79
  var getLineHighlightState = (lineWidth) => ({
78
80
  active: { lineWidth: lineWidth + 1, strokeOpacity: 1 },
79
81
  inactive: { strokeOpacity: import_tokens.CHART_STYLE_DEFAULTS.inactiveOpacity }
80
82
  });
83
+ var getElementHoverScaleInteraction = (theme) => ({
84
+ delay: import_tokens.CHART_STYLE_DEFAULTS.interactionDelay,
85
+ scale: 1.04,
86
+ shadow: true,
87
+ shadowBlur: theme === "dark" ? 7 : theme === "academy" ? 5 : 6,
88
+ shadowColor: theme === "dark" ? "rgba(226, 232, 240, 0.38)" : theme === "academy" ? "rgba(63, 49, 38, 0.44)" : "rgba(15, 23, 42, 0.46)",
89
+ shadowOffsetX: 0,
90
+ shadowOffsetY: theme === "dark" ? 0 : 3,
91
+ zIndex: 10
92
+ });
81
93
  // Annotate the CommonJS export names for ESM import in node:
82
94
  0 && (module.exports = {
83
95
  getCategoryBackgroundHighlightState,
84
96
  getCategoryHighlightInteraction,
97
+ getElementHoverScaleInteraction,
85
98
  getLineHighlightState,
86
99
  getPointHighlightState,
87
100
  getSeriesHighlightByColorInteraction,
@@ -1,4 +1,3 @@
1
- import type { VisualizationTheme } from '../types';
2
1
  export declare const CHART_FONT_FAMILY = "Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, \"Segoe UI\", sans-serif";
3
2
  export declare const CHART_STYLE_DEFAULTS: {
4
3
  readonly animationDuration: 260;
@@ -13,9 +12,10 @@ export declare const CHART_STYLE_DEFAULTS: {
13
12
  readonly pointActiveLineWidth: 5;
14
13
  readonly intervalWidthRatio: 0.64;
15
14
  };
16
- export type ChartVisualTokens = {
15
+ type BuiltInThemeValues = {
17
16
  background: string;
18
17
  textPrimary: string;
18
+ textInverse: string;
19
19
  textSecondary: string;
20
20
  grid: string;
21
21
  axisGrid: string;
@@ -28,4 +28,5 @@ export type ChartVisualTokens = {
28
28
  tooltipMarkerShadow: string;
29
29
  tooltipShadow: string;
30
30
  };
31
- export declare const getChartVisualTokens: (theme: VisualizationTheme) => ChartVisualTokens;
31
+ export declare const getChartVisualTokens: (theme: string) => BuiltInThemeValues;
32
+ export {};
@@ -38,13 +38,14 @@ var CHART_STYLE_DEFAULTS = {
38
38
  pointActiveLineWidth: 5,
39
39
  intervalWidthRatio: 0.64
40
40
  };
41
- var LIGHT_TOKENS = {
41
+ var LIGHT_THEME_VALUES = {
42
42
  background: "#FFFFFF",
43
43
  textPrimary: "#1F2937",
44
+ textInverse: "#FFFFFF",
44
45
  textSecondary: "#667085",
45
46
  grid: "#E7EAF0",
46
- axisGrid: "#EAECF0",
47
- axisLine: "#D0D5DD",
47
+ axisGrid: "#D0D5DD",
48
+ axisLine: "#98A2B3",
48
49
  axisTick: "#98A2B3",
49
50
  separator: "#FFFFFF",
50
51
  tooltipBackground: "rgba(255, 255, 255, 0.96)",
@@ -53,13 +54,14 @@ var LIGHT_TOKENS = {
53
54
  tooltipMarkerShadow: "0 0 0 2px #FFFFFF, 0 1px 3px rgba(15, 23, 42, 0.20)",
54
55
  tooltipShadow: "0 12px 32px rgba(15, 23, 42, 0.12), 0 3px 8px rgba(15, 23, 42, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.82)"
55
56
  };
56
- var DARK_TOKENS = {
57
+ var DARK_THEME_VALUES = {
57
58
  background: "#141414",
58
59
  textPrimary: "#F3F4F6",
60
+ textInverse: "#111827",
59
61
  textSecondary: "#A7AFBE",
60
62
  grid: "#343841",
61
- axisGrid: "#2B2F36",
62
- axisLine: "#454B56",
63
+ axisGrid: "#475467",
64
+ axisLine: "#667085",
63
65
  axisTick: "#596170",
64
66
  separator: "#141414",
65
67
  tooltipBackground: "rgba(26, 27, 31, 0.96)",
@@ -68,9 +70,10 @@ var DARK_TOKENS = {
68
70
  tooltipMarkerShadow: "0 0 0 2px #1A1B1F, 0 1px 3px rgba(0, 0, 0, 0.42)",
69
71
  tooltipShadow: "0 14px 36px rgba(0, 0, 0, 0.34), 0 3px 10px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.08)"
70
72
  };
71
- var ACADEMY_TOKENS = {
73
+ var ACADEMY_THEME_VALUES = {
72
74
  background: "#FFFFFF",
73
75
  textPrimary: "#23262D",
76
+ textInverse: "#FFFFFF",
74
77
  textSecondary: "#626975",
75
78
  grid: "#DDDDDD",
76
79
  axisGrid: "#DDDDDD",
@@ -85,10 +88,10 @@ var ACADEMY_TOKENS = {
85
88
  };
86
89
  var getChartVisualTokens = (theme) => {
87
90
  if (theme === "dark")
88
- return DARK_TOKENS;
91
+ return DARK_THEME_VALUES;
89
92
  if (theme === "academy")
90
- return ACADEMY_TOKENS;
91
- return LIGHT_TOKENS;
93
+ return ACADEMY_THEME_VALUES;
94
+ return LIGHT_THEME_VALUES;
92
95
  };
93
96
  // Annotate the CommonJS export names for ESM import in node:
94
97
  0 && (module.exports = {
@@ -1,4 +1,4 @@
1
- import type { VisualizationOptions, VisualizationTheme } from '../../types';
1
+ import type { ThemeStyle, VisualizationOptions, VisualizationTheme } from '../../types';
2
2
  /**
3
3
  * AreaDataItem is the type for each data item in the area chart.
4
4
  */
@@ -15,14 +15,11 @@ export interface AreaConfig {
15
15
  data: AreaDataItem[];
16
16
  stack?: boolean;
17
17
  title?: string;
18
+ subtitle?: string;
18
19
  axisXTitle?: string;
19
20
  axisYTitle?: string;
20
21
  theme?: VisualizationTheme;
21
- style?: {
22
- backgroundColor?: string;
23
- palette?: string[];
24
- lineWidth?: number;
25
- };
22
+ style?: ThemeStyle;
26
23
  }
27
24
  /**
28
25
  * AreaInstance represents an area chart instance with render and destroy methods.