Mercurial > code > home > repos > streamed-graph
annotate src/layout/ViewConfig.ts @ 128:5a1a79f54779
big rewrite
author | drewp@bigasterisk.com |
---|---|
date | Fri, 05 May 2023 21:26:36 -0700 |
parents | 2e8fa3fec0c8 |
children | cf642d395be4 |
rev | line source |
---|---|
128 | 1 import Immutable from "immutable"; // mostly using this for the builtin equals() testing, since NamedNode(x)!=NamedNode(x) |
2 import { DataFactory, NamedNode, Quad_Predicate, Term } from "n3"; | |
3 import { MultiStore } from "../MultiStore"; | |
4 import { EX } from "./namespaces"; | |
5 import { uriValue } from "./rdf_value"; | |
94 | 6 const Uri = DataFactory.namedNode; |
93 | 7 |
94 | 8 function firstElem<E>(seq: Iterable<E>): E { |
9 for (let e of seq) { | |
10 return e; | |
11 } | |
12 throw new Error("no elems"); | |
13 } | |
14 | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
15 export interface Link { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
16 // If you display a subject u1 with a `pred` edge to u2, then treat u2 as an alias of u1. |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
17 pred: NamedNode; |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
18 } |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
19 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
20 interface TableDesc { |
97 | 21 uri: NamedNode; |
22 primary: NamedNode; | |
23 joins: NamedNode[]; | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
24 links: Link[]; |
97 | 25 } |
26 | |
128 | 27 // High-level guide to how to draw the page, independent of the graph data. |
28 // Layout.ts turns this plus the actual graph data into a structure that's | |
29 // close to the final render. | |
102 | 30 export class ViewConfig { |
128 | 31 viewRoot: NamedNode; // this structure... |
32 graph: MultiStore; // in this graph... | |
33 tables: TableDesc[] = []; // populates all the rest of these fields for use by Layout | |
34 freeStatementsHidePred: Immutable.Set<Quad_Predicate> = Immutable.Set(); | |
95 | 35 |
128 | 36 constructor(graph: MultiStore, viewUri: NamedNode) { |
37 this.graph = graph; | |
38 this.viewRoot = viewUri; | |
39 // todo | |
40 const here = "https://bigasterisk.com/lanscape/"; | |
41 if (this.viewRoot.value.startsWith(here)) { | |
42 this.viewRoot = new NamedNode(this.viewRoot.value.slice(here.length)); | |
43 } | |
44 // todo: might need to reread if graph changes | |
45 this.read(); | |
93 | 46 } |
95 | 47 |
128 | 48 private read() { |
49 for (let table of this.graph.getObjects(this.viewRoot, EX("table"), null)) { | |
50 const t = this.readTable(table); | |
51 this.tables.push(t); | |
102 | 52 } |
128 | 53 this.tables.sort(); |
102 | 54 |
128 | 55 this.readHides(); |
102 | 56 } |
57 | |
128 | 58 private readHides() { |
59 for (let hideInstruction of this.graph.getObjects( | |
60 this.viewRoot, | |
61 EX("freeStatementsHide"), | |
62 null | |
63 )) { | |
64 for (let pred of this.graph.getObjects( | |
65 hideInstruction, | |
66 EX("predicate"), | |
67 null | |
68 )) { | |
69 this.freeStatementsHidePred = this.freeStatementsHidePred.add( | |
70 pred as Quad_Predicate | |
71 ); | |
97 | 72 } |
128 | 73 } |
74 } | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
75 |
128 | 76 private readTable(table: Term): TableDesc { |
77 const tableType = uriValue(this.graph, table, EX("primaryType")); | |
78 const joins: NamedNode[] = []; | |
79 for (let joinType of this.graph.getObjects(table, EX("joinType"), null)) { | |
80 joins.push(joinType as NamedNode); | |
81 } | |
82 joins.sort(); | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
83 |
128 | 84 const links: Link[] = []; |
85 for (let linkDesc of this.graph.getObjects(table, EX("link"), null)) { | |
86 links.push({ | |
87 pred: uriValue(this.graph, linkDesc, EX("predicate")), | |
102 | 88 }); |
94 | 89 } |
102 | 90 |
128 | 91 return { |
92 uri: table as NamedNode, | |
93 primary: tableType, | |
94 joins: joins, | |
95 links: links, | |
96 }; | |
93 | 97 } |
98 } |