) {
+ let cur = this.subjsSeenWithPred.get(pred, undefined);
+ if (cur === undefined) {
+ cur = [];
+ this.subjsSeenWithPred = this.subjsSeenWithPred.set(pred, cur);
+ }
+ cur.push(subj);
}
_displayedPreds(): NamedNode[] {
@@ -70,9 +101,11 @@
preds = tagged.map((e) => e.val);
return preds;
}
+
gotStatements(): boolean {
return !this.subjSet.isEmpty();
}
+
value(): AlignedTable {
const subjs = uniqueSortedTerms(this.subjSet);
const preds = this._displayedPreds();
@@ -87,8 +120,16 @@
outputGrid.push(row);
}
- const headers = preds.map((pred) => {
- return { rdfType: this.rdfType, pred: pred };
+ const headers: ColumnHeader[] = preds.map((pred) => {
+ const subs = this.subjsSeenWithPred.get(pred, []);
+ const types: NamedNode[] = [];
+ subs.forEach((s) => {
+ this.typesSeenForSubj.get(s, []).forEach((t) => {
+ types.push(t);
+ });
+ });
+
+ return { rdfTypes: uniqueSortedTerms(types), pred: pred };
});
return { columnHeaders: headers, rowHeaders: subjs, rows: outputGrid };
}
@@ -107,9 +148,10 @@
graph.forEach(
(q: Quad) => {
const s = q.subject as NamedNode;
+ const rdfType = q.object as NamedNode;
tableBuilders.forEach((tb) => {
- if (tb.rdfType.equals(q.object)) {
- let cur = out.get(s);
+ if (tb.showsType(rdfType)) {
+ let cur = out.get(s, undefined);
if (cur === undefined) {
cur = [];
out = out.set(s, cur);
@@ -165,6 +207,7 @@
graph.forEach(
(q: Quad) => {
const tables = tablesWantingSubject.get(q.subject as NamedNode);
+
if (tables && tables.length) {
tables.forEach((t: AlignedTableBuilder) => t.addQuad(q));
} else {
@@ -182,7 +225,9 @@
const ungrouped: Quad[] = [];
const tableBuilders = this.viewConfig
- ? this.viewConfig.tables.map((t) => new AlignedTableBuilder(t.primary))
+ ? this.viewConfig.tables.map(
+ (t) => new AlignedTableBuilder(t.primary, t.joins)
+ )
: [];
const tablesWantingSubject = subjectsToTablesMap(graph, tableBuilders);
diff -r 069c1f70afa5 -r c2923b20bf5c src/render/GraphView.ts
--- a/src/render/GraphView.ts Sat Mar 19 17:45:01 2022 -0700
+++ b/src/render/GraphView.ts Sun Mar 20 00:54:19 2022 -0700
@@ -8,6 +8,7 @@
PredRow,
SubjRow,
} from "../layout/Layout";
+import { uniqueSortedTerms } from "../layout/rdf_value";
import { SuffixLabels } from "../layout/suffixLabels";
import { ViewConfig } from "../layout/ViewConfig";
import { NodeDisplay } from "./NodeDisplay";
@@ -74,6 +75,7 @@
null
);
}
+
_renderSection(section: AlignedTable | FreeStatements) {
if ((section as any).columnHeaders) {
return this._renderAlignedTable(section as AlignedTable);
@@ -83,31 +85,56 @@
}
_renderAlignedTable(section: AlignedTable): TemplateResult {
- let anyType: NamedNode = new NamedNode('');
- const heads = section.columnHeaders.map((ch) => {
- anyType = ch.rdfType;
- return html`${this.nodeDisplay.render(ch.pred)} | `;
- });
+ const tableTypes: NamedNode[][] = [];
+ const typeHeads: TemplateResult[] = [];
+ const heads: TemplateResult[] = [];
+ for (let ch of section.columnHeaders) {
+ const colSpan = 1; //todo
+ typeHeads.push(
+ html`
+ ${ch.rdfTypes.map((n) => this.nodeDisplay.render(n))}
+ | `
+ );
+
+ tableTypes.push(ch.rdfTypes);
+ heads.push(html`${this.nodeDisplay.render(ch.pred)} | `);
+ }
+
const cells = [];
for (let rowIndex in section.rows) {
- const headerCol = html`${this.nodeDisplay.render(section.rowHeaders[rowIndex])} | `;
- const bodyCols = []
+ const headerCol = this.nodeDisplay.render(section.rowHeaders[rowIndex]);
+ const bodyCols = [];
for (let cellObjs of section.rows[rowIndex]) {
const display = cellObjs.map(
(t) => html`${this.nodeDisplay.render(t)}
`
);
bodyCols.push(html`${display} | `);
}
- cells.push(html`${headerCol}${bodyCols}
`);
+ cells.push(
+ html`
+ ${headerCol} |
+ ${bodyCols}
+
`
+ );
}
+ const tableTypesUnique = uniqueSortedTerms(tableTypes.flat());
+ const typesDisplay = html`${tableTypesUnique.length == 1 ? "type" : "types"}
+ ${tableTypesUnique.map((n) => this.nodeDisplay.render(n))}`;
+
return html`
- [icon] Resources of type ${this.nodeDisplay.render(anyType)}
+ [icon] Resources of ${typesDisplay}