Working generator

This commit is contained in:
2026-01-29 20:32:33 +01:00
parent 0c76ae7928
commit 2f6a12a934
+46 -16
View File
@@ -31,22 +31,26 @@ export default function Home() {
const Plotly = await import("plotly.js-dist-min"); const Plotly = await import("plotly.js-dist-min");
if (cancelled) return; if (cancelled) return;
const xVals = rows.map((r) => Number(r[x]));
const yVals = rows.map((r) => Number(r[y]));
const zVals = rows.map((r) => Number(r[z]));
const trace = { const trace = {
type: "scatter3d", type: "scatter3d" as const,
mode: "markers", mode: "markers" as const,
x: rows.map(r => r[x]), x: xVals,
y: rows.map(r => r[y]), y: yVals,
z: rows.map(r => r[z]), z: zVals,
marker: { marker: {
size: 4, size: 4,
color: rows.map(r => r[z]), color: zVals,
colorscale: "Viridis", colorscale: "Viridis" as const,
}, },
}; };
Plotly.newPlot( Plotly.newPlot(
plotRef.current!, plotRef.current!,
[trace as any], [trace],
{ {
paper_bgcolor: "#0b0d12", paper_bgcolor: "#0b0d12",
plot_bgcolor: "#0b0d12", plot_bgcolor: "#0b0d12",
@@ -74,9 +78,29 @@ export default function Home() {
dynamicTyping: true, dynamicTyping: true,
skipEmptyLines: true, skipEmptyLines: true,
complete: (res) => { complete: (res) => {
const data = res.data as Row[]; const data = (res.data as Row[]).filter(
(row) => row && Object.keys(row).length > 0
);
if (!data.length) {
setRows([]);
setColumns([]);
setX("");
setY("");
setZ("");
return;
}
const cols = Object.keys(data[0]);
setRows(data); setRows(data);
setColumns(Object.keys(data[0])); setColumns(cols);
if (cols.length >= 3) {
setX(cols[0]);
setY(cols[1]);
setZ(cols[2]);
} else {
setX("");
setY("");
setZ("");
}
}, },
}); });
} }
@@ -126,8 +150,10 @@ export default function Home() {
onChange={(e) => setX(e.target.value)} onChange={(e) => setX(e.target.value)}
> >
<option value="">—</option> <option value="">—</option>
{columns.map(c => ( {columns.map((c) => (
<option key={c}>{c}</option> <option key={c} value={c}>
{c}
</option>
))} ))}
</select> </select>
</Control> </Control>
@@ -139,8 +165,10 @@ export default function Home() {
onChange={(e) => setY(e.target.value)} onChange={(e) => setY(e.target.value)}
> >
<option value="">—</option> <option value="">—</option>
{columns.map(c => ( {columns.map((c) => (
<option key={c}>{c}</option> <option key={c} value={c}>
{c}
</option>
))} ))}
</select> </select>
</Control> </Control>
@@ -152,8 +180,10 @@ export default function Home() {
onChange={(e) => setZ(e.target.value)} onChange={(e) => setZ(e.target.value)}
> >
<option value="">—</option> <option value="">—</option>
{columns.map(c => ( {columns.map((c) => (
<option key={c}>{c}</option> <option key={c} value={c}>
{c}
</option>
))} ))}
</select> </select>
</Control> </Control>