annotate src/graph_view.ts @ 38:d4036715028b

try exporting the PolymerElement so it can be depended on and therefore not culled by tree-shaking
author drewp@bigasterisk.com
date Sun, 29 Dec 2019 19:43:25 -0800
parents c751380b70c5
children f551a089a98f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
1 import { html, TemplateResult } from 'lit-html';
20
9ec3cbc8791a build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents: 15
diff changeset
2 import { Quad, Term, NamedNode, N3Store } from 'n3';
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
3 import { DataFactory, Util } from 'n3';
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
4 const { namedNode } = DataFactory;
20
9ec3cbc8791a build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents: 15
diff changeset
5
9ec3cbc8791a build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents: 15
diff changeset
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;
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 20
diff changeset
9 const rdf = { type: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" };
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
10
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
11 type TypeToSubjs = Map<NamedNode, Set<NamedNode>>;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
12 function groupByRdfType(graph: N3Store): { byType: TypeToSubjs, untyped: Set<NamedNode> } {
22
e90d9021c6a0 add back s-g code; this breaks the build a little. WIP
drewp@bigasterisk.com
parents: 20
diff changeset
13 const rdfType = namedNode(rdf.type);
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
14 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
15 const untyped: Set<NamedNode> = new Set(); // subjs
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
16 const internSubjs = new Map<string, NamedNode>();
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
17 graph.forEach((q) => {
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
18 if (!Util.isNamedNode(q.subject)) {
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
19 throw new Error("unsupported " + q.subject.value);
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
20 }
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
21 const subj = q.subject as NamedNode;
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
22
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
23 let subjType: NamedNode | null = null;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
24
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
25 graph.forObjects((o: Quad) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
26 if (Util.isNamedNode(o.object)) {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
27 subjType = o.object as NamedNode;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
28 }
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
29 }, subj, rdfType, null);
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
30
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
31 if (subjType !== null) {
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
32 // (subj, rdf:type, subjType) in graph
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
33 if (!byType.has(subjType)) {
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
34 byType.set(subjType, new Set());
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
35 }
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
36 (byType.get(subjType) as Set<NamedNode>).add(subj);
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
37 } else {
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
38 // no rdf:type stmt in graph
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
39 if (!internSubjs.has(subj.value)) {
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
40 internSubjs.set(subj.value, subj);
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
41 }
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
42 const intSubj: NamedNode = internSubjs.get(subj.value as string) as NamedNode;
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
43 untyped.add(intSubj);
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
44 }
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
45 }, null, null, null, null);
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
46 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
47 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
48
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
49
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
50 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
51 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
52 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
53 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
54 }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
55 getHtml(n: Term): 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
56 if (n.termType == "Literal") {
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
57 let dtPart: any = "";
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
58 if (n.datatype) {
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
59 dtPart = html`
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
60 ^^<span class="literalType">
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
61 ${this.getHtml(n.datatype)}
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
62 </span>`;
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
63 }
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 return html`<span class="literal">${n.value}${dtPart}</span>`;
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
65 }
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
66
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
67 if (n.termType == "NamedNode") {
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
68 let shortened = false;
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
69 let uriValue: string = n.value;
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
70 for (let [long, short] of [
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
71 ["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
72 ["http://www.w3.org/2000/01/rdf-schema#", "rdfs:"],
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
73 ["http://purl.org/dc/elements/1.1/", "dc:"],
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
74 ["http://www.w3.org/2001/XMLSchema#", "xsd:"]]) {
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
75 if (uriValue?.startsWith(long)) {
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
76 uriValue = short + uriValue.substr(long.length);
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
77 shortened = true;
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
78 break;
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
79 }
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
80 }
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
81 if (!shortened) {
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
82
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
83 let dn: string | undefined = this.labels.getLabelForNode(uriValue);
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
84 if (dn === undefined) {
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
85 throw new Error(`dn=${dn}`);
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
86 }
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
87 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
88 }
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
89
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
90
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
91 return html`<a class="graphUri" href="${n.value}">${uriValue}</a>`;
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
92 }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
93
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
94 return html`[${n.termType} ${n.value}]`;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
95 }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
96 }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
97
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
106 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
107 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
108 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
109 }
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
110
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 _addLabelsForAllTerms(labels: SuffixLabels) {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
112 return this.graph.forEach((q: Quad) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
113 if (q.subject.termType === "NamedNode") { labels.planDisplayForNode(q.subject); }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
114 if (q.predicate.termType === "NamedNode") { labels.planDisplayForNode(q.predicate); }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
115 if (q.object.termType === "NamedNode") { labels.planDisplayForNode(q.object); }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
116 if (q.object.termType === "Literal" && q.object.datatype) {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
117 labels.planDisplayForNode(q.object.datatype);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
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 }, null, null, null, null);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
120 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
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 _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
123 const predsSet: Set<NamedNode> = new Set();
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
124 this.graph.forEach((q: Quad) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
125 predsSet.add(q.predicate as NamedNode);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
126 }, subj, null, null, null);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
127 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
128 preds.sort();
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
129 return html`
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
130 <div class="subject">${this.nodeDisplay.getHtml(subj)}
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
131 <!-- 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
132 <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
133 ${preds.map((p) => { return this._predBlock(subj, p); })}
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
134 </div>
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
135 </div>
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 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
138
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
139 _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
140 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
141 <div class="object">
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
142 ${this.nodeDisplay.getHtml(obj)} <!-- indicate what source or graph said this stmt -->
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
143 </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
144 `;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
145 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
146
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
147 _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
148 const objsSet = new Set<Term>();
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
149 this.graph.forEach((q: Quad) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
150 objsSet.add(q.object);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
151 }, subj, pred, null, null);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
152 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
153 objs.sort();
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
154 return html`
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
155 <div class="predicate">${this.nodeDisplay.getHtml(pred)}
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
156 <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
157 ${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
158 </div>
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
159 </div>
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 }
7ca4ff2088c3 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
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
163
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
164 // const byTypeBlock = (typeUri) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
165 // const subjs = Array.from(byType.get(typeUri));
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
166 // subjs.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
167
7ca4ff2088c3 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 graphCells = new Map(); // [subj, pred] : objs
7ca4ff2088c3 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 = new Set();
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
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 // subjs.forEach((subj) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
172 // graph.getQuads({ subject: new NamedNode(subj) }, (q) => {
7ca4ff2088c3 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.add(q.predicate.toString());
7ca4ff2088c3 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 // const cellKey = subj + '|||' + q.predicate.toString();
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
175 // if (!graphCells.has(cellKey)) {
7ca4ff2088c3 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 // graphCells.set(cellKey, new Set());
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
177 // }
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
178 // graphCells.get(cellKey).add(q.object);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
179 // });
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
180 // });
7ca4ff2088c3 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 // const predsList = Array.from(preds);
7ca4ff2088c3 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 // predsList.splice(predsList.indexOf('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), 1);
7ca4ff2088c3 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 // // also pull out label, which should be used on 1st column
7ca4ff2088c3 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 // predsList.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
185
7ca4ff2088c3 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 // const thead = () => {
7ca4ff2088c3 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 // const predColumnHead = (pred) => {
7ca4ff2088c3 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`<th>${rdfNode(new NamedNode(pred))}</th>`;
7ca4ff2088c3 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 // 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
191 // <thead>
7ca4ff2088c3 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 // <tr>
7ca4ff2088c3 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 // <th></th>
7ca4ff2088c3 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 // ${predsList.map(predColumnHead)}
7ca4ff2088c3 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 // </tr>
7ca4ff2088c3 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 // </thead>`;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
197 // };
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
198
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
199 // const instanceRow = (subj) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
200 // const cell = (pred) => {
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
201 // const objs = graphCells.get(subj + '|||' + pred);
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
202 // if (!objs) {
7ca4ff2088c3 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 // return html`<td></td>`;
7ca4ff2088c3 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 // }
7ca4ff2088c3 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 // const objsList = Array.from(objs);
7ca4ff2088c3 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 // objsList.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
207 // const draw = (obj) => {
7ca4ff2088c3 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 // return html`<div>${rdfNode(obj)}</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
209 // };
7ca4ff2088c3 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 // return html`<td>${objsList.map(draw)}</td>`;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
211 // };
8
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 // 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
214 // <tr>
7ca4ff2088c3 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 // <td>${rdfNode(new NamedNode(subj))}</td>
7ca4ff2088c3 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 // ${predsList.map(cell)}
7ca4ff2088c3 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 // </tr>
7ca4ff2088c3 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 // `;
7ca4ff2088c3 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 // };
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
220
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
221 // 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
222 // <div>[icon] ${rdfNode(new NamedNode(typeUri))} resources</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
223 // <div class="typeBlockScroll">
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
224 // <table class="typeBlock">
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
225 // ${thead()}
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
226 // ${subjs.map(instanceRow)}
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
227 // </table>
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
228 // </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
229 // `;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
230 // };
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
231
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
232 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
233
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
234 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
235 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
236 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
237
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
238 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
239 untypedSubjs.sort();
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
240
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
241 return html`
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
242 <link rel="stylesheet" href="../src/streamed-graph.css">
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
243
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
244 <section>
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
245 <h2>
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
246 Current graph (<a href="${this.url}">${this.url}</a>)
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
247 </h2>
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
248 <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
249 <!-- todo: graphs and provenance.
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
250 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
251 <span data-bind="html: $root.createCurie(graphUri())">...</span> graph.-->
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
252 </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
253 {typedSubjs.map(byTypeBlock)}
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
254 <div class="spoGrid">
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
255 ${untypedSubjs.map(this._subjBlock.bind(this))}
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
256 </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
257 </section>
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
258 `;
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
259 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
260 }