Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +49 -52
index.html
CHANGED
|
@@ -12,68 +12,65 @@
|
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<h1>DCM Assembly Visualizer</h1>
|
| 15 |
-
<p>This visualizer is now intended to be used with a Streamlit frontend for file upload.</p>
|
| 16 |
<div id="plot"></div>
|
| 17 |
|
| 18 |
<script>
|
| 19 |
-
let allTraces = [];
|
| 20 |
-
let normalTraces = [];
|
| 21 |
-
|
| 22 |
async function drawFromServer() {
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
|
| 29 |
-
extractTraces(data, color, label);
|
| 30 |
-
}
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
});
|
| 37 |
-
}
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
if (g1 && g2) {
|
| 68 |
-
const [x1, y1, z1] = g1.base_point;
|
| 69 |
-
const [x2, y2, z2] = g2.base_point;
|
| 70 |
-
allTraces.push({
|
| 71 |
-
type: 'scatter3d',
|
| 72 |
-
mode: 'lines',
|
| 73 |
-
x: [x1, x2], y: [y1, y2], z: [z1, z2],
|
| 74 |
-
line: { color: 'green', dash: 'dot', width: 2 }
|
| 75 |
-
});
|
| 76 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
|
|
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<h1>DCM Assembly Visualizer</h1>
|
|
|
|
| 15 |
<div id="plot"></div>
|
| 16 |
|
| 17 |
<script>
|
|
|
|
|
|
|
|
|
|
| 18 |
async function drawFromServer() {
|
| 19 |
+
try {
|
| 20 |
+
const res = await fetch("/parsed_data.json");
|
| 21 |
+
const payload = await res.json();
|
| 22 |
+
console.log("Loaded data:", payload);
|
| 23 |
|
| 24 |
+
let allTraces = [];
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
for (const [color, normalColor, data] of payload.files) {
|
| 27 |
+
for (const [tag, g] of Object.entries(data.geometry)) {
|
| 28 |
+
const [x, y, z] = g.base_point;
|
| 29 |
+
const [nx, ny, nz] = g.normal;
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
allTraces.push({
|
| 32 |
+
type: 'scatter3d',
|
| 33 |
+
mode: 'markers+text',
|
| 34 |
+
x: [x], y: [y], z: [z],
|
| 35 |
+
marker: { color: color, size: 5 },
|
| 36 |
+
text: [g.label || tag],
|
| 37 |
+
textposition: 'top center'
|
| 38 |
+
});
|
| 39 |
|
| 40 |
+
allTraces.push({
|
| 41 |
+
type: 'scatter3d',
|
| 42 |
+
mode: 'lines',
|
| 43 |
+
x: [x, x + nx],
|
| 44 |
+
y: [y, y + ny],
|
| 45 |
+
z: [z, z + nz],
|
| 46 |
+
line: { color: normalColor, width: 2 }
|
| 47 |
+
});
|
| 48 |
+
}
|
| 49 |
|
| 50 |
+
for (const c of data.constraints) {
|
| 51 |
+
const g1 = data.geometry[c.from];
|
| 52 |
+
const g2 = data.geometry[c.to];
|
| 53 |
+
if (g1 && g2) {
|
| 54 |
+
const [x1, y1, z1] = g1.base_point;
|
| 55 |
+
const [x2, y2, z2] = g2.base_point;
|
| 56 |
+
allTraces.push({
|
| 57 |
+
type: 'scatter3d',
|
| 58 |
+
mode: 'lines',
|
| 59 |
+
x: [x1, x2], y: [y1, y2], z: [z1, z2],
|
| 60 |
+
line: { color: 'green', dash: 'dot', width: 2 }
|
| 61 |
+
});
|
| 62 |
+
}
|
| 63 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
}
|
| 65 |
+
|
| 66 |
+
Plotly.newPlot('plot', allTraces, {
|
| 67 |
+
margin: { t: 30 },
|
| 68 |
+
scene: { aspectmode: 'data' },
|
| 69 |
+
title: '3D Assembly Viewer'
|
| 70 |
+
});
|
| 71 |
+
} catch (e) {
|
| 72 |
+
console.error("Failed to load or draw", e);
|
| 73 |
+
document.getElementById("plot").innerText = "Failed to load data or draw. Check console.";
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|