Mercurial > code > home > repos > streamed-graph
annotate src/layout/ViewConfig.ts @ 143:5adf79d4a9f4
release v0.11.0
author | drewp@bigasterisk.com |
---|---|
date | Mon, 08 May 2023 13:29:48 -0700 |
parents | cf642d395be4 |
children |
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"; | |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
4 import { EX, RDF } from "./namespaces"; |
128 | 5 import { uriValue } from "./rdf_value"; |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
6 import { Quad_Graph } from "rdf-js"; |
94 | 7 const Uri = DataFactory.namedNode; |
93 | 8 |
94 | 9 function firstElem<E>(seq: Iterable<E>): E { |
10 for (let e of seq) { | |
11 return e; | |
12 } | |
13 throw new Error("no elems"); | |
14 } | |
15 | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
16 export interface Link { |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
17 // 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
|
18 pred: NamedNode; |
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 |
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
21 interface TableDesc { |
97 | 22 uri: NamedNode; |
23 primary: NamedNode; | |
24 joins: NamedNode[]; | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
25 links: Link[]; |
97 | 26 } |
27 | |
128 | 28 // High-level guide to how to draw the page, independent of the graph data. |
29 // Layout.ts turns this plus the actual graph data into a structure that's | |
30 // close to the final render. | |
102 | 31 export class ViewConfig { |
128 | 32 viewRoot: NamedNode; // this structure... |
33 graph: MultiStore; // in this graph... | |
34 tables: TableDesc[] = []; // populates all the rest of these fields for use by Layout | |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
35 hidePredFrees: Immutable.Set<Quad_Predicate> = Immutable.Set(); |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
36 hideGraphEverywhere: Immutable.Set<Quad_Graph> = Immutable.Set(); |
95 | 37 |
128 | 38 constructor(graph: MultiStore, viewUri: NamedNode) { |
39 this.graph = graph; | |
40 this.viewRoot = viewUri; | |
41 // todo | |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
42 // const here = "https://bigasterisk.com/lanscape/"; |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
43 // if (this.viewRoot.value.startsWith(here)) { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
44 // this.viewRoot = new NamedNode(this.viewRoot.value.slice(here.length)); |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
45 // } |
128 | 46 this.read(); |
93 | 47 } |
95 | 48 |
128 | 49 private read() { |
50 for (let table of this.graph.getObjects(this.viewRoot, EX("table"), null)) { | |
51 const t = this.readTable(table); | |
52 this.tables.push(t); | |
102 | 53 } |
128 | 54 this.tables.sort(); |
102 | 55 |
128 | 56 this.readHides(); |
102 | 57 } |
58 | |
128 | 59 private readHides() { |
139
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
60 for (let instr of this.graph.getObjects(this.viewRoot, EX("hide"), null)) { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
61 const types = this.graph.getObjects(instr, RDF("type"), null); |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
62 if (types.length == 1 && types[0].equals(EX("HideEverywhere"))) { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
63 for (let g of this.graph.getObjects(instr, EX("graph"), null)) { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
64 this.hideGraphEverywhere = this.hideGraphEverywhere.add( |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
65 g as Quad_Graph |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
66 ); |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
67 } |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
68 } else if (types.length == 1 && types[0].equals(EX("HideFreeStatements"))) { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
69 for (let pred of this.graph.getObjects(instr, EX("predicate"), null)) { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
70 this.hidePredFrees = this.hidePredFrees.add(pred as Quad_Predicate); |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
71 } |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
72 } else { |
cf642d395be4
new simpler Patch class; fancier 'hide' view config support
drewp@bigasterisk.com
parents:
128
diff
changeset
|
73 throw new Error(":hide instruction must have 1 valid type"); |
97 | 74 } |
128 | 75 } |
76 } | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
77 |
128 | 78 private readTable(table: Term): TableDesc { |
79 const tableType = uriValue(this.graph, table, EX("primaryType")); | |
80 const joins: NamedNode[] = []; | |
81 for (let joinType of this.graph.getObjects(table, EX("joinType"), null)) { | |
82 joins.push(joinType as NamedNode); | |
83 } | |
84 joins.sort(); | |
122
2e8fa3fec0c8
support joining subjects into wider rows
drewp@bigasterisk.com
parents:
110
diff
changeset
|
85 |
128 | 86 const links: Link[] = []; |
87 for (let linkDesc of this.graph.getObjects(table, EX("link"), null)) { | |
88 links.push({ | |
89 pred: uriValue(this.graph, linkDesc, EX("predicate")), | |
102 | 90 }); |
94 | 91 } |
102 | 92 |
128 | 93 return { |
94 uri: table as NamedNode, | |
95 primary: tableType, | |
96 joins: joins, | |
97 links: links, | |
98 }; | |
93 | 99 } |
100 } |