Skip to content

Commit 087e175

Browse files
committed
matrix d3
1 parent 9a4974b commit 087e175

8 files changed

Lines changed: 1628 additions & 51 deletions

File tree

package-lock.json

Lines changed: 749 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
"@headlessui/tailwindcss": "^0.2.2",
1616
"@heroicons/react": "^2.2.0",
1717
"@tailwindcss/forms": "^0.5.10",
18+
"@types/d3": "^7.4.3",
1819
"@types/plotly.js": "^3.0.0",
1920
"@types/plotly.js-dist-min": "^2.3.4",
21+
"d3": "^7.9.0",
2022
"lucide-react": "^0.515.0",
23+
"ml-regression-simple-linear": "^3.0.1",
2124
"next": "15.3.3",
2225
"plotly.js": "^3.0.1",
2326
"plotly.js-dist-min": "^3.0.1",

src/app/matrix/page.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
'use client';
22

33
import { useEffect, useState } from "react";
4-
import MatrixPlot from "@/components/MatrixPlot";
54
import { usePlotSettings } from '@/context/PlotSettingsContext';
65
import { update_df, getEpoch } from '@/utils/matrixUtils';
6+
import D3MatrixPlot from '@/components/D3MatrixPlot';
77

88
const MatrixPage = () => {
99
const {
1010
dataType,
1111
dataSelection,
1212
labelFontSize,
1313
plotType,
14-
noOfDataPoint
14+
noOfDataPoint,
15+
setSettings
1516
} = usePlotSettings();
1617
const epochs = [...new Set(dataSelection.map(sel => getEpoch(sel)))];
1718
const isValid = dataSelection.length >= 2 && epochs.length === 1;
@@ -32,6 +33,7 @@ const MatrixPage = () => {
3233
.then(([swData, lwData]) => {
3334
setSwMatrix(swData);
3435
setLwMatrix(lwData);
36+
setSettings({ focusRangeMax: 100, focusRangeMaxManuallySet: false });
3537
setError(false);
3638
})
3739
.catch((err) => {
@@ -43,7 +45,7 @@ const MatrixPage = () => {
4345

4446
return (
4547
<div className="p-4">
46-
<h1 className="text-xl font-bold mb-4 text-black">Matrix Scatter Plots</h1>
48+
<h1 className="text-xl font-bold mb-4 text-black">Scatter Matrix of Different Frames</h1>
4749

4850
{!isValid ? (
4951
<p className="text-red-500">Please select at least two items from the same epoch to generate a matrix plot.</p>
@@ -52,16 +54,23 @@ const MatrixPage = () => {
5254
) : error || !swMatrix || !lwMatrix ? (
5355
<p className="text-red-500">Failed to load matrix data.</p>
5456
) : (
55-
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
56-
<MatrixPlot
57+
<div className={`grid gap-6 ${dataSelection.length > 5 ? 'grid-rows-2 grid-cols-1' : 'grid-cols-1 lg:grid-cols-2'}`}>
58+
{/* <MatrixPlot */}
59+
<D3MatrixPlot
5760
matrixData={swMatrix}
5861
labelFontSize={labelFontSize}
5962
title="SW Scatter Matrix"
63+
// subtitle={`Source Brightness measured with BG annulus at each frame (e.g., SW.<i>r<sub>in</sub></i>.<i>r<sub>out</sub></i> → SW.10.30)`}
64+
subtitle="sw"
6065
/>
61-
<MatrixPlot
66+
67+
{/* <MatrixPlot */}
68+
<D3MatrixPlot
6269
matrixData={lwMatrix}
6370
labelFontSize={labelFontSize}
6471
title="LW Scatter Matrix"
72+
// subtitle={`Source Brightness measured with BG annulus at each frame (e.g., LW.<i>r<sub>in</sub></i>.<i>r<sub>out</sub></i> → LW.10.30)`}
73+
subtitle="lw"
6574
/>
6675
</div>
6776
)}

src/app/matrix_plotly/page.tsx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'use client';
2+
3+
import { useEffect, useState } from "react";
4+
import MatrixPlot from "@/components/MatrixPlot";
5+
import { usePlotSettings } from '@/context/PlotSettingsContext';
6+
import { update_df, getEpoch } from '@/utils/matrixUtils';
7+
8+
const MatrixPage = () => {
9+
const {
10+
dataType,
11+
dataSelection,
12+
labelFontSize,
13+
plotType,
14+
noOfDataPoint,
15+
setSettings
16+
} = usePlotSettings();
17+
const epochs = [...new Set(dataSelection.map(sel => getEpoch(sel)))];
18+
const isValid = dataSelection.length >= 2 && epochs.length === 1;
19+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
20+
const [swMatrix, setSwMatrix] = useState<any[] | null>(null);
21+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22+
const [lwMatrix, setLwMatrix] = useState<any[] | null>(null);
23+
const [loading, setLoading] = useState(false);
24+
const [error, setError] = useState(false);
25+
const baseHeight = 600;
26+
const extraPerDimension = 120; // adjust as needed
27+
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
const calcPlotHeight = (matrixData: any[]) => {
30+
const dimCount = matrixData.length > 0 ? Object.keys(matrixData[0]).length : 2;
31+
return dataSelection.length > 5
32+
? baseHeight + (dimCount - 2) * extraPerDimension
33+
: baseHeight;
34+
};
35+
useEffect(() => {
36+
if (!isValid) return;
37+
setLoading(true);
38+
Promise.all([
39+
update_df('SW', dataType as 'average' | 'raw', dataSelection, noOfDataPoint),
40+
update_df('LW', dataType as 'average' | 'raw', dataSelection, noOfDataPoint)
41+
])
42+
.then(([swData, lwData]) => {
43+
setSwMatrix(swData);
44+
setLwMatrix(lwData);
45+
setSettings({ focusRangeMax: 100, focusRangeMaxManuallySet: false });
46+
setError(false);
47+
})
48+
.catch((err) => {
49+
console.error("Matrix loading error", err);
50+
setError(true);
51+
})
52+
.finally(() => setLoading(false));
53+
}, [dataSelection, dataType, plotType, noOfDataPoint, noOfDataPoint]);
54+
55+
return (
56+
<div className="p-4">
57+
<h1 className="text-xl font-bold mb-4 text-black">Scatter Matrix of Different Frames</h1>
58+
59+
{!isValid ? (
60+
<p className="text-red-500">Please select at least two items from the same epoch to generate a matrix plot.</p>
61+
) : loading ? (
62+
<p>Loading matrix...</p>
63+
) : error || !swMatrix || !lwMatrix ? (
64+
<p className="text-red-500">Failed to load matrix data.</p>
65+
) : (
66+
<div className={`grid gap-6 ${dataSelection.length > 5 ? 'grid-rows-2 grid-cols-1' : 'grid-cols-1 lg:grid-cols-2'}`}>
67+
<MatrixPlot
68+
// <D3MatrixPlot
69+
matrixData={swMatrix}
70+
labelFontSize={labelFontSize}
71+
title="SW Scatter Matrix"
72+
subtitle={`Source Brightness measured with BG annulus at each frame (e.g., SW.<i>r<sub>in</sub></i>.<i>r<sub>out</sub></i> → SW.10.30)`}
73+
// subtitle="sw"
74+
height={calcPlotHeight(swMatrix)}
75+
/>
76+
77+
<MatrixPlot
78+
// <D3MatrixPlot
79+
matrixData={lwMatrix}
80+
labelFontSize={labelFontSize}
81+
title="LW Scatter Matrix"
82+
subtitle={`Source Brightness measured with BG annulus at each frame (e.g., LW.<i>r<sub>in</sub></i>.<i>r<sub>out</sub></i> → LW.10.30)`}
83+
// subtitle="lw"
84+
height={calcPlotHeight(lwMatrix)}
85+
/>
86+
</div>
87+
)}
88+
</div>
89+
);
90+
};
91+
92+
export default MatrixPage;

0 commit comments

Comments
 (0)