-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexpand.html
More file actions
338 lines (291 loc) · 12.2 KB
/
expand.html
File metadata and controls
338 lines (291 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!DOCTYPE html>
<!--
YASGUI Graph Plugin – Node Expansion Demo
Demonstrates the double-click-to-expand feature introduced in PR #10.
A small initial graph is shown. Double-clicking any blue URI node
fires a mock DESCRIBE query and merges the returned triples into the
live vis-network graph (no full redraw, positions are preserved).
To develop locally: npm run dev (then open /demo/expand.html)
For production: npm run build
-->
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Graph Plugin – Node Expansion Demo</title>
<style>
* { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
margin: 0;
padding: 16px;
background: #f5f5f5;
min-height: 100vh;
display: flex;
flex-direction: column;
gap: 12px;
}
h1 { margin: 0; color: #333; font-size: 22px; }
.banner {
background: #e8f5e9;
border-left: 4px solid #4caf50;
border-radius: 4px;
padding: 10px 14px;
font-size: 13px;
color: #2e7d32;
line-height: 1.6;
}
.banner strong { font-weight: 700; }
.legend {
background: white;
border-radius: 4px;
padding: 10px 14px;
box-shadow: 0 1px 4px rgba(0,0,0,.08);
font-size: 13px;
display: flex;
gap: 20px;
align-items: center;
flex-wrap: wrap;
}
.legend-title { font-weight: 700; color: #555; white-space: nowrap; }
.legend-item {
display: flex;
align-items: center;
gap: 6px;
white-space: nowrap;
}
.dot {
width: 14px; height: 14px;
border-radius: 50%;
flex-shrink: 0;
}
.border-demo {
width: 14px; height: 14px;
border-radius: 50%;
background: #97C2FC;
flex-shrink: 0;
}
.border-loading { border: 3px solid #ffa500; }
.border-expanded { border: 3px solid #97C2FC; outline: 2px solid #97C2FC; }
#log {
background: #1e1e1e;
color: #d4d4d4;
font-family: 'Cascadia Code', 'Fira Code', monospace;
font-size: 12px;
padding: 10px 14px;
border-radius: 4px;
max-height: 130px;
overflow-y: auto;
flex-shrink: 0;
}
#log .ts { color: #569cd6; margin-right: 6px; }
#log .ok { color: #4ec9b0; }
#log .err { color: #f44747; }
#log .inf { color: #9cdcfe; }
#graph-container {
flex: 1;
background: white;
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0,0,0,.1);
overflow: hidden;
min-height: 420px;
position: relative;
}
</style>
</head>
<body>
<h1>🔷 Node Expansion Demo</h1>
<div class="banner">
<strong>How it works:</strong> The initial graph shows a small social network.
<strong>Double-click any blue URI node</strong> to fire a mock DESCRIBE query for that resource.
New triples are merged into the graph without a full redraw – existing node positions are preserved.
The activity log below shows each expansion event.
</div>
<div class="legend">
<span class="legend-title">Node border states:</span>
<span class="legend-item"><span class="dot border-demo border-loading"></span> Loading (DESCRIBE in flight)</span>
<span class="legend-item"><span class="dot border-demo border-expanded"></span> Expanded (triples merged)</span>
<span class="legend-title" style="margin-left:12px">Colors:</span>
<span class="legend-item"><span class="dot" style="background:#97C2FC"></span> URI node</span>
<span class="legend-item"><span class="dot" style="background:#a6c8a6ff"></span> rdf:type object</span>
<span class="legend-item"><span class="dot" style="background:#c5c5c5ff"></span> Literal</span>
</div>
<div id="log"><span class="inf ts">init</span><span class="inf">Loading plugin…</span></div>
<div id="graph-container"></div>
<script type="module">
/* ─── Activity log ──────────────────────────────────────────────────── */
const logEl = document.getElementById('log');
function addLog(msg, type = 'inf') {
const ts = new Date().toLocaleTimeString('en', { hour12: false, hour: '2-digit', minute: '2-digit', second: '2-digit' });
const line = document.createElement('div');
const tsSpan = document.createElement('span');
tsSpan.className = 'ts';
tsSpan.textContent = ts;
const msgSpan = document.createElement('span');
msgSpan.className = type;
msgSpan.textContent = msg;
line.appendChild(tsSpan);
line.appendChild(msgSpan);
logEl.appendChild(line);
logEl.scrollTop = logEl.scrollHeight;
}
/* ─── Initial graph data (the seed graph) ───────────────────────────── */
/**
* A small seed social network.
* Only Alice and Bob are shown at first; their full data and connections
* to colleagues / employers are returned by mock DESCRIBE queries.
*/
const INITIAL_DATASET = {
head: { vars: ['subject', 'predicate', 'object'] },
results: {
bindings: [
// Alice
{ subject: { type: 'uri', value: 'http://example.org/alice' },
predicate: { type: 'uri', value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' },
object: { type: 'uri', value: 'http://xmlns.com/foaf/0.1/Person' } },
{ subject: { type: 'uri', value: 'http://example.org/alice' },
predicate: { type: 'uri', value: 'http://xmlns.com/foaf/0.1/name' },
object: { type: 'literal', value: 'Alice' } },
{ subject: { type: 'uri', value: 'http://example.org/alice' },
predicate: { type: 'uri', value: 'http://xmlns.com/foaf/0.1/knows' },
object: { type: 'uri', value: 'http://example.org/bob' } },
// Bob
{ subject: { type: 'uri', value: 'http://example.org/bob' },
predicate: { type: 'uri', value: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' },
object: { type: 'uri', value: 'http://xmlns.com/foaf/0.1/Person' } },
{ subject: { type: 'uri', value: 'http://example.org/bob' },
predicate: { type: 'uri', value: 'http://xmlns.com/foaf/0.1/name' },
object: { type: 'literal', value: 'Bob' } },
],
},
prefixes: {
ex: 'http://example.org/',
foaf: 'http://xmlns.com/foaf/0.1/',
rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
org: 'http://www.w3.org/ns/org#',
xsd: 'http://www.w3.org/2001/XMLSchema#',
},
};
/* ─── Mock DESCRIBE responses ────────────────────────────────────────── */
/**
* These strings simulate what a real SPARQL endpoint would return for
* DESCRIBE <uri> queries. Each value is an RDF graph in Turtle format.
*/
const MOCK_DESCRIBE_DATA = {
'http://example.org/alice': `
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://example.org/alice> foaf:mbox "alice@example.org" ;
foaf:age "30"^^xsd:integer ;
org:memberOf <http://example.org/acme-corp> ;
foaf:knows <http://example.org/carol> .
<http://example.org/acme-corp> rdf:type org:Organization ;
rdfs:label "ACME Corporation" .
<http://example.org/carol> foaf:name "Carol" .
`,
'http://example.org/bob': `
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://example.org/bob> foaf:mbox "bob@example.org" ;
foaf:age "28"^^xsd:integer ;
org:memberOf <http://example.org/acme-corp> ;
foaf:knows <http://example.org/dave> .
<http://example.org/dave> foaf:name "Dave" ;
rdf:type foaf:Person .
`,
'http://example.org/carol': `
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix org: <http://www.w3.org/ns/org#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://example.org/carol> rdf:type foaf:Person ;
foaf:mbox "carol@example.org" ;
foaf:knows <http://example.org/dave> ;
org:memberOf <http://example.org/tech-startup> .
<http://example.org/tech-startup> rdfs:label "TechStart Inc." .
`,
'http://example.org/dave': `
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix org: <http://www.w3.org/ns/org#> .
<http://example.org/dave> foaf:mbox "dave@example.org" ;
foaf:knows <http://example.org/alice> ;
org:memberOf <http://example.org/tech-startup> .
`,
'http://example.org/acme-corp': `
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix org: <http://www.w3.org/ns/org#> .
<http://example.org/acme-corp> foaf:homepage <https://example.org/acme> ;
org:hasMember <http://example.org/alice> , <http://example.org/bob> .
`,
'http://example.org/tech-startup': `
@prefix org: <http://www.w3.org/ns/org#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
<http://example.org/tech-startup> rdf:type org:Organization ;
org:hasMember <http://example.org/carol> , <http://example.org/dave> .
`,
};
/* ─── Mock executeQuery ─────────────────────────────────────────────── */
/**
* Simulates yasr.executeQuery().
* Parses the URI from the DESCRIBE query string and returns a mock response
* in Fetch API style ({ text: async () => turtleString }).
* An artificial 600 ms delay makes the orange loading border visible.
*/
function mockExecuteQuery(query, _options) {
const match = query.match(/DESCRIBE\s+<([^>]+)>/i);
const uri = match ? match[1] : null;
addLog(`⟶ DESCRIBE <${uri}>`, 'inf');
return new Promise((resolve) => {
setTimeout(() => {
const data = MOCK_DESCRIBE_DATA[uri];
if (data) {
const tripleCount = data.trim().split('\n').filter(l => l.trim() && !l.trim().startsWith('@prefix') && !l.trim().startsWith('#')).length;
addLog(`⟵ ~${tripleCount} triples returned for <${uri}> (Turtle format)`, 'ok');
resolve({ text: async () => data });
} else {
addLog(`⟵ No mock data for <${uri}> – returning empty result`, 'err');
resolve({ text: async () => '' });
}
}, 600);
});
}
/* ─── Bootstrap ─────────────────────────────────────────────────────── */
(async () => {
// Load plugin using the Vite alias configured in vite.config.ts.
// In dev mode this resolves to src/index.ts; in a production build
// it resolves to the built bundle.
let GraphPlugin;
try {
const module = await import('@matdata/yasgui-graph-plugin');
GraphPlugin = module.default;
addLog('Plugin loaded', 'ok');
} catch (e) {
addLog(`Failed to load plugin: ${e.message}`, 'err');
return;
}
// Build mock YASR with executeQuery wired to mock data
const mockYasr = {
config: { pluginsOptions: { Graph: {} } },
results: {
getBindings: () => INITIAL_DATASET.results.bindings,
head: INITIAL_DATASET.head,
results: INITIAL_DATASET.results,
},
resultsEl: document.getElementById('graph-container'),
getPrefixes: () => INITIAL_DATASET.prefixes,
executeQuery: mockExecuteQuery,
};
const plugin = new GraphPlugin(mockYasr);
await plugin.draw();
const tripleCount = INITIAL_DATASET.results.bindings.length;
addLog(`Initial graph drawn – ${tripleCount} triples, ${Object.keys(MOCK_DESCRIBE_DATA).length} mock DESCRIBE responses available`, 'ok');
addLog('Double-click any blue URI node to expand it', 'inf');
})();
</script>
</body>
</html>