@ktnpm_devops/react-component 0.13.0 → 0.14.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 (390) hide show
  1. package/dist/index.cjs +24 -22
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +4 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +24 -22
  6. package/dist/index.js.map +1 -1
  7. package/dist/index10.cjs +2 -2
  8. package/dist/index10.js +2 -2
  9. package/dist/index100.cjs +57 -24
  10. package/dist/index100.cjs.map +1 -1
  11. package/dist/index100.js +56 -23
  12. package/dist/index100.js.map +1 -1
  13. package/dist/index101.cjs +22 -20
  14. package/dist/index101.cjs.map +1 -1
  15. package/dist/index101.js +21 -19
  16. package/dist/index101.js.map +1 -1
  17. package/dist/index102.cjs +55 -14
  18. package/dist/index102.cjs.map +1 -1
  19. package/dist/index102.js +54 -13
  20. package/dist/index102.js.map +1 -1
  21. package/dist/index103.cjs +13 -55
  22. package/dist/index103.cjs.map +1 -1
  23. package/dist/index103.js +14 -56
  24. package/dist/index103.js.map +1 -1
  25. package/dist/index104.cjs +4 -19
  26. package/dist/index104.cjs.map +1 -1
  27. package/dist/index104.js +5 -20
  28. package/dist/index104.js.map +1 -1
  29. package/dist/index105.cjs +10 -49
  30. package/dist/index105.cjs.map +1 -1
  31. package/dist/index105.js +11 -50
  32. package/dist/index105.js.map +1 -1
  33. package/dist/index106.cjs +30 -27
  34. package/dist/index106.cjs.map +1 -1
  35. package/dist/index106.js +30 -27
  36. package/dist/index106.js.map +1 -1
  37. package/dist/index107.cjs +52 -10
  38. package/dist/index107.cjs.map +1 -1
  39. package/dist/index107.js +53 -11
  40. package/dist/index107.js.map +1 -1
  41. package/dist/index108.cjs +29 -5
  42. package/dist/index108.cjs.map +1 -1
  43. package/dist/index108.js +30 -6
  44. package/dist/index108.js.map +1 -1
  45. package/dist/index109.cjs +21 -15
  46. package/dist/index109.cjs.map +1 -1
  47. package/dist/index109.js +21 -15
  48. package/dist/index109.js.map +1 -1
  49. package/dist/index11.cjs +2 -2
  50. package/dist/index11.js +2 -2
  51. package/dist/index110.cjs +16 -16
  52. package/dist/index110.js +17 -17
  53. package/dist/index111.cjs +11 -2
  54. package/dist/index111.cjs.map +1 -1
  55. package/dist/index111.js +11 -2
  56. package/dist/index111.js.map +1 -1
  57. package/dist/index112.cjs +17 -2
  58. package/dist/index112.cjs.map +1 -1
  59. package/dist/index112.js +18 -3
  60. package/dist/index112.js.map +1 -1
  61. package/dist/index113.cjs +29 -14
  62. package/dist/index113.cjs.map +1 -1
  63. package/dist/index113.js +29 -14
  64. package/dist/index113.js.map +1 -1
  65. package/dist/index114.cjs +118 -0
  66. package/dist/index114.cjs.map +1 -0
  67. package/dist/index114.js +118 -0
  68. package/dist/index114.js.map +1 -0
  69. package/dist/index115.cjs +45 -0
  70. package/dist/index115.cjs.map +1 -0
  71. package/dist/index115.js +45 -0
  72. package/dist/index115.js.map +1 -0
  73. package/dist/index116.cjs +33 -0
  74. package/dist/index116.cjs.map +1 -0
  75. package/dist/index116.js +33 -0
  76. package/dist/index116.js.map +1 -0
  77. package/dist/index117.cjs +1166 -0
  78. package/dist/index117.cjs.map +1 -0
  79. package/dist/index117.js +1167 -0
  80. package/dist/index117.js.map +1 -0
  81. package/dist/index118.cjs +1578 -0
  82. package/dist/index118.cjs.map +1 -0
  83. package/dist/index118.js +1579 -0
  84. package/dist/index118.js.map +1 -0
  85. package/dist/index12.cjs +2 -2
  86. package/dist/index12.js +2 -2
  87. package/dist/index13.cjs +2 -2
  88. package/dist/index13.js +2 -2
  89. package/dist/index14.cjs +2 -2
  90. package/dist/index14.js +2 -2
  91. package/dist/index15.cjs +2 -2
  92. package/dist/index15.js +2 -2
  93. package/dist/index16.cjs +3 -3
  94. package/dist/index16.js +3 -3
  95. package/dist/index17.cjs +2 -2
  96. package/dist/index17.js +2 -2
  97. package/dist/index18.cjs +1 -1
  98. package/dist/index18.js +1 -1
  99. package/dist/index19.cjs +2 -2
  100. package/dist/index19.js +2 -2
  101. package/dist/index20.cjs +2 -2
  102. package/dist/index20.js +2 -2
  103. package/dist/index21.cjs +2 -2
  104. package/dist/index21.js +2 -2
  105. package/dist/index22.cjs +3 -3
  106. package/dist/index22.js +3 -3
  107. package/dist/index23.cjs +3 -3
  108. package/dist/index23.js +3 -3
  109. package/dist/index24.cjs +3 -3
  110. package/dist/index24.js +3 -3
  111. package/dist/index25.cjs +2 -2
  112. package/dist/index25.js +2 -2
  113. package/dist/index26.cjs +2 -2
  114. package/dist/index26.js +2 -2
  115. package/dist/index27.cjs +2 -2
  116. package/dist/index27.js +2 -2
  117. package/dist/index28.cjs +2 -2
  118. package/dist/index28.js +2 -2
  119. package/dist/index29.cjs +3 -3
  120. package/dist/index29.js +3 -3
  121. package/dist/index30.cjs +8 -8
  122. package/dist/index30.js +8 -8
  123. package/dist/index31.cjs +2 -2
  124. package/dist/index31.js +2 -2
  125. package/dist/index32.cjs +2 -2
  126. package/dist/index32.js +2 -2
  127. package/dist/index33.cjs +3 -3
  128. package/dist/index33.js +3 -3
  129. package/dist/index34.cjs +4 -4
  130. package/dist/index34.js +4 -4
  131. package/dist/index35.cjs +20 -38
  132. package/dist/index35.cjs.map +1 -1
  133. package/dist/index35.js +21 -39
  134. package/dist/index35.js.map +1 -1
  135. package/dist/index36.cjs +36 -224
  136. package/dist/index36.cjs.map +1 -1
  137. package/dist/index36.js +37 -225
  138. package/dist/index36.js.map +1 -1
  139. package/dist/index37.cjs +220 -28
  140. package/dist/index37.cjs.map +1 -1
  141. package/dist/index37.js +222 -30
  142. package/dist/index37.js.map +1 -1
  143. package/dist/index38.cjs +30 -106
  144. package/dist/index38.cjs.map +1 -1
  145. package/dist/index38.js +31 -107
  146. package/dist/index38.js.map +1 -1
  147. package/dist/index39.cjs +100 -58
  148. package/dist/index39.cjs.map +1 -1
  149. package/dist/index39.js +101 -59
  150. package/dist/index39.js.map +1 -1
  151. package/dist/index40.cjs +66 -76
  152. package/dist/index40.cjs.map +1 -1
  153. package/dist/index40.js +67 -77
  154. package/dist/index40.js.map +1 -1
  155. package/dist/index41.cjs +76 -57
  156. package/dist/index41.cjs.map +1 -1
  157. package/dist/index41.js +78 -59
  158. package/dist/index41.js.map +1 -1
  159. package/dist/index42.cjs +56 -150
  160. package/dist/index42.cjs.map +1 -1
  161. package/dist/index42.js +58 -152
  162. package/dist/index42.js.map +1 -1
  163. package/dist/index43.cjs +128 -73
  164. package/dist/index43.cjs.map +1 -1
  165. package/dist/index43.js +123 -68
  166. package/dist/index43.js.map +1 -1
  167. package/dist/index44.cjs +94 -68
  168. package/dist/index44.cjs.map +1 -1
  169. package/dist/index44.js +96 -70
  170. package/dist/index44.js.map +1 -1
  171. package/dist/index45.cjs +71 -7
  172. package/dist/index45.cjs.map +1 -1
  173. package/dist/index45.js +72 -8
  174. package/dist/index45.js.map +1 -1
  175. package/dist/index46.cjs +8 -17
  176. package/dist/index46.cjs.map +1 -1
  177. package/dist/index46.js +9 -18
  178. package/dist/index46.js.map +1 -1
  179. package/dist/index47.cjs +15 -75
  180. package/dist/index47.cjs.map +1 -1
  181. package/dist/index47.js +16 -76
  182. package/dist/index47.js.map +1 -1
  183. package/dist/index48.cjs +68 -134
  184. package/dist/index48.cjs.map +1 -1
  185. package/dist/index48.js +70 -136
  186. package/dist/index48.js.map +1 -1
  187. package/dist/index49.cjs +137 -58
  188. package/dist/index49.cjs.map +1 -1
  189. package/dist/index49.js +138 -59
  190. package/dist/index49.js.map +1 -1
  191. package/dist/index50.cjs +61 -102
  192. package/dist/index50.cjs.map +1 -1
  193. package/dist/index50.js +62 -103
  194. package/dist/index50.js.map +1 -1
  195. package/dist/index51.cjs +102 -44
  196. package/dist/index51.cjs.map +1 -1
  197. package/dist/index51.js +103 -45
  198. package/dist/index51.js.map +1 -1
  199. package/dist/index52.cjs +47 -6
  200. package/dist/index52.cjs.map +1 -1
  201. package/dist/index52.js +48 -7
  202. package/dist/index52.js.map +1 -1
  203. package/dist/index53.cjs +6 -147
  204. package/dist/index53.cjs.map +1 -1
  205. package/dist/index53.js +7 -148
  206. package/dist/index53.js.map +1 -1
  207. package/dist/index54.cjs +146 -7
  208. package/dist/index54.cjs.map +1 -1
  209. package/dist/index54.js +148 -9
  210. package/dist/index54.js.map +1 -1
  211. package/dist/index55.cjs +6 -15
  212. package/dist/index55.cjs.map +1 -1
  213. package/dist/index55.js +6 -15
  214. package/dist/index55.js.map +1 -1
  215. package/dist/index56.cjs +15 -64
  216. package/dist/index56.cjs.map +1 -1
  217. package/dist/index56.js +17 -66
  218. package/dist/index56.js.map +1 -1
  219. package/dist/index57.cjs +67 -15
  220. package/dist/index57.cjs.map +1 -1
  221. package/dist/index57.js +66 -14
  222. package/dist/index57.js.map +1 -1
  223. package/dist/index58.cjs +15 -6
  224. package/dist/index58.cjs.map +1 -1
  225. package/dist/index58.js +15 -6
  226. package/dist/index58.js.map +1 -1
  227. package/dist/index59.cjs +13 -19
  228. package/dist/index59.cjs.map +1 -1
  229. package/dist/index59.js +14 -20
  230. package/dist/index59.js.map +1 -1
  231. package/dist/index60.cjs +19 -64
  232. package/dist/index60.cjs.map +1 -1
  233. package/dist/index60.js +19 -64
  234. package/dist/index60.js.map +1 -1
  235. package/dist/index61.cjs +22 -22
  236. package/dist/index61.js +22 -22
  237. package/dist/index62.cjs +22 -22
  238. package/dist/index62.js +22 -22
  239. package/dist/index63.cjs +2 -14
  240. package/dist/index63.cjs.map +1 -1
  241. package/dist/index63.js +3 -15
  242. package/dist/index63.js.map +1 -1
  243. package/dist/index64.cjs +2 -14
  244. package/dist/index64.cjs.map +1 -1
  245. package/dist/index64.js +3 -15
  246. package/dist/index64.js.map +1 -1
  247. package/dist/index66.cjs +1 -1
  248. package/dist/index66.js +1 -1
  249. package/dist/index67.cjs +16 -116
  250. package/dist/index67.cjs.map +1 -1
  251. package/dist/index67.js +14 -114
  252. package/dist/index67.js.map +1 -1
  253. package/dist/index68.cjs +2 -20
  254. package/dist/index68.cjs.map +1 -1
  255. package/dist/index68.js +3 -21
  256. package/dist/index68.js.map +1 -1
  257. package/dist/index69.cjs +17 -24
  258. package/dist/index69.cjs.map +1 -1
  259. package/dist/index69.js +16 -23
  260. package/dist/index69.js.map +1 -1
  261. package/dist/index70.cjs +2 -11
  262. package/dist/index70.cjs.map +1 -1
  263. package/dist/index70.js +3 -12
  264. package/dist/index70.js.map +1 -1
  265. package/dist/index71.cjs +116 -22
  266. package/dist/index71.cjs.map +1 -1
  267. package/dist/index71.js +114 -20
  268. package/dist/index71.js.map +1 -1
  269. package/dist/index72.cjs +18 -69
  270. package/dist/index72.cjs.map +1 -1
  271. package/dist/index72.js +19 -70
  272. package/dist/index72.js.map +1 -1
  273. package/dist/index73.cjs +14 -44
  274. package/dist/index73.cjs.map +1 -1
  275. package/dist/index73.js +15 -45
  276. package/dist/index73.js.map +1 -1
  277. package/dist/index74.cjs +19 -52
  278. package/dist/index74.cjs.map +1 -1
  279. package/dist/index74.js +19 -52
  280. package/dist/index74.js.map +1 -1
  281. package/dist/index75.cjs +5 -14
  282. package/dist/index75.cjs.map +1 -1
  283. package/dist/index75.js +5 -14
  284. package/dist/index75.js.map +1 -1
  285. package/dist/index76.cjs +2 -29
  286. package/dist/index76.cjs.map +1 -1
  287. package/dist/index76.js +3 -30
  288. package/dist/index76.js.map +1 -1
  289. package/dist/index77.cjs +65 -2
  290. package/dist/index77.cjs.map +1 -1
  291. package/dist/index77.js +66 -3
  292. package/dist/index77.js.map +1 -1
  293. package/dist/index78.cjs +19 -34
  294. package/dist/index78.cjs.map +1 -1
  295. package/dist/index78.js +19 -34
  296. package/dist/index78.js.map +1 -1
  297. package/dist/index79.cjs +13 -10
  298. package/dist/index79.cjs.map +1 -1
  299. package/dist/index79.js +14 -11
  300. package/dist/index79.js.map +1 -1
  301. package/dist/index80.cjs +19 -16
  302. package/dist/index80.cjs.map +1 -1
  303. package/dist/index80.js +20 -17
  304. package/dist/index80.js.map +1 -1
  305. package/dist/index81.cjs +35 -21
  306. package/dist/index81.cjs.map +1 -1
  307. package/dist/index81.js +34 -20
  308. package/dist/index81.js.map +1 -1
  309. package/dist/index82.cjs +44 -10
  310. package/dist/index82.cjs.map +1 -1
  311. package/dist/index82.js +42 -8
  312. package/dist/index82.js.map +1 -1
  313. package/dist/index83.cjs +24 -33
  314. package/dist/index83.cjs.map +1 -1
  315. package/dist/index83.js +23 -32
  316. package/dist/index83.js.map +1 -1
  317. package/dist/index84.cjs +20 -40
  318. package/dist/index84.cjs.map +1 -1
  319. package/dist/index84.js +19 -39
  320. package/dist/index84.js.map +1 -1
  321. package/dist/index85.cjs +14 -43
  322. package/dist/index85.cjs.map +1 -1
  323. package/dist/index85.js +13 -42
  324. package/dist/index85.js.map +1 -1
  325. package/dist/index86.cjs +42 -39
  326. package/dist/index86.cjs.map +1 -1
  327. package/dist/index86.js +43 -40
  328. package/dist/index86.js.map +1 -1
  329. package/dist/index87.cjs +51 -39
  330. package/dist/index87.cjs.map +1 -1
  331. package/dist/index87.js +50 -38
  332. package/dist/index87.js.map +1 -1
  333. package/dist/index88.cjs +39 -92
  334. package/dist/index88.cjs.map +1 -1
  335. package/dist/index88.js +38 -91
  336. package/dist/index88.js.map +1 -1
  337. package/dist/index89.cjs +75 -30
  338. package/dist/index89.cjs.map +1 -1
  339. package/dist/index89.js +75 -30
  340. package/dist/index89.js.map +1 -1
  341. package/dist/index90.cjs +36 -112
  342. package/dist/index90.cjs.map +1 -1
  343. package/dist/index90.js +36 -112
  344. package/dist/index90.js.map +1 -1
  345. package/dist/index91.cjs +92 -42
  346. package/dist/index91.cjs.map +1 -1
  347. package/dist/index91.js +91 -41
  348. package/dist/index91.js.map +1 -1
  349. package/dist/index92.cjs +32 -32
  350. package/dist/index92.js +32 -32
  351. package/dist/index93.cjs +19 -134
  352. package/dist/index93.cjs.map +1 -1
  353. package/dist/index93.js +18 -133
  354. package/dist/index93.js.map +1 -1
  355. package/dist/index94.cjs +36 -42
  356. package/dist/index94.cjs.map +1 -1
  357. package/dist/index94.js +36 -42
  358. package/dist/index94.js.map +1 -1
  359. package/dist/index95.cjs +14 -29
  360. package/dist/index95.cjs.map +1 -1
  361. package/dist/index95.js +14 -29
  362. package/dist/index95.js.map +1 -1
  363. package/dist/index96.cjs +37 -16
  364. package/dist/index96.cjs.map +1 -1
  365. package/dist/index96.js +37 -16
  366. package/dist/index96.js.map +1 -1
  367. package/dist/index97.cjs +16 -13
  368. package/dist/index97.cjs.map +1 -1
  369. package/dist/index97.js +17 -14
  370. package/dist/index97.js.map +1 -1
  371. package/dist/index98.cjs +130 -32
  372. package/dist/index98.cjs.map +1 -1
  373. package/dist/index98.js +130 -32
  374. package/dist/index98.js.map +1 -1
  375. package/dist/index99.cjs +45 -43
  376. package/dist/index99.cjs.map +1 -1
  377. package/dist/index99.js +44 -42
  378. package/dist/index99.js.map +1 -1
  379. package/dist/primitives/MarkdownContent/MarkdownContent.d.ts +4 -0
  380. package/dist/primitives/MarkdownContent/MarkdownContent.d.ts.map +1 -0
  381. package/dist/primitives/MarkdownContent/MarkdownContent.types.d.ts +5 -0
  382. package/dist/primitives/MarkdownContent/MarkdownContent.types.d.ts.map +1 -0
  383. package/dist/primitives/MarkdownContent/index.d.ts +3 -0
  384. package/dist/primitives/MarkdownContent/index.d.ts.map +1 -0
  385. package/dist/style.css +108 -0
  386. package/dist/utils/markdown.d.ts +3 -0
  387. package/dist/utils/markdown.d.ts.map +1 -0
  388. package/dist/utils/markdown.test.d.ts +2 -0
  389. package/dist/utils/markdown.test.d.ts.map +1 -0
  390. package/package.json +26 -4
package/dist/index90.cjs CHANGED
@@ -1,118 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const constants = require("./index67.cjs");
4
- function groupByCategory(data, limit, order = "total") {
5
- const grouped = /* @__PURE__ */ new Map();
6
- for (const point of data) {
7
- const key = point.category ?? "Unknown";
8
- if (!grouped.has(key)) {
9
- grouped.set(key, []);
3
+ const weightOf = (point) => point.weight ?? 1;
4
+ const fold = (data) => {
5
+ const byPosition = /* @__PURE__ */ new Map();
6
+ data.forEach((point, index) => {
7
+ const key = `${point.x}|${point.y}`;
8
+ const existing = byPosition.get(key);
9
+ if (!existing) {
10
+ byPosition.set(key, { point, index, count: 1 });
11
+ return;
10
12
  }
11
- grouped.get(key).push({
12
- ts: point.ts ?? "",
13
- value: point.value
14
- });
15
- }
16
- const entries = order === "first-seen" ? [...grouped.entries()] : [...grouped.entries()].sort(
17
- (a, b) => b[1].reduce((sum, p) => sum + p.value, 0) - a[1].reduce((sum, p) => sum + p.value, 0)
18
- );
19
- if (entries.length <= limit) {
20
- return entries;
21
- }
22
- const top = entries.slice(0, limit - 1);
23
- const rest = entries.slice(limit - 1);
24
- const otherMap = /* @__PURE__ */ new Map();
25
- for (const [, points] of rest) {
26
- for (const p of points) {
27
- otherMap.set(p.ts, (otherMap.get(p.ts) ?? 0) + p.value);
28
- }
29
- }
30
- const otherPoints = [...otherMap.entries()].map(([ts, value]) => ({
31
- ts,
32
- value
33
- }));
34
- return [...top, ["Other", otherPoints]];
35
- }
36
- function buildMarkAreas(annotations) {
37
- return annotations.filter((a) => a.end).map((a) => [
38
- {
39
- name: a.label,
40
- xAxis: a.start,
41
- itemStyle: { color: a.color ?? "rgba(255,107,90,0.1)" }
42
- },
43
- { xAxis: a.end }
44
- ]);
45
- }
46
- function buildMarkLines(annotations) {
47
- return annotations.filter((a) => !a.end).map((a) => ({
48
- name: a.label,
49
- xAxis: a.start,
50
- lineStyle: { color: a.color ?? constants.CHART_COLORS[0], type: "dashed" },
51
- label: { formatter: a.label, position: "end" }
52
- }));
53
- }
54
- function buildReferenceLines(referenceLines) {
55
- return referenceLines.map((r) => ({
56
- name: r.label ?? String(r.value),
57
- yAxis: r.value,
58
- lineStyle: {
59
- color: r.color ?? constants.CHART_COLORS[0],
60
- type: r.dashed === false ? "solid" : "dashed"
61
- },
62
- label: {
63
- formatter: r.label ?? String(r.value),
64
- position: "insideEndTop"
65
- }
66
- }));
67
- }
68
- function buildLegendSelected(seriesGroups, hiddenSeries) {
69
- if (!hiddenSeries) return void 0;
70
- const hidden = hiddenSeries instanceof Set ? hiddenSeries : new Set(hiddenSeries);
71
- return Object.fromEntries(seriesGroups.map(([name]) => [name, !hidden.has(name)]));
72
- }
73
- function buildTemporalTrendOption(seriesGroups, config) {
74
- const markAreas = buildMarkAreas(config.annotations);
75
- const markLines = [
76
- ...buildMarkLines(config.annotations),
77
- ...buildReferenceLines(config.referenceLines)
78
- ];
79
- const series = seriesGroups.map(([name, points], idx) => ({
80
- name,
81
- type: "line",
82
- ...config.stacked ? { stack: "total", areaStyle: {} } : {},
83
- emphasis: { focus: "series" },
84
- color: constants.CHART_COLORS[idx % constants.CHART_COLORS.length],
85
- data: points.sort((a, b) => a.ts < b.ts ? -1 : 1).map((p) => [p.ts, p.value]),
86
- ...idx === 0 && (markAreas.length > 0 || markLines.length > 0) ? {
87
- markArea: markAreas.length > 0 ? { silent: true, data: markAreas } : void 0,
88
- markLine: markLines.length > 0 ? { silent: true, symbol: "none", data: markLines } : void 0
89
- } : {}
90
- }));
13
+ existing.count += 1;
14
+ existing.point = {
15
+ ...existing.point,
16
+ weight: weightOf(existing.point) + weightOf(point)
17
+ };
18
+ });
19
+ return [...byPosition.values()];
20
+ };
21
+ const sample = (points, cap) => {
22
+ if (cap <= 1) return points.slice(0, Math.max(cap, 0));
23
+ const lastIndex = points.length - 1;
24
+ const step = lastIndex / (cap - 1);
25
+ return Array.from({ length: cap }, (_, i) => points[Math.round(i * step)]);
26
+ };
27
+ const foldPoints = (data, maxPoints, mergeCoincident) => {
28
+ const folded = mergeCoincident ? fold(data) : data.map((point, index) => ({ point, index, count: 1 }));
29
+ const points = folded.length > maxPoints ? sample(folded, maxPoints) : folded;
30
+ const represented = points.reduce((sum, p) => sum + p.count, 0);
91
31
  return {
92
- tooltip: {
93
- trigger: "axis",
94
- axisPointer: { type: "cross" }
95
- },
96
- legend: {
97
- show: config.showLegend,
98
- type: "scroll",
99
- bottom: 0,
100
- selected: buildLegendSelected(seriesGroups, config.hiddenSeries)
101
- },
102
- grid: {
103
- left: "3%",
104
- right: "4%",
105
- bottom: config.showLegend ? "15%" : "3%",
106
- containLabel: true
107
- },
108
- xAxis: { type: "time" },
109
- yAxis: { type: "value" },
110
- series
32
+ points,
33
+ info: {
34
+ total: data.length,
35
+ drawn: points.length,
36
+ merged: represented - points.length,
37
+ dropped: data.length - represented
38
+ }
111
39
  };
112
- }
113
- exports.buildMarkAreas = buildMarkAreas;
114
- exports.buildMarkLines = buildMarkLines;
115
- exports.buildReferenceLines = buildReferenceLines;
116
- exports.buildTemporalTrendOption = buildTemporalTrendOption;
117
- exports.groupByCategory = groupByCategory;
40
+ };
41
+ exports.foldPoints = foldPoints;
118
42
  //# sourceMappingURL=index90.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index90.cjs","sources":["../src/charts/TemporalTrendChartCard/buildChartOption.ts"],"sourcesContent":["import type {\n ChartSeriesPoint,\n ChartAnnotation,\n ReferenceLine,\n} from '../../types/chart.types';\nimport type { TemporalSeriesOrder } from './TemporalTrendChartCard.types';\nimport { CHART_COLORS } from '../../constants';\n\n/** A category and its points, sorted by the active series order. */\nexport type SeriesGroup = [string, { ts: string; value: number }[]];\n\nexport interface TemporalTrendOptionConfig {\n annotations: ChartAnnotation[];\n referenceLines: ReferenceLine[];\n showLegend: boolean;\n stacked: boolean;\n /** Series to start hidden. `undefined` leaves legend selection uncontrolled. */\n hiddenSeries?: Set<string> | string[];\n}\n\n/** Group data points by category, returning sorted series keyed by category name. */\nexport function groupByCategory(\n data: ChartSeriesPoint[],\n limit: number,\n order: TemporalSeriesOrder = 'total',\n): SeriesGroup[] {\n const grouped = new Map<string, { ts: string; value: number }[]>();\n\n for (const point of data) {\n const key = point.category ?? 'Unknown';\n if (!grouped.has(key)) {\n grouped.set(key, []);\n }\n grouped.get(key)!.push({\n ts: point.ts ?? '',\n value: point.value,\n });\n }\n\n // `first-seen` keeps the Map's insertion order, so each series keeps its\n // colour when the data is refreshed and the totals move.\n const entries =\n order === 'first-seen'\n ? [...grouped.entries()]\n : [...grouped.entries()].sort(\n (a, b) =>\n b[1].reduce((sum, p) => sum + p.value, 0) -\n a[1].reduce((sum, p) => sum + p.value, 0),\n );\n\n if (entries.length <= limit) {\n return entries;\n }\n\n const top = entries.slice(0, limit - 1);\n const rest = entries.slice(limit - 1);\n\n const otherMap = new Map<string, number>();\n for (const [, points] of rest) {\n for (const p of points) {\n otherMap.set(p.ts, (otherMap.get(p.ts) ?? 0) + p.value);\n }\n }\n\n const otherPoints = [...otherMap.entries()].map(([ts, value]) => ({\n ts,\n value,\n }));\n\n return [...top, ['Other', otherPoints] as SeriesGroup];\n}\n\n/** Build markArea items from range annotations. */\nexport function buildMarkAreas(annotations: ChartAnnotation[]) {\n return annotations\n .filter((a) => a.end)\n .map((a) => [\n {\n name: a.label,\n xAxis: a.start,\n itemStyle: { color: a.color ?? 'rgba(255,107,90,0.1)' },\n },\n { xAxis: a.end },\n ]);\n}\n\n/** Build markLine items from point annotations. */\nexport function buildMarkLines(annotations: ChartAnnotation[]) {\n return annotations\n .filter((a) => !a.end)\n .map((a) => ({\n name: a.label,\n xAxis: a.start,\n lineStyle: { color: a.color ?? CHART_COLORS[0], type: 'dashed' as const },\n label: { formatter: a.label, position: 'end' as const },\n }));\n}\n\n/** Build markLine items from horizontal reference lines (KPI target, threshold). */\nexport function buildReferenceLines(referenceLines: ReferenceLine[]) {\n return referenceLines.map((r) => ({\n name: r.label ?? String(r.value),\n yAxis: r.value,\n lineStyle: {\n color: r.color ?? CHART_COLORS[0],\n type: r.dashed === false ? ('solid' as const) : ('dashed' as const),\n },\n label: {\n formatter: r.label ?? String(r.value),\n position: 'insideEndTop' as const,\n },\n }));\n}\n\n/**\n * Legend selection map. Hiding through the legend rather than filtering the\n * series array keeps every series at its own index, and so at its own colour.\n */\nfunction buildLegendSelected(\n seriesGroups: SeriesGroup[],\n hiddenSeries: Set<string> | string[] | undefined,\n) {\n if (!hiddenSeries) return undefined;\n\n const hidden = hiddenSeries instanceof Set ? hiddenSeries : new Set(hiddenSeries);\n return Object.fromEntries(seriesGroups.map(([name]) => [name, !hidden.has(name)]));\n}\n\n/** Assemble the ECharts option for the temporal trend card. */\nexport function buildTemporalTrendOption(\n seriesGroups: SeriesGroup[],\n config: TemporalTrendOptionConfig,\n) {\n const markAreas = buildMarkAreas(config.annotations);\n const markLines = [\n ...buildMarkLines(config.annotations),\n ...buildReferenceLines(config.referenceLines),\n ];\n\n const series = seriesGroups.map(([name, points], idx) => ({\n name,\n type: 'line' as const,\n ...(config.stacked ? { stack: 'total', areaStyle: {} } : {}),\n emphasis: { focus: 'series' as const },\n color: CHART_COLORS[idx % CHART_COLORS.length],\n data: points\n .sort((a, b) => (a.ts < b.ts ? -1 : 1))\n .map((p) => [p.ts, p.value]),\n ...(idx === 0 && (markAreas.length > 0 || markLines.length > 0)\n ? {\n markArea: markAreas.length > 0 ? { silent: true, data: markAreas } : undefined,\n markLine:\n markLines.length > 0\n ? { silent: true, symbol: 'none', data: markLines }\n : undefined,\n }\n : {}),\n }));\n\n return {\n tooltip: {\n trigger: 'axis' as const,\n axisPointer: { type: 'cross' as const },\n },\n legend: {\n show: config.showLegend,\n type: 'scroll' as const,\n bottom: 0,\n selected: buildLegendSelected(seriesGroups, config.hiddenSeries),\n },\n grid: {\n left: '3%',\n right: '4%',\n bottom: config.showLegend ? '15%' : '3%',\n containLabel: true,\n },\n xAxis: { type: 'time' as const },\n yAxis: { type: 'value' as const },\n series,\n };\n}\n"],"names":["CHART_COLORS"],"mappings":";;;AAqBO,SAAS,gBACd,MACA,OACA,QAA6B,SACd;AACf,QAAM,8BAAc,IAAA;AAEpB,aAAW,SAAS,MAAM;AACxB,UAAM,MAAM,MAAM,YAAY;AAC9B,QAAI,CAAC,QAAQ,IAAI,GAAG,GAAG;AACrB,cAAQ,IAAI,KAAK,EAAE;AAAA,IACrB;AACA,YAAQ,IAA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IACzD,UAAU,EAAE,OAAO,SAAA;AAAA,IACnB,OAAOA,UAAAA,aAAa,MAAMA,UAAAA,aAAa,MAAM;AAAA,IAC7C,MAAM,OACH,KAAK,CAAC,GAAG,MAAO,EAAE,KAAK,EAAE,KAAK,KAAK,CAAE,EACrC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC;AAAA,IAC7B,GAAI,QAAQ,MAAM,UAAU,SAAS,KAAK,UAAU,SAAS,KACzD;AAAA,MACE,UAAU,UAAU,SAAS,IAAI,EAAE,QAAQ,MAAM,MAAM,UAAA,IAAc;AAAA,MACrE,UACE,UAAU,SAAS,IACf,EAAE,QAAQ,MAAM,QAAQ,QAAQ,MAAM,UAAA,IACtC;AAAA,IAAA,IAER,CAAA;AAAA,EAAC,EACL;AAEF,SAAO;AAAA,IACL,SAAS;AAAA,MACP,SAAS;AAAA,MACT,aAAa,EAAE,MAAM,QAAA;AAAA,IAAiB;AAAA,IAExC,QAAQ;AAAA,MACN,MAAM,OAAO;AAAA,MACb,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,UAAU,oBAAoB,cAAc,OAAO,YAAY;AAAA,IAAA;AAAA,IAEjE,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,MACP,QAAQ,OAAO,aAAa,QAAQ;AAAA,MACpC,cAAc;AAAA,IAAA;AAAA,IAEhB,OAAO,EAAE,MAAM,OAAA;AAAA,IACf,OAAO,EAAE,MAAM,QAAA;AAAA,IACf;AAAA,EAAA;AAEJ;;;;;;"}
1
+ {"version":3,"file":"index90.cjs","sources":["../src/charts/ScatterChartCard/foldPoints.ts"],"sourcesContent":["import type { ScatterPoint, ScatterRenderInfo } from '../../types/chart.types';\n\n/** A drawn mark, standing for one or more coincident source points. */\nexport interface FoldedPoint {\n /** Representative point. `weight` is the sum across the folded group. */\n point: ScatterPoint;\n /** Index of the representative in the original `data` array. */\n index: number;\n /** How many source points this mark stands for (1 when nothing folded). */\n count: number;\n}\n\nexport interface FoldResult {\n points: FoldedPoint[];\n info: ScatterRenderInfo;\n}\n\n/** Weight a point contributes when folding; unweighted points count as one. */\nconst weightOf = (point: ScatterPoint) => point.weight ?? 1;\n\n/**\n * Group points sharing the same (x, y) into a single mark, summing their weights.\n * A group of one keeps its original weight — including `undefined`, so a dataset\n * with no weights at all stays unweighted and renders at the base symbol size.\n */\nconst fold = (data: ScatterPoint[]): FoldedPoint[] => {\n const byPosition = new Map<string, FoldedPoint>();\n\n data.forEach((point, index) => {\n const key = `${point.x}|${point.y}`;\n const existing = byPosition.get(key);\n\n if (!existing) {\n byPosition.set(key, { point, index, count: 1 });\n return;\n }\n\n existing.count += 1;\n existing.point = {\n ...existing.point,\n weight: weightOf(existing.point) + weightOf(point),\n };\n });\n\n return [...byPosition.values()];\n};\n\n/**\n * Evenly spread `cap` marks across `points`, always keeping the first and last.\n * Deterministic on purpose: the same data must always draw the same chart.\n */\nconst sample = (points: FoldedPoint[], cap: number): FoldedPoint[] => {\n if (cap <= 1) return points.slice(0, Math.max(cap, 0));\n\n const lastIndex = points.length - 1;\n const step = lastIndex / (cap - 1);\n\n return Array.from({ length: cap }, (_, i) => points[Math.round(i * step)]);\n};\n\n/**\n * Fold coincident points, then cap the mark count, then report what happened.\n * Folding runs first because it often removes the need to sample at all.\n *\n * The reported counts satisfy `total === drawn + merged + dropped`.\n */\nexport const foldPoints = (\n data: ScatterPoint[],\n maxPoints: number,\n mergeCoincident: boolean,\n): FoldResult => {\n const folded = mergeCoincident\n ? fold(data)\n : data.map((point, index) => ({ point, index, count: 1 }));\n\n const points = folded.length > maxPoints ? sample(folded, maxPoints) : folded;\n\n const represented = points.reduce((sum, p) => sum + p.count, 0);\n\n return {\n points,\n info: {\n total: data.length,\n drawn: points.length,\n merged: represented - points.length,\n dropped: data.length - represented,\n },\n };\n};\n"],"names":[],"mappings":";;AAkBA,MAAM,WAAW,CAAC,UAAwB,MAAM,UAAU;AAO1D,MAAM,OAAO,CAAC,SAAwC;AAC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{ CHART_COLORS } from "./index67.js";
2
- function groupByCategory(data, limit, order = "total") {
3
- const grouped = /* @__PURE__ */ new Map();
4
- for (const point of data) {
5
- const key = point.category ?? "Unknown";
6
- if (!grouped.has(key)) {
7
- grouped.set(key, []);
1
+ const weightOf = (point) => point.weight ?? 1;
2
+ const fold = (data) => {
3
+ const byPosition = /* @__PURE__ */ new Map();
4
+ data.forEach((point, index) => {
5
+ const key = `${point.x}|${point.y}`;
6
+ const existing = byPosition.get(key);
7
+ if (!existing) {
8
+ byPosition.set(key, { point, index, count: 1 });
9
+ return;
8
10
  }
9
- grouped.get(key).push({
10
- ts: point.ts ?? "",
11
- value: point.value
12
- });
13
- }
14
- const entries = order === "first-seen" ? [...grouped.entries()] : [...grouped.entries()].sort(
15
- (a, b) => b[1].reduce((sum, p) => sum + p.value, 0) - a[1].reduce((sum, p) => sum + p.value, 0)
16
- );
17
- if (entries.length <= limit) {
18
- return entries;
19
- }
20
- const top = entries.slice(0, limit - 1);
21
- const rest = entries.slice(limit - 1);
22
- const otherMap = /* @__PURE__ */ new Map();
23
- for (const [, points] of rest) {
24
- for (const p of points) {
25
- otherMap.set(p.ts, (otherMap.get(p.ts) ?? 0) + p.value);
26
- }
27
- }
28
- const otherPoints = [...otherMap.entries()].map(([ts, value]) => ({
29
- ts,
30
- value
31
- }));
32
- return [...top, ["Other", otherPoints]];
33
- }
34
- function buildMarkAreas(annotations) {
35
- return annotations.filter((a) => a.end).map((a) => [
36
- {
37
- name: a.label,
38
- xAxis: a.start,
39
- itemStyle: { color: a.color ?? "rgba(255,107,90,0.1)" }
40
- },
41
- { xAxis: a.end }
42
- ]);
43
- }
44
- function buildMarkLines(annotations) {
45
- return annotations.filter((a) => !a.end).map((a) => ({
46
- name: a.label,
47
- xAxis: a.start,
48
- lineStyle: { color: a.color ?? CHART_COLORS[0], type: "dashed" },
49
- label: { formatter: a.label, position: "end" }
50
- }));
51
- }
52
- function buildReferenceLines(referenceLines) {
53
- return referenceLines.map((r) => ({
54
- name: r.label ?? String(r.value),
55
- yAxis: r.value,
56
- lineStyle: {
57
- color: r.color ?? CHART_COLORS[0],
58
- type: r.dashed === false ? "solid" : "dashed"
59
- },
60
- label: {
61
- formatter: r.label ?? String(r.value),
62
- position: "insideEndTop"
63
- }
64
- }));
65
- }
66
- function buildLegendSelected(seriesGroups, hiddenSeries) {
67
- if (!hiddenSeries) return void 0;
68
- const hidden = hiddenSeries instanceof Set ? hiddenSeries : new Set(hiddenSeries);
69
- return Object.fromEntries(seriesGroups.map(([name]) => [name, !hidden.has(name)]));
70
- }
71
- function buildTemporalTrendOption(seriesGroups, config) {
72
- const markAreas = buildMarkAreas(config.annotations);
73
- const markLines = [
74
- ...buildMarkLines(config.annotations),
75
- ...buildReferenceLines(config.referenceLines)
76
- ];
77
- const series = seriesGroups.map(([name, points], idx) => ({
78
- name,
79
- type: "line",
80
- ...config.stacked ? { stack: "total", areaStyle: {} } : {},
81
- emphasis: { focus: "series" },
82
- color: CHART_COLORS[idx % CHART_COLORS.length],
83
- data: points.sort((a, b) => a.ts < b.ts ? -1 : 1).map((p) => [p.ts, p.value]),
84
- ...idx === 0 && (markAreas.length > 0 || markLines.length > 0) ? {
85
- markArea: markAreas.length > 0 ? { silent: true, data: markAreas } : void 0,
86
- markLine: markLines.length > 0 ? { silent: true, symbol: "none", data: markLines } : void 0
87
- } : {}
88
- }));
11
+ existing.count += 1;
12
+ existing.point = {
13
+ ...existing.point,
14
+ weight: weightOf(existing.point) + weightOf(point)
15
+ };
16
+ });
17
+ return [...byPosition.values()];
18
+ };
19
+ const sample = (points, cap) => {
20
+ if (cap <= 1) return points.slice(0, Math.max(cap, 0));
21
+ const lastIndex = points.length - 1;
22
+ const step = lastIndex / (cap - 1);
23
+ return Array.from({ length: cap }, (_, i) => points[Math.round(i * step)]);
24
+ };
25
+ const foldPoints = (data, maxPoints, mergeCoincident) => {
26
+ const folded = mergeCoincident ? fold(data) : data.map((point, index) => ({ point, index, count: 1 }));
27
+ const points = folded.length > maxPoints ? sample(folded, maxPoints) : folded;
28
+ const represented = points.reduce((sum, p) => sum + p.count, 0);
89
29
  return {
90
- tooltip: {
91
- trigger: "axis",
92
- axisPointer: { type: "cross" }
93
- },
94
- legend: {
95
- show: config.showLegend,
96
- type: "scroll",
97
- bottom: 0,
98
- selected: buildLegendSelected(seriesGroups, config.hiddenSeries)
99
- },
100
- grid: {
101
- left: "3%",
102
- right: "4%",
103
- bottom: config.showLegend ? "15%" : "3%",
104
- containLabel: true
105
- },
106
- xAxis: { type: "time" },
107
- yAxis: { type: "value" },
108
- series
30
+ points,
31
+ info: {
32
+ total: data.length,
33
+ drawn: points.length,
34
+ merged: represented - points.length,
35
+ dropped: data.length - represented
36
+ }
109
37
  };
110
- }
38
+ };
111
39
  export {
112
- buildMarkAreas,
113
- buildMarkLines,
114
- buildReferenceLines,
115
- buildTemporalTrendOption,
116
- groupByCategory
40
+ foldPoints
117
41
  };
118
42
  //# sourceMappingURL=index90.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index90.js","sources":["../src/charts/TemporalTrendChartCard/buildChartOption.ts"],"sourcesContent":["import type {\n ChartSeriesPoint,\n ChartAnnotation,\n ReferenceLine,\n} from '../../types/chart.types';\nimport type { TemporalSeriesOrder } from './TemporalTrendChartCard.types';\nimport { CHART_COLORS } from '../../constants';\n\n/** A category and its points, sorted by the active series order. */\nexport type SeriesGroup = [string, { ts: string; value: number }[]];\n\nexport interface TemporalTrendOptionConfig {\n annotations: ChartAnnotation[];\n referenceLines: ReferenceLine[];\n showLegend: boolean;\n stacked: boolean;\n /** Series to start hidden. `undefined` leaves legend selection uncontrolled. */\n hiddenSeries?: Set<string> | string[];\n}\n\n/** Group data points by category, returning sorted series keyed by category name. */\nexport function groupByCategory(\n data: ChartSeriesPoint[],\n limit: number,\n order: TemporalSeriesOrder = 'total',\n): SeriesGroup[] {\n const grouped = new Map<string, { ts: string; value: number }[]>();\n\n for (const point of data) {\n const key = point.category ?? 'Unknown';\n if (!grouped.has(key)) {\n grouped.set(key, []);\n }\n grouped.get(key)!.push({\n ts: point.ts ?? '',\n value: point.value,\n });\n }\n\n // `first-seen` keeps the Map's insertion order, so each series keeps its\n // colour when the data is refreshed and the totals move.\n const entries =\n order === 'first-seen'\n ? [...grouped.entries()]\n : [...grouped.entries()].sort(\n (a, b) =>\n b[1].reduce((sum, p) => sum + p.value, 0) -\n a[1].reduce((sum, p) => sum + p.value, 0),\n );\n\n if (entries.length <= limit) {\n return entries;\n }\n\n const top = entries.slice(0, limit - 1);\n const rest = entries.slice(limit - 1);\n\n const otherMap = new Map<string, number>();\n for (const [, points] of rest) {\n for (const p of points) {\n otherMap.set(p.ts, (otherMap.get(p.ts) ?? 0) + p.value);\n }\n }\n\n const otherPoints = [...otherMap.entries()].map(([ts, value]) => ({\n ts,\n value,\n }));\n\n return [...top, ['Other', otherPoints] as SeriesGroup];\n}\n\n/** Build markArea items from range annotations. */\nexport function buildMarkAreas(annotations: ChartAnnotation[]) {\n return annotations\n .filter((a) => a.end)\n .map((a) => [\n {\n name: a.label,\n xAxis: a.start,\n itemStyle: { color: a.color ?? 'rgba(255,107,90,0.1)' },\n },\n { xAxis: a.end },\n ]);\n}\n\n/** Build markLine items from point annotations. */\nexport function buildMarkLines(annotations: ChartAnnotation[]) {\n return annotations\n .filter((a) => !a.end)\n .map((a) => ({\n name: a.label,\n xAxis: a.start,\n lineStyle: { color: a.color ?? CHART_COLORS[0], type: 'dashed' as const },\n label: { formatter: a.label, position: 'end' as const },\n }));\n}\n\n/** Build markLine items from horizontal reference lines (KPI target, threshold). */\nexport function buildReferenceLines(referenceLines: ReferenceLine[]) {\n return referenceLines.map((r) => ({\n name: r.label ?? String(r.value),\n yAxis: r.value,\n lineStyle: {\n color: r.color ?? CHART_COLORS[0],\n type: r.dashed === false ? ('solid' as const) : ('dashed' as const),\n },\n label: {\n formatter: r.label ?? String(r.value),\n position: 'insideEndTop' as const,\n },\n }));\n}\n\n/**\n * Legend selection map. Hiding through the legend rather than filtering the\n * series array keeps every series at its own index, and so at its own colour.\n */\nfunction buildLegendSelected(\n seriesGroups: SeriesGroup[],\n hiddenSeries: Set<string> | string[] | undefined,\n) {\n if (!hiddenSeries) return undefined;\n\n const hidden = hiddenSeries instanceof Set ? hiddenSeries : new Set(hiddenSeries);\n return Object.fromEntries(seriesGroups.map(([name]) => [name, !hidden.has(name)]));\n}\n\n/** Assemble the ECharts option for the temporal trend card. */\nexport function buildTemporalTrendOption(\n seriesGroups: SeriesGroup[],\n config: TemporalTrendOptionConfig,\n) {\n const markAreas = buildMarkAreas(config.annotations);\n const markLines = [\n ...buildMarkLines(config.annotations),\n ...buildReferenceLines(config.referenceLines),\n ];\n\n const series = seriesGroups.map(([name, points], idx) => ({\n name,\n type: 'line' as const,\n ...(config.stacked ? { stack: 'total', areaStyle: {} } : {}),\n emphasis: { focus: 'series' as const },\n color: CHART_COLORS[idx % CHART_COLORS.length],\n data: points\n .sort((a, b) => (a.ts < b.ts ? -1 : 1))\n .map((p) => [p.ts, p.value]),\n ...(idx === 0 && (markAreas.length > 0 || markLines.length > 0)\n ? {\n markArea: markAreas.length > 0 ? { silent: true, data: markAreas } : undefined,\n markLine:\n markLines.length > 0\n ? { silent: true, symbol: 'none', data: markLines }\n : undefined,\n }\n : {}),\n }));\n\n return {\n tooltip: {\n trigger: 'axis' as const,\n axisPointer: { type: 'cross' as const },\n },\n legend: {\n show: config.showLegend,\n type: 'scroll' as const,\n bottom: 0,\n selected: buildLegendSelected(seriesGroups, config.hiddenSeries),\n },\n grid: {\n left: '3%',\n right: '4%',\n bottom: config.showLegend ? '15%' : '3%',\n containLabel: true,\n },\n xAxis: { type: 'time' as const },\n yAxis: { type: 'value' as const },\n series,\n };\n}\n"],"names":[],"mappings":";AAqBO,SAAS,gBACd,MACA,OACA,QAA6B,SACd;AACf,QAAM,8BAAc,IAAA;AAEpB,aAAW,SAAS,MAAM;AACxB,UAAM,MAAM,MAAM,YAAY;AAC9B,QAAI,CAAC,QAAQ,IAAI,GAAG,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E,OAAO,SAAS,WAAW,CAAA,EAAC,IAAM,CAAA;AAAA,IACzD,UAAU,EAAE,OAAO,SAAA;AAAA,IACnB,OAAO,aAAa,MAAM,aAAa,MAAM;AAAA,IAC7C,MAAM,OACH,KAAK,CAAC,GAAG,MAAO,EAAE,KAAK,EAAE,KAAK,KAAK,CAAE,EACrC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC;AAAA,IAC7B,GAAI,QAAQ,MAAM,UAAU,SAAS,KAAK,UAAU,SAAS,KACzD;AAAA,MACE,UAAU,UAAU,SAAS,IAAI,EAAE,QAAQ,MAAM,MAAM,UAAA,IAAc;AAAA,MACrE,UACE,UAAU,SAAS,IACf,EAAE,QAAQ,MAAM,QAAQ,QAAQ,MAAM,UAAA,IACtC;AAAA,IAAA,IAER,CAAA;AAAA,EAAC,EACL;AAEF,SAAO;AAAA,IACL,SAAS;AAAA,MACP,SAAS;AAAA,MACT,aAAa,EAAE,MAAM,QAAA;AAAA,IAAiB;AAAA,IAExC,QAAQ;AAAA,MACN,MAAM,OAAO;AAAA,MACb,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,UAAU,oBAAoB,cAAc,OAAO,YAAY;AAAA,IAAA;AAAA,IAEjE,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,MACP,QAAQ,OAAO,aAAa,QAAQ;AAAA,MACpC,cAAc;AAAA,IAAA;AAAA,IAEhB,OAAO,EAAE,MAAM,OAAA;AAAA,IACf,OAAO,EAAE,MAAM,QAAA;AAAA,IACf;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"index90.js","sources":["../src/charts/ScatterChartCard/foldPoints.ts"],"sourcesContent":["import type { ScatterPoint, ScatterRenderInfo } from '../../types/chart.types';\n\n/** A drawn mark, standing for one or more coincident source points. */\nexport interface FoldedPoint {\n /** Representative point. `weight` is the sum across the folded group. */\n point: ScatterPoint;\n /** Index of the representative in the original `data` array. */\n index: number;\n /** How many source points this mark stands for (1 when nothing folded). */\n count: number;\n}\n\nexport interface FoldResult {\n points: FoldedPoint[];\n info: ScatterRenderInfo;\n}\n\n/** Weight a point contributes when folding; unweighted points count as one. */\nconst weightOf = (point: ScatterPoint) => point.weight ?? 1;\n\n/**\n * Group points sharing the same (x, y) into a single mark, summing their weights.\n * A group of one keeps its original weight — including `undefined`, so a dataset\n * with no weights at all stays unweighted and renders at the base symbol size.\n */\nconst fold = (data: ScatterPoint[]): FoldedPoint[] => {\n const byPosition = new Map<string, FoldedPoint>();\n\n data.forEach((point, index) => {\n const key = `${point.x}|${point.y}`;\n const existing = byPosition.get(key);\n\n if (!existing) {\n byPosition.set(key, { point, index, count: 1 });\n return;\n }\n\n existing.count += 1;\n existing.point = {\n ...existing.point,\n weight: weightOf(existing.point) + weightOf(point),\n };\n });\n\n return [...byPosition.values()];\n};\n\n/**\n * Evenly spread `cap` marks across `points`, always keeping the first and last.\n * Deterministic on purpose: the same data must always draw the same chart.\n */\nconst sample = (points: FoldedPoint[], cap: number): FoldedPoint[] => {\n if (cap <= 1) return points.slice(0, Math.max(cap, 0));\n\n const lastIndex = points.length - 1;\n const step = lastIndex / (cap - 1);\n\n return Array.from({ length: cap }, (_, i) => points[Math.round(i * step)]);\n};\n\n/**\n * Fold coincident points, then cap the mark count, then report what happened.\n * Folding runs first because it often removes the need to sample at all.\n *\n * The reported counts satisfy `total === drawn + merged + dropped`.\n */\nexport const foldPoints = (\n data: ScatterPoint[],\n maxPoints: number,\n mergeCoincident: boolean,\n): FoldResult => {\n const folded = mergeCoincident\n ? fold(data)\n : data.map((point, index) => ({ point, index, count: 1 }));\n\n const points = folded.length > maxPoints ? sample(folded, maxPoints) : folded;\n\n const represented = points.reduce((sum, p) => sum + p.count, 0);\n\n return {\n points,\n info: {\n total: data.length,\n drawn: points.length,\n merged: represented - points.length,\n dropped: data.length - represented,\n },\n };\n};\n"],"names":[],"mappings":"AAkBA,MAAM,WAAW,CAAC,UAAwB,MAAM,UAAU;AAO1D,MAA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
@@ -1,45 +1,95 @@
1
1
  "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const root = "krc-root-xM3Jn";
4
- const header = "krc-header-Pg9ER";
5
- const title = "krc-title-MRZQn";
6
- const headerRight = "krc-headerRight-b0xzW";
7
- const toolbar = "krc-toolbar--rsIi";
8
- const select = "krc-select-79sIN";
9
- const legendToggle = "krc-legendToggle--ofSS";
10
- const legendToggleActive = "krc-legendToggleActive-14gdq";
11
- const chartContainer = "krc-chartContainer-tDTrg";
12
- const loading = "krc-loading-WkgGt";
13
- const error = "krc-error-yzAKV";
14
- const retryButton = "krc-retryButton-wTkWq";
15
- const empty = "krc-empty-1EZzg";
16
- const styles = {
17
- root,
18
- header,
19
- title,
20
- headerRight,
21
- toolbar,
22
- select,
23
- legendToggle,
24
- legendToggleActive,
25
- chartContainer,
26
- loading,
27
- error,
28
- retryButton,
29
- empty
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const constants = require("./index71.cjs");
4
+ const AXIS_NAME_GAP = { X: 28, Y: 38 };
5
+ const GRID_MARGIN = {
6
+ BASE: 8,
7
+ TOP: 16,
8
+ RIGHT: 16,
9
+ X_NAME: 23,
10
+ Y_NAME: 34,
11
+ LEGEND: 30
30
12
  };
31
- exports.chartContainer = chartContainer;
32
- exports.default = styles;
33
- exports.empty = empty;
34
- exports.error = error;
35
- exports.header = header;
36
- exports.headerRight = headerRight;
37
- exports.legendToggle = legendToggle;
38
- exports.legendToggleActive = legendToggleActive;
39
- exports.loading = loading;
40
- exports.retryButton = retryButton;
41
- exports.root = root;
42
- exports.select = select;
43
- exports.title = title;
44
- exports.toolbar = toolbar;
13
+ const UNCATEGORISED_SERIES = "Points";
14
+ const escapeHtml = (value) => value.replace(/[&<>"]/g, (char) => `&#${char.charCodeAt(0)};`);
15
+ const symbolSizeFor = (weight, minWeight, maxWeight) => {
16
+ if (maxWeight === minWeight) return constants.SCATTER.BASE_SYMBOL_SIZE;
17
+ const ratio = Math.sqrt((weight - minWeight) / (maxWeight - minWeight));
18
+ return constants.SCATTER.MIN_SYMBOL_SIZE + (constants.SCATTER.MAX_SYMBOL_SIZE - constants.SCATTER.MIN_SYMBOL_SIZE) * ratio;
19
+ };
20
+ const groupByCategory = (points) => {
21
+ const groups = /* @__PURE__ */ new Map();
22
+ for (const folded of points) {
23
+ const key = folded.point.category ?? UNCATEGORISED_SERIES;
24
+ const group = groups.get(key);
25
+ if (group) group.push(folded);
26
+ else groups.set(key, [folded]);
27
+ }
28
+ return groups;
29
+ };
30
+ const toDataItem = (folded, sizeOf) => ({
31
+ name: folded.point.label,
32
+ value: [folded.point.x, folded.point.y, folded.count, folded.index],
33
+ symbolSize: sizeOf(folded.point.weight)
34
+ });
35
+ const buildTooltipFormatter = (config) => (params) => {
36
+ const { name, seriesName, value, marker } = params;
37
+ const [x, y, count] = value;
38
+ const lines = [`${marker} ${escapeHtml(name)}`];
39
+ lines.push(`${escapeHtml(config.xLabel ?? "x")}: ${x}`);
40
+ lines.push(`${escapeHtml(config.yLabel ?? "y")}: ${y}`);
41
+ if (seriesName !== UNCATEGORISED_SERIES) {
42
+ lines.push(`${escapeHtml(config.categoryLabel ?? "Category")}: ${escapeHtml(seriesName)}`);
43
+ }
44
+ if (count > 1) lines.push(`${count} points here`);
45
+ return lines.join("<br/>");
46
+ };
47
+ const buildScatterOption = (points, config) => {
48
+ const weights = points.map((p) => p.point.weight).filter((w) => w != null);
49
+ const minWeight = weights.length > 0 ? Math.min(...weights) : 0;
50
+ const maxWeight = weights.length > 0 ? Math.max(...weights) : 0;
51
+ const sizeOf = (weight) => weights.length === 0 ? constants.SCATTER.BASE_SYMBOL_SIZE : symbolSizeFor(weight ?? minWeight, minWeight, maxWeight);
52
+ const groups = groupByCategory(points);
53
+ const series = [...groups.entries()].map(([category, group], i) => ({
54
+ name: category,
55
+ type: "scatter",
56
+ data: group.map((folded) => toDataItem(folded, sizeOf)),
57
+ itemStyle: { color: constants.CHART_COLORS[i % constants.CHART_COLORS.length], opacity: 0.85 },
58
+ emphasis: { focus: "series" }
59
+ }));
60
+ return {
61
+ tooltip: { trigger: "item", formatter: buildTooltipFormatter(config) },
62
+ legend: config.showLegend ? { bottom: 0, type: "scroll" } : void 0,
63
+ grid: {
64
+ left: config.yLabel ? GRID_MARGIN.Y_NAME : GRID_MARGIN.BASE,
65
+ right: GRID_MARGIN.RIGHT,
66
+ top: GRID_MARGIN.TOP,
67
+ // Room for the x axis name and the legend, each only when drawn.
68
+ bottom: GRID_MARGIN.BASE + (config.xLabel ? GRID_MARGIN.X_NAME : 0) + (config.showLegend ? GRID_MARGIN.LEGEND : 0),
69
+ containLabel: true
70
+ },
71
+ xAxis: {
72
+ type: "value",
73
+ name: config.xLabel,
74
+ nameLocation: "middle",
75
+ nameGap: AXIS_NAME_GAP.X,
76
+ scale: true
77
+ },
78
+ yAxis: {
79
+ type: "value",
80
+ name: config.yLabel,
81
+ nameLocation: "middle",
82
+ // Without this the y name is drawn horizontally and eats the plot's width.
83
+ nameRotate: 90,
84
+ nameGap: AXIS_NAME_GAP.Y,
85
+ scale: true
86
+ },
87
+ dataZoom: config.enableDataZoom ? [
88
+ { type: "inside", xAxisIndex: 0 },
89
+ { type: "inside", yAxisIndex: 0 }
90
+ ] : void 0,
91
+ series
92
+ };
93
+ };
94
+ exports.buildScatterOption = buildScatterOption;
45
95
  //# sourceMappingURL=index91.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index91.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index91.cjs","sources":["../src/charts/ScatterChartCard/buildScatterOption.ts"],"sourcesContent":["import type { FoldedPoint } from './foldPoints';\nimport { CHART_COLORS, SCATTER } from '../../constants';\n\n/** Distance from each axis line to its name (px — echarts canvas attributes, not CSS). */\nconst AXIS_NAME_GAP = { X: 28, Y: 38 } as const;\n\n/**\n * Grid margins (px). `containLabel` reserves room for the tick *labels* only, so\n * the axis names and the legend need their own margin or they get clipped at the\n * canvas edge. Each margin must exceed its `AXIS_NAME_GAP` by a text height.\n */\nconst GRID_MARGIN = {\n BASE: 8,\n TOP: 16,\n RIGHT: 16,\n X_NAME: 23,\n Y_NAME: 34,\n LEGEND: 30,\n} as const;\n\n/** Series name used when no point carries a category. */\nconst UNCATEGORISED_SERIES = 'Points';\n\nexport interface ScatterOptionConfig {\n xLabel?: string;\n yLabel?: string;\n categoryLabel?: string;\n showLegend: boolean;\n enableDataZoom: boolean;\n}\n\n/** Point labels come from consumer data and land in the tooltip's HTML. */\nconst escapeHtml = (value: string) =>\n value.replace(/[&<>\"]/g, (char) => `&#${char.charCodeAt(0)};`);\n\n/**\n * Map a weight onto a symbol diameter. The square root keeps the mark *area*\n * proportional to the weight, which is how a reader compares bubble sizes.\n * A dataset whose weights are all equal carries no size information, so it\n * renders at the base size rather than all-maximum.\n */\nconst symbolSizeFor = (weight: number, minWeight: number, maxWeight: number) => {\n if (maxWeight === minWeight) return SCATTER.BASE_SYMBOL_SIZE;\n\n const ratio = Math.sqrt((weight - minWeight) / (maxWeight - minWeight));\n return SCATTER.MIN_SYMBOL_SIZE + (SCATTER.MAX_SYMBOL_SIZE - SCATTER.MIN_SYMBOL_SIZE) * ratio;\n};\n\n/** Group marks by category, preserving first-appearance order. */\nconst groupByCategory = (points: FoldedPoint[]) => {\n const groups = new Map<string, FoldedPoint[]>();\n\n for (const folded of points) {\n const key = folded.point.category ?? UNCATEGORISED_SERIES;\n const group = groups.get(key);\n if (group) group.push(folded);\n else groups.set(key, [folded]);\n }\n\n return groups;\n};\n\n/** `[x, y, count, sourceIndex]` — dims beyond the axes carry the tooltip/click metadata. */\nconst toDataItem = (folded: FoldedPoint, sizeOf: (weight: number | null | undefined) => number) => ({\n name: folded.point.label,\n value: [folded.point.x, folded.point.y, folded.count, folded.index],\n symbolSize: sizeOf(folded.point.weight),\n});\n\nconst buildTooltipFormatter = (config: ScatterOptionConfig) => (params: unknown) => {\n const { name, seriesName, value, marker } = params as {\n name: string;\n seriesName: string;\n value: [number, number, number, number];\n marker: string;\n };\n const [x, y, count] = value;\n\n const lines = [`${marker} ${escapeHtml(name)}`];\n lines.push(`${escapeHtml(config.xLabel ?? 'x')}: ${x}`);\n lines.push(`${escapeHtml(config.yLabel ?? 'y')}: ${y}`);\n\n if (seriesName !== UNCATEGORISED_SERIES) {\n lines.push(`${escapeHtml(config.categoryLabel ?? 'Category')}: ${escapeHtml(seriesName)}`);\n }\n\n if (count > 1) lines.push(`${count} points here`);\n\n return lines.join('<br/>');\n};\n\nexport const buildScatterOption = (points: FoldedPoint[], config: ScatterOptionConfig) => {\n const weights = points.map((p) => p.point.weight).filter((w): w is number => w != null);\n const minWeight = weights.length > 0 ? Math.min(...weights) : 0;\n const maxWeight = weights.length > 0 ? Math.max(...weights) : 0;\n\n // An absent weight sits at the bottom of the scale once any weight is present,\n // and yields the base size when none is.\n const sizeOf = (weight: number | null | undefined) =>\n weights.length === 0\n ? SCATTER.BASE_SYMBOL_SIZE\n : symbolSizeFor(weight ?? minWeight, minWeight, maxWeight);\n\n const groups = groupByCategory(points);\n const series = [...groups.entries()].map(([category, group], i) => ({\n name: category,\n type: 'scatter' as const,\n data: group.map((folded) => toDataItem(folded, sizeOf)),\n itemStyle: { color: CHART_COLORS[i % CHART_COLORS.length], opacity: 0.85 },\n emphasis: { focus: 'series' as const },\n }));\n\n return {\n tooltip: { trigger: 'item' as const, formatter: buildTooltipFormatter(config) },\n legend: config.showLegend ? { bottom: 0, type: 'scroll' as const } : undefined,\n grid: {\n left: config.yLabel ? GRID_MARGIN.Y_NAME : GRID_MARGIN.BASE,\n right: GRID_MARGIN.RIGHT,\n top: GRID_MARGIN.TOP,\n // Room for the x axis name and the legend, each only when drawn.\n bottom:\n GRID_MARGIN.BASE +\n (config.xLabel ? GRID_MARGIN.X_NAME : 0) +\n (config.showLegend ? GRID_MARGIN.LEGEND : 0),\n containLabel: true,\n },\n xAxis: {\n type: 'value' as const,\n name: config.xLabel,\n nameLocation: 'middle' as const,\n nameGap: AXIS_NAME_GAP.X,\n scale: true,\n },\n yAxis: {\n type: 'value' as const,\n name: config.yLabel,\n nameLocation: 'middle' as const,\n // Without this the y name is drawn horizontally and eats the plot's width.\n nameRotate: 90,\n nameGap: AXIS_NAME_GAP.Y,\n scale: true,\n },\n dataZoom: config.enableDataZoom\n ? [\n { type: 'inside' as const, xAxisIndex: 0 },\n { type: 'inside' as const, yAxisIndex: 0 },\n ]\n : undefined,\n series,\n };\n};\n"],"names":["SCATTER","CHART_COLORS"],"mappings":";;;AAIA,MAAM,gBAAgB,EAAE,GAAG,IAAI,GAAG,GAAA;AAOlC,MAAM,cAAc;AAAA,EAClB,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AACV;AAGA,MAAM,uBAAuB;AAW7B,MAAM,aAAa,CAAC,UAClB,MAAM,QAAQ,WAAW,CAAC,SAAS,KAAK,KAAK,WAAW,CAAC,CAAC,GAAG;AAQ/D,MAAM,gBAAgB,CAAC,QAAgB,WAAmB,cAAsB;AAC9E,MAAI,cAAc,UAAW,QAAOA,UAAAA,QAAQ;AAE5C,QAAM,QAAQ,KAAK,MAAM,SAAS,cAAc,YAAY,UAAU;AACtE,SAAOA,UAAAA,QAAQ,mBAAmBA,UAAAA,QAAQ,kBAAkBA,UAAAA,QAAQ,mBAAmB;AACzF;AAGA,MAAM,kBAAkB,CAAC,WAA0B;AACjD,QAAM,6BAAa,IAAA;AAEnB,aAAW,UAAU,QAAQ;AAC3B,UAAM,MAAM,OAAO,MAAM,YAAY;AACrC,UAAM,QAAQ,OAAO,IAAI,GAAG;AAC5B,QAAI,MAAO,OAAM,KAAK,MAAM;AAAA,QACvB,QAAO,IAAI,KAAK,CAAC,MAAM,CAAC;AAAA,EAC/B;AAEA,SAAO;AACT;AAGA,MAAM,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