@tetrascience-npm/tetrascience-react-ui 0.6.0-beta.82.1 → 0.6.0-beta.84.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.
- package/dist/components/charts/AreaGraph/AreaGraph.cjs +1 -1
- package/dist/components/charts/AreaGraph/AreaGraph.cjs.map +1 -1
- package/dist/components/charts/AreaGraph/AreaGraph.js +132 -98
- package/dist/components/charts/AreaGraph/AreaGraph.js.map +1 -1
- package/dist/components/charts/BarGraph/BarGraph.cjs +1 -1
- package/dist/components/charts/BarGraph/BarGraph.cjs.map +1 -1
- package/dist/components/charts/BarGraph/BarGraph.js +63 -57
- package/dist/components/charts/BarGraph/BarGraph.js.map +1 -1
- package/dist/components/charts/Boxplot/Boxplot.cjs +1 -1
- package/dist/components/charts/Boxplot/Boxplot.cjs.map +1 -1
- package/dist/components/charts/Boxplot/Boxplot.js +83 -74
- package/dist/components/charts/Boxplot/Boxplot.js.map +1 -1
- package/dist/components/charts/ChartTooltip/ChartTooltip.cjs +2 -0
- package/dist/components/charts/ChartTooltip/ChartTooltip.cjs.map +1 -0
- package/dist/components/charts/ChartTooltip/ChartTooltip.js +163 -0
- package/dist/components/charts/ChartTooltip/ChartTooltip.js.map +1 -0
- package/dist/components/charts/ChartTooltip/lines.cjs +2 -0
- package/dist/components/charts/ChartTooltip/lines.cjs.map +1 -0
- package/dist/components/charts/ChartTooltip/lines.js +29 -0
- package/dist/components/charts/ChartTooltip/lines.js.map +1 -0
- package/dist/components/charts/Chromatogram/Chromatogram.cjs +1 -1
- package/dist/components/charts/Chromatogram/Chromatogram.cjs.map +1 -1
- package/dist/components/charts/Chromatogram/Chromatogram.js +75 -61
- package/dist/components/charts/Chromatogram/Chromatogram.js.map +1 -1
- package/dist/components/charts/ChromatogramChart/ChromatogramChart.cjs +1 -1
- package/dist/components/charts/ChromatogramChart/ChromatogramChart.cjs.map +1 -1
- package/dist/components/charts/ChromatogramChart/ChromatogramChart.js +116 -108
- package/dist/components/charts/ChromatogramChart/ChromatogramChart.js.map +1 -1
- package/dist/components/charts/ChromatogramChart/annotations.cjs +1 -1
- package/dist/components/charts/ChromatogramChart/annotations.cjs.map +1 -1
- package/dist/components/charts/ChromatogramChart/annotations.js +32 -32
- package/dist/components/charts/ChromatogramChart/annotations.js.map +1 -1
- package/dist/components/charts/ChromatogramChart/boundaryMarkers.cjs +1 -1
- package/dist/components/charts/ChromatogramChart/boundaryMarkers.cjs.map +1 -1
- package/dist/components/charts/ChromatogramChart/boundaryMarkers.js +6 -6
- package/dist/components/charts/ChromatogramChart/boundaryMarkers.js.map +1 -1
- package/dist/components/charts/ChromatogramChart/constants.cjs +1 -1
- package/dist/components/charts/ChromatogramChart/constants.cjs.map +1 -1
- package/dist/components/charts/ChromatogramChart/constants.js +11 -5
- package/dist/components/charts/ChromatogramChart/constants.js.map +1 -1
- package/dist/components/charts/ChromatogramChart/dataProcessing.cjs +1 -1
- package/dist/components/charts/ChromatogramChart/dataProcessing.cjs.map +1 -1
- package/dist/components/charts/ChromatogramChart/dataProcessing.js +38 -49
- package/dist/components/charts/ChromatogramChart/dataProcessing.js.map +1 -1
- package/dist/components/charts/DotPlot/DotPlot.cjs +1 -1
- package/dist/components/charts/DotPlot/DotPlot.cjs.map +1 -1
- package/dist/components/charts/DotPlot/DotPlot.js +57 -63
- package/dist/components/charts/DotPlot/DotPlot.js.map +1 -1
- package/dist/components/charts/Histogram/Histogram.cjs +1 -1
- package/dist/components/charts/Histogram/Histogram.cjs.map +1 -1
- package/dist/components/charts/Histogram/Histogram.js +98 -104
- package/dist/components/charts/Histogram/Histogram.js.map +1 -1
- package/dist/components/charts/LineGraph/LineGraph.cjs +1 -1
- package/dist/components/charts/LineGraph/LineGraph.cjs.map +1 -1
- package/dist/components/charts/LineGraph/LineGraph.js +97 -88
- package/dist/components/charts/LineGraph/LineGraph.js.map +1 -1
- package/dist/components/charts/PieChart/PieChart.cjs +1 -1
- package/dist/components/charts/PieChart/PieChart.cjs.map +1 -1
- package/dist/components/charts/PieChart/PieChart.js +65 -68
- package/dist/components/charts/PieChart/PieChart.js.map +1 -1
- package/dist/components/charts/PlateMap/PlateMap.cjs +1 -1
- package/dist/components/charts/PlateMap/PlateMap.cjs.map +1 -1
- package/dist/components/charts/PlateMap/PlateMap.js +271 -256
- package/dist/components/charts/PlateMap/PlateMap.js.map +1 -1
- package/dist/components/charts/PlateMap/constants.cjs +1 -1
- package/dist/components/charts/PlateMap/constants.cjs.map +1 -1
- package/dist/components/charts/PlateMap/constants.js +20 -29
- package/dist/components/charts/PlateMap/constants.js.map +1 -1
- package/dist/components/charts/ScatterGraph/ScatterGraph.cjs +1 -1
- package/dist/components/charts/ScatterGraph/ScatterGraph.cjs.map +1 -1
- package/dist/components/charts/ScatterGraph/ScatterGraph.js +113 -89
- package/dist/components/charts/ScatterGraph/ScatterGraph.js.map +1 -1
- package/dist/hooks/use-plotly-theme.cjs +1 -1
- package/dist/hooks/use-plotly-theme.cjs.map +1 -1
- package/dist/hooks/use-plotly-theme.js +4 -2
- package/dist/hooks/use-plotly-theme.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +156 -76
- package/dist/index.js +587 -581
- package/dist/index.js.map +1 -1
- package/dist/index.tailwind.css +1 -1
- package/dist/utils/colors.cjs +1 -1
- package/dist/utils/colors.cjs.map +1 -1
- package/dist/utils/colors.js +38 -93
- package/dist/utils/colors.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,52 +1,54 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { useRef as
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { jsxs as L, jsx as B } from "react/jsx-runtime";
|
|
2
|
+
import z from "plotly.js-dist";
|
|
3
|
+
import { useRef as P, useMemo as i, useEffect as U } from "react";
|
|
4
|
+
import { useChartTooltip as V } from "../ChartTooltip/ChartTooltip.js";
|
|
5
|
+
import { usePlotlyTheme as X } from "../../../hooks/use-plotly-theme.js";
|
|
6
|
+
import { seriesColor as Y } from "../../../utils/colors.js";
|
|
7
|
+
const F = ({
|
|
6
8
|
dataSeries: a,
|
|
7
|
-
width:
|
|
8
|
-
height:
|
|
9
|
-
xRange:
|
|
10
|
-
yRange:
|
|
11
|
-
variant:
|
|
12
|
-
xTitle:
|
|
13
|
-
yTitle:
|
|
14
|
-
title:
|
|
15
|
-
barWidth:
|
|
9
|
+
width: x = 1e3,
|
|
10
|
+
height: M = 600,
|
|
11
|
+
xRange: h,
|
|
12
|
+
yRange: s,
|
|
13
|
+
variant: p = "group",
|
|
14
|
+
xTitle: g = "Columns",
|
|
15
|
+
yTitle: d = "Rows",
|
|
16
|
+
title: k = "Bar Graph",
|
|
17
|
+
barWidth: w = 24
|
|
16
18
|
}) => {
|
|
17
|
-
const
|
|
19
|
+
const c = P(null), t = X(), { bindTooltip: b, tooltipElement: A } = V({ xLabel: g, yLabel: d }), { yMin: C, yMax: E } = i(() => {
|
|
18
20
|
let r = Number.MAX_VALUE, o = Number.MIN_VALUE, n = Number.MAX_VALUE, e = Number.MIN_VALUE;
|
|
19
21
|
a.forEach((N) => {
|
|
20
|
-
N.x.forEach((
|
|
21
|
-
r = Math.min(r,
|
|
22
|
-
}), N.y.forEach((
|
|
23
|
-
n = Math.min(n,
|
|
22
|
+
N.x.forEach((m) => {
|
|
23
|
+
r = Math.min(r, m), o = Math.max(o, m);
|
|
24
|
+
}), N.y.forEach((m) => {
|
|
25
|
+
n = Math.min(n, m), e = Math.max(e, m);
|
|
24
26
|
});
|
|
25
27
|
});
|
|
26
|
-
const l = (o - r) * 0.1,
|
|
28
|
+
const l = (o - r) * 0.1, u = (e - n) * 0.1;
|
|
27
29
|
return {
|
|
28
30
|
xMin: r - l,
|
|
29
31
|
xMax: o + l,
|
|
30
|
-
yMin:
|
|
31
|
-
yMax: e +
|
|
32
|
+
yMin: p === "stack" ? 0 : n - u,
|
|
33
|
+
yMax: e + u
|
|
32
34
|
};
|
|
33
|
-
}, [a,
|
|
34
|
-
() =>
|
|
35
|
-
[
|
|
36
|
-
),
|
|
35
|
+
}, [a, p]), f = i(
|
|
36
|
+
() => s || [C, E],
|
|
37
|
+
[s, C, E]
|
|
38
|
+
), I = i(
|
|
37
39
|
() => [...new Set(a.flatMap((r) => r.x))],
|
|
38
40
|
[a]
|
|
39
|
-
),
|
|
40
|
-
const r =
|
|
41
|
+
), _ = i(() => {
|
|
42
|
+
const r = f[1] - f[0];
|
|
41
43
|
let o = Math.pow(10, Math.floor(Math.log10(r)));
|
|
42
44
|
r / o > 10 && (o = o * 2), r / o < 4 && (o = o / 2);
|
|
43
45
|
const n = [];
|
|
44
|
-
let e = Math.ceil(
|
|
45
|
-
for (; e <=
|
|
46
|
+
let e = Math.ceil(f[0] / o) * o;
|
|
47
|
+
for (; e <= f[1]; )
|
|
46
48
|
n.push(e), e += o;
|
|
47
49
|
return n;
|
|
48
|
-
}, [
|
|
49
|
-
switch (
|
|
50
|
+
}, [f]), v = i(() => {
|
|
51
|
+
switch (p) {
|
|
50
52
|
case "stack":
|
|
51
53
|
return "stack";
|
|
52
54
|
case "overlay":
|
|
@@ -54,7 +56,7 @@ const Y = ({
|
|
|
54
56
|
default:
|
|
55
57
|
return "group";
|
|
56
58
|
}
|
|
57
|
-
}, [
|
|
59
|
+
}, [p]), y = i(
|
|
58
60
|
() => ({
|
|
59
61
|
tickcolor: t.tickColor,
|
|
60
62
|
ticklen: 12,
|
|
@@ -73,41 +75,42 @@ const Y = ({
|
|
|
73
75
|
}),
|
|
74
76
|
[t]
|
|
75
77
|
);
|
|
76
|
-
return
|
|
77
|
-
if (!
|
|
78
|
-
const r = a.map((l) => ({
|
|
78
|
+
return U(() => {
|
|
79
|
+
if (!c.current) return;
|
|
80
|
+
const r = a.map((l, u) => ({
|
|
79
81
|
x: l.x,
|
|
80
82
|
y: l.y,
|
|
81
83
|
type: "bar",
|
|
82
84
|
name: l.name,
|
|
85
|
+
hoverinfo: "none",
|
|
83
86
|
marker: {
|
|
84
|
-
color: l.color
|
|
87
|
+
color: Y(u, l.color)
|
|
85
88
|
},
|
|
86
|
-
width:
|
|
89
|
+
width: w,
|
|
87
90
|
error_y: l.error_y
|
|
88
91
|
})), o = {
|
|
89
92
|
title: {
|
|
90
|
-
text:
|
|
93
|
+
text: k,
|
|
91
94
|
font: {
|
|
92
95
|
size: 32,
|
|
93
96
|
family: "Inter, sans-serif",
|
|
94
97
|
color: t.textColor
|
|
95
98
|
}
|
|
96
99
|
},
|
|
97
|
-
width:
|
|
98
|
-
height:
|
|
100
|
+
width: x,
|
|
101
|
+
height: M,
|
|
99
102
|
margin: { l: 80, r: 30, b: 80, t: 60, pad: 0 },
|
|
100
103
|
paper_bgcolor: t.paperBg,
|
|
101
104
|
plot_bgcolor: t.plotBg,
|
|
102
105
|
font: {
|
|
103
106
|
family: "Inter, sans-serif"
|
|
104
107
|
},
|
|
105
|
-
barmode:
|
|
108
|
+
barmode: v,
|
|
106
109
|
bargap: 0.15,
|
|
107
110
|
dragmode: !1,
|
|
108
111
|
xaxis: {
|
|
109
112
|
title: {
|
|
110
|
-
text:
|
|
113
|
+
text: g,
|
|
111
114
|
font: {
|
|
112
115
|
size: 16,
|
|
113
116
|
color: t.textSecondary,
|
|
@@ -117,16 +120,16 @@ const Y = ({
|
|
|
117
120
|
standoff: 32
|
|
118
121
|
},
|
|
119
122
|
gridcolor: t.gridColor,
|
|
120
|
-
range:
|
|
121
|
-
autorange: !
|
|
123
|
+
range: h,
|
|
124
|
+
autorange: !h,
|
|
122
125
|
tickmode: "array",
|
|
123
|
-
tickvals:
|
|
126
|
+
tickvals: I,
|
|
124
127
|
showgrid: !0,
|
|
125
|
-
...
|
|
128
|
+
...y
|
|
126
129
|
},
|
|
127
130
|
yaxis: {
|
|
128
131
|
title: {
|
|
129
|
-
text:
|
|
132
|
+
text: d,
|
|
130
133
|
font: {
|
|
131
134
|
size: 16,
|
|
132
135
|
color: t.textSecondary,
|
|
@@ -136,12 +139,12 @@ const Y = ({
|
|
|
136
139
|
standoff: 30
|
|
137
140
|
},
|
|
138
141
|
gridcolor: t.gridColor,
|
|
139
|
-
range:
|
|
140
|
-
autorange: !
|
|
142
|
+
range: s,
|
|
143
|
+
autorange: !s,
|
|
141
144
|
tickmode: "array",
|
|
142
|
-
tickvals:
|
|
145
|
+
tickvals: _,
|
|
143
146
|
showgrid: !0,
|
|
144
|
-
...
|
|
147
|
+
...y
|
|
145
148
|
},
|
|
146
149
|
legend: {
|
|
147
150
|
x: 0.5,
|
|
@@ -162,14 +165,17 @@ const Y = ({
|
|
|
162
165
|
displayModeBar: !1,
|
|
163
166
|
displaylogo: !1
|
|
164
167
|
};
|
|
165
|
-
|
|
166
|
-
const e =
|
|
168
|
+
z.newPlot(c.current, r, o, n), b(c.current);
|
|
169
|
+
const e = c.current;
|
|
167
170
|
return () => {
|
|
168
|
-
e &&
|
|
171
|
+
e && z.purge(e);
|
|
169
172
|
};
|
|
170
|
-
}, [a,
|
|
173
|
+
}, [a, x, M, h, s, g, d, k, w, v, y, I, _, t, b]), /* @__PURE__ */ L("div", { className: "bar-graph-container relative", children: [
|
|
174
|
+
/* @__PURE__ */ B("div", { ref: c, style: { width: "100%", height: "100%" } }),
|
|
175
|
+
A
|
|
176
|
+
] });
|
|
171
177
|
};
|
|
172
178
|
export {
|
|
173
|
-
|
|
179
|
+
F as BarGraph
|
|
174
180
|
};
|
|
175
181
|
//# sourceMappingURL=BarGraph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarGraph.js","sources":["../../../../src/components/charts/BarGraph/BarGraph.tsx"],"sourcesContent":["import Plotly from \"plotly.js-dist\";\nimport React, { useEffect, useRef, useMemo } from \"react\";\n\nimport { usePlotlyTheme } from \"@/hooks/use-plotly-theme\";\n\ninterface BarDataSeries {\n x: number[];\n y: number[];\n name: string;\n color: string;\n error_y?: {\n type: \"data\";\n array: number[];\n visible: boolean;\n };\n}\n\ntype BarGraphVariant = \"group\" | \"stack\" | \"overlay\";\n\ninterface BarGraphProps {\n dataSeries: BarDataSeries[];\n width?: number;\n height?: number;\n xRange?: [number, number];\n yRange?: [number, number];\n variant?: BarGraphVariant;\n xTitle?: string;\n yTitle?: string;\n title?: string;\n barWidth?: number;\n}\n\nconst BarGraph: React.FC<BarGraphProps> = ({\n dataSeries,\n width = 1000,\n height = 600,\n xRange,\n yRange,\n variant = \"group\",\n xTitle = \"Columns\",\n yTitle = \"Rows\",\n title = \"Bar Graph\",\n barWidth = 24,\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n\n const { yMin, yMax } = useMemo(() => {\n let minX = Number.MAX_VALUE;\n let maxX = Number.MIN_VALUE;\n let minY = Number.MAX_VALUE;\n let maxY = Number.MIN_VALUE;\n\n dataSeries.forEach((series) => {\n series.x.forEach((x) => {\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n });\n series.y.forEach((y) => {\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n });\n });\n\n const xPadding = (maxX - minX) * 0.1;\n const yPadding = (maxY - minY) * 0.1;\n\n return {\n xMin: minX - xPadding,\n xMax: maxX + xPadding,\n yMin: variant === \"stack\" ? 0 : minY - yPadding,\n yMax: maxY + yPadding,\n };\n }, [dataSeries, variant]);\n\n const effectiveYRange = useMemo(\n () => yRange || [yMin, yMax],\n [yRange, yMin, yMax],\n );\n\n const xTicks = useMemo(\n () => [...new Set(dataSeries.flatMap((s) => s.x))],\n [dataSeries],\n );\n\n const yTicks = useMemo(() => {\n const range = effectiveYRange[1] - effectiveYRange[0];\n let step = Math.pow(10, Math.floor(Math.log10(range)));\n\n if (range / step > 10) step = step * 2;\n if (range / step < 4) step = step / 2;\n\n const ticks = [];\n let current = Math.ceil(effectiveYRange[0] / step) * step;\n while (current <= effectiveYRange[1]) {\n ticks.push(current);\n current += step;\n }\n return ticks;\n }, [effectiveYRange]);\n\n const barMode = useMemo((): \"group\" | \"stack\" | \"overlay\" => {\n switch (variant) {\n case \"stack\":\n return \"stack\";\n case \"overlay\":\n return \"overlay\";\n case \"group\":\n default:\n return \"group\";\n }\n }, [variant]);\n\n const tickOptions = useMemo(\n () => ({\n tickcolor: theme.tickColor,\n ticklen: 12,\n tickwidth: 1,\n ticks: \"outside\" as const,\n tickfont: {\n size: 16,\n color: theme.textColor,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n linecolor: theme.lineColor,\n linewidth: 1,\n position: 0,\n zeroline: false,\n }),\n [theme],\n );\n\n useEffect(() => {\n if (!plotRef.current) return;\n\n const data = dataSeries.map((series) => ({\n x: series.x,\n y: series.y,\n type: \"bar\" as const,\n name: series.name,\n marker: {\n color: series.color,\n },\n width: barWidth,\n error_y: series.error_y,\n }));\n\n const layout = {\n title: {\n text: title,\n font: {\n size: 32,\n family: \"Inter, sans-serif\",\n color: theme.textColor,\n },\n },\n width,\n height,\n margin: { l: 80, r: 30, b: 80, t: 60, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n barmode: barMode,\n bargap: 0.15,\n dragmode: false as const,\n xaxis: {\n title: {\n text: xTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 32,\n },\n gridcolor: theme.gridColor,\n range: xRange,\n autorange: !xRange,\n tickmode: \"array\" as const,\n tickvals: xTicks,\n showgrid: true,\n ...tickOptions,\n },\n yaxis: {\n title: {\n text: yTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 30,\n },\n gridcolor: theme.gridColor,\n range: yRange,\n autorange: !yRange,\n tickmode: \"array\" as const,\n tickvals: yTicks,\n showgrid: true,\n ...tickOptions,\n },\n legend: {\n x: 0.5,\n y: -0.2,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n orientation: \"h\" as const,\n font: {\n size: 16,\n color: theme.legendColor,\n family: \"Inter, sans-serif\",\n weight: 500,\n },\n },\n showlegend: dataSeries.length > 1,\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n };\n\n Plotly.newPlot(plotRef.current, data, layout, config);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n // Cleanup function\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [dataSeries, width, height, xRange, yRange, xTitle, yTitle, title, barWidth, barMode, tickOptions, xTicks, yTicks, theme]);\n\n return (\n <div className=\"bar-graph-container\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n </div>\n );\n};\n\nexport { BarGraph };\nexport type { BarDataSeries, BarGraphVariant, BarGraphProps };\n"],"names":["BarGraph","dataSeries","width","height","xRange","yRange","variant","xTitle","yTitle","title","barWidth","plotRef","useRef","theme","usePlotlyTheme","yMin","yMax","useMemo","minX","maxX","minY","maxY","series","x","y","xPadding","yPadding","effectiveYRange","xTicks","s","yTicks","range","step","ticks","current","barMode","tickOptions","useEffect","data","layout","config","Plotly","plotElement","jsx"],"mappings":";;;;AAgCA,MAAMA,IAAoC,CAAC;AAAA,EACzC,YAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,QAAAC,IAAS;AAAA,EACT,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,QAAAC,IAAS;AAAA,EACT,QAAAC,IAAS;AAAA,EACT,OAAAC,IAAQ;AAAA,EACR,UAAAC,IAAW;AACb,MAAM;AACJ,QAAMC,IAAUC,EAAuB,IAAI,GACrCC,IAAQC,EAAA,GAER,EAAE,MAAAC,GAAM,MAAAC,EAAA,IAASC,EAAQ,MAAM;AACnC,QAAIC,IAAO,OAAO,WACdC,IAAO,OAAO,WACdC,IAAO,OAAO,WACdC,IAAO,OAAO;AAElB,IAAApB,EAAW,QAAQ,CAACqB,MAAW;AAC7B,MAAAA,EAAO,EAAE,QAAQ,CAACC,MAAM;AACtB,QAAAL,IA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AAA,IAE5B;AAAA,EACF,GAAG,CAACzC,GAAYC,GAAOC,GAAQC,GAAQC,GAAQE,GAAQC,GAAQC,GAAOC,GAAUyB,GAASC,GAAaR,GAAQE,GAAQjB,CAAK,CAAC,GAG1H,gBAAA8B,EAAC,OAAA,EAAI,WAAU,uBACb,4BAAC,OAAA,EAAI,KAAKhC,GAAS,OAAO,EAAE,OAAO,QAAQ,QAAQ,OAAA,GAAU,GAC/D;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"BarGraph.js","sources":["../../../../src/components/charts/BarGraph/BarGraph.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 { seriesColor } from \"@/utils/colors\";\n\ninterface BarDataSeries {\n x: number[];\n y: number[];\n name: string;\n /** Optional color override (auto-assigned from CHART_COLORS if not provided) */\n color?: string;\n error_y?: {\n type: \"data\";\n array: number[];\n visible: boolean;\n };\n}\n\ntype BarGraphVariant = \"group\" | \"stack\" | \"overlay\";\n\ninterface BarGraphProps {\n dataSeries: BarDataSeries[];\n width?: number;\n height?: number;\n xRange?: [number, number];\n yRange?: [number, number];\n variant?: BarGraphVariant;\n xTitle?: string;\n yTitle?: string;\n title?: string;\n barWidth?: number;\n}\n\nconst BarGraph: React.FC<BarGraphProps> = ({\n dataSeries,\n width = 1000,\n height = 600,\n xRange,\n yRange,\n variant = \"group\",\n xTitle = \"Columns\",\n yTitle = \"Rows\",\n title = \"Bar Graph\",\n barWidth = 24,\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n const { bindTooltip, tooltipElement } = useChartTooltip({ xLabel: xTitle, yLabel: yTitle });\n\n const { yMin, yMax } = useMemo(() => {\n let minX = Number.MAX_VALUE;\n let maxX = Number.MIN_VALUE;\n let minY = Number.MAX_VALUE;\n let maxY = Number.MIN_VALUE;\n\n dataSeries.forEach((series) => {\n series.x.forEach((x) => {\n minX = Math.min(minX, x);\n maxX = Math.max(maxX, x);\n });\n series.y.forEach((y) => {\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n });\n });\n\n const xPadding = (maxX - minX) * 0.1;\n const yPadding = (maxY - minY) * 0.1;\n\n return {\n xMin: minX - xPadding,\n xMax: maxX + xPadding,\n yMin: variant === \"stack\" ? 0 : minY - yPadding,\n yMax: maxY + yPadding,\n };\n }, [dataSeries, variant]);\n\n const effectiveYRange = useMemo(\n () => yRange || [yMin, yMax],\n [yRange, yMin, yMax],\n );\n\n const xTicks = useMemo(\n () => [...new Set(dataSeries.flatMap((s) => s.x))],\n [dataSeries],\n );\n\n const yTicks = useMemo(() => {\n const range = effectiveYRange[1] - effectiveYRange[0];\n let step = Math.pow(10, Math.floor(Math.log10(range)));\n\n if (range / step > 10) step = step * 2;\n if (range / step < 4) step = step / 2;\n\n const ticks = [];\n let current = Math.ceil(effectiveYRange[0] / step) * step;\n while (current <= effectiveYRange[1]) {\n ticks.push(current);\n current += step;\n }\n return ticks;\n }, [effectiveYRange]);\n\n const barMode = useMemo((): \"group\" | \"stack\" | \"overlay\" => {\n switch (variant) {\n case \"stack\":\n return \"stack\";\n case \"overlay\":\n return \"overlay\";\n case \"group\":\n default:\n return \"group\";\n }\n }, [variant]);\n\n const tickOptions = useMemo(\n () => ({\n tickcolor: theme.tickColor,\n ticklen: 12,\n tickwidth: 1,\n ticks: \"outside\" as const,\n tickfont: {\n size: 16,\n color: theme.textColor,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n linecolor: theme.lineColor,\n linewidth: 1,\n position: 0,\n zeroline: false,\n }),\n [theme],\n );\n\n useEffect(() => {\n if (!plotRef.current) return;\n\n const data = dataSeries.map((series, index) => ({\n x: series.x,\n y: series.y,\n type: \"bar\" as const,\n name: series.name,\n hoverinfo: \"none\" as const,\n marker: {\n color: seriesColor(index, series.color),\n },\n width: barWidth,\n error_y: series.error_y,\n }));\n\n const layout = {\n title: {\n text: title,\n font: {\n size: 32,\n family: \"Inter, sans-serif\",\n color: theme.textColor,\n },\n },\n width,\n height,\n margin: { l: 80, r: 30, b: 80, t: 60, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n barmode: barMode,\n bargap: 0.15,\n dragmode: false as const,\n xaxis: {\n title: {\n text: xTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 32,\n },\n gridcolor: theme.gridColor,\n range: xRange,\n autorange: !xRange,\n tickmode: \"array\" as const,\n tickvals: xTicks,\n showgrid: true,\n ...tickOptions,\n },\n yaxis: {\n title: {\n text: yTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 30,\n },\n gridcolor: theme.gridColor,\n range: yRange,\n autorange: !yRange,\n tickmode: \"array\" as const,\n tickvals: yTicks,\n showgrid: true,\n ...tickOptions,\n },\n legend: {\n x: 0.5,\n y: -0.2,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n orientation: \"h\" as const,\n font: {\n size: 16,\n color: theme.legendColor,\n family: \"Inter, sans-serif\",\n weight: 500,\n },\n },\n showlegend: dataSeries.length > 1,\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n };\n\n Plotly.newPlot(plotRef.current, data, layout, config);\n bindTooltip(plotRef.current);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n // Cleanup function\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [dataSeries, width, height, xRange, yRange, xTitle, yTitle, title, barWidth, barMode, tickOptions, xTicks, yTicks, theme, bindTooltip]);\n\n return (\n <div className=\"bar-graph-container relative\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n {tooltipElement}\n </div>\n );\n};\n\nexport { BarGraph };\nexport type { BarDataSeries, BarGraphVariant, BarGraphProps };\n"],"names":["BarGraph","dataSeries","width","height","xRange","yRange","variant","xTitle","yTitle","title","barWidth","plotRef","useRef","theme","usePlotlyTheme","bindTooltip","tooltipElement","useChartTooltip","yMin","yMax","useMemo","minX","maxX","minY","maxY","series","x","y","xPadding","yPadding","effectiveYRange","xTicks","s","yTicks","range","step","ticks","current","barMode","tickOptions","useEffect","data","index","seriesColor","layout","config","Plotly","plotElement","jsxs","jsx"],"mappings":";;;;;;AAoCA,MAAMA,IAAoC,CAAC;AAAA,EACzC,YAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,QAAAC,IAAS;AAAA,EACT,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,QAAAC,IAAS;AAAA,EACT,QAAAC,IAAS;AAAA,EACT,OAAAC,IAAQ;AAAA,EACR,UAAAC,IAAW;AACb,MAAM;AACJ,QAAMC,IAAUC,EAAuB,IAAI,GACrCC,IAAQC,EAAA,GACR,EAAE,aAAAC,GAAa,gBAAAC,EAAA,IAAmBC,EAAgB,EAAE,QAAQV,GAAQ,QAAQC,GAAQ,GAEpF,EAAE,MAAAU,GAAM,MAAAC,EAAA,IAASC,EAAQ,MAAM;AACnC,QAAIC,IAAO,OAAO,WACdC,IAAO,OAAO,WACdC,IAAO,OAAO,WACdC,IAAO,OAAO;AAElB,IAAAvB,EAAW,QAAQ,CAACwB,MAAW;AAC7B,MAAAA,EAAO,EAAE,QAAQ,CAACC,MAAM;AACtB,QAAAL,IAAO,KAAK,IAAIA,GAAMK,CAAC,GACvBJ,IAAO,KAAK,IAAIA,GAAMI,CAAC;AAAA,MACzB,CAAC,GACDD,EAAO,EAAE,QAAQ,CAACE,MAAM;AACtB,QAAAJ,IAAO,KAAK,IAAIA,GAAMI,CAAC,GACvBH,IAAO,KAAK,IAAIA,GAAMG,CAAC;AAAA,MACzB,CAAC;AAAA,IACH,CAAC;AAED,UAAMC,KAAYN,IA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CACb,UAAA;AAAA,IAAA,gBAAAC,EAAC,OAAA,EAAI,KAAKtC,GAAS,OAAO,EAAE,OAAO,QAAQ,QAAQ,OAAA,EAAO,CAAG;AAAA,IAC5DK;AAAA,EAAA,GACH;AAEJ;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),E=require("plotly.js-dist"),s=require("react"),q=require("../ChartTooltip/ChartTooltip.cjs"),z=require("../../../hooks/use-plotly-theme.cjs"),B=require("../../../utils/colors.cjs"),N=-1.8,O=({dataSeries:u,width:d=1e3,height:y=600,xRange:p,yRange:a,xTitle:h="Columns",yTitle:m="Rows",title:x="Boxplot",showPoints:M=!1})=>{const f=s.useRef(null),t=z.usePlotlyTheme(),{bindTooltip:b,tooltipElement:P}=q.useChartTooltip({xLabel:h,yLabel:m}),{yMin:w,yMax:k}=s.useMemo(()=>{let e=Number.MAX_VALUE,o=Number.MIN_VALUE;u.forEach(n=>{n.y.forEach(r=>{e=Math.min(e,r),o=Math.max(o,r)})});const i=(o-e)*.1;return{yMin:e-i,yMax:o+i}},[u]),c=s.useMemo(()=>a||[w,k],[a,w,k]),C=s.useMemo(()=>{const e=c[1]-c[0];let o=Math.pow(10,Math.floor(Math.log10(e)));e/o>10&&(o=o*2),e/o<4&&(o=o/2);const i=[];let n=Math.ceil(c[0]/o)*o;for(;n<=c[1];)i.push(n),n+=o;return i},[c]),g=s.useMemo(()=>({tickcolor:t.tickColor,ticklen:12,tickwidth:1,ticks:"outside",tickfont:{size:16,color:t.textColor,family:"Inter, sans-serif",weight:400},linecolor:t.lineColor,linewidth:1,position:0,zeroline:!1}),[t]),I=s.useMemo(()=>({text:x,x:.5,y:.95,xanchor:"center",yanchor:"top",font:{size:32,weight:600,family:"Inter, sans-serif",color:t.textColor,lineheight:1.2,standoff:30}}),[x,t]);return s.useEffect(()=>{if(!f.current)return;const e=u.map((r,j)=>{const l=B.seriesColor(j,r.color);return{y:r.y,x:r.x,type:"box",name:r.name,hoverinfo:"none",marker:{color:l},line:{color:l},fillcolor:typeof l=="string"&&l.startsWith("#")&&l.length===7?`${l}40`:l,boxpoints:M?r.boxpoints||"outliers":!1,jitter:r.jitter||.3,pointpos:r.pointpos||N}}),o={width:d,height:y,title:I,margin:{l:80,r:40,b:80,t:80,pad:0},paper_bgcolor:t.paperBg,plot_bgcolor:t.plotBg,font:{family:"Inter, sans-serif"},dragmode:!1,xaxis:{title:{text:h,font:{size:16,color:t.textSecondary,family:"Inter, sans-serif",weight:400},standoff:15},gridcolor:t.gridColor,range:p,autorange:!p,showgrid:!0,...g},yaxis:{title:{text:m,font:{size:16,color:t.textSecondary,family:"Inter, sans-serif",weight:400},standoff:15},gridcolor:t.gridColor,range:a,autorange:!a,tickmode:"array",tickvals:C,showgrid:!0,...g},legend:{x:.5,y:-.2,xanchor:"center",yanchor:"top",orientation:"h",font:{size:13,color:t.legendColor,family:"Inter, sans-serif",weight:500,lineheight:18}},showlegend:!0},i={responsive:!0,displayModeBar:!1,displaylogo:!1};E.newPlot(f.current,e,o,i),b(f.current);const n=f.current;return()=>{n&&E.purge(n)}},[u,d,y,p,a,c,h,m,M,I,g,C,t,b]),v.jsxs("div",{className:"boxplot-container relative",children:[v.jsx("div",{ref:f,style:{width:"100%",height:"100%"}}),P]})};exports.Boxplot=O;
|
|
2
2
|
//# sourceMappingURL=Boxplot.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Boxplot.cjs","sources":["../../../../src/components/charts/Boxplot/Boxplot.tsx"],"sourcesContent":["import Plotly from \"plotly.js-dist\";\nimport React, { useEffect, useRef, useMemo } from \"react\";\n\nimport { usePlotlyTheme } from \"@/hooks/use-plotly-theme\";\n\n/** Default point position offset from the box edge */\nconst DEFAULT_POINT_POSITION = -1.8;\n\ninterface BoxDataSeries {\n y: number[];\n name: string;\n color: string;\n x?: string[] | number[];\n boxpoints?: \"all\" | \"outliers\" | \"suspectedoutliers\" | false;\n jitter?: number;\n pointpos?: number;\n}\n\ninterface BoxplotProps {\n dataSeries: BoxDataSeries[];\n width?: number;\n height?: number;\n xRange?: [number, number];\n yRange?: [number, number];\n xTitle?: string;\n yTitle?: string;\n title?: string;\n showPoints?: boolean;\n}\n\nconst Boxplot: React.FC<BoxplotProps> = ({\n dataSeries,\n width = 1000,\n height = 600,\n xRange,\n yRange,\n xTitle = \"Columns\",\n yTitle = \"Rows\",\n title = \"Boxplot\",\n showPoints = false,\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n\n const { yMin, yMax } = useMemo(() => {\n let minY = Number.MAX_VALUE;\n let maxY = Number.MIN_VALUE;\n\n dataSeries.forEach((series) => {\n series.y.forEach((y) => {\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n });\n });\n\n const yPadding = (maxY - minY) * 0.1;\n\n return {\n yMin: minY - yPadding,\n yMax: maxY + yPadding,\n };\n }, [dataSeries]);\n\n const effectiveYRange = useMemo(\n () => yRange || [yMin, yMax],\n [yRange, yMin, yMax],\n );\n\n const yTicks = useMemo(() => {\n const range = effectiveYRange[1] - effectiveYRange[0];\n let step = Math.pow(10, Math.floor(Math.log10(range)));\n\n if (range / step > 10) step = step * 2;\n if (range / step < 4) step = step / 2;\n\n const ticks = [];\n let current = Math.ceil(effectiveYRange[0] / step) * step;\n while (current <= effectiveYRange[1]) {\n ticks.push(current);\n current += step;\n }\n return ticks;\n }, [effectiveYRange]);\n\n const tickOptions = useMemo(\n () => ({\n tickcolor: theme.tickColor,\n ticklen: 12,\n tickwidth: 1,\n ticks: \"outside\" as const,\n tickfont: {\n size: 16,\n color: theme.textColor,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n linecolor: theme.lineColor,\n linewidth: 1,\n position: 0,\n zeroline: false,\n }),\n [theme],\n );\n\n const titleOptions = useMemo(\n () => ({\n text: title,\n x: 0.5,\n y: 0.95,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n font: {\n size: 32,\n weight: 600,\n family: \"Inter, sans-serif\",\n color: theme.textColor,\n lineheight: 1.2,\n standoff: 30,\n },\n }),\n [title, theme],\n );\n\n useEffect(() => {\n if (!plotRef.current) return;\n\n const data = dataSeries.map((series) => ({\n y: series.y,\n x: series.x,\n type: \"box\" as const,\n name: series.name,\n marker: {\n color: series.color,\n },\n line: {\n color: series.color,\n },\n fillcolor: series.color + \"40\", // Add transparency\n boxpoints: showPoints ? series.boxpoints || \"outliers\" : (false as const),\n jitter: series.jitter || 0.3,\n pointpos: series.pointpos || DEFAULT_POINT_POSITION,\n }));\n\n const layout = {\n width,\n height: height,\n title: titleOptions,\n margin: { l: 80, r: 40, b: 80, t: 80, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n dragmode: false as const,\n xaxis: {\n title: {\n text: xTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: xRange,\n autorange: !xRange,\n showgrid: true,\n ...tickOptions,\n },\n yaxis: {\n title: {\n text: yTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: yRange,\n autorange: !yRange,\n tickmode: \"array\" as const,\n tickvals: yTicks,\n showgrid: true,\n ...tickOptions,\n },\n legend: {\n x: 0.5,\n y: -0.2,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n orientation: \"h\" as const,\n font: {\n size: 13,\n color: theme.legendColor,\n family: \"Inter, sans-serif\",\n weight: 500,\n lineheight: 18,\n },\n },\n showlegend: true,\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n };\n\n Plotly.newPlot(plotRef.current, data, layout, config);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n // Cleanup function\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [dataSeries, width, height, xRange, yRange, effectiveYRange, xTitle, yTitle, showPoints, titleOptions, tickOptions, yTicks, theme]);\n\n return (\n <div className=\"boxplot-container\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n </div>\n );\n};\n\nexport { Boxplot };\nexport type { BoxDataSeries, BoxplotProps };\n"],"names":["DEFAULT_POINT_POSITION","Boxplot","dataSeries","width","height","xRange","yRange","xTitle","yTitle","title","showPoints","plotRef","useRef","theme","usePlotlyTheme","yMin","yMax","useMemo","minY","maxY","series","y","yPadding","effectiveYRange","yTicks","range","step","ticks","current","tickOptions","titleOptions","useEffect","data","layout","config","Plotly","plotElement","jsx"],"mappings":"qNAMMA,EAAyB,KAwBzBC,EAAkC,CAAC,CACvC,WAAAC,EACA,MAAAC,EAAQ,IACR,OAAAC,EAAS,IACT,OAAAC,EACA,OAAAC,EACA,OAAAC,EAAS,UACT,OAAAC,EAAS,OACT,MAAAC,EAAQ,UACR,WAAAC,EAAa,EACf,IAAM,CACJ,MAAMC,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAAQC,EAAAA,eAAA,EAER,CAAE,KAAAC,EAAM,KAAAC,CAAA,EAASC,EAAAA,QAAQ,IAAM,CACnC,IAAIC,EAAO,OAAO,UACdC,EAAO,OAAO,UAElBjB,EAAW,QAASkB,GAAW,CAC7BA,EAAO,EAAE,QAASC,GAAM,CACtBH,EAAO,KAAK,IAAIA,EAAMG,CAAC,EACvBF,EAAO,KAAK,IAAIA,EAAME,CAAC,CACzB,CAAC,CACH,CAAC,EAED,MAAMC,GAAYH,EAAOD,GAAQ,GAEjC,MAAO,CACL,KAAMA,EAAOI,EACb,KAAMH,EAAOG,CAAA,CAEjB,EAAG,CAACpB,CAAU,CAAC,EAETqB,EAAkBN,EAAAA,QACtB,IAAMX,GAAU,CA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B,EAAQC,EAAQE,EAAYoB,EAAcD,EAAaL,EAAQX,CAAK,CAAC,EAGnIwB,EAAAA,IAAC,MAAA,CAAI,UAAU,oBACb,eAAC,MAAA,CAAI,IAAK1B,EAAS,MAAO,CAAE,MAAO,OAAQ,OAAQ,MAAA,EAAU,EAC/D,CAEJ"}
|
|
1
|
+
{"version":3,"file":"Boxplot.cjs","sources":["../../../../src/components/charts/Boxplot/Boxplot.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 { seriesColor } from \"@/utils/colors\";\n\n/** Default point position offset from the box edge */\nconst DEFAULT_POINT_POSITION = -1.8;\n\ninterface BoxDataSeries {\n y: number[];\n name: string;\n /** Optional color override (auto-assigned from CHART_COLORS if not provided) */\n color?: string;\n x?: string[] | number[];\n boxpoints?: \"all\" | \"outliers\" | \"suspectedoutliers\" | false;\n jitter?: number;\n pointpos?: number;\n}\n\ninterface BoxplotProps {\n dataSeries: BoxDataSeries[];\n width?: number;\n height?: number;\n xRange?: [number, number];\n yRange?: [number, number];\n xTitle?: string;\n yTitle?: string;\n title?: string;\n showPoints?: boolean;\n}\n\nconst Boxplot: React.FC<BoxplotProps> = ({\n dataSeries,\n width = 1000,\n height = 600,\n xRange,\n yRange,\n xTitle = \"Columns\",\n yTitle = \"Rows\",\n title = \"Boxplot\",\n showPoints = false,\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n const { bindTooltip, tooltipElement } = useChartTooltip({ xLabel: xTitle, yLabel: yTitle });\n\n const { yMin, yMax } = useMemo(() => {\n let minY = Number.MAX_VALUE;\n let maxY = Number.MIN_VALUE;\n\n dataSeries.forEach((series) => {\n series.y.forEach((y) => {\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n });\n });\n\n const yPadding = (maxY - minY) * 0.1;\n\n return {\n yMin: minY - yPadding,\n yMax: maxY + yPadding,\n };\n }, [dataSeries]);\n\n const effectiveYRange = useMemo(\n () => yRange || [yMin, yMax],\n [yRange, yMin, yMax],\n );\n\n const yTicks = useMemo(() => {\n const range = effectiveYRange[1] - effectiveYRange[0];\n let step = Math.pow(10, Math.floor(Math.log10(range)));\n\n if (range / step > 10) step = step * 2;\n if (range / step < 4) step = step / 2;\n\n const ticks = [];\n let current = Math.ceil(effectiveYRange[0] / step) * step;\n while (current <= effectiveYRange[1]) {\n ticks.push(current);\n current += step;\n }\n return ticks;\n }, [effectiveYRange]);\n\n const tickOptions = useMemo(\n () => ({\n tickcolor: theme.tickColor,\n ticklen: 12,\n tickwidth: 1,\n ticks: \"outside\" as const,\n tickfont: {\n size: 16,\n color: theme.textColor,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n linecolor: theme.lineColor,\n linewidth: 1,\n position: 0,\n zeroline: false,\n }),\n [theme],\n );\n\n const titleOptions = useMemo(\n () => ({\n text: title,\n x: 0.5,\n y: 0.95,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n font: {\n size: 32,\n weight: 600,\n family: \"Inter, sans-serif\",\n color: theme.textColor,\n lineheight: 1.2,\n standoff: 30,\n },\n }),\n [title, theme],\n );\n\n useEffect(() => {\n if (!plotRef.current) return;\n\n const data = dataSeries.map((series, index) => {\n const color = seriesColor(index, series.color);\n return {\n y: series.y,\n x: series.x,\n type: \"box\" as const,\n name: series.name,\n hoverinfo: \"none\" as const,\n marker: {\n color,\n },\n line: {\n color,\n },\n fillcolor:\n typeof color === \"string\" && color.startsWith(\"#\") && color.length === 7\n ? `${color}40`\n : color, // Add transparency for hex colors only\n boxpoints: showPoints\n ? series.boxpoints || \"outliers\"\n : (false as const),\n jitter: series.jitter || 0.3,\n pointpos: series.pointpos || DEFAULT_POINT_POSITION,\n };\n });\n\n const layout = {\n width,\n height: height,\n title: titleOptions,\n margin: { l: 80, r: 40, b: 80, t: 80, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n dragmode: false as const,\n xaxis: {\n title: {\n text: xTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: xRange,\n autorange: !xRange,\n showgrid: true,\n ...tickOptions,\n },\n yaxis: {\n title: {\n text: yTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: yRange,\n autorange: !yRange,\n tickmode: \"array\" as const,\n tickvals: yTicks,\n showgrid: true,\n ...tickOptions,\n },\n legend: {\n x: 0.5,\n y: -0.2,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n orientation: \"h\" as const,\n font: {\n size: 13,\n color: theme.legendColor,\n family: \"Inter, sans-serif\",\n weight: 500,\n lineheight: 18,\n },\n },\n showlegend: true,\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n };\n\n Plotly.newPlot(plotRef.current, data, layout, config);\n bindTooltip(plotRef.current);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n // Cleanup function\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [dataSeries, width, height, xRange, yRange, effectiveYRange, xTitle, yTitle, showPoints, titleOptions, tickOptions, yTicks, theme, bindTooltip]);\n\n return (\n <div className=\"boxplot-container relative\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n {tooltipElement}\n </div>\n );\n};\n\nexport { Boxplot };\nexport type { BoxDataSeries, BoxplotProps };\n"],"names":["DEFAULT_POINT_POSITION","Boxplot","dataSeries","width","height","xRange","yRange","xTitle","yTitle","title","showPoints","plotRef","useRef","theme","usePlotlyTheme","bindTooltip","tooltipElement","useChartTooltip","yMin","yMax","useMemo","minY","maxY","series","y","yPadding","effectiveYRange","yTicks","range","step","ticks","current","tickOptions","titleOptions","useEffect","data","index","color","seriesColor","layout","config","Plotly","plotElement","jsxs","jsx"],"mappings":"0SASMA,EAAyB,KAyBzBC,EAAkC,CAAC,CACvC,WAAAC,EACA,MAAAC,EAAQ,IACR,OAAAC,EAAS,IACT,OAAAC,EACA,OAAAC,EACA,OAAAC,EAAS,UACT,OAAAC,EAAS,OACT,MAAAC,EAAQ,UACR,WAAAC,EAAa,EACf,IAAM,CACJ,MAAMC,EAAUC,EAAAA,OAAuB,IAAI,EACrCC,EAAQC,EAAAA,eAAA,EACR,CAAE,YAAAC,EAAa,eAAAC,CAAA,EAAmBC,EAAAA,gBAAgB,CAAE,OAAQV,EAAQ,OAAQC,EAAQ,EAEpF,CAAE,KAAAU,EAAM,KAAAC,CAAA,EAASC,EAAAA,QAAQ,IAAM,CACnC,IAAIC,EAAO,OAAO,UACdC,EAAO,OAAO,UAElBpB,EAAW,QAASqB,GAAW,CAC7BA,EAAO,EAAE,QAASC,GAAM,CACtBH,EAAO,KAAK,IAAIA,EAAMG,CAAC,EACvBF,EAAO,KAAK,IAAIA,EAAME,CAAC,CACzB,CAAC,CACH,CAAC,EAED,MAAMC,GAAYH,EAAOD,GAAQ,GAEjC,MAAO,CACL,KAAMA,EAAOI,EACb,KAAMH,EAAOG,CAAA,CAEjB,EAAG,CAACvB,CAAU,CAAC,EAETwB,EAAkBN,EAAAA,QACtB,IAAMd,GAAU,CAACY,EAAMC,CAAI,EAC3B,CAACb,EAAQY,EAAMC,CAAI,CAAA,EAGfQ,EAASP,EAAAA,QAAQ,IAAM,CAC3B,MAAMQ,EAAQF,EAAgB,CAAC,EAAIA,EAAgB,CAAC,EACpD,IAAIG,EAAO,KAAK,IAAI,GAAI,KAAK,MAAM,KAAK,MAAMD,CAAK,CAAC,CAAC,EAEjDA,EAAQC,EAAO,KAAIA,EAAOA,EAAO,GACjCD,EAAQC,EAAO,IAAGA,EAAOA,EAAO,GAEpC,MAAMC,EAAQ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AAKjC,EAAS,MAAO,CAAE,MAAO,OAAQ,OAAQ,MAAA,CAAO,CAAG,EAC5DK,CAAA,EACH,CAEJ"}
|
|
@@ -1,43 +1,45 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { useRef as
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { jsxs as N, jsx as _ } from "react/jsx-runtime";
|
|
2
|
+
import E from "plotly.js-dist";
|
|
3
|
+
import { useRef as B, useMemo as f, useEffect as L } from "react";
|
|
4
|
+
import { useChartTooltip as O } from "../ChartTooltip/ChartTooltip.js";
|
|
5
|
+
import { usePlotlyTheme as P } from "../../../hooks/use-plotly-theme.js";
|
|
6
|
+
import { seriesColor as j } from "../../../utils/colors.js";
|
|
7
|
+
const A = -1.8, W = ({
|
|
8
|
+
dataSeries: p,
|
|
9
|
+
width: d = 1e3,
|
|
10
|
+
height: x = 600,
|
|
11
|
+
xRange: m,
|
|
12
|
+
yRange: a,
|
|
13
|
+
xTitle: h = "Columns",
|
|
14
|
+
yTitle: u = "Rows",
|
|
15
|
+
title: y = "Boxplot",
|
|
16
|
+
showPoints: M = !1
|
|
15
17
|
}) => {
|
|
16
|
-
const
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
n.y.forEach((
|
|
20
|
-
|
|
18
|
+
const c = B(null), t = P(), { bindTooltip: w, tooltipElement: v } = O({ xLabel: h, yLabel: u }), { yMin: b, yMax: k } = f(() => {
|
|
19
|
+
let e = Number.MAX_VALUE, o = Number.MIN_VALUE;
|
|
20
|
+
p.forEach((n) => {
|
|
21
|
+
n.y.forEach((r) => {
|
|
22
|
+
e = Math.min(e, r), o = Math.max(o, r);
|
|
21
23
|
});
|
|
22
24
|
});
|
|
23
|
-
const
|
|
25
|
+
const i = (o - e) * 0.1;
|
|
24
26
|
return {
|
|
25
|
-
yMin:
|
|
26
|
-
yMax: o +
|
|
27
|
+
yMin: e - i,
|
|
28
|
+
yMax: o + i
|
|
27
29
|
};
|
|
28
|
-
}, [
|
|
29
|
-
() =>
|
|
30
|
-
[
|
|
31
|
-
),
|
|
32
|
-
const
|
|
33
|
-
let o = Math.pow(10, Math.floor(Math.log10(
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
let n = Math.ceil(
|
|
37
|
-
for (; n <=
|
|
38
|
-
|
|
39
|
-
return
|
|
40
|
-
}, [
|
|
30
|
+
}, [p]), s = f(
|
|
31
|
+
() => a || [b, k],
|
|
32
|
+
[a, b, k]
|
|
33
|
+
), C = f(() => {
|
|
34
|
+
const e = s[1] - s[0];
|
|
35
|
+
let o = Math.pow(10, Math.floor(Math.log10(e)));
|
|
36
|
+
e / o > 10 && (o = o * 2), e / o < 4 && (o = o / 2);
|
|
37
|
+
const i = [];
|
|
38
|
+
let n = Math.ceil(s[0] / o) * o;
|
|
39
|
+
for (; n <= s[1]; )
|
|
40
|
+
i.push(n), n += o;
|
|
41
|
+
return i;
|
|
42
|
+
}, [s]), g = f(
|
|
41
43
|
() => ({
|
|
42
44
|
tickcolor: t.tickColor,
|
|
43
45
|
ticklen: 12,
|
|
@@ -55,9 +57,9 @@ const _ = -1.8, A = ({
|
|
|
55
57
|
zeroline: !1
|
|
56
58
|
}),
|
|
57
59
|
[t]
|
|
58
|
-
), I =
|
|
60
|
+
), I = f(
|
|
59
61
|
() => ({
|
|
60
|
-
text:
|
|
62
|
+
text: y,
|
|
61
63
|
x: 0.5,
|
|
62
64
|
y: 0.95,
|
|
63
65
|
xanchor: "center",
|
|
@@ -71,29 +73,33 @@ const _ = -1.8, A = ({
|
|
|
71
73
|
standoff: 30
|
|
72
74
|
}
|
|
73
75
|
}),
|
|
74
|
-
[
|
|
76
|
+
[y, t]
|
|
75
77
|
);
|
|
76
|
-
return
|
|
77
|
-
if (!
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
return L(() => {
|
|
79
|
+
if (!c.current) return;
|
|
80
|
+
const e = p.map((r, z) => {
|
|
81
|
+
const l = j(z, r.color);
|
|
82
|
+
return {
|
|
83
|
+
y: r.y,
|
|
84
|
+
x: r.x,
|
|
85
|
+
type: "box",
|
|
86
|
+
name: r.name,
|
|
87
|
+
hoverinfo: "none",
|
|
88
|
+
marker: {
|
|
89
|
+
color: l
|
|
90
|
+
},
|
|
91
|
+
line: {
|
|
92
|
+
color: l
|
|
93
|
+
},
|
|
94
|
+
fillcolor: typeof l == "string" && l.startsWith("#") && l.length === 7 ? `${l}40` : l,
|
|
95
|
+
// Add transparency for hex colors only
|
|
96
|
+
boxpoints: M ? r.boxpoints || "outliers" : !1,
|
|
97
|
+
jitter: r.jitter || 0.3,
|
|
98
|
+
pointpos: r.pointpos || A
|
|
99
|
+
};
|
|
100
|
+
}), o = {
|
|
101
|
+
width: d,
|
|
102
|
+
height: x,
|
|
97
103
|
title: I,
|
|
98
104
|
margin: { l: 80, r: 40, b: 80, t: 80, pad: 0 },
|
|
99
105
|
paper_bgcolor: t.paperBg,
|
|
@@ -104,7 +110,7 @@ const _ = -1.8, A = ({
|
|
|
104
110
|
dragmode: !1,
|
|
105
111
|
xaxis: {
|
|
106
112
|
title: {
|
|
107
|
-
text:
|
|
113
|
+
text: h,
|
|
108
114
|
font: {
|
|
109
115
|
size: 16,
|
|
110
116
|
color: t.textSecondary,
|
|
@@ -114,14 +120,14 @@ const _ = -1.8, A = ({
|
|
|
114
120
|
standoff: 15
|
|
115
121
|
},
|
|
116
122
|
gridcolor: t.gridColor,
|
|
117
|
-
range:
|
|
118
|
-
autorange: !
|
|
123
|
+
range: m,
|
|
124
|
+
autorange: !m,
|
|
119
125
|
showgrid: !0,
|
|
120
|
-
...
|
|
126
|
+
...g
|
|
121
127
|
},
|
|
122
128
|
yaxis: {
|
|
123
129
|
title: {
|
|
124
|
-
text:
|
|
130
|
+
text: u,
|
|
125
131
|
font: {
|
|
126
132
|
size: 16,
|
|
127
133
|
color: t.textSecondary,
|
|
@@ -131,12 +137,12 @@ const _ = -1.8, A = ({
|
|
|
131
137
|
standoff: 15
|
|
132
138
|
},
|
|
133
139
|
gridcolor: t.gridColor,
|
|
134
|
-
range:
|
|
135
|
-
autorange: !
|
|
140
|
+
range: a,
|
|
141
|
+
autorange: !a,
|
|
136
142
|
tickmode: "array",
|
|
137
|
-
tickvals:
|
|
143
|
+
tickvals: C,
|
|
138
144
|
showgrid: !0,
|
|
139
|
-
...
|
|
145
|
+
...g
|
|
140
146
|
},
|
|
141
147
|
legend: {
|
|
142
148
|
x: 0.5,
|
|
@@ -153,19 +159,22 @@ const _ = -1.8, A = ({
|
|
|
153
159
|
}
|
|
154
160
|
},
|
|
155
161
|
showlegend: !0
|
|
156
|
-
},
|
|
162
|
+
}, i = {
|
|
157
163
|
responsive: !0,
|
|
158
164
|
displayModeBar: !1,
|
|
159
165
|
displaylogo: !1
|
|
160
166
|
};
|
|
161
|
-
|
|
162
|
-
const n =
|
|
167
|
+
E.newPlot(c.current, e, o, i), w(c.current);
|
|
168
|
+
const n = c.current;
|
|
163
169
|
return () => {
|
|
164
|
-
n &&
|
|
170
|
+
n && E.purge(n);
|
|
165
171
|
};
|
|
166
|
-
}, [
|
|
172
|
+
}, [p, d, x, m, a, s, h, u, M, I, g, C, t, w]), /* @__PURE__ */ N("div", { className: "boxplot-container relative", children: [
|
|
173
|
+
/* @__PURE__ */ _("div", { ref: c, style: { width: "100%", height: "100%" } }),
|
|
174
|
+
v
|
|
175
|
+
] });
|
|
167
176
|
};
|
|
168
177
|
export {
|
|
169
|
-
|
|
178
|
+
W as Boxplot
|
|
170
179
|
};
|
|
171
180
|
//# sourceMappingURL=Boxplot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Boxplot.js","sources":["../../../../src/components/charts/Boxplot/Boxplot.tsx"],"sourcesContent":["import Plotly from \"plotly.js-dist\";\nimport React, { useEffect, useRef, useMemo } from \"react\";\n\nimport { usePlotlyTheme } from \"@/hooks/use-plotly-theme\";\n\n/** Default point position offset from the box edge */\nconst DEFAULT_POINT_POSITION = -1.8;\n\ninterface BoxDataSeries {\n y: number[];\n name: string;\n color: string;\n x?: string[] | number[];\n boxpoints?: \"all\" | \"outliers\" | \"suspectedoutliers\" | false;\n jitter?: number;\n pointpos?: number;\n}\n\ninterface BoxplotProps {\n dataSeries: BoxDataSeries[];\n width?: number;\n height?: number;\n xRange?: [number, number];\n yRange?: [number, number];\n xTitle?: string;\n yTitle?: string;\n title?: string;\n showPoints?: boolean;\n}\n\nconst Boxplot: React.FC<BoxplotProps> = ({\n dataSeries,\n width = 1000,\n height = 600,\n xRange,\n yRange,\n xTitle = \"Columns\",\n yTitle = \"Rows\",\n title = \"Boxplot\",\n showPoints = false,\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n\n const { yMin, yMax } = useMemo(() => {\n let minY = Number.MAX_VALUE;\n let maxY = Number.MIN_VALUE;\n\n dataSeries.forEach((series) => {\n series.y.forEach((y) => {\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n });\n });\n\n const yPadding = (maxY - minY) * 0.1;\n\n return {\n yMin: minY - yPadding,\n yMax: maxY + yPadding,\n };\n }, [dataSeries]);\n\n const effectiveYRange = useMemo(\n () => yRange || [yMin, yMax],\n [yRange, yMin, yMax],\n );\n\n const yTicks = useMemo(() => {\n const range = effectiveYRange[1] - effectiveYRange[0];\n let step = Math.pow(10, Math.floor(Math.log10(range)));\n\n if (range / step > 10) step = step * 2;\n if (range / step < 4) step = step / 2;\n\n const ticks = [];\n let current = Math.ceil(effectiveYRange[0] / step) * step;\n while (current <= effectiveYRange[1]) {\n ticks.push(current);\n current += step;\n }\n return ticks;\n }, [effectiveYRange]);\n\n const tickOptions = useMemo(\n () => ({\n tickcolor: theme.tickColor,\n ticklen: 12,\n tickwidth: 1,\n ticks: \"outside\" as const,\n tickfont: {\n size: 16,\n color: theme.textColor,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n linecolor: theme.lineColor,\n linewidth: 1,\n position: 0,\n zeroline: false,\n }),\n [theme],\n );\n\n const titleOptions = useMemo(\n () => ({\n text: title,\n x: 0.5,\n y: 0.95,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n font: {\n size: 32,\n weight: 600,\n family: \"Inter, sans-serif\",\n color: theme.textColor,\n lineheight: 1.2,\n standoff: 30,\n },\n }),\n [title, theme],\n );\n\n useEffect(() => {\n if (!plotRef.current) return;\n\n const data = dataSeries.map((series) => ({\n y: series.y,\n x: series.x,\n type: \"box\" as const,\n name: series.name,\n marker: {\n color: series.color,\n },\n line: {\n color: series.color,\n },\n fillcolor: series.color + \"40\", // Add transparency\n boxpoints: showPoints ? series.boxpoints || \"outliers\" : (false as const),\n jitter: series.jitter || 0.3,\n pointpos: series.pointpos || DEFAULT_POINT_POSITION,\n }));\n\n const layout = {\n width,\n height: height,\n title: titleOptions,\n margin: { l: 80, r: 40, b: 80, t: 80, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n dragmode: false as const,\n xaxis: {\n title: {\n text: xTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: xRange,\n autorange: !xRange,\n showgrid: true,\n ...tickOptions,\n },\n yaxis: {\n title: {\n text: yTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: yRange,\n autorange: !yRange,\n tickmode: \"array\" as const,\n tickvals: yTicks,\n showgrid: true,\n ...tickOptions,\n },\n legend: {\n x: 0.5,\n y: -0.2,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n orientation: \"h\" as const,\n font: {\n size: 13,\n color: theme.legendColor,\n family: \"Inter, sans-serif\",\n weight: 500,\n lineheight: 18,\n },\n },\n showlegend: true,\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n };\n\n Plotly.newPlot(plotRef.current, data, layout, config);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n // Cleanup function\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [dataSeries, width, height, xRange, yRange, effectiveYRange, xTitle, yTitle, showPoints, titleOptions, tickOptions, yTicks, theme]);\n\n return (\n <div className=\"boxplot-container\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n </div>\n );\n};\n\nexport { Boxplot };\nexport type { BoxDataSeries, BoxplotProps };\n"],"names":["DEFAULT_POINT_POSITION","Boxplot","dataSeries","width","height","xRange","yRange","xTitle","yTitle","title","showPoints","plotRef","useRef","theme","usePlotlyTheme","yMin","yMax","useMemo","minY","maxY","series","y","yPadding","effectiveYRange","yTicks","range","step","ticks","current","tickOptions","titleOptions","useEffect","data","layout","config","Plotly","plotElement","jsx"],"mappings":";;;;AAMA,MAAMA,IAAyB,MAwBzBC,IAAkC,CAAC;AAAA,EACvC,YAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,QAAAC,IAAS;AAAA,EACT,QAAAC;AAAA,EACA,QAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,QAAAC,IAAS;AAAA,EACT,OAAAC,IAAQ;AAAA,EACR,YAAAC,IAAa;AACf,MAAM;AACJ,QAAMC,IAAUC,EAAuB,IAAI,GACrCC,IAAQC,EAAA,GAER,EAAE,MAAAC,GAAM,MAAAC,EAAA,IAASC,EAAQ,MAAM;AACn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AAwB,EAAC,OAAA,EAAI,WAAU,qBACb,4BAAC,OAAA,EAAI,KAAK1B,GAAS,OAAO,EAAE,OAAO,QAAQ,QAAQ,OAAA,GAAU,GAC/D;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"Boxplot.js","sources":["../../../../src/components/charts/Boxplot/Boxplot.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 { seriesColor } from \"@/utils/colors\";\n\n/** Default point position offset from the box edge */\nconst DEFAULT_POINT_POSITION = -1.8;\n\ninterface BoxDataSeries {\n y: number[];\n name: string;\n /** Optional color override (auto-assigned from CHART_COLORS if not provided) */\n color?: string;\n x?: string[] | number[];\n boxpoints?: \"all\" | \"outliers\" | \"suspectedoutliers\" | false;\n jitter?: number;\n pointpos?: number;\n}\n\ninterface BoxplotProps {\n dataSeries: BoxDataSeries[];\n width?: number;\n height?: number;\n xRange?: [number, number];\n yRange?: [number, number];\n xTitle?: string;\n yTitle?: string;\n title?: string;\n showPoints?: boolean;\n}\n\nconst Boxplot: React.FC<BoxplotProps> = ({\n dataSeries,\n width = 1000,\n height = 600,\n xRange,\n yRange,\n xTitle = \"Columns\",\n yTitle = \"Rows\",\n title = \"Boxplot\",\n showPoints = false,\n}) => {\n const plotRef = useRef<HTMLDivElement>(null);\n const theme = usePlotlyTheme();\n const { bindTooltip, tooltipElement } = useChartTooltip({ xLabel: xTitle, yLabel: yTitle });\n\n const { yMin, yMax } = useMemo(() => {\n let minY = Number.MAX_VALUE;\n let maxY = Number.MIN_VALUE;\n\n dataSeries.forEach((series) => {\n series.y.forEach((y) => {\n minY = Math.min(minY, y);\n maxY = Math.max(maxY, y);\n });\n });\n\n const yPadding = (maxY - minY) * 0.1;\n\n return {\n yMin: minY - yPadding,\n yMax: maxY + yPadding,\n };\n }, [dataSeries]);\n\n const effectiveYRange = useMemo(\n () => yRange || [yMin, yMax],\n [yRange, yMin, yMax],\n );\n\n const yTicks = useMemo(() => {\n const range = effectiveYRange[1] - effectiveYRange[0];\n let step = Math.pow(10, Math.floor(Math.log10(range)));\n\n if (range / step > 10) step = step * 2;\n if (range / step < 4) step = step / 2;\n\n const ticks = [];\n let current = Math.ceil(effectiveYRange[0] / step) * step;\n while (current <= effectiveYRange[1]) {\n ticks.push(current);\n current += step;\n }\n return ticks;\n }, [effectiveYRange]);\n\n const tickOptions = useMemo(\n () => ({\n tickcolor: theme.tickColor,\n ticklen: 12,\n tickwidth: 1,\n ticks: \"outside\" as const,\n tickfont: {\n size: 16,\n color: theme.textColor,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n linecolor: theme.lineColor,\n linewidth: 1,\n position: 0,\n zeroline: false,\n }),\n [theme],\n );\n\n const titleOptions = useMemo(\n () => ({\n text: title,\n x: 0.5,\n y: 0.95,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n font: {\n size: 32,\n weight: 600,\n family: \"Inter, sans-serif\",\n color: theme.textColor,\n lineheight: 1.2,\n standoff: 30,\n },\n }),\n [title, theme],\n );\n\n useEffect(() => {\n if (!plotRef.current) return;\n\n const data = dataSeries.map((series, index) => {\n const color = seriesColor(index, series.color);\n return {\n y: series.y,\n x: series.x,\n type: \"box\" as const,\n name: series.name,\n hoverinfo: \"none\" as const,\n marker: {\n color,\n },\n line: {\n color,\n },\n fillcolor:\n typeof color === \"string\" && color.startsWith(\"#\") && color.length === 7\n ? `${color}40`\n : color, // Add transparency for hex colors only\n boxpoints: showPoints\n ? series.boxpoints || \"outliers\"\n : (false as const),\n jitter: series.jitter || 0.3,\n pointpos: series.pointpos || DEFAULT_POINT_POSITION,\n };\n });\n\n const layout = {\n width,\n height: height,\n title: titleOptions,\n margin: { l: 80, r: 40, b: 80, t: 80, pad: 0 },\n paper_bgcolor: theme.paperBg,\n plot_bgcolor: theme.plotBg,\n font: {\n family: \"Inter, sans-serif\",\n },\n dragmode: false as const,\n xaxis: {\n title: {\n text: xTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: xRange,\n autorange: !xRange,\n showgrid: true,\n ...tickOptions,\n },\n yaxis: {\n title: {\n text: yTitle,\n font: {\n size: 16,\n color: theme.textSecondary,\n family: \"Inter, sans-serif\",\n weight: 400,\n },\n standoff: 15,\n },\n gridcolor: theme.gridColor,\n range: yRange,\n autorange: !yRange,\n tickmode: \"array\" as const,\n tickvals: yTicks,\n showgrid: true,\n ...tickOptions,\n },\n legend: {\n x: 0.5,\n y: -0.2,\n xanchor: \"center\" as const,\n yanchor: \"top\" as const,\n orientation: \"h\" as const,\n font: {\n size: 13,\n color: theme.legendColor,\n family: \"Inter, sans-serif\",\n weight: 500,\n lineheight: 18,\n },\n },\n showlegend: true,\n };\n\n const config = {\n responsive: true,\n displayModeBar: false,\n displaylogo: false,\n };\n\n Plotly.newPlot(plotRef.current, data, layout, config);\n bindTooltip(plotRef.current);\n\n // Capture ref value for cleanup\n const plotElement = plotRef.current;\n\n // Cleanup function\n return () => {\n if (plotElement) {\n Plotly.purge(plotElement);\n }\n };\n }, [dataSeries, width, height, xRange, yRange, effectiveYRange, xTitle, yTitle, showPoints, titleOptions, tickOptions, yTicks, theme, bindTooltip]);\n\n return (\n <div className=\"boxplot-container relative\">\n <div ref={plotRef} style={{ width: \"100%\", height: \"100%\" }} />\n {tooltipElement}\n </div>\n );\n};\n\nexport { Boxplot };\nexport type { BoxDataSeries, BoxplotProps };\n"],"names":["DEFAULT_POINT_POSITION","Boxplot","dataSeries","width","height","xRange","yRange","xTitle","yTitle","title","showPoints","plotRef","useRef","theme","usePlotlyTheme","bindTooltip","tooltipElement","useChartTooltip","yMin","yMax","useMemo","minY","maxY","series","y","yPadding","effectiveYRange","yTicks","range","step","ticks","current","tickOptions","titleOptions","useEffect","data","index","color","seriesColor","layout","config","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QAAQ;AAAA,QACN,GAAG;AAAA,QACH,GAAG;AAAA,QACH,SAAS;AAAA,QACT,SAAS;AAAA,QACT,aAAa;AAAA,QACb,MAAM;AAAA,UACJ,MAAM;AAAA,UACN,OAAOnB,EAAM;AAAA,UACb,QAAQ;AAAA,UACR,QAAQ;AAAA,UACR,YAAY;AAAA,QAAA;AAAA,MACd;AAAA,MAEF,YAAY;AAAA,IAAA,GAGR2B,IAAS;AAAA,MACb,YAAY;AAAA,MACZ,gBAAgB;AAAA,MAChB,aAAa;AAAA,IAAA;AAGf,IAAAC,EAAO,QAAQ9B,EAAQ,SAASwB,GAAMI,GAAQC,CAAM,GACpDzB,EAAYJ,EAAQ,OAAO;AAG3B,UAAM+B,IAAc/B,EAAQ;AAG5B,WAAO,MAAM;AACX,MAAI+B,KACFD,EAAO,MAAMC,CAAW;AAAA,IAE5B;AAAA,EACF,GAAG,CAACxC,GAAYC,GAAOC,GAAQC,GAAQC,GAAQoB,GAAiBnB,GAAQC,GAAQE,GAAYuB,GAAcD,GAAaL,GAAQd,GAAOE,CAAW,CAAC,GAGhJ,gBAAA4B,EAAC,OAAA,EAAI,WAAU,8BACb,UAAA;AAAA,IAAA,gBAAAC,EAAC,OAAA,EAAI,KAAKjC,GAAS,OAAO,EAAE,OAAO,QAAQ,QAAQ,OAAA,EAAO,CAAG;AAAA,IAC5DK;AAAA,EAAA,GACH;AAEJ;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("react/jsx-runtime"),j=require("plotly.js-dist"),u=require("react"),O=require("react-dom"),A=require("./lines.cjs"),L=require("../../../lib/utils.cjs"),X=20,q=150,H=200,y=8,W=10,I={top:"bottom",bottom:"top",left:"right",right:"left"},z={top:{wrapper:"-translate-x-1/2 -translate-y-[calc(100%+10px)]",arrow:"-bottom-1 left-1/2 -translate-x-1/2"},bottom:{wrapper:"-translate-x-1/2 translate-y-[10px]",arrow:"-top-1 left-1/2 -translate-x-1/2"},left:{wrapper:"-translate-y-1/2 -translate-x-[calc(100%+10px)]",arrow:"-right-1 top-1/2 -translate-y-1/2"},right:{wrapper:"-translate-y-1/2 translate-x-[10px]",arrow:"-left-1 top-1/2 -translate-y-1/2"}},k=(t,o,n,r)=>{const e=y,s=W,i={top:o.top-s-r>=e,bottom:o.top+s+r<=window.innerHeight-e,left:o.left-s-n>=e,right:o.left+s+n<=window.innerWidth-e};return!i[t]&&i[I[t]]?I[t]:t};function N({anchor:t,bubbleRef:o}){const n=u.useRef(null),r=t?.side??"top",[e,s]=u.useState(r),i=u.useCallback(l=>{n.current=l,typeof o=="function"?o(l):o&&(o.current=l)},[o]);if(u.useLayoutEffect(()=>{const l=n.current;if(!t||!l)return;const c=k(r,t,l.offsetWidth,l.offsetHeight);s(x=>x===c?x:c)},[t,r]),!t)return null;const p=z[e];return O.createPortal(m.jsx("div",{"data-slot":"chart-tooltip-anchor",className:"pointer-events-none fixed z-50",style:{left:t.left,top:t.top},children:m.jsx("div",{ref:i,className:L.cn("w-max",p.wrapper),children:m.jsxs("div",{role:"tooltip","data-slot":"tooltip-content","data-side":e,className:L.cn("relative w-fit max-w-xs rounded-md bg-foreground px-3 py-1.5 text-xs text-background",t.closing?"animate-out fade-out zoom-out-95 fill-mode-forwards":"animate-in fade-in-0 zoom-in-95"),children:[t.lines.map((l,c)=>m.jsx("div",{children:l},`${c}-${l}`)),m.jsx("span",{"aria-hidden":!0,className:L.cn("absolute size-2.5 rotate-45 rounded-[2px] bg-foreground",p.arrow)})]})})}),document.body)}const G=(t,o,n,r)=>{const e=n/2,s=Math.min(Math.max(t,e+y),window.innerWidth-e-y),i=Math.min(Math.max(o,r+10+y),window.innerHeight-y);return{left:s,top:i}};function Y(t={}){const[o,n]=u.useState(null),r=u.useRef(void 0),e=u.useRef(t);e.current=t;const s=u.useRef(null),i=u.useRef(null),p=u.useRef(null);return{bindTooltip:u.useCallback(c=>{if(!c)return;p.current?.(),p.current=null,n(null),i.current=null,j.relayout(c,{hoverdistance:e.current.hoverDistance??X});const x=c,M=(a,f,w)=>{const T=s.current,{left:v,top:R}=G(f,w,T?.offsetWidth??0,T?.offsetHeight??0);n({left:v,top:R,lines:a,side:e.current.side})};x.on("plotly_hover",a=>{const f=a.points??[],{getLines:w,xLabel:T,yLabel:v,followCursor:R}=e.current,g=w?w(f):A.chartTooltipLines(f,{xLabel:T,yLabel:v});if(g.length===0)return;clearTimeout(r.current);const h=a.event;if(R){i.current=g,M(g,h?.clientX??0,h?.clientY??0);return}const b=f[0],d=b?.bbox;let E=0,S=0;if(d){const C=c.getBoundingClientRect();E=C.left+(d.x0+d.x1)/2;const _=b?.yaxis;d.y0===d.y1&&typeof b?.y=="number"&&typeof _?.l2p=="function"&&typeof _._offset=="number"?S=C.top+_._offset+_.l2p(b.y):S=C.top+Math.min(d.y0,d.y1)}else h&&(E=h.clientX,S=h.clientY);n({left:E,top:S,lines:g,side:e.current.side})});const P=a=>{if(!e.current.followCursor)return;const f=i.current;f&&M(f,a.clientX,a.clientY)};c.addEventListener("mousemove",P),p.current=()=>c.removeEventListener("mousemove",P),x.on("plotly_unhover",()=>{clearTimeout(r.current),i.current=null,r.current=setTimeout(()=>{n(a=>a&&{...a,closing:!0}),r.current=setTimeout(()=>n(null),H)},q)})},[]),tooltipElement:m.jsx(N,{anchor:o,bubbleRef:s})}}exports.chartTooltipLines=A.chartTooltipLines;exports.ChartTooltip=N;exports.useChartTooltip=Y;
|
|
2
|
+
//# sourceMappingURL=ChartTooltip.cjs.map
|