annotate src/graph_view.ts @ 94:a5f53d397526

view: pick types to show at top-level
author drewp@bigasterisk.com
date Wed, 12 Jan 2022 22:09:20 -0800
parents 955cde1550c3
children 4d19759d0d9a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
1 import { html, TemplateResult } from "lit";
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
2 import { DataFactory, Literal, NamedNode, Quad, Store, Term, Util } from "n3";
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
3 import { SuffixLabels } from "./suffixLabels";
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
4 import {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
5 groupByRdfType,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
6 MultiSubjsTypeBlockLayout,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
7 predsForSubj,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
8 TypeToSubjs,
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
9 } from "./tabulate";
93
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
10 import { View } from "./view_loader";
76
58676ebdce0f sort and dedup imports
drewp@bigasterisk.com
parents: 71
diff changeset
11
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
12 const { namedNode } = DataFactory;
20
9ec3cbc8791a build is running, but no tests, and lots of code is disabled
drewp@bigasterisk.com
parents: 15
diff changeset
13
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
14 // https://github.com/rdfjs/N3.js/issues/265
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
15 if ((Literal.prototype as any).hashCode === undefined) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
16 (Literal.prototype as any).hashCode = () => 0;
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
17 }
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
18 if ((NamedNode.prototype as any).hashCode === undefined) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
19 (NamedNode.prototype as any).hashCode = () => 0;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
20 }
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
21 class NodeDisplay {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
22 labels: SuffixLabels;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
23 constructor(labels: SuffixLabels) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
24 this.labels = labels;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
25 }
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
26 render(n: Term | NamedNode): TemplateResult {
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
27 if (Util.isLiteral(n)) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
28 n = n as Literal;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
29 let dtPart: any = "";
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
30 if (
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
31 n.datatype &&
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
32 n.datatype.value != "http://www.w3.org/2001/XMLSchema#string" && // boring
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
33 n.datatype.value !=
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
34 "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString" // boring
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
35 ) {
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
36 dtPart = html`
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
37 ^^<span class="literalType"> ${this.render(n.datatype)} </span>
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
38 `;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
39 }
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
40 return html` <span class="literal">${n.value}${dtPart}</span> `;
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
41 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
42
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
43 if (Util.isNamedNode(n)) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
44 n = n as NamedNode;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
45 let shortened = false;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
46 let uriValue: string = n.value;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
47 for (let [long, short] of [
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
48 ["http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:"],
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
49 ["http://www.w3.org/2000/01/rdf-schema#", "rdfs:"],
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
50 ["http://purl.org/dc/elements/1.1/", "dc:"],
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
51 ["http://www.w3.org/2001/XMLSchema#", "xsd:"],
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
52 ]) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
53 if (uriValue.startsWith(long)) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
54 uriValue = short + uriValue.substr(long.length);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
55 shortened = true;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
56 break;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
57 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
58 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
59 if (!shortened) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
60 let dn: string | undefined = this.labels.getLabelForNode(uriValue);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
61 if (dn === undefined) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
62 throw new Error(`dn=${dn}`);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
63 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
64 uriValue = dn;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
65 }
28
c751380b70c5 uniqueness problem with NamedNodes in set
drewp@bigasterisk.com
parents: 22
diff changeset
66
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
67 return html` <a class="graphUri" href="${n.value}">${uriValue}</a> `;
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
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
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
70 return html` [${n.termType} ${n.value}] `;
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
71 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
72 }
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
73
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
74 export class GraphView {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
75 url: string;
93
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
76 view: View;
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
77 graph: Store;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
78 nodeDisplay: NodeDisplay;
93
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
79 constructor(url: string, viewUrl: string, graph: Store) {
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
80 this.url = url;
93
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
81 this.view = new View(viewUrl);
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
82 this.graph = graph;
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
83
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
84 const labels = new SuffixLabels();
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
85 this._addLabelsForAllTerms(labels);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
86 this.nodeDisplay = new NodeDisplay(labels);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
87 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
88
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
89 _addLabelsForAllTerms(labels: SuffixLabels) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
90 return this.graph.forEach(
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
91 (q: Quad) => {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
92 if (q.subject.termType === "NamedNode") {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
93 labels.planDisplayForNode(q.subject);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
94 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
95 if (q.predicate.termType === "NamedNode") {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
96 labels.planDisplayForNode(q.predicate);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
97 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
98 if (q.object.termType === "NamedNode") {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
99 labels.planDisplayForNode(q.object);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
100 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
101 if (q.object.termType === "Literal" && q.object.datatype) {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
102 labels.planDisplayForNode(q.object.datatype);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
103 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
104 },
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
105 null,
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
106 null,
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
107 null,
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
108 null
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
109 );
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
110 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
111
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
112 _subjPredObjsBlock(subj: NamedNode) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
113 const columns = predsForSubj(this.graph, subj);
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
114 return html`
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
115 <div class="subject">
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
116 ${this.nodeDisplay.render(subj)}
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
117 <!-- todo: special section for uri/type-and-icon/label/comment -->
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
118 <div>
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
119 ${columns.map((p) => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
120 return this._predObjsBlock(subj, p);
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
121 })}
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
122 </div>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
123 </div>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
124 `;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
125 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
126
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
127 _objCell(obj: Term) {
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
128 return html`
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
129 <div class="object">
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
130 ${this.nodeDisplay.render(obj)}
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
131 <!-- indicate what source or graph said this stmt -->
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
132 </div>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
133 `;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
134 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
135
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
136 _predObjsBlock(subj: NamedNode, pred: NamedNode) {
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
137 const objsSet = new Set<Term>();
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
138 this.graph.forEach(
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
139 (q: Quad) => {
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
140 objsSet.add(q.object);
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
141 },
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
142 subj,
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
143 pred,
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
144 null,
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
145 null
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
146 );
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
147 const objs = Array.from(objsSet.values());
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
148 objs.sort();
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
149 return html`
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
150 <div class="predicate">
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
151 ${this.nodeDisplay.render(pred)}
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
152 <div>${objs.map(this._objCell.bind(this))}</div>
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
153 </div>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
154 `;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
155 }
15
7ca4ff2088c3 managed to use a newer ts or something, so this includes a bunch of type fixes too
drewp@bigasterisk.com
parents: 9
diff changeset
156
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
157 _drawObj(obj: Term): TemplateResult {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
158 return html` <div>${this.nodeDisplay.render(obj)}</div> `;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
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
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
161 _drawColumnHead(pred: NamedNode): TemplateResult {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
162 return html` <th>${this.nodeDisplay.render(pred)}</th> `;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
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
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
165 _thead(layout: MultiSubjsTypeBlockLayout): TemplateResult {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
166 return html`
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
167 <thead>
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
168 <tr>
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
169 <th></th>
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
170 ${layout.preds.map(this._drawColumnHead.bind(this))}
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
171 </tr>
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
172 </thead>
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
173 `;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
174 }
49
c16a331f42e5 rewrap; stylesheet
drewp@bigasterisk.com
parents: 40
diff changeset
175
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
176 _msbCell(layout: MultiSubjsTypeBlockLayout, subj: NamedNode) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
177 return (pred: NamedNode): TemplateResult => {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
178 const objs = layout.graphCells.get(layout.makeCellKey(subj, pred));
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
179 if (!objs || !objs.size) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
180 return html` <td></td> `;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
181 }
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
182 const objsList = Array.from(objs);
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
183 objsList.sort();
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
184 return html` <td>${objsList.map(this._drawObj.bind(this))}</td> `;
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
185 };
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
186 }
8
6fefd287aff9 closer- element now holds a changing graph, but can't draw it yet
drewp@bigasterisk.com
parents:
diff changeset
187
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
188 _instanceRow(layout: MultiSubjsTypeBlockLayout) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
189 return (subj: NamedNode): TemplateResult => {
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
190 return html`
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
191 <tr>
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
192 <td>${this.nodeDisplay.render(subj)}</td>
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
193 ${layout.preds.map(this._msbCell(layout, subj))}
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
194 </tr>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
195 `;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
196 };
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
197 }
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
198
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
199 _multiSubjsTypeBlock(byType: TypeToSubjs, typeUri: NamedNode) {
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
200 const layout = new MultiSubjsTypeBlockLayout(this.graph, byType, typeUri);
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
201
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
202 return html`
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
203 <div>[icon] ${this.nodeDisplay.render(typeUri)} type resources</div>
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
204 <div class="typeBlockScroll">
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
205 <table class="typeBlock">
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
206 ${this._thead(layout)} ${layout.subjs.map(this._instanceRow(layout))}
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
207 </table>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
208 </div>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
209 `;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
210 }
49
c16a331f42e5 rewrap; stylesheet
drewp@bigasterisk.com
parents: 40
diff changeset
211
93
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
212 async makeTemplate(): Promise<TemplateResult> {
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
213 await this.view.ready;
94
a5f53d397526 view: pick types to show at top-level
drewp@bigasterisk.com
parents: 93
diff changeset
214 const { byType, typesPresent, untypedSubjs } = groupByRdfType(this.graph);
93
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
215 let viewTitle = html` (no view)`;
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
216 if (this.view.url) {
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
217 viewTitle = html` using view <a href="${this.view.url}">${this.view.label()}</a>`;
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
218 }
94
a5f53d397526 view: pick types to show at top-level
drewp@bigasterisk.com
parents: 93
diff changeset
219 const typesToShow = this.view.typesToShow(typesPresent);
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
220 return html`
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
221 <section>
93
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
222 <h2>
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
223 Current graph (<a href="${this.url}">${this.url}</a>)${viewTitle}
955cde1550c3 start the View work: parse view document
drewp@bigasterisk.com
parents: 88
diff changeset
224 </h2>
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
225 <div>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
226 <!-- todo: graphs and provenance.
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
227 These statements are all in the
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
228 <span data-bind="html: $root.createCurie(graphUri())">...</span> graph.-->
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
229 </div>
94
a5f53d397526 view: pick types to show at top-level
drewp@bigasterisk.com
parents: 93
diff changeset
230 ${typesToShow.map((t: NamedNode) =>
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
231 this._multiSubjsTypeBlock(byType, t)
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
232 )}
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
233 <div class="spoGrid">
88
ac7ad087d474 graph view rewrites and fixes for the multi-subject table
drewp@bigasterisk.com
parents: 84
diff changeset
234 ${untypedSubjs.map(this._subjPredObjsBlock.bind(this))}
84
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
235 </div>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
236 </section>
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
237 `;
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
238 }
067d66a45a51 enable more code. factor out setGraphView
drewp@bigasterisk.com
parents: 79
diff changeset
239 }