Mercurial > code > home > repos > streamed-graph
annotate src/graph_view.ts @ 40:648bd89f9d47
sloppy fix for type imports
author | drewp@bigasterisk.com |
---|---|
date | Mon, 30 Dec 2019 15:29:23 -0800 |
parents | f551a089a98f |
children | c16a331f42e5 |
rev | line source |
---|---|
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
1 import { html, TemplateResult } from 'lit-html'; |
40 | 2 import { Quad, Term, N3Store } from 'n3'; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
3 import { DataFactory, Util } from 'n3'; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
4 const { namedNode } = DataFactory; |
40 | 5 import * as RDF from "rdf-js"; |
6 type NamedNode = RDF.NamedNode; | |
20
9ec3cbc8791a
build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents:
15
diff
changeset
|
7 |
9ec3cbc8791a
build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents:
15
diff
changeset
|
8 import { SuffixLabels } from './suffixLabels'; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
9 // import ns from 'n3/src/IRIs'; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
10 // const { rdf } = ns; |
40 | 11 const rdf = { type: namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")}; |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
12 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
13 type TypeToSubjs = Map<NamedNode, Set<NamedNode>>; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
14 function groupByRdfType(graph: N3Store): { byType: TypeToSubjs, untyped: Set<NamedNode> } { |
40 | 15 const rdfType = rdf.type; |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
16 const byType: TypeToSubjs = new Map(); |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
17 const untyped: Set<NamedNode> = new Set(); // subjs |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
18 const internSubjs = new Map<string, NamedNode>(); |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
19 graph.forEach((q) => { |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
20 if (!Util.isNamedNode(q.subject)) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
21 throw new Error("unsupported " + q.subject.value); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
22 } |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
23 const subj = q.subject as NamedNode; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
24 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
25 let subjType: NamedNode | null = null; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
26 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
27 graph.forObjects((o: Quad) => { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
28 if (Util.isNamedNode(o.object)) { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
29 subjType = o.object as NamedNode; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
30 } |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
31 }, subj, rdfType, null); |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
32 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
33 if (subjType !== null) { |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
34 // (subj, rdf:type, subjType) in graph |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
35 if (!byType.has(subjType)) { |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
36 byType.set(subjType, new Set()); |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
37 } |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
38 (byType.get(subjType) as Set<NamedNode>).add(subj); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
39 } else { |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
40 // no rdf:type stmt in graph |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
41 if (!internSubjs.has(subj.value)) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
42 internSubjs.set(subj.value, subj); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
43 } |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
44 const intSubj: NamedNode = internSubjs.get(subj.value as string) as NamedNode; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
45 untyped.add(intSubj); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
46 } |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
47 }, null, null, null, null); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
48 return { byType: byType, untyped: untyped }; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
49 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
50 |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
51 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
52 class NodeDisplay { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
53 labels: SuffixLabels; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
54 constructor(labels: SuffixLabels) { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
55 this.labels = labels; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
56 } |
40 | 57 getHtml(n: Term|NamedNode): TemplateResult { |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
58 if (n.termType == "Literal") { |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
59 let dtPart: any = ""; |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
60 if (n.datatype) { |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
61 dtPart = html` |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
62 ^^<span class="literalType"> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
63 ${this.getHtml(n.datatype)} |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
64 </span>`; |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
65 } |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
66 return html`<span class="literal">${n.value}${dtPart}</span>`; |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
67 } |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
68 |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
69 if (n.termType == "NamedNode") { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
70 let shortened = false; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
71 let uriValue: string = n.value; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
72 for (let [long, short] of [ |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
73 ["http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:"], |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
74 ["http://www.w3.org/2000/01/rdf-schema#", "rdfs:"], |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
75 ["http://purl.org/dc/elements/1.1/", "dc:"], |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
76 ["http://www.w3.org/2001/XMLSchema#", "xsd:"]]) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
77 if (uriValue?.startsWith(long)) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
78 uriValue = short + uriValue.substr(long.length); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
79 shortened = true; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
80 break; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
81 } |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
82 } |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
83 if (!shortened) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
84 |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
85 let dn: string | undefined = this.labels.getLabelForNode(uriValue); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
86 if (dn === undefined) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
87 throw new Error(`dn=${dn}`); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
88 } |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
89 uriValue = dn; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
90 } |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
91 |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
92 |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
93 return html`<a class="graphUri" href="${n.value}">${uriValue}</a>`; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
94 } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
95 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
96 return html`[${n.termType} ${n.value}]`; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
97 } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
98 } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
99 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
100 export class GraphView { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
101 url: string; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
102 graph: N3Store; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
103 nodeDisplay: NodeDisplay; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
104 constructor(url: string, graph: N3Store) { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
105 this.url = url; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
106 this.graph = graph; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
107 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
108 const labels = new SuffixLabels(); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
109 this._addLabelsForAllTerms(labels); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
110 this.nodeDisplay = new NodeDisplay(labels); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
111 } |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
112 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
113 _addLabelsForAllTerms(labels: SuffixLabels) { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
114 return this.graph.forEach((q: Quad) => { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
115 if (q.subject.termType === "NamedNode") { labels.planDisplayForNode(q.subject); } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
116 if (q.predicate.termType === "NamedNode") { labels.planDisplayForNode(q.predicate); } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
117 if (q.object.termType === "NamedNode") { labels.planDisplayForNode(q.object); } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
118 if (q.object.termType === "Literal" && q.object.datatype) { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
119 labels.planDisplayForNode(q.object.datatype); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
120 } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
121 }, null, null, null, null); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
122 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
123 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
124 _subjBlock(subj: NamedNode) { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
125 const predsSet: Set<NamedNode> = new Set(); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
126 this.graph.forEach((q: Quad) => { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
127 predsSet.add(q.predicate as NamedNode); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
128 }, subj, null, null, null); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
129 const preds = Array.from(predsSet.values()); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
130 preds.sort(); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
131 return html` |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
132 <div class="subject">${this.nodeDisplay.getHtml(subj)} |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
133 <!-- todo: special section for uri/type-and-icon/label/comment --> |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
134 <div> |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
135 ${preds.map((p) => { return this._predBlock(subj, p); })} |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
136 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
137 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
138 `; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
139 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
140 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
141 _objBlock(obj: Term) { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
142 return html` |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
143 <div class="object"> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
144 ${this.nodeDisplay.getHtml(obj)} <!-- indicate what source or graph said this stmt --> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
145 </div> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
146 `; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
147 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
148 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
149 _predBlock(subj: NamedNode, pred: NamedNode) { |
20
9ec3cbc8791a
build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents:
15
diff
changeset
|
150 const objsSet = new Set<Term>(); |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
151 this.graph.forEach((q: Quad) => { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
152 objsSet.add(q.object); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
153 }, subj, pred, null, null); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
154 const objs = Array.from(objsSet.values()); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
155 objs.sort(); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
156 return html` |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
157 <div class="predicate">${this.nodeDisplay.getHtml(pred)} |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
158 <div> |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
159 ${objs.map(this._objBlock.bind(this))} |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
160 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
161 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
162 `; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
163 } |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
164 |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
165 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
166 byTypeBlock(byType: TypeToSubjs, typeUri: NamedNode) { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
167 const subjSet = byType.get(typeUri); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
168 const subjs: Array<NamedNode> = subjSet ? Array.from(subjSet) : []; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
169 subjs.sort(); |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
170 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
171 const graphCells = new Map<string, Set<Term>>(); // [subj, pred] : objs |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
172 const makeCellKey = (subj: NamedNode, pred: NamedNode) => subj.value + '|||' + pred.value; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
173 const preds = new Set<NamedNode>(); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
174 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
175 subjs.forEach((subj: NamedNode) => { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
176 this.graph.forEach((q: Quad) => { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
177 if (!Util.isNamedNode(q.predicate)) { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
178 throw new Error(); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
179 } |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
180 preds.add(q.predicate as NamedNode); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
181 const cellKey = makeCellKey(subj, q.predicate as NamedNode); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
182 if (!graphCells.has(cellKey)) { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
183 graphCells.set(cellKey, new Set<Term>()); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
184 } |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
185 graphCells.get(cellKey)!.add(q.object); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
186 }, subj, null, null, null); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
187 }); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
188 const predsList = Array.from(preds); |
40 | 189 predsList.splice(predsList.indexOf(rdf.type), 1); |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
190 // also pull out label, which should be used on 1st column |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
191 predsList.sort(); |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
192 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
193 const thead = () => { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
194 const predColumnHead = (pred: NamedNode) => { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
195 return html`<th>${this.nodeDisplay.getHtml(pred)}</th>`; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
196 }; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
197 return html` |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
198 <thead> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
199 <tr> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
200 <th></th> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
201 ${predsList.map(predColumnHead)} |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
202 </tr> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
203 </thead>`; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
204 }; |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
205 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
206 const instanceRow = (subj: NamedNode) => { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
207 const cell = (pred: NamedNode) => { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
208 const objs = graphCells.get(subj + '|||' + pred); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
209 if (!objs) { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
210 return html`<td></td>`; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
211 } |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
212 const objsList = Array.from(objs); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
213 objsList.sort(); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
214 const draw = (obj: Term) => { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
215 return html`<div>${this.nodeDisplay.getHtml(obj)}</div>` |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
216 }; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
217 return html`<td>${objsList.map(draw)}</td>`; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
218 }; |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
219 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
220 return html` |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
221 <tr> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
222 <td>${this.nodeDisplay.getHtml(subj)}</td> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
223 ${predsList.map(cell)} |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
224 </tr> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
225 `; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
226 }; |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
227 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
228 return html` |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
229 <div>[icon] ${this.nodeDisplay.getHtml(typeUri)} resources</div> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
230 <div class="typeBlockScroll"> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
231 <table class="typeBlock"> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
232 ${thead()} |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
233 ${subjs.map(instanceRow)} |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
234 </table> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
235 </div> |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
236 `; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
237 }; |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
238 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
239 makeTemplate(): TemplateResult { |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
240 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
241 const { byType, untyped } = groupByRdfType(this.graph); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
242 const typedSubjs = Array.from(byType.keys()); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
243 typedSubjs.sort(); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
244 |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
245 const untypedSubjs = Array.from(untyped.values()); |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
246 untypedSubjs.sort(); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
247 |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
248 return html` |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
249 <link rel="stylesheet" href="../src/streamed-graph.css"> |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
250 |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
251 <section> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
252 <h2> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
253 Current graph (<a href="${this.url}">${this.url}</a>) |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
254 </h2> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
255 <div> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
256 <!-- todo: graphs and provenance. |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
257 These statements are all in the |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
258 <span data-bind="html: $root.createCurie(graphUri())">...</span> graph.--> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
259 </div> |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
260 ${typedSubjs.map((t: NamedNode) => this.byTypeBlock(byType, t))} |
15
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
261 <div class="spoGrid"> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
262 ${untypedSubjs.map(this._subjBlock.bind(this))} |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
263 </div> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
264 </section> |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
265 `; |
7ca4ff2088c3
managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents:
9
diff
changeset
|
266 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
267 } |