diff --git a/app/routes/home.tsx b/app/routes/home.tsx
index b80b83d..2ce3571 100644
--- a/app/routes/home.tsx
+++ b/app/routes/home.tsx
@@ -31,22 +31,26 @@ export default function Home() {
const Plotly = await import("plotly.js-dist-min");
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 = {
- type: "scatter3d",
- mode: "markers",
- x: rows.map(r => r[x]),
- y: rows.map(r => r[y]),
- z: rows.map(r => r[z]),
+ type: "scatter3d" as const,
+ mode: "markers" as const,
+ x: xVals,
+ y: yVals,
+ z: zVals,
marker: {
size: 4,
- color: rows.map(r => r[z]),
- colorscale: "Viridis",
+ color: zVals,
+ colorscale: "Viridis" as const,
},
};
Plotly.newPlot(
plotRef.current!,
- [trace as any],
+ [trace],
{
paper_bgcolor: "#0b0d12",
plot_bgcolor: "#0b0d12",
@@ -74,9 +78,29 @@ export default function Home() {
dynamicTyping: true,
skipEmptyLines: true,
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);
- 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)}
>
- {columns.map(c => (
-
+ {columns.map((c) => (
+
))}
@@ -139,8 +165,10 @@ export default function Home() {
onChange={(e) => setY(e.target.value)}
>
- {columns.map(c => (
-
+ {columns.map((c) => (
+
))}
@@ -152,8 +180,10 @@ export default function Home() {
onChange={(e) => setZ(e.target.value)}
>
- {columns.map(c => (
-
+ {columns.map((c) => (
+
))}