comparison src/graph_view.ts @ 39:f551a089a98f

add back type-block rendering. untested.
author drewp@bigasterisk.com
date Sun, 29 Dec 2019 19:59:08 -0800
parents c751380b70c5
children 648bd89f9d47
comparison
equal deleted inserted replaced
38:d4036715028b 39:f551a089a98f
159 </div> 159 </div>
160 `; 160 `;
161 } 161 }
162 162
163 163
164 // const byTypeBlock = (typeUri) => { 164 byTypeBlock(byType: TypeToSubjs, typeUri: NamedNode) {
165 // const subjs = Array.from(byType.get(typeUri)); 165 const subjSet = byType.get(typeUri);
166 // subjs.sort(); 166 const subjs: Array<NamedNode> = subjSet ? Array.from(subjSet) : [];
167 167 subjs.sort();
168 // const graphCells = new Map(); // [subj, pred] : objs 168
169 // const preds = new Set(); 169 const graphCells = new Map<string, Set<Term>>(); // [subj, pred] : objs
170 170 const makeCellKey = (subj: NamedNode, pred: NamedNode) => subj.value + '|||' + pred.value;
171 // subjs.forEach((subj) => { 171 const preds = new Set<NamedNode>();
172 // graph.getQuads({ subject: new NamedNode(subj) }, (q) => { 172
173 // preds.add(q.predicate.toString()); 173 subjs.forEach((subj: NamedNode) => {
174 // const cellKey = subj + '|||' + q.predicate.toString(); 174 this.graph.forEach((q: Quad) => {
175 // if (!graphCells.has(cellKey)) { 175 if (!Util.isNamedNode(q.predicate)) {
176 // graphCells.set(cellKey, new Set()); 176 throw new Error();
177 // } 177 }
178 // graphCells.get(cellKey).add(q.object); 178 preds.add(q.predicate as NamedNode);
179 // }); 179 const cellKey = makeCellKey(subj, q.predicate as NamedNode);
180 // }); 180 if (!graphCells.has(cellKey)) {
181 // const predsList = Array.from(preds); 181 graphCells.set(cellKey, new Set<Term>());
182 // predsList.splice(predsList.indexOf('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), 1); 182 }
183 // // also pull out label, which should be used on 1st column 183 graphCells.get(cellKey)!.add(q.object);
184 // predsList.sort(); 184 }, subj, null, null, null);
185 185 });
186 // const thead = () => { 186 const predsList = Array.from(preds);
187 // const predColumnHead = (pred) => { 187 predsList.splice(predsList.indexOf(new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')), 1);
188 // return html`<th>${rdfNode(new NamedNode(pred))}</th>`; 188 // also pull out label, which should be used on 1st column
189 // }; 189 predsList.sort();
190 // return html` 190
191 // <thead> 191 const thead = () => {
192 // <tr> 192 const predColumnHead = (pred: NamedNode) => {
193 // <th></th> 193 return html`<th>${this.nodeDisplay.getHtml(pred)}</th>`;
194 // ${predsList.map(predColumnHead)} 194 };
195 // </tr> 195 return html`
196 // </thead>`; 196 <thead>
197 // }; 197 <tr>
198 198 <th></th>
199 // const instanceRow = (subj) => { 199 ${predsList.map(predColumnHead)}
200 // const cell = (pred) => { 200 </tr>
201 // const objs = graphCells.get(subj + '|||' + pred); 201 </thead>`;
202 // if (!objs) { 202 };
203 // return html`<td></td>`; 203
204 // } 204 const instanceRow = (subj: NamedNode) => {
205 // const objsList = Array.from(objs); 205 const cell = (pred: NamedNode) => {
206 // objsList.sort(); 206 const objs = graphCells.get(subj + '|||' + pred);
207 // const draw = (obj) => { 207 if (!objs) {
208 // return html`<div>${rdfNode(obj)}</div>` 208 return html`<td></td>`;
209 // }; 209 }
210 // return html`<td>${objsList.map(draw)}</td>`; 210 const objsList = Array.from(objs);
211 // }; 211 objsList.sort();
212 212 const draw = (obj: Term) => {
213 // return html` 213 return html`<div>${this.nodeDisplay.getHtml(obj)}</div>`
214 // <tr> 214 };
215 // <td>${rdfNode(new NamedNode(subj))}</td> 215 return html`<td>${objsList.map(draw)}</td>`;
216 // ${predsList.map(cell)} 216 };
217 // </tr> 217
218 // `; 218 return html`
219 // }; 219 <tr>
220 220 <td>${this.nodeDisplay.getHtml(subj)}</td>
221 // return html` 221 ${predsList.map(cell)}
222 // <div>[icon] ${rdfNode(new NamedNode(typeUri))} resources</div> 222 </tr>
223 // <div class="typeBlockScroll"> 223 `;
224 // <table class="typeBlock"> 224 };
225 // ${thead()} 225
226 // ${subjs.map(instanceRow)} 226 return html`
227 // </table> 227 <div>[icon] ${this.nodeDisplay.getHtml(typeUri)} resources</div>
228 // </div> 228 <div class="typeBlockScroll">
229 // `; 229 <table class="typeBlock">
230 // }; 230 ${thead()}
231 ${subjs.map(instanceRow)}
232 </table>
233 </div>
234 `;
235 };
231 236
232 makeTemplate(): TemplateResult { 237 makeTemplate(): TemplateResult {
233 238
234 const { byType, untyped } = groupByRdfType(this.graph); 239 const { byType, untyped } = groupByRdfType(this.graph);
235 const typedSubjs = Array.from(byType.keys()); 240 const typedSubjs = Array.from(byType.keys());
248 <div> 253 <div>
249 <!-- todo: graphs and provenance. 254 <!-- todo: graphs and provenance.
250 These statements are all in the 255 These statements are all in the
251 <span data-bind="html: $root.createCurie(graphUri())">...</span> graph.--> 256 <span data-bind="html: $root.createCurie(graphUri())">...</span> graph.-->
252 </div> 257 </div>
253 {typedSubjs.map(byTypeBlock)} 258 ${typedSubjs.map((t: NamedNode) => this.byTypeBlock(byType, t))}
254 <div class="spoGrid"> 259 <div class="spoGrid">
255 ${untypedSubjs.map(this._subjBlock.bind(this))} 260 ${untypedSubjs.map(this._subjBlock.bind(this))}
256 </div> 261 </div>
257 </section> 262 </section>
258 `; 263 `;