@antv/gpt-vis 1.3.2 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +12 -3
  136. package/dist/cjs/vis/summary/index.js +29 -11
  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 +12 -3
  276. package/dist/esm/vis/summary/index.js +35 -16
  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,75 @@
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/components/centroid.ts
20
+ var centroid_exports = {};
21
+ __export(centroid_exports, {
22
+ centroid: () => centroid
23
+ });
24
+ module.exports = __toCommonJS(centroid_exports);
25
+ var import_utils = require("../utils");
26
+ var import_point = require("./point");
27
+ var centroid = {
28
+ g2: (annotations, { mapping, defaults }) => annotations.flatMap((annotation) => {
29
+ var _a, _b, _c, _d;
30
+ const rows = (0, import_utils.selectRows)(mapping.data, annotation.data);
31
+ const xs = (0, import_utils.numericRows)(rows, mapping.x);
32
+ const ys = new Set((0, import_utils.numericRows)(rows, mapping.y).map(({ row }) => row));
33
+ const selected = xs.filter(({ row }) => ys.has(row)).map(({ row }) => row);
34
+ if (!selected.length)
35
+ return [];
36
+ const weights = selected.map(
37
+ (row) => annotation.weight === void 0 ? 1 : (0, import_utils.finiteValue)(row[annotation.weight], "weight")
38
+ );
39
+ if (weights.some((weight) => weight < 0))
40
+ throw new Error("Invalid annotation: centroid weights must be nonnegative.");
41
+ const max = weights.reduce((a, b) => Math.max(a, b), 0);
42
+ if (max === 0)
43
+ throw new Error("Invalid annotation: centroid needs positive total weight.");
44
+ const normalized = weights.map((weight) => weight / max);
45
+ const total = normalized.reduce((a, b) => a + b, 0);
46
+ const center = (field) => {
47
+ const values = selected.map((row) => (0, import_utils.finiteValue)(row[field], field));
48
+ const scale = values.reduce((a, b) => Math.max(a, Math.abs(b)), 0);
49
+ return scale === 0 ? 0 : values.reduce((sum, value, i) => sum + value / scale * (normalized[i] / total), 0) * scale;
50
+ };
51
+ return import_point.point.create(
52
+ {
53
+ data: { [mapping.x]: center(mapping.x), [mapping.y]: center(mapping.y) },
54
+ label: annotation.label ?? (annotation.weight === void 0 ? "Center" : "Weighted center"),
55
+ pulse: annotation.pulse ?? false,
56
+ style: {
57
+ ...annotation.style,
58
+ size: ((_a = annotation.style) == null ? void 0 : _a.size) ?? Math.max(defaults.size, 7),
59
+ lineWidth: ((_b = annotation.style) == null ? void 0 : _b.lineWidth) ?? 2,
60
+ fill: ((_c = annotation.style) == null ? void 0 : _c.fill) ?? "none"
61
+ }
62
+ },
63
+ {
64
+ shape: "plus",
65
+ outline: ((_d = annotation.style) == null ? void 0 : _d.stroke) ?? defaults.stroke,
66
+ halo: annotation.pulse === true,
67
+ zIndex: 2
68
+ }
69
+ );
70
+ })
71
+ };
72
+ // Annotate the CommonJS export names for ESM import in node:
73
+ 0 && (module.exports = {
74
+ centroid
75
+ });
@@ -0,0 +1,25 @@
1
+ import type { Annotation } from '../../types/annotation';
2
+ import type { Point } from '../layout';
3
+ import type { AnnotationComponent } from '../registry';
4
+ /** Connector geometry, arrows and label anchors are shared by the native G2 and G6 scenes. */
5
+ export declare const connector: AnnotationComponent<'connector', 'g2' | 'g6'> & {
6
+ create: typeof createConnector;
7
+ brace: typeof brace;
8
+ arc: typeof arc;
9
+ };
10
+ declare function createConnector<T extends object>(options: Omit<Extract<Annotation<T>, {
11
+ type: 'connector';
12
+ }>, 'type'>): Extract<Annotation<T>, {
13
+ type: 'connector';
14
+ }>[];
15
+ export interface ConnectorShape {
16
+ paths: Point[][];
17
+ anchor: Point;
18
+ direction: Point;
19
+ labelAnchor?: Point;
20
+ }
21
+ /** A brace between screen-space endpoints, with its anchor at the central cusp. */
22
+ declare function brace(a: Point, b: Point, side: 'top' | 'right'): ConnectorShape;
23
+ /** An offset arc with end caps; angles are measured in turns, including across the seam. */
24
+ declare function arc(center: Point, project: (angle: number) => Point, [start, end]: Point, offset?: number): ConnectorShape;
25
+ export {};
@@ -0,0 +1,298 @@
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/components/connector.ts
20
+ var connector_exports = {};
21
+ __export(connector_exports, {
22
+ connector: () => connector
23
+ });
24
+ module.exports = __toCommonJS(connector_exports);
25
+ var connector = {
26
+ create: createConnector,
27
+ brace,
28
+ arc,
29
+ g2: () => drawG2,
30
+ g6: () => drawG6
31
+ };
32
+ function createConnector(options) {
33
+ return [{ ...options, type: "connector" }];
34
+ }
35
+ var drawG2 = (annotations, context) => {
36
+ return {
37
+ marks: annotations.map((annotation) => {
38
+ var _a;
39
+ const { defaults } = context;
40
+ const paint = getPaint(annotation.style, defaults);
41
+ let geometry;
42
+ return context.createMark(annotation, {
43
+ nativeType: "link",
44
+ style: { ...paint, fill: "none" },
45
+ draw: (scene) => createConnectorShape(scene, geometry, paint, defaults.connector),
46
+ decorate: (element) => element.setAttribute("annotationSegments", geometry.segments),
47
+ label: {
48
+ annotationAnchor: () => geometry.anchor,
49
+ fill: ((_a = annotation.style) == null ? void 0 : _a.labelFill) ?? paint.stroke,
50
+ position: "inside"
51
+ },
52
+ geometry: (native) => (_index, scale, value, coordinate) => {
53
+ const points = annotation.data.map((datum) => context.position(datum, coordinate));
54
+ if (points.some((point) => !point))
55
+ return [[], []];
56
+ const [from, to] = points;
57
+ geometry = getConnectorGeometry(
58
+ coordinate.map(from),
59
+ coordinate.map(to),
60
+ annotation,
61
+ coordinate.getSize(),
62
+ defaults.connector
63
+ );
64
+ return native(
65
+ [0],
66
+ scale,
67
+ {
68
+ ...value,
69
+ x: [from[0]],
70
+ y: [from[1]],
71
+ x1: [to[0]],
72
+ y1: [to[1]]
73
+ },
74
+ coordinate
75
+ );
76
+ }
77
+ });
78
+ })
79
+ };
80
+ };
81
+ var drawG6 = (annotations, context) => {
82
+ for (const annotation of annotations) {
83
+ const positions = annotation.data.map((datum) => context.position(datum));
84
+ if (positions.some((point) => !point))
85
+ continue;
86
+ const [a, b] = positions;
87
+ const { defaults } = context;
88
+ const paint = getPaint(annotation.style, defaults);
89
+ const geometry = getConnectorGeometry(a, b, annotation, context.size, defaults.connector);
90
+ context.segments.push(...geometry.segments);
91
+ const shape = createConnectorShape(context.scene, geometry, paint, defaults.connector);
92
+ shape.className = "annotation-mark";
93
+ context.root.appendChild(shape);
94
+ context.label(annotation, geometry.anchor, {
95
+ fill: paint.stroke
96
+ });
97
+ }
98
+ return {};
99
+ };
100
+ function getPaint(style, defaults) {
101
+ return {
102
+ stroke: (style == null ? void 0 : style.stroke) ?? defaults.stroke,
103
+ lineWidth: (style == null ? void 0 : style.lineWidth) ?? defaults.lineWidth.connector,
104
+ lineDash: style == null ? void 0 : style.lineDash
105
+ };
106
+ }
107
+ function getConnectorGeometry(a, b, { shape = "line", orientation }, [width, height], defaults) {
108
+ let points = [a, b];
109
+ let path = [
110
+ ["M", ...a],
111
+ ["L", ...b]
112
+ ];
113
+ const guides = [];
114
+ let anchor = [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2];
115
+ const guideSegments = [];
116
+ const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
117
+ if (shape === "curve" && length) {
118
+ let nx = (b[1] - a[1]) / length;
119
+ let ny = (a[0] - b[0]) / length;
120
+ if (ny > 0 || ny === 0 && nx > 0) {
121
+ nx = -nx;
122
+ ny = -ny;
123
+ }
124
+ const bend = Math.min(defaults.maxCurveHeight, length * defaults.curveRatio);
125
+ if (anchor[0] + nx * bend * 2 < 0 || anchor[0] + nx * bend * 2 > width || anchor[1] + ny * bend * 2 < 0 || anchor[1] + ny * bend * 2 > height) {
126
+ nx = -nx;
127
+ ny = -ny;
128
+ }
129
+ const control = [anchor[0] + nx * bend * 2, anchor[1] + ny * bend * 2];
130
+ path = [
131
+ ["M", ...a],
132
+ ["Q", ...control, ...b]
133
+ ];
134
+ points = Array.from({ length: 17 }, (_, i) => {
135
+ const t = i / 16;
136
+ return [0, 1].map(
137
+ (axis) => (1 - t) ** 2 * a[axis] + 2 * (1 - t) * t * control[axis] + t ** 2 * b[axis]
138
+ );
139
+ });
140
+ anchor = points[8];
141
+ } else if (shape === "dimension" || shape === "bracket") {
142
+ const horizontal = (orientation ?? (shape === "dimension" ? "vertical" : "horizontal")) === "horizontal";
143
+ const cross = horizontal ? 1 : 0;
144
+ let side = horizontal ? -1 : 1;
145
+ let lane = (side < 0 ? Math.min(a[cross], b[cross]) : Math.max(a[cross], b[cross])) + side * defaults.offset;
146
+ if (lane < 0 || lane > (horizontal ? height : width)) {
147
+ side = -side;
148
+ lane = (side < 0 ? Math.min(a[cross], b[cross]) : Math.max(a[cross], b[cross])) + side * defaults.offset;
149
+ }
150
+ lane = Math.max(0, Math.min(horizontal ? height : width, lane));
151
+ const p = horizontal ? [a[0], lane] : [lane, a[1]];
152
+ const q = horizontal ? [b[0], lane] : [lane, b[1]];
153
+ anchor = [(p[0] + q[0]) / 2, (p[1] + q[1]) / 2];
154
+ if (shape === "bracket") {
155
+ points = [a, p, q, b];
156
+ path = points.map(([x, y], i) => [i ? "L" : "M", x, y]);
157
+ } else {
158
+ points = [p, q];
159
+ path = [
160
+ ["M", ...p],
161
+ ["L", ...q]
162
+ ];
163
+ for (const [source, target] of [
164
+ [a, p],
165
+ [b, q]
166
+ ]) {
167
+ const end = [...target];
168
+ end[cross] += Math.sign(target[cross] - source[cross]) * defaults.extension;
169
+ guides.push(["M", ...source], ["L", ...end]);
170
+ guideSegments.push([source, end]);
171
+ }
172
+ }
173
+ }
174
+ return {
175
+ path,
176
+ guides,
177
+ anchor,
178
+ points,
179
+ segments: [...points.slice(1).map((point, i) => [points[i], point]), ...guideSegments],
180
+ arrows: shape === "bracket" ? "none" : shape === "dimension" ? "both" : "end"
181
+ };
182
+ }
183
+ function createConnectorShape(scene, geometry, paint, defaults) {
184
+ const group = scene.createElement("g", { style: { pointerEvents: "none" } });
185
+ const style = {
186
+ ...paint,
187
+ fill: "none",
188
+ pointerEvents: "none",
189
+ lineCap: "round",
190
+ lineJoin: "round"
191
+ };
192
+ const path = (attributes) => scene.createElement("path", { style: { ...style, ...attributes } });
193
+ if (geometry.guides.length)
194
+ group.appendChild(path({ d: geometry.guides, strokeOpacity: 0.5, lineWidth: 1 }));
195
+ const length = geometry.points.slice(1).reduce(
196
+ (sum, p, i) => sum + Math.hypot(p[0] - geometry.points[i][0], p[1] - geometry.points[i][1]),
197
+ 0
198
+ );
199
+ const head = Math.min(length * 0.35, Math.max(defaults.arrowSize, (paint.lineWidth ?? 0) * 3));
200
+ const marker = () => path({
201
+ lineDash: void 0,
202
+ d: [
203
+ ["M", head, -head / 2],
204
+ ["L", 0, 0],
205
+ ["L", head, head / 2]
206
+ ]
207
+ });
208
+ group.appendChild(
209
+ path({
210
+ d: geometry.path,
211
+ markerStart: length && geometry.arrows === "both" ? marker() : void 0,
212
+ markerEnd: length && geometry.arrows !== "none" ? marker() : void 0
213
+ })
214
+ );
215
+ return group;
216
+ }
217
+ function brace(a, b, side) {
218
+ const horizontal = side === "top";
219
+ const axis = horizontal ? 0 : 1;
220
+ let start = Math.min(a[axis], b[axis]);
221
+ let end = Math.max(a[axis], b[axis]);
222
+ if (end - start < 12) {
223
+ start -= 6;
224
+ end += 6;
225
+ }
226
+ const middle = (start + end) / 2;
227
+ const depth = Math.min(6, (end - start) / 6);
228
+ const edge = a[1 - axis];
229
+ const convert = ([a2, b2]) => horizontal ? [a2, edge - b2] : [edge + b2, a2];
230
+ const curves = [
231
+ [
232
+ [start, -depth],
233
+ [start, 0],
234
+ [start, 0],
235
+ [start + depth, 0]
236
+ ],
237
+ [
238
+ [start + depth, 0],
239
+ [middle - depth, 0],
240
+ [middle - depth, 0],
241
+ [middle, depth]
242
+ ],
243
+ [
244
+ [middle, depth],
245
+ [middle + depth, 0],
246
+ [middle + depth, 0],
247
+ [end - depth, 0]
248
+ ],
249
+ [
250
+ [end - depth, 0],
251
+ [end, 0],
252
+ [end, 0],
253
+ [end, -depth]
254
+ ]
255
+ ];
256
+ const path = curves.flatMap(
257
+ ([a2, b2, c, d], index) => Array.from({ length: 9 }, (_, i) => i / 8).filter((t) => !index || t > 0).map(
258
+ (t) => convert(
259
+ [0, 1].map(
260
+ (axis2) => (1 - t) ** 3 * a2[axis2] + 3 * (1 - t) ** 2 * t * b2[axis2] + 3 * (1 - t) * t * t * c[axis2] + t ** 3 * d[axis2]
261
+ )
262
+ )
263
+ )
264
+ );
265
+ return {
266
+ paths: [path],
267
+ anchor: convert([middle, depth]),
268
+ direction: horizontal ? [0, -1] : [1, 0]
269
+ };
270
+ }
271
+ function arc(center, project, [start, end], offset = 10) {
272
+ const outer = (angle, offset2) => {
273
+ const point = project(angle % 1);
274
+ const radius2 = Math.hypot(point[0] - center[0], point[1] - center[1]);
275
+ return point.map(
276
+ (value, axis) => center[axis] + (value - center[axis]) * (1 + offset2 / radius2)
277
+ );
278
+ };
279
+ const full = end - start >= 1 - 1e-6;
280
+ const trim = full ? 0 : Math.min(8e-3, (end - start) / 8);
281
+ const from = start + trim, to = end - trim;
282
+ const steps = Math.max(8, Math.ceil((to - from) * 120));
283
+ const points = Array.from(
284
+ { length: steps + 1 },
285
+ (_, i) => outer(from + (to - from) * i / steps, offset)
286
+ );
287
+ const anchor = outer((start + end) / 2, offset);
288
+ const radius = Math.hypot(anchor[0] - center[0], anchor[1] - center[1]);
289
+ return {
290
+ paths: [full ? points : [outer(from, offset - 5), ...points, outer(to, offset - 5)]],
291
+ anchor,
292
+ direction: [(anchor[0] - center[0]) / radius, (anchor[1] - center[1]) / radius]
293
+ };
294
+ }
295
+ // Annotate the CommonJS export names for ESM import in node:
296
+ 0 && (module.exports = {
297
+ connector
298
+ });
@@ -0,0 +1,3 @@
1
+ import type { AnnotationComponent } from '../registry';
2
+ /** Compute selected observations' contribution to the full input total. */
3
+ export declare const contribution: AnnotationComponent<'contribution', 'g2' | 'table'>;
@@ -0,0 +1,136 @@
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/components/contribution.ts
20
+ var contribution_exports = {};
21
+ __export(contribution_exports, {
22
+ contribution: () => contribution
23
+ });
24
+ module.exports = __toCommonJS(contribution_exports);
25
+ var import_label = require("../label");
26
+ var import_utils = require("../utils");
27
+ var import_connector = require("./connector");
28
+ var import_highlight = require("./highlight");
29
+ var contribution = {
30
+ g2: (annotations, { mapping, chartType }) => annotations.flatMap((annotation) => {
31
+ const rows = (0, import_utils.selectedRows)(mapping.data, annotation.data);
32
+ const share = contributionShare(mapping.data, rows, mapping.y);
33
+ if (share === void 0)
34
+ return [];
35
+ const highlights = import_highlight.highlight.create({
36
+ data: rows,
37
+ label: getLabel(annotation.label, share, rows.length),
38
+ style: annotation.style
39
+ });
40
+ highlights.forEach(
41
+ (highlight2) => import_label.labelConnectors.set(highlight2, contributionConnector(chartType))
42
+ );
43
+ if (rows.length === 1 && annotation.label === void 0)
44
+ highlights.forEach((highlight2) => import_label.nativePercentageLabels.add(highlight2));
45
+ return highlights;
46
+ }),
47
+ table: (annotations, { data }) => annotations.flatMap((annotation) => {
48
+ const rows = (0, import_utils.selectedRows)(data, annotation.data.row);
49
+ const share = contributionShare(data, rows, annotation.data.field);
50
+ if (share === void 0)
51
+ return [];
52
+ const highlights = import_highlight.highlight.create({
53
+ data: rows.map((row) => ({ row, column: annotation.data.column })),
54
+ label: getLabel(annotation.label, share, rows.length),
55
+ style: annotation.style
56
+ });
57
+ highlights.forEach(
58
+ (highlight2) => import_label.labelConnectors.set(highlight2, contributionConnector("bar"))
59
+ );
60
+ return highlights;
61
+ })
62
+ };
63
+ function contributionConnector(chartType) {
64
+ return (anchors, geometry, coordinate, index, count) => {
65
+ if (!anchors.length)
66
+ return void 0;
67
+ if (chartType !== "pie" || !coordinate) {
68
+ const horizontal = chartType !== "bar";
69
+ const axis = horizontal ? 0 : 1;
70
+ const measured = (["bar", "column"].includes(chartType) ? geometry.flatMap(({ points: points2 }) => points2) : []).filter((point) => point == null ? void 0 : point.every(Number.isFinite));
71
+ const points = measured.length ? measured : anchors;
72
+ const start = Math.min(...points.map((point) => point[axis]));
73
+ const end = Math.max(...points.map((point) => point[axis]));
74
+ const edge = horizontal ? Math.min(...points.map((point) => point[1])) - 12 - index * 14 : Math.max(...points.map((point) => point[0])) + 12 + index * 14;
75
+ return import_connector.connector.brace(
76
+ horizontal ? [start, edge] : [edge, start],
77
+ horizontal ? [end, edge] : [edge, end],
78
+ horizontal ? "top" : "right"
79
+ );
80
+ }
81
+ const intervals = geometry.flatMap(
82
+ ({ y, y1 }) => Number.isFinite(y) && Number.isFinite(y1) && y !== y1 ? [[Math.min(y, y1), Math.max(y, y1)]] : []
83
+ ).sort((a, b) => a[0] - b[0]);
84
+ const runs = [];
85
+ for (const [start, end] of intervals) {
86
+ const last = runs.at(-1);
87
+ if (last && start <= last[1] + 1e-6)
88
+ last[1] = Math.max(last[1], end);
89
+ else
90
+ runs.push([start, end]);
91
+ }
92
+ if (runs.length > 1 && runs[0][0] < 1e-6 && runs.at(-1)[1] > 1 - 1e-6) {
93
+ const first = runs.shift();
94
+ runs.at(-1)[1] = first[1] + 1;
95
+ }
96
+ if (!runs.length)
97
+ return void 0;
98
+ const center = coordinate.getCenter();
99
+ const shapes = runs.map(
100
+ (run) => import_connector.connector.arc(center, (angle) => coordinate.map([0, angle]), run, 10 + index * 12)
101
+ );
102
+ const primary = runs.reduce((best, run) => run[1] - run[0] > best[1] - best[0] ? run : best);
103
+ const inner = coordinate.map([1, 0]);
104
+ const innerRadius = Math.hypot(inner[0] - center[0], inner[1] - center[1]);
105
+ return {
106
+ ...shapes[runs.indexOf(primary)],
107
+ paths: shapes.flatMap(({ paths }) => paths),
108
+ labelAnchor: innerRadius >= 50 ? [center[0], center[1] + (index - (count - 1) / 2) * 34] : void 0
109
+ };
110
+ };
111
+ }
112
+ function getLabel(label, share, count) {
113
+ if (label !== void 0)
114
+ return label;
115
+ const percentage = new Intl.NumberFormat("en-US", {
116
+ style: "percent",
117
+ maximumFractionDigits: 1
118
+ }).format(share);
119
+ return `${count > 1 ? `Selected ${count} items` : "Contribution"}: ${percentage}`;
120
+ }
121
+ function contributionShare(data, rows, field) {
122
+ const values = (0, import_utils.numericRows)(data, field);
123
+ if (values.some(({ value }) => value < 0))
124
+ throw new Error("Invalid annotation: contribution requires nonnegative values.");
125
+ const total = values.reduce((sum, { value }) => sum + value, 0);
126
+ if (total === 0)
127
+ return void 0;
128
+ if (!Number.isFinite(total))
129
+ throw new Error("Invalid annotation: contribution requires a finite total.");
130
+ const selected = new Set(rows);
131
+ return values.filter(({ row }) => selected.has(row)).reduce((sum, { value }) => sum + value, 0) / total;
132
+ }
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ contribution
136
+ });
@@ -0,0 +1,3 @@
1
+ import type { AnnotationComponent } from '../registry';
2
+ /** Resolve native curve crossings, then reuse paths and directional point presets. */
3
+ export declare const crossing: AnnotationComponent<'crossing'>;