Spaces:
Running
Running
Refactor: Isolate URMSM view from DOM, fix renderers, and decouple LPG/RDF visualization
Browse files- ARCHITECTURE.md +2 -2
- js/app.js +90 -56
- js/renderers/mermaid-adapter.js +17 -30
- js/renderers/vis-adapter.js +23 -35
- js/urmsm/bom-view.js +30 -18
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: "
|
| 34 |
-
edges: [ { id: "e1", from: "
|
| 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 {
|
| 18 |
import { generateLpgStorage, generateLpgQuery } from './sms/lpg-generator.js';
|
| 19 |
import { generateRdfStorage, generateRdfQuery } from './sms/rdf-generator.js';
|
| 20 |
|
| 21 |
/**
|
| 22 |
-
*
|
| 23 |
-
*
|
| 24 |
-
*
|
| 25 |
-
*
|
| 26 |
-
* @returns {string} HTML table string.
|
| 27 |
*/
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 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 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 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
|
| 193 |
|
| 194 |
-
const
|
| 195 |
if (settings.storage === 'LPG') {
|
| 196 |
-
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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'
|
| 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 |
-
|
| 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;"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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;"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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' }">{{
|
| 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}
|
| 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
|
| 111 |
-
|
| 112 |
-
|
| 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':
|
| 135 |
-
|
| 136 |
-
case '
|
| 137 |
-
|
| 138 |
-
case 'State':
|
| 139 |
-
|
|
|
|
|
|
|
| 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.
|
| 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.
|
| 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
|
|
|
|
|
|
|
|
|
|
| 148 |
*/
|
| 149 |
function getEdgeStyle(edge) {
|
| 150 |
-
const
|
| 151 |
-
|
| 152 |
switch (edge.type) {
|
| 153 |
case 'composition':
|
| 154 |
return {
|
| 155 |
-
color:
|
| 156 |
-
dashes: !
|
| 157 |
-
width:
|
| 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
|
| 169 |
-
dashes:
|
| 170 |
width: 1
|
| 171 |
};
|
|
|
|
| 172 |
default:
|
| 173 |
-
return { color: { color: '#94a3b8' }, dashes:
|
| 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
|
| 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 {
|
| 16 |
*/
|
| 17 |
-
export function
|
| 18 |
-
return
|
| 19 |
}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
const children = activeEdges
|
| 24 |
.filter(e => e.from === nodeId)
|
| 25 |
-
.map(e => e.to);
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 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 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|