@antv/gpt-vis 1.3.2 → 1.4.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 (284) hide show
  1. package/README.md +261 -137
  2. package/README.zh-CN.md +263 -116
  3. package/dist/cjs/annotation/components/bottom-n.d.ts +2 -0
  4. package/dist/cjs/annotation/components/bottom-n.js +57 -0
  5. package/dist/cjs/annotation/components/centroid.d.ts +2 -0
  6. package/dist/cjs/annotation/components/centroid.js +75 -0
  7. package/dist/cjs/annotation/components/connector.d.ts +25 -0
  8. package/dist/cjs/annotation/components/connector.js +298 -0
  9. package/dist/cjs/annotation/components/contribution.d.ts +3 -0
  10. package/dist/cjs/annotation/components/contribution.js +136 -0
  11. package/dist/cjs/annotation/components/crossing.d.ts +3 -0
  12. package/dist/cjs/annotation/components/crossing.js +504 -0
  13. package/dist/cjs/annotation/components/event.d.ts +2 -0
  14. package/dist/cjs/annotation/components/event.js +62 -0
  15. package/dist/cjs/annotation/components/first.d.ts +2 -0
  16. package/dist/cjs/annotation/components/first.js +42 -0
  17. package/dist/cjs/annotation/components/group.d.ts +3 -0
  18. package/dist/cjs/annotation/components/group.js +73 -0
  19. package/dist/cjs/annotation/components/highlight.d.ts +14 -0
  20. package/dist/cjs/annotation/components/highlight.js +552 -0
  21. package/dist/cjs/annotation/components/index.d.ts +34 -0
  22. package/dist/cjs/annotation/components/index.js +128 -0
  23. package/dist/cjs/annotation/components/last.d.ts +2 -0
  24. package/dist/cjs/annotation/components/last.js +42 -0
  25. package/dist/cjs/annotation/components/max-x.d.ts +2 -0
  26. package/dist/cjs/annotation/components/max-x.js +41 -0
  27. package/dist/cjs/annotation/components/max-y.d.ts +2 -0
  28. package/dist/cjs/annotation/components/max-y.js +41 -0
  29. package/dist/cjs/annotation/components/mean.d.ts +2 -0
  30. package/dist/cjs/annotation/components/mean.js +50 -0
  31. package/dist/cjs/annotation/components/median.d.ts +2 -0
  32. package/dist/cjs/annotation/components/median.js +49 -0
  33. package/dist/cjs/annotation/components/min-x.d.ts +2 -0
  34. package/dist/cjs/annotation/components/min-x.js +41 -0
  35. package/dist/cjs/annotation/components/min-y.d.ts +2 -0
  36. package/dist/cjs/annotation/components/min-y.js +41 -0
  37. package/dist/cjs/annotation/components/outlier.d.ts +3 -0
  38. package/dist/cjs/annotation/components/outlier.js +83 -0
  39. package/dist/cjs/annotation/components/path.d.ts +20 -0
  40. package/dist/cjs/annotation/components/path.js +147 -0
  41. package/dist/cjs/annotation/components/peak.d.ts +2 -0
  42. package/dist/cjs/annotation/components/peak.js +42 -0
  43. package/dist/cjs/annotation/components/point.d.ts +26 -0
  44. package/dist/cjs/annotation/components/point.js +241 -0
  45. package/dist/cjs/annotation/components/quadrant.d.ts +3 -0
  46. package/dist/cjs/annotation/components/quadrant.js +97 -0
  47. package/dist/cjs/annotation/components/quantile.d.ts +2 -0
  48. package/dist/cjs/annotation/components/quantile.js +49 -0
  49. package/dist/cjs/annotation/components/range-inside.d.ts +2 -0
  50. package/dist/cjs/annotation/components/range-inside.js +65 -0
  51. package/dist/cjs/annotation/components/range-outside.d.ts +2 -0
  52. package/dist/cjs/annotation/components/range-outside.js +65 -0
  53. package/dist/cjs/annotation/components/range-x.d.ts +2 -0
  54. package/dist/cjs/annotation/components/range-x.js +39 -0
  55. package/dist/cjs/annotation/components/range-y.d.ts +2 -0
  56. package/dist/cjs/annotation/components/range-y.js +39 -0
  57. package/dist/cjs/annotation/components/range.d.ts +15 -0
  58. package/dist/cjs/annotation/components/range.js +87 -0
  59. package/dist/cjs/annotation/components/target.d.ts +2 -0
  60. package/dist/cjs/annotation/components/target.js +51 -0
  61. package/dist/cjs/annotation/components/text.d.ts +15 -0
  62. package/dist/cjs/annotation/components/text.js +74 -0
  63. package/dist/cjs/annotation/components/threshold-highlight.d.ts +3 -0
  64. package/dist/cjs/annotation/components/threshold-highlight.js +223 -0
  65. package/dist/cjs/annotation/components/threshold-x.d.ts +2 -0
  66. package/dist/cjs/annotation/components/threshold-x.js +39 -0
  67. package/dist/cjs/annotation/components/threshold-y.d.ts +2 -0
  68. package/dist/cjs/annotation/components/threshold-y.js +40 -0
  69. package/dist/cjs/annotation/components/top-n.d.ts +2 -0
  70. package/dist/cjs/annotation/components/top-n.js +57 -0
  71. package/dist/cjs/annotation/components/valley.d.ts +2 -0
  72. package/dist/cjs/annotation/components/valley.js +42 -0
  73. package/dist/cjs/annotation/index.d.ts +1 -0
  74. package/dist/cjs/annotation/index.js +29 -0
  75. package/dist/cjs/annotation/label.d.ts +38 -0
  76. package/dist/cjs/annotation/label.js +347 -0
  77. package/dist/cjs/annotation/layout.d.ts +12 -0
  78. package/dist/cjs/annotation/layout.js +142 -0
  79. package/dist/cjs/annotation/merge.d.ts +19 -0
  80. package/dist/cjs/annotation/merge.js +60 -0
  81. package/dist/cjs/annotation/registry.d.ts +190 -0
  82. package/dist/cjs/annotation/registry.js +134 -0
  83. package/dist/cjs/annotation/runtime/g2.d.ts +90 -0
  84. package/dist/cjs/annotation/runtime/g2.js +521 -0
  85. package/dist/cjs/annotation/runtime/g6.d.ts +40 -0
  86. package/dist/cjs/annotation/runtime/g6.js +310 -0
  87. package/dist/cjs/annotation/runtime/index.d.ts +11 -0
  88. package/dist/cjs/annotation/runtime/index.js +41 -0
  89. package/dist/cjs/annotation/runtime/summary.d.ts +17 -0
  90. package/dist/cjs/annotation/runtime/summary.js +39 -0
  91. package/dist/cjs/annotation/runtime/table.d.ts +16 -0
  92. package/dist/cjs/annotation/runtime/table.js +39 -0
  93. package/dist/cjs/annotation/utils.d.ts +40 -0
  94. package/dist/cjs/annotation/utils.js +275 -0
  95. package/dist/cjs/theme/annotation.d.ts +236 -0
  96. package/dist/cjs/theme/annotation.js +167 -0
  97. package/dist/cjs/theme/g2.js +13 -15
  98. package/dist/cjs/theme/g6.js +2 -2
  99. package/dist/cjs/theme/summary.js +2 -2
  100. package/dist/cjs/types/annotation.d.ts +310 -0
  101. package/dist/cjs/types/annotation.js +17 -0
  102. package/dist/cjs/types/index.d.ts +1 -0
  103. package/dist/cjs/util/axis.d.ts +28 -0
  104. package/dist/cjs/util/axis.js +184 -0
  105. package/dist/cjs/util/components.d.ts +0 -10
  106. package/dist/cjs/util/components.js +9 -64
  107. package/dist/cjs/util/index.d.ts +7 -4
  108. package/dist/cjs/util/index.js +53 -9
  109. package/dist/cjs/vis/area/index.d.ts +2 -0
  110. package/dist/cjs/vis/area/index.js +30 -13
  111. package/dist/cjs/vis/bar/index.d.ts +2 -0
  112. package/dist/cjs/vis/bar/index.js +37 -7
  113. package/dist/cjs/vis/boxplot/index.js +14 -3
  114. package/dist/cjs/vis/column/index.d.ts +2 -0
  115. package/dist/cjs/vis/column/index.js +28 -9
  116. package/dist/cjs/vis/dual-axes/index.js +9 -9
  117. package/dist/cjs/vis/fishbone-diagram/index.js +2 -2
  118. package/dist/cjs/vis/flow-diagram/index.js +2 -2
  119. package/dist/cjs/vis/funnel/index.js +10 -13
  120. package/dist/cjs/vis/histogram/index.js +2 -2
  121. package/dist/cjs/vis/indented-tree/index.js +2 -2
  122. package/dist/cjs/vis/line/index.d.ts +2 -0
  123. package/dist/cjs/vis/line/index.js +26 -10
  124. package/dist/cjs/vis/liquid/index.js +2 -2
  125. package/dist/cjs/vis/mindmap/index.js +2 -2
  126. package/dist/cjs/vis/network-graph/index.d.ts +2 -0
  127. package/dist/cjs/vis/network-graph/index.js +24 -3
  128. package/dist/cjs/vis/organization-chart/index.js +2 -2
  129. package/dist/cjs/vis/pie/index.d.ts +2 -0
  130. package/dist/cjs/vis/pie/index.js +21 -10
  131. package/dist/cjs/vis/radar/index.js +4 -6
  132. package/dist/cjs/vis/sankey/index.js +14 -1
  133. package/dist/cjs/vis/scatter/index.d.ts +10 -3
  134. package/dist/cjs/vis/scatter/index.js +18 -7
  135. package/dist/cjs/vis/summary/index.d.ts +9 -2
  136. package/dist/cjs/vis/summary/index.js +25 -8
  137. package/dist/cjs/vis/table/index.d.ts +2 -0
  138. package/dist/cjs/vis/table/index.js +48 -30
  139. package/dist/cjs/vis/venn/index.js +2 -2
  140. package/dist/cjs/vis/violin/index.js +14 -3
  141. package/dist/cjs/vis/waterfall/index.js +17 -9
  142. package/dist/cjs/vis/word-cloud/index.js +4 -6
  143. package/dist/esm/annotation/components/bottom-n.d.ts +2 -0
  144. package/dist/esm/annotation/components/bottom-n.js +42 -0
  145. package/dist/esm/annotation/components/centroid.d.ts +2 -0
  146. package/dist/esm/annotation/components/centroid.js +73 -0
  147. package/dist/esm/annotation/components/connector.d.ts +25 -0
  148. package/dist/esm/annotation/components/connector.js +332 -0
  149. package/dist/esm/annotation/components/contribution.d.ts +3 -0
  150. package/dist/esm/annotation/components/contribution.js +174 -0
  151. package/dist/esm/annotation/components/crossing.d.ts +3 -0
  152. package/dist/esm/annotation/components/crossing.js +665 -0
  153. package/dist/esm/annotation/components/event.d.ts +2 -0
  154. package/dist/esm/annotation/components/event.js +46 -0
  155. package/dist/esm/annotation/components/first.d.ts +2 -0
  156. package/dist/esm/annotation/components/first.js +18 -0
  157. package/dist/esm/annotation/components/group.d.ts +3 -0
  158. package/dist/esm/annotation/components/group.js +64 -0
  159. package/dist/esm/annotation/components/highlight.d.ts +14 -0
  160. package/dist/esm/annotation/components/highlight.js +838 -0
  161. package/dist/esm/annotation/components/index.d.ts +34 -0
  162. package/dist/esm/annotation/components/index.js +34 -0
  163. package/dist/esm/annotation/components/last.d.ts +2 -0
  164. package/dist/esm/annotation/components/last.js +18 -0
  165. package/dist/esm/annotation/components/max-x.d.ts +2 -0
  166. package/dist/esm/annotation/components/max-x.js +17 -0
  167. package/dist/esm/annotation/components/max-y.d.ts +2 -0
  168. package/dist/esm/annotation/components/max-y.js +17 -0
  169. package/dist/esm/annotation/components/mean.d.ts +2 -0
  170. package/dist/esm/annotation/components/mean.js +40 -0
  171. package/dist/esm/annotation/components/median.d.ts +2 -0
  172. package/dist/esm/annotation/components/median.js +32 -0
  173. package/dist/esm/annotation/components/min-x.d.ts +2 -0
  174. package/dist/esm/annotation/components/min-x.js +17 -0
  175. package/dist/esm/annotation/components/min-y.d.ts +2 -0
  176. package/dist/esm/annotation/components/min-y.js +17 -0
  177. package/dist/esm/annotation/components/outlier.d.ts +3 -0
  178. package/dist/esm/annotation/components/outlier.js +98 -0
  179. package/dist/esm/annotation/components/path.d.ts +20 -0
  180. package/dist/esm/annotation/components/path.js +165 -0
  181. package/dist/esm/annotation/components/peak.d.ts +2 -0
  182. package/dist/esm/annotation/components/peak.js +20 -0
  183. package/dist/esm/annotation/components/point.d.ts +26 -0
  184. package/dist/esm/annotation/components/point.js +277 -0
  185. package/dist/esm/annotation/components/quadrant.d.ts +3 -0
  186. package/dist/esm/annotation/components/quadrant.js +83 -0
  187. package/dist/esm/annotation/components/quantile.d.ts +2 -0
  188. package/dist/esm/annotation/components/quantile.js +32 -0
  189. package/dist/esm/annotation/components/range-inside.d.ts +2 -0
  190. package/dist/esm/annotation/components/range-inside.js +55 -0
  191. package/dist/esm/annotation/components/range-outside.d.ts +2 -0
  192. package/dist/esm/annotation/components/range-outside.js +55 -0
  193. package/dist/esm/annotation/components/range-x.d.ts +2 -0
  194. package/dist/esm/annotation/components/range-x.js +15 -0
  195. package/dist/esm/annotation/components/range-y.d.ts +2 -0
  196. package/dist/esm/annotation/components/range-y.js +15 -0
  197. package/dist/esm/annotation/components/range.d.ts +15 -0
  198. package/dist/esm/annotation/components/range.js +92 -0
  199. package/dist/esm/annotation/components/target.d.ts +2 -0
  200. package/dist/esm/annotation/components/target.js +44 -0
  201. package/dist/esm/annotation/components/text.d.ts +15 -0
  202. package/dist/esm/annotation/components/text.js +78 -0
  203. package/dist/esm/annotation/components/threshold-highlight.d.ts +3 -0
  204. package/dist/esm/annotation/components/threshold-highlight.js +297 -0
  205. package/dist/esm/annotation/components/threshold-x.d.ts +2 -0
  206. package/dist/esm/annotation/components/threshold-x.js +23 -0
  207. package/dist/esm/annotation/components/threshold-y.d.ts +2 -0
  208. package/dist/esm/annotation/components/threshold-y.js +24 -0
  209. package/dist/esm/annotation/components/top-n.d.ts +2 -0
  210. package/dist/esm/annotation/components/top-n.js +42 -0
  211. package/dist/esm/annotation/components/valley.d.ts +2 -0
  212. package/dist/esm/annotation/components/valley.js +20 -0
  213. package/dist/esm/annotation/index.d.ts +1 -0
  214. package/dist/esm/annotation/index.js +1 -0
  215. package/dist/esm/annotation/label.d.ts +38 -0
  216. package/dist/esm/annotation/label.js +449 -0
  217. package/dist/esm/annotation/layout.d.ts +12 -0
  218. package/dist/esm/annotation/layout.js +182 -0
  219. package/dist/esm/annotation/merge.d.ts +19 -0
  220. package/dist/esm/annotation/merge.js +67 -0
  221. package/dist/esm/annotation/registry.d.ts +190 -0
  222. package/dist/esm/annotation/registry.js +220 -0
  223. package/dist/esm/annotation/runtime/g2.d.ts +90 -0
  224. package/dist/esm/annotation/runtime/g2.js +754 -0
  225. package/dist/esm/annotation/runtime/g6.d.ts +40 -0
  226. package/dist/esm/annotation/runtime/g6.js +447 -0
  227. package/dist/esm/annotation/runtime/index.d.ts +11 -0
  228. package/dist/esm/annotation/runtime/index.js +26 -0
  229. package/dist/esm/annotation/runtime/summary.d.ts +17 -0
  230. package/dist/esm/annotation/runtime/summary.js +21 -0
  231. package/dist/esm/annotation/runtime/table.d.ts +16 -0
  232. package/dist/esm/annotation/runtime/table.js +21 -0
  233. package/dist/esm/annotation/utils.d.ts +40 -0
  234. package/dist/esm/annotation/utils.js +370 -0
  235. package/dist/esm/theme/annotation.d.ts +236 -0
  236. package/dist/esm/theme/annotation.js +186 -0
  237. package/dist/esm/theme/g2.js +2 -10
  238. package/dist/esm/theme/g6.js +1 -1
  239. package/dist/esm/theme/summary.js +1 -1
  240. package/dist/esm/types/annotation.d.ts +310 -0
  241. package/dist/esm/types/annotation.js +1 -0
  242. package/dist/esm/types/index.d.ts +1 -0
  243. package/dist/esm/util/axis.d.ts +28 -0
  244. package/dist/esm/util/axis.js +222 -0
  245. package/dist/esm/util/components.d.ts +0 -10
  246. package/dist/esm/util/components.js +24 -69
  247. package/dist/esm/util/index.d.ts +7 -4
  248. package/dist/esm/util/index.js +7 -4
  249. package/dist/esm/vis/area/index.d.ts +2 -0
  250. package/dist/esm/vis/area/index.js +32 -9
  251. package/dist/esm/vis/bar/index.d.ts +2 -0
  252. package/dist/esm/vis/bar/index.js +37 -6
  253. package/dist/esm/vis/boxplot/index.js +10 -2
  254. package/dist/esm/vis/column/index.d.ts +2 -0
  255. package/dist/esm/vis/column/index.js +33 -12
  256. package/dist/esm/vis/dual-axes/index.js +10 -10
  257. package/dist/esm/vis/fishbone-diagram/index.js +1 -1
  258. package/dist/esm/vis/flow-diagram/index.js +1 -1
  259. package/dist/esm/vis/funnel/index.js +2 -7
  260. package/dist/esm/vis/histogram/index.js +4 -3
  261. package/dist/esm/vis/indented-tree/index.js +1 -1
  262. package/dist/esm/vis/line/index.d.ts +2 -0
  263. package/dist/esm/vis/line/index.js +31 -9
  264. package/dist/esm/vis/liquid/index.js +1 -1
  265. package/dist/esm/vis/mindmap/index.js +1 -1
  266. package/dist/esm/vis/network-graph/index.d.ts +2 -0
  267. package/dist/esm/vis/network-graph/index.js +29 -2
  268. package/dist/esm/vis/organization-chart/index.js +1 -1
  269. package/dist/esm/vis/pie/index.d.ts +2 -0
  270. package/dist/esm/vis/pie/index.js +25 -8
  271. package/dist/esm/vis/radar/index.js +1 -3
  272. package/dist/esm/vis/sankey/index.js +15 -1
  273. package/dist/esm/vis/scatter/index.d.ts +10 -3
  274. package/dist/esm/vis/scatter/index.js +28 -5
  275. package/dist/esm/vis/summary/index.d.ts +9 -2
  276. package/dist/esm/vis/summary/index.js +31 -13
  277. package/dist/esm/vis/table/index.d.ts +2 -0
  278. package/dist/esm/vis/table/index.js +50 -33
  279. package/dist/esm/vis/venn/index.js +1 -1
  280. package/dist/esm/vis/violin/index.js +10 -2
  281. package/dist/esm/vis/waterfall/index.js +16 -13
  282. package/dist/esm/vis/word-cloud/index.js +1 -3
  283. package/dist/umd/index.min.js +1 -1
  284. package/package.json +1 -1
@@ -0,0 +1,275 @@
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/annotation/utils.ts
20
+ var utils_exports = {};
21
+ __export(utils_exports, {
22
+ annotationField: () => annotationField,
23
+ axisPosition: () => axisPosition,
24
+ axisRange: () => axisRange,
25
+ createPointPulse: () => createPointPulse,
26
+ finiteValue: () => finiteValue,
27
+ formatNumber: () => formatNumber,
28
+ getDimOpacity: () => getDimOpacity,
29
+ numericRows: () => numericRows,
30
+ quantileValue: () => quantileValue,
31
+ selectExtreme: () => selectExtreme,
32
+ selectLocalExtrema: () => selectLocalExtrema,
33
+ selectRange: () => selectRange,
34
+ selectRank: () => selectRank,
35
+ selectRows: () => selectRows,
36
+ selectedRows: () => selectedRows
37
+ });
38
+ module.exports = __toCommonJS(utils_exports);
39
+ function selectRows(data, selectors) {
40
+ if (selectors === void 0)
41
+ return data;
42
+ const targets = Array.isArray(selectors) ? selectors : [selectors];
43
+ if (!targets.length)
44
+ throw new Error("Invalid annotation: selection needs target data.");
45
+ const selected = /* @__PURE__ */ new Set();
46
+ for (const target of targets) {
47
+ if (!target || typeof target !== "object" || Array.isArray(target) || !Object.keys(target).length)
48
+ throw new Error("Invalid annotation: selection needs a nonempty original-field selector.");
49
+ const entries = Object.entries(target);
50
+ if (data.length && entries.some(([key]) => !data.some((row) => Object.hasOwn(row, key))))
51
+ throw new Error("Invalid annotation: selection contains an unknown field.");
52
+ const matches = data.filter(
53
+ (row) => entries.every(([key, value]) => row[key] === value)
54
+ );
55
+ if (data.length && !matches.length)
56
+ throw new Error("Invalid annotation: selection matches no data.");
57
+ matches.forEach((row) => selected.add(row));
58
+ }
59
+ return data.filter((row) => selected.has(row));
60
+ }
61
+ function numericRows(data, field, temporal = false) {
62
+ if (!field || data.length && !data.some((row) => Object.hasOwn(row, field)))
63
+ throw new Error(`Invalid annotation: unknown numeric field ${field}.`);
64
+ return data.flatMap((row) => {
65
+ const raw = row[field];
66
+ if (raw === null || raw === void 0 || typeof raw === "number" && !Number.isFinite(raw))
67
+ return [];
68
+ const value = temporal && typeof raw === "string" && /^\d{4}-\d{2}-\d{2}(?:T|$)/.test(raw) ? Date.parse(raw) : raw;
69
+ if (typeof value !== "number" || !Number.isFinite(value))
70
+ throw new Error(
71
+ `Invalid annotation: ${field} requires finite numeric${temporal ? " or ISO date" : ""} values.`
72
+ );
73
+ return [{ row, value }];
74
+ });
75
+ }
76
+ function selectExtreme(data, field, maximum, temporal = false) {
77
+ const values = numericRows(data, field, temporal);
78
+ const extreme = values.reduce(
79
+ (result, { value }) => maximum ? Math.max(result, value) : Math.min(result, value),
80
+ maximum ? -Infinity : Infinity
81
+ );
82
+ return values.filter(({ value }) => value === extreme).map(({ row }) => row);
83
+ }
84
+ function selectRank(data, field, n, descending) {
85
+ if (!Number.isSafeInteger(n) || n < 1)
86
+ throw new Error("Invalid annotation: n must be a positive integer.");
87
+ return numericRows(data, field).sort((a, b) => descending ? b.value - a.value : a.value - b.value).slice(0, n).map(({ row }) => row);
88
+ }
89
+ function selectRange(data, field, range, outside) {
90
+ if (!Array.isArray(range) || range.length !== 2 || !range.every(Number.isFinite) || range[0] > range[1])
91
+ throw new Error("Invalid annotation: range needs two finite, ordered bounds.");
92
+ return numericRows(data, field).filter(
93
+ ({ value }) => outside ? value < range[0] || value > range[1] : value >= range[0] && value <= range[1]
94
+ ).map(({ row }) => row);
95
+ }
96
+ function selectedRows(data, selectors) {
97
+ if (selectors === void 0)
98
+ throw new Error("Invalid annotation: selection needs target data.");
99
+ return selectRows(data, selectors);
100
+ }
101
+ function selectLocalExtrema(data, field, maximum, series, { minProminence = 0, minDistance = 1 } = {}) {
102
+ if (!Number.isFinite(minProminence) || minProminence < 0)
103
+ throw new Error("Invalid annotation: minProminence must be nonnegative and finite.");
104
+ if (!Number.isSafeInteger(minDistance) || minDistance < 1)
105
+ throw new Error("Invalid annotation: minDistance must be a positive integer in observations.");
106
+ const sign = maximum ? 1 : -1;
107
+ const values = new Map(numericRows(data, field).map(({ row, value }) => [row, value]));
108
+ const groups = /* @__PURE__ */ new Map();
109
+ for (const row of data) {
110
+ const key = series ? row[series] : void 0;
111
+ if (!groups.has(key))
112
+ groups.set(key, []);
113
+ groups.get(key).push(row);
114
+ }
115
+ const selected = /* @__PURE__ */ new Set();
116
+ for (const rows of groups.values()) {
117
+ const candidates = [];
118
+ for (let start = 1; start < rows.length - 1; ) {
119
+ const value = values.get(rows[start]);
120
+ if (value === void 0) {
121
+ start++;
122
+ continue;
123
+ }
124
+ let end = start;
125
+ while (end + 1 < rows.length && values.get(rows[end + 1]) === value)
126
+ end++;
127
+ const left = values.get(rows[start - 1]);
128
+ const right = values.get(rows[end + 1]);
129
+ if (left !== void 0 && right !== void 0 && (maximum ? value > left && value > right : value < left && value < right)) {
130
+ const height = sign * value;
131
+ const base = (from, step) => {
132
+ let minimum = height;
133
+ for (let i = from; i >= 0 && i < rows.length; i += step) {
134
+ const current = values.get(rows[i]);
135
+ if (current === void 0 || sign * current > height)
136
+ break;
137
+ minimum = Math.min(minimum, sign * current);
138
+ }
139
+ return minimum;
140
+ };
141
+ candidates.push({
142
+ index: Math.floor((start + end) / 2),
143
+ height,
144
+ prominence: minProminence === 0 ? 0 : height - Math.max(base(start - 1, -1), base(end + 1, 1))
145
+ });
146
+ }
147
+ start = end + 1;
148
+ }
149
+ const spaced = minDistance === 1 ? candidates : [];
150
+ if (minDistance > 1) {
151
+ for (const candidate of candidates.sort((a, b) => b.height - a.height || a.index - b.index)) {
152
+ if (spaced.every(({ index }) => Math.abs(index - candidate.index) >= minDistance))
153
+ spaced.push(candidate);
154
+ }
155
+ }
156
+ for (const candidate of spaced)
157
+ if (candidate.prominence >= minProminence)
158
+ selected.add(rows[candidate.index]);
159
+ }
160
+ return data.filter((row) => selected.has(row));
161
+ }
162
+ function getDimOpacity(annotations, fallback) {
163
+ let dim = 1;
164
+ for (const { style } of annotations) {
165
+ const opacity = (style == null ? void 0 : style.dimOpacity) ?? fallback;
166
+ if (!Number.isFinite(opacity) || opacity < 0 || opacity > 1)
167
+ throw new Error("Invalid annotation: dimOpacity must be between 0 and 1.");
168
+ dim = Math.min(dim, opacity);
169
+ }
170
+ return dim;
171
+ }
172
+ function quantileValue(values, p) {
173
+ if (!Number.isFinite(p) || p < 0 || p > 1)
174
+ throw new Error("Invalid annotation: quantile p must be between 0 and 1.");
175
+ const index = (values.length - 1) * p;
176
+ const a = values[Math.floor(index)];
177
+ const b = values[Math.ceil(index)];
178
+ const t = index - Math.floor(index);
179
+ return Number.isFinite(b - a) ? a + (b - a) * t : a * (1 - t) + b * t;
180
+ }
181
+ function finiteValue(value, name) {
182
+ if (typeof value !== "number" || !Number.isFinite(value))
183
+ throw new Error(`Invalid annotation: ${name} must be finite.`);
184
+ return value;
185
+ }
186
+ function annotationField(mapping, axis = "y") {
187
+ if (axis !== "x" && axis !== "y")
188
+ throw new Error("Invalid annotation: axis must be x or y.");
189
+ return mapping[axis];
190
+ }
191
+ function axisPosition(field, value) {
192
+ if (typeof value === "number")
193
+ finiteValue(value, field);
194
+ else if (typeof value !== "string" || !value.length)
195
+ throw new Error("Invalid annotation: axis positions need a number or nonempty string.");
196
+ return { [field]: value };
197
+ }
198
+ function axisRange(field, bounds) {
199
+ if (!Array.isArray(bounds) || bounds.length !== 2)
200
+ throw new Error("Invalid annotation: range needs two boundary values.");
201
+ for (const value of bounds)
202
+ axisPosition(field, value);
203
+ if (typeof bounds[0] !== typeof bounds[1])
204
+ throw new Error("Invalid annotation: range boundaries must have the same type.");
205
+ if (typeof bounds[0] === "number" && bounds[0] > bounds[1])
206
+ throw new Error("Invalid annotation: numeric range bounds must be ordered.");
207
+ return { [field]: bounds };
208
+ }
209
+ function formatNumber(value) {
210
+ return new Intl.NumberFormat("en-US", { maximumFractionDigits: 4 }).format(value);
211
+ }
212
+ function createPointPulse(scene, defaults, redraw) {
213
+ const rings = /* @__PURE__ */ new Set();
214
+ const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
215
+ const clear = () => {
216
+ for (const ring of rings)
217
+ ring.destroy();
218
+ rings.clear();
219
+ };
220
+ motion.addEventListener("change", redraw);
221
+ return {
222
+ add(parent, [x, y], size, color, animated = true) {
223
+ const ring = scene.createElement("circle", {
224
+ className: "annotation-pulse",
225
+ style: {
226
+ cx: x,
227
+ cy: y,
228
+ r: size * defaults.staticScale,
229
+ stroke: color,
230
+ fill: "none",
231
+ lineWidth: defaults.lineWidth,
232
+ opacity: defaults.opacity,
233
+ pointerEvents: "none",
234
+ zIndex: -1
235
+ }
236
+ });
237
+ parent.appendChild(ring);
238
+ rings.add(ring);
239
+ if (!animated || motion.matches)
240
+ return;
241
+ const animation = ring.animate(
242
+ [
243
+ { r: size * defaults.startScale, opacity: defaults.opacity },
244
+ { r: size * defaults.endScale, opacity: 0 }
245
+ ],
246
+ { duration: defaults.duration, iterations: Infinity, easing: "ease-out" }
247
+ );
248
+ if (animation)
249
+ animation.currentTime = performance.now() % defaults.duration;
250
+ },
251
+ clear,
252
+ destroy() {
253
+ motion.removeEventListener("change", redraw);
254
+ clear();
255
+ }
256
+ };
257
+ }
258
+ // Annotate the CommonJS export names for ESM import in node:
259
+ 0 && (module.exports = {
260
+ annotationField,
261
+ axisPosition,
262
+ axisRange,
263
+ createPointPulse,
264
+ finiteValue,
265
+ formatNumber,
266
+ getDimOpacity,
267
+ numericRows,
268
+ quantileValue,
269
+ selectExtreme,
270
+ selectLocalExtrema,
271
+ selectRange,
272
+ selectRank,
273
+ selectRows,
274
+ selectedRows
275
+ });
@@ -0,0 +1,236 @@
1
+ import type { ChartType, ThemeStyle, VisualizationTheme } from '../types';
2
+ import type { getThemeObject } from './g2';
3
+ /** Graph and DOM annotations follow their chart's theme and local styles. */
4
+ export declare function getAnnotationDefaults(type: ChartType, theme?: VisualizationTheme, localStyle?: ThemeStyle): {
5
+ stroke: string;
6
+ pointStroke: string;
7
+ lineWidth: {
8
+ path: number;
9
+ connector: number;
10
+ point: number;
11
+ };
12
+ size: number;
13
+ shape: string;
14
+ pulse: {
15
+ duration: number;
16
+ startScale: number;
17
+ endScale: number;
18
+ staticScale: number;
19
+ opacity: number;
20
+ lineWidth: number;
21
+ };
22
+ connector: {
23
+ offset: number;
24
+ extension: number;
25
+ curveRatio: number;
26
+ maxCurveHeight: number;
27
+ arrowSize: number;
28
+ };
29
+ labelFill: string;
30
+ fontFamily: string;
31
+ labelFontSize: number;
32
+ fontWeight: number | "normal" | "bold";
33
+ labels: {
34
+ path: {
35
+ padding: number[];
36
+ backgroundOpacity: number;
37
+ fill: string;
38
+ background: string;
39
+ border: string;
40
+ borderOpacity: number;
41
+ radius: number;
42
+ maxWidth: number;
43
+ gap: number;
44
+ fontWeight: number | "normal" | "bold";
45
+ };
46
+ range: {
47
+ border: string;
48
+ borderOpacity: number;
49
+ backgroundOpacity: number;
50
+ fill: string;
51
+ background: string;
52
+ padding: number[];
53
+ radius: number;
54
+ maxWidth: number;
55
+ gap: number;
56
+ fontWeight: number | "normal" | "bold";
57
+ };
58
+ connector: {
59
+ padding: number[];
60
+ fontWeight: number;
61
+ fill: string;
62
+ background: string;
63
+ backgroundOpacity: number;
64
+ border: string;
65
+ borderOpacity: number;
66
+ radius: number;
67
+ maxWidth: number;
68
+ gap: number;
69
+ };
70
+ point: {
71
+ border: string;
72
+ padding: number[];
73
+ radius: number;
74
+ maxWidth: number;
75
+ gap: number;
76
+ fontWeight: number;
77
+ fill: string;
78
+ background: string;
79
+ backgroundOpacity: number;
80
+ borderOpacity: number;
81
+ };
82
+ text: {
83
+ background: string;
84
+ padding: number[];
85
+ maxWidth: number;
86
+ gap: number;
87
+ fill: string;
88
+ backgroundOpacity: number;
89
+ border: string;
90
+ borderOpacity: number;
91
+ radius: number;
92
+ fontWeight: number | "normal" | "bold";
93
+ };
94
+ highlight: {
95
+ border: string;
96
+ padding: number[];
97
+ gap: number;
98
+ fill: string;
99
+ background: string;
100
+ backgroundOpacity: number;
101
+ borderOpacity: number;
102
+ radius: number;
103
+ maxWidth: number;
104
+ fontWeight: number | "normal" | "bold";
105
+ };
106
+ };
107
+ highlight: {
108
+ color: string;
109
+ fillOpacity: number;
110
+ dimOpacity: number;
111
+ background: string;
112
+ labelBackground: string;
113
+ labelBorder: string;
114
+ labelGap: number;
115
+ contributionDimOpacity: number;
116
+ pieDimOpacity: number;
117
+ lineWidth: number;
118
+ };
119
+ };
120
+ /** Annotation defaults follow the resolved chart theme. */
121
+ export declare function getAnnotationStyle({ theme, mark }: ReturnType<typeof getThemeObject>): {
122
+ palette: string[];
123
+ directions: {
124
+ up: string;
125
+ down: string;
126
+ };
127
+ stroke: string;
128
+ pointStroke: string;
129
+ lineWidth: {
130
+ path: number;
131
+ range: number;
132
+ connector: number;
133
+ point: number;
134
+ };
135
+ fillOpacity: number;
136
+ size: number;
137
+ shape: string;
138
+ pulse: {
139
+ duration: number;
140
+ startScale: number;
141
+ endScale: number;
142
+ staticScale: number;
143
+ opacity: number;
144
+ lineWidth: number;
145
+ };
146
+ connector: {
147
+ offset: number;
148
+ extension: number;
149
+ curveRatio: number;
150
+ maxCurveHeight: number;
151
+ arrowSize: number;
152
+ };
153
+ highlight: {
154
+ color: string;
155
+ dimOpacity: number;
156
+ contributionDimOpacity: number;
157
+ pieDimOpacity: number;
158
+ lineWidth: number;
159
+ };
160
+ fontFamily: string;
161
+ labelFontSize: number;
162
+ labels: {
163
+ path: {
164
+ padding: number[];
165
+ backgroundOpacity: number;
166
+ fill: string;
167
+ background: string;
168
+ border: string;
169
+ borderOpacity: number;
170
+ radius: number;
171
+ maxWidth: number;
172
+ gap: number;
173
+ fontWeight: number | "normal" | "bold";
174
+ };
175
+ range: {
176
+ border: string;
177
+ borderOpacity: number;
178
+ backgroundOpacity: number;
179
+ fill: string;
180
+ background: string;
181
+ padding: number[];
182
+ radius: number;
183
+ maxWidth: number;
184
+ gap: number;
185
+ fontWeight: number | "normal" | "bold";
186
+ };
187
+ connector: {
188
+ padding: number[];
189
+ fontWeight: number;
190
+ fill: string;
191
+ background: string;
192
+ backgroundOpacity: number;
193
+ border: string;
194
+ borderOpacity: number;
195
+ radius: number;
196
+ maxWidth: number;
197
+ gap: number;
198
+ };
199
+ point: {
200
+ border: string;
201
+ padding: number[];
202
+ radius: number;
203
+ maxWidth: number;
204
+ gap: number;
205
+ fontWeight: number;
206
+ fill: string;
207
+ background: string;
208
+ backgroundOpacity: number;
209
+ borderOpacity: number;
210
+ };
211
+ text: {
212
+ background: string;
213
+ padding: number[];
214
+ maxWidth: number;
215
+ gap: number;
216
+ fill: string;
217
+ backgroundOpacity: number;
218
+ border: string;
219
+ borderOpacity: number;
220
+ radius: number;
221
+ fontWeight: number | "normal" | "bold";
222
+ };
223
+ highlight: {
224
+ border: string;
225
+ padding: number[];
226
+ gap: number;
227
+ fill: string;
228
+ background: string;
229
+ backgroundOpacity: number;
230
+ borderOpacity: number;
231
+ radius: number;
232
+ maxWidth: number;
233
+ fontWeight: number | "normal" | "bold";
234
+ };
235
+ };
236
+ };
@@ -0,0 +1,167 @@
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/theme/annotation.ts
20
+ var annotation_exports = {};
21
+ __export(annotation_exports, {
22
+ getAnnotationDefaults: () => getAnnotationDefaults,
23
+ getAnnotationStyle: () => getAnnotationStyle
24
+ });
25
+ module.exports = __toCommonJS(annotation_exports);
26
+ var import_tokens = require("../util/tokens");
27
+ var import_merge = require("./merge");
28
+ var import_resolve = require("./resolve");
29
+ var import_shared = require("./shared");
30
+ var pointPulse = {
31
+ duration: 1800,
32
+ startScale: 1.5,
33
+ endScale: 3,
34
+ staticScale: 2.2,
35
+ opacity: 0.32,
36
+ lineWidth: 1
37
+ };
38
+ var connector = {
39
+ offset: 24,
40
+ extension: 4,
41
+ curveRatio: 0.12,
42
+ maxCurveHeight: 40,
43
+ arrowSize: 9
44
+ };
45
+ var highlight = {
46
+ dimOpacity: 0.16,
47
+ contributionDimOpacity: 0.16,
48
+ pieDimOpacity: 0.16,
49
+ lineWidth: 2
50
+ };
51
+ function getLabelStyles({
52
+ surface,
53
+ border,
54
+ accent,
55
+ text,
56
+ fontWeight,
57
+ radius
58
+ }) {
59
+ const base = {
60
+ fill: text,
61
+ background: surface,
62
+ backgroundOpacity: 1,
63
+ border: "none",
64
+ borderOpacity: 1,
65
+ padding: [3, 6],
66
+ radius: Math.min(radius, 4),
67
+ maxWidth: 200,
68
+ gap: 8,
69
+ fontWeight
70
+ };
71
+ return {
72
+ path: { ...base, padding: [2, 4], backgroundOpacity: 0.94 },
73
+ range: { ...base, border: accent, borderOpacity: 0.3, backgroundOpacity: 0.94 },
74
+ connector: { ...base, padding: [3, 6], fontWeight: 500 },
75
+ point: { ...base, border, padding: [8, 10], radius, maxWidth: 220, gap: 12, fontWeight: 500 },
76
+ text: { ...base, background: "none", padding: [0, 0], maxWidth: 260, gap: 0 },
77
+ highlight: { ...base, border, padding: [4, 7], gap: 10 }
78
+ };
79
+ }
80
+ function getAnnotationDefaults(type, theme, localStyle) {
81
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
82
+ const { baseTheme, tokens, styles } = (0, import_resolve.resolveTheme)(type, theme, localStyle);
83
+ const style = (0, import_merge.mergeTheme)({}, ...styles);
84
+ const visual = (0, import_tokens.getChartVisualTokens)(baseTheme);
85
+ const palette = (0, import_shared.normalizePalette)(style.palette, baseTheme);
86
+ const stroke = palette[0];
87
+ const labelFill = ((_a = style.label) == null ? void 0 : _a.fill) ?? tokens.colorText ?? visual.textPrimary;
88
+ const fontWeight = ((_b = style.label) == null ? void 0 : _b.fontWeight) ?? tokens.fontWeight ?? 400;
89
+ return {
90
+ stroke,
91
+ pointStroke: ((_d = (_c = style.mark) == null ? void 0 : _c.point) == null ? void 0 : _d.stroke) ?? style.backgroundColor ?? visual.background,
92
+ lineWidth: {
93
+ path: ((_f = (_e = style.mark) == null ? void 0 : _e.line) == null ? void 0 : _f.lineWidth) ?? tokens.lineWidth ?? 1.5,
94
+ connector: ((_h = (_g = style.mark) == null ? void 0 : _g.connector) == null ? void 0 : _h.lineWidth) ?? tokens.lineWidth ?? 2,
95
+ point: ((_j = (_i = style.mark) == null ? void 0 : _i.point) == null ? void 0 : _j.lineWidth) ?? tokens.lineWidth ?? 1.5
96
+ },
97
+ size: ((_l = (_k = style.mark) == null ? void 0 : _k.point) == null ? void 0 : _l.size) ?? import_tokens.CHART_STYLE_DEFAULTS.scatterPointSize,
98
+ shape: ((_n = (_m = style.mark) == null ? void 0 : _m.point) == null ? void 0 : _n.shape) ?? "point",
99
+ pulse: pointPulse,
100
+ connector,
101
+ labelFill,
102
+ fontFamily: ((_o = style.label) == null ? void 0 : _o.fontFamily) ?? tokens.fontFamily ?? import_tokens.CHART_FONT_FAMILY,
103
+ labelFontSize: ((_p = style.label) == null ? void 0 : _p.fontSize) ?? tokens.fontSize ?? 12,
104
+ fontWeight,
105
+ labels: getLabelStyles({
106
+ surface: tokens.colorSurface ?? style.backgroundColor ?? visual.tooltipBackground,
107
+ border: tokens.colorStroke ?? visual.tooltipBorder,
108
+ accent: stroke,
109
+ text: labelFill,
110
+ fontWeight,
111
+ radius: tokens.radius ?? 6
112
+ }),
113
+ highlight: {
114
+ ...highlight,
115
+ color: palette[1] ?? stroke,
116
+ fillOpacity: 0.16,
117
+ dimOpacity: type === "table" || type === "summary" ? 1 : highlight.dimOpacity,
118
+ background: style.backgroundColor ?? visual.background,
119
+ labelBackground: visual.tooltipBackground,
120
+ labelBorder: visual.tooltipBorder,
121
+ labelGap: 16
122
+ }
123
+ };
124
+ }
125
+ function getAnnotationStyle({ theme, mark }) {
126
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
127
+ const shape = mark.point.shape ?? "point";
128
+ const palette = theme.category10;
129
+ const visual = (0, import_tokens.getChartVisualTokens)(theme.type);
130
+ const tooltip = ((_a = theme.tooltip) == null ? void 0 : _a.css)[".g2-tooltip"];
131
+ return {
132
+ palette,
133
+ directions: {
134
+ up: theme.type === "dark" ? "#4ade80" : "#16a34a",
135
+ down: theme.type === "dark" ? "#f87171" : "#dc2626"
136
+ },
137
+ stroke: palette[0],
138
+ pointStroke: mark.point.stroke ?? theme.view.viewFill,
139
+ lineWidth: {
140
+ path: mark.line.lineWidth ?? ((_c = (_b = theme.line) == null ? void 0 : _b.line) == null ? void 0 : _c.lineWidth) ?? import_tokens.CHART_STYLE_DEFAULTS.lineWidth,
141
+ range: mark.interval.lineWidth ?? ((_e = (_d = theme.interval) == null ? void 0 : _d.rect) == null ? void 0 : _e.lineWidth) ?? 1.5,
142
+ connector: mark.connector.lineWidth ?? ((_g = (_f = theme.connector) == null ? void 0 : _f.connector) == null ? void 0 : _g.lineWidth) ?? 2,
143
+ point: mark.point.lineWidth ?? ((_i = (_h = theme.point) == null ? void 0 : _h[shape]) == null ? void 0 : _i.lineWidth) ?? ((_k = (_j = theme.point) == null ? void 0 : _j.point) == null ? void 0 : _k.lineWidth) ?? import_tokens.CHART_STYLE_DEFAULTS.pointLineWidth
144
+ },
145
+ fillOpacity: 0.12,
146
+ size: mark.point.size ?? import_tokens.CHART_STYLE_DEFAULTS.scatterPointSize,
147
+ shape,
148
+ pulse: pointPulse,
149
+ connector,
150
+ highlight: { ...highlight, color: palette[1] ?? palette[0] },
151
+ fontFamily: ((_l = theme.label) == null ? void 0 : _l.fontFamily) ?? ((_m = theme.axis) == null ? void 0 : _m.labelFontFamily) ?? import_tokens.CHART_FONT_FAMILY,
152
+ labelFontSize: ((_n = theme.label) == null ? void 0 : _n.fontSize) ?? ((_o = theme.axis) == null ? void 0 : _o.labelFontSize) ?? 12,
153
+ labels: getLabelStyles({
154
+ surface: tooltip["background-color"] ?? visual.tooltipBackground,
155
+ border: ((_p = theme.axis) == null ? void 0 : _p.lineStroke) ?? visual.tooltipBorder,
156
+ accent: palette[0],
157
+ text: (_q = theme.label) == null ? void 0 : _q.fill,
158
+ fontWeight: ((_r = theme.label) == null ? void 0 : _r.fontWeight) ?? 400,
159
+ radius: Number.parseFloat(String(tooltip["border-radius"] ?? 6))
160
+ })
161
+ };
162
+ }
163
+ // Annotate the CommonJS export names for ESM import in node:
164
+ 0 && (module.exports = {
165
+ getAnnotationDefaults,
166
+ getAnnotationStyle
167
+ });