svg-table 0.1.2 → 0.2.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/CHANGES.md +8 -0
- package/TableStyler.ts +68 -49
- package/dist/TableData.js +94 -106
- package/dist/TableData.js.map +1 -1
- package/dist/TableFormatter.js +54 -81
- package/dist/TableFormatter.js.map +1 -1
- package/dist/TableStyler.d.ts +24 -24
- package/dist/TableStyler.d.ts.map +1 -1
- package/dist/TableStyler.js +225 -270
- package/dist/TableStyler.js.map +1 -1
- package/dist/stylings.d.ts +23 -14
- package/dist/stylings.d.ts.map +1 -1
- package/dist/stylings.js +31 -38
- package/dist/stylings.js.map +1 -1
- package/dist/tableData.test.js +90 -90
- package/dist/tableData.test.js.map +1 -1
- package/dist/tableFormatter.test.js +57 -53
- package/dist/tableFormatter.test.js.map +1 -1
- package/dist/tableStyler.test.js +141 -299
- package/dist/tableStyler.test.js.map +1 -1
- package/dist/tableSvg.js +120 -158
- package/dist/tableSvg.js.map +1 -1
- package/dist/tableUtils.js +2 -2
- package/dist/tableUtils.js.map +1 -1
- package/eslint.config.js +10 -3
- package/jest.config.cjs +7 -0
- package/package.json +12 -10
- package/stylings.ts +23 -15
- package/tableData.test.ts +4 -4
- package/tableStyler.test.ts +1 -1
- package/tableSvg.ts +1 -1
- package/tsconfig.json +18 -83
- package/jest.config.js +0 -5
- package/svg-table-0.0.1.tgz +0 -0
- package/svg-table-0.1.2-snapshot.tgz +0 -0
package/dist/TableStyler.js
CHANGED
|
@@ -1,97 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.TableStyler = exports.StyledTable = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
const TableData_1 = require("./TableData");
|
|
5
|
+
const data_frame_ts_1 = require("data-frame-ts");
|
|
6
|
+
const result_fn_1 = require("result-fn");
|
|
7
|
+
const stylings_1 = require("./stylings");
|
|
19
8
|
/**
|
|
20
9
|
* Represents a table with applied styles.
|
|
21
10
|
* Provides methods to access the styling information for different parts of the table.
|
|
22
11
|
*/
|
|
23
|
-
|
|
12
|
+
class StyledTable {
|
|
24
13
|
/**
|
|
25
14
|
* Creates a new StyledTable instance.
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
this.dataFrame =
|
|
36
|
-
this.font =
|
|
37
|
-
this.border =
|
|
38
|
-
this.background =
|
|
39
|
-
this.dimension =
|
|
40
|
-
this.padding =
|
|
41
|
-
this.margin =
|
|
15
|
+
* @param dataFrame_ The data frame containing the table data
|
|
16
|
+
* @param font_ The font settings for the table
|
|
17
|
+
* @param border_ The border settings for the table
|
|
18
|
+
* @param background_ The background settings for the table
|
|
19
|
+
* @param dimension_ The dimension settings for the table
|
|
20
|
+
* @param padding_ The padding settings for the table
|
|
21
|
+
* @param margin_ The margin settings for the table
|
|
22
|
+
*/
|
|
23
|
+
constructor(dataFrame_, font_, border_, background_, dimension_, padding_, margin_) {
|
|
24
|
+
this.dataFrame = dataFrame_;
|
|
25
|
+
this.font = font_;
|
|
26
|
+
this.border = border_;
|
|
27
|
+
this.background = background_;
|
|
28
|
+
this.dimension = dimension_;
|
|
29
|
+
this.padding = padding_;
|
|
30
|
+
this.margin = margin_;
|
|
42
31
|
}
|
|
43
32
|
/**
|
|
44
33
|
* @return A copy of the {@link DataFrame} with all the styling and formatting tags
|
|
45
34
|
*/
|
|
46
|
-
|
|
35
|
+
data() {
|
|
47
36
|
return this.dataFrame.copy();
|
|
48
|
-
}
|
|
49
|
-
|
|
37
|
+
}
|
|
38
|
+
tableData() {
|
|
50
39
|
// fromDataFrame makes a copy of the data frame
|
|
51
40
|
return TableData_1.TableData.fromDataFrame(this.dataFrame);
|
|
52
|
-
}
|
|
41
|
+
}
|
|
53
42
|
/**
|
|
54
43
|
* Returns the font settings for the table.
|
|
55
44
|
* @returns A copy of the table's font settings
|
|
56
45
|
*/
|
|
57
|
-
|
|
58
|
-
return
|
|
59
|
-
}
|
|
46
|
+
tableFont() {
|
|
47
|
+
return Object.assign({}, this.font);
|
|
48
|
+
}
|
|
60
49
|
/**
|
|
61
50
|
* Returns the border settings for the table.
|
|
62
51
|
* @returns A copy of the table's border settings
|
|
63
52
|
*/
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
-
}
|
|
53
|
+
tableBorder() {
|
|
54
|
+
return Object.assign({}, this.border);
|
|
55
|
+
}
|
|
67
56
|
/**
|
|
68
57
|
* Returns the background settings for the table.
|
|
69
58
|
* @returns A copy of the table's background settings
|
|
70
59
|
*/
|
|
71
|
-
|
|
72
|
-
return
|
|
73
|
-
}
|
|
60
|
+
tableBackground() {
|
|
61
|
+
return Object.assign({}, this.background);
|
|
62
|
+
}
|
|
74
63
|
/**
|
|
75
64
|
* Returns the dimension settings for the table.
|
|
76
65
|
* @returns A copy of the table's dimension settings
|
|
77
66
|
*/
|
|
78
|
-
|
|
79
|
-
return
|
|
80
|
-
}
|
|
67
|
+
tableDimensions() {
|
|
68
|
+
return Object.assign({}, this.dimension);
|
|
69
|
+
}
|
|
81
70
|
/**
|
|
82
71
|
* Returns the padding settings for the table.
|
|
83
72
|
* @returns A copy of the table's padding settings
|
|
84
73
|
*/
|
|
85
|
-
|
|
86
|
-
return
|
|
87
|
-
}
|
|
74
|
+
tablePadding() {
|
|
75
|
+
return Object.assign({}, this.padding);
|
|
76
|
+
}
|
|
88
77
|
/**
|
|
89
78
|
* Returns the margin settings for the table.
|
|
90
79
|
* @returns A copy of the table's margin settings
|
|
91
80
|
*/
|
|
92
|
-
|
|
93
|
-
return
|
|
94
|
-
}
|
|
81
|
+
tableMargin() {
|
|
82
|
+
return Object.assign({}, this.margin);
|
|
83
|
+
}
|
|
95
84
|
/**
|
|
96
85
|
* Retrieves styling tags for a specific column.
|
|
97
86
|
* @param columnIndex The index of the column
|
|
@@ -99,22 +88,22 @@ var StyledTable = /** @class */ (function () {
|
|
|
99
88
|
* @returns A Result containing the tag if found, or an error message
|
|
100
89
|
* @private
|
|
101
90
|
*/
|
|
102
|
-
|
|
91
|
+
columnTagsFor(columnIndex, tagStyleType) {
|
|
103
92
|
// find all the tags and type them to row-header tags
|
|
104
|
-
|
|
93
|
+
const tags = this.dataFrame
|
|
105
94
|
.columnTagsFor(columnIndex)
|
|
106
|
-
.filter(
|
|
107
|
-
.map(
|
|
95
|
+
.filter(tag => tag.matchesId(tagStyleType, data_frame_ts_1.ColumnCoordinate.of(columnIndex)))
|
|
96
|
+
.map(tag => tag);
|
|
108
97
|
if (tags.length === 0) {
|
|
109
|
-
return (0, result_fn_1.failureResult)(
|
|
98
|
+
return (0, result_fn_1.failureResult)(`(StyledTable::columnTagsFor) No matching column-style tags found for table; column_index: ${columnIndex}; tag_type: ${tagStyleType}`);
|
|
110
99
|
}
|
|
111
100
|
// when there are more than one tag representing the row-header style, then sort based on priority and
|
|
112
101
|
// take the first one
|
|
113
102
|
if (tags.length > 1) {
|
|
114
|
-
tags.sort(
|
|
103
|
+
tags.sort((tagA, tagB) => tagB.value.priority - tagA.value.priority);
|
|
115
104
|
}
|
|
116
105
|
return (0, result_fn_1.successResult)(tags[0]);
|
|
117
|
-
}
|
|
106
|
+
}
|
|
118
107
|
/**
|
|
119
108
|
* Retrieves styling tags for a specific row.
|
|
120
109
|
* @param rowIndex The index of the row
|
|
@@ -122,125 +111,121 @@ var StyledTable = /** @class */ (function () {
|
|
|
122
111
|
* @returns A Result containing the tag if found, or an error message
|
|
123
112
|
* @private
|
|
124
113
|
*/
|
|
125
|
-
|
|
126
|
-
var tagStyleType = [];
|
|
127
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
128
|
-
tagStyleType[_i - 1] = arguments[_i];
|
|
129
|
-
}
|
|
114
|
+
rowTagsFor(rowIndex, ...tagStyleType) {
|
|
130
115
|
// find all the tags and type them to column-header tags
|
|
131
|
-
|
|
116
|
+
const tags = this.dataFrame
|
|
132
117
|
.rowTagsFor(rowIndex)
|
|
133
|
-
.filter(
|
|
134
|
-
.map(
|
|
118
|
+
.filter(tag => tagStyleType.filter(styleType => tag.matchesId(styleType, data_frame_ts_1.RowCoordinate.of(rowIndex))).length > 0)
|
|
119
|
+
.map(tag => tag);
|
|
135
120
|
if (tags.length === 0) {
|
|
136
|
-
return (0, result_fn_1.failureResult)(
|
|
121
|
+
return (0, result_fn_1.failureResult)(`(StyledTable::rowTagsFor) No matching row-style tags found for table; row_index: ${rowIndex}; tag_type: ${tagStyleType}`);
|
|
137
122
|
}
|
|
138
123
|
// when there are more than one tag representing the column-header, the sort based on the priority and
|
|
139
124
|
// take the first one
|
|
140
125
|
if (tags.length > 1) {
|
|
141
|
-
tags.sort(
|
|
126
|
+
tags.sort((tagA, tagB) => tagB.value.priority - tagA.value.priority);
|
|
142
127
|
}
|
|
143
128
|
return (0, result_fn_1.successResult)(tags[0]);
|
|
144
|
-
}
|
|
129
|
+
}
|
|
145
130
|
/**
|
|
146
131
|
* Checks if the table has a row header.
|
|
147
132
|
* @returns `true` if the table has a row header, `false` otherwise
|
|
148
133
|
*/
|
|
149
|
-
|
|
134
|
+
hasRowHeader() {
|
|
150
135
|
return TableData_1.TableData.hasRowHeader(this.dataFrame);
|
|
151
|
-
}
|
|
136
|
+
}
|
|
152
137
|
/**
|
|
153
138
|
* Checks if the table has a column header.
|
|
154
139
|
* @returns `true` if the table has a row header, `false` otherwise
|
|
155
140
|
*/
|
|
156
|
-
|
|
141
|
+
hasColumnHeader() {
|
|
157
142
|
return TableData_1.TableData.hasColumnHeader(this.dataFrame);
|
|
158
|
-
}
|
|
143
|
+
}
|
|
159
144
|
/**
|
|
160
145
|
* Checks if the table has a footer header.
|
|
161
146
|
* @returns `true` if the table has a row header, `false` otherwise
|
|
162
147
|
*/
|
|
163
|
-
|
|
148
|
+
hasFooter() {
|
|
164
149
|
return TableData_1.TableData.hasFooter(this.dataFrame);
|
|
165
|
-
}
|
|
150
|
+
}
|
|
166
151
|
/**
|
|
167
152
|
* Gets the style for the row header.
|
|
168
153
|
* @returns A Result containing the row header style if found, or an error message
|
|
169
154
|
*/
|
|
170
|
-
|
|
155
|
+
rowHeaderStyle() {
|
|
171
156
|
if (!TableData_1.TableData.hasRowHeader(this.dataFrame)) {
|
|
172
157
|
return (0, result_fn_1.failureResult)("(StyledTable::rowHeaderStyle) The table data does not have a row header");
|
|
173
158
|
}
|
|
174
159
|
return this
|
|
175
160
|
.columnTagsFor(0, stylings_1.TableStyleType.ROW_HEADER)
|
|
176
|
-
.map(
|
|
177
|
-
}
|
|
161
|
+
.map(tag => tag.value);
|
|
162
|
+
}
|
|
178
163
|
/**
|
|
179
164
|
* Gets the style for the column header.
|
|
180
165
|
* @returns A Result containing the column header style if found, or an error message
|
|
181
166
|
*/
|
|
182
|
-
|
|
167
|
+
columnHeaderStyle() {
|
|
183
168
|
if (!TableData_1.TableData.hasColumnHeader(this.dataFrame)) {
|
|
184
169
|
return (0, result_fn_1.failureResult)("(StyledTable::columnHeaderStyle) The table data does not have a column header");
|
|
185
170
|
}
|
|
186
171
|
return this
|
|
187
172
|
.rowTagsFor(0, stylings_1.TableStyleType.COLUMN_HEADER)
|
|
188
|
-
.map(
|
|
189
|
-
}
|
|
173
|
+
.map(tag => tag.value);
|
|
174
|
+
}
|
|
190
175
|
/**
|
|
191
176
|
* Gets the style for the footer.
|
|
192
177
|
* @returns A Result containing the footer style if found, or an error message
|
|
193
178
|
*/
|
|
194
|
-
|
|
179
|
+
footerStyle() {
|
|
195
180
|
if (!TableData_1.TableData.hasFooter(this.dataFrame)) {
|
|
196
181
|
return (0, result_fn_1.failureResult)("(StyledTable::footerStyle) The table data does not have a footer");
|
|
197
182
|
}
|
|
198
183
|
return this
|
|
199
184
|
.rowTagsFor(this.dataFrame.rowCount() - 1, stylings_1.TableStyleType.FOOTER)
|
|
200
|
-
.map(
|
|
201
|
-
}
|
|
185
|
+
.map(tag => tag.value);
|
|
186
|
+
}
|
|
202
187
|
/**
|
|
203
188
|
* Gets the style for a specific row.
|
|
204
189
|
* @param rowIndex The index of the row
|
|
205
190
|
* @returns A Result containing the row style if found, or an error message
|
|
206
191
|
*/
|
|
207
|
-
|
|
192
|
+
rowStyleFor(rowIndex) {
|
|
208
193
|
return this
|
|
209
194
|
.rowTagsFor(rowIndex, stylings_1.TableStyleType.ROW)
|
|
210
|
-
.map(
|
|
211
|
-
}
|
|
195
|
+
.map(tag => tag.value);
|
|
196
|
+
}
|
|
212
197
|
/**
|
|
213
198
|
* Gets the style for a specific column.
|
|
214
199
|
* @param columnIndex The index of the column
|
|
215
200
|
* @returns A Result containing the column style if found, or an error message
|
|
216
201
|
*/
|
|
217
|
-
|
|
202
|
+
columnStyleFor(columnIndex) {
|
|
218
203
|
return this
|
|
219
204
|
.columnTagsFor(columnIndex, stylings_1.TableStyleType.COLUMN)
|
|
220
|
-
.map(
|
|
221
|
-
}
|
|
205
|
+
.map(tag => tag.value);
|
|
206
|
+
}
|
|
222
207
|
/**
|
|
223
208
|
* Gets the style for a specific cell.
|
|
224
209
|
* @param rowIndex The row index of the cell
|
|
225
210
|
* @param columnIndex The column index of the cell
|
|
226
211
|
* @returns A Result containing the cell style if found, or an error message
|
|
227
212
|
*/
|
|
228
|
-
|
|
213
|
+
cellStyleFor(rowIndex, columnIndex) {
|
|
229
214
|
// find all the tags and type them to column-header tags
|
|
230
|
-
|
|
215
|
+
const tags = this.dataFrame
|
|
231
216
|
.cellTagsFor(rowIndex, columnIndex)
|
|
232
|
-
.filter(
|
|
233
|
-
.map(
|
|
217
|
+
.filter(tag => tag.matchesId(stylings_1.TableStyleType.CELL, data_frame_ts_1.CellCoordinate.of(rowIndex, columnIndex)))
|
|
218
|
+
.map(tag => tag);
|
|
234
219
|
if (tags.length === 0) {
|
|
235
|
-
return (0, result_fn_1.failureResult)(
|
|
220
|
+
return (0, result_fn_1.failureResult)(`(StyledTable::cellStyleFor) No matching cell-style tags found for table; row_index: ${rowIndex}; column_index: ${columnIndex}`);
|
|
236
221
|
}
|
|
237
222
|
// when there are more than one tag representing the column-header, the sort based on the priority and
|
|
238
223
|
// take the first one
|
|
239
224
|
if (tags.length > 1) {
|
|
240
|
-
tags.sort(
|
|
225
|
+
tags.sort((tagA, tagB) => tagB.value.priority - tagA.value.priority);
|
|
241
226
|
}
|
|
242
227
|
return (0, result_fn_1.successResult)(tags[0].value);
|
|
243
|
-
}
|
|
228
|
+
}
|
|
244
229
|
/**
|
|
245
230
|
* Unlike the methods that retrieve the particular styles, say for a cell, a column header,
|
|
246
231
|
* and so forth, this method returns a {@link CellStyle} calculated from all the styles
|
|
@@ -259,21 +244,21 @@ var StyledTable = /** @class */ (function () {
|
|
|
259
244
|
* @return A result object containing the cell style if the indices are valid, or an error
|
|
260
245
|
* message if they are not.
|
|
261
246
|
*/
|
|
262
|
-
|
|
247
|
+
stylesForDataCoordinates(rowIndex, columnIndex) {
|
|
263
248
|
if (rowIndex < 0 || rowIndex >= TableData_1.TableData.dataRowCount(this.dataFrame) ||
|
|
264
249
|
columnIndex < 0 || columnIndex >= TableData_1.TableData.dataColumnCount(this.dataFrame)) {
|
|
265
|
-
return (0, result_fn_1.failureResult)(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
250
|
+
return (0, result_fn_1.failureResult)(`(StyledTable::dataCellStyles) Invalid row and/or column index for data; row_index${rowIndex}` +
|
|
251
|
+
`; column_index: ${columnIndex}` +
|
|
252
|
+
`; valid_row_index: [0, ${TableData_1.TableData.dataRowCount(this.dataFrame)})` +
|
|
253
|
+
`; valid_column_index: [0, ${TableData_1.TableData.dataColumnCount(this.dataFrame)})` +
|
|
254
|
+
`; has_column_header: ${TableData_1.TableData.hasColumnHeader(this.dataFrame)}` +
|
|
255
|
+
`; has_row_header: ${TableData_1.TableData.hasRowHeader(this.dataFrame)}` +
|
|
256
|
+
`; has_footer: ${TableData_1.TableData.hasFooter(this.dataFrame)}`);
|
|
272
257
|
}
|
|
273
|
-
|
|
274
|
-
|
|
258
|
+
const columnHeaderOffset = TableData_1.TableData.hasColumnHeader(this.dataFrame) ? 1 : 0;
|
|
259
|
+
const rowHeaderOffset = TableData_1.TableData.hasRowHeader(this.dataFrame) ? 1 : 0;
|
|
275
260
|
return this.stylesForTableCoordinates(rowIndex + columnHeaderOffset, columnIndex + rowHeaderOffset);
|
|
276
|
-
}
|
|
261
|
+
}
|
|
277
262
|
/**
|
|
278
263
|
* Unlike the methods that retrieve the particular styles, say for a cell, a column header,
|
|
279
264
|
* and so forth, this method returns a {@link CellStyle} calculated from all the styles
|
|
@@ -290,41 +275,41 @@ var StyledTable = /** @class */ (function () {
|
|
|
290
275
|
* row or column indexes are out of range.
|
|
291
276
|
* @see stylesForDataCoordinates
|
|
292
277
|
*/
|
|
293
|
-
|
|
278
|
+
stylesForTableCoordinates(rowIndex, columnIndex) {
|
|
294
279
|
if (rowIndex < 0 || rowIndex >= this.dataFrame.rowCount() || columnIndex < 0 || columnIndex >= this.dataFrame.columnCount()) {
|
|
295
|
-
return (0, result_fn_1.failureResult)(
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
280
|
+
return (0, result_fn_1.failureResult)(`(StyledTable::stylesFor) Invalid row and/or column index` +
|
|
281
|
+
`; row_index: ${rowIndex}` +
|
|
282
|
+
`; column_index: ${columnIndex}` +
|
|
283
|
+
`; valid_row_index: [0, ${this.dataFrame.rowCount()})` +
|
|
284
|
+
`; valid_column_index: [0, ${this.dataFrame.columnCount()})`);
|
|
300
285
|
}
|
|
301
286
|
//
|
|
302
287
|
// determine what styles may be available
|
|
303
|
-
|
|
288
|
+
const availableStyling = [];
|
|
304
289
|
if (rowIndex === 0) {
|
|
305
|
-
this.columnHeaderStyle().onSuccess(
|
|
290
|
+
this.columnHeaderStyle().onSuccess(styling => availableStyling.push(styling));
|
|
306
291
|
}
|
|
307
292
|
if (columnIndex === 0) {
|
|
308
|
-
this.rowHeaderStyle().onSuccess(
|
|
293
|
+
this.rowHeaderStyle().onSuccess(styling => availableStyling.push(styling));
|
|
309
294
|
}
|
|
310
295
|
if (rowIndex === this.dataFrame.rowCount() - 1) {
|
|
311
|
-
this.footerStyle().onSuccess(
|
|
296
|
+
this.footerStyle().onSuccess(styling => availableStyling.push(styling));
|
|
312
297
|
}
|
|
313
|
-
this.rowStyleFor(rowIndex).onSuccess(
|
|
314
|
-
this.columnStyleFor(columnIndex).onSuccess(
|
|
298
|
+
this.rowStyleFor(rowIndex).onSuccess(styling => availableStyling.push(styling));
|
|
299
|
+
this.columnStyleFor(columnIndex).onSuccess(styling => availableStyling.push(styling));
|
|
315
300
|
// the cell style is handled differently when it doesn't exist because we need a default set of
|
|
316
301
|
// values for the cell style in case not all properties are found in the available styles
|
|
317
302
|
this.cellStyleFor(rowIndex, columnIndex)
|
|
318
|
-
.onSuccess(
|
|
319
|
-
.onFailure(
|
|
303
|
+
.onSuccess(styling => availableStyling.push(styling))
|
|
304
|
+
.onFailure(() => availableStyling.push({ style: stylings_1.defaultCellStyle, priority: -1 }));
|
|
320
305
|
//
|
|
321
306
|
// calculate the style for the cell based on the priorities and available styles
|
|
322
|
-
|
|
323
|
-
.sort(
|
|
324
|
-
.reduce(
|
|
307
|
+
const cellStyle = availableStyling
|
|
308
|
+
.sort((stylingA, stylingB) => stylingA.priority - stylingB.priority)
|
|
309
|
+
.reduce((style, curr) => ({
|
|
325
310
|
font: (curr.style.hasOwnProperty('font') ?
|
|
326
311
|
// @ts-ignore
|
|
327
|
-
|
|
312
|
+
Object.assign(Object.assign({}, style.font), curr.style.font) : (style.hasOwnProperty('font') ? Object.assign({}, style.font) : stylings_1.defaultTableFont)),
|
|
328
313
|
alignText: (curr.style.hasOwnProperty('alignText') ?
|
|
329
314
|
// @ts-ignore
|
|
330
315
|
curr.style.alignText : (style.hasOwnProperty('alignText') ? style.alignText : stylings_1.defaultColumnStyle.alignText)),
|
|
@@ -333,87 +318,86 @@ var StyledTable = /** @class */ (function () {
|
|
|
333
318
|
curr.style.verticalAlignText : (style.hasOwnProperty('verticalAlignText') ? style.verticalAlignText : stylings_1.defaultColumnStyle.verticalAlignText)),
|
|
334
319
|
background: (curr.style.hasOwnProperty('background') ?
|
|
335
320
|
// @ts-ignore
|
|
336
|
-
|
|
321
|
+
Object.assign(Object.assign({}, style.background), curr.style.background) : (style.hasOwnProperty('background') ? style.background : stylings_1.defaultTableBackground)),
|
|
337
322
|
dimension: (curr.style.hasOwnProperty('dimension') ?
|
|
338
323
|
// @ts-ignore
|
|
339
|
-
|
|
324
|
+
Object.assign(Object.assign({}, style.dimension), curr.style.dimension) : (style.hasOwnProperty('dimension') ? Object.assign({}, style.dimension) : stylings_1.defaultDimension)),
|
|
340
325
|
padding: (curr.style.hasOwnProperty('padding') ?
|
|
341
326
|
// @ts-ignore
|
|
342
|
-
|
|
327
|
+
Object.assign(Object.assign({}, style.padding), curr.style.padding) : (style.hasOwnProperty('padding') ? Object.assign({}, style.padding) : stylings_1.defaultTablePadding)),
|
|
343
328
|
border: (curr.style.hasOwnProperty('border') ?
|
|
344
329
|
// @ts-ignore
|
|
345
|
-
|
|
346
|
-
})
|
|
330
|
+
Object.assign(Object.assign({}, style.border), curr.style.border) : (style.hasOwnProperty('border') ? Object.assign({}, style.border) : stylings_1.defaultBorder)),
|
|
331
|
+
}), stylings_1.defaultCellStyle);
|
|
347
332
|
return (0, result_fn_1.successResult)(cellStyle);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
}());
|
|
333
|
+
}
|
|
334
|
+
}
|
|
351
335
|
exports.StyledTable = StyledTable;
|
|
352
336
|
/**
|
|
353
337
|
* Builder class for creating styled tables.
|
|
354
338
|
* Provides methods to configure various styling aspects of a table.
|
|
355
339
|
*/
|
|
356
|
-
|
|
340
|
+
class TableStyler {
|
|
357
341
|
/**
|
|
358
342
|
* Private constructor to enforce factory method usage.
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
361
|
-
* @param
|
|
362
|
-
* @param
|
|
363
|
-
* @param
|
|
364
|
-
* @param
|
|
365
|
-
* @param
|
|
366
|
-
* @param
|
|
367
|
-
*/
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
this.dataFrame =
|
|
377
|
-
this.font =
|
|
378
|
-
this.border =
|
|
379
|
-
this.background =
|
|
380
|
-
this.dimension =
|
|
381
|
-
this.padding =
|
|
382
|
-
this.margin =
|
|
383
|
-
this.errors =
|
|
343
|
+
* @param dataFrame_ The data frame containing the table data
|
|
344
|
+
* @param font_ The font settings for the table
|
|
345
|
+
* @param border_ The border settings for the table
|
|
346
|
+
* @param background_ The background settings for the table
|
|
347
|
+
* @param dimension_ The dimension settings for the table
|
|
348
|
+
* @param padding_ The padding settings for the table
|
|
349
|
+
* @param margin_ The margin settings for the table
|
|
350
|
+
* @param errors_ Array to collect error messages during styling operations
|
|
351
|
+
*/
|
|
352
|
+
constructor(dataFrame_, font_ = stylings_1.defaultTableFont, border_ = stylings_1.defaultBorder, background_ = stylings_1.defaultTableBackground, dimension_ = { width: NaN, height: NaN }, padding_ = stylings_1.defaultTablePadding, margin_ = stylings_1.defaultTableMargin, errors_ = []) {
|
|
353
|
+
this.font = stylings_1.defaultTableFont;
|
|
354
|
+
this.border = stylings_1.defaultBorder;
|
|
355
|
+
this.background = stylings_1.defaultTableBackground;
|
|
356
|
+
this.dimension = { width: NaN, height: NaN };
|
|
357
|
+
this.padding = stylings_1.defaultTablePadding;
|
|
358
|
+
this.margin = stylings_1.defaultTableMargin;
|
|
359
|
+
this.errors = [];
|
|
360
|
+
this.dataFrame = dataFrame_;
|
|
361
|
+
this.font = font_;
|
|
362
|
+
this.border = border_;
|
|
363
|
+
this.background = background_;
|
|
364
|
+
this.dimension = dimension_;
|
|
365
|
+
this.padding = padding_;
|
|
366
|
+
this.margin = margin_;
|
|
367
|
+
this.errors = errors_;
|
|
384
368
|
}
|
|
385
369
|
/**
|
|
386
370
|
* Creates a TableStyler from a TableData object.
|
|
387
371
|
* @param tableData The TableData object to style
|
|
388
372
|
* @returns A new TableStyler instance
|
|
389
373
|
*/
|
|
390
|
-
|
|
374
|
+
static fromTableData(tableData) {
|
|
391
375
|
return new TableStyler(tableData.unwrapDataFrame());
|
|
392
|
-
}
|
|
376
|
+
}
|
|
393
377
|
/**
|
|
394
378
|
* Creates a TableStyler from a DataFrame object.
|
|
395
379
|
* @param dataFrame The DataFrame object to style
|
|
396
380
|
* @returns A new TableStyler instance
|
|
397
381
|
*/
|
|
398
|
-
|
|
382
|
+
static fromDataFrame(dataFrame) {
|
|
399
383
|
return new TableStyler(dataFrame.copy());
|
|
400
|
-
}
|
|
384
|
+
}
|
|
401
385
|
/**
|
|
402
386
|
* Creates a copy of this TableStyler instance.
|
|
403
387
|
* @returns A new TableStyler instance with the same properties
|
|
404
388
|
*/
|
|
405
|
-
|
|
389
|
+
copy() {
|
|
406
390
|
return new TableStyler(this.dataFrame, this.font, this.border, this.background, this.dimension, this.padding, this.margin, this.errors);
|
|
407
|
-
}
|
|
391
|
+
}
|
|
408
392
|
/**
|
|
409
393
|
* Creates a new TableStyler with updated properties.
|
|
410
394
|
* @param properties Partial properties to update
|
|
411
395
|
* @returns A new TableStyler instance with updated properties
|
|
412
396
|
*/
|
|
413
|
-
|
|
414
|
-
|
|
397
|
+
update(properties) {
|
|
398
|
+
const { dataFrame = this.dataFrame, font = this.font, border = this.border, background = this.background, dimension = this.dimension, padding = this.padding, margin = this.margin, } = properties;
|
|
415
399
|
return new TableStyler(dataFrame, font, border, background, dimension, padding, margin, this.errors);
|
|
416
|
-
}
|
|
400
|
+
}
|
|
417
401
|
/**
|
|
418
402
|
* Applies the specified font settings for the table and returns a new {@link TableStyler}
|
|
419
403
|
* instance with the updated font configuration.
|
|
@@ -422,62 +406,50 @@ var TableStyler = /** @class */ (function () {
|
|
|
422
406
|
* properties of the TableFont.
|
|
423
407
|
* @return A new {@link TableStyler} instance with the updated font settings.
|
|
424
408
|
*/
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
return builder;
|
|
429
|
-
};
|
|
409
|
+
withTableFont(font) {
|
|
410
|
+
return this.update({ font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), font) });
|
|
411
|
+
}
|
|
430
412
|
/**
|
|
431
413
|
* Sets the background for the table.
|
|
432
414
|
* @param background The background settings to apply
|
|
433
415
|
* @returns A new TableStyler instance with the updated background
|
|
434
416
|
*/
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
return builder;
|
|
439
|
-
};
|
|
417
|
+
withTableBackground(background) {
|
|
418
|
+
return this.update({ background: Object.assign(Object.assign({}, this.background), background) });
|
|
419
|
+
}
|
|
440
420
|
/**
|
|
441
421
|
* Sets the border for the table.
|
|
442
422
|
* @param border The border settings to apply
|
|
443
423
|
* @returns A new TableStyler instance with the updated border
|
|
444
424
|
*/
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
return builder;
|
|
449
|
-
};
|
|
425
|
+
withBorder(border) {
|
|
426
|
+
return this.update({ border: Object.assign(Object.assign({}, this.border), border) });
|
|
427
|
+
}
|
|
450
428
|
/**
|
|
451
429
|
* Sets the dimensions for the table.
|
|
452
430
|
* @param width The width of the table
|
|
453
431
|
* @param height The height of the table
|
|
454
432
|
* @returns A new TableStyler instance with the updated dimensions
|
|
455
433
|
*/
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
return builder;
|
|
460
|
-
};
|
|
434
|
+
withDimensions(width, height) {
|
|
435
|
+
return this.update({ dimension: { width, height } });
|
|
436
|
+
}
|
|
461
437
|
/**
|
|
462
438
|
* Sets the padding for the table.
|
|
463
439
|
* @param padding The padding settings to apply
|
|
464
440
|
* @returns A new TableStyler instance with the updated padding
|
|
465
441
|
*/
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
return builder;
|
|
470
|
-
};
|
|
442
|
+
withPadding(padding) {
|
|
443
|
+
return this.update({ padding: Object.assign(Object.assign({}, this.padding), padding) });
|
|
444
|
+
}
|
|
471
445
|
/**
|
|
472
446
|
* Sets the margin for the table.
|
|
473
447
|
* @param margin The margin settings to apply
|
|
474
448
|
* @returns A new TableStyler instance with the updated margin
|
|
475
449
|
*/
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
return builder;
|
|
480
|
-
};
|
|
450
|
+
withMargin(margin) {
|
|
451
|
+
return this.update({ margin: Object.assign(Object.assign({}, this.margin), margin) });
|
|
452
|
+
}
|
|
481
453
|
/**
|
|
482
454
|
* Tags a row with a style.
|
|
483
455
|
* @param rowIndex The index of the row to tag
|
|
@@ -486,14 +458,13 @@ var TableStyler = /** @class */ (function () {
|
|
|
486
458
|
* @returns A Result containing a new TableStyler with the tagged row, or an error message
|
|
487
459
|
* @private
|
|
488
460
|
*/
|
|
489
|
-
|
|
490
|
-
var _this = this;
|
|
461
|
+
tagRow(rowIndex, tagStyleType, style) {
|
|
491
462
|
return this.dataFrame.tagRow(rowIndex, tagStyleType, style)
|
|
492
463
|
// when successfully tagged, make an updated copy of this builder with the new data-frame
|
|
493
|
-
.map(
|
|
464
|
+
.map(df => this.update({ dataFrame: df }))
|
|
494
465
|
// when failed to tag, add to the errors
|
|
495
|
-
.onFailure(
|
|
496
|
-
}
|
|
466
|
+
.onFailure(error => this.errors.push(error));
|
|
467
|
+
}
|
|
497
468
|
/**
|
|
498
469
|
* Tags a column with a style.
|
|
499
470
|
* @param columnIndex The index of the column to tag
|
|
@@ -502,24 +473,21 @@ var TableStyler = /** @class */ (function () {
|
|
|
502
473
|
* @returns A Result containing a new TableStyler with the tagged column, or an error message
|
|
503
474
|
* @private
|
|
504
475
|
*/
|
|
505
|
-
|
|
506
|
-
var _this = this;
|
|
476
|
+
tagColumn(columnIndex, tagStyleType, style) {
|
|
507
477
|
return this.dataFrame.tagColumn(columnIndex, tagStyleType, style)
|
|
508
478
|
// when successfully tagged, make an updated copy of this builder with the new data-frame
|
|
509
|
-
.map(
|
|
479
|
+
.map(df => this.update({ dataFrame: df }))
|
|
510
480
|
// when failed to tag, add to the errors
|
|
511
|
-
.onFailure(
|
|
512
|
-
}
|
|
481
|
+
.onFailure(error => this.errors.push(error));
|
|
482
|
+
}
|
|
513
483
|
/**
|
|
514
484
|
* Sets the style for the column header row.
|
|
515
485
|
* @param columnHeaderStyle The style to apply to the column header. Style properties that are not specified
|
|
516
486
|
* will be set to their default values.
|
|
517
|
-
* @param priority The priority of this style (higher values take precedence)
|
|
487
|
+
* @param [priority=Infinity] The priority of this style (higher values take precedence)
|
|
518
488
|
* @returns A new TableStyler instance with the column header style applied
|
|
519
489
|
*/
|
|
520
|
-
|
|
521
|
-
if (columnHeaderStyle === void 0) { columnHeaderStyle = stylings_1.defaultColumnHeaderStyle; }
|
|
522
|
-
if (priority === void 0) { priority = Infinity; }
|
|
490
|
+
withColumnHeaderStyle(columnHeaderStyle = stylings_1.defaultColumnHeaderStyle, priority = Infinity) {
|
|
523
491
|
if (!TableData_1.TableData.hasColumnHeader(this.dataFrame)) {
|
|
524
492
|
this.errors.push("The column header style can only be supplied when the table data has a column header");
|
|
525
493
|
return this;
|
|
@@ -528,7 +496,7 @@ var TableStyler = /** @class */ (function () {
|
|
|
528
496
|
return this
|
|
529
497
|
.tagRow(0, stylings_1.TableStyleType.COLUMN_HEADER, (0, stylings_1.stylingFor)(columnHeaderStyle, stylings_1.defaultColumnHeaderStyle, priority))
|
|
530
498
|
.getOrElse(this);
|
|
531
|
-
}
|
|
499
|
+
}
|
|
532
500
|
/**
|
|
533
501
|
* Sets the style for the row header column.
|
|
534
502
|
* @param rowHeaderStyle The style to apply to the row header. Style properties that are not specified
|
|
@@ -536,8 +504,7 @@ var TableStyler = /** @class */ (function () {
|
|
|
536
504
|
* @param priority The priority of this style (higher values take precedence)
|
|
537
505
|
* @returns A new TableStyler instance with the row header style applied
|
|
538
506
|
*/
|
|
539
|
-
|
|
540
|
-
if (priority === void 0) { priority = Infinity; }
|
|
507
|
+
withRowHeaderStyle(rowHeaderStyle, priority = Infinity) {
|
|
541
508
|
if (!TableData_1.TableData.hasRowHeader(this.dataFrame)) {
|
|
542
509
|
this.errors.push("The row header style can only be supplied when the table data has row headers");
|
|
543
510
|
return this;
|
|
@@ -546,7 +513,7 @@ var TableStyler = /** @class */ (function () {
|
|
|
546
513
|
return this
|
|
547
514
|
.tagColumn(0, stylings_1.TableStyleType.ROW_HEADER, (0, stylings_1.stylingFor)(rowHeaderStyle, stylings_1.defaultRowHeaderStyle, priority))
|
|
548
515
|
.getOrElse(this);
|
|
549
|
-
}
|
|
516
|
+
}
|
|
550
517
|
/**
|
|
551
518
|
* Sets the style for the footer row.
|
|
552
519
|
* @param footerStyle The style to apply to the footer. Style properties that are not specified
|
|
@@ -554,18 +521,17 @@ var TableStyler = /** @class */ (function () {
|
|
|
554
521
|
* @param priority The priority of this style (higher values take precedence)
|
|
555
522
|
* @returns A new TableStyler instance with the footer style applied
|
|
556
523
|
*/
|
|
557
|
-
|
|
558
|
-
if (priority === void 0) { priority = Infinity; }
|
|
524
|
+
withFooterStyle(footerStyle, priority = Infinity) {
|
|
559
525
|
if (!TableData_1.TableData.hasFooter(this.dataFrame)) {
|
|
560
526
|
this.errors.push("The footer style can only be supplied when the table data has a footer");
|
|
561
527
|
return this;
|
|
562
528
|
}
|
|
563
529
|
// tag the row the footer style, and if it fails, then return this (unmodified) builder
|
|
564
|
-
|
|
530
|
+
const footerIndex = TableData_1.TableData.tableRowCount(this.dataFrame) - 1;
|
|
565
531
|
return this
|
|
566
532
|
.tagRow(footerIndex, stylings_1.TableStyleType.FOOTER, (0, stylings_1.stylingFor)(footerStyle, stylings_1.defaultFooterStyle, priority))
|
|
567
533
|
.getOrElse(this);
|
|
568
|
-
}
|
|
534
|
+
}
|
|
569
535
|
/**
|
|
570
536
|
* Sets the style for a specific row.
|
|
571
537
|
* @param rowIndex The index of the row to style
|
|
@@ -574,17 +540,16 @@ var TableStyler = /** @class */ (function () {
|
|
|
574
540
|
* @param priority The priority of this style (higher values take precedence)
|
|
575
541
|
* @returns A new TableStyler instance with the row style applied
|
|
576
542
|
*/
|
|
577
|
-
|
|
578
|
-
if (priority === void 0) { priority = 0; }
|
|
543
|
+
withRowStyle(rowIndex, rowStyle, priority = 0) {
|
|
579
544
|
if (rowIndex < 0 || rowIndex >= TableData_1.TableData.tableRowCount(this.dataFrame)) {
|
|
580
|
-
this.errors.push(
|
|
545
|
+
this.errors.push(`The row index, when setting a row-style, must be between 0 and ${TableData_1.TableData.tableRowCount(this.dataFrame) - 1}`);
|
|
581
546
|
return this;
|
|
582
547
|
}
|
|
583
548
|
// tag the row with a style, and if it fails, then return this (unmodified) builder
|
|
584
549
|
return this
|
|
585
550
|
.tagRow(rowIndex, stylings_1.TableStyleType.ROW, (0, stylings_1.stylingFor)(rowStyle, stylings_1.defaultRowStyle, priority))
|
|
586
551
|
.getOrElse(this);
|
|
587
|
-
}
|
|
552
|
+
}
|
|
588
553
|
/**
|
|
589
554
|
* Applies specific styles to rows in a table based on the provided row indexes.
|
|
590
555
|
*
|
|
@@ -596,24 +561,22 @@ var TableStyler = /** @class */ (function () {
|
|
|
596
561
|
* @return A new TableStyler instance with the specified row styles applied.
|
|
597
562
|
* @see withRowStyle
|
|
598
563
|
*/
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
var indexes = rowIndexes.length > 0 ?
|
|
564
|
+
withRowStyles(rowIndexes, rowStyle, priority = 0) {
|
|
565
|
+
const indexes = rowIndexes.length > 0 ?
|
|
602
566
|
rowIndexes :
|
|
603
|
-
new Array(this.dataFrame.rowCount()).fill(0).map(
|
|
567
|
+
new Array(this.dataFrame.rowCount()).fill(0).map((_, i) => i);
|
|
604
568
|
return TableStyler.withRowStyles(this, indexes, rowStyle, priority);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
if (priority === void 0) { priority = 0; }
|
|
569
|
+
}
|
|
570
|
+
static withRowStyles(tableStyler, rowIndexes, rowStyle, priority = 0) {
|
|
608
571
|
if (rowIndexes.length > 0) {
|
|
609
|
-
|
|
572
|
+
const rowIndex = rowIndexes.shift();
|
|
610
573
|
if (rowIndex != null) {
|
|
611
|
-
|
|
574
|
+
const styler = tableStyler.withRowStyle(rowIndex, rowStyle, priority);
|
|
612
575
|
return TableStyler.withRowStyles(styler, rowIndexes, rowStyle, priority);
|
|
613
576
|
}
|
|
614
577
|
}
|
|
615
578
|
return tableStyler;
|
|
616
|
-
}
|
|
579
|
+
}
|
|
617
580
|
/**
|
|
618
581
|
* Sets the style for a specific column.
|
|
619
582
|
* @param columnIndex The index of the column to style
|
|
@@ -622,17 +585,16 @@ var TableStyler = /** @class */ (function () {
|
|
|
622
585
|
* @param priority The priority of this style (higher values take precedence)
|
|
623
586
|
* @returns A new TableStyler instance with the column style applied
|
|
624
587
|
*/
|
|
625
|
-
|
|
626
|
-
if (priority === void 0) { priority = 0; }
|
|
588
|
+
withColumnStyle(columnIndex, columnStyle, priority = 0) {
|
|
627
589
|
if (columnIndex < 0 || columnIndex >= TableData_1.TableData.tableColumnCount(this.dataFrame)) {
|
|
628
|
-
this.errors.push(
|
|
590
|
+
this.errors.push(`The column index, when setting a column-style, must be between 0 and ${TableData_1.TableData.tableColumnCount(this.dataFrame) - 1}`);
|
|
629
591
|
return this;
|
|
630
592
|
}
|
|
631
593
|
// tag the row with a style, and if it fails, then return this (unmodified) builder
|
|
632
594
|
return this
|
|
633
595
|
.tagColumn(columnIndex, stylings_1.TableStyleType.COLUMN, (0, stylings_1.stylingFor)(columnStyle, stylings_1.defaultColumnStyle, priority))
|
|
634
596
|
.getOrElse(this);
|
|
635
|
-
}
|
|
597
|
+
}
|
|
636
598
|
/**
|
|
637
599
|
* Applies specified styles to the columns of a table.
|
|
638
600
|
*
|
|
@@ -643,24 +605,22 @@ var TableStyler = /** @class */ (function () {
|
|
|
643
605
|
* @return Returns an instance of TableStyler with the updated column styles applied.
|
|
644
606
|
* @see withColumnStyle
|
|
645
607
|
*/
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
var indexes = columnIndexes.length > 0 ?
|
|
608
|
+
withColumnStyles(columnIndexes, columnStyle, priority = 0) {
|
|
609
|
+
const indexes = columnIndexes.length > 0 ?
|
|
649
610
|
columnIndexes :
|
|
650
|
-
new Array(this.dataFrame.columnCount()).fill(0).map(
|
|
611
|
+
new Array(this.dataFrame.columnCount()).fill(0).map((_, i) => i);
|
|
651
612
|
return TableStyler.withColumnStyles(this, indexes, columnStyle, priority);
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
if (priority === void 0) { priority = 0; }
|
|
613
|
+
}
|
|
614
|
+
static withColumnStyles(tableStyler, columnIndexes, columnStyle, priority = 0) {
|
|
655
615
|
if (columnIndexes.length > 0) {
|
|
656
|
-
|
|
616
|
+
const columnIndex = columnIndexes.shift();
|
|
657
617
|
if (columnIndex != null) {
|
|
658
|
-
|
|
618
|
+
const styler = tableStyler.withColumnStyle(columnIndex, columnStyle, priority);
|
|
659
619
|
return TableStyler.withColumnStyles(styler, columnIndexes, columnStyle, priority);
|
|
660
620
|
}
|
|
661
621
|
}
|
|
662
622
|
return tableStyler;
|
|
663
|
-
}
|
|
623
|
+
}
|
|
664
624
|
/**
|
|
665
625
|
* Sets the style for a specific cell.
|
|
666
626
|
* @param rowIndex The row index of the cell to style
|
|
@@ -670,25 +630,23 @@ var TableStyler = /** @class */ (function () {
|
|
|
670
630
|
* @param priority The priority of this style (higher values take precedence)
|
|
671
631
|
* @returns A new TableStyler instance with the cell style applied
|
|
672
632
|
*/
|
|
673
|
-
|
|
674
|
-
var _this = this;
|
|
675
|
-
if (priority === void 0) { priority = 0; }
|
|
633
|
+
withCellStyle(rowIndex, columnIndex, cellStyle, priority = 0) {
|
|
676
634
|
if (rowIndex < 0 || rowIndex >= TableData_1.TableData.tableRowCount(this.dataFrame) ||
|
|
677
635
|
columnIndex < 0 || columnIndex >= TableData_1.TableData.tableColumnCount(this.dataFrame)) {
|
|
678
|
-
this.errors.push(
|
|
679
|
-
|
|
636
|
+
this.errors.push(`The (row, column) indices, when setting a cell-style, must be in ` +
|
|
637
|
+
`([0, ${TableData_1.TableData.tableRowCount(this.dataFrame)}), [0, ${TableData_1.TableData.tableColumnCount(this.dataFrame)}))`);
|
|
680
638
|
return this;
|
|
681
639
|
}
|
|
682
640
|
// tag the cell with the cell-style
|
|
683
641
|
return this.dataFrame
|
|
684
642
|
.tagCell(rowIndex, columnIndex, stylings_1.TableStyleType.CELL, (0, stylings_1.stylingFor)(cellStyle, stylings_1.defaultCellStyle, priority))
|
|
685
643
|
// when successfully tagged, make an updated copy of this builder with the new data-frame
|
|
686
|
-
.map(
|
|
644
|
+
.map(df => this.update({ dataFrame: df }))
|
|
687
645
|
// when failed to tag, add to the errors
|
|
688
|
-
.onFailure(
|
|
646
|
+
.onFailure(error => this.errors.push(error))
|
|
689
647
|
// when failed, return this (unmodified) builder
|
|
690
648
|
.getOrElse(this);
|
|
691
|
-
}
|
|
649
|
+
}
|
|
692
650
|
/**
|
|
693
651
|
* Sets the style for a specific cell based on a predicate.
|
|
694
652
|
* @param predicate A function that accepts the value, row-index, and column-index of the cell, and
|
|
@@ -699,26 +657,23 @@ var TableStyler = /** @class */ (function () {
|
|
|
699
657
|
* @see withCellStyle
|
|
700
658
|
* @see withCellStyles
|
|
701
659
|
*/
|
|
702
|
-
|
|
703
|
-
var _this = this;
|
|
704
|
-
if (priority === void 0) { priority = 0; }
|
|
660
|
+
withCellStyleWhen(predicate, cellStyle, priority = 0) {
|
|
705
661
|
return this.dataFrame
|
|
706
662
|
.tagCellWhen(predicate, stylings_1.TableStyleType.CELL, (0, stylings_1.stylingFor)(cellStyle, stylings_1.defaultCellStyle, priority))
|
|
707
663
|
// when successfully tagged, make an updated copy of this builder with the new data-frame
|
|
708
|
-
.map(
|
|
664
|
+
.map(df => this.update({ dataFrame: df }))
|
|
709
665
|
// when failed to tag, add to the errors
|
|
710
|
-
.onFailure(
|
|
666
|
+
.onFailure(error => this.errors.push(error))
|
|
711
667
|
// when failed, return this (unmodified) builder
|
|
712
668
|
.getOrElse(this);
|
|
713
|
-
}
|
|
669
|
+
}
|
|
714
670
|
/**
|
|
715
671
|
* Finalizes the styling process and creates a StyledTable instance.
|
|
716
672
|
* @returns A StyledTable instance with all the applied styles
|
|
717
673
|
*/
|
|
718
|
-
|
|
674
|
+
styleTable() {
|
|
719
675
|
return new StyledTable(this.dataFrame, this.font, this.border, this.background, this.dimension, this.padding, this.margin);
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
}());
|
|
676
|
+
}
|
|
677
|
+
}
|
|
723
678
|
exports.TableStyler = TableStyler;
|
|
724
679
|
//# sourceMappingURL=TableStyler.js.map
|