Spaces:
Running
Running
JS bug fix
Browse files
script.js
CHANGED
|
@@ -107,10 +107,21 @@ function getVisOptions() {
|
|
| 107 |
return {
|
| 108 |
physics: {
|
| 109 |
stabilization: { iterations: 120 },
|
| 110 |
-
barnesHut: {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
},
|
| 112 |
nodes: { shape: 'box', margin: 10, font: { size: 12, face: 'system-ui' }, borderWidth: 1.5 },
|
| 113 |
-
edges: {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
};
|
| 115 |
}
|
| 116 |
|
|
@@ -182,7 +193,6 @@ function setEngine(engine) {
|
|
| 182 |
render();
|
| 183 |
}
|
| 184 |
|
| 185 |
-
// Export/Import JSON logic
|
| 186 |
function exportData() {
|
| 187 |
const data = { baseNodes, edgesStore, currentTime, edgeSeq };
|
| 188 |
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
|
|
@@ -263,52 +273,88 @@ function buildTreeHTML(nodeId, activeEdges) {
|
|
| 263 |
}
|
| 264 |
|
| 265 |
function renderVisData(visibleEdges) {
|
| 266 |
-
visNodes.clear();
|
|
|
|
| 267 |
|
| 268 |
if (currentOntology === 'BFO') {
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
dashes: !e.isActive,
|
| 305 |
-
width: e.isActive ? 2 : 1,
|
| 306 |
-
smooth: smoothConfig
|
| 307 |
-
});
|
| 308 |
-
});
|
| 309 |
});
|
| 310 |
-
}
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
const parentStates = {};
|
| 313 |
|
| 314 |
visibleEdges.forEach(e => {
|
|
@@ -321,11 +367,23 @@ function renderVisData(visibleEdges) {
|
|
| 321 |
visEdges.add({ from: childStateId, to: `4d_${e.to}`, label: 'temporalPartOf', color: '#94a3b8', dashes: true });
|
| 322 |
|
| 323 |
if (currentMode === 'LPG') {
|
| 324 |
-
visEdges.add({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
if (!parentStates[e.from]) parentStates[e.from] = [];
|
| 326 |
parentStates[e.from].push({ id: parentStateId, edge: e });
|
| 327 |
} else {
|
| 328 |
-
visEdges.add({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 329 |
}
|
| 330 |
});
|
| 331 |
|
|
@@ -333,7 +391,13 @@ function renderVisData(visibleEdges) {
|
|
| 333 |
Object.keys(parentStates).forEach(parentId => {
|
| 334 |
const list = parentStates[parentId];
|
| 335 |
for (let i = 0; i < list.length - 1; i++) {
|
| 336 |
-
visEdges.add({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
}
|
| 338 |
});
|
| 339 |
}
|
|
@@ -451,7 +515,7 @@ function render() {
|
|
| 451 |
} else {
|
| 452 |
let ttl = `# BFO 3D in SMS: RDF Turtle with Reification\n`;
|
| 453 |
edgesStore.forEach(e => {
|
| 454 |
-
const isActive = (e.valid_to === null ||
|
| 455 |
if (!isActive && !showHistory) return;
|
| 456 |
ttl += `\n_:${e.id} a :TemporalPartMembership ;\n :hasParent :${e.from} ;\n :hasChild :${e.to} ;\n :validFrom "${e.valid_from}"^^xsd:integer ${e.valid_to !== null ? ';\n :validTo "' + e.valid_to + '"^^xsd:integer .' : ' .'}\n`;
|
| 457 |
});
|
|
|
|
| 107 |
return {
|
| 108 |
physics: {
|
| 109 |
stabilization: { iterations: 120 },
|
| 110 |
+
barnesHut: {
|
| 111 |
+
gravitationalConstant: isComplex ? -24000 : -10000,
|
| 112 |
+
centralGravity: 0.25,
|
| 113 |
+
springLength: isComplex ? 220 : 150,
|
| 114 |
+
springConstant: 0.04,
|
| 115 |
+
damping: 0.09,
|
| 116 |
+
avoidOverlap: 1
|
| 117 |
+
}
|
| 118 |
},
|
| 119 |
nodes: { shape: 'box', margin: 10, font: { size: 12, face: 'system-ui' }, borderWidth: 1.5 },
|
| 120 |
+
edges: {
|
| 121 |
+
arrows: 'to',
|
| 122 |
+
smooth: { type: 'continuous', roundness: 0.2 },
|
| 123 |
+
font: { size: 10, align: 'middle', background: '#ffffff', strokeWidth: 0 }
|
| 124 |
+
}
|
| 125 |
};
|
| 126 |
}
|
| 127 |
|
|
|
|
| 193 |
render();
|
| 194 |
}
|
| 195 |
|
|
|
|
| 196 |
function exportData() {
|
| 197 |
const data = { baseNodes, edgesStore, currentTime, edgeSeq };
|
| 198 |
const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
|
|
|
|
| 273 |
}
|
| 274 |
|
| 275 |
function renderVisData(visibleEdges) {
|
| 276 |
+
visNodes.clear();
|
| 277 |
+
visEdges.clear();
|
| 278 |
|
| 279 |
if (currentOntology === 'BFO') {
|
| 280 |
+
if (currentMode === 'LPG') {
|
| 281 |
+
baseNodes.forEach(n => {
|
| 282 |
+
visNodes.add({
|
| 283 |
+
id: n.id,
|
| 284 |
+
label: `${n.label}\n(:bfo:MaterialEntity)`,
|
| 285 |
+
color: n.type === 'system' ? '#0284c7' : '#64748b',
|
| 286 |
+
font: { color: '#ffffff', bold: n.type === 'system' }
|
| 287 |
+
});
|
| 288 |
+
});
|
| 289 |
|
| 290 |
+
// Группируем ребра по направленной паре (from -> to) для веерного расхождения
|
| 291 |
+
const pairMap = {};
|
| 292 |
+
visibleEdges.forEach(e => {
|
| 293 |
+
const pairKey = `${e.from}->${e.to}`;
|
| 294 |
+
if (!pairMap[pairKey]) pairMap[pairKey] = [];
|
| 295 |
+
pairMap[pairKey].push(e);
|
| 296 |
+
});
|
| 297 |
|
| 298 |
+
Object.values(pairMap).forEach(edgesGroup => {
|
| 299 |
+
edgesGroup.sort((a, b) => a.valid_from - b.valid_from);
|
| 300 |
+
const count = edgesGroup.length;
|
| 301 |
+
edgesGroup.forEach((e, idx) => {
|
| 302 |
+
const smoothConfig = count === 1
|
| 303 |
+
? { type: 'continuous', roundness: 0.2 }
|
| 304 |
+
: { type: 'curvedCW', roundness: Math.min(0.14 + (idx * 0.14), 0.85) };
|
| 305 |
+
|
| 306 |
+
visEdges.add({
|
| 307 |
+
id: e.id,
|
| 308 |
+
from: e.from,
|
| 309 |
+
to: e.to,
|
| 310 |
+
label: e.isActive ? `has_part: [T${e.valid_from}..now]` : `has_part: [T${e.valid_from}..T${e.valid_to}]`,
|
| 311 |
+
color: e.isActive ? { color: '#10b981' } : { color: '#cbd5e1' },
|
| 312 |
+
dashes: !e.isActive,
|
| 313 |
+
width: e.isActive ? 2 : 1,
|
| 314 |
+
smooth: smoothConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
});
|
| 316 |
+
});
|
| 317 |
+
});
|
| 318 |
+
} else {
|
| 319 |
+
// BFO + RDF (W3C Reification)
|
| 320 |
+
baseNodes.forEach(n => {
|
| 321 |
+
visNodes.add({
|
| 322 |
+
id: n.id,
|
| 323 |
+
label: `:${n.label}\na bfo:MaterialEntity`,
|
| 324 |
+
color: n.type === 'system' ? '#0284c7' : '#475569',
|
| 325 |
+
font: { color: '#ffffff' }
|
| 326 |
+
});
|
| 327 |
+
});
|
| 328 |
+
visibleEdges.forEach(e => {
|
| 329 |
+
const stmtId = `stmt_${e.id}`, litFromId = `lit_from_${e.id}`, litToId = `lit_to_${e.id}`;
|
| 330 |
+
visNodes.add({
|
| 331 |
+
id: stmtId,
|
| 332 |
+
label: `_:${e.id}\na :TemporalPartMembership`,
|
| 333 |
+
shape: 'diamond',
|
| 334 |
+
size: 26,
|
| 335 |
+
color: e.isActive ? '#f59e0b' : '#e2e8f0',
|
| 336 |
+
font: { size: 9, color: e.isActive ? '#000000' : '#64748b' }
|
| 337 |
+
});
|
| 338 |
+
visEdges.add({ from: stmtId, to: e.from, label: ':hasParent', color: '#94a3b8' });
|
| 339 |
+
visEdges.add({ from: stmtId, to: e.to, label: ':hasChild', color: '#94a3b8' });
|
| 340 |
+
visNodes.add({ id: litFromId, label: `"T${e.valid_from}"^^xsd:int`, shape: 'box', color: '#f8fafc', font: { size: 8 } });
|
| 341 |
+
visEdges.add({ from: stmtId, to: litFromId, label: ':validFrom', color: '#cbd5e1' });
|
| 342 |
+
if (e.valid_to !== null) {
|
| 343 |
+
visNodes.add({ id: litToId, label: `"T${e.valid_to}"^^xsd:int`, shape: 'box', color: '#f8fafc', font: { size: 8 } });
|
| 344 |
+
visEdges.add({ from: stmtId, to: litToId, label: ':validTo', color: '#cbd5e1', dashes: true });
|
| 345 |
+
}
|
| 346 |
+
});
|
| 347 |
+
}
|
| 348 |
+
} else {
|
| 349 |
+
// ISO 15926 (4D Individuals & Temporal Slices)
|
| 350 |
+
baseNodes.forEach(n => {
|
| 351 |
+
visNodes.add({
|
| 352 |
+
id: `4d_${n.id}`,
|
| 353 |
+
label: `${n.label}_4D\n(iso:ActualIndividual)`,
|
| 354 |
+
color: '#4f46e5',
|
| 355 |
+
font: { color: '#ffffff', bold: true }
|
| 356 |
+
});
|
| 357 |
+
});
|
| 358 |
const parentStates = {};
|
| 359 |
|
| 360 |
visibleEdges.forEach(e => {
|
|
|
|
| 367 |
visEdges.add({ from: childStateId, to: `4d_${e.to}`, label: 'temporalPartOf', color: '#94a3b8', dashes: true });
|
| 368 |
|
| 369 |
if (currentMode === 'LPG') {
|
| 370 |
+
visEdges.add({
|
| 371 |
+
from: parentStateId,
|
| 372 |
+
to: childStateId,
|
| 373 |
+
label: `COMPOSED_OF\n{qty:1, rev:'${e.id}'}`,
|
| 374 |
+
color: e.isActive ? { color: '#10b981' } : { color: '#cbd5e1' },
|
| 375 |
+
width: e.isActive ? 2 : 1
|
| 376 |
+
});
|
| 377 |
if (!parentStates[e.from]) parentStates[e.from] = [];
|
| 378 |
parentStates[e.from].push({ id: parentStateId, edge: e });
|
| 379 |
} else {
|
| 380 |
+
visEdges.add({
|
| 381 |
+
from: parentStateId,
|
| 382 |
+
to: childStateId,
|
| 383 |
+
label: ':hasPart',
|
| 384 |
+
color: e.isActive ? { color: '#10b981' } : { color: '#cbd5e1' },
|
| 385 |
+
width: e.isActive ? 2 : 1
|
| 386 |
+
});
|
| 387 |
}
|
| 388 |
});
|
| 389 |
|
|
|
|
| 391 |
Object.keys(parentStates).forEach(parentId => {
|
| 392 |
const list = parentStates[parentId];
|
| 393 |
for (let i = 0; i < list.length - 1; i++) {
|
| 394 |
+
visEdges.add({
|
| 395 |
+
from: list[i].id,
|
| 396 |
+
to: list[i+1].id,
|
| 397 |
+
label: `TRANSITION_TO\n{at: T${list[i+1].edge.valid_from}}`,
|
| 398 |
+
color: { color: '#f59e0b' },
|
| 399 |
+
width: 2
|
| 400 |
+
});
|
| 401 |
}
|
| 402 |
});
|
| 403 |
}
|
|
|
|
| 515 |
} else {
|
| 516 |
let ttl = `# BFO 3D in SMS: RDF Turtle with Reification\n`;
|
| 517 |
edgesStore.forEach(e => {
|
| 518 |
+
const isActive = (e.valid_to === null || edge.valid_to > currentTime) && edge.valid_from <= currentTime;
|
| 519 |
if (!isActive && !showHistory) return;
|
| 520 |
ttl += `\n_:${e.id} a :TemporalPartMembership ;\n :hasParent :${e.from} ;\n :hasChild :${e.to} ;\n :validFrom "${e.valid_from}"^^xsd:integer ${e.valid_to !== null ? ';\n :validTo "' + e.valid_to + '"^^xsd:integer .' : ' .'}\n`;
|
| 521 |
});
|