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