Mercurial > code > home > repos > streamed-graph
diff src/layout/Layout.test.ts @ 118:c2923b20bf5c
support multi labels per column
author | drewp@bigasterisk.com |
---|---|
date | Sun, 20 Mar 2022 00:54:19 -0700 |
parents | dd3325cc023e |
children | 8715633f5213 |
line wrap: on
line diff
--- a/src/layout/Layout.test.ts Sat Mar 19 17:45:01 2022 -0700 +++ b/src/layout/Layout.test.ts Sun Mar 20 00:54:19 2022 -0700 @@ -84,14 +84,14 @@ expect(lr.sections).toHaveLength(2); }); it("puts the right type in the table", async () => { - const sec0 = lr.sections[0] as AlignedTable; - expect(sec0.columnHeaders).toEqual([ - { rdfType: EX("T1"), pred: EX("color") }, - { rdfType: EX("T1"), pred: EX("size") }, + const section0 = lr.sections[0] as AlignedTable; + expect(section0.columnHeaders).toEqual([ + { rdfTypes: [EX("T1")], pred: EX("color") }, + { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, // and doesn't include rdf:type as a column header here ]); - expect(sec0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); - expect(sec0.rows).toEqual([ + expect(section0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); + expect(section0.rows).toEqual([ [[EX("red")], []], [[EX("blue")], []], [[], []], @@ -123,26 +123,60 @@ const layout = new Layout(vc); const lr = layout.plan(await typedStatements()); expect(lr.sections).toHaveLength(2); - expect(lr.sections[0]).toEqual({ - columnHeaders: [ - { rdfType: EX("T1"), pred: EX("color") }, - { rdfType: EX("T1"), pred: EX("size") }, - ], - rowHeaders: [EX("a"), EX("b"), EX("c"), EX("e")], - rows: [ + const section0 = lr.sections[0] as AlignedTable; + expect(section0.columnHeaders).toEqual([ + { rdfTypes: [EX("T1")], pred: EX("color") }, + { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, + ]); + expect(section0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); + expect(section0.rows).toEqual([ + [[EX("red")], []], + [[EX("blue")], []], + [[], []], + [[], [EX("small")]], + ]); + const section1 = lr.sections[1] as AlignedTable; + expect(section1.columnHeaders).toEqual([ + { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, + ]); + expect(section1.rowHeaders).toEqual([EX("d"), EX("e")]); + expect(section1.rows).toEqual([ + [[EX("big")]], // + [[EX("small")]], + ]); + }); + describe("joins multiple types into one table", () => { + it("can simply merge types", async () => { + const vc = new ViewConfig(); + await vc.readFromGraph(` + @prefix ex: <http://example.com/> . + @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . + @prefix : <http://example.com/> . + + <> a :View; :table [ :primaryType :T1; :joinType :T2 ] . + `); + vc.graph.forEach((q) => console.log("vc", q), null, null, null, null); + const layout = new Layout(vc); + const lr = layout.plan( + await n3Graph(` + @prefix : <http://example.com/> . + :g1 { + :a a :T1 ; :color :red . + :b a :T2 ; :size :big . + } + `) + ); + expect(lr.sections).toHaveLength(1); + const section0 = lr.sections[0] as AlignedTable; + expect(section0.columnHeaders).toEqual([ + { rdfTypes: [EX("T1")], pred: EX("color") }, + { rdfTypes: [EX("T2")], pred: EX("size") }, + ]); + expect(section0.rowHeaders).toEqual([EX("a"), EX("b")]); + expect(section0.rows).toEqual([ [[EX("red")], []], - [[EX("blue")], []], - [[], []], - [[], [EX("small")]], - ], - }); - expect(lr.sections[1]).toEqual({ - columnHeaders: [{ rdfType: EX("T2"), pred: EX("size") }], - rowHeaders: [EX("d"), EX("e")], - rows: [ - [[EX("big")]], // - [[EX("small")]], - ], + [[], [EX("big")]], + ]); }); }); it.skip("makes a table out of ungrouped triples with the same type", async () => {});