Mercurial > code > home > repos > streamed-graph
annotate src/graph_view.ts @ 71:f7143866fae1
merge
author | drewp@bigasterisk.com |
---|---|
date | Tue, 11 Feb 2020 00:07:54 -0800 |
parents | eb1294174dd4 72ad92ebda7a |
children | 58676ebdce0f |
rev | line source |
---|---|
49 | 1 import { html, TemplateResult } from "lit-html"; |
69
72ad92ebda7a
don't need forObjects typing workaround anymore
drewp@bigasterisk.com
parents:
52
diff
changeset
|
2 import { Quad, Term, N3Store, Literal, Quad_Object, NamedNode } from "n3"; |
49 | 3 import { DataFactory, Util } 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
|
4 const { namedNode } = DataFactory; |
20
9ec3cbc8791a
build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents:
15
diff
changeset
|
5 |
49 | 6 import { SuffixLabels } from "./suffixLabels"; |
65
eb1294174dd4
n3 type fixes, maybe a major rdf:Type bug too
drewp@bigasterisk.com
parents:
52
diff
changeset
|
7 import { Quad_Object } 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
|
8 // 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
|
9 // const { rdf } = ns; |
49 | 10 const rdf = { |
11 type: namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#type") | |
12 }; | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
13 |
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
|
14 type TypeToSubjs = Map<NamedNode, Set<NamedNode>>; |
69
72ad92ebda7a
don't need forObjects typing workaround anymore
drewp@bigasterisk.com
parents:
52
diff
changeset
|
15 // When there are multiple types, an arbitrary one is used. |
49 | 16 function groupByRdfType( |
17 graph: N3Store | |
18 ): { byType: TypeToSubjs; untyped: Set<NamedNode> } { | |
40 | 19 const rdfType = rdf.type; |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
20 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
|
21 const untyped: Set<NamedNode> = new Set(); // subjs |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
22 const internSubjs = new Map<string, NamedNode>(); |
49 | 23 graph.forEach( |
24 q => { | |
25 if (!Util.isNamedNode(q.subject)) { | |
26 throw new Error("unsupported " + q.subject.value); | |
27 } | |
28 const subj = q.subject as NamedNode; | |
29 | |
30 let subjType: NamedNode | null = null; | |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
31 |
49 | 32 graph.forObjects( |
69
72ad92ebda7a
don't need forObjects typing workaround anymore
drewp@bigasterisk.com
parents:
52
diff
changeset
|
33 (o: Quad_Object) => { |
72ad92ebda7a
don't need forObjects typing workaround anymore
drewp@bigasterisk.com
parents:
52
diff
changeset
|
34 subjType = o as NamedNode; |
49 | 35 }, |
36 subj, | |
37 rdfType, | |
38 null | |
39 ); | |
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
|
40 |
49 | 41 if (subjType !== null) { |
42 // (subj, rdf:type, subjType) in graph | |
43 if (!byType.has(subjType)) { | |
44 byType.set(subjType, new Set()); | |
45 } | |
46 (byType.get(subjType) as Set<NamedNode>).add(subj); | |
47 } else { | |
48 // no rdf:type stmt in graph | |
49 if (!internSubjs.has(subj.value)) { | |
50 internSubjs.set(subj.value, subj); | |
51 } | |
52 const intSubj: NamedNode = internSubjs.get( | |
53 subj.value as string | |
54 ) as NamedNode; | |
55 untyped.add(intSubj); | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
56 } |
49 | 57 }, |
58 null, | |
59 null, | |
60 null, | |
61 null | |
62 ); | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
63 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
|
64 } |
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 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
|
67 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
|
68 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
|
69 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
|
70 } |
49 | 71 getHtml(n: Term | NamedNode): TemplateResult { |
52 | 72 if (Util.isLiteral(n)) { |
73 n = n as Literal; | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
74 let dtPart: any = ""; |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
75 if (n.datatype) { |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
76 dtPart = html` |
49 | 77 ^^<span class="literalType"> |
78 ${this.getHtml(n.datatype)} | |
79 </span> | |
80 `; | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
81 } |
49 | 82 return html` |
83 <span class="literal">${n.value}${dtPart}</span> | |
84 `; | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
85 } |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
86 |
52 | 87 if (Util.isNamedNode(n)) { |
88 n = n as NamedNode; | |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
89 let shortened = false; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
90 let uriValue: string = n.value; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
91 for (let [long, short] of [ |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
92 ["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
|
93 ["http://www.w3.org/2000/01/rdf-schema#", "rdfs:"], |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
94 ["http://purl.org/dc/elements/1.1/", "dc:"], |
49 | 95 ["http://www.w3.org/2001/XMLSchema#", "xsd:"] |
96 ]) { | |
52 | 97 if (uriValue.startsWith(long)) { |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
98 uriValue = short + uriValue.substr(long.length); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
99 shortened = true; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
100 break; |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
101 } |
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
|
102 } |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
103 if (!shortened) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
104 let dn: string | undefined = this.labels.getLabelForNode(uriValue); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
105 if (dn === undefined) { |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
106 throw new Error(`dn=${dn}`); |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
107 } |
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
108 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
|
109 } |
28
c751380b70c5
uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents:
22
diff
changeset
|
110 |
49 | 111 return html` |
112 <a class="graphUri" href="${n.value}">${uriValue}</a> | |
113 `; | |
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
|
114 } |
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 |
49 | 116 return html` |
117 [${n.termType} ${n.value}] | |
118 `; | |
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
|
119 } |
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 |
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 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 |
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 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
|
131 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
|
132 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
|
133 } |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
134 |
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 _addLabelsForAllTerms(labels: SuffixLabels) { |
49 | 136 return this.graph.forEach( |
137 (q: Quad) => { | |
138 if (q.subject.termType === "NamedNode") { | |
139 labels.planDisplayForNode(q.subject); | |
140 } | |
141 if (q.predicate.termType === "NamedNode") { | |
142 labels.planDisplayForNode(q.predicate); | |
143 } | |
144 if (q.object.termType === "NamedNode") { | |
145 labels.planDisplayForNode(q.object); | |
146 } | |
147 if (q.object.termType === "Literal" && q.object.datatype) { | |
148 labels.planDisplayForNode(q.object.datatype); | |
149 } | |
150 }, | |
151 null, | |
152 null, | |
153 null, | |
154 null | |
155 ); | |
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
|
156 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
157 |
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
|
158 _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
|
159 const predsSet: Set<NamedNode> = new Set(); |
49 | 160 this.graph.forEach( |
161 (q: Quad) => { | |
162 predsSet.add(q.predicate as NamedNode); | |
163 }, | |
164 subj, | |
165 null, | |
166 null, | |
167 null | |
168 ); | |
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
|
169 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
|
170 preds.sort(); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
171 return html` |
49 | 172 <div class="subject"> |
173 ${this.nodeDisplay.getHtml(subj)} | |
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
|
174 <!-- 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
|
175 <div> |
49 | 176 ${preds.map(p => { |
177 return this._predBlock(subj, p); | |
178 })} | |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
179 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
180 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
181 `; |
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
|
182 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
183 |
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
|
184 _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
|
185 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
|
186 <div class="object"> |
49 | 187 ${this.nodeDisplay.getHtml(obj)} |
188 <!-- indicate what source or graph said this stmt --> | |
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
|
189 </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
|
190 `; |
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
|
191 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
192 |
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
|
193 _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
|
194 const objsSet = new Set<Term>(); |
49 | 195 this.graph.forEach( |
196 (q: Quad) => { | |
197 objsSet.add(q.object); | |
198 }, | |
199 subj, | |
200 pred, | |
201 null, | |
202 null | |
203 ); | |
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
|
204 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
|
205 objs.sort(); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
206 return html` |
49 | 207 <div class="predicate"> |
208 ${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
|
209 <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
|
210 ${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
|
211 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
212 </div> |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
213 `; |
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
|
214 } |
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
|
215 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
216 byTypeBlock(byType: TypeToSubjs, typeUri: NamedNode) { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
217 const subjSet = byType.get(typeUri); |
49 | 218 const subjs: Array<NamedNode> = subjSet ? Array.from(subjSet) : []; |
219 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
|
220 |
49 | 221 const graphCells = new Map<string, Set<Term>>(); // [subj, pred] : objs |
222 const makeCellKey = (subj: NamedNode, pred: NamedNode) => | |
223 subj.value + "|||" + pred.value; | |
224 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
|
225 |
49 | 226 subjs.forEach((subj: NamedNode) => { |
227 this.graph.forEach( | |
228 (q: Quad) => { | |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
229 if (!Util.isNamedNode(q.predicate)) { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
230 throw new Error(); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
231 } |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
232 preds.add(q.predicate as NamedNode); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
233 const cellKey = makeCellKey(subj, q.predicate as NamedNode); |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
234 if (!graphCells.has(cellKey)) { |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
235 graphCells.set(cellKey, new Set<Term>()); |
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 graphCells.get(cellKey)!.add(q.object); |
49 | 238 }, |
239 subj, | |
240 null, | |
241 null, | |
242 null | |
243 ); | |
244 }); | |
245 const predsList = Array.from(preds); | |
246 predsList.splice(predsList.indexOf(rdf.type), 1); | |
247 // also pull out label, which should be used on 1st column | |
248 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
|
249 |
49 | 250 const thead = () => { |
251 const predColumnHead = (pred: NamedNode) => { | |
252 return html` | |
253 <th>${this.nodeDisplay.getHtml(pred)}</th> | |
254 `; | |
255 }; | |
256 return html` | |
257 <thead> | |
258 <tr> | |
259 <th></th> | |
260 ${predsList.map(predColumnHead)} | |
261 </tr> | |
262 </thead> | |
263 `; | |
264 }; | |
265 | |
266 const instanceRow = (subj: NamedNode) => { | |
267 const cell = (pred: NamedNode) => { | |
268 const objs = graphCells.get(subj + "|||" + pred); | |
269 if (!objs) { | |
270 return html` | |
271 <td></td> | |
272 `; | |
273 } | |
274 const objsList = Array.from(objs); | |
275 objsList.sort(); | |
276 const draw = (obj: Term) => { | |
277 return html` | |
278 <div>${this.nodeDisplay.getHtml(obj)}</div> | |
279 `; | |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
280 }; |
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
281 return html` |
49 | 282 <td>${objsList.map(draw)}</td> |
283 `; | |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
284 }; |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
285 |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
286 return html` |
49 | 287 <tr> |
288 <td>${this.nodeDisplay.getHtml(subj)}</td> | |
289 ${predsList.map(cell)} | |
290 </tr> | |
291 `; | |
39
f551a089a98f
add back type-block rendering. untested.
drewp@bigasterisk.com
parents:
28
diff
changeset
|
292 }; |
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
|
293 |
49 | 294 return html` |
295 <div>[icon] ${this.nodeDisplay.getHtml(typeUri)} resources</div> | |
296 <div class="typeBlockScroll"> | |
297 <table class="typeBlock"> | |
298 ${thead()} ${subjs.map(instanceRow)} | |
299 </table> | |
300 </div> | |
301 `; | |
302 } | |
303 | |
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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 |
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
|
309 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
|
310 untypedSubjs.sort(); |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
311 |
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
312 return html` |
49 | 313 <section> |
314 <h2>Current graph (<a href="${this.url}">${this.url}</a>)</h2> | |
315 <div> | |
316 <!-- todo: graphs and provenance. | |
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
|
317 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
|
318 <span data-bind="html: $root.createCurie(graphUri())">...</span> graph.--> |
49 | 319 </div> |
320 ${typedSubjs.map((t: NamedNode) => this.byTypeBlock(byType, t))} | |
321 <div class="spoGrid"> | |
322 ${untypedSubjs.map(this._subjBlock.bind(this))} | |
323 </div> | |
324 </section> | |
325 `; | |
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
|
326 } |
8
6fefd287aff9
closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff
changeset
|
327 } |