Mercurial > code > home > repos > streamed-graph
comparison src/render/NodeDisplay.ts @ 106:2468f2227d22
make src/layout/ and src/render/ separation
author | drewp@bigasterisk.com |
---|---|
date | Sun, 13 Mar 2022 22:00:30 -0700 |
parents | src/NodeDisplay.ts@4d19759d0d9a |
children |
comparison
equal
deleted
inserted
replaced
105:4bb8c7775c83 | 106:2468f2227d22 |
---|---|
1 import { html, TemplateResult } from "lit"; | |
2 import { Literal, NamedNode, Term, Util } from "n3"; | |
3 import { SuffixLabels } from "../layout/suffixLabels"; | |
4 | |
5 export class NodeDisplay { | |
6 labels: SuffixLabels; | |
7 constructor(labels: SuffixLabels) { | |
8 this.labels = labels; | |
9 } | |
10 render(n: Term | NamedNode): TemplateResult { | |
11 if (Util.isLiteral(n)) { | |
12 n = n as Literal; | |
13 let dtPart: any = ""; | |
14 if (n.datatype && | |
15 n.datatype.value != "http://www.w3.org/2001/XMLSchema#string" && // boring | |
16 n.datatype.value != | |
17 "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" // boring | |
18 ) { | |
19 dtPart = html` | |
20 ^^<span class="literalType"> ${this.render(n.datatype)} </span> | |
21 `; | |
22 } | |
23 return html` <span class="literal">${n.value}${dtPart}</span> `; | |
24 } | |
25 | |
26 if (Util.isNamedNode(n)) { | |
27 n = n as NamedNode; | |
28 let shortened = false; | |
29 let uriValue: string = n.value; | |
30 for (let [long, short] of [ | |
31 ["http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:"], | |
32 ["http://www.w3.org/2000/01/rdf-schema#", "rdfs:"], | |
33 ["http://purl.org/dc/elements/1.1/", "dc:"], | |
34 ["http://www.w3.org/2001/XMLSchema#", "xsd:"], | |
35 ]) { | |
36 if (uriValue.startsWith(long)) { | |
37 uriValue = short + uriValue.substr(long.length); | |
38 shortened = true; | |
39 break; | |
40 } | |
41 } | |
42 if (!shortened) { | |
43 let dn: string | undefined = this.labels.getLabelForNode(uriValue); | |
44 if (dn === undefined) { | |
45 throw new Error(`dn=${dn}`); | |
46 } | |
47 uriValue = dn; | |
48 } | |
49 | |
50 return html` <a class="graphUri" href="${n.value}">${uriValue}</a> `; | |
51 } | |
52 | |
53 return html` [${n.termType} ${n.value}] `; | |
54 } | |
55 } |