svg-table 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/d3types.ts +17 -0
- package/dist/d3types.d.ts +12 -0
- package/dist/d3types.d.ts.map +1 -0
- package/dist/d3types.js +3 -0
- package/dist/d3types.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/stylings.d.ts +206 -0
- package/dist/stylings.d.ts.map +1 -0
- package/dist/stylings.js +123 -0
- package/dist/stylings.js.map +1 -0
- package/dist/tableData.d.ts +168 -0
- package/dist/tableData.d.ts.map +1 -0
- package/dist/tableData.js +329 -0
- package/dist/tableData.js.map +1 -0
- package/dist/tableData.test.d.ts +2 -0
- package/dist/tableData.test.d.ts.map +1 -0
- package/dist/tableData.test.js +259 -0
- package/dist/tableData.test.js.map +1 -0
- package/dist/tableFormatter.d.ts +179 -0
- package/dist/tableFormatter.d.ts.map +1 -0
- package/dist/tableFormatter.js +298 -0
- package/dist/tableFormatter.js.map +1 -0
- package/dist/tableFormatter.test.d.ts +2 -0
- package/dist/tableFormatter.test.d.ts.map +1 -0
- package/dist/tableFormatter.test.js +101 -0
- package/dist/tableFormatter.test.js.map +1 -0
- package/dist/tableStyler.d.ts +310 -0
- package/dist/tableStyler.d.ts.map +1 -0
- package/dist/tableStyler.js +665 -0
- package/dist/tableStyler.js.map +1 -0
- package/dist/tableStyler.test.d.ts +2 -0
- package/dist/tableStyler.test.d.ts.map +1 -0
- package/dist/tableStyler.test.js +225 -0
- package/dist/tableStyler.test.js.map +1 -0
- package/dist/tableSvg.d.ts +41 -0
- package/dist/tableSvg.d.ts.map +1 -0
- package/dist/tableSvg.js +634 -0
- package/dist/tableSvg.js.map +1 -0
- package/dist/tableUtils.d.ts +14 -0
- package/dist/tableUtils.d.ts.map +1 -0
- package/dist/tableUtils.js +18 -0
- package/dist/tableUtils.js.map +1 -0
- package/eslint.config.js +23 -0
- package/index.ts +82 -0
- package/jest.config.js +5 -0
- package/package.json +44 -0
- package/stylings.ts +311 -0
- package/svg-table-0.0.1-snapshot.tgz +0 -0
- package/tableData.test.ts +290 -0
- package/tableData.ts +359 -0
- package/tableFormatter.test.ts +122 -0
- package/tableFormatter.ts +306 -0
- package/tableStyler.test.ts +268 -0
- package/tableStyler.ts +798 -0
- package/tableSvg.ts +820 -0
- package/tableUtils.ts +20 -0
- package/tsconfig.json +102 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TableData = exports.TableTagType = void 0;
|
|
4
|
+
var result_fn_1 = require("result-fn");
|
|
5
|
+
var DataFrame_1 = require("data-frame-ts/dist/DataFrame");
|
|
6
|
+
var tableFormatter_1 = require("./tableFormatter");
|
|
7
|
+
/**
|
|
8
|
+
* The types of tags the {@link TableData} supports
|
|
9
|
+
*/
|
|
10
|
+
var TableTagType;
|
|
11
|
+
(function (TableTagType) {
|
|
12
|
+
TableTagType["COLUMN_HEADER"] = "column-header";
|
|
13
|
+
TableTagType["ROW_HEADER"] = "row-header";
|
|
14
|
+
TableTagType["FOOTER"] = "footer";
|
|
15
|
+
})(TableTagType || (exports.TableTagType = TableTagType = {}));
|
|
16
|
+
/**
|
|
17
|
+
* Represents the table data, row and column headers, and footers
|
|
18
|
+
*/
|
|
19
|
+
var TableData = /** @class */ (function () {
|
|
20
|
+
/**
|
|
21
|
+
* The matrix of data, including row, column headers, and footers, if they exist
|
|
22
|
+
*/
|
|
23
|
+
function TableData(dataFrame) {
|
|
24
|
+
this.dataFrame = dataFrame;
|
|
25
|
+
}
|
|
26
|
+
TableData.fromDataFrame = function (dataFrame) {
|
|
27
|
+
return new TableData(dataFrame.copy());
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Adds a column-header where each element in the column-header is the name of the column.
|
|
31
|
+
* Note that the specified column {@link header} determines the number of data columns in the table. This
|
|
32
|
+
* means that you must specify a header for each data column. No need to account for a possible column
|
|
33
|
+
* containing row-headers. The builder will take care of any adjustments needed for that.
|
|
34
|
+
* @param header An array describing the columns in the table.
|
|
35
|
+
* @param formatting The formatter, and its priority, for the row that represents the column-header. Note that the column
|
|
36
|
+
* header should not account for a possible column containing row-headers. The builder will take care
|
|
37
|
+
* of any adjustments needed for that.
|
|
38
|
+
* @param rowHeaderProvider
|
|
39
|
+
* @return A {@link TableData} which represents the next step in the guided builder
|
|
40
|
+
*/
|
|
41
|
+
TableData.prototype.withColumnHeader = function (header, formatting, rowHeaderProvider) {
|
|
42
|
+
if (formatting === void 0) { formatting = (0, tableFormatter_1.defaultFormatting)(); }
|
|
43
|
+
if (rowHeaderProvider === void 0) { rowHeaderProvider = function () { return undefined; }; }
|
|
44
|
+
// just return a copy of the data table if the header is empty
|
|
45
|
+
if (header.length === 0) {
|
|
46
|
+
return (0, result_fn_1.successResult)(new TableData(this.dataFrame.copy()));
|
|
47
|
+
}
|
|
48
|
+
// when a row header has already been applied, then the table has grown by one column,
|
|
49
|
+
// and so we need to insert an empty cell at the beginning of the column header
|
|
50
|
+
var updatedHeader = header.slice();
|
|
51
|
+
if (this.dataFrame.columnTagsFor(0).some(function (tag) { return tag.value === TableTagType.ROW_HEADER; })) {
|
|
52
|
+
updatedHeader.unshift(rowHeaderProvider());
|
|
53
|
+
}
|
|
54
|
+
// when there is already a column-header, then replace it with the new one
|
|
55
|
+
if (this.dataFrame.rowTagsFor(0).some(function (tag) { return tag.value === TableTagType.COLUMN_HEADER; })) {
|
|
56
|
+
return this.dataFrame
|
|
57
|
+
.mapRow(0, function (_, rowIndex) { return header[rowIndex]; })
|
|
58
|
+
.map(function (df) { return new TableData(df); });
|
|
59
|
+
}
|
|
60
|
+
return this.dataFrame
|
|
61
|
+
.insertRowBefore(0, updatedHeader)
|
|
62
|
+
.flatMap(function (df) { return df.tagRow(0, "column-header", TableTagType.COLUMN_HEADER); })
|
|
63
|
+
.flatMap(function (df) { return df.tagRow(0, tableFormatter_1.TableFormatterType.COLUMN, formatting); })
|
|
64
|
+
.map(function (df) { return new TableData(df); });
|
|
65
|
+
};
|
|
66
|
+
TableData.prototype.withRowHeader = function (header, formatting, columnHeaderProvider, footerProvider) {
|
|
67
|
+
if (formatting === void 0) { formatting = (0, tableFormatter_1.defaultFormatting)(); }
|
|
68
|
+
if (columnHeaderProvider === void 0) { columnHeaderProvider = function () { return undefined; }; }
|
|
69
|
+
if (footerProvider === void 0) { footerProvider = function () { return undefined; }; }
|
|
70
|
+
// just return a copy of the data table if the header is empty
|
|
71
|
+
if (header.length === 0) {
|
|
72
|
+
return (0, result_fn_1.successResult)(TableData.fromDataFrame(this.dataFrame.copy()));
|
|
73
|
+
}
|
|
74
|
+
// when there is a column-header and/or footer, we adjust the (row) header by adding
|
|
75
|
+
// empty elements so that the length of the (row) header matches the number of rows,
|
|
76
|
+
// including the column header and the footer
|
|
77
|
+
var updatedHeader = header.slice();
|
|
78
|
+
// recall that a column-header is a row, specifically the first row
|
|
79
|
+
if (this.dataFrame.rowTagsFor(0).some(function (tag) { return tag.value === TableTagType.COLUMN_HEADER; })) {
|
|
80
|
+
updatedHeader.unshift(columnHeaderProvider());
|
|
81
|
+
}
|
|
82
|
+
if (this.dataFrame.rowTagsFor(this.dataFrame.rowCount() - 1).some(function (tag) { return tag.value === TableTagType.FOOTER; })) {
|
|
83
|
+
updatedHeader.push(footerProvider());
|
|
84
|
+
}
|
|
85
|
+
// when there is already a row-header, then replace it with the new one
|
|
86
|
+
if (this.dataFrame.columnTagsFor(0).some(function (tag) { return tag.value === TableTagType.ROW_HEADER; })) {
|
|
87
|
+
return this.dataFrame
|
|
88
|
+
.mapColumn(0, function (_, rowIndex) { return header[rowIndex]; })
|
|
89
|
+
.map(function (df) { return TableData.fromDataFrame(df); });
|
|
90
|
+
}
|
|
91
|
+
return this.dataFrame
|
|
92
|
+
.insertColumnBefore(0, updatedHeader)
|
|
93
|
+
.flatMap(function (df) { return df.tagColumn(0, "row-header", TableTagType.ROW_HEADER); })
|
|
94
|
+
.flatMap(function (df) { return df.tagColumn(0, tableFormatter_1.TableFormatterType.COLUMN, formatting); })
|
|
95
|
+
.map(function (df) { return TableData.fromDataFrame(df); });
|
|
96
|
+
};
|
|
97
|
+
TableData.prototype.withFooter = function (footer, formatting, rowHeaderProvider) {
|
|
98
|
+
if (formatting === void 0) { formatting = (0, tableFormatter_1.defaultFormatting)(); }
|
|
99
|
+
if (rowHeaderProvider === void 0) { rowHeaderProvider = function () { return undefined; }; }
|
|
100
|
+
// just return a copy of the data table if the footer is empty
|
|
101
|
+
if (footer.length === 0) {
|
|
102
|
+
return (0, result_fn_1.successResult)(TableData.fromDataFrame(this.dataFrame.copy()));
|
|
103
|
+
}
|
|
104
|
+
// when a row header has already been applied, then the table has grown by one column,
|
|
105
|
+
// and so we need to insert an empty cell at the beginning of the footer
|
|
106
|
+
var updatedFooter = footer.slice();
|
|
107
|
+
if (this.dataFrame.columnTagsFor(0).some(function (tag) { return tag.value === TableTagType.ROW_HEADER; })) {
|
|
108
|
+
updatedFooter.unshift(rowHeaderProvider());
|
|
109
|
+
}
|
|
110
|
+
// when there is already a footer, then replace it with the new one
|
|
111
|
+
if (this.dataFrame.rowTagsFor(0).some(function (tag) { return tag.value === TableTagType.FOOTER; })) {
|
|
112
|
+
return this.dataFrame
|
|
113
|
+
.mapRow(this.dataFrame.rowCount() - 1, function (_, rowIndex) { return footer[rowIndex]; })
|
|
114
|
+
.map(function (df) { return TableData.fromDataFrame(df); });
|
|
115
|
+
}
|
|
116
|
+
return this.dataFrame
|
|
117
|
+
.pushRow(updatedFooter)
|
|
118
|
+
.flatMap(function (df) { return df.tagRow(df.rowCount() - 1, "footer", TableTagType.FOOTER); })
|
|
119
|
+
.flatMap(function (df) { return df.tagRow(df.rowCount() - 1, tableFormatter_1.TableFormatterType.ROW, formatting); })
|
|
120
|
+
.map(function (df) { return TableData.fromDataFrame(df); });
|
|
121
|
+
};
|
|
122
|
+
TableData.hasColumnHeader = function (dataFrame) {
|
|
123
|
+
return dataFrame.rowTagsFor(0).some(function (tag) { return tag.value === TableTagType.COLUMN_HEADER; });
|
|
124
|
+
};
|
|
125
|
+
TableData.hasRowHeader = function (dataFrame) {
|
|
126
|
+
return dataFrame.columnTagsFor(0).some(function (tag) { return tag.value === TableTagType.ROW_HEADER; });
|
|
127
|
+
};
|
|
128
|
+
TableData.hasFooter = function (dataFrame) {
|
|
129
|
+
return dataFrame.rowTagsFor(dataFrame.rowCount() - 1).some(function (tag) { return tag.value === TableTagType.FOOTER; });
|
|
130
|
+
};
|
|
131
|
+
TableData.dataRowCount = function (dataFrame) {
|
|
132
|
+
return dataFrame.rowCount() - (TableData.hasColumnHeader(dataFrame) ? 1 : 0) - (TableData.hasFooter(dataFrame) ? 1 : 0);
|
|
133
|
+
};
|
|
134
|
+
TableData.dataColumnCount = function (dataFrame) {
|
|
135
|
+
return dataFrame.columnCount() - (TableData.hasRowHeader(dataFrame) ? 1 : 0);
|
|
136
|
+
};
|
|
137
|
+
TableData.tableRowCount = function (dataFrame) {
|
|
138
|
+
return dataFrame.rowCount();
|
|
139
|
+
};
|
|
140
|
+
TableData.tableColumnCount = function (dataFrame) {
|
|
141
|
+
return dataFrame.columnCount();
|
|
142
|
+
};
|
|
143
|
+
TableData.prototype.hasColumnHeader = function () {
|
|
144
|
+
// return this.dataFrame.rowTagsFor(0).some(tag => tag.value === TableTagType.COLUMN_HEADER)
|
|
145
|
+
return TableData.hasColumnHeader(this.dataFrame);
|
|
146
|
+
};
|
|
147
|
+
TableData.prototype.hasRowHeader = function () {
|
|
148
|
+
// return this.dataFrame.columnTagsFor(0).some(tag => tag.value === TableTagType.ROW_HEADER)
|
|
149
|
+
return TableData.hasRowHeader(this.dataFrame);
|
|
150
|
+
};
|
|
151
|
+
TableData.prototype.hasFooter = function () {
|
|
152
|
+
// return this.dataFrame.rowTagsFor(this.dataFrame.rowCount() - 1).some(tag => tag.value === TableTagType.FOOTER)
|
|
153
|
+
return TableData.hasFooter(this.dataFrame);
|
|
154
|
+
};
|
|
155
|
+
TableData.prototype.dataRowCount = function () {
|
|
156
|
+
// return this.dataFrame.rowCount() - (this.hasColumnHeader() ? 1 : 0) - (this.hasFooter() ? 1 : 0)
|
|
157
|
+
return TableData.dataRowCount(this.dataFrame);
|
|
158
|
+
};
|
|
159
|
+
TableData.prototype.dataColumnCount = function () {
|
|
160
|
+
// return this.dataFrame.columnCount() - (this.hasRowHeader() ? 1 : 0)
|
|
161
|
+
return TableData.dataColumnCount(this.dataFrame);
|
|
162
|
+
};
|
|
163
|
+
TableData.prototype.tableRowCount = function () {
|
|
164
|
+
return this.dataFrame.rowCount();
|
|
165
|
+
};
|
|
166
|
+
TableData.prototype.tableColumnCount = function () {
|
|
167
|
+
return this.dataFrame.columnCount();
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* @param [includeRowHeader=false] When `true` includes an extra empty column element when the table
|
|
171
|
+
* has a row-header. When `false` returns only the column-header elements
|
|
172
|
+
* @return A {@link Result} holding the column header if it exists; or a failure if no column-header exists
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* const columnHeader = ['A', 'B', 'C', 'D', 'E']
|
|
176
|
+
* const rowHeader = ['one', 'two', 'three', 'four']
|
|
177
|
+
* const footer = ['a10', 'b10', 'c10', 'd10', 'e10']
|
|
178
|
+
* const data = DataFrame.from([
|
|
179
|
+
* ['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
180
|
+
* ['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
181
|
+
* ['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
182
|
+
* ['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
183
|
+
* ]).getOrThrow()
|
|
184
|
+
*
|
|
185
|
+
* // create a data-table with a column-header, row-header, footer, and data
|
|
186
|
+
* const tableData = createTableData<string>(data)
|
|
187
|
+
* .withColumnHeader(columnHeader)
|
|
188
|
+
* .flatMap(table => table.withRowHeader(rowHeader))
|
|
189
|
+
* .flatMap(table => table.withFooter(footer))
|
|
190
|
+
* .getOrThrow()
|
|
191
|
+
*
|
|
192
|
+
* // the column-header retrieved from the table-data should equal the column-header originally set
|
|
193
|
+
* expect(tableData.columnHeader().getOrThrow().equals(columnHeader)).toBeTruthy()
|
|
194
|
+
* ``` */
|
|
195
|
+
TableData.prototype.columnHeader = function (includeRowHeader) {
|
|
196
|
+
if (includeRowHeader === void 0) { includeRowHeader = false; }
|
|
197
|
+
if (this.hasColumnHeader()) {
|
|
198
|
+
var startColumn_1 = this.hasRowHeader() && !includeRowHeader ? 1 : 0;
|
|
199
|
+
return this.dataFrame
|
|
200
|
+
.rowSlice(0)
|
|
201
|
+
.map(function (row) { return row.slice(startColumn_1); })
|
|
202
|
+
.mapFailure(function (err) { return "(TableData::columnHeader) Failed to retrieve column-header.\n" + err; });
|
|
203
|
+
}
|
|
204
|
+
return (0, result_fn_1.failureResult)("(TableData::columnHeader) Failed to retrieve the column-header because no column header exists.");
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* @param [includeColumnHeader=false] When `true` returns an extra empty row element if the table data
|
|
208
|
+
* has a column header. When `false` does not include the empty extra row element.
|
|
209
|
+
* @param [includeFooter=false] When `true` returns an extra empty row element if the table data
|
|
210
|
+
* has a footer. When `false` does not include the empty extra row element.
|
|
211
|
+
* @return A {@link Result} holding the row-header if it exists; or a failure if no row-header exists
|
|
212
|
+
* @example
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const columnHeader = ['A', 'B', 'C', 'D', 'E']
|
|
215
|
+
* const rowHeader = ['one', 'two', 'three', 'four']
|
|
216
|
+
* const footer = ['a10', 'b10', 'c10', 'd10', 'e10']
|
|
217
|
+
* const data = DataFrame.from([
|
|
218
|
+
* ['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
219
|
+
* ['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
220
|
+
* ['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
221
|
+
* ['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
222
|
+
* ]).getOrThrow()
|
|
223
|
+
*
|
|
224
|
+
* // create a data-table with a column-header, row-header, footer, and data
|
|
225
|
+
* const tableData = createTableData<string>(data)
|
|
226
|
+
* .withColumnHeader(columnHeader)
|
|
227
|
+
* .flatMap(table => table.withRowHeader(rowHeader))
|
|
228
|
+
* .flatMap(table => table.withFooter(footer))
|
|
229
|
+
* .getOrThrow()
|
|
230
|
+
*
|
|
231
|
+
* // the row-header retrieved from the table-data should equal the row-header originally set
|
|
232
|
+
* expect(tableData.rowHeader().getOrThrow().equals(rowHeader)).toBeTruthy()
|
|
233
|
+
* ``` */
|
|
234
|
+
TableData.prototype.rowHeader = function (includeColumnHeader, includeFooter) {
|
|
235
|
+
if (includeColumnHeader === void 0) { includeColumnHeader = false; }
|
|
236
|
+
if (includeFooter === void 0) { includeFooter = false; }
|
|
237
|
+
if (this.hasRowHeader()) {
|
|
238
|
+
var startRow_1 = this.hasColumnHeader() && !includeColumnHeader ? 1 : 0;
|
|
239
|
+
var endRow_1 = this.hasFooter() && !includeFooter ? this.dataFrame.rowCount() - 1 : this.dataFrame.rowCount();
|
|
240
|
+
return this.dataFrame
|
|
241
|
+
.columnSlice(0)
|
|
242
|
+
.map(function (row) { return row.slice(startRow_1, endRow_1); })
|
|
243
|
+
.mapFailure(function (err) { return "(TableData::rowHeader) Failed to retrieve row-header.\n" + err; });
|
|
244
|
+
}
|
|
245
|
+
return (0, result_fn_1.failureResult)("(TableData::rowHeader) Failed to retrieve the row-header because no row header exists.");
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* @param [includeRowHeader=false] When `true` includes an extra empty column element when the table
|
|
249
|
+
* has a row-header. When `false` returns only the column-header elements
|
|
250
|
+
* @return A {@link Result} holding the footer, if exists; or a failure if no footer exists
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* const columnHeader = ['A', 'B', 'C', 'D', 'E']
|
|
254
|
+
* const rowHeader = ['one', 'two', 'three', 'four']
|
|
255
|
+
* const footer = ['a10', 'b10', 'c10', 'd10', 'e10']
|
|
256
|
+
* const data = DataFrame.from([
|
|
257
|
+
* ['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
258
|
+
* ['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
259
|
+
* ['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
260
|
+
* ['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
261
|
+
* ]).getOrThrow()
|
|
262
|
+
*
|
|
263
|
+
* // create a data-table with a column-header, row-header, footer, and data
|
|
264
|
+
* const tableData = createTableData<string>(data)
|
|
265
|
+
* .withColumnHeader(columnHeader)
|
|
266
|
+
* .flatMap(table => table.withRowHeader(rowHeader))
|
|
267
|
+
* .flatMap(table => table.withFooter(footer))
|
|
268
|
+
* .getOrThrow()
|
|
269
|
+
*
|
|
270
|
+
* // the footer retrieved from the table-data should equal the footer originally set
|
|
271
|
+
* expect(tableData.footer().getOrThrow().equals(footer)).toBeTruthy()
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
TableData.prototype.footer = function (includeRowHeader) {
|
|
275
|
+
if (includeRowHeader === void 0) { includeRowHeader = false; }
|
|
276
|
+
if (this.hasFooter()) {
|
|
277
|
+
var startColumn_2 = this.hasRowHeader() && !includeRowHeader ? 1 : 0;
|
|
278
|
+
return this.dataFrame
|
|
279
|
+
.rowSlice(this.dataFrame.rowCount() - 1)
|
|
280
|
+
.map(function (row) { return row.slice(startColumn_2); })
|
|
281
|
+
.mapFailure(function (err) { return "(TableData::footer) Failed to retrieve footer.\n" + err; });
|
|
282
|
+
}
|
|
283
|
+
return (0, result_fn_1.failureResult)("(TableData::footer) Failed to retrieve the footer because no footer exists.");
|
|
284
|
+
};
|
|
285
|
+
/**
|
|
286
|
+
* Retrieves the "data" from the data-table. This excludes any column headers, row-headers, and footers.
|
|
287
|
+
* @return A {@link Result} holding a {@link DataFrame} with the "data" from the data-table. This excludes any
|
|
288
|
+
* column headers, row-headers, and footers.
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* const columnHeader = ['A', 'B', 'C', 'D', 'E']
|
|
292
|
+
* const rowHeader = ['one', 'two', 'three', 'four']
|
|
293
|
+
* const footer = ['a10', 'b10', 'c10', 'd10', 'e10']
|
|
294
|
+
* const data = DataFrame.from([
|
|
295
|
+
* ['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
296
|
+
* ['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
297
|
+
* ['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
298
|
+
* ['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
299
|
+
* ]).getOrThrow()
|
|
300
|
+
*
|
|
301
|
+
* // create a data-table with a column-header, row-header, footer, and data
|
|
302
|
+
* const tableData = createTableData<string>(data)
|
|
303
|
+
* .withColumnHeader(columnHeader)
|
|
304
|
+
* .flatMap(table => table.withRowHeader(rowHeader))
|
|
305
|
+
* .flatMap(table => table.withFooter(footer))
|
|
306
|
+
* .getOrThrow()
|
|
307
|
+
*
|
|
308
|
+
* // the data retrieved from the table-data should equal the data originally set
|
|
309
|
+
* expect(tableData.data().getOrThrow().equals(data)).toBeTruthy()
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
TableData.prototype.data = function () {
|
|
313
|
+
var startRow = this.hasColumnHeader() ? 1 : 0;
|
|
314
|
+
var endRow = this.hasFooter() ? this.dataFrame.rowCount() - 2 : this.dataFrame.rowCount() - 1;
|
|
315
|
+
var startColumn = this.hasRowHeader() ? 1 : 0;
|
|
316
|
+
return this.dataFrame
|
|
317
|
+
.subFrame((0, DataFrame_1.indexFrom)(startRow, startColumn), (0, DataFrame_1.indexFrom)(endRow, this.dataFrame.columnCount() - 1))
|
|
318
|
+
.mapFailure(function (err) { return "(TableData::data) Failed to retrieve data.\n" + err; });
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* @return a copy of the {@link DataFrame} that has been prepared by this class.
|
|
322
|
+
*/
|
|
323
|
+
TableData.prototype.unwrapDataFrame = function () {
|
|
324
|
+
return this.dataFrame.copy();
|
|
325
|
+
};
|
|
326
|
+
return TableData;
|
|
327
|
+
}());
|
|
328
|
+
exports.TableData = TableData;
|
|
329
|
+
//# sourceMappingURL=tableData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tableData.js","sourceRoot":"","sources":["../tableData.ts"],"names":[],"mappings":";;;AACA,uCAAoE;AACpE,0DAAuD;AACvD,mDAAwF;AAExF;;GAEG;AACH,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,+CAA+B,CAAA;IAC/B,yCAAyB,CAAA;IACzB,iCAAiB,CAAA;AACrB,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB;AAED;;GAEG;AACH;IACI;;OAEG;IACH,mBAAqC,SAAuB;QAAvB,cAAS,GAAT,SAAS,CAAc;IAC5D,CAAC;IAEM,uBAAa,GAApB,UAAwB,SAAuB;QAC3C,OAAO,IAAI,SAAS,CAAI,SAAS,CAAC,IAAI,EAAE,CAAC,CAAA;IAC7C,CAAC;IAED;;;;;;;;;;;OAWG;IACI,oCAAgB,GAAvB,UACI,MAAgB,EAChB,UAAkD,EAClD,iBAAwD;QADxD,2BAAA,EAAA,iBAA4B,kCAAiB,GAAK;QAClD,kCAAA,EAAA,kCAA+C,OAAA,SAAS,EAAT,CAAS;QAExD,8DAA8D;QAC9D,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,IAAA,yBAAa,EAAC,IAAI,SAAS,CAAI,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QACjE,CAAC;QAED,sFAAsF;QACtF,+EAA+E;QAC/E,IAAM,aAAa,GAAG,MAAM,CAAC,KAAK,EAAE,CAAA;QACpC,IAAI,IAAI,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|
|
1
|
+
{"version":3,"file":"tableData.test.d.ts","sourceRoot":"","sources":["../tableData.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var data_frame_ts_1 = require("data-frame-ts");
|
|
4
|
+
var tableData_1 = require("./tableData");
|
|
5
|
+
describe('creating and manipulating table data', function () {
|
|
6
|
+
test('should be able to create a simple table from row data without a footer', function () {
|
|
7
|
+
var columnHeader = ['A', 'B', 'C', 'D', 'E'];
|
|
8
|
+
var rowHeader = ['one', 'two', 'three', 'four'];
|
|
9
|
+
var data = data_frame_ts_1.DataFrame.from([
|
|
10
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
11
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
12
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
13
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
14
|
+
]).getOrThrow();
|
|
15
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
16
|
+
.withColumnHeader(columnHeader)
|
|
17
|
+
.flatMap(function (table) { return table.withRowHeader(rowHeader); })
|
|
18
|
+
.getOrThrow();
|
|
19
|
+
expect(tableData.hasColumnHeader()).toBeTruthy();
|
|
20
|
+
expect(tableData.tableRowCount()).toBe(4 + 1);
|
|
21
|
+
expect(tableData.dataRowCount()).toBe(4);
|
|
22
|
+
expect(tableData.hasFooter()).toBeFalsy();
|
|
23
|
+
expect(tableData.tableColumnCount()).toEqual(5 + 1);
|
|
24
|
+
expect(tableData.dataColumnCount()).toEqual(5);
|
|
25
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(['A', 'B', 'C', 'D', 'E']);
|
|
26
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(['one', 'two', 'three', 'four']);
|
|
27
|
+
expect(tableData.footer().getOrElse([])).toEqual([]);
|
|
28
|
+
expect(tableData.data().getOrThrow().rowSlices()).toEqual(data.rowSlices());
|
|
29
|
+
});
|
|
30
|
+
test('should be able to create a simple table from row data with a footer', function () {
|
|
31
|
+
var columnHeader = ['A', 'B', 'C', 'D', 'E'];
|
|
32
|
+
var rowHeader = ['one', 'two', 'three', 'four'];
|
|
33
|
+
var footer = ['a10', 'b10', 'c10', 'd10', 'e10'];
|
|
34
|
+
var data = data_frame_ts_1.DataFrame.from([
|
|
35
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
36
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
37
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
38
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
39
|
+
]).getOrThrow();
|
|
40
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
41
|
+
.withColumnHeader(columnHeader)
|
|
42
|
+
.flatMap(function (table) { return table.withFooter(footer); })
|
|
43
|
+
.flatMap(function (table) { return table.withRowHeader(rowHeader); })
|
|
44
|
+
.getOrThrow();
|
|
45
|
+
expect(tableData.hasColumnHeader()).toBeTruthy();
|
|
46
|
+
expect(tableData.tableRowCount()).toBe(/*data*/ 4 + /*header*/ 1 + /*footer*/ 1);
|
|
47
|
+
expect(tableData.hasFooter()).toBeTruthy();
|
|
48
|
+
expect(tableData.tableColumnCount()).toEqual(/*data*/ 5 + /*header*/ 1);
|
|
49
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
|
|
50
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader);
|
|
51
|
+
expect(tableData.footer().getOrThrow()).toEqual(footer);
|
|
52
|
+
expect(tableData.data().getOrThrow().rowSlices()).toEqual(data.rowSlices());
|
|
53
|
+
});
|
|
54
|
+
test('should be able to create a simple table from row data with a footer 2', function () {
|
|
55
|
+
var columnHeader = ['A', 'B', 'C', 'D', 'E'];
|
|
56
|
+
var rowHeader = ['one', 'two', 'three', 'four'];
|
|
57
|
+
var footer = ['a10', 'b10', 'c10', 'd10', 'e10'];
|
|
58
|
+
var data = data_frame_ts_1.DataFrame.from([
|
|
59
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
60
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
61
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
62
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
63
|
+
]).getOrThrow();
|
|
64
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
65
|
+
.withColumnHeader(columnHeader)
|
|
66
|
+
.flatMap(function (table) { return table.withRowHeader(rowHeader); })
|
|
67
|
+
.flatMap(function (table) { return table.withFooter(footer); })
|
|
68
|
+
.getOrThrow();
|
|
69
|
+
expect(tableData.hasColumnHeader()).toBeTruthy();
|
|
70
|
+
expect(tableData.tableRowCount()).toBe(/*data*/ 4 + /*header*/ 1 + /*footer*/ 1);
|
|
71
|
+
expect(tableData.hasFooter()).toBeTruthy();
|
|
72
|
+
expect(tableData.tableColumnCount()).toEqual(/*data*/ 5 + /*header*/ 1);
|
|
73
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
|
|
74
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader);
|
|
75
|
+
expect(tableData.footer().getOrThrow()).toEqual(footer);
|
|
76
|
+
expect(tableData.data().getOrThrow().rowSlices()).toEqual(data.rowSlices());
|
|
77
|
+
});
|
|
78
|
+
test('should be able to create a simple table from row data with a footer 3', function () {
|
|
79
|
+
var columnHeader = ['A', 'B', 'C', 'D', 'E'];
|
|
80
|
+
var rowHeader = ['one', 'two', 'three', 'four'];
|
|
81
|
+
var footer = ['a10', 'b10', 'c10', 'd10', 'e10'];
|
|
82
|
+
var data = data_frame_ts_1.DataFrame.from([
|
|
83
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
84
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
85
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
86
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
87
|
+
]).getOrThrow();
|
|
88
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
89
|
+
.withFooter(footer)
|
|
90
|
+
.flatMap(function (table) { return table.withColumnHeader(columnHeader); })
|
|
91
|
+
.flatMap(function (table) { return table.withRowHeader(rowHeader); })
|
|
92
|
+
.getOrThrow();
|
|
93
|
+
expect(tableData.hasColumnHeader()).toBeTruthy();
|
|
94
|
+
expect(tableData.tableRowCount()).toBe(/*data*/ 4 + /*header*/ 1 + /*footer*/ 1);
|
|
95
|
+
expect(tableData.hasFooter()).toBeTruthy();
|
|
96
|
+
expect(tableData.tableColumnCount()).toEqual(/*data*/ 5 + /*header*/ 1);
|
|
97
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
|
|
98
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader);
|
|
99
|
+
expect(tableData.footer().getOrThrow()).toEqual(footer);
|
|
100
|
+
expect(tableData.data().getOrThrow().rowSlices()).toEqual(data.rowSlices());
|
|
101
|
+
});
|
|
102
|
+
test('should be able to create a simple table from row data with a footer with no header', function () {
|
|
103
|
+
var columnHeader = ['A', 'B', 'C', 'D', 'E'];
|
|
104
|
+
var rowHeader = ['one', 'two', 'three', 'four'];
|
|
105
|
+
var footer = ['a10', 'b10', 'c10', 'd10', 'e10'];
|
|
106
|
+
var data = data_frame_ts_1.DataFrame.from([
|
|
107
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
108
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
109
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
110
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
111
|
+
]).getOrThrow();
|
|
112
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
113
|
+
.withColumnHeader(columnHeader)
|
|
114
|
+
.flatMap(function (table) { return table.withFooter(footer); })
|
|
115
|
+
.flatMap(function (table) { return table.withRowHeader(rowHeader); })
|
|
116
|
+
.getOrThrow();
|
|
117
|
+
expect(tableData.hasColumnHeader()).toBeTruthy();
|
|
118
|
+
expect(tableData.tableRowCount()).toBe(/*data*/ 4 + /*header*/ 1 + /*footer*/ 1);
|
|
119
|
+
expect(tableData.hasFooter()).toBeTruthy();
|
|
120
|
+
expect(tableData.tableColumnCount()).toEqual(/*data*/ 5 + /*header*/ 1);
|
|
121
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
|
|
122
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader);
|
|
123
|
+
expect(tableData.footer().getOrThrow()).toEqual(footer);
|
|
124
|
+
expect(tableData.data().getOrThrow().equals(data)).toBeTruthy();
|
|
125
|
+
});
|
|
126
|
+
test('should be able to create a simple table from column data without a footer', function () {
|
|
127
|
+
var columnHeader = ['A', 'B', 'C', 'D'];
|
|
128
|
+
var rowHeader = ['one', 'two', 'three', 'four', 'five'];
|
|
129
|
+
var data = data_frame_ts_1.DataFrame.fromColumnData([
|
|
130
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
131
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
132
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
133
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
134
|
+
]).getOrThrow();
|
|
135
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
136
|
+
.withColumnHeader(columnHeader)
|
|
137
|
+
.flatMap(function (table) { return table.withRowHeader(rowHeader); })
|
|
138
|
+
.getOrThrow();
|
|
139
|
+
expect(tableData.hasRowHeader()).toBeTruthy();
|
|
140
|
+
expect(tableData.tableRowCount()).toEqual(5 + 1); // the thing is transposed
|
|
141
|
+
expect(tableData.hasFooter()).toBeFalsy();
|
|
142
|
+
expect(tableData.tableColumnCount()).toEqual(4 + 1);
|
|
143
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
|
|
144
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader);
|
|
145
|
+
expect(tableData.data().getOrThrow().equals(data)).toBeTruthy();
|
|
146
|
+
});
|
|
147
|
+
test('should be able to create a simple table from column data without a footer 2', function () {
|
|
148
|
+
var columnHeader = ['A', 'B', 'C', 'D'];
|
|
149
|
+
var rowHeader = ['one', 'two', 'three', 'four', 'five'];
|
|
150
|
+
var data = data_frame_ts_1.DataFrame.fromColumnData([
|
|
151
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
152
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
153
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
154
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
155
|
+
]).getOrThrow();
|
|
156
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
157
|
+
.withRowHeader(rowHeader)
|
|
158
|
+
.flatMap(function (table) { return table.withColumnHeader(columnHeader); })
|
|
159
|
+
.getOrThrow();
|
|
160
|
+
expect(tableData.hasRowHeader()).toBeTruthy();
|
|
161
|
+
expect(tableData.tableRowCount()).toEqual(5 + 1); // the thing is transposed
|
|
162
|
+
expect(tableData.hasFooter()).toBeFalsy();
|
|
163
|
+
expect(tableData.tableColumnCount()).toEqual(4 + 1);
|
|
164
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
|
|
165
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader);
|
|
166
|
+
expect(tableData.data().getOrThrow().equals(data)).toBeTruthy();
|
|
167
|
+
});
|
|
168
|
+
test('should be able to create a table from column data without a footer', function () {
|
|
169
|
+
var header = ['A', 'B', 'C', 'D'];
|
|
170
|
+
var data = data_frame_ts_1.DataFrame.fromColumnData([
|
|
171
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
172
|
+
[10, 20, 30, 40, 50],
|
|
173
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
174
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
175
|
+
]).getOrThrow();
|
|
176
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
177
|
+
.withColumnHeader(header)
|
|
178
|
+
.getOrThrow();
|
|
179
|
+
expect(tableData.tableRowCount()).toBe(6);
|
|
180
|
+
expect(tableData.hasFooter()).toBeFalsy();
|
|
181
|
+
expect(tableData.tableColumnCount()).toEqual(4);
|
|
182
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(header);
|
|
183
|
+
expect(tableData.data().getOrThrow().equals(data)).toBeTruthy();
|
|
184
|
+
});
|
|
185
|
+
test('should throw error when the data dimensions are inconsistent with the header dimensions', function () {
|
|
186
|
+
var result = data_frame_ts_1.DataFrame.from([['a1'], ['a2']])
|
|
187
|
+
.map(function (df) { return tableData_1.TableData.fromDataFrame(df); })
|
|
188
|
+
.flatMap(function (table) { return table.withColumnHeader(['a', 'b']); });
|
|
189
|
+
expect(result.failed).toBeTruthy();
|
|
190
|
+
expect(result.error).toEqual("(DataFrame::insertRowBefore) The row must have the same number of elements as the data has columns. num_rows: 2; num_columns: 2");
|
|
191
|
+
result = data_frame_ts_1.DataFrame.fromColumnData([['a1'], ['a2'], ['a3']])
|
|
192
|
+
.map(function (df) { return tableData_1.TableData.fromDataFrame(df); })
|
|
193
|
+
.flatMap(function (table) { return table.withColumnHeader(['a', 'b']); });
|
|
194
|
+
expect(result.failed).toBeTruthy();
|
|
195
|
+
expect(result.error).toEqual("(DataFrame::insertRowBefore) The row must have the same number of elements as the data has columns. num_rows: 1; num_columns: 2");
|
|
196
|
+
});
|
|
197
|
+
test('should throw error when the rows do not all have the same number of columns', function () {
|
|
198
|
+
var result = data_frame_ts_1.DataFrame.from([['a1', 'a2'], ['b2']])
|
|
199
|
+
.map(function (df) { return tableData_1.TableData.fromDataFrame(df); })
|
|
200
|
+
.flatMap(function (table) { return table.withColumnHeader(['a', 'b']); });
|
|
201
|
+
expect(result.failed).toBeTruthy();
|
|
202
|
+
expect(result.error).toEqual("(DataFrame.validateDimensions) All rows must have the same number of columns; min_num_columns: 1, maximum_columns: 2");
|
|
203
|
+
result = data_frame_ts_1.DataFrame.fromColumnData([['a1'], ['a2', 'b2']])
|
|
204
|
+
.map(function (df) { return tableData_1.TableData.fromDataFrame(df); })
|
|
205
|
+
.flatMap(function (table) { return table.withColumnHeader(['a', 'b']); });
|
|
206
|
+
expect(result.failed).toBeTruthy();
|
|
207
|
+
expect(result.error).toEqual("(DataFrame.validateDimensions) All columns must have the same number of rows; min_num_rows: 1, maximum_rows: 2");
|
|
208
|
+
});
|
|
209
|
+
test('should be able to create a table of numbers when no formatter is specified', function () {
|
|
210
|
+
var tableData = tableData_1.TableData.fromDataFrame(data_frame_ts_1.DataFrame.from([[11, 12, 13], [21, 22, 23]]).getOrThrow());
|
|
211
|
+
expect(tableData.tableRowCount()).toEqual(2);
|
|
212
|
+
expect(tableData.data().flatMap(function (df) { return df.rowSlice(0).map(function (row) { return row.length; }); }).getOrThrow()).toEqual(3);
|
|
213
|
+
expect(tableData.data().flatMap(function (df) { return df.rowSlice(1).map(function (row) { return row.length; }); }).getOrThrow()).toEqual(3);
|
|
214
|
+
});
|
|
215
|
+
describe('retrieving information about the table', function () {
|
|
216
|
+
var columnHeader = ['A', 'B', 'C', 'D', 'E'];
|
|
217
|
+
var rowHeader = ['one', 'two', 'three', 'four'];
|
|
218
|
+
var footer = ['a10', 'b10', 'c10', 'd10', 'e10'];
|
|
219
|
+
var data = data_frame_ts_1.DataFrame.from([
|
|
220
|
+
['a1', 'b1', 'c1', 'd1', 'e1'],
|
|
221
|
+
['a2', 'b2', 'c2', 'd2', 'e2'],
|
|
222
|
+
['a3', 'b3', 'c3', 'd3', 'e3'],
|
|
223
|
+
['a4', 'b4', 'c4', 'd4', 'e4'],
|
|
224
|
+
]).getOrThrow();
|
|
225
|
+
var tableData = tableData_1.TableData.fromDataFrame(data)
|
|
226
|
+
.withColumnHeader(columnHeader)
|
|
227
|
+
.flatMap(function (table) { return table.withRowHeader(rowHeader); })
|
|
228
|
+
.flatMap(function (table) { return table.withFooter(footer); })
|
|
229
|
+
.getOrThrow();
|
|
230
|
+
test("should be able to get the column header", function () {
|
|
231
|
+
expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
|
|
232
|
+
});
|
|
233
|
+
test("should be able to get the row header", function () {
|
|
234
|
+
expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader);
|
|
235
|
+
});
|
|
236
|
+
test("should be able to get the footer", function () {
|
|
237
|
+
expect(tableData.footer().getOrThrow()).toEqual(footer);
|
|
238
|
+
});
|
|
239
|
+
test("should be able to get the data", function () {
|
|
240
|
+
expect(tableData.data().getOrThrow().equals(data)).toBeTruthy();
|
|
241
|
+
});
|
|
242
|
+
test("should be able to get the table row count", function () {
|
|
243
|
+
expect(tableData.tableRowCount()).toEqual(4 + 1 + 1); // data + column_header + footer
|
|
244
|
+
});
|
|
245
|
+
test("should be able to get the table column count", function () {
|
|
246
|
+
expect(tableData.tableColumnCount()).toEqual(5 + 1); // data + row_header
|
|
247
|
+
});
|
|
248
|
+
test("should be able to determine whether the table has a column header", function () {
|
|
249
|
+
expect(tableData.hasColumnHeader()).toBeTruthy();
|
|
250
|
+
});
|
|
251
|
+
test("should be able to determine whether the table has a row header", function () {
|
|
252
|
+
expect(tableData.hasRowHeader()).toBeTruthy();
|
|
253
|
+
});
|
|
254
|
+
test("should be able to determine whether the table has a footer", function () {
|
|
255
|
+
expect(tableData.hasFooter()).toBeTruthy();
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
//# sourceMappingURL=tableData.test.js.map
|