Mercurial > code > home > repos > streamed-graph
diff src/layout/Layout.test.ts @ 122:2e8fa3fec0c8
support joining subjects into wider rows
author | drewp@bigasterisk.com |
---|---|
date | Sun, 20 Mar 2022 14:12:03 -0700 |
parents | 3584f24becf4 |
children |
line wrap: on
line diff
--- a/src/layout/Layout.test.ts Sun Mar 20 14:10:56 2022 -0700 +++ b/src/layout/Layout.test.ts Sun Mar 20 14:12:03 2022 -0700 @@ -74,7 +74,7 @@ const vc = new ViewConfig(); await vc.readFromGraph(` @prefix : <http://example.com/> . - + <> a :View; :table [ :primaryType :T1 ] .`); const layout = new Layout(vc); lr = layout.plan(await typedStatements()); @@ -199,7 +199,104 @@ { rdfTypes: [EX("T1")], pred: EX("p3") }, { rdfTypes: [EX("T2")], pred: EX("p2") }, ]); - }) + }); + it("joins over an edge", async () => { + const vc = new ViewConfig(); + await vc.readFromGraph(` + @prefix : <http://example.com/> . + + <> a :View; :table [ + :primaryType :T1; + :link [:predicate :predLink ] ] . + `); + const layout = new Layout(vc); + const lr = layout.plan( + await n3Graph(` + @prefix : <http://example.com/> . + :g1 { + :a a :T1; :color :red; :predLink :b . + :b a :T2; :size :big . + } + `) + ); + + expect(lr.sections).toHaveLength(1); // no loose statements + const section0 = lr.sections[0] as AlignedTable; + expect(section0.rowHeaders).toEqual([EX("a")]); + expect(section0.columnHeaders).toEqual([ + { rdfTypes: [EX("T1")], pred: EX("color") }, + // :predLink column is hidden + { rdfTypes: [EX("T2")], pred: EX("size") }, + ]); + }); }); + it("joins 3 subjects into one", async () => { + const vc = new ViewConfig(); + await vc.readFromGraph(` + @prefix : <http://example.com/> . + + <> a :View; :table [ + :primaryType :T1; + :link + [:predicate :pred1Link ], + [:predicate :pred2Link ] + ] . + `); + const layout = new Layout(vc); + const lr = layout.plan( + await n3Graph(` + @prefix : <http://example.com/> . + :g1 { + :a a :T1; :color :red; :pred1Link :b; :pred2Link :c . + :b a :T2; :size :big . + :c a :T3; :bright 50 . + } + `) + ); + + expect(lr.sections).toHaveLength(1); // no loose statements + const section0 = lr.sections[0] as AlignedTable; + expect(section0.rowHeaders).toEqual([EX("a")]); + expect(section0.columnHeaders).toEqual([ + { rdfTypes: [EX("T1")], pred: EX("color") }, + { rdfTypes: [EX("T2")], pred: EX("size") }, + { rdfTypes: [EX("T3")], pred: EX("bright") }, + ]); + }); + it("links rows to predicate that themselves are linked in", async () => { + const vc = new ViewConfig(); + await vc.readFromGraph(` + @prefix : <http://example.com/> . + + <> a :View; :table [ + :primaryType :T1; + :link + [:predicate :pred1Link ], + [:predicate :pred2Link ] + ] . + `); + const layout = new Layout(vc); + const lr = layout.plan( + await n3Graph(` + @prefix : <http://example.com/> . + :g1 { + :a a :T1; :color :red; :pred1Link :b . + :b a :T2; :size :big; :pred2Link :c . + :c a :T3; :bright 50 . + } + `) + ); + console.log(JSON.stringify(lr.sections, null, " ")); + + expect(lr.sections).toHaveLength(1); // no loose statements + const section0 = lr.sections[0] as AlignedTable; + expect(section0.rowHeaders).toEqual([EX("a")]); + expect(section0.columnHeaders).toEqual([ + { rdfTypes: [EX("T1")], pred: EX("color") }, + { rdfTypes: [EX("T2")], pred: EX("size") }, + { rdfTypes: [EX("T3")], pred: EX("bright") }, + ]); + }); + it.skip("makes a table out of ungrouped triples with the same type", async () => {}); });