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