svg-table 0.0.2 → 0.1.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 +9 -0
- package/README.md +447 -1
- package/TableFormatter.ts +286 -5
- package/TableStyler.ts +74 -5
- package/dist/TableFormatter.d.ts +280 -0
- package/dist/TableFormatter.d.ts.map +1 -1
- package/dist/TableFormatter.js +286 -5
- package/dist/TableFormatter.js.map +1 -1
- package/dist/TableStyler.d.ts +56 -1
- package/dist/TableStyler.d.ts.map +1 -1
- package/dist/TableStyler.js +61 -2
- package/dist/TableStyler.js.map +1 -1
- package/dist/tableFormatter.test.js +41 -2
- package/dist/tableFormatter.test.js.map +1 -1
- package/dist/tableStyler.test.js +222 -6
- package/dist/tableStyler.test.js.map +1 -1
- package/dist/tableSvg.js +4 -2
- package/dist/tableSvg.js.map +1 -1
- package/package.json +1 -1
- package/tableFormatter.test.ts +46 -2
- package/tableStyler.test.ts +130 -7
- package/tableSvg.ts +4 -2
package/dist/TableFormatter.js
CHANGED
|
@@ -92,6 +92,9 @@ var TableFormatter = /** @class */ (function () {
|
|
|
92
92
|
* @param formatter The formatter
|
|
93
93
|
* @param [priority = 0] The priority of this formatter. If cells have more than one associated formatter,
|
|
94
94
|
* the one with the highest priority number is used.
|
|
95
|
+
* @see addColumnFormatters
|
|
96
|
+
* @see addRowFormatter
|
|
97
|
+
* @see addRowFormatters
|
|
95
98
|
* @example
|
|
96
99
|
* ```typescript
|
|
97
100
|
* // create the data
|
|
@@ -135,14 +138,68 @@ var TableFormatter = /** @class */ (function () {
|
|
|
135
138
|
.tagColumn(columnIndex, TableFormatterType.COLUMN, { formatter: formatter, priority: priority })
|
|
136
139
|
.map(function (data) { return new TableFormatter(data); });
|
|
137
140
|
};
|
|
141
|
+
/**
|
|
142
|
+
* Adds formatters to specified column indexes in a table formatter.
|
|
143
|
+
*
|
|
144
|
+
* @param columnIndexes An array of column indexes to which the formatter will be applied.
|
|
145
|
+
* @param formatter The formatting function to apply to the specified columns.
|
|
146
|
+
* @param [priority = 0] The priority level for the formatter. Higher priority formatters are applied first.
|
|
147
|
+
* @return A result indicating the success or failure of adding the column formatters.
|
|
148
|
+
* @see addColumnFormatter
|
|
149
|
+
* @see addRowFormatter
|
|
150
|
+
* @see addRowFormatters
|
|
151
|
+
* @see addCellFormatter
|
|
152
|
+
* @see addCellFormatters
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* const data = DataFrame.from<string | number | Date>([
|
|
157
|
+
* [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
|
|
158
|
+
* [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
|
|
159
|
+
* [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
|
|
160
|
+
* [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
|
|
161
|
+
* ]).getOrThrow()
|
|
162
|
+
* const columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount']
|
|
163
|
+
* const rowHeader = [1, 2, 3, 4]
|
|
164
|
+
*
|
|
165
|
+
* const tableData = TableData.fromDataFrame<string | number | Date>(data)
|
|
166
|
+
* .withColumnHeader(columnHeader)
|
|
167
|
+
* .flatMap(td => td.withRowHeader(rowHeader))
|
|
168
|
+
* .flatMap(tableData => TableFormatter.fromTableData(tableData)
|
|
169
|
+
* // add the default formatter for the column header, at the highest priority so that
|
|
170
|
+
* // it is the one that applies to the row representing the column header
|
|
171
|
+
* .addRowFormatters([0], defaultFormatter, Infinity)
|
|
172
|
+
* // add the default formatter for the row header, at the highest priority so that
|
|
173
|
+
* // it is the one that applies to the column representing the row header
|
|
174
|
+
* .flatMap(tf => tf.addColumnFormatters([0], defaultFormatter, Infinity))
|
|
175
|
+
* // add the column formatters for each column at the default (lowest) priority
|
|
176
|
+
* // (notice that the columns are shifted by one for the columns because the row-header
|
|
177
|
+
* // occupies the first column (index=0))
|
|
178
|
+
* .flatMap(tf => tf.addColumnFormatter(1, value => (value as Date).toLocaleDateString()))
|
|
179
|
+
* .flatMap(tf => tf.addColumnFormatter(2, value => defaultFormatter(value)))
|
|
180
|
+
* .flatMap(tf => tf.addColumnFormatter(4, value => `$ ${(value as number).toFixed(2)}`))
|
|
181
|
+
* .flatMap(tf => tf.addColumnFormatter(5, value => `${(value as number).toFixed(0)}`))
|
|
182
|
+
* // format the table data and get back a TableData<string>
|
|
183
|
+
* .flatMap(tf => tf.formatTable())
|
|
184
|
+
* )
|
|
185
|
+
* .getOrThrow()
|
|
186
|
+
*
|
|
187
|
+
* const expectedData = DataFrame.from<string>([
|
|
188
|
+
* ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
|
|
189
|
+
* ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
|
|
190
|
+
* ['2/3/2021', '34567', 'gnm-h234', '$ 3.65', '40'],
|
|
191
|
+
* ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
|
|
192
|
+
* ]).getOrThrow()
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
138
195
|
TableFormatter.prototype.addColumnFormatters = function (columnIndexes, formatter, priority) {
|
|
139
196
|
if (priority === void 0) { priority = 0; }
|
|
140
|
-
return TableFormatter.addColumnFormatters(this, columnIndexes, formatter, priority);
|
|
197
|
+
return TableFormatter.addColumnFormatters(this, columnIndexes.slice(), formatter, priority);
|
|
141
198
|
};
|
|
142
199
|
TableFormatter.addColumnFormatters = function (tableFormatter, columnIndexes, formatter, priority) {
|
|
143
200
|
if (priority === void 0) { priority = 0; }
|
|
144
201
|
if (columnIndexes.length > 0) {
|
|
145
|
-
var columnIndex = columnIndexes.
|
|
202
|
+
var columnIndex = columnIndexes.shift();
|
|
146
203
|
if (columnIndex != null) {
|
|
147
204
|
return tableFormatter
|
|
148
205
|
.addColumnFormatter(columnIndex, formatter, priority)
|
|
@@ -151,12 +208,114 @@ var TableFormatter = /** @class */ (function () {
|
|
|
151
208
|
}
|
|
152
209
|
return (0, result_fn_1.successResult)(tableFormatter);
|
|
153
210
|
};
|
|
211
|
+
/**
|
|
212
|
+
* Formatters convert the row value types to formatted strings. The formatter used to format each cell in
|
|
213
|
+
* a given row depends on the priority of each formatter associated with that cell. The formatter with the
|
|
214
|
+
* highest priority is used. If two or more formatters for a given cell have the same priority, the selected
|
|
215
|
+
* formatter is indeterminant.
|
|
216
|
+
* @param rowIndex The index of the row to which to add the formatter
|
|
217
|
+
* @param formatter The formatter
|
|
218
|
+
* @param [priority = 0] The priority of this formatter. If cells have more than one associated formatter,
|
|
219
|
+
* the one with the highest priority number is used.
|
|
220
|
+
* @see addColumnFormatter
|
|
221
|
+
* @see addColumnFormatters
|
|
222
|
+
* @see addRowFormatters
|
|
223
|
+
* @example
|
|
224
|
+
* ```typescript
|
|
225
|
+
* // create the data
|
|
226
|
+
* const data = DataFrame.from<string | number | Date>([
|
|
227
|
+
* [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
|
|
228
|
+
* [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
|
|
229
|
+
* [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
|
|
230
|
+
* [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
|
|
231
|
+
* ]).getOrThrow()
|
|
232
|
+
*
|
|
233
|
+
* // create the table-data object from the data, and then hand the table-data
|
|
234
|
+
* // to the table formatter, add column formats, and format the table, getting
|
|
235
|
+
* // back a new TableData<string>
|
|
236
|
+
* const tableData: TableData<string> = TableData.fromDataFrame<string | number | Date>(data)
|
|
237
|
+
* // from the table-data, create a table-formatter
|
|
238
|
+
* .flatMap(tableData => createTableFormatterFrom(tableData)
|
|
239
|
+
* // add a column formatter for the first column of dates
|
|
240
|
+
* .addColumnFormatter(0, value => (value as Date).toLocaleDateString())
|
|
241
|
+
* // add a column formatter to the second column of number
|
|
242
|
+
* .flatMap(tf => tf.addColumnFormatter(1, value => defaultFormatter(value)))
|
|
243
|
+
* // add a column formatter to the fourth column of currencies
|
|
244
|
+
* .flatMap(tf => tf.addColumnFormatter(3, value => `$ ${(value as number).toFixed(2)}`))
|
|
245
|
+
* .flatMap(tf => tf.addColumnFormatter(4, value => `${(value as number).toFixed(0)}`))
|
|
246
|
+
* // format the table into a new TableData<string> object
|
|
247
|
+
* .flatMap(tf => tf.formatTable())
|
|
248
|
+
* )
|
|
249
|
+
* .getOrThrow()
|
|
250
|
+
*
|
|
251
|
+
* // we expect the data-frame in the table data to be the following
|
|
252
|
+
* const expectedData = DataFrame.from<string>([
|
|
253
|
+
* ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
|
|
254
|
+
* ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
|
|
255
|
+
* ['2/3/2021', '34567', 'GNM-H234', '$ 3.65', '40'],
|
|
256
|
+
* ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
|
|
257
|
+
* ]).getOrThrow()
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
154
260
|
TableFormatter.prototype.addRowFormatter = function (rowIndex, formatter, priority) {
|
|
155
261
|
if (priority === void 0) { priority = 0; }
|
|
156
262
|
return this.dataFrame
|
|
157
263
|
.tagRow(rowIndex, TableFormatterType.ROW, { formatter: formatter, priority: priority })
|
|
158
264
|
.map(function (data) { return new TableFormatter(data); });
|
|
159
265
|
};
|
|
266
|
+
/**
|
|
267
|
+
* Adds formatters to specified row indexes in a table formatter.
|
|
268
|
+
*
|
|
269
|
+
* @param rowIndexes An array of row indexes to which the formatter will be applied.
|
|
270
|
+
* @param formatter The formatting function to apply to the specified columns.
|
|
271
|
+
* @param [priority = 0] The priority level for the formatter. Higher priority formatters are applied first.
|
|
272
|
+
* @return A result indicating the success or failure of adding the row formatters.
|
|
273
|
+
* @see addColumnFormatter
|
|
274
|
+
* @see addRowFormatter
|
|
275
|
+
* @see addRowFormatters
|
|
276
|
+
* @see addCellFormatter
|
|
277
|
+
* @see addCellFormatters
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* const data = DataFrame.from<string | number | Date>([
|
|
281
|
+
* [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
|
|
282
|
+
* [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
|
|
283
|
+
* [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
|
|
284
|
+
* [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
|
|
285
|
+
* ]).getOrThrow()
|
|
286
|
+
* const columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount']
|
|
287
|
+
* const rowHeader = [1, 2, 3, 4]
|
|
288
|
+
*
|
|
289
|
+
* const tableData = TableData.fromDataFrame<string | number | Date>(data)
|
|
290
|
+
* .withColumnHeader(columnHeader)
|
|
291
|
+
* .flatMap(td => td.withRowHeader(rowHeader))
|
|
292
|
+
* .flatMap(tableData => TableFormatter.fromTableData(tableData)
|
|
293
|
+
* // add the default formatter for the column header, at the highest priority so that
|
|
294
|
+
* // it is the one that applies to the row representing the column header
|
|
295
|
+
* .addRowFormatters([0], defaultFormatter, Infinity)
|
|
296
|
+
* // add the default formatter for the row header, at the highest priority so that
|
|
297
|
+
* // it is the one that applies to the column representing the row header
|
|
298
|
+
* .flatMap(tf => tf.addColumnFormatters([0], defaultFormatter, Infinity))
|
|
299
|
+
* // add the column formatters for each column at the default (lowest) priority
|
|
300
|
+
* // (notice that the columns are shifted by one for the columns because the row-header
|
|
301
|
+
* // occupies the first column (index=0))
|
|
302
|
+
* .flatMap(tf => tf.addColumnFormatter(1, value => (value as Date).toLocaleDateString()))
|
|
303
|
+
* .flatMap(tf => tf.addColumnFormatter(2, value => defaultFormatter(value)))
|
|
304
|
+
* .flatMap(tf => tf.addColumnFormatter(4, value => `$ ${(value as number).toFixed(2)}`))
|
|
305
|
+
* .flatMap(tf => tf.addColumnFormatter(5, value => `${(value as number).toFixed(0)}`))
|
|
306
|
+
* // format the table data and get back a TableData<string>
|
|
307
|
+
* .flatMap(tf => tf.formatTable())
|
|
308
|
+
* )
|
|
309
|
+
* .getOrThrow()
|
|
310
|
+
*
|
|
311
|
+
* const expectedData = DataFrame.from<string>([
|
|
312
|
+
* ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
|
|
313
|
+
* ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
|
|
314
|
+
* ['2/3/2021', '34567', 'gnm-h234', '$ 3.65', '40'],
|
|
315
|
+
* ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
|
|
316
|
+
* ]).getOrThrow()
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
160
319
|
TableFormatter.prototype.addRowFormatters = function (rowIndexes, formatter, priority) {
|
|
161
320
|
if (priority === void 0) { priority = 0; }
|
|
162
321
|
return TableFormatter.addRowFormatters(this, rowIndexes.slice(), formatter, priority);
|
|
@@ -173,21 +332,132 @@ var TableFormatter = /** @class */ (function () {
|
|
|
173
332
|
}
|
|
174
333
|
return (0, result_fn_1.successResult)(tableFormatter);
|
|
175
334
|
};
|
|
335
|
+
/**
|
|
336
|
+
* Adds a formatter to a specified cell based on the row and column indexes.
|
|
337
|
+
* @param rowIndex The row index of the cell.
|
|
338
|
+
* @param columnIndex The column index of the cell.
|
|
339
|
+
* @param formatter The formatter to apply to the cell.
|
|
340
|
+
* @param [priority = 0] The priority level for the formatter. Higher priority formatters are applied first.
|
|
341
|
+
* @return A result indicating the success or failure of adding the cell formatter.
|
|
342
|
+
* @see addColumnFormatter
|
|
343
|
+
* @see addRowFormatter
|
|
344
|
+
* @see addRowFormatters
|
|
345
|
+
* @see addCellFormatters
|
|
346
|
+
* @see addCellFormatters
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* const data = DataFrame.from<string | number | Date>([
|
|
350
|
+
* [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
|
|
351
|
+
* [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
|
|
352
|
+
* [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
|
|
353
|
+
* [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
|
|
354
|
+
* ]).getOrThrow()
|
|
355
|
+
* const columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount']
|
|
356
|
+
* const rowHeader = [1, 2, 3, 4]
|
|
357
|
+
*
|
|
358
|
+
* const tableData = TableData.fromDataFrame<string | number | Date>(data)
|
|
359
|
+
* .withColumnHeader(columnHeader)
|
|
360
|
+
* .flatMap(td => td.withRowHeader(rowHeader))
|
|
361
|
+
* .flatMap(tableData => TableFormatter.fromTableData(tableData)
|
|
362
|
+
* // add the default formatter for the column header, at the highest priority so that
|
|
363
|
+
* // it is the one that applies to the row representing the column header
|
|
364
|
+
* .addRowFormatters([0], defaultFormatter, Infinity)
|
|
365
|
+
* // add the default formatter for the row header, at the highest priority so that
|
|
366
|
+
* // it is the one that applies to the column representing the row header
|
|
367
|
+
* .flatMap(tf => tf.addColumnFormatters([0], defaultFormatter, Infinity))
|
|
368
|
+
* // add the column formatters for each column at the default (lowest) priority
|
|
369
|
+
* // (notice that the columns are shifted by one for the columns because the row-header
|
|
370
|
+
* // occupies the first column (index=0))
|
|
371
|
+
* .flatMap(tf => tf.addColumnFormatter(1, value => (value as Date).toLocaleDateString()))
|
|
372
|
+
* .flatMap(tf => tf.addColumnFormatter(2, value => defaultFormatter(value)))
|
|
373
|
+
* .flatMap(tf => tf.addColumnFormatter(4, value => `$ ${(value as number).toFixed(2)}`))
|
|
374
|
+
* .flatMap(tf => tf.addColumnFormatter(5, value => `${(value as number).toFixed(0)}`))
|
|
375
|
+
* // override the cell formatter for a select set of cells
|
|
376
|
+
* .flatMap(tf => tf.addCellFormatter(1, 4, value => `${(value as number).toFixed(2)}`, 1000))
|
|
377
|
+
* .flatMap(tf => tf.addCellFormatters([[3, 5], [4, 5]], value => `${((value as number) * 10).toFixed(0)}`, 1000))
|
|
378
|
+
* // format the table data and get back a TableData<string>
|
|
379
|
+
* .flatMap(tf => tf.formatTable())
|
|
380
|
+
* )
|
|
381
|
+
* .getOrThrow()
|
|
382
|
+
*
|
|
383
|
+
* const expectedData = DataFrame.from<string>([
|
|
384
|
+
* ['2/1/2021', '12345', 'gnm-f234', '123.45', '4'], // overwrite (1, 4) to remove "$"
|
|
385
|
+
* ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
|
|
386
|
+
* ['2/3/2021', '34567', 'gnm-h234', '$ 3.65', '400'], // overwrite (3, 5) to multiply by 10
|
|
387
|
+
* ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '90'], // overwrite (4, 5) to multiply by 10
|
|
388
|
+
* ]).getOrThrow()
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
176
391
|
TableFormatter.prototype.addCellFormatter = function (rowIndex, columnIndex, formatter, priority) {
|
|
177
392
|
if (priority === void 0) { priority = 0; }
|
|
178
393
|
return this.dataFrame
|
|
179
394
|
.tagCell(rowIndex, columnIndex, TableFormatterType.CELL, { formatter: formatter, priority: priority })
|
|
180
395
|
.map(function (data) { return new TableFormatter(data); });
|
|
181
396
|
};
|
|
397
|
+
/**
|
|
398
|
+
* Adds formatters to specified cell indexes in a table formatter.
|
|
399
|
+
* @param cellIndexes An array of cell indexes to which the formatter will be applied.
|
|
400
|
+
* @param formatter The formatting function to apply to the specified cells.
|
|
401
|
+
* @param [priority = 0] The priority level for the formatter. Higher priority formatters are applied first.
|
|
402
|
+
* @return A result indicating the success or failure of adding the cell formatters.
|
|
403
|
+
* @see addColumnFormatter
|
|
404
|
+
* @see addRowFormatter
|
|
405
|
+
* @see addRowFormatters
|
|
406
|
+
* @see addCellFormatters
|
|
407
|
+
* @see addCellFormatters
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const data = DataFrame.from<string | number | Date>([
|
|
411
|
+
* [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
|
|
412
|
+
* [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
|
|
413
|
+
* [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
|
|
414
|
+
* [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
|
|
415
|
+
* ]).getOrThrow()
|
|
416
|
+
* const columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount']
|
|
417
|
+
* const rowHeader = [1, 2, 3, 4]
|
|
418
|
+
*
|
|
419
|
+
* const tableData = TableData.fromDataFrame<string | number | Date>(data)
|
|
420
|
+
* .withColumnHeader(columnHeader)
|
|
421
|
+
* .flatMap(td => td.withRowHeader(rowHeader))
|
|
422
|
+
* .flatMap(tableData => TableFormatter.fromTableData(tableData)
|
|
423
|
+
* // add the default formatter for the column header, at the highest priority so that
|
|
424
|
+
* // it is the one that applies to the row representing the column header
|
|
425
|
+
* .addRowFormatters([0], defaultFormatter, Infinity)
|
|
426
|
+
* // add the default formatter for the row header, at the highest priority so that
|
|
427
|
+
* // it is the one that applies to the column representing the row header
|
|
428
|
+
* .flatMap(tf => tf.addColumnFormatters([0], defaultFormatter, Infinity))
|
|
429
|
+
* // add the column formatters for each column at the default (lowest) priority
|
|
430
|
+
* // (notice that the columns are shifted by one for the columns because the row-header
|
|
431
|
+
* // occupies the first column (index=0))
|
|
432
|
+
* .flatMap(tf => tf.addColumnFormatter(1, value => (value as Date).toLocaleDateString()))
|
|
433
|
+
* .flatMap(tf => tf.addColumnFormatter(2, value => defaultFormatter(value)))
|
|
434
|
+
* .flatMap(tf => tf.addColumnFormatter(4, value => `$ ${(value as number).toFixed(2)}`))
|
|
435
|
+
* .flatMap(tf => tf.addColumnFormatter(5, value => `${(value as number).toFixed(0)}`))
|
|
436
|
+
* // override the cell formatter for a select set of cells
|
|
437
|
+
* .flatMap(tf => tf.addCellFormatter(1, 4, value => `${(value as number).toFixed(2)}`, 1000))
|
|
438
|
+
* .flatMap(tf => tf.addCellFormatters([[3, 5], [4, 5]], value => `${((value as number) * 10).toFixed(0)}`, 1000))
|
|
439
|
+
* // format the table data and get back a TableData<string>
|
|
440
|
+
* .flatMap(tf => tf.formatTable())
|
|
441
|
+
* )
|
|
442
|
+
* .getOrThrow()
|
|
443
|
+
*
|
|
444
|
+
* const expectedData = DataFrame.from<string>([
|
|
445
|
+
* ['2/1/2021', '12345', 'gnm-f234', '123.45', '4'], // overwrite (1, 4) to remove "$"
|
|
446
|
+
* ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
|
|
447
|
+
* ['2/3/2021', '34567', 'gnm-h234', '$ 3.65', '400'], // overwrite (3, 5) to multiply by 10
|
|
448
|
+
* ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '90'], // overwrite (4, 5) to multiply by 10
|
|
449
|
+
* ]).getOrThrow()
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
182
452
|
TableFormatter.prototype.addCellFormatters = function (cellIndexes, formatter, priority) {
|
|
183
453
|
if (priority === void 0) { priority = 0; }
|
|
184
|
-
return TableFormatter.addCellFormatters(this, cellIndexes, formatter, priority);
|
|
454
|
+
return TableFormatter.addCellFormatters(this, cellIndexes.slice(), formatter, priority);
|
|
185
455
|
};
|
|
186
456
|
TableFormatter.addCellFormatters = function (tableFormatter, cellIndexes, formatter, priority) {
|
|
187
457
|
var _a;
|
|
188
458
|
if (priority === void 0) { priority = 0; }
|
|
189
459
|
if (cellIndexes.length > 0) {
|
|
190
|
-
var _b = __read((_a = cellIndexes.
|
|
460
|
+
var _b = __read((_a = cellIndexes.shift()) !== null && _a !== void 0 ? _a : [undefined, undefined], 2), rowIndex = _b[0], columnIndex = _b[1];
|
|
191
461
|
if (rowIndex != null && columnIndex != null) {
|
|
192
462
|
return tableFormatter
|
|
193
463
|
.addCellFormatter(rowIndex, columnIndex, formatter, priority)
|
|
@@ -266,10 +536,21 @@ var TableFormatter = /** @class */ (function () {
|
|
|
266
536
|
TableFormatter.prototype.formatTable = function () {
|
|
267
537
|
return this.formatTableInto(function (dataFrame) { return TableData_1.TableData.fromDataFrame(dataFrame); });
|
|
268
538
|
};
|
|
539
|
+
/**
|
|
540
|
+
* Generally, the {@link TableFormatter} formats the {@link DataFrame} into a `TableData<string>`
|
|
541
|
+
* where all the elements of the {@link TableData} are a string. Because a formatted table does
|
|
542
|
+
* not necessarily have to be a `TableData<string>` (which would contain a `DataFrame<string>`,
|
|
543
|
+
* this method allows mapping a {@link DataFrame} into any desired type.
|
|
544
|
+
* @param mapper A function that takes a `DataFrame<string>` and returns a desired type (`D`).
|
|
545
|
+
* @return A `Result<D, string>` where the `Result<D, string>` is either success, containing the
|
|
546
|
+
* desired type (`D`), or failure, containing an error message.
|
|
547
|
+
* @see formatTable
|
|
548
|
+
*/
|
|
269
549
|
TableFormatter.prototype.formatTableInto = function (mapper) {
|
|
270
550
|
var _this = this;
|
|
271
551
|
var formattingFailures = [];
|
|
272
|
-
var formattedDataFrame = this
|
|
552
|
+
var formattedDataFrame = this
|
|
553
|
+
.dataFrame
|
|
273
554
|
.mapElements(function (elem, row, col) {
|
|
274
555
|
var tags = _this.dataFrame
|
|
275
556
|
.tagsFor(row, col)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableFormatter.js","sourceRoot":"","sources":["../TableFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAcA,4CAEC;AAOD,8CAKC;AAQD,0CAMC;AAzCD,uCAAoE;AACpE,yCAAsC;AAOtC;;;;GAIG;AACH,SAAgB,gBAAgB,CAAI,KAAQ;IACxC,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAG,KAAK,CAAE,CAAA;AAClE,CAAC;AAOD,SAAgB,iBAAiB;IAC7B,OAAO;QACH,SAAS,EAAE,CAAA,gBAAmB,CAAA;QAC9B,QAAQ,EA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,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,OAAO,IAAA,yBAAa,EAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAA;QACpD,CAAC;QACD,OAAO,IAAA,yBAAa,EAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IAClE,CAAC;IACL,qBAAC;AAAD,CAAC,AAzhBD,IAyhBC;AAzhBY,wCAAc"}
|
package/dist/TableStyler.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TableData } from "./TableData";
|
|
2
2
|
import { DataFrame } from "data-frame-ts";
|
|
3
3
|
import { type Result } from "result-fn";
|
|
4
|
-
import { type Background, type Border, type CellStyle, type ColumnHeaderStyle, type ColumnStyle, type Dimension, type FooterStyle, type Padding, type RowHeaderStyle, type RowStyle, type Styling, type TableFont, type TableStylerProps
|
|
4
|
+
import { type Background, type Border, type CellStyle, type ColumnHeaderStyle, type ColumnStyle, type Dimension, type FooterStyle, Margin, type Padding, type RowHeaderStyle, type RowStyle, type Styling, type TableFont, type TableStylerProps } from "./stylings";
|
|
5
5
|
/**
|
|
6
6
|
* Represents a table with applied styles.
|
|
7
7
|
* Provides methods to access the styling information for different parts of the table.
|
|
@@ -76,8 +76,20 @@ export declare class StyledTable<V> {
|
|
|
76
76
|
* @private
|
|
77
77
|
*/
|
|
78
78
|
private rowTagsFor;
|
|
79
|
+
/**
|
|
80
|
+
* Checks if the table has a row header.
|
|
81
|
+
* @returns `true` if the table has a row header, `false` otherwise
|
|
82
|
+
*/
|
|
79
83
|
hasRowHeader(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Checks if the table has a column header.
|
|
86
|
+
* @returns `true` if the table has a row header, `false` otherwise
|
|
87
|
+
*/
|
|
80
88
|
hasColumnHeader(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if the table has a footer header.
|
|
91
|
+
* @returns `true` if the table has a row header, `false` otherwise
|
|
92
|
+
*/
|
|
81
93
|
hasFooter(): boolean;
|
|
82
94
|
/**
|
|
83
95
|
* Gets the style for the row header.
|
|
@@ -89,6 +101,10 @@ export declare class StyledTable<V> {
|
|
|
89
101
|
* @returns A Result containing the column header style if found, or an error message
|
|
90
102
|
*/
|
|
91
103
|
columnHeaderStyle(): Result<Styling<ColumnHeaderStyle>, string>;
|
|
104
|
+
/**
|
|
105
|
+
* Gets the style for the footer.
|
|
106
|
+
* @returns A Result containing the footer style if found, or an error message
|
|
107
|
+
*/
|
|
92
108
|
footerStyle(): Result<Styling<FooterStyle>, string>;
|
|
93
109
|
/**
|
|
94
110
|
* Gets the style for a specific row.
|
|
@@ -194,6 +210,14 @@ export declare class TableStyler<V> {
|
|
|
194
210
|
* @returns A new TableStyler instance with updated properties
|
|
195
211
|
*/
|
|
196
212
|
update(properties: Partial<TableStylerProps<V>>): TableStyler<V>;
|
|
213
|
+
/**
|
|
214
|
+
* Applies the specified font settings for the table and returns a new {@link TableStyler}
|
|
215
|
+
* instance with the updated font configuration.
|
|
216
|
+
*
|
|
217
|
+
* @param font - The font configuration to be applied. This object can include partial
|
|
218
|
+
* properties of the TableFont.
|
|
219
|
+
* @return A new {@link TableStyler} instance with the updated font settings.
|
|
220
|
+
*/
|
|
197
221
|
withTableFont(font: Partial<TableFont>): TableStyler<V>;
|
|
198
222
|
/**
|
|
199
223
|
* Sets the background for the table.
|
|
@@ -277,6 +301,17 @@ export declare class TableStyler<V> {
|
|
|
277
301
|
* @returns A new TableStyler instance with the row style applied
|
|
278
302
|
*/
|
|
279
303
|
withRowStyle(rowIndex: number, rowStyle: Partial<RowStyle>, priority?: number): TableStyler<V>;
|
|
304
|
+
/**
|
|
305
|
+
* Applies specific styles to rows in a table based on the provided row indexes.
|
|
306
|
+
*
|
|
307
|
+
* @param rowIndexes - An array of row indexes to which the styles will be applied. If the
|
|
308
|
+
* array is empty, all rows will be styled.
|
|
309
|
+
* @param rowStyle - An object representing the styles to apply to the specified rows.
|
|
310
|
+
* @param [priority=0] - An optional priority value for the styles. Higher priority values
|
|
311
|
+
* override lower ones.
|
|
312
|
+
* @return A new TableStyler instance with the specified row styles applied.
|
|
313
|
+
* @see withRowStyle
|
|
314
|
+
*/
|
|
280
315
|
withRowStyles(rowIndexes: Array<number>, rowStyle: Partial<RowStyle>, priority?: number): TableStyler<V>;
|
|
281
316
|
private static withRowStyles;
|
|
282
317
|
/**
|
|
@@ -288,6 +323,16 @@ export declare class TableStyler<V> {
|
|
|
288
323
|
* @returns A new TableStyler instance with the column style applied
|
|
289
324
|
*/
|
|
290
325
|
withColumnStyle(columnIndex: number, columnStyle: Partial<ColumnStyle>, priority?: number): TableStyler<V>;
|
|
326
|
+
/**
|
|
327
|
+
* Applies specified styles to the columns of a table.
|
|
328
|
+
*
|
|
329
|
+
* @param columnIndexes - Array of column indexes to which the style should be applied. If the array
|
|
330
|
+
* is empty, styles will be applied to all columns.
|
|
331
|
+
* @param columnStyle - Partial column style configuration object defining the styles to be applied.
|
|
332
|
+
* @param [priority=0] - Optional priority value to determine the precedence of this style over others.
|
|
333
|
+
* @return Returns an instance of TableStyler with the updated column styles applied.
|
|
334
|
+
* @see withColumnStyle
|
|
335
|
+
*/
|
|
291
336
|
withColumnStyles(columnIndexes: Array<number>, columnStyle: Partial<ColumnStyle>, priority?: number): TableStyler<V>;
|
|
292
337
|
private static withColumnStyles;
|
|
293
338
|
/**
|
|
@@ -300,6 +345,16 @@ export declare class TableStyler<V> {
|
|
|
300
345
|
* @returns A new TableStyler instance with the cell style applied
|
|
301
346
|
*/
|
|
302
347
|
withCellStyle(rowIndex: number, columnIndex: number, cellStyle: Partial<CellStyle>, priority?: number): TableStyler<V>;
|
|
348
|
+
/**
|
|
349
|
+
* Sets the style for a specific cell based on a predicate.
|
|
350
|
+
* @param predicate A function that accepts the value, row-index, and column-index of the cell, and
|
|
351
|
+
* returns `true` if the cell should be styled, or `false` otherwise.
|
|
352
|
+
* @param cellStyle The style to apply to the cell if the predicate is `true`.
|
|
353
|
+
* @param priority The style's priority. Higher priority values override lower ones.
|
|
354
|
+
* @returns A new TableStyler instance with the cell style applied.
|
|
355
|
+
* @see withCellStyle
|
|
356
|
+
* @see withCellStyles
|
|
357
|
+
*/
|
|
303
358
|
withCellStyleWhen(predicate: (value: V, rowIndex: number, columnIndex: number) => boolean, cellStyle: Partial<CellStyle>, priority?: number): TableStyler<V>;
|
|
304
359
|
/**
|
|
305
360
|
* Finalizes the styling process and creates a StyledTable instance.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableStyler.d.ts","sourceRoot":"","sources":["../TableStyler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAmC,SAAS,EAAyC,MAAM,eAAe,CAAC;AAClH,OAAO,EAAgB,KAAK,MAAM,EAAgB,MAAM,WAAW,CAAC;AACpE,OAAO,EACH,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,
|
|
1
|
+
{"version":3,"file":"TableStyler.d.ts","sourceRoot":"","sources":["../TableStyler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAmC,SAAS,EAAyC,MAAM,eAAe,CAAC;AAClH,OAAO,EAAgB,KAAK,MAAM,EAAgB,MAAM,WAAW,CAAC;AACpE,OAAO,EACH,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAahB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,MAAM,EACN,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,OAAO,EAGZ,KAAK,SAAS,EACd,KAAK,gBAAgB,EAExB,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,qBAAa,WAAW,CAAC,CAAC;IAalB,OAAO,C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AC,CAAC,CAAC;IAWjB;;;OAGG;IACH,UAAU,IAAI,WAAW,CAAC,CAAC,CAAC;CAc/B"}
|
package/dist/TableStyler.js
CHANGED
|
@@ -142,12 +142,24 @@ var StyledTable = /** @class */ (function () {
|
|
|
142
142
|
}
|
|
143
143
|
return (0, result_fn_1.successResult)(tags[0]);
|
|
144
144
|
};
|
|
145
|
+
/**
|
|
146
|
+
* Checks if the table has a row header.
|
|
147
|
+
* @returns `true` if the table has a row header, `false` otherwise
|
|
148
|
+
*/
|
|
145
149
|
StyledTable.prototype.hasRowHeader = function () {
|
|
146
150
|
return TableData_1.TableData.hasRowHeader(this.dataFrame);
|
|
147
151
|
};
|
|
152
|
+
/**
|
|
153
|
+
* Checks if the table has a column header.
|
|
154
|
+
* @returns `true` if the table has a row header, `false` otherwise
|
|
155
|
+
*/
|
|
148
156
|
StyledTable.prototype.hasColumnHeader = function () {
|
|
149
157
|
return TableData_1.TableData.hasColumnHeader(this.dataFrame);
|
|
150
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* Checks if the table has a footer header.
|
|
161
|
+
* @returns `true` if the table has a row header, `false` otherwise
|
|
162
|
+
*/
|
|
151
163
|
StyledTable.prototype.hasFooter = function () {
|
|
152
164
|
return TableData_1.TableData.hasFooter(this.dataFrame);
|
|
153
165
|
};
|
|
@@ -175,6 +187,10 @@ var StyledTable = /** @class */ (function () {
|
|
|
175
187
|
.rowTagsFor(0, stylings_1.TableStyleType.COLUMN_HEADER)
|
|
176
188
|
.map(function (tag) { return tag.value; });
|
|
177
189
|
};
|
|
190
|
+
/**
|
|
191
|
+
* Gets the style for the footer.
|
|
192
|
+
* @returns A Result containing the footer style if found, or an error message
|
|
193
|
+
*/
|
|
178
194
|
StyledTable.prototype.footerStyle = function () {
|
|
179
195
|
if (!TableData_1.TableData.hasFooter(this.dataFrame)) {
|
|
180
196
|
return (0, result_fn_1.failureResult)("(StyledTable::footerStyle) The table data does not have a footer");
|
|
@@ -398,6 +414,14 @@ var TableStyler = /** @class */ (function () {
|
|
|
398
414
|
var _a = properties.dataFrame, dataFrame = _a === void 0 ? this.dataFrame : _a, _b = properties.font, font = _b === void 0 ? this.font : _b, _c = properties.border, border = _c === void 0 ? this.border : _c, _d = properties.background, background = _d === void 0 ? this.background : _d, _e = properties.dimension, dimension = _e === void 0 ? this.dimension : _e, _f = properties.padding, padding = _f === void 0 ? this.padding : _f, _g = properties.margin, margin = _g === void 0 ? this.margin : _g;
|
|
399
415
|
return new TableStyler(dataFrame, font, border, background, dimension, padding, margin, this.errors);
|
|
400
416
|
};
|
|
417
|
+
/**
|
|
418
|
+
* Applies the specified font settings for the table and returns a new {@link TableStyler}
|
|
419
|
+
* instance with the updated font configuration.
|
|
420
|
+
*
|
|
421
|
+
* @param font - The font configuration to be applied. This object can include partial
|
|
422
|
+
* properties of the TableFont.
|
|
423
|
+
* @return A new {@link TableStyler} instance with the updated font settings.
|
|
424
|
+
*/
|
|
401
425
|
TableStyler.prototype.withTableFont = function (font) {
|
|
402
426
|
var builder = this.copy();
|
|
403
427
|
builder.font = __assign(__assign({}, stylings_1.defaultTableFont), font);
|
|
@@ -561,9 +585,22 @@ var TableStyler = /** @class */ (function () {
|
|
|
561
585
|
.tagRow(rowIndex, stylings_1.TableStyleType.ROW, (0, stylings_1.stylingFor)(rowStyle, stylings_1.defaultRowStyle, priority))
|
|
562
586
|
.getOrElse(this);
|
|
563
587
|
};
|
|
588
|
+
/**
|
|
589
|
+
* Applies specific styles to rows in a table based on the provided row indexes.
|
|
590
|
+
*
|
|
591
|
+
* @param rowIndexes - An array of row indexes to which the styles will be applied. If the
|
|
592
|
+
* array is empty, all rows will be styled.
|
|
593
|
+
* @param rowStyle - An object representing the styles to apply to the specified rows.
|
|
594
|
+
* @param [priority=0] - An optional priority value for the styles. Higher priority values
|
|
595
|
+
* override lower ones.
|
|
596
|
+
* @return A new TableStyler instance with the specified row styles applied.
|
|
597
|
+
* @see withRowStyle
|
|
598
|
+
*/
|
|
564
599
|
TableStyler.prototype.withRowStyles = function (rowIndexes, rowStyle, priority) {
|
|
565
600
|
if (priority === void 0) { priority = 0; }
|
|
566
|
-
var indexes = rowIndexes.length > 0 ?
|
|
601
|
+
var indexes = rowIndexes.length > 0 ?
|
|
602
|
+
rowIndexes :
|
|
603
|
+
new Array(this.dataFrame.rowCount()).fill(0).map(function (_, i) { return i; });
|
|
567
604
|
return TableStyler.withRowStyles(this, indexes, rowStyle, priority);
|
|
568
605
|
};
|
|
569
606
|
TableStyler.withRowStyles = function (tableStyler, rowIndexes, rowStyle, priority) {
|
|
@@ -596,9 +633,21 @@ var TableStyler = /** @class */ (function () {
|
|
|
596
633
|
.tagColumn(columnIndex, stylings_1.TableStyleType.COLUMN, (0, stylings_1.stylingFor)(columnStyle, stylings_1.defaultColumnStyle, priority))
|
|
597
634
|
.getOrElse(this);
|
|
598
635
|
};
|
|
636
|
+
/**
|
|
637
|
+
* Applies specified styles to the columns of a table.
|
|
638
|
+
*
|
|
639
|
+
* @param columnIndexes - Array of column indexes to which the style should be applied. If the array
|
|
640
|
+
* is empty, styles will be applied to all columns.
|
|
641
|
+
* @param columnStyle - Partial column style configuration object defining the styles to be applied.
|
|
642
|
+
* @param [priority=0] - Optional priority value to determine the precedence of this style over others.
|
|
643
|
+
* @return Returns an instance of TableStyler with the updated column styles applied.
|
|
644
|
+
* @see withColumnStyle
|
|
645
|
+
*/
|
|
599
646
|
TableStyler.prototype.withColumnStyles = function (columnIndexes, columnStyle, priority) {
|
|
600
647
|
if (priority === void 0) { priority = 0; }
|
|
601
|
-
var indexes = columnIndexes.length > 0 ?
|
|
648
|
+
var indexes = columnIndexes.length > 0 ?
|
|
649
|
+
columnIndexes :
|
|
650
|
+
new Array(this.dataFrame.columnCount()).fill(0).map(function (_, i) { return i; });
|
|
602
651
|
return TableStyler.withColumnStyles(this, indexes, columnStyle, priority);
|
|
603
652
|
};
|
|
604
653
|
TableStyler.withColumnStyles = function (tableStyler, columnIndexes, columnStyle, priority) {
|
|
@@ -640,6 +689,16 @@ var TableStyler = /** @class */ (function () {
|
|
|
640
689
|
// when failed, return this (unmodified) builder
|
|
641
690
|
.getOrElse(this);
|
|
642
691
|
};
|
|
692
|
+
/**
|
|
693
|
+
* Sets the style for a specific cell based on a predicate.
|
|
694
|
+
* @param predicate A function that accepts the value, row-index, and column-index of the cell, and
|
|
695
|
+
* returns `true` if the cell should be styled, or `false` otherwise.
|
|
696
|
+
* @param cellStyle The style to apply to the cell if the predicate is `true`.
|
|
697
|
+
* @param priority The style's priority. Higher priority values override lower ones.
|
|
698
|
+
* @returns A new TableStyler instance with the cell style applied.
|
|
699
|
+
* @see withCellStyle
|
|
700
|
+
* @see withCellStyles
|
|
701
|
+
*/
|
|
643
702
|
TableStyler.prototype.withCellStyleWhen = function (predicate, cellStyle, priority) {
|
|
644
703
|
var _this = this;
|
|
645
704
|
if (priority === void 0) { priority = 0; }
|