mdld-parse 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -1
- package/dist/.nojekyll +0 -0
- package/dist/CNAME +1 -0
- package/dist/README.md +425 -0
- package/dist/docs/API.md +397 -0
- package/dist/docs/Architecture.md +190 -0
- package/dist/docs/Guide.md +322 -0
- package/dist/docs/LLM-MDLD-Inducer.md +550 -0
- package/dist/docs/Parser.md +654 -0
- package/dist/docs/Performance.md +238 -0
- package/dist/docs/Spec-render.md +1439 -0
- package/dist/docs/Subject.md +180 -0
- package/dist/docs/Syntax.md +463 -0
- package/dist/docs/TodoList.md +215 -0
- package/dist/docs/Use-Cases.md +354 -0
- package/dist/docs/index.html +108 -0
- package/dist/docs/index.md +56 -0
- package/dist/docs/origin.md +459 -0
- package/dist/docs/polarity.md +586 -0
- package/dist/docs/primary-subject.md +199 -0
- package/dist/docs/statements.md +226 -0
- package/dist/docs/tokenization-performance-report.md +164 -0
- package/dist/examples/Cookbook.md +32 -0
- package/dist/examples/Status-SHACL.md +33 -0
- package/dist/examples/demo/index.md +35 -0
- package/dist/examples/demo/journal.md +18 -0
- package/dist/examples/demo/minimal.md +11 -0
- package/dist/examples/demo/project.md +15 -0
- package/dist/examples/demo/recipe.md +31 -0
- package/dist/examples/demo/research.md +46 -0
- package/dist/examples/demo/space-mission.md +48 -0
- package/dist/examples/dogfood.md +288 -0
- package/dist/examples/few-shot.md +309 -0
- package/dist/examples/graph/rdf-graph.html +473 -0
- package/dist/examples/graph/rdf_force_graph_web_component.html +506 -0
- package/dist/examples/index.md +45 -0
- package/dist/examples/llm-time-workflow.md +173 -0
- package/dist/examples/prov-o.md +2367 -0
- package/dist/examples/rdf.md +827 -0
- package/dist/examples/shacl.md +3399 -0
- package/dist/examples/statements.md +43 -0
- package/dist/examples/workflow.md +150 -0
- package/dist/index.html +2827 -0
- package/dist/index.js +1548 -0
- package/dist/logo.svg +7 -0
- package/dist/spec/Spec-compact.md +363 -0
- package/dist/spec/Spec-ultra.md +221 -0
- package/dist/spec/Spec.md +1068 -0
- package/dist/spec/index.md +46 -0
- package/package.json +13 -8
- package/src/constants.js +0 -31
- package/src/generate.js +0 -245
- package/src/index.js +0 -13
- package/src/locate.js +0 -23
- package/src/merge.js +0 -157
- package/src/parse.js +0 -765
- package/src/render.js +0 -576
- package/src/shared.js +0 -577
- package/src/utils.js +0 -430
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
6
|
+
<title>rdf-graph</title>
|
|
7
|
+
<style>
|
|
8
|
+
*{box-sizing:border-box;margin:0;padding:0}
|
|
9
|
+
html,body{width:100%;height:100%;overflow:hidden;background:#020408}
|
|
10
|
+
rdf-graph{display:block;width:100vw;height:100vh}
|
|
11
|
+
/* scanlines overlay */
|
|
12
|
+
body::after{content:'';position:fixed;inset:0;background:repeating-linear-gradient(0deg,transparent,transparent 2px,rgba(0,0,0,.18) 2px,rgba(0,0,0,.18) 4px);pointer-events:none;z-index:9999}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<rdf-graph id="g"></rdf-graph>
|
|
17
|
+
|
|
18
|
+
<script>
|
|
19
|
+
/**
|
|
20
|
+
* <rdf-graph> — RDF Quad Force Graph Web Component
|
|
21
|
+
* W3C Custom Elements v1 · Shadow DOM · SVG · No deps
|
|
22
|
+
* API: el.quads = Array<{subject,predicate,object,termType}>
|
|
23
|
+
*/
|
|
24
|
+
customElements.define('rdf-graph', class extends HTMLElement {
|
|
25
|
+
|
|
26
|
+
connectedCallback() {
|
|
27
|
+
const sh = this.attachShadow({ mode: 'open' });
|
|
28
|
+
sh.innerHTML = `<style>
|
|
29
|
+
:host{display:block;width:100%;height:100%;overflow:hidden}
|
|
30
|
+
svg{width:100%;height:100%;font-family:'Courier New',monospace}
|
|
31
|
+
.node{cursor:grab}.node:active{cursor:grabbing}
|
|
32
|
+
</style>
|
|
33
|
+
<svg id="v" xmlns="http://www.w3.org/2000/svg">
|
|
34
|
+
<defs>
|
|
35
|
+
<!-- glow for nodes -->
|
|
36
|
+
<filter id="glow" x="-60%" y="-60%" width="220%" height="220%">
|
|
37
|
+
<feGaussianBlur stdDeviation="3" result="blur"/>
|
|
38
|
+
<feMerge><feMergeNode in="blur"/><feMergeNode in="SourceGraphic"/></feMerge>
|
|
39
|
+
</filter>
|
|
40
|
+
<!-- arrowhead for regular links -->
|
|
41
|
+
<marker id="arr" markerWidth="7" markerHeight="7" refX="6" refY="3.5"
|
|
42
|
+
orient="auto" markerUnits="userSpaceOnUse">
|
|
43
|
+
<path d="M0,1 L7,3.5 L0,6z" fill="#2a4a7a"/>
|
|
44
|
+
</marker>
|
|
45
|
+
<!-- arrowhead for type links -->
|
|
46
|
+
<marker id="tarr" markerWidth="5" markerHeight="5" refX="4" refY="2.5"
|
|
47
|
+
orient="auto" markerUnits="userSpaceOnUse">
|
|
48
|
+
<path d="M0,0.5 L5,2.5 L0,4.5z" fill="#102030"/>
|
|
49
|
+
</marker>
|
|
50
|
+
</defs>
|
|
51
|
+
<!-- CRT grid -->
|
|
52
|
+
<g id="grid" opacity="1"></g>
|
|
53
|
+
<!-- layer: links behind nodes -->
|
|
54
|
+
<g id="ll"></g>
|
|
55
|
+
<!-- layer: nodes on top -->
|
|
56
|
+
<g id="nn"></g>
|
|
57
|
+
<!-- HUD corner text -->
|
|
58
|
+
<text id="hud" x="8" y="14" fill="#1a3a2a" font-size="8" font-family="'Courier New',monospace">rdf-graph v1</text>
|
|
59
|
+
</svg>`;
|
|
60
|
+
|
|
61
|
+
this._v = sh.getElementById('v');
|
|
62
|
+
this._ll = sh.getElementById('ll');
|
|
63
|
+
this._nn = sh.getElementById('nn');
|
|
64
|
+
this._gr = sh.getElementById('grid');
|
|
65
|
+
this._hud= sh.getElementById('hud');
|
|
66
|
+
|
|
67
|
+
this._initDrag();
|
|
68
|
+
|
|
69
|
+
new ResizeObserver(() => this._onResize()).observe(this);
|
|
70
|
+
|
|
71
|
+
if (this._q) this._build(this._q);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ── public API ───────────────────────────────────────────── */
|
|
75
|
+
set quads(q) { this._q = q; if (this._v) this._build(q); }
|
|
76
|
+
|
|
77
|
+
/* ── drag ─────────────────────────────────────────────────── */
|
|
78
|
+
_initDrag() {
|
|
79
|
+
let drag = null;
|
|
80
|
+
this._v.addEventListener('pointerdown', e => {
|
|
81
|
+
const g = e.composedPath().find(el => el.dataset?.i !== undefined);
|
|
82
|
+
if (!g) return;
|
|
83
|
+
drag = { i: +g.dataset.i };
|
|
84
|
+
g.setPointerCapture(e.pointerId);
|
|
85
|
+
});
|
|
86
|
+
this._v.addEventListener('pointermove', e => {
|
|
87
|
+
if (drag === null) return;
|
|
88
|
+
const n = this._na[drag.i];
|
|
89
|
+
const r = this._v.getBoundingClientRect();
|
|
90
|
+
const vb = this._v.viewBox.baseVal;
|
|
91
|
+
n.x += e.movementX * (vb.width / r.width);
|
|
92
|
+
n.y += e.movementY * (vb.height / r.height);
|
|
93
|
+
n.vx = n.vy = 0;
|
|
94
|
+
n.pinned = true;
|
|
95
|
+
});
|
|
96
|
+
this._v.addEventListener('pointerup', () => {
|
|
97
|
+
if (drag !== null && this._na[drag.i]) this._na[drag.i].pinned = false;
|
|
98
|
+
drag = null;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* ── resize ───────────────────────────────────────────────── */
|
|
103
|
+
_onResize() {
|
|
104
|
+
const W = this.clientWidth || 800;
|
|
105
|
+
const H = this.clientHeight || 600;
|
|
106
|
+
this._W = W; this._H = H;
|
|
107
|
+
this._v.setAttribute('viewBox', `0 0 ${W} ${H}`);
|
|
108
|
+
this._drawGrid(W, H);
|
|
109
|
+
if (this._na && !this._built) {
|
|
110
|
+
// first resize after build → relax center
|
|
111
|
+
const cx = W/2, cy = H/2;
|
|
112
|
+
for (const n of this._na) { n.x += cx - W/2; n.y += cy - H/2; }
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* ── grid ─────────────────────────────────────────────────── */
|
|
117
|
+
_drawGrid(W, H) {
|
|
118
|
+
const step = 44;
|
|
119
|
+
let s = '';
|
|
120
|
+
for (let x = 0; x <= W; x += step)
|
|
121
|
+
s += `<line x1="${x}" y1="0" x2="${x}" y2="${H}" stroke="#0b1f30" stroke-width=".5"/>`;
|
|
122
|
+
for (let y = 0; y <= H; y += step)
|
|
123
|
+
s += `<line x1="0" y1="${y}" x2="${W}" y2="${y}" stroke="#0b1f30" stroke-width=".5"/>`;
|
|
124
|
+
// crosshair at center
|
|
125
|
+
s += `<circle cx="${W/2|0}" cy="${H/2|0}" r="2" fill="none" stroke="#0f2840" stroke-width=".5"/>`;
|
|
126
|
+
s += `<line x1="${W/2|0}" y1="${H/2-6|0}" x2="${W/2|0}" y2="${H/2+6|0}" stroke="#0f2840" stroke-width=".5"/>`;
|
|
127
|
+
s += `<line x1="${W/2-6|0}" y1="${H/2|0}" x2="${W/2+6|0}" y2="${H/2|0}" stroke="#0f2840" stroke-width=".5"/>`;
|
|
128
|
+
this._gr.innerHTML = s;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/* ── utils ────────────────────────────────────────────────── */
|
|
132
|
+
_hash(s) {
|
|
133
|
+
// djb2 variant
|
|
134
|
+
let h = 5381;
|
|
135
|
+
for (let i = 0; i < s.length; i++) h = (h * 33 ^ s.charCodeAt(i)) >>> 0;
|
|
136
|
+
return h;
|
|
137
|
+
}
|
|
138
|
+
_shorten(u) {
|
|
139
|
+
// last segment after # / : for readable labels
|
|
140
|
+
const m = u.match(/[#\/:]([^#\/:?]+)(?:[?#].*)?$/);
|
|
141
|
+
const s = (m ? m[1] : u).replace(/[^\w\-\.]/g, '');
|
|
142
|
+
return s.slice(0, 18) || u.slice(-8);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* ── build graph from quads ───────────────────────────────── */
|
|
146
|
+
_build(quads) {
|
|
147
|
+
const TYPE = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
|
|
148
|
+
const idx = Object.create(null); // iri → node index
|
|
149
|
+
const na = []; // node array
|
|
150
|
+
const la = []; // link array
|
|
151
|
+
const types = Object.create(null);// subject iri → type iri
|
|
152
|
+
|
|
153
|
+
const getNode = iri => {
|
|
154
|
+
if (iri in idx) return idx[iri];
|
|
155
|
+
const i = na.length;
|
|
156
|
+
idx[iri] = i;
|
|
157
|
+
na.push({ id: iri, r: 9, vx: 0, vy: 0, pinned: false });
|
|
158
|
+
return i;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// pass 1: collect rdf:type declarations
|
|
162
|
+
for (const q of quads)
|
|
163
|
+
if (q.predicate.value === TYPE && q.object.termType === 'NamedNode')
|
|
164
|
+
types[q.subject.value] = q.object.value;
|
|
165
|
+
|
|
166
|
+
// pass 2: build nodes + links
|
|
167
|
+
for (const q of quads) {
|
|
168
|
+
const si = getNode(q.subject.value);
|
|
169
|
+
if (q.object.termType === 'Literal') {
|
|
170
|
+
// literals → grow subject node
|
|
171
|
+
na[si].r = Math.min(na[si].r + 1.4, 24);
|
|
172
|
+
} else if (q.object.termType === 'NamedNode') {
|
|
173
|
+
const oi = getNode(q.object.value);
|
|
174
|
+
la.push({
|
|
175
|
+
s: si,
|
|
176
|
+
o: oi,
|
|
177
|
+
p: this._shorten(q.predicate.value),
|
|
178
|
+
isType: q.predicate.value === TYPE
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// pass 3: colour by type, label
|
|
184
|
+
for (let i = 0; i < na.length; i++) {
|
|
185
|
+
const n = na[i];
|
|
186
|
+
const t = types[n.id];
|
|
187
|
+
const h = this._hash(t || n.id) % 360;
|
|
188
|
+
if (t) {
|
|
189
|
+
n.color = `hsl(${h},75%,52%)`;
|
|
190
|
+
n.glow = `hsl(${h},90%,72%)`;
|
|
191
|
+
n.stroke = `hsl(${h},60%,70%)`;
|
|
192
|
+
} else {
|
|
193
|
+
n.color = `hsl(${h},18%,32%)`;
|
|
194
|
+
n.glow = `hsl(${h},30%,55%)`;
|
|
195
|
+
n.stroke = `hsl(${h},25%,48%)`;
|
|
196
|
+
}
|
|
197
|
+
n.label = this._shorten(n.id);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const W = this.clientWidth || 800;
|
|
201
|
+
const H = this.clientHeight || 600;
|
|
202
|
+
this._W = W; this._H = H;
|
|
203
|
+
this._v.setAttribute('viewBox', `0 0 ${W} ${H}`);
|
|
204
|
+
this._drawGrid(W, H);
|
|
205
|
+
|
|
206
|
+
// scatter initial positions in a spiral
|
|
207
|
+
const R = Math.min(W, H) * 0.28;
|
|
208
|
+
na.forEach((n, i) => {
|
|
209
|
+
const a = (i / na.length) * 2 * Math.PI;
|
|
210
|
+
const jit = (Math.sin(i * 7919) * 0.5 + 0.5) * 30;
|
|
211
|
+
n.x = W / 2 + Math.cos(a) * (R + jit);
|
|
212
|
+
n.y = H / 2 + Math.sin(a) * (R + jit);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
this._na = na;
|
|
216
|
+
this._la = la;
|
|
217
|
+
this._built = false;
|
|
218
|
+
this._tick = 0;
|
|
219
|
+
|
|
220
|
+
this._mkEls();
|
|
221
|
+
if (this._raf) cancelAnimationFrame(this._raf);
|
|
222
|
+
this._sim();
|
|
223
|
+
|
|
224
|
+
// update hud
|
|
225
|
+
this._hud.textContent =
|
|
226
|
+
`rdf-graph · ${na.length} nodes · ${la.length} links`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/* ── create SVG elements (once) ───────────────────────────── */
|
|
230
|
+
_mkEls() {
|
|
231
|
+
const NS = 'http://www.w3.org/2000/svg';
|
|
232
|
+
this._ll.innerHTML = '';
|
|
233
|
+
this._nn.innerHTML = '';
|
|
234
|
+
this._le = [];
|
|
235
|
+
this._ne = [];
|
|
236
|
+
|
|
237
|
+
// links
|
|
238
|
+
for (let i = 0; i < this._la.length; i++) {
|
|
239
|
+
const l = this._la[i];
|
|
240
|
+
const g = document.createElementNS(NS, 'g');
|
|
241
|
+
const line = document.createElementNS(NS, 'line');
|
|
242
|
+
line.setAttribute('stroke', l.isType ? '#0e1e2e' : '#1e3e6e');
|
|
243
|
+
line.setAttribute('stroke-width', l.isType ? '.5' : '1');
|
|
244
|
+
line.setAttribute('stroke-dasharray', l.isType ? '3 4' : 'none');
|
|
245
|
+
if (!l.isType)
|
|
246
|
+
line.setAttribute('marker-end', 'url(#arr)');
|
|
247
|
+
const txt = document.createElementNS(NS, 'text');
|
|
248
|
+
txt.setAttribute('fill', '#1a4a6a');
|
|
249
|
+
txt.setAttribute('font-size', '6.5');
|
|
250
|
+
txt.setAttribute('text-anchor', 'middle');
|
|
251
|
+
txt.setAttribute('dominant-baseline','middle');
|
|
252
|
+
txt.setAttribute('pointer-events', 'none');
|
|
253
|
+
txt.textContent = l.isType ? '' : l.p;
|
|
254
|
+
g.append(line, txt);
|
|
255
|
+
this._ll.appendChild(g);
|
|
256
|
+
this._le.push({ line, txt });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// nodes
|
|
260
|
+
for (let i = 0; i < this._na.length; i++) {
|
|
261
|
+
const n = this._na[i];
|
|
262
|
+
const g = document.createElementNS(NS, 'g');
|
|
263
|
+
g.setAttribute('class', 'node');
|
|
264
|
+
g.setAttribute('data-i', i);
|
|
265
|
+
g.setAttribute('filter', 'url(#glow)');
|
|
266
|
+
|
|
267
|
+
const c = document.createElementNS(NS, 'circle');
|
|
268
|
+
c.setAttribute('r', n.r);
|
|
269
|
+
c.setAttribute('fill', n.color);
|
|
270
|
+
c.setAttribute('stroke', n.stroke);
|
|
271
|
+
c.setAttribute('stroke-width', '1');
|
|
272
|
+
|
|
273
|
+
// inner cross (demo-scene detail)
|
|
274
|
+
const lx = document.createElementNS(NS, 'line');
|
|
275
|
+
lx.setAttribute('x1', -n.r * .4); lx.setAttribute('x2', n.r * .4);
|
|
276
|
+
lx.setAttribute('y1', '0'); lx.setAttribute('y2', '0');
|
|
277
|
+
lx.setAttribute('stroke', n.glow); lx.setAttribute('stroke-width', '.5');
|
|
278
|
+
lx.setAttribute('pointer-events', 'none');
|
|
279
|
+
const ly = document.createElementNS(NS, 'line');
|
|
280
|
+
ly.setAttribute('x1', '0'); ly.setAttribute('x2', '0');
|
|
281
|
+
ly.setAttribute('y1', -n.r * .4); ly.setAttribute('y2', n.r * .4);
|
|
282
|
+
ly.setAttribute('stroke', n.glow); ly.setAttribute('stroke-width', '.5');
|
|
283
|
+
ly.setAttribute('pointer-events', 'none');
|
|
284
|
+
|
|
285
|
+
const t = document.createElementNS(NS, 'text');
|
|
286
|
+
t.setAttribute('fill', 'rgba(190,220,255,.75)');
|
|
287
|
+
t.setAttribute('font-size', '6');
|
|
288
|
+
t.setAttribute('text-anchor', 'middle');
|
|
289
|
+
t.setAttribute('dominant-baseline','hanging');
|
|
290
|
+
t.setAttribute('y', n.r + 2);
|
|
291
|
+
t.setAttribute('pointer-events', 'none');
|
|
292
|
+
t.textContent = n.label;
|
|
293
|
+
|
|
294
|
+
g.append(c, lx, ly, t);
|
|
295
|
+
this._nn.appendChild(g);
|
|
296
|
+
this._ne.push({ g, c });
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/* ── force simulation (Euler integration) ─────────────────── */
|
|
301
|
+
_sim() {
|
|
302
|
+
const na = this._na, la = this._la;
|
|
303
|
+
const step = () => {
|
|
304
|
+
const W = this._W, H = this._H;
|
|
305
|
+
const cx = W / 2, cy = H / 2;
|
|
306
|
+
const n = na.length;
|
|
307
|
+
let energy = 0;
|
|
308
|
+
|
|
309
|
+
// ── repulsion (O n²) ──
|
|
310
|
+
for (let i = 0; i < n; i++) {
|
|
311
|
+
for (let j = i + 1; j < n; j++) {
|
|
312
|
+
const a = na[i], b = na[j];
|
|
313
|
+
let dx = b.x - a.x, dy = b.y - a.y;
|
|
314
|
+
const d2 = dx * dx + dy * dy + 1;
|
|
315
|
+
const d = Math.sqrt(d2);
|
|
316
|
+
const f = Math.min(2200 / d2, 10);
|
|
317
|
+
const nx = dx / d, ny = dy / d;
|
|
318
|
+
if (!a.pinned) { a.vx -= f * nx; a.vy -= f * ny; }
|
|
319
|
+
if (!b.pinned) { b.vx += f * nx; b.vy += f * ny; }
|
|
320
|
+
// collision resolve
|
|
321
|
+
const sep = a.r + b.r + 5;
|
|
322
|
+
if (d < sep) {
|
|
323
|
+
const push = (sep - d) * .45;
|
|
324
|
+
if (!a.pinned) { a.x -= nx * push; a.y -= ny * push; }
|
|
325
|
+
if (!b.pinned) { b.x += nx * push; b.y += ny * push; }
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// ── spring attraction ──
|
|
331
|
+
for (const l of la) {
|
|
332
|
+
const a = na[l.s], b = na[l.o];
|
|
333
|
+
let dx = b.x - a.x, dy = b.y - a.y;
|
|
334
|
+
const d = Math.sqrt(dx * dx + dy * dy) || 1;
|
|
335
|
+
const rest = l.isType ? 95 : 68;
|
|
336
|
+
const k = l.isType ? .022 : .042;
|
|
337
|
+
const f = (d - rest) * k;
|
|
338
|
+
const nx = dx / d, ny = dy / d;
|
|
339
|
+
if (!a.pinned) { a.vx += f * nx; a.vy += f * ny; }
|
|
340
|
+
if (!b.pinned) { b.vx -= f * nx; b.vy -= f * ny; }
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ── center gravity + damping + clamp ──
|
|
344
|
+
for (const nd of na) {
|
|
345
|
+
if (nd.pinned) continue;
|
|
346
|
+
nd.vx += (cx - nd.x) * .005;
|
|
347
|
+
nd.vy += (cy - nd.y) * .005;
|
|
348
|
+
nd.vx *= .80; nd.vy *= .80;
|
|
349
|
+
nd.x += nd.vx; nd.y += nd.vy;
|
|
350
|
+
nd.x = Math.max(nd.r + 2, Math.min(W - nd.r - 2, nd.x));
|
|
351
|
+
nd.y = Math.max(nd.r + 2, Math.min(H - nd.r - 2, nd.y));
|
|
352
|
+
energy += nd.vx * nd.vx + nd.vy * nd.vy;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ── DOM update ──
|
|
356
|
+
for (let i = 0; i < n; i++) {
|
|
357
|
+
const nd = na[i], el = this._ne[i];
|
|
358
|
+
el.g.setAttribute('transform', `translate(${nd.x | 0} ${nd.y | 0})`);
|
|
359
|
+
}
|
|
360
|
+
for (let i = 0; i < la.length; i++) {
|
|
361
|
+
const l = la[i], el = this._le[i];
|
|
362
|
+
const a = na[l.s], b = na[l.o];
|
|
363
|
+
const dx = b.x - a.x, dy = b.y - a.y;
|
|
364
|
+
const d = Math.sqrt(dx * dx + dy * dy) || 1;
|
|
365
|
+
const nx = dx / d, ny = dy / d;
|
|
366
|
+
const x1 = a.x + nx * (a.r + 1);
|
|
367
|
+
const y1 = a.y + ny * (a.r + 1);
|
|
368
|
+
// pull arrow tip back from circle edge
|
|
369
|
+
const tip = b.r + (l.isType ? 2 : 9);
|
|
370
|
+
const x2 = b.x - nx * tip;
|
|
371
|
+
const y2 = b.y - ny * tip;
|
|
372
|
+
// skip degenerate lines
|
|
373
|
+
if ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1) < 4) continue;
|
|
374
|
+
el.line.setAttribute('x1', x1 | 0); el.line.setAttribute('y1', y1 | 0);
|
|
375
|
+
el.line.setAttribute('x2', x2 | 0); el.line.setAttribute('y2', y2 | 0);
|
|
376
|
+
el.txt.setAttribute('x', ((x1 + x2) / 2) | 0);
|
|
377
|
+
el.txt.setAttribute('y', ((y1 + y2) / 2) | 0);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
this._tick++;
|
|
381
|
+
if (energy > .03 || this._tick < 400)
|
|
382
|
+
this._raf = requestAnimationFrame(step);
|
|
383
|
+
else
|
|
384
|
+
this._built = true;
|
|
385
|
+
};
|
|
386
|
+
this._raf = requestAnimationFrame(step);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
/* ═══════════════════════════════════════════════════════════
|
|
391
|
+
DEMO DATA — remove / replace with your own quads
|
|
392
|
+
═══════════════════════════════════════════════════════════ */
|
|
393
|
+
const RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
|
|
394
|
+
const RDFS = 'http://www.w3.org/2000/01/rdf-schema#';
|
|
395
|
+
const PROV = 'http://www.w3.org/ns/prov#';
|
|
396
|
+
const SCHEMA = 'http://schema.org/';
|
|
397
|
+
const ME = 'tag:me@example.com,2026:';
|
|
398
|
+
|
|
399
|
+
const nn = v => ({ termType: 'NamedNode', value: v });
|
|
400
|
+
const lit = v => ({ termType: 'Literal', value: v });
|
|
401
|
+
const q = (s,p,o) => ({ termType:'Quad', subject:nn(s), predicate:nn(p), object:o });
|
|
402
|
+
|
|
403
|
+
const quads = [
|
|
404
|
+
// ── day ──
|
|
405
|
+
q(ME+'day-2024-07-18', RDF+'type', nn(PROV+'Activity')),
|
|
406
|
+
q(ME+'day-2024-07-18', RDFS+'label', lit('2024-07-18 — A good day')),
|
|
407
|
+
q(ME+'day-2024-07-18', RDFS+'comment', lit('Productive and enjoyable.')),
|
|
408
|
+
q(ME+'day-2024-07-18', PROV+'startedAtTime',lit('2024-07-18T00:00:00Z')),
|
|
409
|
+
q(ME+'day-2024-07-18', PROV+'endedAtTime', lit('2024-07-18T23:59:59Z')),
|
|
410
|
+
q(ME+'day-2024-07-18', PROV+'wasAssociatedWith', nn(ME+'person-alice')),
|
|
411
|
+
|
|
412
|
+
// ── people ──
|
|
413
|
+
q(ME+'person-alice', RDF+'type', nn(SCHEMA+'Person')),
|
|
414
|
+
q(ME+'person-alice', SCHEMA+'name', lit('Alice')),
|
|
415
|
+
q(ME+'person-alice', SCHEMA+'email', lit('alice@example.com')),
|
|
416
|
+
q(ME+'person-alice', SCHEMA+'knows', nn(ME+'person-bob')),
|
|
417
|
+
q(ME+'person-alice', SCHEMA+'memberOf', nn(ME+'org-acme')),
|
|
418
|
+
|
|
419
|
+
q(ME+'person-bob', RDF+'type', nn(SCHEMA+'Person')),
|
|
420
|
+
q(ME+'person-bob', SCHEMA+'name', lit('Bob')),
|
|
421
|
+
q(ME+'person-bob', SCHEMA+'knows', nn(ME+'person-carol')),
|
|
422
|
+
q(ME+'person-bob', SCHEMA+'memberOf', nn(ME+'org-acme')),
|
|
423
|
+
|
|
424
|
+
q(ME+'person-carol', RDF+'type', nn(SCHEMA+'Person')),
|
|
425
|
+
q(ME+'person-carol', SCHEMA+'name', lit('Carol')),
|
|
426
|
+
q(ME+'person-carol', SCHEMA+'memberOf', nn(ME+'org-beta')),
|
|
427
|
+
|
|
428
|
+
// ── orgs ──
|
|
429
|
+
q(ME+'org-acme', RDF+'type', nn(SCHEMA+'Organization')),
|
|
430
|
+
q(ME+'org-acme', SCHEMA+'name', lit('ACME Corp')),
|
|
431
|
+
q(ME+'org-acme', SCHEMA+'subOrganization', nn(ME+'org-beta')),
|
|
432
|
+
|
|
433
|
+
q(ME+'org-beta', RDF+'type', nn(SCHEMA+'Organization')),
|
|
434
|
+
q(ME+'org-beta', SCHEMA+'name', lit('Beta Division')),
|
|
435
|
+
|
|
436
|
+
// ── activities / tasks ──
|
|
437
|
+
q(ME+'task-run', RDF+'type', nn(PROV+'Activity')),
|
|
438
|
+
q(ME+'task-run', RDFS+'label', lit('Morning run')),
|
|
439
|
+
q(ME+'task-run', PROV+'wasInfluencedBy', nn(ME+'day-2024-07-18')),
|
|
440
|
+
q(ME+'task-run', PROV+'wasAssociatedWith',nn(ME+'person-alice')),
|
|
441
|
+
|
|
442
|
+
q(ME+'task-meet', RDF+'type', nn(SCHEMA+'Event')),
|
|
443
|
+
q(ME+'task-meet', RDFS+'label', lit('Team standup')),
|
|
444
|
+
q(ME+'task-meet', SCHEMA+'attendee', nn(ME+'person-alice')),
|
|
445
|
+
q(ME+'task-meet', SCHEMA+'attendee', nn(ME+'person-bob')),
|
|
446
|
+
q(ME+'task-meet', SCHEMA+'attendee', nn(ME+'person-carol')),
|
|
447
|
+
q(ME+'task-meet', PROV+'wasInfluencedBy', nn(ME+'day-2024-07-18')),
|
|
448
|
+
q(ME+'task-meet', SCHEMA+'isPartOf', nn(ME+'project-x')),
|
|
449
|
+
|
|
450
|
+
q(ME+'task-review', RDF+'type', nn(PROV+'Activity')),
|
|
451
|
+
q(ME+'task-review', RDFS+'label', lit('Code review')),
|
|
452
|
+
q(ME+'task-review', PROV+'wasAssociatedWith',nn(ME+'person-bob')),
|
|
453
|
+
q(ME+'task-review', SCHEMA+'isPartOf', nn(ME+'project-x')),
|
|
454
|
+
|
|
455
|
+
// ── project ──
|
|
456
|
+
q(ME+'project-x', RDF+'type', nn(SCHEMA+'Project')),
|
|
457
|
+
q(ME+'project-x', SCHEMA+'name', lit('Project X')),
|
|
458
|
+
q(ME+'project-x', SCHEMA+'description',lit('Strategic initiative for Q3.')),
|
|
459
|
+
q(ME+'project-x', SCHEMA+'member', nn(ME+'person-alice')),
|
|
460
|
+
q(ME+'project-x', SCHEMA+'member', nn(ME+'person-bob')),
|
|
461
|
+
q(ME+'project-x', PROV+'wasAttributedTo', nn(ME+'org-acme')),
|
|
462
|
+
|
|
463
|
+
// ── dataset provenance ──
|
|
464
|
+
q(ME+'dataset-01', RDF+'type', nn(PROV+'Entity')),
|
|
465
|
+
q(ME+'dataset-01', RDFS+'label', lit('Sales dataset')),
|
|
466
|
+
q(ME+'dataset-01', PROV+'wasGeneratedBy',nn(ME+'task-review')),
|
|
467
|
+
q(ME+'dataset-01', PROV+'wasAttributedTo',nn(ME+'person-bob')),
|
|
468
|
+
];
|
|
469
|
+
|
|
470
|
+
document.getElementById('g').quads = quads;
|
|
471
|
+
</script>
|
|
472
|
+
</body>
|
|
473
|
+
</html>
|