comparison src/layout/Layout.ts @ 128:5a1a79f54779

big rewrite
author drewp@bigasterisk.com
date Fri, 05 May 2023 21:26:36 -0700
parents 2e8fa3fec0c8
children cf642d395be4
comparison
equal deleted inserted replaced
127:d2580faef057 128:5a1a79f54779
218 }); 218 });
219 219
220 return out; 220 return out;
221 } 221 }
222 222
223 function freeStatmentsSection(stmts: Quad[]): FreeStatements { 223 function freeStatmentsSection(viewConfig: ViewConfig, stmts: Quad[]): FreeStatements {
224 const subjs: NamedNode[] = []; 224 const subjs: NamedNode[] = [];
225 stmts.forEach((q) => { 225 stmts.forEach((q) => {
226 if (viewConfig.freeStatementsHidePred.has(q.predicate)) {
227 return;
228 }
226 subjs.push(q.subject as NamedNode); 229 subjs.push(q.subject as NamedNode);
227 }); 230 });
228 return { 231 return {
229 subjRows: uniqueSortedTerms(subjs).map((subj) => { 232 subjRows: uniqueSortedTerms(subjs).map((subj) => {
230 const preds: NamedNode[] = []; 233 const preds: NamedNode[] = [];
231 let po = Immutable.Map<NamedNode, Term[]>(); 234 let po = Immutable.Map<NamedNode, Term[]>();
232 stmts.forEach((q) => { 235 stmts.forEach((q) => {
233 if (q.subject.equals(subj)) { 236 if (q.subject.equals(subj) && !viewConfig.freeStatementsHidePred.has(q.predicate)) {
234 const p = q.predicate as NamedNode; 237 const p = q.predicate as NamedNode;
235 preds.push(p); 238 preds.push(p);
236 po = addToValues(po, p, q.object as NamedNode); 239 po = addToValues(po, p, q.object as NamedNode);
237 } 240 }
238 }); 241 });
246 }; 249 };
247 } 250 }
248 251
249 // The description of how this page should look: sections, tables, etc. 252 // The description of how this page should look: sections, tables, etc.
250 export class Layout { 253 export class Layout {
251 constructor(public viewConfig?: ViewConfig) {} 254 constructor(public viewConfig: ViewConfig) {}
252 255
253 private groupAllStatements( 256 private groupAllStatements(
254 graph: Store, 257 graph: Store,
255 tablesWantingSubject: SubjectTableBuilders, 258 tablesWantingSubject: SubjectTableBuilders,
256 ungrouped: Quad[] 259 ungrouped: Quad[]
271 null 274 null
272 ); 275 );
273 } 276 }
274 277
275 private generateSections( 278 private generateSections(
279 viewConfig: ViewConfig,
276 tableBuilders: AlignedTableBuilder[], 280 tableBuilders: AlignedTableBuilder[],
277 ungrouped: Quad[] 281 ungrouped: Quad[]
278 ): (AlignedTable | FreeStatements)[] { 282 ): (AlignedTable | FreeStatements)[] {
279 const sections = []; 283 const sections = [];
280 for (const t of tableBuilders) { 284 for (const t of tableBuilders) {
281 if (t.gotStatements()) { 285 if (t.gotStatements()) {
282 sections.push(t.value()); 286 sections.push(t.value());
283 } 287 }
284 } 288 }
285 if (ungrouped.length) { 289 if (ungrouped.length) {
286 sections.push(freeStatmentsSection(ungrouped)); 290 sections.push(freeStatmentsSection(viewConfig, ungrouped));
287 } 291 }
288 return sections; 292 return sections;
289 } 293 }
290 294
291 plan(graph: Store): LayoutResult { 295 plan(graph: Store): LayoutResult {
292 const vcTables = this.viewConfig ? this.viewConfig.tables : []; 296 const vcTables = this.viewConfig.tables;
293 const tableBuilders = vcTables.map( 297 const tableBuilders = vcTables.map(
294 (t) => new AlignedTableBuilder(t.primary, t.joins, t.links) 298 (t) => new AlignedTableBuilder(t.primary, t.joins, t.links)
295 ); 299 );
296 300
297 const tablesWantingSubject = subjectsToTablesMap(graph, tableBuilders); 301 const tablesWantingSubject = subjectsToTablesMap(graph, tableBuilders);
298 const ungrouped: Quad[] = []; 302 const ungrouped: Quad[] = [];
299 this.groupAllStatements(graph, tablesWantingSubject, ungrouped); 303 this.groupAllStatements(graph, tablesWantingSubject, ungrouped);
300 return { sections: this.generateSections(tableBuilders, ungrouped) }; 304 return { sections: this.generateSections(this.viewConfig, tableBuilders, ungrouped) };
301 } 305 }
302 } 306 }