Alef1986 commited on
Commit
7ba2705
·
1 Parent(s): 40194dd

Refactor: Isolate URMSM view from DOM, fix renderers, and decouple LPG/RDF visualization

Browse files
ARCHITECTURE.md CHANGED
@@ -30,7 +30,7 @@ This is a **Buildless Vue 3** application using native ES6 modules.
30
  All `smim/` adapters must return an object in this format to decouple ontologies from renderers:
31
  \`\`\`javascript
32
  {
33
- nodes: [ { id: "part_1_state_2", label: "Part 1 [T2..]", type: "State", data: { isActive: true } } ],
34
- edges: [ { id: "e1", from: "parent_state", to: "child_state", label: "hasPart", type: "composition", data: {} } ]
35
  }
36
  \`\`\`
 
30
  All `smim/` adapters must return an object in this format to decouple ontologies from renderers:
31
  \`\`\`javascript
32
  {
33
+ nodes: [ { id: "st_Part_1_e1", label: "Part_1_State", type: "State", properties: { isCurrent: true } } ],
34
+ edges: [ { id: "e1", from: "st_System_A_e1", to: "st_Part_1_e1", label: "hasPart", type: "composition", properties: { validFrom: 0, validTo: null, isCurrent: true } } ]
35
  }
36
  \`\`\`
js/app.js CHANGED
@@ -14,57 +14,42 @@ import * as bfoAdapter from './smim/bfo.js';
14
  import * as isoAdapter from './smim/iso15926.js';
15
  import { initVisNetwork, updateVisNetwork } from './renderers/vis-adapter.js';
16
  import { updateMermaidNetwork } from './renderers/mermaid-adapter.js';
17
- import { generateBomHtml } from './urmsm/bom-view.js';
18
  import { generateLpgStorage, generateLpgQuery } from './sms/lpg-generator.js';
19
  import { generateRdfStorage, generateRdfQuery } from './sms/rdf-generator.js';
20
 
21
  /**
22
- * Renders an array of LPG relationship storage records as an HTML table.
23
- * Applies 'active-row' and 'closed-row' classes for temporal highlighting.
24
- *
25
- * @param {Array<Object>} rows - Array of LPG relationship records.
26
- * @returns {string} HTML table string.
27
  */
28
- function renderLpgTable(rows) {
29
- if (!rows || rows.length === 0) {
30
- return '<div style="color: #94a3b8; padding: 8px;">No relationship records</div>';
31
- }
32
-
33
- let html = '<table><thead><tr>';
34
- html += '<th>Source</th><th>Target</th><th>Type</th><th>Properties</th><th>Status</th>';
35
- html += '</tr></thead><tbody>';
36
-
37
- rows.forEach(row => {
38
- const rowClass = row.isActive ? 'active-row' : 'closed-row';
39
- const statusText = row.isActive ? 'Active' : 'Closed';
40
-
41
- // Format relationship properties excluding the internal isCurrent flag
42
- const propEntries = Object.entries(row.properties || {})
43
- .filter(([key]) => key !== 'isCurrent');
44
-
45
- let propHtml = '—';
46
- if (propEntries.length > 0) {
47
- const formattedProps = propEntries.map(([k, v]) => {
48
- const valStr = v === null ? 'null' : (typeof v === 'number' ? `T${v}` : `'${v}'`);
49
- return `${k}: ${valStr}`;
50
- }).join(', ');
51
- propHtml = `<code>{ ${formattedProps} }</code>`;
52
  }
53
-
54
- html += `<tr class="${rowClass}">`;
55
- html += `<td>${row.from}</td>`;
56
- html += `<td><strong>${row.to}</strong></td>`;
57
- html += `<td><code>:${row.label}</code></td>`;
58
- html += `<td>${propHtml}</td>`;
59
- html += `<td>${statusText}</td>`;
60
- html += '</tr>';
61
- });
62
-
63
- html += '</tbody></table>';
64
- return html;
65
- }
 
66
 
67
  const App = {
 
 
 
68
  setup() {
69
  // 1. Local UI Settings (Isolated from domain state)
70
  const settings = reactive({
@@ -189,19 +174,33 @@ const App = {
189
  });
190
 
191
  // Derived Views for the Sidebar (URMSM & SMS)
192
- const bomHtml = computed(() => generateBomHtml('System_A', activeEdges.value));
193
 
194
- const storageHtml = computed(() => {
195
  if (settings.storage === 'LPG') {
196
- const records = generateLpgStorage(semanticGraph.value);
197
- return renderLpgTable(records);
198
- } else {
199
- const ttl = generateRdfStorage(semanticGraph.value);
200
- return `<pre class="code-block">${ttl}</pre>`;
201
  }
 
202
  });
203
 
204
- const queryHtml = computed(() => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  if (settings.storage === 'LPG') {
206
  return generateLpgQuery(semanticGraph.value, state.currentTime);
207
  } else {
@@ -216,7 +215,7 @@ const App = {
216
 
217
  function renderGraph() {
218
  if (settings.engine === 'vis') {
219
- const isComplex = settings.ontology === 'ISO15926' || settings.storage === 'RDF';
220
  updateVisNetwork(semanticGraph.value, isComplex);
221
  } else if (mermaidContainer.value) {
222
  updateMermaidNetwork(semanticGraph.value, mermaidContainer.value);
@@ -313,7 +312,7 @@ const App = {
313
  handleAdd, handleRemove,
314
  partNameInput, selectedParent, selectedEdgeToRemove, showHistory,
315
  activeNodes, activeEdges,
316
- bomHtml, storageHtml, queryHtml,
317
  visContainer, mermaidContainer,
318
  startResizeH, startResizeV
319
  };
@@ -412,7 +411,14 @@ const App = {
412
  <span>{{ t.titleBom }}</span>
413
  <span class="iec-badge align-right">IEC 63339 / URMSM<span class="iec-tooltip" v-html="t.tooltips.urmsm"></span></span>
414
  </h4>
415
- <div id="tree-container" style="overflow-y: auto;" v-html="bomHtml"></div>
 
 
 
 
 
 
 
416
  </div>
417
 
418
  <div class="resizer-h" @mousedown="(e) => startResizeV(e, 'bomHeight', '.sidebar')"></div>
@@ -423,7 +429,35 @@ const App = {
423
  <span>{{ t.titleStorage }}</span>
424
  <span style="color:#0284c7; font-weight: 600;">SMS / {{ settings.ontology }} / {{ settings.storage }}</span>
425
  </h4>
426
- <div id="storage-content" style="overflow-y: auto; display: flex; flex-direction: column;" v-html="storageHtml"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
  </div>
428
 
429
  <div class="resizer-h" @mousedown="(e) => startResizeV(e, 'storageHeight', '.sidebar')"></div>
@@ -435,7 +469,7 @@ const App = {
435
  <span style="font-weight: normal; text-transform: none; color: #0d9488;">{{ t.queryDesc }}</span>
436
  </h4>
437
  <div id="query-content" style="display: flex; flex-direction: column; flex: 1;">
438
- <pre class="code-block" :style="{ color: settings.ontology === 'BFO' ? '#0369a1' : '#3730a3' }">{{ queryHtml }}</pre>
439
  </div>
440
  </div>
441
  </div>
 
14
  import * as isoAdapter from './smim/iso15926.js';
15
  import { initVisNetwork, updateVisNetwork } from './renderers/vis-adapter.js';
16
  import { updateMermaidNetwork } from './renderers/mermaid-adapter.js';
17
+ import { generateBomTree } from './urmsm/bom-view.js';
18
  import { generateLpgStorage, generateLpgQuery } from './sms/lpg-generator.js';
19
  import { generateRdfStorage, generateRdfQuery } from './sms/rdf-generator.js';
20
 
21
  /**
22
+ * RECURSIVE BOM TREE NODE COMPONENT
23
+ * ---------------------------------
24
+ * Pure Vue component for rendering hierarchical Bill of Materials nodes
25
+ * without raw HTML strings or external DOM manipulation.
 
26
  */
27
+ const BomNode = {
28
+ name: 'BomNode',
29
+ props: {
30
+ node: {
31
+ type: Object,
32
+ required: true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  }
34
+ },
35
+ template: `
36
+ <li>
37
+ <strong>{{ node.id }}</strong>
38
+ <ul v-if="node.children && node.children.length > 0" class="tree">
39
+ <bom-node
40
+ v-for="child in node.children"
41
+ :key="child.id"
42
+ :node="child"
43
+ />
44
+ </ul>
45
+ </li>
46
+ `
47
+ };
48
 
49
  const App = {
50
+ components: {
51
+ BomNode
52
+ },
53
  setup() {
54
  // 1. Local UI Settings (Isolated from domain state)
55
  const settings = reactive({
 
174
  });
175
 
176
  // Derived Views for the Sidebar (URMSM & SMS)
177
+ const bomTree = computed(() => generateBomTree('System_A', activeEdges.value));
178
 
179
+ const lpgRecords = computed(() => {
180
  if (settings.storage === 'LPG') {
181
+ return generateLpgStorage(semanticGraph.value);
 
 
 
 
182
  }
183
+ return [];
184
  });
185
 
186
+ const rdfTtl = computed(() => {
187
+ if (settings.storage === 'RDF') {
188
+ return generateRdfStorage(semanticGraph.value);
189
+ }
190
+ return '';
191
+ });
192
+
193
+ function formatProperties(props) {
194
+ if (!props) return '';
195
+ const entries = Object.entries(props).filter(([key]) => key !== 'isCurrent');
196
+ if (entries.length === 0) return '';
197
+ return entries.map(([k, v]) => {
198
+ const valStr = v === null ? 'null' : (typeof v === 'number' ? `T${v}` : `'${v}'`);
199
+ return `${k}: ${valStr}`;
200
+ }).join(', ');
201
+ }
202
+
203
+ const queryCode = computed(() => {
204
  if (settings.storage === 'LPG') {
205
  return generateLpgQuery(semanticGraph.value, state.currentTime);
206
  } else {
 
215
 
216
  function renderGraph() {
217
  if (settings.engine === 'vis') {
218
+ const isComplex = settings.ontology === 'ISO15926';
219
  updateVisNetwork(semanticGraph.value, isComplex);
220
  } else if (mermaidContainer.value) {
221
  updateMermaidNetwork(semanticGraph.value, mermaidContainer.value);
 
312
  handleAdd, handleRemove,
313
  partNameInput, selectedParent, selectedEdgeToRemove, showHistory,
314
  activeNodes, activeEdges,
315
+ bomTree, lpgRecords, rdfTtl, formatProperties, queryCode,
316
  visContainer, mermaidContainer,
317
  startResizeH, startResizeV
318
  };
 
411
  <span>{{ t.titleBom }}</span>
412
  <span class="iec-badge align-right">IEC 63339 / URMSM<span class="iec-tooltip" v-html="t.tooltips.urmsm"></span></span>
413
  </h4>
414
+ <div id="tree-container" style="overflow-y: auto;">
415
+ <template v-if="bomTree">
416
+ <strong>{{ bomTree.id }}</strong>
417
+ <ul v-if="bomTree.children && bomTree.children.length > 0" class="tree">
418
+ <bom-node v-for="child in bomTree.children" :key="child.id" :node="child" />
419
+ </ul>
420
+ </template>
421
+ </div>
422
  </div>
423
 
424
  <div class="resizer-h" @mousedown="(e) => startResizeV(e, 'bomHeight', '.sidebar')"></div>
 
429
  <span>{{ t.titleStorage }}</span>
430
  <span style="color:#0284c7; font-weight: 600;">SMS / {{ settings.ontology }} / {{ settings.storage }}</span>
431
  </h4>
432
+ <div id="storage-content" style="overflow-y: auto; display: flex; flex-direction: column;">
433
+ <table v-if="settings.storage === 'LPG' && lpgRecords.length > 0">
434
+ <thead>
435
+ <tr>
436
+ <th>{{ t.sourceCol }}</th>
437
+ <th>{{ t.targetCol }}</th>
438
+ <th>Type</th>
439
+ <th>Properties</th>
440
+ <th>{{ t.statusCol }}</th>
441
+ </tr>
442
+ </thead>
443
+ <tbody>
444
+ <tr v-for="row in lpgRecords" :key="row.id" :class="row.isActive ? 'active-row' : 'closed-row'">
445
+ <td>{{ row.from }}</td>
446
+ <td><strong>{{ row.to }}</strong></td>
447
+ <td><code>:{{ row.label }}</code></td>
448
+ <td>
449
+ <code v-if="formatProperties(row.properties)">{ {{ formatProperties(row.properties) }} }</code>
450
+ <span v-else>—</span>
451
+ </td>
452
+ <td>{{ row.isActive ? t.activeStatus : t.closedStatus }}</td>
453
+ </tr>
454
+ </tbody>
455
+ </table>
456
+ <div v-else-if="settings.storage === 'LPG'" style="color: #94a3b8; padding: 8px;">
457
+ No relationship records
458
+ </div>
459
+ <pre v-else class="code-block">{{ rdfTtl }}</pre>
460
+ </div>
461
  </div>
462
 
463
  <div class="resizer-h" @mousedown="(e) => startResizeV(e, 'storageHeight', '.sidebar')"></div>
 
469
  <span style="font-weight: normal; text-transform: none; color: #0d9488;">{{ t.queryDesc }}</span>
470
  </h4>
471
  <div id="query-content" style="display: flex; flex-direction: column; flex: 1;">
472
+ <pre class="code-block" :style="{ color: settings.ontology === 'BFO' ? '#0369a1' : '#3730a3' }">{{ queryCode }}</pre>
473
  </div>
474
  </div>
475
  </div>
js/renderers/mermaid-adapter.js CHANGED
@@ -68,6 +68,10 @@ async function executePendingRender(definition, container) {
68
 
69
  /**
70
  * Builds the string definition for the Mermaid flowchart.
 
 
 
 
71
  */
72
  function buildMermaidDefinition(semanticGraph) {
73
  // 1. Initialise the graph direction and styling classes
@@ -75,8 +79,6 @@ function buildMermaidDefinition(semanticGraph) {
75
  def += ' classDef default fill:#f8fafc,stroke:#cbd5e1,color:#334155,stroke-width:1px\n';
76
  def += ' classDef bfoSys fill:#0284c7,stroke:#0369a1,color:#ffffff,stroke-width:2px\n';
77
  def += ' classDef bfoElem fill:#64748b,stroke:#475569,color:#ffffff,stroke-width:1px\n';
78
- def += ' classDef rdfStmt fill:#f59e0b,stroke:#d97706,color:#000000,stroke-width:1px\n';
79
- def += ' classDef rdfLit fill:#f1f5f9,stroke:#cbd5e1,color:#334155,stroke-dasharray:3 3\n';
80
  def += ' classDef iso4d fill:#4f46e5,stroke:#3730a3,color:#ffffff,stroke-width:2px\n';
81
  def += ' classDef isoState fill:#0d9488,stroke:#0f766e,color:#ffffff,stroke-width:1px\n\n';
82
 
@@ -85,20 +87,8 @@ function buildMermaidDefinition(semanticGraph) {
85
  const safeId = sanitizeId(node.id);
86
  const styleClass = getNodeClass(node);
87
  const safeLabel = node.label.replace(/\n/g, '<br/>'); // Support multi-line
88
-
89
- let shapeOpen = '["';
90
- let shapeClose = '"]';
91
-
92
- // Assign specific shapes based on type
93
- if (node.type === 'TemporalPartMembership') {
94
- shapeOpen = '{{ "'; // Hexagon for RDF Statements
95
- shapeClose = '" }}';
96
- } else if (node.type === 'Literal') {
97
- shapeOpen = '(["'; // Pill shape for Literals
98
- shapeClose = '"])';
99
- }
100
 
101
- def += ` ${safeId}${shapeOpen}<b>${safeLabel}</b><br/><i>${node.type}</i>${shapeClose}:::${styleClass}\n`;
102
  });
103
 
104
  def += '\n';
@@ -107,15 +97,10 @@ function buildMermaidDefinition(semanticGraph) {
107
  semanticGraph.edges.forEach(edge => {
108
  const safeFrom = sanitizeId(edge.from);
109
  const safeTo = sanitizeId(edge.to);
110
- const isActive = edge.data?.isActive !== false;
111
-
112
- let linkStyle = '-->'; // Solid line
113
-
114
- if (!isActive || edge.data?.isPast || edge.type === 'classification') {
115
- linkStyle = '-.->'; // Dashed line for inactive, historical, or classification links
116
- } else if (edge.type === 'transition') {
117
- linkStyle = '==>'; // Thick line for LPG state transitions
118
- }
119
 
120
  // Escape quotes in the label
121
  const safeEdgeLabel = (edge.label || '').replace(/"/g, "'");
@@ -131,12 +116,14 @@ function buildMermaidDefinition(semanticGraph) {
131
  */
132
  function getNodeClass(node) {
133
  switch (node.type) {
134
- case 'MaterialEntity': return node.data?.entityType === 'system' ? 'bfoSys' : 'bfoElem';
135
- case 'TemporalPartMembership': return 'rdfStmt';
136
- case 'Literal': return 'rdfLit';
137
- case 'ActualIndividual': return 'iso4d';
138
- case 'State': return 'isoState';
139
- default: return 'default';
 
 
140
  }
141
  }
142
 
 
68
 
69
  /**
70
  * Builds the string definition for the Mermaid flowchart.
71
+ * Pure renderer for canonical 3D (BFO) and 4D (ISO 15926) graphs.
72
+ *
73
+ * @param {Object} semanticGraph - Standardised Semantic Graph.
74
+ * @returns {string} Mermaid chart definition string.
75
  */
76
  function buildMermaidDefinition(semanticGraph) {
77
  // 1. Initialise the graph direction and styling classes
 
79
  def += ' classDef default fill:#f8fafc,stroke:#cbd5e1,color:#334155,stroke-width:1px\n';
80
  def += ' classDef bfoSys fill:#0284c7,stroke:#0369a1,color:#ffffff,stroke-width:2px\n';
81
  def += ' classDef bfoElem fill:#64748b,stroke:#475569,color:#ffffff,stroke-width:1px\n';
 
 
82
  def += ' classDef iso4d fill:#4f46e5,stroke:#3730a3,color:#ffffff,stroke-width:2px\n';
83
  def += ' classDef isoState fill:#0d9488,stroke:#0f766e,color:#ffffff,stroke-width:1px\n\n';
84
 
 
87
  const safeId = sanitizeId(node.id);
88
  const styleClass = getNodeClass(node);
89
  const safeLabel = node.label.replace(/\n/g, '<br/>'); // Support multi-line
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
+ def += ` ${safeId}["<b>${safeLabel}</b><br/><i>${node.type}</i>"]:::${styleClass}\n`;
92
  });
93
 
94
  def += '\n';
 
97
  semanticGraph.edges.forEach(edge => {
98
  const safeFrom = sanitizeId(edge.from);
99
  const safeTo = sanitizeId(edge.to);
100
+ const isCurrent = edge.properties?.isCurrent !== false;
101
+
102
+ // Solid line for active composition, dashed line for closed or structural classification links
103
+ const linkStyle = (!isCurrent || edge.type === 'classification') ? '-.->' : '-->';
 
 
 
 
 
104
 
105
  // Escape quotes in the label
106
  const safeEdgeLabel = (edge.label || '').replace(/"/g, "'");
 
116
  */
117
  function getNodeClass(node) {
118
  switch (node.type) {
119
+ case 'MaterialEntity':
120
+ return node.properties?.entityType === 'system' ? 'bfoSys' : 'bfoElem';
121
+ case 'ActualIndividual':
122
+ return 'iso4d';
123
+ case 'State':
124
+ return 'isoState';
125
+ default:
126
+ return 'default';
127
  }
128
  }
129
 
js/renderers/vis-adapter.js CHANGED
@@ -25,7 +25,7 @@ export function initVisNetwork(container) {
25
  * Updates the network with a new Semantic Graph.
26
  *
27
  * @param {Object} semanticGraph - { nodes: [], edges: [] }
28
- * @param {boolean} isComplex - Flag to adjust physics for denser graphs (e.g., RDF).
29
  */
30
  export function updateVisNetwork(semanticGraph, isComplex = false) {
31
  if (!network) {
@@ -96,33 +96,22 @@ export function updateVisNetwork(semanticGraph, isComplex = false) {
96
 
97
  /**
98
  * Determines the visual style of a node based on its ontological type.
 
 
 
 
99
  */
100
  function getNodeStyle(node) {
101
  switch (node.type) {
102
  // BFO 3D Continuants
103
- case 'MaterialEntity':
104
- const isSystem = node.data?.entityType === 'system';
105
  return {
106
  shape: 'box',
107
  color: isSystem ? '#0284c7' : '#64748b', // Blue for System, Slate for Element
108
  font: { color: '#ffffff', bold: isSystem }
109
  };
110
-
111
- // RDF Reification Statements
112
- case 'TemporalPartMembership':
113
- const isStmtActive = node.data?.isActive;
114
- return {
115
- shape: 'diamond',
116
- size: 26,
117
- color: isStmtActive ? '#f59e0b' : '#e2e8f0', // Amber if active, light grey if past
118
- font: { size: 9, color: isStmtActive ? '#000000' : '#64748b' }
119
- };
120
- case 'Literal':
121
- return {
122
- shape: 'box',
123
- color: '#f8fafc',
124
- font: { size: 8, color: '#334155' }
125
- };
126
 
127
  // ISO 15926 4D Perdurants
128
  case 'ActualIndividual':
@@ -131,6 +120,7 @@ function getNodeStyle(node) {
131
  color: '#4f46e5', // Indigo
132
  font: { color: '#ffffff', bold: true }
133
  };
 
134
  case 'State':
135
  return {
136
  shape: 'box',
@@ -144,33 +134,31 @@ function getNodeStyle(node) {
144
  }
145
 
146
  /**
147
- * Determines the visual style of an edge based on its ontological type and temporal state.
 
 
 
148
  */
149
  function getEdgeStyle(edge) {
150
- const isActive = edge.data?.isActive !== false; // Default to true if not explicitly false
151
-
152
  switch (edge.type) {
153
  case 'composition':
154
  return {
155
- color: isActive ? { color: '#10b981' } : { color: '#cbd5e1' }, // Emerald active, Slate past
156
- dashes: !isActive,
157
- width: isActive ? 2 : 1
158
- };
159
- case 'transition':
160
- return {
161
- color: { color: '#f59e0b' }, // Amber for state transitions
162
- dashes: false,
163
- width: 2
164
  };
 
165
  case 'classification':
166
- case 'reification':
167
  return {
168
- color: { color: '#94a3b8' }, // Subtle slate for structural RDF/4D links
169
- dashes: edge.data?.isPast || edge.type === 'classification',
170
  width: 1
171
  };
 
172
  default:
173
- return { color: { color: '#94a3b8' }, dashes: false, width: 1 };
174
  }
175
  }
176
 
 
25
  * Updates the network with a new Semantic Graph.
26
  *
27
  * @param {Object} semanticGraph - { nodes: [], edges: [] }
28
+ * @param {boolean} isComplex - Flag to adjust physics for denser graphs (e.g. ISO 15926 4D).
29
  */
30
  export function updateVisNetwork(semanticGraph, isComplex = false) {
31
  if (!network) {
 
96
 
97
  /**
98
  * Determines the visual style of a node based on its ontological type.
99
+ * Only handles canonical 3D (BFO) and 4D (ISO 15926) domain entities.
100
+ *
101
+ * @param {Object} node - Canonical semantic node.
102
+ * @returns {Object} Vis.js node styling object.
103
  */
104
  function getNodeStyle(node) {
105
  switch (node.type) {
106
  // BFO 3D Continuants
107
+ case 'MaterialEntity': {
108
+ const isSystem = node.properties?.entityType === 'system';
109
  return {
110
  shape: 'box',
111
  color: isSystem ? '#0284c7' : '#64748b', // Blue for System, Slate for Element
112
  font: { color: '#ffffff', bold: isSystem }
113
  };
114
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
  // ISO 15926 4D Perdurants
117
  case 'ActualIndividual':
 
120
  color: '#4f46e5', // Indigo
121
  font: { color: '#ffffff', bold: true }
122
  };
123
+
124
  case 'State':
125
  return {
126
  shape: 'box',
 
134
  }
135
 
136
  /**
137
+ * Determines the visual style of an edge based on its ontological type and temporal validity.
138
+ *
139
+ * @param {Object} edge - Canonical semantic edge with properties.
140
+ * @returns {Object} Vis.js edge styling object.
141
  */
142
  function getEdgeStyle(edge) {
143
+ const isCurrent = edge.properties?.isCurrent !== false;
144
+
145
  switch (edge.type) {
146
  case 'composition':
147
  return {
148
+ color: isCurrent ? { color: '#10b981' } : { color: '#cbd5e1' }, // Emerald active, Slate past
149
+ dashes: !isCurrent,
150
+ width: isCurrent ? 2 : 1
 
 
 
 
 
 
151
  };
152
+
153
  case 'classification':
 
154
  return {
155
+ color: { color: '#94a3b8' }, // Subtle slate for structural 4D temporalPartOf links
156
+ dashes: !isCurrent,
157
  width: 1
158
  };
159
+
160
  default:
161
+ return { color: { color: '#94a3b8' }, dashes: !isCurrent, width: 1 };
162
  }
163
  }
164
 
js/urmsm/bom-view.js CHANGED
@@ -5,32 +5,44 @@
5
  * According to ISO 42010, this is a specific viewpoint for an engineer
6
  * who only cares about the physical breakdown at time T, abstracting away
7
  * the underlying database mechanics (LPG/RDF) and temporal ontologies.
 
 
8
  */
9
 
10
  /**
11
- * Recursively builds an HTML tree for the BOM.
12
  *
13
  * @param {string} rootId - The ID of the top-level system.
14
- * @param {Array} activeEdges - Array of currently active edges (filtered for Time = T).
15
- * @returns {string} HTML string representing the tree structure.
16
  */
17
- export function generateBomHtml(rootId, activeEdges) {
18
- return `<strong>${rootId}</strong>` + buildTreeRecursive(rootId, activeEdges);
19
  }
20
 
21
- function buildTreeRecursive(nodeId, activeEdges) {
22
- // Find all children where this node is the parent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  const children = activeEdges
24
  .filter(e => e.from === nodeId)
25
- .map(e => e.to);
26
 
27
- if (children.length === 0) return '';
28
-
29
- let html = '<ul class="tree">';
30
- children.forEach(childId => {
31
- html += `<li><strong>${childId}</strong>${buildTreeRecursive(childId, activeEdges)}</li>`;
32
- });
33
- html += '</ul>';
34
-
35
- return html;
36
- }
 
5
  * According to ISO 42010, this is a specific viewpoint for an engineer
6
  * who only cares about the physical breakdown at time T, abstracting away
7
  * the underlying database mechanics (LPG/RDF) and temporal ontologies.
8
+ *
9
+ * Returns pure hierarchical data structures without any DOM or HTML coupling.
10
  */
11
 
12
  /**
13
+ * Recursively builds a pure hierarchical tree structure for the BOM.
14
  *
15
  * @param {string} rootId - The ID of the top-level system.
16
+ * @param {Array<Object>} activeEdges - Array of currently active edges (filtered for Time = T).
17
+ * @returns {Object} Hierarchical node structure: { id: string, children: Array<Object> }.
18
  */
19
+ export function generateBomTree(rootId, activeEdges) {
20
+ return buildTreeRecursive(rootId, activeEdges || [], new Set());
21
  }
22
 
23
+ /**
24
+ * Helper function to recursively populate tree nodes while guarding against circular references.
25
+ *
26
+ * @param {string} nodeId - Current node identifier.
27
+ * @param {Array<Object>} activeEdges - Array of active relationship edges.
28
+ * @param {Set<string>} visited - Set of previously visited node identifiers to avoid cycles.
29
+ * @returns {Object} Tree node object.
30
+ */
31
+ function buildTreeRecursive(nodeId, activeEdges, visited = new Set()) {
32
+ if (visited.has(nodeId)) {
33
+ return { id: nodeId, children: [] };
34
+ }
35
+
36
+ const nextVisited = new Set(visited);
37
+ nextVisited.add(nodeId);
38
+
39
+ // Find all child IDs where this node acts as the parent
40
  const children = activeEdges
41
  .filter(e => e.from === nodeId)
42
+ .map(e => buildTreeRecursive(e.to, activeEdges, nextVisited));
43
 
44
+ return {
45
+ id: nodeId,
46
+ children
47
+ };
48
+ }