Pushpak21 commited on
Commit
59b0d5e
·
verified ·
1 Parent(s): b88d840

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- const res = await fetch("/parsed_data.json");
24
- const payload = await res.json();
25
- allTraces = [];
26
- normalTraces = [];
27
 
28
- for (const [color, label, data] of payload.files) {
29
- extractTraces(data, color, label);
30
- }
31
 
32
- Plotly.newPlot('plot', [...allTraces, ...normalTraces.filter(t => t.visible)], {
33
- margin: { t: 30 },
34
- scene: { aspectmode: 'data' },
35
- title: '3D Assembly Viewer'
36
- });
37
- }
38
 
39
- function extractTraces(data, baseColor, normalColor) {
40
- for (const [tag, g] of Object.entries(data.geometry)) {
41
- const [x, y, z] = g.base_point;
42
- const [nx, ny, nz] = g.normal;
 
 
 
 
43
 
44
- allTraces.push({
45
- type: 'scatter3d',
46
- mode: 'markers+text',
47
- x: [x], y: [y], z: [z],
48
- marker: { color: baseColor, size: 5 },
49
- text: [g.label || tag],
50
- textposition: 'top center'
51
- });
 
52
 
53
- normalTraces.push({
54
- type: 'scatter3d',
55
- mode: 'lines',
56
- x: [x, x + nx],
57
- y: [y, y + ny],
58
- z: [z, z + nz],
59
- line: { color: normalColor, width: 2 },
60
- visible: true
61
- });
62
- }
63
-
64
- for (const c of data.constraints) {
65
- const g1 = data.geometry[c.from];
66
- const g2 = data.geometry[c.to];
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