Mercurial > code > home > repos > streamed-graph
view src/elements/graph-view/NodeDisplay.ts @ 128:5a1a79f54779
big rewrite
author | drewp@bigasterisk.com |
---|---|
date | Fri, 05 May 2023 21:26:36 -0700 |
parents | src/render/NodeDisplay.ts@2468f2227d22 |
children |
line wrap: on
line source
import { html, TemplateResult } from "lit"; import { Literal, NamedNode, Term, Util } from "n3"; import { SuffixLabels } from "../../layout/suffixLabels"; export class NodeDisplay { labels: SuffixLabels; constructor(labels: SuffixLabels) { this.labels = labels; } render(n: Term | NamedNode): TemplateResult { if (Util.isLiteral(n)) { n = n as Literal; let dtPart: any = ""; if (n.datatype && n.datatype.value != "http://www.w3.org/2001/XMLSchema#string" && // boring n.datatype.value != "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" // boring ) { dtPart = html` ^^<span class="literalType"> ${this.render(n.datatype)} </span> `; } return html` <span class="literal">${n.value}${dtPart}</span> `; } if (Util.isNamedNode(n)) { n = n as NamedNode; let shortened = false; let uriValue: string = n.value; for (let [long, short] of [ ["http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:"], ["http://www.w3.org/2000/01/rdf-schema#", "rdfs:"], ["http://purl.org/dc/elements/1.1/", "dc:"], ["http://www.w3.org/2001/XMLSchema#", "xsd:"], ]) { if (uriValue.startsWith(long)) { uriValue = short + uriValue.substr(long.length); shortened = true; break; } } if (!shortened) { let dn: string | undefined = this.labels.getLabelForNode(uriValue); if (dn === undefined) { throw new Error(`dn=${dn}`); } uriValue = dn; } return html` <a class="graphUri" href="${n.value}">${uriValue}</a> `; } return html` [${n.termType} ${n.value}] `; } }