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