# HG changeset patch # User drewp@bigasterisk.com # Date 1577678348 28800 # Node ID f551a089a98f553487d93470a75cf2e11758aadc # Parent d4036715028b6d831d0015b9628f091aad47542c add back type-block rendering. untested. diff -r d4036715028b -r f551a089a98f src/graph_view.ts --- a/src/graph_view.ts Sun Dec 29 19:43:25 2019 -0800 +++ b/src/graph_view.ts Sun Dec 29 19:59:08 2019 -0800 @@ -161,73 +161,78 @@ } - // const byTypeBlock = (typeUri) => { - // const subjs = Array.from(byType.get(typeUri)); - // subjs.sort(); + byTypeBlock(byType: TypeToSubjs, typeUri: NamedNode) { + const subjSet = byType.get(typeUri); + const subjs: Array = subjSet ? Array.from(subjSet) : []; + subjs.sort(); - // const graphCells = new Map(); // [subj, pred] : objs - // const preds = new Set(); + const graphCells = new Map>(); // [subj, pred] : objs + const makeCellKey = (subj: NamedNode, pred: NamedNode) => subj.value + '|||' + pred.value; + const preds = new Set(); - // subjs.forEach((subj) => { - // graph.getQuads({ subject: new NamedNode(subj) }, (q) => { - // preds.add(q.predicate.toString()); - // const cellKey = subj + '|||' + q.predicate.toString(); - // if (!graphCells.has(cellKey)) { - // graphCells.set(cellKey, new Set()); - // } - // graphCells.get(cellKey).add(q.object); - // }); - // }); - // const predsList = Array.from(preds); - // predsList.splice(predsList.indexOf('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), 1); - // // also pull out label, which should be used on 1st column - // predsList.sort(); + subjs.forEach((subj: NamedNode) => { + this.graph.forEach((q: Quad) => { + if (!Util.isNamedNode(q.predicate)) { + throw new Error(); + } + preds.add(q.predicate as NamedNode); + const cellKey = makeCellKey(subj, q.predicate as NamedNode); + if (!graphCells.has(cellKey)) { + graphCells.set(cellKey, new Set()); + } + graphCells.get(cellKey)!.add(q.object); + }, subj, null, null, null); + }); + const predsList = Array.from(preds); + predsList.splice(predsList.indexOf(new NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')), 1); + // also pull out label, which should be used on 1st column + predsList.sort(); - // const thead = () => { - // const predColumnHead = (pred) => { - // return html`${rdfNode(new NamedNode(pred))}`; - // }; - // return html` - // - // - // - // ${predsList.map(predColumnHead)} - // - // `; - // }; + const thead = () => { + const predColumnHead = (pred: NamedNode) => { + return html`${this.nodeDisplay.getHtml(pred)}`; + }; + return html` + + + + ${predsList.map(predColumnHead)} + + `; + }; - // const instanceRow = (subj) => { - // const cell = (pred) => { - // const objs = graphCells.get(subj + '|||' + pred); - // if (!objs) { - // return html``; - // } - // const objsList = Array.from(objs); - // objsList.sort(); - // const draw = (obj) => { - // return html`
${rdfNode(obj)}
` - // }; - // return html`${objsList.map(draw)}`; - // }; + const instanceRow = (subj: NamedNode) => { + const cell = (pred: NamedNode) => { + const objs = graphCells.get(subj + '|||' + pred); + if (!objs) { + return html``; + } + const objsList = Array.from(objs); + objsList.sort(); + const draw = (obj: Term) => { + return html`
${this.nodeDisplay.getHtml(obj)}
` + }; + return html`${objsList.map(draw)}`; + }; - // return html` - // - // ${rdfNode(new NamedNode(subj))} - // ${predsList.map(cell)} - // - // `; - // }; + return html` + + ${this.nodeDisplay.getHtml(subj)} + ${predsList.map(cell)} + + `; + }; - // return html` - //
[icon] ${rdfNode(new NamedNode(typeUri))} resources
- //
- // - // ${thead()} - // ${subjs.map(instanceRow)} - //
- //
- // `; - // }; + return html` +
[icon] ${this.nodeDisplay.getHtml(typeUri)} resources
+
+ + ${thead()} + ${subjs.map(instanceRow)} +
+
+ `; + }; makeTemplate(): TemplateResult { @@ -250,7 +255,7 @@ These statements are all in the ... graph.--> - {typedSubjs.map(byTypeBlock)} + ${typedSubjs.map((t: NamedNode) => this.byTypeBlock(byType, t))}
${untypedSubjs.map(this._subjBlock.bind(this))}