Mercurial > code > home > repos > streamed-graph
comparison 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 |
comparison
equal
deleted
inserted
replaced
117:069c1f70afa5 | 118:c2923b20bf5c |
---|---|
82 }); | 82 }); |
83 it("returns 2 sections", () => { | 83 it("returns 2 sections", () => { |
84 expect(lr.sections).toHaveLength(2); | 84 expect(lr.sections).toHaveLength(2); |
85 }); | 85 }); |
86 it("puts the right type in the table", async () => { | 86 it("puts the right type in the table", async () => { |
87 const sec0 = lr.sections[0] as AlignedTable; | 87 const section0 = lr.sections[0] as AlignedTable; |
88 expect(sec0.columnHeaders).toEqual([ | 88 expect(section0.columnHeaders).toEqual([ |
89 { rdfType: EX("T1"), pred: EX("color") }, | 89 { rdfTypes: [EX("T1")], pred: EX("color") }, |
90 { rdfType: EX("T1"), pred: EX("size") }, | 90 { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, |
91 // and doesn't include rdf:type as a column header here | 91 // and doesn't include rdf:type as a column header here |
92 ]); | 92 ]); |
93 expect(sec0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); | 93 expect(section0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); |
94 expect(sec0.rows).toEqual([ | 94 expect(section0.rows).toEqual([ |
95 [[EX("red")], []], | 95 [[EX("red")], []], |
96 [[EX("blue")], []], | 96 [[EX("blue")], []], |
97 [[], []], | 97 [[], []], |
98 [[], [EX("small")]], | 98 [[], [EX("small")]], |
99 ]); | 99 ]); |
121 | 121 |
122 <> a :View; :table [ :primaryType :T1 ], [ :primaryType :T2 ] .`); | 122 <> a :View; :table [ :primaryType :T1 ], [ :primaryType :T2 ] .`); |
123 const layout = new Layout(vc); | 123 const layout = new Layout(vc); |
124 const lr = layout.plan(await typedStatements()); | 124 const lr = layout.plan(await typedStatements()); |
125 expect(lr.sections).toHaveLength(2); | 125 expect(lr.sections).toHaveLength(2); |
126 expect(lr.sections[0]).toEqual({ | 126 const section0 = lr.sections[0] as AlignedTable; |
127 columnHeaders: [ | 127 expect(section0.columnHeaders).toEqual([ |
128 { rdfType: EX("T1"), pred: EX("color") }, | 128 { rdfTypes: [EX("T1")], pred: EX("color") }, |
129 { rdfType: EX("T1"), pred: EX("size") }, | 129 { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, |
130 ], | 130 ]); |
131 rowHeaders: [EX("a"), EX("b"), EX("c"), EX("e")], | 131 expect(section0.rowHeaders).toEqual([EX("a"), EX("b"), EX("c"), EX("e")]); |
132 rows: [ | 132 expect(section0.rows).toEqual([ |
133 [[EX("red")], []], | |
134 [[EX("blue")], []], | |
135 [[], []], | |
136 [[], [EX("small")]], | |
137 ]); | |
138 const section1 = lr.sections[1] as AlignedTable; | |
139 expect(section1.columnHeaders).toEqual([ | |
140 { rdfTypes: [EX("T1"), EX("T2")], pred: EX("size") }, | |
141 ]); | |
142 expect(section1.rowHeaders).toEqual([EX("d"), EX("e")]); | |
143 expect(section1.rows).toEqual([ | |
144 [[EX("big")]], // | |
145 [[EX("small")]], | |
146 ]); | |
147 }); | |
148 describe("joins multiple types into one table", () => { | |
149 it("can simply merge types", async () => { | |
150 const vc = new ViewConfig(); | |
151 await vc.readFromGraph(` | |
152 @prefix ex: <http://example.com/> . | |
153 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . | |
154 @prefix : <http://example.com/> . | |
155 | |
156 <> a :View; :table [ :primaryType :T1; :joinType :T2 ] . | |
157 `); | |
158 vc.graph.forEach((q) => console.log("vc", q), null, null, null, null); | |
159 const layout = new Layout(vc); | |
160 const lr = layout.plan( | |
161 await n3Graph(` | |
162 @prefix : <http://example.com/> . | |
163 :g1 { | |
164 :a a :T1 ; :color :red . | |
165 :b a :T2 ; :size :big . | |
166 } | |
167 `) | |
168 ); | |
169 expect(lr.sections).toHaveLength(1); | |
170 const section0 = lr.sections[0] as AlignedTable; | |
171 expect(section0.columnHeaders).toEqual([ | |
172 { rdfTypes: [EX("T1")], pred: EX("color") }, | |
173 { rdfTypes: [EX("T2")], pred: EX("size") }, | |
174 ]); | |
175 expect(section0.rowHeaders).toEqual([EX("a"), EX("b")]); | |
176 expect(section0.rows).toEqual([ | |
133 [[EX("red")], []], | 177 [[EX("red")], []], |
134 [[EX("blue")], []], | 178 [[], [EX("big")]], |
135 [[], []], | 179 ]); |
136 [[], [EX("small")]], | |
137 ], | |
138 }); | |
139 expect(lr.sections[1]).toEqual({ | |
140 columnHeaders: [{ rdfType: EX("T2"), pred: EX("size") }], | |
141 rowHeaders: [EX("d"), EX("e")], | |
142 rows: [ | |
143 [[EX("big")]], // | |
144 [[EX("small")]], | |
145 ], | |
146 }); | 180 }); |
147 }); | 181 }); |
148 it.skip("makes a table out of ungrouped triples with the same type", async () => {}); | 182 it.skip("makes a table out of ungrouped triples with the same type", async () => {}); |
149 }); | 183 }); |