Alef1986 commited on
Commit
fd64fe2
·
verified ·
1 Parent(s): 62b4f9a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +993 -19
index.html CHANGED
@@ -1,19 +1,993 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="sv">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>Knowledge Architecture Workbench (BFO vs ISO 15926 | LPG vs RDF)</title>
6
+ <!-- Third-party CDN libraries: Mermaid.js & Vis.js -->
7
+ <script src="https://cdn.jsdelivr.net/npm/mermaid@10.9.8/dist/mermaid.min.js"></script>
8
+ <script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
9
+ <style>
10
+ * { box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
11
+ body { margin: 0; padding: 12px; background: #f8fafc; color: #0f172a; display: flex; flex-direction: column; height: 100vh; }
12
+
13
+ /* Dual-tier control console */
14
+ .control-deck { background: #ffffff; border: 1px solid #cbd5e1; border-radius: 8px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
15
+ .deck-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 14px; }
16
+ .deck-row-top { background: #f1f5f9; border-bottom: 1px solid #e2e8f0; border-top-left-radius: 7px; border-top-right-radius: 7px; }
17
+
18
+ .badge { background: #0284c7; color: #ffffff; font-weight: bold; padding: 4px 10px; border-radius: 6px; font-size: 13px; }
19
+ .section-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #475569; display: flex; align-items: center; gap: 4px; }
20
+
21
+ button { background: #0f172a; color: #ffffff; border: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 500; }
22
+ button:hover { background: #334155; }
23
+ button.secondary { background: #e2e8f0; color: #0f172a; }
24
+ button.secondary:hover { background: #cbd5e1; }
25
+ button.danger { background: #ef4444; }
26
+ button.danger:hover { background: #dc2626; }
27
+
28
+ .btn-group { display: flex; border: 1px solid #cbd5e1; border-radius: 6px; overflow: hidden; background: #ffffff; }
29
+ .btn-group button { border-radius: 0; background: #ffffff; color: #475569; padding: 4px 10px; border-right: 1px solid #cbd5e1; font-size: 12px; font-weight: 600; line-height: 1.2; }
30
+ .btn-group button:last-child { border-right: none; }
31
+ .btn-group button.active { background: #0284c7; color: #ffffff; }
32
+ .btn-group.flag-group button { font-size: 15px; padding: 3px 8px; }
33
+
34
+ input, select { padding: 5px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 12px; }
35
+ .divider { height: 18px; width: 1px; background: #cbd5e1; margin: 0 4px; }
36
+
37
+ .main-container { display: flex; flex: 1; gap: 10px; min-height: 0; }
38
+ #canvas-container { flex: 2; background: #ffffff; border: 1px solid #e2e8f0; border-radius: 8px; position: relative; overflow: hidden; }
39
+ #vis-container { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }
40
+ #mermaid-container { width: 100%; height: 100%; position: absolute; top: 0; left: 0; overflow: auto; padding: 24px 24px 140px 24px; display: flex; justify-content: center; align-items: flex-start; background: #ffffff; }
41
+ #mermaid-container svg { width: auto; height: auto; max-width: none; }
42
+
43
+ /* Dynamic graph legend badge */
44
+ .graph-legend {
45
+ position: absolute;
46
+ bottom: 12px;
47
+ left: 12px;
48
+ background: rgba(255, 255, 255, 0.96);
49
+ backdrop-filter: blur(4px);
50
+ border: 1px solid #cbd5e1;
51
+ border-radius: 8px;
52
+ padding: 10px 14px;
53
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
54
+ font-size: 11px;
55
+ color: #334155;
56
+ z-index: 20;
57
+ max-width: 330px;
58
+ }
59
+ .legend-title { font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #475569; margin-bottom: 6px; display: flex; justify-content: space-between; border-bottom: 1px solid #e2e8f0; padding-bottom: 4px; }
60
+ .legend-section { margin-top: 5px; }
61
+ .legend-section-title { font-weight: 600; color: #64748b; font-size: 10px; margin-bottom: 3px; text-transform: uppercase; }
62
+ .legend-item { display: flex; align-items: center; margin-bottom: 3px; line-height: 1.25; }
63
+
64
+ /* Legend glyph swatches */
65
+ .swatch-box-sys { width: 13px; height: 11px; background: #0284c7; border: 1px solid #0369a1; border-radius: 2px; margin-right: 8px; flex-shrink: 0; }
66
+ .swatch-box-elem { width: 13px; height: 11px; background: #64748b; border: 1px solid #475569; border-radius: 2px; margin-right: 8px; flex-shrink: 0; }
67
+ .swatch-box-4d { width: 13px; height: 11px; background: #4f46e5; border: 1px solid #3730a3; border-radius: 2px; margin-right: 8px; flex-shrink: 0; }
68
+ .swatch-box-state { width: 13px; height: 11px; background: #0d9488; border: 1px solid #0f766e; border-radius: 2px; margin-right: 8px; flex-shrink: 0; }
69
+ .swatch-diamond { width: 9px; height: 9px; background: #f59e0b; border: 1px solid #d97706; transform: rotate(45deg); margin: 0 10px 0 2px; flex-shrink: 0; }
70
+ .swatch-literal { width: 14px; height: 9px; background: #f1f5f9; border: 1px dashed #94a3b8; border-radius: 2px; margin-right: 8px; flex-shrink: 0; }
71
+ .swatch-line-active { width: 16px; height: 2px; background: #10b981; margin-right: 8px; flex-shrink: 0; }
72
+ .swatch-line-past { width: 16px; height: 0; border-top: 2px dashed #94a3b8; margin-right: 8px; flex-shrink: 0; }
73
+ .swatch-line-transition { width: 16px; height: 2px; background: #f59e0b; margin-right: 8px; flex-shrink: 0; }
74
+
75
+ /* Right sidebar container */
76
+ .sidebar { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 350px; }
77
+ .card { background: #ffffff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 10px 12px; overflow-y: auto; }
78
+ .card h4 { margin: 0 0 6px 0; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #64748b; display: flex; justify-content: space-between; }
79
+
80
+ ul.tree, ul.tree ul { list-style-type: none; padding-left: 14px; margin: 2px 0; }
81
+ ul.tree li { position: relative; padding: 2px 0; font-size: 12px; }
82
+ ul.tree li::before { content: "├─ "; color: #94a3b8; }
83
+ ul.tree li:last-child::before { content: "└─ "; color: #94a3b8; }
84
+
85
+ table { width: 100%; border-collapse: collapse; font-size: 11px; }
86
+ th, td { text-align: left; padding: 4px 6px; border-bottom: 1px solid #f1f5f9; }
87
+ th { color: #64748b; font-weight: 600; }
88
+ .active-row { background: #f0fdf4; }
89
+ .closed-row { color: #94a3b8; text-decoration: line-through; }
90
+
91
+ pre.code-block { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 11px; color: #1e293b; line-height: 1.35; background: #f8fafc; padding: 8px; border-radius: 4px; border: 1px solid #e2e8f0; max-height: 140px; overflow-y: auto; white-space: pre-wrap; }
92
+ </style>
93
+ </head>
94
+ <body>
95
+
96
+ <!-- Dual-tier control console -->
97
+ <div class="control-deck">
98
+ <!-- Tier 1: Architectural paradigms (Ontology + Graph Model + Rendering Engine) -->
99
+ <div class="deck-row deck-row-top">
100
+ <div class="section-label">🏛️ <span id="lbl-onto-title">Ontologi:</span></div>
101
+ <div class="btn-group">
102
+ <button id="onto-bfo" class="active" onclick="setOntology('BFO')">BFO (3D Continuant)</button>
103
+ <button id="onto-iso" onclick="setOntology('ISO15926')">ISO 15926 (4D Perdurant)</button>
104
+ </div>
105
+
106
+ <div class="divider"></div>
107
+
108
+ <div class="section-label">💾 <span id="lbl-graph-title">Datamodell:</span></div>
109
+ <div class="btn-group">
110
+ <button id="mode-lpg" class="active" onclick="setGraphMode('LPG')">LPG</button>
111
+ <button id="mode-rdf" onclick="setGraphMode('RDF')">RDF (W3C)</button>
112
+ </div>
113
+
114
+ <div class="divider"></div>
115
+
116
+ <div class="section-label">🎨 <span id="lbl-engine-title">Motor:</span></div>
117
+ <div class="btn-group">
118
+ <button id="eng-vis" class="active" onclick="setEngine('vis')">🌐 Vis.js</button>
119
+ <button id="eng-mermaid" onclick="setEngine('mermaid')">📊 Mermaid</button>
120
+ </div>
121
+
122
+ <div style="margin-left: auto;" class="btn-group flag-group">
123
+ <button id="lang-sv" class="active" onclick="setLanguage('sv')" title="Svenska">🇸🇪</button>
124
+ <button id="lang-en" onclick="setLanguage('en')" title="British English">🇬🇧</button>
125
+ <button id="lang-ru" onclick="setLanguage('ru')" title="Русский">🇷🇺</button>
126
+ </div>
127
+ </div>
128
+
129
+ <!-- Tier 2: Operational engineering actions (BOM Authoring) -->
130
+ <div class="deck-row">
131
+ <span class="badge" id="time-display">T = 0</span>
132
+ <button id="step-btn" onclick="advanceTime()"></button>
133
+
134
+ <div class="divider"></div>
135
+
136
+ <label id="lbl-parent" style="font-size: 11px; color: #64748b; font-weight: 600;"></label>
137
+ <select id="parent-select"></select>
138
+
139
+ <input type="text" id="part-input" style="width: 120px;">
140
+ <button id="add-btn" class="secondary" onclick="handleAddPart()"></button>
141
+
142
+ <div class="divider"></div>
143
+ <select id="remove-select"></select>
144
+ <button id="remove-btn" class="danger" onclick="handleRemoveEdge()"></button>
145
+
146
+ <div class="divider"></div>
147
+
148
+ <label style="font-size: 11px; color: #475569; display: flex; align-items: center; gap: 4px;">
149
+ <input type="checkbox" id="history-toggle" checked onchange="render()"> <span id="lbl-history"></span>
150
+ </label>
151
+ </div>
152
+ </div>
153
+
154
+ <div class="main-container">
155
+ <!-- Visualisation canvas with dual rendering container -->
156
+ <div id="canvas-container">
157
+ <div id="vis-container"></div>
158
+ <div id="mermaid-container" style="display: none;"></div>
159
+ <div id="graph-legend" class="graph-legend"></div>
160
+ </div>
161
+
162
+ <!-- Sidebar: 3 inspection cards -->
163
+ <div class="sidebar">
164
+ <!-- 1. End-user viewpoint (IEC 63339 URMSM BOM View) -->
165
+ <div class="card" style="flex: 0 0 25%;">
166
+ <h4><span id="title-bom"></span> <span style="color:#0284c7; font-weight: normal;">URMSM / Viewpoint</span></h4>
167
+ <div id="tree-container"></div>
168
+ </div>
169
+
170
+ <!-- 2. Query complexity inspector (Cypher / SPARQL) -->
171
+ <div class="card" style="flex: 1;">
172
+ <h4><span id="title-query"></span> <span id="query-lang-tag" style="color:#0284c7; font-weight: normal;"></span></h4>
173
+ <div id="query-content"></div>
174
+ </div>
175
+
176
+ <!-- 3. Physical data model representation -->
177
+ <div class="card" style="flex: 1;">
178
+ <h4><span id="title-storage"></span> <span id="storage-paradigm-tag" style="color:#0284c7; font-weight: normal;"></span></h4>
179
+ <div id="storage-content"></div>
180
+ </div>
181
+ </div>
182
+ </div>
183
+
184
+ <script>
185
+ // Initialise Mermaid rendering configuration
186
+ mermaid.initialize({
187
+ startOnLoad: false,
188
+ theme: 'neutral',
189
+ securityLevel: 'loose',
190
+ flowchart: { curve: 'basis', htmlLabels: true }
191
+ });
192
+
193
+ // Multilingual dictionary (Swedish, British English, Russian)
194
+ const i18n = {
195
+ sv: {
196
+ ontoTitle: "Ontologi:",
197
+ graphTitle: "Datamodell:",
198
+ engineTitle: "Grafmotor:",
199
+ stepBtn: "Lås steg (T+1)",
200
+ parent: "Överordnad:",
201
+ partPlaceholder: "Komponentnamn",
202
+ addBtn: "+ Lägg till",
203
+ removeBtn: "Uteslut relation",
204
+ history: "Historik",
205
+ titleBom: "Struktur (BOM-träd)",
206
+ titleQuery: "Genererad databasfråga",
207
+ titleStorage: "Under huven",
208
+ activeStatus: "Aktiv",
209
+ closedStatus: "Avslutad",
210
+ sourceCol: "Källa",
211
+ targetCol: "Mål",
212
+ statusCol: "Status",
213
+ legend: {
214
+ title: "Teckenförklaring",
215
+ nodes: "Noder",
216
+ edges: "Relationer",
217
+ bfoSys: "Continuant / System (:System)",
218
+ bfoElem: "Continuant / Komponent (:Element)",
219
+ bfoActiveEdge: "Aktiv relation [giltig till nu]",
220
+ bfoPastEdge: "Historisk relation (avslutad)",
221
+ iso4d: "4D-individ (Spatio-Temporal Extent)",
222
+ isoState: "Temporal del / Tillstånd (State)",
223
+ isoPartRel: "Tidlös komposition (hasPart)",
224
+ isoSliceRel: "temporalPartOf (del av 4D-individ)",
225
+ isoTransitionRel: "TRANSITION_TO (tillståndskedja i LPG)",
226
+ rdfStmt: "Reifiering (_:statement)",
227
+ rdfLit: "Literal (tidsstämpel xsd:int)",
228
+ rdfPred: "RDF-predikat"
229
+ }
230
+ },
231
+ en: {
232
+ ontoTitle: "Ontology:",
233
+ graphTitle: "Data Model:",
234
+ engineTitle: "Renderer:",
235
+ stepBtn: "Commit step (T+1)",
236
+ parent: "Parent:",
237
+ partPlaceholder: "Component name",
238
+ addBtn: "+ Add",
239
+ removeBtn: "Sever relation",
240
+ history: "History",
241
+ titleBom: "BOM Tree Structure",
242
+ titleQuery: "Generated Database Query",
243
+ titleStorage: "Under the Bonnet",
244
+ activeStatus: "Active",
245
+ closedStatus: "Closed",
246
+ sourceCol: "Source",
247
+ targetCol: "Target",
248
+ statusCol: "Status",
249
+ legend: {
250
+ title: "Graph Legend",
251
+ nodes: "Node Types",
252
+ edges: "Relationships",
253
+ bfoSys: "Continuant / System (:System)",
254
+ bfoElem: "Continuant / Component (:Element)",
255
+ bfoActiveEdge: "Active relation [valid to now]",
256
+ bfoPastEdge: "Historical relation (closed)",
257
+ iso4d: "4D Individual (Spatio-Temporal Extent)",
258
+ isoState: "Temporal Part / State",
259
+ isoPartRel: "Tenseless Composition (hasPart)",
260
+ isoSliceRel: "temporalPartOf (Extent link)",
261
+ isoTransitionRel: "TRANSITION_TO (State Chain in LPG)",
262
+ rdfStmt: "Reification Node (_:statement)",
263
+ rdfLit: "Literal (xsd:int timestamp)",
264
+ rdfPred: "RDF Predicate"
265
+ }
266
+ },
267
+ ru: {
268
+ ontoTitle: "Онтология:",
269
+ graphTitle: "Модель данных:",
270
+ engineTitle: "Движок:",
271
+ stepBtn: "Зафиксировать шаг (T+1)",
272
+ parent: "Родитель:",
273
+ partPlaceholder: "Имя компонента",
274
+ addBtn: "+ Добавить",
275
+ removeBtn: "Исключить связь",
276
+ history: "История",
277
+ titleBom: "Состав изделия (BOM)",
278
+ titleQuery: "Генерируемый запрос к БД",
279
+ titleStorage: "Под капотом",
280
+ activeStatus: "Активна",
281
+ closedStatus: "Закрыта",
282
+ sourceCol: "Источник",
283
+ targetCol: "Цель",
284
+ statusCol: "Статус",
285
+ legend: {
286
+ title: "Легенда графа",
287
+ nodes: "Типы узлов",
288
+ edges: "Типы связей",
289
+ bfoSys: "Континуант / Система (:System)",
290
+ bfoElem: "Континуант / Компонент (:Element)",
291
+ bfoActiveEdge: "Активная связь [действует сейчас]",
292
+ bfoPastEdge: "Архивная связь (закрыта)",
293
+ iso4d: "4D-индивид (Пространственно-временной объем)",
294
+ isoState: "Темпоральный срез / Состояние",
295
+ isoPartRel: "Вневременной состав (hasPart)",
296
+ isoSliceRel: "temporalPartOf (связь с 4D-целым)",
297
+ isoTransitionRel: "TRANSITION_TO (цепочка состояний в LPG)",
298
+ rdfStmt: "Узел реификации (_:statement)",
299
+ rdfLit: "Литерал (метка времени xsd:int)",
300
+ rdfPred: "RDF-предикат"
301
+ }
302
+ }
303
+ };
304
+
305
+ // System state variables
306
+ let currentLang = 'sv';
307
+ let currentOntology = 'BFO'; // 'BFO' (3D) | 'ISO15926' (4D)
308
+ let currentMode = 'LPG'; // 'LPG' | 'RDF'
309
+ let currentEngine = 'vis'; // 'vis' | 'mermaid'
310
+ let currentTime = 0;
311
+ const ROOT_ID = 'System_A';
312
+
313
+ // Canonical inventory of items
314
+ const baseNodes = [
315
+ { id: ROOT_ID, label: 'System_A', type: 'system' }
316
+ ];
317
+
318
+ // Master temporal edge storage
319
+ let edgesStore = [];
320
+ let edgeSeq = 1;
321
+ let mermaidCounter = 0;
322
+
323
+ // Concurrency queue for Mermaid rendering
324
+ let isRenderingMermaid = false;
325
+ let pendingMermaidDef = null;
326
+
327
+ // Vis.js dataset instances
328
+ const visNodes = new vis.DataSet();
329
+ const visEdges = new vis.DataSet();
330
+ const visContainer = document.getElementById('vis-container');
331
+
332
+ // Vis.js physics setup optimised for readable node separation
333
+ function getVisOptions() {
334
+ const isComplex = (currentMode === 'RDF' || currentOntology === 'ISO15926');
335
+ return {
336
+ physics: {
337
+ stabilization: { iterations: 120 },
338
+ barnesHut: {
339
+ gravitationalConstant: isComplex ? -24000 : -10000,
340
+ centralGravity: 0.25,
341
+ springLength: isComplex ? 220 : 150,
342
+ springConstant: 0.04,
343
+ damping: 0.09,
344
+ avoidOverlap: 1
345
+ }
346
+ },
347
+ nodes: {
348
+ shape: 'box',
349
+ margin: 10,
350
+ font: { size: 12, face: 'system-ui' },
351
+ borderWidth: 1.5
352
+ },
353
+ edges: {
354
+ arrows: 'to',
355
+ smooth: { type: 'continuous', roundness: 0.2 },
356
+ font: {
357
+ size: 10,
358
+ align: 'middle',
359
+ background: '#ffffff',
360
+ strokeWidth: 0
361
+ }
362
+ }
363
+ };
364
+ }
365
+
366
+ const network = new vis.Network(visContainer, { nodes: visNodes, edges: visEdges }, getVisOptions());
367
+
368
+ // Sanitise string for safe inclusion in Mermaid grammar
369
+ function safeId(id) {
370
+ return id.replace(/[^a-zA-Z0-9_]/g, '_');
371
+ }
372
+
373
+ // Switch current UI language
374
+ function setLanguage(lang) {
375
+ currentLang = lang;
376
+ ['sv', 'en', 'ru'].forEach(l => {
377
+ document.getElementById(`lang-${l}`).className = (lang === l) ? 'active' : '';
378
+ });
379
+
380
+ const t = i18n[lang];
381
+ document.getElementById('lbl-onto-title').innerText = t.ontoTitle;
382
+ document.getElementById('lbl-graph-title').innerText = t.graphTitle;
383
+ document.getElementById('lbl-engine-title').innerText = t.engineTitle;
384
+ document.getElementById('step-btn').innerText = t.stepBtn;
385
+ document.getElementById('lbl-parent').innerText = t.parent;
386
+ document.getElementById('part-input').placeholder = t.partPlaceholder;
387
+ document.getElementById('add-btn').innerText = t.addBtn;
388
+ document.getElementById('remove-btn').innerText = t.removeBtn;
389
+ document.getElementById('lbl-history').innerText = t.history;
390
+ document.getElementById('title-bom').innerText = t.titleBom;
391
+ document.getElementById('title-query').innerText = t.titleQuery;
392
+ document.getElementById('title-storage').innerText = t.titleStorage;
393
+
394
+ render();
395
+ }
396
+
397
+ // Switch upper ontology paradigm
398
+ function setOntology(onto) {
399
+ currentOntology = onto;
400
+ document.getElementById('onto-bfo').className = (onto === 'BFO') ? 'active' : '';
401
+ document.getElementById('onto-iso').className = (onto === 'ISO15926') ? 'active' : '';
402
+ network.setOptions(getVisOptions());
403
+ render();
404
+ }
405
+
406
+ // Switch database model paradigm
407
+ function setGraphMode(mode) {
408
+ currentMode = mode;
409
+ document.getElementById('mode-lpg').className = (mode === 'LPG') ? 'active' : '';
410
+ document.getElementById('mode-rdf').className = (mode === 'RDF') ? 'active' : '';
411
+ network.setOptions(getVisOptions());
412
+ render();
413
+ }
414
+
415
+ // Switch active canvas rendering engine
416
+ function setEngine(engine) {
417
+ currentEngine = engine;
418
+ document.getElementById('eng-vis').className = (engine === 'vis') ? 'active' : '';
419
+ document.getElementById('eng-mermaid').className = (engine === 'mermaid') ? 'active' : '';
420
+
421
+ if (engine === 'vis') {
422
+ document.getElementById('vis-container').style.display = 'block';
423
+ document.getElementById('mermaid-container').style.display = 'none';
424
+ network.setOptions(getVisOptions());
425
+ network.fit();
426
+ } else {
427
+ document.getElementById('vis-container').style.display = 'none';
428
+ document.getElementById('mermaid-container').style.display = 'flex';
429
+ }
430
+ render();
431
+ }
432
+
433
+ // Add component relationship to master store
434
+ function addPart(parentId, name, silent = false) {
435
+ if (!name || !parentId) return;
436
+ const partId = name.trim();
437
+ if (parentId === partId) return;
438
+
439
+ const exists = edgesStore.find(e => e.from === parentId && e.to === partId && e.valid_to === null);
440
+ if (exists) return;
441
+
442
+ if (!baseNodes.some(n => n.id === partId)) {
443
+ baseNodes.push({ id: partId, label: partId, type: 'element' });
444
+ }
445
+
446
+ edgesStore.push({
447
+ id: 'e' + edgeSeq++,
448
+ from: parentId,
449
+ to: partId,
450
+ valid_from: currentTime,
451
+ valid_to: null
452
+ });
453
+
454
+ if (!silent) render();
455
+ }
456
+
457
+ // Handle user submission for adding a part
458
+ function handleAddPart() {
459
+ const parent = document.getElementById('parent-select').value;
460
+ const input = document.getElementById('part-input');
461
+ addPart(parent, input.value);
462
+ input.value = '';
463
+ }
464
+
465
+ // Sever relationship at current time coordinate
466
+ function handleRemoveEdge() {
467
+ const edgeId = document.getElementById('remove-select').value;
468
+ const edge = edgesStore.find(e => e.id === edgeId);
469
+ if (edge && edge.valid_to === null) {
470
+ edge.valid_to = currentTime;
471
+ }
472
+ render();
473
+ }
474
+
475
+ // Advance global discrete time coordinate
476
+ function advanceTime() {
477
+ currentTime++;
478
+ document.getElementById('time-display').innerText = `T = ${currentTime}`;
479
+ render();
480
+ }
481
+
482
+ // Recursive HTML tree builder for the end-user BOM viewpoint
483
+ function buildTreeHTML(nodeId, activeEdges) {
484
+ const children = activeEdges.filter(e => e.from === nodeId).map(e => e.to);
485
+ if (children.length === 0) return '';
486
+ let html = '<ul class="tree">';
487
+ children.forEach(childId => {
488
+ html += `<li><strong>${childId}</strong>${buildTreeHTML(childId, activeEdges)}</li>`;
489
+ });
490
+ html += '</ul>';
491
+ return html;
492
+ }
493
+
494
+ // Compile domain events into Vis.js representation
495
+ function renderVisData(visibleEdges) {
496
+ visNodes.clear();
497
+ visEdges.clear();
498
+
499
+ if (currentOntology === 'BFO') {
500
+ if (currentMode === 'LPG') {
501
+ // BFO + LPG: Continuant entities with temporal properties on edges
502
+ baseNodes.forEach(n => {
503
+ visNodes.add({
504
+ id: n.id,
505
+ label: `${n.label}\n(:bfo:MaterialEntity)`,
506
+ color: n.type === 'system' ? '#0284c7' : '#64748b',
507
+ font: { color: '#ffffff', bold: n.type === 'system' }
508
+ });
509
+ });
510
+ visibleEdges.forEach(e => {
511
+ visEdges.add({
512
+ id: e.id,
513
+ from: e.from,
514
+ to: e.to,
515
+ label: e.isActive ? `has_part: [T${e.valid_from}..now]` : `has_part: [T${e.valid_from}..T${e.valid_to}]`,
516
+ color: e.isActive ? { color: '#10b981' } : { color: '#cbd5e1' },
517
+ dashes: !e.isActive,
518
+ width: e.isActive ? 2 : 1
519
+ });
520
+ });
521
+ } else {
522
+ // BFO + RDF: W3C reification diamond nodes for temporal relation
523
+ baseNodes.forEach(n => {
524
+ visNodes.add({
525
+ id: n.id,
526
+ label: `:${n.label}\na bfo:MaterialEntity`,
527
+ color: n.type === 'system' ? '#0284c7' : '#475569',
528
+ font: { color: '#ffffff' }
529
+ });
530
+ });
531
+ visibleEdges.forEach(e => {
532
+ const stmtId = `stmt_${e.id}`;
533
+ const litFromId = `lit_from_${e.id}`;
534
+ const litToId = `lit_to_${e.id}`;
535
+
536
+ visNodes.add({
537
+ id: stmtId,
538
+ label: `_:${e.id}\na :TemporalPartMembership`,
539
+ shape: 'diamond',
540
+ size: 26,
541
+ color: e.isActive ? '#f59e0b' : '#e2e8f0',
542
+ font: { size: 9, color: e.isActive ? '#000000' : '#64748b' }
543
+ });
544
+
545
+ visEdges.add({ from: stmtId, to: e.from, label: ':hasParent', color: '#94a3b8' });
546
+ visEdges.add({ from: stmtId, to: e.to, label: ':hasChild', color: '#94a3b8' });
547
+ visNodes.add({ id: litFromId, label: `"T${e.valid_from}"^^xsd:int`, shape: 'box', color: '#f8fafc', font: { size: 8 } });
548
+ visEdges.add({ from: stmtId, to: litFromId, label: ':validFrom', color: '#cbd5e1' });
549
+
550
+ if (e.valid_to !== null) {
551
+ visNodes.add({ id: litToId, label: `"T${e.valid_to}"^^xsd:int`, shape: 'box', color: '#f8fafc', font: { size: 8 } });
552
+ visEdges.add({ from: stmtId, to: litToId, label: ':validTo', color: '#cbd5e1', dashes: true });
553
+ }
554
+ });
555
+ }
556
+ } else {
557
+ // ISO 15926 (4D Perdurantism)
558
+ baseNodes.forEach(n => {
559
+ visNodes.add({
560
+ id: `4d_${n.id}`,
561
+ label: `${n.label}_4D\n(iso:ActualIndividual)`,
562
+ color: '#4f46e5',
563
+ font: { color: '#ffffff', bold: true }
564
+ });
565
+ });
566
+
567
+ const parentStates = {};
568
+
569
+ visibleEdges.forEach(e => {
570
+ const parentStateId = `st_${e.from}_${e.id}`;
571
+ const childStateId = `st_${e.to}_${e.id}`;
572
+ const timeSpan = e.isActive ? `[T${e.valid_from}..now]` : `[T${e.valid_from}..T${e.valid_to}]`;
573
+
574
+ visNodes.add({
575
+ id: parentStateId,
576
+ label: `${e.from}_State\n${timeSpan}`,
577
+ color: '#0d9488',
578
+ font: { color: '#ffffff' }
579
+ });
580
+ visNodes.add({
581
+ id: childStateId,
582
+ label: `${e.to}_State\n${timeSpan}`,
583
+ color: '#0d9488',
584
+ font: { color: '#ffffff' }
585
+ });
586
+
587
+ // Link spatial-temporal slices to 4D individual extent
588
+ visEdges.add({ from: parentStateId, to: `4d_${e.from}`, label: 'temporalPartOf', color: '#94a3b8', dashes: true });
589
+ visEdges.add({ from: childStateId, to: `4d_${e.to}`, label: 'temporalPartOf', color: '#94a3b8', dashes: true });
590
+
591
+ if (currentMode === 'LPG') {
592
+ // LPG: Tenseless composition with revision attributes
593
+ visEdges.add({
594
+ from: parentStateId,
595
+ to: childStateId,
596
+ label: `COMPOSED_OF\n{qty:1, rev:'${e.id}'}`,
597
+ color: e.isActive ? { color: '#10b981' } : { color: '#cbd5e1' },
598
+ width: e.isActive ? 2 : 1
599
+ });
600
+
601
+ if (!parentStates[e.from]) parentStates[e.from] = [];
602
+ parentStates[e.from].push({ id: parentStateId, edge: e });
603
+ } else {
604
+ // RDF: Pure binary tenseless predicate
605
+ visEdges.add({
606
+ from: parentStateId,
607
+ to: childStateId,
608
+ label: ':hasPart',
609
+ color: e.isActive ? { color: '#10b981' } : { color: '#cbd5e1' },
610
+ width: e.isActive ? 2 : 1
611
+ });
612
+ }
613
+ });
614
+
615
+ // LPG: Model state transition chain (state progression)
616
+ if (currentMode === 'LPG') {
617
+ Object.keys(parentStates).forEach(parentId => {
618
+ const list = parentStates[parentId];
619
+ for (let i = 0; i < list.length - 1; i++) {
620
+ visEdges.add({
621
+ from: list[i].id,
622
+ to: list[i+1].id,
623
+ label: `TRANSITION_TO\n{at: T${list[i+1].edge.valid_from}}`,
624
+ color: { color: '#f59e0b' },
625
+ width: 2
626
+ });
627
+ }
628
+ });
629
+ }
630
+ }
631
+ }
632
+
633
+ // Compile domain events into Mermaid definition
634
+ function generateMermaidDef(visibleEdges) {
635
+ let def = 'flowchart TD\n';
636
+ def += ' classDef bfoSys fill:#0284c7,stroke:#0369a1,color:#ffffff,stroke-width:2px\n';
637
+ def += ' classDef bfoElem fill:#64748b,stroke:#475569,color:#ffffff,stroke-width:1px\n';
638
+ def += ' classDef iso4d fill:#4f46e5,stroke:#3730a3,color:#ffffff,stroke-width:2px\n';
639
+ def += ' classDef isoState fill:#0d9488,stroke:#0f766e,color:#ffffff,stroke-width:1px\n';
640
+ def += ' classDef rdfStmt fill:#f59e0b,stroke:#d97706,color:#000000,stroke-width:1px\n';
641
+ def += ' classDef rdfLit fill:#f1f5f9,stroke:#cbd5e1,color:#334155,stroke-dasharray:3 3\n\n';
642
+
643
+ if (currentOntology === 'BFO') {
644
+ if (currentMode === 'LPG') {
645
+ baseNodes.forEach(n => {
646
+ const sId = safeId(n.id);
647
+ const cls = n.type === 'system' ? 'bfoSys' : 'bfoElem';
648
+ def += ` ${sId}["<b>${n.label}</b><br/>bfo:MaterialEntity"]:::${cls}\n`;
649
+ });
650
+ visibleEdges.forEach(e => {
651
+ const f = safeId(e.from);
652
+ const t = safeId(e.to);
653
+ if (e.isActive) {
654
+ def += ` ${f} -->|"has_part: T${e.valid_from} → now"| ${t}\n`;
655
+ } else {
656
+ def += ` ${f} -.->|"has_part: T${e.valid_from} → T${e.valid_to}"| ${t}\n`;
657
+ }
658
+ });
659
+ } else {
660
+ baseNodes.forEach(n => {
661
+ const sId = safeId(n.id);
662
+ def += ` ${sId}["<b>:${n.label}</b><br/>a bfo:MaterialEntity"]:::bfoSys\n`;
663
+ });
664
+ visibleEdges.forEach(e => {
665
+ const stmtId = `stmt_${safeId(e.id)}`;
666
+ const f = safeId(e.from);
667
+ const t = safeId(e.to);
668
+ const lFrom = `lit_from_${safeId(e.id)}`;
669
+ const lTo = `lit_to_${safeId(e.id)}`;
670
+
671
+ def += ` ${stmtId}{{"<b>_:${e.id}</b><br/>a :TemporalPartMembership"}}:::rdfStmt\n`;
672
+ def += ` ${stmtId} -->|:hasParent| ${f}\n`;
673
+ def += ` ${stmtId} -->|:hasChild| ${t}\n`;
674
+ def += ` ${lFrom}(["T${e.valid_from} (xsd:int)"]):::rdfLit\n`;
675
+ def += ` ${stmtId} -->|:validFrom| ${lFrom}\n`;
676
+ if (e.valid_to !== null) {
677
+ def += ` ${lTo}(["T${e.valid_to} (xsd:int)"]):::rdfLit\n`;
678
+ def += ` ${stmtId} -.->|:validTo| ${lTo}\n`;
679
+ }
680
+ });
681
+ }
682
+ } else {
683
+ // ISO 15926 (4D)
684
+ baseNodes.forEach(n => {
685
+ const wId = `whole_${safeId(n.id)}`;
686
+ def += ` ${wId}["<b>${n.label}_4D</b><br/>iso:ActualIndividual"]:::iso4d\n`;
687
+ });
688
+
689
+ const parentStates = {};
690
+
691
+ visibleEdges.forEach(e => {
692
+ const pState = `st_${safeId(e.from)}_${safeId(e.id)}`;
693
+ const cState = `st_${safeId(e.to)}_${safeId(e.id)}`;
694
+ const pWhole = `whole_${safeId(e.from)}`;
695
+ const cWhole = `whole_${safeId(e.to)}`;
696
+ const span = e.isActive ? `T${e.valid_from} → now` : `T${e.valid_from} → T${e.valid_to}`;
697
+
698
+ def += ` ${pState}["${e.from}_State<br/>${span}"]:::isoState\n`;
699
+ def += ` ${cState}["${e.to}_State<br/>${span}"]:::isoState\n`;
700
+
701
+ def += ` ${pState} -.->|temporalPartOf| ${pWhole}\n`;
702
+ def += ` ${cState} -.->|temporalPartOf| ${cWhole}\n`;
703
+
704
+ if (currentMode === 'LPG') {
705
+ def += ` ${pState} -->|"COMPOSED_OF [qty:1]"| ${cState}\n`;
706
+ if (!parentStates[e.from]) parentStates[e.from] = [];
707
+ parentStates[e.from].push({ id: pState, edge: e });
708
+ } else {
709
+ def += ` ${pState} -->|:hasPart| ${cState}\n`;
710
+ }
711
+ });
712
+
713
+ if (currentMode === 'LPG') {
714
+ Object.keys(parentStates).forEach(parentId => {
715
+ const list = parentStates[parentId];
716
+ for (let i = 0; i < list.length - 1; i++) {
717
+ def += ` ${list[i].id} ==>|"TRANSITION_TO (at: T${list[i+1].edge.valid_from})"| ${list[i+1].id}\n`;
718
+ }
719
+ });
720
+ }
721
+ }
722
+
723
+ return def;
724
+ }
725
+
726
+ // Execute Mermaid rendering asynchronously with serialised queue
727
+ async function executeMermaidRender(chartDefinition) {
728
+ if (isRenderingMermaid) {
729
+ pendingMermaidDef = chartDefinition;
730
+ return;
731
+ }
732
+ isRenderingMermaid = true;
733
+ const container = document.getElementById('mermaid-container');
734
+
735
+ try {
736
+ const renderId = 'mermaid_svg_' + (++mermaidCounter);
737
+ const { svg } = await mermaid.render(renderId, chartDefinition);
738
+ container.innerHTML = svg;
739
+ } catch (err) {
740
+ console.error("Mermaid Render Error:", err);
741
+ } finally {
742
+ isRenderingMermaid = false;
743
+ if (pendingMermaidDef) {
744
+ const next = pendingMermaidDef;
745
+ pendingMermaidDef = null;
746
+ executeMermaidRender(next);
747
+ }
748
+ }
749
+ }
750
+
751
+ // Synchronise static legend glyphs with selected ontology and model
752
+ function updateLegend() {
753
+ const leg = i18n[currentLang].legend;
754
+ const container = document.getElementById('graph-legend');
755
+ const headerTag = `${currentOntology} + ${currentMode}`;
756
+
757
+ if (currentOntology === 'BFO') {
758
+ if (currentMode === 'LPG') {
759
+ container.innerHTML = `
760
+ <div class="legend-title"><span>${leg.title}</span> <span style="color:#0284c7;">${headerTag}</span></div>
761
+ <div class="legend-section">
762
+ <div class="legend-section-title">${leg.nodes}</div>
763
+ <div class="legend-item"><span class="swatch-box-sys"></span>${leg.bfoSys}</div>
764
+ <div class="legend-item"><span class="swatch-box-elem"></span>${leg.bfoElem}</div>
765
+ </div>
766
+ <div class="legend-section">
767
+ <div class="legend-section-title">${leg.edges}</div>
768
+ <div class="legend-item"><span class="swatch-line-active"></span>${leg.bfoActiveEdge}</div>
769
+ <div class="legend-item"><span class="swatch-line-past"></span>${leg.bfoPastEdge}</div>
770
+ </div>
771
+ `;
772
+ } else {
773
+ container.innerHTML = `
774
+ <div class="legend-title"><span>${leg.title}</span> <span style="color:#0284c7;">${headerTag}</span></div>
775
+ <div class="legend-section">
776
+ <div class="legend-section-title">${leg.nodes}</div>
777
+ <div class="legend-item"><span class="swatch-box-sys"></span>${leg.bfoSys}</div>
778
+ <div class="legend-item"><span class="swatch-diamond"></span>${leg.rdfStmt}</div>
779
+ <div class="legend-item"><span class="swatch-literal"></span>${leg.rdfLit}</div>
780
+ </div>
781
+ <div class="legend-section">
782
+ <div class="legend-section-title">${leg.edges}</div>
783
+ <div class="legend-item"><span class="swatch-line-pred"></span>${leg.rdfPred} (:hasParent, :validFrom)</div>
784
+ </div>
785
+ `;
786
+ }
787
+ } else {
788
+ const extraLpgEdge = (currentMode === 'LPG')
789
+ ? `<div class="legend-item"><span class="swatch-line-transition"></span>${leg.isoTransitionRel}</div>`
790
+ : '';
791
+
792
+ container.innerHTML = `
793
+ <div class="legend-title"><span>${leg.title}</span> <span style="color:#4f46e5;">${headerTag}</span></div>
794
+ <div class="legend-section">
795
+ <div class="legend-section-title">${leg.nodes}</div>
796
+ <div class="legend-item"><span class="swatch-box-4d"></span>${leg.iso4d}</div>
797
+ <div class="legend-item"><span class="swatch-box-state"></span>${leg.isoState}</div>
798
+ </div>
799
+ <div class="legend-section">
800
+ <div class="legend-section-title">${leg.edges}</div>
801
+ <div class="legend-item"><span class="swatch-line-active"></span>${leg.isoPartRel}</div>
802
+ <div class="legend-item"><span class="swatch-line-past"></span>${leg.isoSliceRel}</div>
803
+ ${extraLpgEdge}
804
+ </div>
805
+ `;
806
+ }
807
+ }
808
+
809
+ // Generate database query required to fetch BOM at time coordinate T
810
+ function generateDatabaseQuery() {
811
+ const queryTag = document.getElementById('query-lang-tag');
812
+ const queryContainer = document.getElementById('query-content');
813
+
814
+ if (currentOntology === 'BFO') {
815
+ if (currentMode === 'LPG') {
816
+ queryTag.innerText = 'Cypher (Neo4j / LPG)';
817
+ const cypher = `// Retrieve entire active BOM hierarchy of ${ROOT_ID} at T = ${currentTime}\n` +
818
+ `MATCH path = (root:System {id: '${ROOT_ID}'})-[:HAS_PART*]->(leaf:Element)\n` +
819
+ `WHERE ALL(r IN relationships(path)\n` +
820
+ ` WHERE r.valid_from <= ${currentTime} AND (r.valid_to > ${currentTime} OR r.valid_to IS NULL))\n` +
821
+ `RETURN [n IN nodes(path) | n.id] AS bom_path,\n` +
822
+ ` leaf.id AS component_id;\n` +
823
+ `// Complexity: O(k^d) traversal with in-memory relationship filtering`;
824
+ queryContainer.innerHTML = `<pre class="code-block">${cypher}</pre>`;
825
+ } else {
826
+ queryTag.innerText = 'SPARQL 1.1 (W3C RDF)';
827
+ const sparql = `# Retrieve active BOM for :${ROOT_ID} at T = ${currentTime} via reified statements\n` +
828
+ `PREFIX : <http://example.org/engineering#>\n` +
829
+ `PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n\n` +
830
+ `SELECT ?parent ?child\n` +
831
+ `WHERE {\n` +
832
+ ` ?rel a :TemporalPartMembership ;\n` +
833
+ ` :hasParent ?parent ;\n` +
834
+ ` :hasChild ?child ;\n` +
835
+ ` :validFrom ?validFrom .\n` +
836
+ ` OPTIONAL { ?rel :validTo ?validTo . }\n` +
837
+ ` FILTER (?validFrom <= ${currentTime} && (!BOUND(?validTo) || ?validTo > ${currentTime}))\n` +
838
+ `}\n` +
839
+ `# Complexity: Join-intensive index scan over intermediate statement nodes`;
840
+ queryContainer.innerHTML = `<pre class="code-block">${sparql}</pre>`;
841
+ }
842
+ } else {
843
+ // ISO 15926 (4D)
844
+ if (currentMode === 'LPG') {
845
+ queryTag.innerText = 'Cypher (ISO 15926 in LPG)';
846
+ const cypher = `// Traverse 4D states intersecting T = ${currentTime}\n` +
847
+ `MATCH (root4D:ActualIndividual {id: '4d_${ROOT_ID}'})<-[:temporalPartOf]-(rootState:State)\n` +
848
+ `WHERE rootState.valid_from <= ${currentTime} AND (rootState.valid_to > ${currentTime} OR rootState.valid_to IS NULL)\n` +
849
+ `MATCH path = (rootState)-[:COMPOSED_OF*]->(leafState:State)-[:temporalPartOf]->(leaf4D:ActualIndividual)\n` +
850
+ `RETURN root4D.id AS root, leaf4D.id AS component, leafState.id AS active_slice;\n` +
851
+ `// Benefit: Native fast traversal over timeless composition links`;
852
+ queryContainer.innerHTML = `<pre class="code-block">${cypher}</pre>`;
853
+ } else {
854
+ queryTag.innerText = 'SPARQL 1.1 (ISO 15926 Pure Binary Triples)';
855
+ const sparql = `# Pure binary 4D navigation for :${ROOT_ID} at T = ${currentTime}\n` +
856
+ `PREFIX iso: <http://standards.iso.org/iso/15926/part2#>\n` +
857
+ `PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n\n` +
858
+ `SELECT ?component4D ?activeStateSlice\n` +
859
+ `WHERE {\n` +
860
+ ` :${ROOT_ID}_4D ^iso:temporalPartOf ?rootState .\n` +
861
+ ` ?rootState iso:validFrom ?from .\n` +
862
+ ` OPTIONAL { ?rootState iso:validTo ?to . }\n` +
863
+ ` FILTER (?from <= ${currentTime} && (!BOUND(?to) || ?to > ${currentTime}))\n\n` +
864
+ ` ?rootState (iso:hasPart)+ ?activeStateSlice .\n` +
865
+ ` ?activeStateSlice iso:temporalPartOf ?component4D .\n` +
866
+ `}\n` +
867
+ `# Benefit: No reification; uses standard property path (iso:hasPart)+`;
868
+ queryContainer.innerHTML = `<pre class="code-block">${sparql}</pre>`;
869
+ }
870
+ }
871
+ }
872
+
873
+ // Core application render pipeline
874
+ function render() {
875
+ const t = i18n[currentLang];
876
+ const showHistory = document.getElementById('history-toggle').checked;
877
+
878
+ const activeEdges = [];
879
+ const visibleEdges = [];
880
+ edgesStore.forEach(edge => {
881
+ const isActive = (edge.valid_to === null || edge.valid_to > currentTime) && edge.valid_from <= currentTime;
882
+ const isPast = edge.valid_to !== null && edge.valid_to <= currentTime;
883
+ if (isActive) activeEdges.push(edge);
884
+ if (isActive || (isPast && showHistory)) visibleEdges.push({ ...edge, isActive });
885
+ });
886
+
887
+ // Render canvas through selected engine
888
+ if (currentEngine === 'vis') {
889
+ renderVisData(visibleEdges);
890
+ } else {
891
+ executeMermaidRender(generateMermaidDef(visibleEdges));
892
+ }
893
+
894
+ // Update static legend
895
+ updateLegend();
896
+
897
+ // Render end-user BOM hierarchy
898
+ const treeContainer = document.getElementById('tree-container');
899
+ treeContainer.innerHTML = `<strong>${ROOT_ID}</strong>` + buildTreeHTML(ROOT_ID, activeEdges);
900
+
901
+ // Populate interactive authoring dropdowns
902
+ const parentSelect = document.getElementById('parent-select');
903
+ const removeSelect = document.getElementById('remove-select');
904
+ parentSelect.innerHTML = '';
905
+ removeSelect.innerHTML = '';
906
+
907
+ const activeNodes = new Set([ROOT_ID]);
908
+ activeEdges.forEach(e => { activeNodes.add(e.from); activeNodes.add(e.to); });
909
+ activeNodes.forEach(id => {
910
+ const opt = document.createElement('option');
911
+ opt.value = id; opt.innerText = id;
912
+ parentSelect.appendChild(opt);
913
+ });
914
+
915
+ activeEdges.forEach(e => {
916
+ const opt = document.createElement('option');
917
+ opt.value = e.id;
918
+ opt.innerText = `${e.from} → ${e.to}`;
919
+ removeSelect.appendChild(opt);
920
+ });
921
+
922
+ // Render query comparison card
923
+ generateDatabaseQuery();
924
+
925
+ // Render physical storage card
926
+ const storageTag = document.getElementById('storage-paradigm-tag');
927
+ const storageContent = document.getElementById('storage-content');
928
+ storageTag.innerText = `${currentOntology} / ${currentMode}`;
929
+
930
+ if (currentOntology === 'BFO') {
931
+ if (currentMode === 'LPG') {
932
+ let html = `<table><thead><tr><th>${t.sourceCol}</th><th>${t.targetCol}</th><th>valid_from</th><th>valid_to</th><th>${t.statusCol}</th></tr></thead><tbody>`;
933
+ edgesStore.forEach(edge => {
934
+ const isActive = (edge.valid_to === null || edge.valid_to > currentTime) && edge.valid_from <= currentTime;
935
+ html += `<tr class="${isActive ? 'active-row' : 'closed-row'}">
936
+ <td>${edge.from}</td><td><strong>${edge.to}</strong></td>
937
+ <td>T${edge.valid_from}</td><td>${edge.valid_to !== null ? 'T' + edge.valid_to : '—'}</td>
938
+ <td>${isActive ? t.activeStatus : t.closedStatus}</td>
939
+ </tr>`;
940
+ });
941
+ html += '</tbody></table>';
942
+ storageContent.innerHTML = html;
943
+ } else {
944
+ let ttl = `# BFO 3D: RDF Turtle with Reification\n`;
945
+ edgesStore.forEach(e => {
946
+ const isActive = (e.valid_to === null || edge.valid_to > currentTime) && edge.valid_from <= currentTime;
947
+ if (!isActive && !showHistory) return;
948
+ ttl += `\n_:${e.id} a :TemporalPartMembership ;\n`;
949
+ ttl += ` :hasParent :${e.from} ;\n`;
950
+ ttl += ` :hasChild :${e.to} ;\n`;
951
+ ttl += ` :validFrom "${e.valid_from}"^^xsd:integer ${e.valid_to !== null ? ';\n :validTo "' + e.valid_to + '"^^xsd:integer .' : ' .'}\n`;
952
+ });
953
+ storageContent.innerHTML = `<pre class="code-block">${ttl}</pre>`;
954
+ }
955
+ } else {
956
+ // ISO 15926
957
+ if (currentMode === 'LPG') {
958
+ let html = `<table><thead><tr><th>Parent Slice</th><th>Child Slice</th><th>LPG Rel Properties</th><th>4D Extent</th></tr></thead><tbody>`;
959
+ visibleEdges.forEach(e => {
960
+ const span = e.isActive ? `[T${e.valid_from}..now]` : `[T${e.valid_from}..T${e.valid_to}]`;
961
+ html += `<tr class="${e.isActive ? 'active-row' : 'closed-row'}">
962
+ <td>${e.from}_State</td><td><strong>${e.to}_State</strong></td>
963
+ <td><code>{qty: 1, rev: '${e.id}', span: '${span}'}</code></td>
964
+ <td>${e.from}_4D, ${e.to}_4D</td>
965
+ </tr>`;
966
+ });
967
+ html += '</tbody></table>';
968
+ storageContent.innerHTML = html;
969
+ } else {
970
+ let ttl = `# ISO 15926-2: Pure Binary RDF Triples (Tenseless Composition)\n`;
971
+ visibleEdges.forEach(e => {
972
+ const pState = `:${e.from}_state_${e.id}`;
973
+ const cState = `:${e.to}_state_${e.id}`;
974
+ ttl += `\n:${e.from}_4D a iso:ActualIndividual .\n`;
975
+ ttl += `:${e.to}_4D a iso:ActualIndividual .\n`;
976
+ ttl += `${pState} a iso:State ;\n iso:temporalPartOf :${e.from}_4D ;\n iso:hasPart ${cState} .\n`;
977
+ ttl += `${cState} a iso:State ;\n iso:temporalPartOf :${e.to}_4D .\n`;
978
+ });
979
+ storageContent.innerHTML = `<pre class="code-block">${ttl}</pre>`;
980
+ }
981
+ }
982
+ }
983
+
984
+ // Initial baseline data at T=0
985
+ addPart(ROOT_ID, 'SubAssembly_1', true);
986
+ addPart(ROOT_ID, 'Part_A', true);
987
+ addPart('SubAssembly_1', 'Sensor_X', true);
988
+
989
+ // Initialise default localisation
990
+ setLanguage('sv');
991
+ </script>
992
+ </body>
993
+ </html>