@tetrascience-npm/tetrascience-react-ui 0.6.0 → 0.7.0-beta.103.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 (184) hide show
  1. package/README.md +55 -0
  2. package/dist/components/ai/chain-of-thought.cjs +1 -1
  3. package/dist/components/ai/chain-of-thought.cjs.map +1 -1
  4. package/dist/components/ai/chain-of-thought.js +5 -5
  5. package/dist/components/ai/chain-of-thought.js.map +1 -1
  6. package/dist/components/ai/conversation.cjs +2 -2
  7. package/dist/components/ai/conversation.cjs.map +1 -1
  8. package/dist/components/ai/conversation.js +2 -2
  9. package/dist/components/ai/conversation.js.map +1 -1
  10. package/dist/components/ai/queue.cjs +1 -1
  11. package/dist/components/ai/queue.cjs.map +1 -1
  12. package/dist/components/ai/queue.js +9 -9
  13. package/dist/components/ai/queue.js.map +1 -1
  14. package/dist/components/charts/AreaGraph/AreaGraph.cjs +1 -1
  15. package/dist/components/charts/AreaGraph/AreaGraph.cjs.map +1 -1
  16. package/dist/components/charts/AreaGraph/AreaGraph.js +165 -103
  17. package/dist/components/charts/AreaGraph/AreaGraph.js.map +1 -1
  18. package/dist/components/charts/BarGraph/BarGraph.cjs +1 -1
  19. package/dist/components/charts/BarGraph/BarGraph.cjs.map +1 -1
  20. package/dist/components/charts/BarGraph/BarGraph.js +135 -90
  21. package/dist/components/charts/BarGraph/BarGraph.js.map +1 -1
  22. package/dist/components/charts/Boxplot/Boxplot.cjs +1 -1
  23. package/dist/components/charts/Boxplot/Boxplot.cjs.map +1 -1
  24. package/dist/components/charts/Boxplot/Boxplot.js +130 -92
  25. package/dist/components/charts/Boxplot/Boxplot.js.map +1 -1
  26. package/dist/components/charts/ChartTooltip/ChartTooltip.cjs +2 -0
  27. package/dist/components/charts/ChartTooltip/ChartTooltip.cjs.map +1 -0
  28. package/dist/components/charts/ChartTooltip/ChartTooltip.js +163 -0
  29. package/dist/components/charts/ChartTooltip/ChartTooltip.js.map +1 -0
  30. package/dist/components/charts/ChartTooltip/lines.cjs +2 -0
  31. package/dist/components/charts/ChartTooltip/lines.cjs.map +1 -0
  32. package/dist/components/charts/ChartTooltip/lines.js +29 -0
  33. package/dist/components/charts/ChartTooltip/lines.js.map +1 -0
  34. package/dist/components/charts/Chromatogram/Chromatogram.cjs +1 -1
  35. package/dist/components/charts/Chromatogram/Chromatogram.cjs.map +1 -1
  36. package/dist/components/charts/Chromatogram/Chromatogram.js +75 -61
  37. package/dist/components/charts/Chromatogram/Chromatogram.js.map +1 -1
  38. package/dist/components/charts/ChromatogramChart/ChromatogramChart.cjs +1 -1
  39. package/dist/components/charts/ChromatogramChart/ChromatogramChart.cjs.map +1 -1
  40. package/dist/components/charts/ChromatogramChart/ChromatogramChart.js +116 -108
  41. package/dist/components/charts/ChromatogramChart/ChromatogramChart.js.map +1 -1
  42. package/dist/components/charts/ChromatogramChart/annotations.cjs +1 -1
  43. package/dist/components/charts/ChromatogramChart/annotations.cjs.map +1 -1
  44. package/dist/components/charts/ChromatogramChart/annotations.js +32 -32
  45. package/dist/components/charts/ChromatogramChart/annotations.js.map +1 -1
  46. package/dist/components/charts/ChromatogramChart/boundaryMarkers.cjs +1 -1
  47. package/dist/components/charts/ChromatogramChart/boundaryMarkers.cjs.map +1 -1
  48. package/dist/components/charts/ChromatogramChart/boundaryMarkers.js +6 -6
  49. package/dist/components/charts/ChromatogramChart/boundaryMarkers.js.map +1 -1
  50. package/dist/components/charts/ChromatogramChart/constants.cjs +1 -1
  51. package/dist/components/charts/ChromatogramChart/constants.cjs.map +1 -1
  52. package/dist/components/charts/ChromatogramChart/constants.js +11 -5
  53. package/dist/components/charts/ChromatogramChart/constants.js.map +1 -1
  54. package/dist/components/charts/ChromatogramChart/dataProcessing.cjs +1 -1
  55. package/dist/components/charts/ChromatogramChart/dataProcessing.cjs.map +1 -1
  56. package/dist/components/charts/ChromatogramChart/dataProcessing.js +38 -49
  57. package/dist/components/charts/ChromatogramChart/dataProcessing.js.map +1 -1
  58. package/dist/components/charts/DotPlot/DotPlot.cjs +1 -1
  59. package/dist/components/charts/DotPlot/DotPlot.cjs.map +1 -1
  60. package/dist/components/charts/DotPlot/DotPlot.js +112 -88
  61. package/dist/components/charts/DotPlot/DotPlot.js.map +1 -1
  62. package/dist/components/charts/Histogram/Histogram.cjs +1 -1
  63. package/dist/components/charts/Histogram/Histogram.cjs.map +1 -1
  64. package/dist/components/charts/Histogram/Histogram.js +132 -115
  65. package/dist/components/charts/Histogram/Histogram.js.map +1 -1
  66. package/dist/components/charts/LineGraph/LineGraph.cjs +1 -1
  67. package/dist/components/charts/LineGraph/LineGraph.cjs.map +1 -1
  68. package/dist/components/charts/LineGraph/LineGraph.js +151 -111
  69. package/dist/components/charts/LineGraph/LineGraph.js.map +1 -1
  70. package/dist/components/charts/PieChart/PieChart.cjs +1 -1
  71. package/dist/components/charts/PieChart/PieChart.cjs.map +1 -1
  72. package/dist/components/charts/PieChart/PieChart.js +81 -70
  73. package/dist/components/charts/PieChart/PieChart.js.map +1 -1
  74. package/dist/components/charts/PlateMap/PlateMap.cjs +1 -1
  75. package/dist/components/charts/PlateMap/PlateMap.cjs.map +1 -1
  76. package/dist/components/charts/PlateMap/PlateMap.js +271 -256
  77. package/dist/components/charts/PlateMap/PlateMap.js.map +1 -1
  78. package/dist/components/charts/PlateMap/constants.cjs +1 -1
  79. package/dist/components/charts/PlateMap/constants.cjs.map +1 -1
  80. package/dist/components/charts/PlateMap/constants.js +20 -29
  81. package/dist/components/charts/PlateMap/constants.js.map +1 -1
  82. package/dist/components/charts/ScatterGraph/ScatterGraph.cjs +1 -1
  83. package/dist/components/charts/ScatterGraph/ScatterGraph.cjs.map +1 -1
  84. package/dist/components/charts/ScatterGraph/ScatterGraph.js +154 -106
  85. package/dist/components/charts/ScatterGraph/ScatterGraph.js.map +1 -1
  86. package/dist/components/composed/DataAppShell/DataAppShell.cjs +1 -1
  87. package/dist/components/composed/DataAppShell/DataAppShell.cjs.map +1 -1
  88. package/dist/components/composed/DataAppShell/DataAppShell.js +118 -111
  89. package/dist/components/composed/DataAppShell/DataAppShell.js.map +1 -1
  90. package/dist/components/composed/PlateMapEditor/PlateMapGrid.cjs +1 -1
  91. package/dist/components/composed/PlateMapEditor/PlateMapGrid.cjs.map +1 -1
  92. package/dist/components/composed/PlateMapEditor/PlateMapGrid.js +1 -1
  93. package/dist/components/composed/PlateMapEditor/PlateMapGrid.js.map +1 -1
  94. package/dist/components/composed/PlateMapEditor/WellLegend.cjs +1 -1
  95. package/dist/components/composed/PlateMapEditor/WellLegend.cjs.map +1 -1
  96. package/dist/components/composed/PlateMapEditor/WellLegend.js +8 -8
  97. package/dist/components/composed/PlateMapEditor/WellLegend.js.map +1 -1
  98. package/dist/components/composed/RichListItem/RichListItem.cjs +1 -1
  99. package/dist/components/composed/RichListItem/RichListItem.cjs.map +1 -1
  100. package/dist/components/composed/RichListItem/RichListItem.js +16 -16
  101. package/dist/components/composed/RichListItem/RichListItem.js.map +1 -1
  102. package/dist/components/ui/accordion.cjs +1 -1
  103. package/dist/components/ui/accordion.cjs.map +1 -1
  104. package/dist/components/ui/accordion.js +1 -1
  105. package/dist/components/ui/accordion.js.map +1 -1
  106. package/dist/components/ui/badge.cjs +1 -1
  107. package/dist/components/ui/badge.cjs.map +1 -1
  108. package/dist/components/ui/badge.js +8 -8
  109. package/dist/components/ui/badge.js.map +1 -1
  110. package/dist/components/ui/button.cjs +1 -1
  111. package/dist/components/ui/button.cjs.map +1 -1
  112. package/dist/components/ui/button.js +11 -11
  113. package/dist/components/ui/button.js.map +1 -1
  114. package/dist/components/ui/checkbox.cjs +1 -1
  115. package/dist/components/ui/checkbox.cjs.map +1 -1
  116. package/dist/components/ui/checkbox.js +1 -1
  117. package/dist/components/ui/checkbox.js.map +1 -1
  118. package/dist/components/ui/combobox.cjs +1 -1
  119. package/dist/components/ui/combobox.cjs.map +1 -1
  120. package/dist/components/ui/combobox.js +12 -12
  121. package/dist/components/ui/combobox.js.map +1 -1
  122. package/dist/components/ui/input-group.cjs +1 -1
  123. package/dist/components/ui/input-group.cjs.map +1 -1
  124. package/dist/components/ui/input-group.js +19 -19
  125. package/dist/components/ui/input-group.js.map +1 -1
  126. package/dist/components/ui/item.cjs +1 -1
  127. package/dist/components/ui/item.cjs.map +1 -1
  128. package/dist/components/ui/item.js +1 -1
  129. package/dist/components/ui/item.js.map +1 -1
  130. package/dist/components/ui/menubar.cjs +1 -1
  131. package/dist/components/ui/menubar.cjs.map +1 -1
  132. package/dist/components/ui/menubar.js +1 -1
  133. package/dist/components/ui/menubar.js.map +1 -1
  134. package/dist/components/ui/navigation-menu.cjs +1 -1
  135. package/dist/components/ui/navigation-menu.cjs.map +1 -1
  136. package/dist/components/ui/navigation-menu.js +54 -54
  137. package/dist/components/ui/navigation-menu.js.map +1 -1
  138. package/dist/components/ui/radio-group.cjs +1 -1
  139. package/dist/components/ui/radio-group.cjs.map +1 -1
  140. package/dist/components/ui/radio-group.js +1 -1
  141. package/dist/components/ui/radio-group.js.map +1 -1
  142. package/dist/components/ui/resizable.cjs +1 -1
  143. package/dist/components/ui/resizable.cjs.map +1 -1
  144. package/dist/components/ui/resizable.js +27 -15
  145. package/dist/components/ui/resizable.js.map +1 -1
  146. package/dist/components/ui/select.cjs +1 -1
  147. package/dist/components/ui/select.cjs.map +1 -1
  148. package/dist/components/ui/select.js +1 -1
  149. package/dist/components/ui/select.js.map +1 -1
  150. package/dist/components/ui/slider.cjs +1 -1
  151. package/dist/components/ui/slider.cjs.map +1 -1
  152. package/dist/components/ui/slider.js +9 -9
  153. package/dist/components/ui/slider.js.map +1 -1
  154. package/dist/components/ui/table.cjs +1 -1
  155. package/dist/components/ui/table.cjs.map +1 -1
  156. package/dist/components/ui/table.js +13 -13
  157. package/dist/components/ui/table.js.map +1 -1
  158. package/dist/components/ui/tabs.cjs +1 -1
  159. package/dist/components/ui/tabs.cjs.map +1 -1
  160. package/dist/components/ui/tabs.js +7 -7
  161. package/dist/components/ui/tabs.js.map +1 -1
  162. package/dist/components/ui/toggle.cjs +1 -1
  163. package/dist/components/ui/toggle.cjs.map +1 -1
  164. package/dist/components/ui/toggle.js +12 -12
  165. package/dist/components/ui/toggle.js.map +1 -1
  166. package/dist/hooks/use-element-size.cjs +2 -0
  167. package/dist/hooks/use-element-size.cjs.map +1 -0
  168. package/dist/hooks/use-element-size.js +21 -0
  169. package/dist/hooks/use-element-size.js.map +1 -0
  170. package/dist/hooks/use-plotly-theme.cjs +1 -1
  171. package/dist/hooks/use-plotly-theme.cjs.map +1 -1
  172. package/dist/hooks/use-plotly-theme.js +4 -2
  173. package/dist/hooks/use-plotly-theme.js.map +1 -1
  174. package/dist/index.cjs +1 -1
  175. package/dist/index.css +1 -1
  176. package/dist/index.d.ts +254 -77
  177. package/dist/index.js +587 -581
  178. package/dist/index.js.map +1 -1
  179. package/dist/index.tailwind.css +1 -1
  180. package/dist/utils/colors.cjs +1 -1
  181. package/dist/utils/colors.cjs.map +1 -1
  182. package/dist/utils/colors.js +38 -93
  183. package/dist/utils/colors.js.map +1 -1
  184. package/package.json +18 -12
@@ -0,0 +1,163 @@
1
+ import { jsx as h, jsxs as O } from "react/jsx-runtime";
2
+ import X from "plotly.js-dist";
3
+ import { useRef as d, useState as N, useCallback as R, useLayoutEffect as H } from "react";
4
+ import { createPortal as W } from "react-dom";
5
+ import { chartTooltipLines as z } from "./lines.js";
6
+ import { cn as L } from "../../../lib/utils.js";
7
+ const G = 20, Y = 150, j = 200, y = 8, k = 10, C = {
8
+ top: "bottom",
9
+ bottom: "top",
10
+ left: "right",
11
+ right: "left"
12
+ }, B = {
13
+ top: {
14
+ wrapper: "-translate-x-1/2 -translate-y-[calc(100%+10px)]",
15
+ arrow: "-bottom-1 left-1/2 -translate-x-1/2"
16
+ },
17
+ bottom: {
18
+ wrapper: "-translate-x-1/2 translate-y-[10px]",
19
+ arrow: "-top-1 left-1/2 -translate-x-1/2"
20
+ },
21
+ left: {
22
+ wrapper: "-translate-y-1/2 -translate-x-[calc(100%+10px)]",
23
+ arrow: "-right-1 top-1/2 -translate-y-1/2"
24
+ },
25
+ right: {
26
+ wrapper: "-translate-y-1/2 translate-x-[10px]",
27
+ arrow: "-left-1 top-1/2 -translate-y-1/2"
28
+ }
29
+ }, V = (t, o, n, r) => {
30
+ const e = y, s = k, i = {
31
+ top: o.top - s - r >= e,
32
+ bottom: o.top + s + r <= window.innerHeight - e,
33
+ left: o.left - s - n >= e,
34
+ right: o.left + s + n <= window.innerWidth - e
35
+ };
36
+ return !i[t] && i[C[t]] ? C[t] : t;
37
+ };
38
+ function $({ anchor: t, bubbleRef: o }) {
39
+ const n = d(null), r = t?.side ?? "top", [e, s] = N(r), i = R(
40
+ (l) => {
41
+ n.current = l, typeof o == "function" ? o(l) : o && (o.current = l);
42
+ },
43
+ [o]
44
+ );
45
+ if (H(() => {
46
+ const l = n.current;
47
+ if (!t || !l) return;
48
+ const c = V(
49
+ r,
50
+ t,
51
+ l.offsetWidth,
52
+ l.offsetHeight
53
+ );
54
+ s((m) => m === c ? m : c);
55
+ }, [t, r]), !t) return null;
56
+ const p = B[e];
57
+ return W(
58
+ /* @__PURE__ */ h(
59
+ "div",
60
+ {
61
+ "data-slot": "chart-tooltip-anchor",
62
+ className: "pointer-events-none fixed z-50",
63
+ style: { left: t.left, top: t.top },
64
+ children: /* @__PURE__ */ h("div", { ref: i, className: L("w-max", p.wrapper), children: /* @__PURE__ */ O(
65
+ "div",
66
+ {
67
+ role: "tooltip",
68
+ "data-slot": "tooltip-content",
69
+ "data-side": e,
70
+ className: L(
71
+ "relative w-fit max-w-xs rounded-md bg-foreground px-3 py-1.5 text-xs text-background",
72
+ t.closing ? "animate-out fade-out zoom-out-95 fill-mode-forwards" : "animate-in fade-in-0 zoom-in-95"
73
+ ),
74
+ children: [
75
+ t.lines.map((l, c) => /* @__PURE__ */ h("div", { children: l }, `${c}-${l}`)),
76
+ /* @__PURE__ */ h(
77
+ "span",
78
+ {
79
+ "aria-hidden": !0,
80
+ className: L(
81
+ "absolute size-2.5 rotate-45 rounded-[2px] bg-foreground",
82
+ p.arrow
83
+ )
84
+ }
85
+ )
86
+ ]
87
+ }
88
+ ) })
89
+ }
90
+ ),
91
+ document.body
92
+ );
93
+ }
94
+ const D = (t, o, n, r) => {
95
+ const e = n / 2, s = Math.min(
96
+ Math.max(t, e + y),
97
+ window.innerWidth - e - y
98
+ ), i = Math.min(
99
+ Math.max(o, r + 10 + y),
100
+ window.innerHeight - y
101
+ );
102
+ return { left: s, top: i };
103
+ };
104
+ function Z(t = {}) {
105
+ const [o, n] = N(null), r = d(void 0), e = d(t);
106
+ e.current = t;
107
+ const s = d(null), i = d(null), p = d(null);
108
+ return {
109
+ bindTooltip: R((c) => {
110
+ if (!c) return;
111
+ p.current?.(), p.current = null, n(null), i.current = null, X.relayout(c, {
112
+ hoverdistance: e.current.hoverDistance ?? G
113
+ });
114
+ const m = c, P = (a, u, w) => {
115
+ const g = s.current, { left: E, top: S } = D(
116
+ u,
117
+ w,
118
+ g?.offsetWidth ?? 0,
119
+ g?.offsetHeight ?? 0
120
+ );
121
+ n({ left: E, top: S, lines: a, side: e.current.side });
122
+ };
123
+ m.on("plotly_hover", (a) => {
124
+ const u = a.points ?? [], { getLines: w, xLabel: g, yLabel: E, followCursor: S } = e.current, T = w ? w(u) : z(u, { xLabel: g, yLabel: E });
125
+ if (T.length === 0) return;
126
+ clearTimeout(r.current);
127
+ const x = a.event;
128
+ if (S) {
129
+ i.current = T, P(T, x?.clientX ?? 0, x?.clientY ?? 0);
130
+ return;
131
+ }
132
+ const b = u[0], f = b?.bbox;
133
+ let M = 0, _ = 0;
134
+ if (f) {
135
+ const I = c.getBoundingClientRect();
136
+ M = I.left + (f.x0 + f.x1) / 2;
137
+ const v = b?.yaxis;
138
+ f.y0 === f.y1 && typeof b?.y == "number" && typeof v?.l2p == "function" && typeof v._offset == "number" ? _ = I.top + v._offset + v.l2p(b.y) : _ = I.top + Math.min(f.y0, f.y1);
139
+ } else x && (M = x.clientX, _ = x.clientY);
140
+ n({ left: M, top: _, lines: T, side: e.current.side });
141
+ });
142
+ const A = (a) => {
143
+ if (!e.current.followCursor) return;
144
+ const u = i.current;
145
+ u && P(u, a.clientX, a.clientY);
146
+ };
147
+ c.addEventListener("mousemove", A), p.current = () => c.removeEventListener("mousemove", A), m.on("plotly_unhover", () => {
148
+ clearTimeout(r.current), i.current = null, r.current = setTimeout(() => {
149
+ n(
150
+ (a) => a && { ...a, closing: !0 }
151
+ ), r.current = setTimeout(() => n(null), j);
152
+ }, Y);
153
+ });
154
+ }, []),
155
+ tooltipElement: /* @__PURE__ */ h($, { anchor: o, bubbleRef: s })
156
+ };
157
+ }
158
+ export {
159
+ $ as ChartTooltip,
160
+ z as chartTooltipLines,
161
+ Z as useChartTooltip
162
+ };
163
+ //# sourceMappingURL=ChartTooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartTooltip.js","sources":["../../../../src/components/charts/ChartTooltip/ChartTooltip.tsx"],"sourcesContent":["import Plotly from \"plotly.js-dist\";\nimport { useCallback, useLayoutEffect, useRef, useState } from \"react\";\nimport { createPortal } from \"react-dom\";\n\nimport { chartTooltipLines } from \"./lines\";\n\nimport type { ChartTooltipHoverPoint } from \"./lines\";\nimport type { Ref } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\nexport { chartTooltipLines } from \"./lines\";\nexport type { ChartTooltipHoverPoint } from \"./lines\";\n\n/**\n * How far (px) from a point Plotly still reports a hover. Matches Plotly's\n * default — a larger radius makes tooltips snap to neighbors in dense plots\n */\nconst HOVER_DISTANCE_PX = 20;\n/** Grace period before hiding, so the tooltip survives gaps between points */\nconst HIDE_GRACE_MS = 150;\n/** How long the exit animation plays before the tooltip unmounts */\nconst EXIT_ANIMATION_MS = 200;\n\n/** Which edge of the point the tooltip is placed against (matches Radix). */\nexport type ChartTooltipSide = \"top\" | \"bottom\" | \"left\" | \"right\";\n\nexport interface ChartTooltipAnchor {\n left: number;\n top: number;\n lines: string[];\n /** Preferred placement side; auto-flips to the opposite when it won't fit */\n side?: ChartTooltipSide;\n /** Plays the exit animation before the tooltip unmounts */\n closing?: boolean;\n}\n\n/** Keep an anchor point this far from the viewport edges when clamping */\nconst VIEWPORT_PADDING_PX = 8;\n/** Gap (px) between the anchor point and the bubble on every side */\nconst TOOLTIP_GAP_PX = 10;\n\n/** The opposite side to flip to when the preferred one has no room */\nconst OPPOSITE_SIDE: Record<ChartTooltipSide, ChartTooltipSide> = {\n top: \"bottom\",\n bottom: \"top\",\n left: \"right\",\n right: \"left\",\n};\n\n/**\n * Per-side transforms. The wrapper carries positioning transforms (kept off\n * the bubble so they don't clobber the entry/exit animation), and the arrow\n * sits on the edge facing the point.\n */\nconst SIDE_CLASSES: Record<ChartTooltipSide, { wrapper: string; arrow: string }> = {\n top: {\n wrapper: \"-translate-x-1/2 -translate-y-[calc(100%+10px)]\",\n arrow: \"-bottom-1 left-1/2 -translate-x-1/2\",\n },\n bottom: {\n wrapper: \"-translate-x-1/2 translate-y-[10px]\",\n arrow: \"-top-1 left-1/2 -translate-x-1/2\",\n },\n left: {\n wrapper: \"-translate-y-1/2 -translate-x-[calc(100%+10px)]\",\n arrow: \"-right-1 top-1/2 -translate-y-1/2\",\n },\n right: {\n wrapper: \"-translate-y-1/2 translate-x-[10px]\",\n arrow: \"-left-1 top-1/2 -translate-y-1/2\",\n },\n};\n\ninterface ChartTooltipEmitter {\n on: (event: string, handler: (data: ChartTooltipHoverEvent) => void) => void;\n}\n\ninterface ChartTooltipHoverEvent {\n points?: ChartTooltipHoverPoint[];\n event?: MouseEvent;\n}\n\nexport interface ChartTooltipProps {\n /** Anchor position (viewport coordinates) and content lines */\n anchor: ChartTooltipAnchor | null;\n /** Ref to the bubble node, used by cursor-following charts to clamp it on-screen */\n bubbleRef?: Ref<HTMLDivElement>;\n}\n\n/**\n * Resolve the side the bubble actually renders on: keep the preferred side\n * when it fits in the viewport, otherwise flip to the opposite side.\n */\nconst resolveSide = (\n preferred: ChartTooltipSide,\n anchor: { left: number; top: number },\n width: number,\n height: number,\n): ChartTooltipSide => {\n const pad = VIEWPORT_PADDING_PX;\n const reach = TOOLTIP_GAP_PX;\n const fits: Record<ChartTooltipSide, boolean> = {\n top: anchor.top - reach - height >= pad,\n bottom: anchor.top + reach + height <= window.innerHeight - pad,\n left: anchor.left - reach - width >= pad,\n right: anchor.left + reach + width <= window.innerWidth - pad,\n };\n // Flip only when the preferred side overflows and the opposite has room\n if (!fits[preferred] && fits[OPPOSITE_SIDE[preferred]]) {\n return OPPOSITE_SIDE[preferred];\n }\n return preferred;\n};\n\n/**\n * The design-system tooltip anchored at a chart position; drive it with\n * `useChartTooltip`.\n *\n * Renders the same visual as the ui `TooltipContent` (bubble + arrow) but\n * positions it directly from the anchor coordinates — Radix's popper\n * repositions asynchronously and mis-measures animated content, which made\n * tooltips drift on charts. Placement supports all four sides with\n * Radix-style collision flipping.\n */\nexport function ChartTooltip({ anchor, bubbleRef }: ChartTooltipProps) {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const preferredSide = anchor?.side ?? \"top\";\n const [resolvedSide, setResolvedSide] = useState<ChartTooltipSide>(preferredSide);\n\n // Forward the wrapper node to both the internal measure ref and the\n // optional external ref (used by cursor-following charts to clamp it)\n const setBubbleNode = useCallback(\n (node: HTMLDivElement | null) => {\n wrapperRef.current = node;\n if (typeof bubbleRef === \"function\") bubbleRef(node);\n else if (bubbleRef) {\n (bubbleRef as { current: HTMLDivElement | null }).current = node;\n }\n },\n [bubbleRef],\n );\n\n // Measure before paint and flip to the opposite side if needed\n useLayoutEffect(() => {\n const node = wrapperRef.current;\n if (!anchor || !node) return;\n const next = resolveSide(\n preferredSide,\n anchor,\n node.offsetWidth,\n node.offsetHeight,\n );\n setResolvedSide((current) => (current === next ? current : next));\n }, [anchor, preferredSide]);\n\n if (!anchor) return null;\n const side = SIDE_CLASSES[resolvedSide];\n return createPortal(\n <div\n data-slot=\"chart-tooltip-anchor\"\n className=\"pointer-events-none fixed z-50\"\n style={{ left: anchor.left, top: anchor.top }}\n >\n {/* Positioning transforms live on this node; animations (which also\n drive `transform`) live on the bubble below so they can't clobber\n each other */}\n <div ref={setBubbleNode} className={cn(\"w-max\", side.wrapper)}>\n <div\n role=\"tooltip\"\n data-slot=\"tooltip-content\"\n data-side={resolvedSide}\n className={cn(\n \"relative w-fit max-w-xs rounded-md bg-foreground px-3 py-1.5 text-xs text-background\",\n anchor.closing\n ? \"animate-out fade-out zoom-out-95 fill-mode-forwards\"\n : \"animate-in fade-in-0 zoom-in-95\",\n )}\n >\n {anchor.lines.map((line, index) => (\n <div key={`${index}-${line}`}>{line}</div>\n ))}\n <span\n aria-hidden\n className={cn(\n \"absolute size-2.5 rotate-45 rounded-[2px] bg-foreground\",\n side.arrow,\n )}\n />\n </div>\n </div>\n </div>,\n document.body,\n );\n}\n\nexport interface UseChartTooltipOptions {\n /** Axis label used for the default x line (falls back to \"X\") */\n xLabel?: string;\n /** Axis label used for the default y line (falls back to \"Y\") */\n yLabel?: string;\n /** Override the default line builder entirely */\n getLines?: (points: ChartTooltipHoverPoint[]) => string[];\n /**\n * Track the cursor instead of anchoring to the hovered point's bounds, and\n * keep the tooltip clamped inside the viewport. Use for traces with large\n * hover targets (e.g. pie slices) where a fixed anchor feels disconnected.\n */\n followCursor?: boolean;\n /**\n * Override Plotly's hover hit radius (px). A larger radius makes big markers\n * (e.g. heatmap circles) hoverable across their whole face.\n */\n hoverDistance?: number;\n /**\n * Preferred side to place the tooltip on relative to the point. Auto-flips to\n * the opposite side when there isn't room (Radix-style). Defaults to \"top\".\n */\n side?: ChartTooltipSide;\n}\n\n/** Clamp an anchor point so a bubble of `width`×`height` stays on-screen */\nconst clampAnchor = (\n left: number,\n top: number,\n width: number,\n height: number,\n): { left: number; top: number } => {\n const halfWidth = width / 2;\n const clampedLeft = Math.min(\n Math.max(left, halfWidth + VIEWPORT_PADDING_PX),\n window.innerWidth - halfWidth - VIEWPORT_PADDING_PX,\n );\n // The bubble sits above the anchor; keep its top edge inside the viewport\n const clampedTop = Math.min(\n Math.max(top, height + 10 + VIEWPORT_PADDING_PX),\n window.innerHeight - VIEWPORT_PADDING_PX,\n );\n return { left: clampedLeft, top: clampedTop };\n};\n\n/**\n * Drives the design-system tooltip from Plotly hover events.\n *\n * ```tsx\n * const { bindTooltip, tooltipElement } = useChartTooltip({ xLabel, yLabel });\n * // after Plotly.newPlot(...): set trace hoverinfo to \"none\", then\n * bindTooltip(plotRef.current);\n * // anywhere in the chart markup:\n * {tooltipElement}\n * ```\n */\nexport function useChartTooltip(options: UseChartTooltipOptions = {}) {\n const [anchor, setAnchor] = useState<ChartTooltipAnchor | null>(null);\n const hideTimerRef = useRef<ReturnType<typeof setTimeout>>(undefined);\n const optionsRef = useRef(options);\n optionsRef.current = options;\n // Measured bubble node, used to clamp the cursor-following tooltip on-screen\n const bubbleRef = useRef<HTMLDivElement>(null);\n // Active lines while a cursor-following tooltip is shown; null when hidden\n const cursorLinesRef = useRef<string[] | null>(null);\n // Removes the mousemove listener registered by the previous bindTooltip call\n const detachMouseMoveRef = useRef<(() => void) | null>(null);\n\n const bindTooltip = useCallback((plotDiv: HTMLElement | null) => {\n if (!plotDiv) return;\n // The chart effect can re-run (size/theme/props changes) and call this\n // again on the same node; drop the prior mousemove listener so they don't\n // accumulate. (Plotly's own hover/unhover handlers are cleared by newPlot.)\n detachMouseMoveRef.current?.();\n detachMouseMoveRef.current = null;\n setAnchor(null);\n cursorLinesRef.current = null;\n\n // A larger hover radius makes the tooltip easier to acquire and keep\n void Plotly.relayout(plotDiv, {\n hoverdistance: optionsRef.current.hoverDistance ?? HOVER_DISTANCE_PX,\n });\n\n const emitter = plotDiv as unknown as ChartTooltipEmitter;\n\n // Place the cursor-following tooltip at the (clamped) cursor position\n const positionAtCursor = (lines: string[], clientX: number, clientY: number) => {\n const bubble = bubbleRef.current;\n const { left, top } = clampAnchor(\n clientX,\n clientY,\n bubble?.offsetWidth ?? 0,\n bubble?.offsetHeight ?? 0,\n );\n setAnchor({ left, top, lines, side: optionsRef.current.side });\n };\n\n emitter.on(\"plotly_hover\", (eventData) => {\n const points = eventData.points ?? [];\n const { getLines, xLabel, yLabel, followCursor } = optionsRef.current;\n const lines = getLines\n ? getLines(points)\n : chartTooltipLines(points, { xLabel, yLabel });\n if (lines.length === 0) return;\n\n clearTimeout(hideTimerRef.current);\n\n const mouse = eventData.event;\n if (followCursor) {\n cursorLinesRef.current = lines;\n positionAtCursor(lines, mouse?.clientX ?? 0, mouse?.clientY ?? 0);\n return;\n }\n\n // Anchor to the hovered point's bounds (in plot-div pixels) when\n // Plotly provides them; fall back to the mouse position. The anchor\n // is position:fixed, so viewport coordinates are used directly.\n const point = points[0];\n const bbox = point?.bbox;\n let left = 0;\n let top = 0;\n if (bbox) {\n const rect = plotDiv.getBoundingClientRect();\n left = rect.left + (bbox.x0 + bbox.x1) / 2;\n // Bars report a zero-height bbox that sits below their visual top;\n // anchor to the bar's true top via the axis projection instead.\n const yaxis = point?.yaxis;\n if (\n bbox.y0 === bbox.y1 &&\n typeof point?.y === \"number\" &&\n typeof yaxis?.l2p === \"function\" &&\n typeof yaxis._offset === \"number\"\n ) {\n top = rect.top + yaxis._offset + yaxis.l2p(point.y);\n } else {\n top = rect.top + Math.min(bbox.y0, bbox.y1);\n }\n } else if (mouse) {\n left = mouse.clientX;\n top = mouse.clientY;\n }\n setAnchor({ left, top, lines, side: optionsRef.current.side });\n });\n\n // While following the cursor, keep the tooltip glued to the pointer even\n // when Plotly does not re-fire hover within the same point (e.g. a slice)\n const handleMouseMove = (event: MouseEvent) => {\n if (!optionsRef.current.followCursor) return;\n const lines = cursorLinesRef.current;\n if (!lines) return;\n positionAtCursor(lines, event.clientX, event.clientY);\n };\n plotDiv.addEventListener(\"mousemove\", handleMouseMove);\n detachMouseMoveRef.current = () =>\n plotDiv.removeEventListener(\"mousemove\", handleMouseMove);\n\n emitter.on(\"plotly_unhover\", () => {\n clearTimeout(hideTimerRef.current);\n cursorLinesRef.current = null;\n // After the grace period, play the exit animation, then unmount\n hideTimerRef.current = setTimeout(() => {\n setAnchor((previous) =>\n previous ? { ...previous, closing: true } : previous,\n );\n hideTimerRef.current = setTimeout(() => setAnchor(null), EXIT_ANIMATION_MS);\n }, HIDE_GRACE_MS);\n });\n }, []);\n\n return {\n bindTooltip,\n tooltipElement: <ChartTooltip anchor={anchor} bubbleRef={bubbleRef} />,\n };\n}\n"],"names":["HOVER_DISTANCE_PX","HIDE_GRACE_MS","EXIT_ANIMATION_MS","VIEWPORT_PADDING_PX","TOOLTIP_GAP_PX","OPPOSITE_SIDE","SIDE_CLASSES","resolveSide","preferred","anchor","width","height","pad","reach","fits","ChartTooltip","bubbleRef","wrapperRef","useRef","preferredSide","resolvedSide","setResolvedSide","useState","setBubbleNode","useCallback","node","useLayoutEffect","next","current","side","createPortal","jsx","cn","jsxs","line","index","clampAnchor","left","top","halfWidth","clampedLeft","clampedTop","useChartTooltip","options","setAnchor","hideTimerRef","optionsRef","cursorLinesRef","detachMouseMoveRef","plotDiv","Plotly","emitter","positionAtCursor","lines","clientX","clientY","bubble","eventData","points","getLines","xLabel","yLabel","followCursor","chartTooltipLines","mouse","point","bbox","rect","yaxis","handleMouseMove","event","previous"],"mappings":";;;;;;AAkBA,MAAMA,IAAoB,IAEpBC,IAAgB,KAEhBC,IAAoB,KAgBpBC,IAAsB,GAEtBC,IAAiB,IAGjBC,IAA4D;AAAA,EAChE,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AACT,GAOMC,IAA6E;AAAA,EACjF,KAAK;AAAA,IACH,SAAS;AAAA,IACT,OAAO;AAAA,EAAA;AAAA,EAET,QAAQ;AAAA,IACN,SAAS;AAAA,IACT,OAAO;AAAA,EAAA;AAAA,EAET,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,OAAO;AAAA,EAAA;AAAA,EAET,OAAO;AAAA,IACL,SAAS;AAAA,IACT,OAAO;AAAA,EAAA;AAEX,GAsBMC,IAAc,CAClBC,GACAC,GACAC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AgB,WAAAO,EAAA,CAAsB;AAAA,EAAA;AAExE;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=e=>typeof e!="number"||Number.isInteger(e)?String(e):e.toFixed(2),u=e=>{const n=[String(e.label),`Value: ${i(e.value??e.v)}`];return typeof e.percent=="number"?n.push(`${e.percent.toFixed(1)}%`):typeof e.text=="string"&&e.text.endsWith("%")&&n.push(e.text),n},o=(e,n)=>{const[t]=e,r=t.x===void 0?[]:[`${n}: ${i(t.x)}`];for(const s of e)s.y!==void 0&&r.push(`${s.data?.name??"Series"}: ${i(s.y)}`);return r},f=(e,n,t)=>{const r=[];return e.data?.name&&r.push(e.data.name),e.x!==void 0&&r.push(`${n}: ${i(e.x)}`),e.y!==void 0&&r.push(`${t}: ${i(e.y)}`),e.z!==void 0&&r.push(`Value: ${i(e.z)}`),r};function a(e,n){if(e.length===0)return[];const[t]=e;if(t.label!==void 0&&(t.value??t.v)!==void 0&&t.x===void 0&&t.y===void 0)return u(t);if(typeof t.text=="string"&&t.text.length>0)return t.text.split("<br>").filter(Boolean);const r=n?.xLabel||"X",s=n?.yLabel||"Y";return e.length>1?o(e,r):f(t,r,s)}exports.chartTooltipLines=a;
2
+ //# sourceMappingURL=lines.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.cjs","sources":["../../../../src/components/charts/ChartTooltip/lines.ts"],"sourcesContent":["/**\n * Minimal structural view of a Plotly hover point — covers cartesian, pie,\n * and heatmap traces without depending on Plotly's loose event typings.\n */\nexport interface ChartTooltipHoverPoint {\n x?: number | string;\n y?: number | string;\n z?: number;\n /** Pie slice label */\n label?: string;\n /** Pie slice value */\n value?: number;\n /** Pie slice raw value (Plotly's `v` alias) */\n v?: number;\n /** Pie slice percentage (0–100) */\n percent?: number;\n /** Per-point hover text (e.g. PlateMap wells), lines separated by `<br>` */\n text?: string;\n pointIndex?: number;\n data?: { name?: string };\n /** Per-point custom data attached to the trace */\n customdata?: unknown;\n /** Hovered point bounds in plot-div pixels (provided by Plotly) */\n bbox?: { x0: number; x1: number; y0: number; y1: number };\n /**\n * Plotly axis objects (internal) used to project a data value to a plot-div\n * pixel. Bars report a `bbox` that sits below their visual top, so we anchor\n * to `_offset + l2p(value)` instead.\n */\n yaxis?: { _offset?: number; l2p?: (value: number) => number };\n xaxis?: { _offset?: number; l2p?: (value: number) => number };\n}\n\nconst formatValue = (value: number | string): string => {\n if (typeof value !== \"number\") return String(value);\n return Number.isInteger(value) ? String(value) : value.toFixed(2);\n};\n\nconst pieLines = (point: ChartTooltipHoverPoint): string[] => {\n const lines = [\n String(point.label),\n `Value: ${formatValue((point.value ?? point.v)!)}`,\n ];\n if (typeof point.percent === \"number\") {\n lines.push(`${point.percent.toFixed(1)}%`);\n } else if (typeof point.text === \"string\" && point.text.endsWith(\"%\")) {\n lines.push(point.text);\n }\n return lines;\n};\n\n/** Unified hover across multiple traces: shared x, one line per trace */\nconst unifiedLines = (\n points: ChartTooltipHoverPoint[],\n xLabel: string,\n): string[] => {\n const [first] = points;\n const lines =\n first.x === undefined ? [] : [`${xLabel}: ${formatValue(first.x)}`];\n for (const point of points) {\n if (point.y === undefined) continue;\n lines.push(`${point.data?.name ?? \"Series\"}: ${formatValue(point.y)}`);\n }\n return lines;\n};\n\nconst cartesianLines = (\n point: ChartTooltipHoverPoint,\n xLabel: string,\n yLabel: string,\n): string[] => {\n const lines: string[] = [];\n if (point.data?.name) lines.push(point.data.name);\n if (point.x !== undefined) lines.push(`${xLabel}: ${formatValue(point.x)}`);\n if (point.y !== undefined) lines.push(`${yLabel}: ${formatValue(point.y)}`);\n if (point.z !== undefined) lines.push(`Value: ${formatValue(point.z)}`);\n return lines;\n};\n\n/**\n * Build default tooltip lines from Plotly hover points. Handles pie slices,\n * text-carrying traces (e.g. PlateMap wells), single cartesian points, and\n * unified multi-trace hovers.\n */\nexport function chartTooltipLines(\n points: ChartTooltipHoverPoint[],\n labels?: { xLabel?: string; yLabel?: string },\n): string[] {\n if (points.length === 0) return [];\n const [first] = points;\n\n // Pie hover points carry label/value without axis coordinates; bar points\n // also alias label/value but always have x/y\n if (\n first.label !== undefined &&\n (first.value ?? first.v) !== undefined &&\n first.x === undefined &&\n first.y === undefined\n ) {\n return pieLines(first);\n }\n\n // Traces that carry their own hover text (e.g. PlateMap wells)\n if (typeof first.text === \"string\" && first.text.length > 0) {\n return first.text.split(\"<br>\").filter(Boolean);\n }\n\n const xLabel = labels?.xLabel || \"X\";\n const yLabel = labels?.yLabel || \"Y\";\n return points.length > 1\n ? unifiedLines(points, xLabel)\n : cartesianLines(first, xLabel, yLabel);\n}\n"],"names":["formatValue","value","pieLines","point","lines","unifiedLines","points","xLabel","first","cartesianLines","yLabel","chartTooltipLines","labels"],"mappings":"gFAiCA,MAAMA,EAAeC,GACf,OAAOA,GAAU,UACd,OAAO,UAAUA,CAAK,EADS,OAAOA,CAAK,EACDA,EAAM,QAAQ,CAAC,EAG5DC,EAAYC,GAA4C,CAC5D,MAAMC,EAAQ,CACZ,OAAOD,EAAM,KAAK,EAClB,UAAUH,EAAaG,EAAM,OAASA,EAAM,CAAG,CAAC,EAAA,EAElD,OAAI,OAAOA,EAAM,SAAY,SAC3BC,EAAM,KAAK,GAAGD,EAAM,QAAQ,QAAQ,CAAC,CAAC,GAAG,EAChC,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,SAAS,GAAG,GAClEC,EAAM,KAAKD,EAAM,IAAI,EAEhBC,CACT,EAGMC,EAAe,CACnBC,EACAC,IACa,CACb,KAAM,CAACC,CAAK,EAAIF,EACVF,EACJI,EAAM,IAAM,OAAY,CAAA,EAAK,CAAC,GAAGD,CAAM,KAAKP,EAAYQ,EAAM,CAAC,CAAC,EAAE,EACpE,UAAWL,KAASG,EACdH,EAAM,IAAM,QAChBC,EAAM,KAAK,GAAGD,EAAM,MAAM,MAAQ,QAAQ,KAAKH,EAAYG,EAAM,CAAC,CAAC,EAAE,EAEvE,OAAOC,CACT,EAEMK,EAAiB,CACrBN,EACAI,EACAG,IACa,CACb,MAAMN,EAAkB,CAAA,EACxB,OAAID,EAAM,MAAM,QAAY,KAAKA,EAAM,KAAK,IAAI,EAC5CA,EAAM,IAAM,QAAWC,EAAM,KAAK,GAAGG,CAAM,KAAKP,EAAYG,EAAM,CAAC,CAAC,EAAE,EACtEA,EAAM,IAAM,QAAWC,EAAM,KAAK,GAAGM,CAAM,KAAKV,EAAYG,EAAM,CAAC,CAAC,EAAE,EACtEA,EAAM,IAAM,QAAWC,EAAM,KAAK,UAAUJ,EAAYG,EAAM,CAAC,CAAC,EAAE,EAC/DC,CACT,EAOO,SAASO,EACdL,EACAM,EACU,CACV,GAAIN,EAAO,SAAW,EAAG,MAAO,CAAA,EAChC,KAAM,CAACE,CAAK,EAAIF,EAIhB,GACEE,EAAM,QAAU,SACfA,EAAM,OAASA,EAAM,KAAO,QAC7BA,EAAM,IAAM,QACZA,EAAM,IAAM,OAEZ,OAAON,EAASM,CAAK,EAIvB,GAAI,OAAOA,EAAM,MAAS,UAAYA,EAAM,KAAK,OAAS,EACxD,OAAOA,EAAM,KAAK,MAAM,MAAM,EAAE,OAAO,OAAO,EAGhD,MAAMD,EAASK,GAAQ,QAAU,IAC3BF,EAASE,GAAQ,QAAU,IACjC,OAAON,EAAO,OAAS,EACnBD,EAAaC,EAAQC,CAAM,EAC3BE,EAAeD,EAAOD,EAAQG,CAAM,CAC1C"}
@@ -0,0 +1,29 @@
1
+ const i = (e) => typeof e != "number" || Number.isInteger(e) ? String(e) : e.toFixed(2), f = (e) => {
2
+ const n = [
3
+ String(e.label),
4
+ `Value: ${i(e.value ?? e.v)}`
5
+ ];
6
+ return typeof e.percent == "number" ? n.push(`${e.percent.toFixed(1)}%`) : typeof e.text == "string" && e.text.endsWith("%") && n.push(e.text), n;
7
+ }, u = (e, n) => {
8
+ const [t] = e, r = t.x === void 0 ? [] : [`${n}: ${i(t.x)}`];
9
+ for (const s of e)
10
+ s.y !== void 0 && r.push(`${s.data?.name ?? "Series"}: ${i(s.y)}`);
11
+ return r;
12
+ }, a = (e, n, t) => {
13
+ const r = [];
14
+ return e.data?.name && r.push(e.data.name), e.x !== void 0 && r.push(`${n}: ${i(e.x)}`), e.y !== void 0 && r.push(`${t}: ${i(e.y)}`), e.z !== void 0 && r.push(`Value: ${i(e.z)}`), r;
15
+ };
16
+ function o(e, n) {
17
+ if (e.length === 0) return [];
18
+ const [t] = e;
19
+ if (t.label !== void 0 && (t.value ?? t.v) !== void 0 && t.x === void 0 && t.y === void 0)
20
+ return f(t);
21
+ if (typeof t.text == "string" && t.text.length > 0)
22
+ return t.text.split("<br>").filter(Boolean);
23
+ const r = n?.xLabel || "X", s = n?.yLabel || "Y";
24
+ return e.length > 1 ? u(e, r) : a(t, r, s);
25
+ }
26
+ export {
27
+ o as chartTooltipLines
28
+ };
29
+ //# sourceMappingURL=lines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines.js","sources":["../../../../src/components/charts/ChartTooltip/lines.ts"],"sourcesContent":["/**\n * Minimal structural view of a Plotly hover point — covers cartesian, pie,\n * and heatmap traces without depending on Plotly's loose event typings.\n */\nexport interface ChartTooltipHoverPoint {\n x?: number | string;\n y?: number | string;\n z?: number;\n /** Pie slice label */\n label?: string;\n /** Pie slice value */\n value?: number;\n /** Pie slice raw value (Plotly's `v` alias) */\n v?: number;\n /** Pie slice percentage (0–100) */\n percent?: number;\n /** Per-point hover text (e.g. PlateMap wells), lines separated by `<br>` */\n text?: string;\n pointIndex?: number;\n data?: { name?: string };\n /** Per-point custom data attached to the trace */\n customdata?: unknown;\n /** Hovered point bounds in plot-div pixels (provided by Plotly) */\n bbox?: { x0: number; x1: number; y0: number; y1: number };\n /**\n * Plotly axis objects (internal) used to project a data value to a plot-div\n * pixel. Bars report a `bbox` that sits below their visual top, so we anchor\n * to `_offset + l2p(value)` instead.\n */\n yaxis?: { _offset?: number; l2p?: (value: number) => number };\n xaxis?: { _offset?: number; l2p?: (value: number) => number };\n}\n\nconst formatValue = (value: number | string): string => {\n if (typeof value !== \"number\") return String(value);\n return Number.isInteger(value) ? String(value) : value.toFixed(2);\n};\n\nconst pieLines = (point: ChartTooltipHoverPoint): string[] => {\n const lines = [\n String(point.label),\n `Value: ${formatValue((point.value ?? point.v)!)}`,\n ];\n if (typeof point.percent === \"number\") {\n lines.push(`${point.percent.toFixed(1)}%`);\n } else if (typeof point.text === \"string\" && point.text.endsWith(\"%\")) {\n lines.push(point.text);\n }\n return lines;\n};\n\n/** Unified hover across multiple traces: shared x, one line per trace */\nconst unifiedLines = (\n points: ChartTooltipHoverPoint[],\n xLabel: string,\n): string[] => {\n const [first] = points;\n const lines =\n first.x === undefined ? [] : [`${xLabel}: ${formatValue(first.x)}`];\n for (const point of points) {\n if (point.y === undefined) continue;\n lines.push(`${point.data?.name ?? \"Series\"}: ${formatValue(point.y)}`);\n }\n return lines;\n};\n\nconst cartesianLines = (\n point: ChartTooltipHoverPoint,\n xLabel: string,\n yLabel: string,\n): string[] => {\n const lines: string[] = [];\n if (point.data?.name) lines.push(point.data.name);\n if (point.x !== undefined) lines.push(`${xLabel}: ${formatValue(point.x)}`);\n if (point.y !== undefined) lines.push(`${yLabel}: ${formatValue(point.y)}`);\n if (point.z !== undefined) lines.push(`Value: ${formatValue(point.z)}`);\n return lines;\n};\n\n/**\n * Build default tooltip lines from Plotly hover points. Handles pie slices,\n * text-carrying traces (e.g. PlateMap wells), single cartesian points, and\n * unified multi-trace hovers.\n */\nexport function chartTooltipLines(\n points: ChartTooltipHoverPoint[],\n labels?: { xLabel?: string; yLabel?: string },\n): string[] {\n if (points.length === 0) return [];\n const [first] = points;\n\n // Pie hover points carry label/value without axis coordinates; bar points\n // also alias label/value but always have x/y\n if (\n first.label !== undefined &&\n (first.value ?? first.v) !== undefined &&\n first.x === undefined &&\n first.y === undefined\n ) {\n return pieLines(first);\n }\n\n // Traces that carry their own hover text (e.g. PlateMap wells)\n if (typeof first.text === \"string\" && first.text.length > 0) {\n return first.text.split(\"<br>\").filter(Boolean);\n }\n\n const xLabel = labels?.xLabel || \"X\";\n const yLabel = labels?.yLabel || \"Y\";\n return points.length > 1\n ? unifiedLines(points, xLabel)\n : cartesianLines(first, xLabel, yLabel);\n}\n"],"names":["formatValue","value","pieLines","point","lines","unifiedLines","points","xLabel","first","cartesianLines","yLabel","chartTooltipLines","labels"],"mappings":"AAiCA,MAAMA,IAAc,CAACC,MACf,OAAOA,KAAU,YACd,OAAO,UAAUA,CAAK,IADS,OAAOA,CAAK,IACDA,EAAM,QAAQ,CAAC,GAG5DC,IAAW,CAACC,MAA4C;AAC5D,QAAMC,IAAQ;AAAA,IACZ,OAAOD,EAAM,KAAK;AAAA,IAClB,UAAUH,EAAaG,EAAM,SAASA,EAAM,CAAG,CAAC;AAAA,EAAA;AAElD,SAAI,OAAOA,EAAM,WAAY,WAC3BC,EAAM,KAAK,GAAGD,EAAM,QAAQ,QAAQ,CAAC,CAAC,GAAG,IAChC,OAAOA,EAAM,QAAS,YAAYA,EAAM,KAAK,SAAS,GAAG,KAClEC,EAAM,KAAKD,EAAM,IAAI,GAEhBC;AACT,GAGMC,IAAe,CACnBC,GACAC,MACa;AACb,QAAM,CAACC,CAAK,IAAIF,GACVF,IACJI,EAAM,MAAM,SAAY,CAAA,IAAK,CAAC,GAAGD,CAAM,KAAKP,EAAYQ,EAAM,CAAC,CAAC,EAAE;AACpE,aAAWL,KAASG;AAClB,IAAIH,EAAM,MAAM,UAChBC,EAAM,KAAK,GAAGD,EAAM,MAAM,QAAQ,QAAQ,KAAKH,EAAYG,EAAM,CAAC,CAAC,EAAE;AAEvE,SAAOC;AACT,GAEMK,IAAiB,CACrBN,GACAI,GACAG,MACa;AACb,QAAMN,IAAkB,CAAA;AACxB,SAAID,EAAM,MAAM,UAAY,KAAKA,EAAM,KAAK,IAAI,GAC5CA,EAAM,MAAM,UAAWC,EAAM,KAAK,GAAGG,CAAM,KAAKP,EAAYG,EAAM,CAAC,CAAC,EAAE,GACtEA,EAAM,MAAM,UAAWC,EAAM,KAAK,GAAGM,CAAM,KAAKV,EAAYG,EAAM,CAAC,CAAC,EAAE,GACtEA,EAAM,MAAM,UAAWC,EAAM,KAAK,UAAUJ,EAAYG,EAAM,CAAC,CAAC,EAAE,GAC/DC;AACT;AAOO,SAASO,EACdL,GACAM,GACU;AACV,MAAIN,EAAO,WAAW,EAAG,QAAO,CAAA;AAChC,QAAM,CAACE,CAAK,IAAIF;AAIhB,MACEE,EAAM,UAAU,WACfA,EAAM,SAASA,EAAM,OAAO,UAC7BA,EAAM,MAAM,UACZA,EAAM,MAAM;AAEZ,WAAON,EAASM,CAAK;AAIvB,MAAI,OAAOA,EAAM,QAAS,YAAYA,EAAM,KAAK,SAAS;AACxD,WAAOA,EAAM,KAAK,MAAM,MAAM,EAAE,OAAO,OAAO;AAGhD,QAAMD,IAASK,GAAQ,UAAU,KAC3BF,IAASE,GAAQ,UAAU;AACjC,SAAON,EAAO,SAAS,IACnBD,EAAaC,GAAQC,CAAM,IAC3BE,EAAeD,GAAOD,GAAQG,CAAM;AAC1C;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),F=require("plotly.js-dist"),n=require("react"),G=require("../../../hooks/use-plotly-theme.cjs");;/* empty css */const O=75,D=1.05,R=e=>{const a={A:e.peakA,T:e.peakT,G:e.peakG,C:e.peakC},p=Object.values(a);if(p.every(c=>c===p[0]))return"";let u="",h=0;return Object.entries(a).forEach(([c,f])=>{f>h&&(u=c,h=f)}),u},$=({data:e=[],width:a=900,height:p=600,positionInterval:x=10,colorA:u="#2D9CDB",colorT:h="#A1C63C",colorG:c="#FF5C64",colorC:f="#FFA62E"})=>{const d=n.useRef(null),y=G.usePlotlyTheme(),s=n.useMemo(()=>e.map(t=>t.position),[e]),S=n.useMemo(()=>e.map(t=>R(t)),[e]),M=n.useMemo(()=>e.map(t=>t.peakA),[e]),P=n.useMemo(()=>e.map(t=>t.peakT),[e]),k=n.useMemo(()=>e.map(t=>t.peakG),[e]),T=n.useMemo(()=>e.map(t=>t.peakC),[e]),C=n.useMemo(()=>({x:s,y:M,type:"scatter",mode:"lines",name:"A",line:{color:u,width:2,shape:"spline"}}),[s,M,u]),b=n.useMemo(()=>({x:s,y:P,type:"scatter",mode:"lines",name:"T",line:{color:h,width:2,shape:"spline"}}),[s,P,h]),N=n.useMemo(()=>({x:s,y:k,type:"scatter",mode:"lines",name:"G",line:{color:c,width:2,shape:"spline"}}),[s,k,c]),v=n.useMemo(()=>({x:s,y:T,type:"scatter",mode:"lines",name:"C",line:{color:f,width:2,shape:"spline"}}),[s,T,f]),w=n.useMemo(()=>Math.max(...M,...P,...k,...T),[M,P,k,T]);if(n.useEffect(()=>{if(!d.current||e.length===0)return;const t=[C,b,N,v],j={width:a,height:p-O,margin:{l:0,r:0,b:20,t:10,pad:0},paper_bgcolor:y.paperBg,plot_bgcolor:y.plotBg,font:{family:"Inter, sans-serif"},showlegend:!1,xaxis:{showgrid:!1,zeroline:!1,showticklabels:!1,showline:!1,range:[Math.min(...s),Math.max(...s)],fixedrange:!0},yaxis:{showgrid:!1,zeroline:!1,showticklabels:!1,showline:!1,range:[0,w*D],fixedrange:!0}},i={responsive:!0,displayModeBar:!1,displaylogo:!1,fillFrame:!0};F.newPlot(d.current,t,j,i);const l=d.current;return()=>{l&&F.purge(l)}},[e,a,p,C,b,N,v,w,s,y]),e.length===0)return r.jsx("div",{className:"chart-container",children:"No data available"});const _=()=>{const t=()=>{const i=Math.min(...s),l=Math.max(...s),q=a;return r.jsx("div",{className:"sequence-letters-container",children:S.map((m,g)=>{const o=s[g],A=m==="A"?u:m==="T"?h:m==="G"?c:m==="C"?f:y.textColor,B=(o-i)/(l-i)*q;return r.jsx("span",{className:"sequence-letter",style:{left:`${B}px`,color:A},children:m},`base-${g}`)})})},j=()=>{const i=Math.min(...s),l=Math.max(...s),q=a,m=Math.ceil(i/x)*x,g=[];for(let o=m;o<=l;o+=x)g.push({position:o,label:o.toString()});return r.jsx("div",{className:"position-numbers-container",children:g.map(o=>{const E=(o.position-i)/(l-i)*q;return r.jsx("span",{className:"position-number",style:{left:`${E}px`},children:o.label},`pos-${o.position}`)})})};return r.jsxs("div",{className:"sequence-header",children:[t(),j()]})};return r.jsxs("div",{className:"chromatogram-container",style:{width:a,height:p},children:[_(),r.jsx("div",{className:"chromatogram-chart",children:r.jsx("div",{ref:d,style:{width:"100%",height:"100%"}})})]})};exports.Chromatogram=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),w=require("plotly.js-dist"),n=require("react"),B=require("../ChartTooltip/ChartTooltip.cjs"),F=require("../../../hooks/use-plotly-theme.cjs"),k=require("../../../utils/colors.cjs");;/* empty css */const $=75,D=1.05,I=e=>{const i={A:e.peakA,T:e.peakT,G:e.peakG,C:e.peakC},m=Object.values(i);if(m.every(l=>l===m[0]))return"";let u="",h=0;return Object.entries(i).forEach(([l,f])=>{f>h&&(u=l,h=f)}),u},V=({data:e=[],width:i=900,height:m=600,positionInterval:d=10,colorA:u=k.CHART_COLORS[0],colorT:h=k.CHART_COLORS[2],colorG:l=k.CHART_COLORS[3],colorC:f=k.CHART_COLORS[1]})=>{const g=n.useRef(null),y=F.usePlotlyTheme(),{bindTooltip:b,tooltipElement:L}=B.useChartTooltip({xLabel:"Position",yLabel:"Intensity"}),s=n.useMemo(()=>e.map(t=>t.position),[e]),E=n.useMemo(()=>e.map(t=>I(t)),[e]),T=n.useMemo(()=>e.map(t=>t.peakA),[e]),M=n.useMemo(()=>e.map(t=>t.peakT),[e]),C=n.useMemo(()=>e.map(t=>t.peakG),[e]),P=n.useMemo(()=>e.map(t=>t.peakC),[e]),O=n.useMemo(()=>({x:s,y:T,type:"scatter",mode:"lines",hoverinfo:"none",name:"A",line:{color:u,width:2,shape:"spline"}}),[s,T,u]),j=n.useMemo(()=>({x:s,y:M,type:"scatter",mode:"lines",hoverinfo:"none",name:"T",line:{color:h,width:2,shape:"spline"}}),[s,M,h]),R=n.useMemo(()=>({x:s,y:C,type:"scatter",mode:"lines",hoverinfo:"none",name:"G",line:{color:l,width:2,shape:"spline"}}),[s,C,l]),A=n.useMemo(()=>({x:s,y:P,type:"scatter",mode:"lines",hoverinfo:"none",name:"C",line:{color:f,width:2,shape:"spline"}}),[s,P,f]),N=n.useMemo(()=>Math.max(...T,...M,...C,...P),[T,M,C,P]);if(n.useEffect(()=>{if(!g.current||e.length===0)return;const t=[O,j,R,A],q={width:i,height:m-$,margin:{l:0,r:0,b:20,t:10,pad:0},paper_bgcolor:y.paperBg,plot_bgcolor:y.plotBg,font:{family:"Inter, sans-serif"},showlegend:!1,xaxis:{showgrid:!1,zeroline:!1,showticklabels:!1,showline:!1,range:[Math.min(...s),Math.max(...s)],fixedrange:!0},yaxis:{showgrid:!1,zeroline:!1,showticklabels:!1,showline:!1,range:[0,N*D],fixedrange:!0}},a={responsive:!0,displayModeBar:!1,displaylogo:!1,fillFrame:!0};w.newPlot(g.current,t,q,a),b(g.current);const c=g.current;return()=>{c&&w.purge(c)}},[e,i,m,O,j,R,A,N,s,y,b]),e.length===0)return r.jsx("div",{className:"chart-container",children:"No data available"});const G=()=>{const t=()=>{const a=Math.min(...s),c=Math.max(...s),v=i;return r.jsx("div",{className:"sequence-letters-container",children:E.map((p,x)=>{const o=s[x],S=p==="A"?u:p==="T"?h:p==="G"?l:p==="C"?f:y.textColor,H=(o-a)/(c-a)*v;return r.jsx("span",{className:"sequence-letter",style:{left:`${H}px`,color:S},children:p},`base-${x}`)})})},q=()=>{const a=Math.min(...s),c=Math.max(...s),v=i,p=Math.ceil(a/d)*d,x=[];for(let o=p;o<=c;o+=d)x.push({position:o,label:o.toString()});return r.jsx("div",{className:"position-numbers-container",children:x.map(o=>{const _=(o.position-a)/(c-a)*v;return r.jsx("span",{className:"position-number",style:{left:`${_}px`},children:o.label},`pos-${o.position}`)})})};return r.jsxs("div",{className:"sequence-header",children:[t(),q()]})};return r.jsxs("div",{className:"chromatogram-container relative",style:{width:i,height:m},children:[G(),r.jsx("div",{className:"chromatogram-chart",children:r.jsx("div",{ref:g,style:{width:"100%",height:"100%"}})}),L]})};exports.Chromatogram=V;
2
2
  //# sourceMappingURL=Chromatogram.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"Chromatogram.cjs","sources":["../../../../src/components/charts/Chromatogram/Chromatogram.tsx"],"sourcesContent":["import Plotly from \"plotly.js-dist\";\nimport React, { useEffect, useRef, useMemo } from \"react\";\n\nimport { usePlotlyTheme } from \"@/hooks/use-plotly-theme\";\nimport \"./Chromatogram.scss\";\n\n/** Height offset for the plot area in pixels */\nconst PLOT_HEIGHT_OFFSET = 75;\n/** Scale factor for y-axis range to add padding above max value */\nconst Y_AXIS_PADDING_FACTOR = 1.05;\n\ninterface PeakData {\n position: number;\n base?: string;\n peakA: number;\n peakT: number;\n peakG: number;\n peakC: number;\n}\n\ninterface ChromatogramProps {\n data?: PeakData[];\n width?: number;\n height?: number;\n positionInterval?: number;\n colorA?: string;\n colorT?: string;\n colorG?: string;\n colorC?: string;\n}\n\nconst determineBase = (item: PeakData): string => {\n const peakValues = {\n A: item.peakA,\n T: item.peakT,\n G: item.peakG,\n C: item.peakC,\n };\n\n const values = Object.values(peakValues);\n const allEqual = values.every((val) => val === values[0]);\n\n if (allEqual) {\n return \"\";\n }\n\n let highestBase = \"\";\n let highestValue = 0;\n\n Object.entries(peakValues).forEach(([base, value]) => {\n if (value > highestValue) {\n highestBase = base;\n highestValue = value;\n }\n });\n\n return highestBase;\n};\n\nconst Chromatogram: React.FC<ChromatogramProps> = ({\n data = [],\n width = 900,\n height = 600,\n positionInterval = 10,\n colorA = \"#2D9CDB\",\n colorT = \"#A1C63C\",\n colorG = \"#FF5C64\",\n colorC = \"#FFA62E\",\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n\n const positions = useMemo(() => data.map((item) => item.position), [data]);\n const sequence = useMemo(() => data.map((item) => determineBase(item)), [data]);\n const peakA = useMemo(() => data.map((item) => item.peakA), [data]);\n const peakT = useMemo(() => data.map((item) => item.peakT), [data]);\n const peakG = useMemo(() => data.map((item) => item.peakG), [data]);\n const peakC = useMemo(() => data.map((item) => item.peakC), [data]);\n\n const aTrace = useMemo(\n () => ({\n x: positions,\n y: peakA,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n name: \"A\",\n line: { color: colorA, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakA, colorA],\n );\n\n const tTrace = useMemo(\n () => ({\n x: positions,\n y: peakT,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n name: \"T\",\n line: { color: colorT, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakT, colorT],\n );\n\n const gTrace = useMemo(\n () => ({\n x: positions,\n y: peakG,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n name: \"G\",\n line: { color: colorG, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakG, colorG],\n );\n\n const cTrace = useMemo(\n () => ({\n x: positions,\n y: peakC,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n name: \"C\",\n line: { color: colorC, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakC, colorC],\n );\n\n const maxValue = useMemo(\n () => Math.max(...peakA, ...peakT, ...peakG, ...peakC),\n [peakA, peakT, peakG, peakC],\n );\n\n useEffect(() => {\n if (!plotRef.current || data.length === 0) return;\n\n const plotData = [aTrace, tTrace, gTrace, cTrace];\n\n const layout: Partial<Plotly.Layout> = {\n width: width,\n height: height - PLOT_HEIGHT_OFFSET,\n margin: { l: 0, r: 0, b: 20, t: 10, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n showlegend: false,\n xaxis: {\n showgrid: false,\n zeroline: false,\n showticklabels: false,\n showline: false,\n range: [Math.min(...positions), Math.max(...positions)],\n fixedrange: true,\n },\n yaxis: {\n showgrid: false,\n zeroline: false,\n showticklabels: false,\n showline: false,\n range: [0, maxValue * Y_AXIS_PADDING_FACTOR],\n fixedrange: true,\n },\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n fillFrame: true,\n };\n\n Plotly.newPlot(plotRef.current, plotData, layout, config);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [data, width, height, aTrace, tTrace, gTrace, cTrace, maxValue, positions, theme]);\n\n if (data.length === 0) {\n return <div className=\"chart-container\">No data available</div>;\n }\n\n const renderSequence = () => {\n const renderSequenceLetters = () => {\n const minPosition = Math.min(...positions);\n const maxPosition = Math.max(...positions);\n const chartWidth = width;\n\n return (\n <div className=\"sequence-letters-container\">\n {sequence.map((base, index) => {\n const position = positions[index];\n const color =\n base === \"A\"\n ? colorA\n : base === \"T\"\n ? colorT\n : base === \"G\"\n ? colorG\n : base === \"C\"\n ? colorC\n : theme.textColor;\n\n const percentage =\n (position - minPosition) / (maxPosition - minPosition);\n const leftPosition = percentage * chartWidth;\n\n return (\n <span\n key={`base-${index}`}\n className=\"sequence-letter\"\n style={{\n left: `${leftPosition}px`,\n color,\n }}\n >\n {base}\n </span>\n );\n })}\n </div>\n );\n };\n\n const renderPositionNumbers = () => {\n const minPosition = Math.min(...positions);\n const maxPosition = Math.max(...positions);\n const chartWidth = width;\n\n const startPos =\n Math.ceil(minPosition / positionInterval) * positionInterval;\n\n const regularPositionLabels: Array<{ position: number; label: string }> =\n [];\n\n for (let pos = startPos; pos <= maxPosition; pos += positionInterval) {\n regularPositionLabels.push({\n position: pos,\n label: pos.toString(),\n });\n }\n\n return (\n <div className=\"position-numbers-container\">\n {regularPositionLabels.map((label) => {\n const percentage =\n (label.position - minPosition) / (maxPosition - minPosition);\n const leftPosition = percentage * chartWidth;\n\n return (\n <span\n key={`pos-${label.position}`}\n className=\"position-number\"\n style={{\n left: `${leftPosition}px`,\n }}\n >\n {label.label}\n </span>\n );\n })}\n </div>\n );\n };\n\n return (\n <div className=\"sequence-header\">\n {renderSequenceLetters()}\n {renderPositionNumbers()}\n </div>\n );\n };\n\n return (\n <div className=\"chromatogram-container\" style={{ width, height }}>\n {renderSequence()}\n <div className=\"chromatogram-chart\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n </div>\n </div>\n );\n};\n\nexport { Chromatogram };\nexport type { PeakData, ChromatogramProps };\n"],"names":["PLOT_HEIGHT_OFFSET","Y_AXIS_PADDING_FACTOR","determineBase","item","peakValues","values","val","highestBase","highestValue","base","value","Chromatogram","data","width","height","positionInterval","colorA","colorT","colorG","colorC","plotRef","useRef","theme","usePlotlyTheme","positions","useMemo","sequence","peakA","peakT","peakG","peakC","aTrace","tTrace","gTrace","cTrace","maxValue","useEffect","plotData","layout","config","Plotly","plotElement","jsx","renderSequence","renderSequenceLetters","minPosition","maxPosition","chartWidth","index","position","color","leftPosition","renderPositionNumbers","startPos","regularPositionLabels","pos","label","jsxs"],"mappings":"wPAOA,MAAMA,EAAqB,GAErBC,EAAwB,KAsBxBC,EAAiBC,GAA2B,CAChD,MAAMC,EAAa,CACjB,EAAGD,EAAK,MACR,EAAGA,EAAK,MACR,EAAGA,EAAK,MACR,EAAGA,EAAK,KAAA,EAGJE,EAAS,OAAO,OAAOD,CAAU,EAGvC,GAFiBC,EAAO,MAAOC,GAAQA,IAAQD,EAAO,CAAC,CAAC,EAGtD,MAAO,GAGT,IAAIE,EAAc,GACdC,EAAe,EAEnB,cAAO,QAAQJ,CAAU,EAAE,QAAQ,CAAC,CAACK,EAAMC,CAAK,IAAM,CAChDA,EAAQF,IACVD,EAAcE,EACdD,EAAeE,EAEnB,CAAC,EAEMH,CACT,EAEMI,EAA4C,CAAC,CACjD,KAAAC,EAAO,CAAA,EACP,MAAAC,EAAQ,IACR,OAAAC,EAAS,IACT,iBAAAC,EAAmB,GACnB,OAAAC,EAAS,UACT,OAAAC,EAAS,UACT,OAAAC,EAAS,UACT,OAAAC,EAAS,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,SAAAK,EAAM,KAAA,EANF,OAAOA,EAAM,QAAQ,EAAA,CAShC,CAAC,CAAA,CACH,CAEJ,EAEA,OACEC,EAAAA,KAAC,MAAA,CAAI,UAAU,kBACZ,SAAA,CAAAb,EAAA,EACAQ,EAAA,CAAsB,EACzB,CAEJ,EAEA,OACEK,EAAAA,KAAC,OAAI,UAAU,yBAAyB,MAAO,CAAE,MAAA5C,EAAO,OAAAC,GACrD,SAAA,CAAA6B,EAAA,EACDD,EAAAA,IAAC,MAAA,CAAI,UAAU,qBACb,eAAC,MAAA,CAAI,IAAKtB,EAAS,MAAO,CAAE,MAAO,OAAQ,OAAQ,MAAA,EAAU,CAAA,CAC/D,CAAA,EACF,CAEJ"}
1
+ {"version":3,"file":"Chromatogram.cjs","sources":["../../../../src/components/charts/Chromatogram/Chromatogram.tsx"],"sourcesContent":["import Plotly from \"plotly.js-dist\";\nimport React, { useEffect, useRef, useMemo } from \"react\";\n\nimport { useChartTooltip } from \"../ChartTooltip\";\n\nimport { usePlotlyTheme } from \"@/hooks/use-plotly-theme\";\nimport { CHART_COLORS } from \"@/utils/colors\";\nimport \"./Chromatogram.scss\";\n\n/** Height offset for the plot area in pixels */\nconst PLOT_HEIGHT_OFFSET = 75;\n/** Scale factor for y-axis range to add padding above max value */\nconst Y_AXIS_PADDING_FACTOR = 1.05;\n\ninterface PeakData {\n position: number;\n base?: string;\n peakA: number;\n peakT: number;\n peakG: number;\n peakC: number;\n}\n\ninterface ChromatogramProps {\n data?: PeakData[];\n width?: number;\n height?: number;\n positionInterval?: number;\n colorA?: string;\n colorT?: string;\n colorG?: string;\n colorC?: string;\n}\n\nconst determineBase = (item: PeakData): string => {\n const peakValues = {\n A: item.peakA,\n T: item.peakT,\n G: item.peakG,\n C: item.peakC,\n };\n\n const values = Object.values(peakValues);\n const allEqual = values.every((val) => val === values[0]);\n\n if (allEqual) {\n return \"\";\n }\n\n let highestBase = \"\";\n let highestValue = 0;\n\n Object.entries(peakValues).forEach(([base, value]) => {\n if (value > highestValue) {\n highestBase = base;\n highestValue = value;\n }\n });\n\n return highestBase;\n};\n\nconst Chromatogram: React.FC<ChromatogramProps> = ({\n data = [],\n width = 900,\n height = 600,\n positionInterval = 10,\n colorA = CHART_COLORS[0], // blue\n colorT = CHART_COLORS[2], // teal/green\n colorG = CHART_COLORS[3], // red\n colorC = CHART_COLORS[1], // orange\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n const { bindTooltip, tooltipElement } = useChartTooltip({\n xLabel: \"Position\",\n yLabel: \"Intensity\",\n });\n\n const positions = useMemo(() => data.map((item) => item.position), [data]);\n const sequence = useMemo(() => data.map((item) => determineBase(item)), [data]);\n const peakA = useMemo(() => data.map((item) => item.peakA), [data]);\n const peakT = useMemo(() => data.map((item) => item.peakT), [data]);\n const peakG = useMemo(() => data.map((item) => item.peakG), [data]);\n const peakC = useMemo(() => data.map((item) => item.peakC), [data]);\n\n const aTrace = useMemo(\n () => ({\n x: positions,\n y: peakA,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n hoverinfo: \"none\" as const,\n name: \"A\",\n line: { color: colorA, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakA, colorA],\n );\n\n const tTrace = useMemo(\n () => ({\n x: positions,\n y: peakT,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n hoverinfo: \"none\" as const,\n name: \"T\",\n line: { color: colorT, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakT, colorT],\n );\n\n const gTrace = useMemo(\n () => ({\n x: positions,\n y: peakG,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n hoverinfo: \"none\" as const,\n name: \"G\",\n line: { color: colorG, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakG, colorG],\n );\n\n const cTrace = useMemo(\n () => ({\n x: positions,\n y: peakC,\n type: \"scatter\" as const,\n mode: \"lines\" as const,\n hoverinfo: \"none\" as const,\n name: \"C\",\n line: { color: colorC, width: 2, shape: \"spline\" as const },\n }),\n [positions, peakC, colorC],\n );\n\n const maxValue = useMemo(\n () => Math.max(...peakA, ...peakT, ...peakG, ...peakC),\n [peakA, peakT, peakG, peakC],\n );\n\n useEffect(() => {\n if (!plotRef.current || data.length === 0) return;\n\n const plotData = [aTrace, tTrace, gTrace, cTrace];\n\n const layout: Partial<Plotly.Layout> = {\n width: width,\n height: height - PLOT_HEIGHT_OFFSET,\n margin: { l: 0, r: 0, b: 20, t: 10, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n showlegend: false,\n xaxis: {\n showgrid: false,\n zeroline: false,\n showticklabels: false,\n showline: false,\n range: [Math.min(...positions), Math.max(...positions)],\n fixedrange: true,\n },\n yaxis: {\n showgrid: false,\n zeroline: false,\n showticklabels: false,\n showline: false,\n range: [0, maxValue * Y_AXIS_PADDING_FACTOR],\n fixedrange: true,\n },\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n fillFrame: true,\n };\n\n Plotly.newPlot(plotRef.current, plotData, layout, config);\n bindTooltip(plotRef.current);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [data, width, height, aTrace, tTrace, gTrace, cTrace, maxValue, positions, theme, bindTooltip]);\n\n if (data.length === 0) {\n return <div className=\"chart-container\">No data available</div>;\n }\n\n const renderSequence = () => {\n const renderSequenceLetters = () => {\n const minPosition = Math.min(...positions);\n const maxPosition = Math.max(...positions);\n const chartWidth = width;\n\n return (\n <div className=\"sequence-letters-container\">\n {sequence.map((base, index) => {\n const position = positions[index];\n const color =\n base === \"A\"\n ? colorA\n : base === \"T\"\n ? colorT\n : base === \"G\"\n ? colorG\n : base === \"C\"\n ? colorC\n : theme.textColor;\n\n const percentage =\n (position - minPosition) / (maxPosition - minPosition);\n const leftPosition = percentage * chartWidth;\n\n return (\n <span\n key={`base-${index}`}\n className=\"sequence-letter\"\n style={{\n left: `${leftPosition}px`,\n color,\n }}\n >\n {base}\n </span>\n );\n })}\n </div>\n );\n };\n\n const renderPositionNumbers = () => {\n const minPosition = Math.min(...positions);\n const maxPosition = Math.max(...positions);\n const chartWidth = width;\n\n const startPos =\n Math.ceil(minPosition / positionInterval) * positionInterval;\n\n const regularPositionLabels: Array<{ position: number; label: string }> =\n [];\n\n for (let pos = startPos; pos <= maxPosition; pos += positionInterval) {\n regularPositionLabels.push({\n position: pos,\n label: pos.toString(),\n });\n }\n\n return (\n <div className=\"position-numbers-container\">\n {regularPositionLabels.map((label) => {\n const percentage =\n (label.position - minPosition) / (maxPosition - minPosition);\n const leftPosition = percentage * chartWidth;\n\n return (\n <span\n key={`pos-${label.position}`}\n className=\"position-number\"\n style={{\n left: `${leftPosition}px`,\n }}\n >\n {label.label}\n </span>\n );\n })}\n </div>\n );\n };\n\n return (\n <div className=\"sequence-header\">\n {renderSequenceLetters()}\n {renderPositionNumbers()}\n </div>\n );\n };\n\n return (\n <div className=\"chromatogram-container relative\" style={{ width, height }}>\n {renderSequence()}\n <div className=\"chromatogram-chart\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n </div>\n {tooltipElement}\n </div>\n );\n};\n\nexport { Chromatogram };\nexport type { PeakData, ChromatogramProps };\n"],"names":["PLOT_HEIGHT_OFFSET","Y_AXIS_PADDING_FACTOR","determineBase","item","peakValues","values","val","highestBase","highestValue","base","value","Chromatogram","data","width","height","positionInterval","colorA","CHART_COLORS","colorT","colorG","colorC","plotRef","useRef","theme","usePlotlyTheme","bindTooltip","tooltipElement","useChartTooltip","positions","useMemo","sequence","peakA","peakT","peakG","peakC","aTrace","tTrace","gTrace","cTrace","maxValue","useEffect","plotData","layout","config","Plotly","plotElement","jsx","renderSequence","renderSequenceLetters","minPosition","maxPosition","chartWidth","index","position","color","leftPosition","renderPositionNumbers","startPos","regularPositionLabels","pos","label","jsxs"],"mappings":"6UAUA,MAAMA,EAAqB,GAErBC,EAAwB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AAQ,OAAQ,MAAA,EAAU,EAC/D,EACCK,CAAA,EACH,CAEJ"}
@@ -1,80 +1,93 @@
1
- import { jsx as p, jsxs as _ } from "react/jsx-runtime";
2
- import B from "plotly.js-dist";
3
- import { useRef as D, useMemo as n, useEffect as O } from "react";
4
- import { usePlotlyTheme as j } from "../../../hooks/use-plotly-theme.js";
1
+ import { jsx as p, jsxs as G } from "react/jsx-runtime";
2
+ import L from "plotly.js-dist";
3
+ import { useRef as F, useMemo as s, useEffect as $ } from "react";
4
+ import { useChartTooltip as D } from "../ChartTooltip/ChartTooltip.js";
5
+ import { usePlotlyTheme as H } from "../../../hooks/use-plotly-theme.js";
6
+ import { CHART_COLORS as b } from "../../../utils/colors.js";
5
7
  /* empty css */
6
- const $ = 75, L = 1.05, R = (e) => {
8
+ const I = 75, V = 1.05, z = (e) => {
7
9
  const r = {
8
10
  A: e.peakA,
9
11
  T: e.peakT,
10
12
  G: e.peakG,
11
13
  C: e.peakC
12
14
  }, m = Object.values(r);
13
- if (m.every((i) => i === m[0]))
15
+ if (m.every((a) => a === m[0]))
14
16
  return "";
15
17
  let h = "", u = 0;
16
- return Object.entries(r).forEach(([i, f]) => {
17
- f > u && (h = i, u = f);
18
+ return Object.entries(r).forEach(([a, f]) => {
19
+ f > u && (h = a, u = f);
18
20
  }), h;
19
- }, Y = ({
21
+ }, ee = ({
20
22
  data: e = [],
21
23
  width: r = 900,
22
24
  height: m = 600,
23
- positionInterval: d = 10,
24
- colorA: h = "#2D9CDB",
25
- colorT: u = "#A1C63C",
26
- colorG: i = "#FF5C64",
27
- colorC: f = "#FFA62E"
25
+ positionInterval: x = 10,
26
+ colorA: h = b[0],
27
+ // blue
28
+ colorT: u = b[2],
29
+ // teal/green
30
+ colorG: a = b[3],
31
+ // red
32
+ colorC: f = b[1]
33
+ // orange
28
34
  }) => {
29
- const x = D(null), y = j(), s = n(() => e.map((t) => t.position), [e]), G = n(() => e.map((t) => R(t)), [e]), k = n(() => e.map((t) => t.peakA), [e]), P = n(() => e.map((t) => t.peakT), [e]), T = n(() => e.map((t) => t.peakG), [e]), C = n(() => e.map((t) => t.peakC), [e]), b = n(
35
+ const g = F(null), y = H(), { bindTooltip: M, tooltipElement: B } = D({
36
+ xLabel: "Position",
37
+ yLabel: "Intensity"
38
+ }), n = s(() => e.map((t) => t.position), [e]), R = s(() => e.map((t) => z(t)), [e]), T = s(() => e.map((t) => t.peakA), [e]), k = s(() => e.map((t) => t.peakT), [e]), P = s(() => e.map((t) => t.peakG), [e]), v = s(() => e.map((t) => t.peakC), [e]), q = s(
30
39
  () => ({
31
- x: s,
32
- y: k,
40
+ x: n,
41
+ y: T,
33
42
  type: "scatter",
34
43
  mode: "lines",
44
+ hoverinfo: "none",
35
45
  name: "A",
36
46
  line: { color: h, width: 2, shape: "spline" }
37
47
  }),
38
- [s, k, h]
39
- ), q = n(
48
+ [n, T, h]
49
+ ), w = s(
40
50
  () => ({
41
- x: s,
42
- y: P,
51
+ x: n,
52
+ y: k,
43
53
  type: "scatter",
44
54
  mode: "lines",
55
+ hoverinfo: "none",
45
56
  name: "T",
46
57
  line: { color: u, width: 2, shape: "spline" }
47
58
  }),
48
- [s, P, u]
49
- ), v = n(
59
+ [n, k, u]
60
+ ), A = s(
50
61
  () => ({
51
- x: s,
52
- y: T,
62
+ x: n,
63
+ y: P,
53
64
  type: "scatter",
54
65
  mode: "lines",
66
+ hoverinfo: "none",
55
67
  name: "G",
56
- line: { color: i, width: 2, shape: "spline" }
68
+ line: { color: a, width: 2, shape: "spline" }
57
69
  }),
58
- [s, T, i]
59
- ), w = n(
70
+ [n, P, a]
71
+ ), E = s(
60
72
  () => ({
61
- x: s,
62
- y: C,
73
+ x: n,
74
+ y: v,
63
75
  type: "scatter",
64
76
  mode: "lines",
77
+ hoverinfo: "none",
65
78
  name: "C",
66
79
  line: { color: f, width: 2, shape: "spline" }
67
80
  }),
68
- [s, C, f]
69
- ), A = n(
70
- () => Math.max(...k, ...P, ...T, ...C),
71
- [k, P, T, C]
81
+ [n, v, f]
82
+ ), _ = s(
83
+ () => Math.max(...T, ...k, ...P, ...v),
84
+ [T, k, P, v]
72
85
  );
73
- return O(() => {
74
- if (!x.current || e.length === 0) return;
75
- const t = [b, q, v, w], N = {
86
+ return $(() => {
87
+ if (!g.current || e.length === 0) return;
88
+ const t = [q, w, A, E], N = {
76
89
  width: r,
77
- height: m - $,
90
+ height: m - I,
78
91
  margin: { l: 0, r: 0, b: 20, t: 10, pad: 0 },
79
92
  paper_bgcolor: y.paperBg,
80
93
  plot_bgcolor: y.plotBg,
@@ -87,7 +100,7 @@ const $ = 75, L = 1.05, R = (e) => {
87
100
  zeroline: !1,
88
101
  showticklabels: !1,
89
102
  showline: !1,
90
- range: [Math.min(...s), Math.max(...s)],
103
+ range: [Math.min(...n), Math.max(...n)],
91
104
  fixedrange: !0
92
105
  },
93
106
  yaxis: {
@@ -95,54 +108,54 @@ const $ = 75, L = 1.05, R = (e) => {
95
108
  zeroline: !1,
96
109
  showticklabels: !1,
97
110
  showline: !1,
98
- range: [0, A * L],
111
+ range: [0, _ * V],
99
112
  fixedrange: !0
100
113
  }
101
- }, a = {
114
+ }, i = {
102
115
  responsive: !0,
103
116
  displayModeBar: !1,
104
117
  displaylogo: !1,
105
118
  fillFrame: !0
106
119
  };
107
- B.newPlot(x.current, t, N, a);
108
- const c = x.current;
120
+ L.newPlot(g.current, t, N, i), M(g.current);
121
+ const l = g.current;
109
122
  return () => {
110
- c && B.purge(c);
123
+ l && L.purge(l);
111
124
  };
112
- }, [e, r, m, b, q, v, w, A, s, y]), e.length === 0 ? /* @__PURE__ */ p("div", { className: "chart-container", children: "No data available" }) : /* @__PURE__ */ _("div", { className: "chromatogram-container", style: { width: r, height: m }, children: [
125
+ }, [e, r, m, q, w, A, E, _, n, y, M]), e.length === 0 ? /* @__PURE__ */ p("div", { className: "chart-container", children: "No data available" }) : /* @__PURE__ */ G("div", { className: "chromatogram-container relative", style: { width: r, height: m }, children: [
113
126
  (() => {
114
127
  const t = () => {
115
- const a = Math.min(...s), c = Math.max(...s), M = r;
116
- return /* @__PURE__ */ p("div", { className: "sequence-letters-container", children: G.map((l, g) => {
117
- const o = s[g], E = l === "A" ? h : l === "T" ? u : l === "G" ? i : l === "C" ? f : y.textColor, S = (o - a) / (c - a) * M;
128
+ const i = Math.min(...n), l = Math.max(...n), C = r;
129
+ return /* @__PURE__ */ p("div", { className: "sequence-letters-container", children: R.map((c, d) => {
130
+ const o = n[d], O = c === "A" ? h : c === "T" ? u : c === "G" ? a : c === "C" ? f : y.textColor, j = (o - i) / (l - i) * C;
118
131
  return /* @__PURE__ */ p(
119
132
  "span",
120
133
  {
121
134
  className: "sequence-letter",
122
135
  style: {
123
- left: `${S}px`,
124
- color: E
136
+ left: `${j}px`,
137
+ color: O
125
138
  },
126
- children: l
139
+ children: c
127
140
  },
128
- `base-${g}`
141
+ `base-${d}`
129
142
  );
130
143
  }) });
131
144
  }, N = () => {
132
- const a = Math.min(...s), c = Math.max(...s), M = r, l = Math.ceil(a / d) * d, g = [];
133
- for (let o = l; o <= c; o += d)
134
- g.push({
145
+ const i = Math.min(...n), l = Math.max(...n), C = r, c = Math.ceil(i / x) * x, d = [];
146
+ for (let o = c; o <= l; o += x)
147
+ d.push({
135
148
  position: o,
136
149
  label: o.toString()
137
150
  });
138
- return /* @__PURE__ */ p("div", { className: "position-numbers-container", children: g.map((o) => {
139
- const F = (o.position - a) / (c - a) * M;
151
+ return /* @__PURE__ */ p("div", { className: "position-numbers-container", children: d.map((o) => {
152
+ const S = (o.position - i) / (l - i) * C;
140
153
  return /* @__PURE__ */ p(
141
154
  "span",
142
155
  {
143
156
  className: "position-number",
144
157
  style: {
145
- left: `${F}px`
158
+ left: `${S}px`
146
159
  },
147
160
  children: o.label
148
161
  },
@@ -150,15 +163,16 @@ const $ = 75, L = 1.05, R = (e) => {
150
163
  );
151
164
  }) });
152
165
  };
153
- return /* @__PURE__ */ _("div", { className: "sequence-header", children: [
166
+ return /* @__PURE__ */ G("div", { className: "sequence-header", children: [
154
167
  t(),
155
168
  N()
156
169
  ] });
157
170
  })(),
158
- /* @__PURE__ */ p("div", { className: "chromatogram-chart", children: /* @__PURE__ */ p("div", { ref: x, style: { width: "100%", height: "100%" } }) })
171
+ /* @__PURE__ */ p("div", { className: "chromatogram-chart", children: /* @__PURE__ */ p("div", { ref: g, style: { width: "100%", height: "100%" } }) }),
172
+ B
159
173
  ] });
160
174
  };
161
175
  export {
162
- Y as Chromatogram
176
+ ee as Chromatogram
163
177
  };
164
178
  //# sourceMappingURL=Chromatogram.js.map