@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,347 @@
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/label.ts
20
+ var label_exports = {};
21
+ __export(label_exports, {
22
+ bindLabels: () => bindLabels,
23
+ bindPieLabels: () => bindPieLabels,
24
+ drawLabelColors: () => drawLabelColors,
25
+ getLabelColorWidth: () => getLabelColorWidth,
26
+ groupLabels: () => groupLabels,
27
+ labelConnectors: () => labelConnectors,
28
+ nativePercentageLabels: () => nativePercentageLabels,
29
+ rankedLabels: () => rankedLabels
30
+ });
31
+ module.exports = __toCommonJS(label_exports);
32
+ var nativePercentageLabels = /* @__PURE__ */ new WeakSet();
33
+ var labelConnectors = /* @__PURE__ */ new WeakMap();
34
+ var rankedLabels = /* @__PURE__ */ new WeakMap();
35
+ var groupLabels = /* @__PURE__ */ new WeakSet();
36
+ var colorSize = 10;
37
+ var colorGap = 6;
38
+ function bindLabels(container, content, items, defaults) {
39
+ const labeled = items.filter(({ annotation }) => annotation.label);
40
+ if (!labeled.length)
41
+ return () => {
42
+ };
43
+ const previous = container.getAttribute("style");
44
+ const previousContent = content.getAttribute("style");
45
+ const notes = document.createElement("aside");
46
+ notes.className = "annotation-labels";
47
+ notes.setAttribute("aria-label", "Annotations");
48
+ Object.assign(notes.style, {
49
+ display: "grid",
50
+ alignContent: "start",
51
+ justifyItems: "start",
52
+ gap: `${defaults.highlight.labelGap}px`,
53
+ minWidth: "0",
54
+ width: "max-content",
55
+ maxWidth: `${defaults.labels.highlight.maxWidth}px`
56
+ });
57
+ const cards = labeled.map(({ annotation }) => {
58
+ var _a, _b, _c;
59
+ const card = document.createElement("div");
60
+ card.textContent = annotation.label;
61
+ Object.assign(card.style, {
62
+ position: "relative",
63
+ zIndex: "1",
64
+ color: ((_a = annotation.style) == null ? void 0 : _a.labelFill) ?? defaults.labelFill,
65
+ fontFamily: defaults.fontFamily,
66
+ fontSize: `${((_b = annotation.style) == null ? void 0 : _b.labelFontSize) ?? defaults.labelFontSize}px`,
67
+ fontWeight: String(defaults.fontWeight),
68
+ lineHeight: "1.6",
69
+ overflowWrap: "anywhere",
70
+ background: defaults.highlight.labelBackground,
71
+ border: `1px solid ${defaults.highlight.labelBorder}`,
72
+ borderLeft: `3px solid ${((_c = annotation.style) == null ? void 0 : _c.stroke) ?? defaults.stroke}`,
73
+ borderRadius: "6px",
74
+ width: "fit-content",
75
+ maxWidth: "100%",
76
+ boxSizing: "border-box",
77
+ padding: `${defaults.labels.highlight.padding[0]}px ${defaults.labels.highlight.padding[1]}px`
78
+ });
79
+ notes.appendChild(card);
80
+ return card;
81
+ });
82
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
83
+ svg.classList.add("annotation-leaders");
84
+ svg.setAttribute("aria-hidden", "true");
85
+ Object.assign(svg.style, {
86
+ position: "absolute",
87
+ top: "0",
88
+ left: "0",
89
+ width: "100%",
90
+ height: "100%",
91
+ overflow: "visible",
92
+ pointerEvents: "none"
93
+ });
94
+ Object.assign(container.style, {
95
+ position: "relative",
96
+ display: "grid",
97
+ gap: `${defaults.highlight.labelGap * 2}px`,
98
+ alignItems: "start",
99
+ alignContent: "start",
100
+ justifyContent: "start"
101
+ });
102
+ Object.assign(content.style, { minWidth: "0", width: "fit-content", maxWidth: "100%" });
103
+ container.append(notes, svg);
104
+ let disposed = false;
105
+ const draw = () => {
106
+ var _a, _b;
107
+ if (disposed)
108
+ return;
109
+ container.style.gridTemplateColumns = "minmax(0, max-content)";
110
+ notes.style.position = "";
111
+ notes.style.height = "";
112
+ notes.style.width = "max-content";
113
+ cards.forEach((card) => Object.assign(card.style, { position: "relative", top: "" }));
114
+ const style = getComputedStyle(container);
115
+ const width = container.clientWidth - parseFloat(style.paddingLeft) - parseFloat(style.paddingRight);
116
+ notes.style.maxWidth = `${Math.min(defaults.labels.highlight.maxWidth, width)}px`;
117
+ const gap = defaults.highlight.labelGap * 2;
118
+ const side = content.getBoundingClientRect().width + gap + notes.offsetWidth <= width || width >= 650;
119
+ if (side) {
120
+ container.style.gridTemplateColumns = "minmax(0, max-content) max-content";
121
+ notes.style.width = `${notes.offsetWidth}px`;
122
+ notes.style.position = "relative";
123
+ }
124
+ const root = container.getBoundingClientRect();
125
+ const body = content.getBoundingClientRect();
126
+ const targets = labeled.map((item) => {
127
+ const bounds = item.bounds();
128
+ return Array.isArray(bounds) ? bounds : bounds ? [bounds] : [];
129
+ });
130
+ if (side) {
131
+ const placements = cards.map((card, index) => ({
132
+ card,
133
+ height: card.offsetHeight,
134
+ y: targets[index].length ? targets[index].reduce((sum, box) => sum + (box.top + box.bottom) / 2, 0) / targets[index].length - body.top : 0,
135
+ top: 0
136
+ })).sort((a, b) => a.y - b.y);
137
+ const height = Math.max(
138
+ body.height,
139
+ placements.reduce((sum, item) => sum + item.height, 0) + (cards.length - 1) * defaults.highlight.labelGap
140
+ );
141
+ let bottom = 0;
142
+ for (const item of placements) {
143
+ item.top = Math.max(bottom, item.y - item.height / 2);
144
+ bottom = item.top + item.height + defaults.highlight.labelGap;
145
+ }
146
+ bottom = height;
147
+ for (const item of placements.reverse()) {
148
+ item.top = Math.min(item.top, bottom - item.height);
149
+ bottom = item.top - defaults.highlight.labelGap;
150
+ Object.assign(item.card.style, { position: "absolute", top: `${item.top}px` });
151
+ }
152
+ notes.style.height = `${height}px`;
153
+ }
154
+ svg.textContent = "";
155
+ for (const [index, bounds] of targets.entries()) {
156
+ const connect = labelConnectors.get(labeled[index].annotation);
157
+ if (connect) {
158
+ const points = bounds.filter((box) => box.width && box.height).flatMap((box) => [
159
+ [Math.min(box.right, body.right) - root.left, box.top - root.top],
160
+ [Math.min(box.right, body.right) - root.left, box.bottom - root.top]
161
+ ]);
162
+ const bracket = connect(points, [], void 0, index, labeled.length);
163
+ if (!bracket)
164
+ continue;
165
+ const card = cards[index].getBoundingClientRect();
166
+ const endX = (side ? card.left : card.right) - root.left;
167
+ const endY = card.top + card.height / 2 - root.top;
168
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
169
+ const outline = bracket.paths.map((points2) => points2.map(([x, y], i) => `${i ? "L" : "M"}${x},${y}`).join(" ")).join(" ");
170
+ const leader = side ? `H${endX} V${endY}` : `H${Math.max(bracket.anchor[0] + 8, body.right - root.left + gap / 2)} V${endY} H${endX}`;
171
+ path.setAttribute("d", `${outline} M${bracket.anchor.join(",")} ${leader}`);
172
+ path.setAttribute("fill", "none");
173
+ path.setAttribute("stroke", ((_a = labeled[index].annotation.style) == null ? void 0 : _a.stroke) ?? defaults.stroke);
174
+ path.setAttribute("stroke-width", "1.5");
175
+ path.setAttribute("stroke-linejoin", "round");
176
+ svg.appendChild(path);
177
+ continue;
178
+ }
179
+ for (const target of bounds) {
180
+ const card = cards[index].getBoundingClientRect();
181
+ if (!target || !target.width || !target.height)
182
+ continue;
183
+ const x = Math.max(body.left, Math.min(target.right, body.right)) - root.left;
184
+ const y = (target.top + target.bottom) / 2 - root.top;
185
+ const endX = (side ? card.left : card.right) - root.left;
186
+ const endY = card.top + card.height / 2 - root.top;
187
+ const lane = side ? (body.right - root.left + endX) / 2 : body.right - root.left + gap / 2;
188
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
189
+ path.setAttribute("d", `M${x},${y} H${lane} V${endY} H${endX}`);
190
+ path.setAttribute("fill", "none");
191
+ path.setAttribute("stroke", ((_b = labeled[index].annotation.style) == null ? void 0 : _b.stroke) ?? defaults.stroke);
192
+ path.setAttribute("stroke-width", "1.5");
193
+ path.setAttribute("stroke-linejoin", "round");
194
+ svg.appendChild(path);
195
+ }
196
+ }
197
+ };
198
+ let frame;
199
+ const scheduleDraw = () => {
200
+ if (disposed || frame !== void 0)
201
+ return;
202
+ frame = requestAnimationFrame(() => {
203
+ frame = void 0;
204
+ draw();
205
+ });
206
+ };
207
+ const resize = new ResizeObserver(scheduleDraw);
208
+ resize.observe(container);
209
+ resize.observe(content);
210
+ content.addEventListener("scroll", scheduleDraw, true);
211
+ document.fonts.ready.then(scheduleDraw);
212
+ document.fonts.addEventListener("loadingdone", scheduleDraw);
213
+ draw();
214
+ return () => {
215
+ disposed = true;
216
+ if (frame !== void 0)
217
+ cancelAnimationFrame(frame);
218
+ resize.disconnect();
219
+ content.removeEventListener("scroll", scheduleDraw, true);
220
+ document.fonts.removeEventListener("loadingdone", scheduleDraw);
221
+ notes.remove();
222
+ svg.remove();
223
+ if (previous === null)
224
+ container.removeAttribute("style");
225
+ else
226
+ container.setAttribute("style", previous);
227
+ if (previousContent === null)
228
+ content.removeAttribute("style");
229
+ else
230
+ content.setAttribute("style", previousContent);
231
+ };
232
+ }
233
+ function getLabelColorWidth(colors) {
234
+ return colors.length * (colorSize + colorGap);
235
+ }
236
+ function drawLabelColors(label, scene, colors, box, padding) {
237
+ const keys = scene.createElement("g", {
238
+ className: "annotation-label-colors",
239
+ style: { pointerEvents: "none" }
240
+ });
241
+ label.appendChild(keys);
242
+ colors.forEach(
243
+ (fill, index) => keys.appendChild(
244
+ scene.createElement("rect", {
245
+ className: "annotation-label-color",
246
+ style: {
247
+ x: box.x + padding + index * (colorSize + colorGap),
248
+ y: box.y + (box.height - colorSize) / 2,
249
+ width: colorSize,
250
+ height: colorSize,
251
+ radius: 2,
252
+ fill,
253
+ stroke: "none",
254
+ pointerEvents: "none"
255
+ }
256
+ })
257
+ )
258
+ );
259
+ }
260
+ function bindPieLabels(selections, context) {
261
+ bindRankLabels(selections, context);
262
+ const automatic = selections.filter(({ annotation }) => nativePercentageLabels.has(annotation));
263
+ if (!automatic.length)
264
+ return {};
265
+ return {
266
+ update: () => {
267
+ var _a;
268
+ const labels = context.getScene().querySelectorAll(".label");
269
+ for (const { annotation, rows } of automatic) {
270
+ const native = labels.find((label) => {
271
+ var _a2;
272
+ const element = (_a2 = label.__data__) == null ? void 0 : _a2.dependentElement;
273
+ return label.getAttribute("annotationNativePercentage") && element && rows.includes(element.__data__.data) && label.style.visibility !== "hidden" && Number(label.style.opacity ?? 1) > 0 && label.querySelectorAll("text").some(
274
+ (text) => text.style.visibility !== "hidden" && Number(text.style.opacity ?? 1) > 0 && Number(text.style.fillOpacity ?? 1) > 0
275
+ );
276
+ });
277
+ for (const label of labels) {
278
+ const element = (_a = label.__data__) == null ? void 0 : _a.dependentElement;
279
+ if ((element == null ? void 0 : element.getAttribute("annotationSelection")) !== annotation)
280
+ continue;
281
+ const visibility = native ? "hidden" : "visible";
282
+ label.attr({
283
+ visibility,
284
+ backgroundVisibility: visibility,
285
+ connectorVisibility: visibility
286
+ });
287
+ }
288
+ }
289
+ }
290
+ };
291
+ }
292
+ function bindRankLabels(selections, context) {
293
+ const groups = /* @__PURE__ */ new Map();
294
+ for (const { annotation, rows } of selections) {
295
+ const source = rankedLabels.get(annotation);
296
+ if (!source || !annotation.label)
297
+ continue;
298
+ let group = groups.get(source);
299
+ if (!group) {
300
+ group = { annotation, text: /* @__PURE__ */ new Map() };
301
+ groups.set(source, group);
302
+ }
303
+ for (const row of rows)
304
+ group.text.set(row, annotation.label);
305
+ }
306
+ if (!groups.size)
307
+ return;
308
+ const mark = context.sourceMarks[0];
309
+ mark.labels = [
310
+ ...mark.labels ?? [],
311
+ ...[...groups.values()].map(({ annotation, text }) => {
312
+ var _a;
313
+ return {
314
+ ...context.getTextStyle(annotation),
315
+ text: (row) => text.get(row) ?? "",
316
+ position: "inside",
317
+ annotationLabel: "highlight",
318
+ annotationInside: true,
319
+ background: false,
320
+ connector: false,
321
+ transform: [
322
+ { type: () => removeEmptyLabels },
323
+ ...((_a = annotation.style) == null ? void 0 : _a.labelFill) === void 0 ? [{ type: "contrastReverse" }] : []
324
+ ]
325
+ };
326
+ })
327
+ ];
328
+ }
329
+ function removeEmptyLabels(labels) {
330
+ return labels.filter((label) => {
331
+ if (label.getAttribute("text"))
332
+ return true;
333
+ label.destroy();
334
+ return false;
335
+ });
336
+ }
337
+ // Annotate the CommonJS export names for ESM import in node:
338
+ 0 && (module.exports = {
339
+ bindLabels,
340
+ bindPieLabels,
341
+ drawLabelColors,
342
+ getLabelColorWidth,
343
+ groupLabels,
344
+ labelConnectors,
345
+ nativePercentageLabels,
346
+ rankedLabels
347
+ });
@@ -0,0 +1,12 @@
1
+ export type Point = [number, number];
2
+ export interface Box {
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ height: number;
7
+ }
8
+ export type Segment = [Point, Point];
9
+ /** Keep a preferred native position when clear; otherwise try nearby spaces and obstacle edges. */
10
+ export declare function placeLabel(anchor: Point, size: Point, view: Point, gap: number, boxes: Box[], segments: Segment[], preferred?: Point): Box;
11
+ /** Route only explanation leaders; explicit annotation lines retain their original geometry. */
12
+ export declare function routeLeader(anchor: Point, target: Box, boxes: Box[], segments: Segment[]): Point[];
@@ -0,0 +1,142 @@
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/layout.ts
20
+ var layout_exports = {};
21
+ __export(layout_exports, {
22
+ placeLabel: () => placeLabel,
23
+ routeLeader: () => routeLeader
24
+ });
25
+ module.exports = __toCommonJS(layout_exports);
26
+ function insideLength([a, b], box) {
27
+ let start = 0;
28
+ let end = 1;
29
+ for (const [axis, low, high] of [
30
+ [0, box.x, box.x + box.width],
31
+ [1, box.y, box.y + box.height]
32
+ ]) {
33
+ const delta = b[axis] - a[axis];
34
+ if (!delta) {
35
+ if (a[axis] < low || a[axis] > high)
36
+ return 0;
37
+ } else {
38
+ const t0 = (low - a[axis]) / delta;
39
+ const t1 = (high - a[axis]) / delta;
40
+ start = Math.max(start, Math.min(t0, t1));
41
+ end = Math.min(end, Math.max(t0, t1));
42
+ }
43
+ }
44
+ return Math.max(0, end - start) * Math.hypot(b[0] - a[0], b[1] - a[1]);
45
+ }
46
+ function padded(box) {
47
+ return { x: box.x - 4, y: box.y - 4, width: box.width + 8, height: box.height + 8 };
48
+ }
49
+ function overlap(a, b) {
50
+ return Math.max(0, Math.min(a.x + a.width, b.x + b.width) - Math.max(a.x, b.x)) * Math.max(0, Math.min(a.y + a.height, b.y + b.height) - Math.max(a.y, b.y));
51
+ }
52
+ function placeLabel(anchor, size, view, gap, boxes, segments, preferred) {
53
+ const [x, y] = anchor;
54
+ const [width, height] = size;
55
+ const above = [x - width / 2, y - gap - height];
56
+ const candidates = [
57
+ preferred ?? above,
58
+ above,
59
+ [x - width / 2, y + gap],
60
+ [x + gap, y - height / 2],
61
+ [x - gap - width, y - height / 2],
62
+ [x - gap - width, y - gap - height],
63
+ [x + gap, y - gap - height],
64
+ [x - gap - width, y + gap],
65
+ [x + gap, y + gap]
66
+ ];
67
+ const left = Math.min(...candidates.map(([x2]) => x2));
68
+ const top = Math.min(...candidates.map(([, y2]) => y2));
69
+ const near = {
70
+ x: left - 4,
71
+ y: top - 4,
72
+ width: Math.max(...candidates.map(([x2]) => x2)) - left + width + 8,
73
+ height: Math.max(...candidates.map(([, y2]) => y2)) - top + height + 8
74
+ };
75
+ for (const box of boxes) {
76
+ if (!overlap(box, near))
77
+ continue;
78
+ candidates.push(
79
+ [box.x - width - 4, y - height / 2],
80
+ [box.x + box.width + 4, y - height / 2],
81
+ [x - width / 2, box.y - height - 4],
82
+ [x - width / 2, box.y + box.height + 4]
83
+ );
84
+ }
85
+ let best;
86
+ let bestScore = Infinity;
87
+ for (const [left2, top2] of candidates) {
88
+ const box = {
89
+ x: Math.max(0, Math.min(left2, view[0] - width)),
90
+ y: Math.max(0, Math.min(top2, view[1] - height)),
91
+ width,
92
+ height
93
+ };
94
+ const collisions = boxes.reduce((sum, other) => sum + overlap(box, padded(other)), 0) + segments.reduce((sum, segment) => sum + insideLength(segment, padded(box)) * 6, 0);
95
+ const score = collisions * 100 + Math.hypot(box.x - candidates[0][0], box.y - candidates[0][1]);
96
+ if (score < bestScore) {
97
+ best = box;
98
+ bestScore = score;
99
+ }
100
+ }
101
+ return best;
102
+ }
103
+ function routeLeader(anchor, target, boxes, segments) {
104
+ const [x, y] = anchor;
105
+ const edge = [
106
+ Math.max(target.x, Math.min(x, target.x + target.width)),
107
+ Math.max(target.y, Math.min(y, target.y + target.height))
108
+ ];
109
+ if (edge[0] === x && edge[1] === y)
110
+ return [];
111
+ const obstacles = boxes.filter(
112
+ (box) => box !== target && !(x >= box.x && x <= box.x + box.width && y >= box.y && y <= box.y + box.height)
113
+ );
114
+ const routes = [
115
+ [anchor, edge],
116
+ [anchor, [edge[0], y], edge],
117
+ [anchor, [x, edge[1]], edge]
118
+ ];
119
+ for (const box of obstacles) {
120
+ if (!insideLength([anchor, edge], padded(box)))
121
+ continue;
122
+ for (const lane of [box.x - 6, box.x + box.width + 6])
123
+ routes.push([anchor, [lane, y], [lane, edge[1]], edge]);
124
+ for (const lane of [box.y - 6, box.y + box.height + 6])
125
+ routes.push([anchor, [x, lane], [edge[0], lane], edge]);
126
+ }
127
+ const score = (route) => route.slice(1).reduce((sum, point, index) => {
128
+ const segment = [route[index], point];
129
+ return sum + Math.hypot(point[0] - segment[0][0], point[1] - segment[0][1]) + obstacles.reduce((cost, box) => cost + insideLength(segment, box) * 100, 0) + segments.reduce((cost, other) => cost + (crosses(segment, other) ? 40 : 0), 0) + // A leader must approach the card from outside, never travel through its text.
130
+ insideLength(segment, target) * 100;
131
+ }, 0);
132
+ return routes.reduce((best, route) => score(route) < score(best) ? route : best);
133
+ }
134
+ function crosses([a, b], [c, d]) {
135
+ const side = (p, q, r) => (q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0]);
136
+ return side(a, b, c) * side(a, b, d) < 0 && side(c, d, a) * side(c, d, b) < 0;
137
+ }
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ placeLabel,
141
+ routeLeader
142
+ });
@@ -0,0 +1,19 @@
1
+ import type { AnnotationResult } from './registry';
2
+ export interface AnnotationEntry<A extends {
3
+ type: string;
4
+ }, C, R = AnnotationResult> {
5
+ annotation: A;
6
+ draw: (annotations: A[], context: C) => R;
7
+ }
8
+ export interface AnnotationGroup<A extends {
9
+ type: string;
10
+ }, C, R = AnnotationResult> {
11
+ annotations: A[];
12
+ draw: AnnotationEntry<A, C, R>['draw'];
13
+ }
14
+ /** Group configurations into shared drawing calls; components resolve the selected data. */
15
+ export declare function mergeAnnotations<A extends {
16
+ type: string;
17
+ }, C, R = AnnotationResult>(entries: AnnotationEntry<A, C, R>[]): AnnotationGroup<A, C, R>[];
18
+ /** Reused primitives retain their native marks, update hooks and resource cleanup. */
19
+ export declare function mergeResults(results: AnnotationResult[]): AnnotationResult;
@@ -0,0 +1,60 @@
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/merge.ts
20
+ var merge_exports = {};
21
+ __export(merge_exports, {
22
+ mergeAnnotations: () => mergeAnnotations,
23
+ mergeResults: () => mergeResults
24
+ });
25
+ module.exports = __toCommonJS(merge_exports);
26
+ function mergeAnnotations(entries) {
27
+ const groups = [];
28
+ const shared = /* @__PURE__ */ new Map();
29
+ for (const { annotation, draw } of entries) {
30
+ const existing = shared.get(annotation.type);
31
+ if (existing) {
32
+ existing.annotations.push(annotation);
33
+ continue;
34
+ }
35
+ const previous = groups.at(-1);
36
+ if ((previous == null ? void 0 : previous.annotations[0].type) === annotation.type) {
37
+ previous.annotations.push(annotation);
38
+ continue;
39
+ }
40
+ const group = { annotations: [annotation], draw };
41
+ groups.push(group);
42
+ if (annotation.type === "highlight" || annotation.type === "thresholdHighlight")
43
+ shared.set(annotation.type, group);
44
+ }
45
+ return groups;
46
+ }
47
+ function mergeResults(results) {
48
+ const updates = results.flatMap(({ update }) => update ? [update] : []);
49
+ const cleanups = results.flatMap(({ cleanup }) => cleanup ? [cleanup] : []);
50
+ return {
51
+ marks: results.flatMap(({ marks }) => marks ?? []),
52
+ update: updates.length ? () => updates.forEach((update) => update()) : void 0,
53
+ cleanup: cleanups.length ? () => cleanups.forEach((cleanup) => cleanup()) : void 0
54
+ };
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ mergeAnnotations,
59
+ mergeResults
60
+ });