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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/d3types.ts +17 -0
  4. package/dist/d3types.d.ts +12 -0
  5. package/dist/d3types.d.ts.map +1 -0
  6. package/dist/d3types.js +3 -0
  7. package/dist/d3types.js.map +1 -0
  8. package/dist/index.d.ts +10 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +36 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/stylings.d.ts +206 -0
  13. package/dist/stylings.d.ts.map +1 -0
  14. package/dist/stylings.js +123 -0
  15. package/dist/stylings.js.map +1 -0
  16. package/dist/tableData.d.ts +168 -0
  17. package/dist/tableData.d.ts.map +1 -0
  18. package/dist/tableData.js +329 -0
  19. package/dist/tableData.js.map +1 -0
  20. package/dist/tableData.test.d.ts +2 -0
  21. package/dist/tableData.test.d.ts.map +1 -0
  22. package/dist/tableData.test.js +259 -0
  23. package/dist/tableData.test.js.map +1 -0
  24. package/dist/tableFormatter.d.ts +179 -0
  25. package/dist/tableFormatter.d.ts.map +1 -0
  26. package/dist/tableFormatter.js +298 -0
  27. package/dist/tableFormatter.js.map +1 -0
  28. package/dist/tableFormatter.test.d.ts +2 -0
  29. package/dist/tableFormatter.test.d.ts.map +1 -0
  30. package/dist/tableFormatter.test.js +101 -0
  31. package/dist/tableFormatter.test.js.map +1 -0
  32. package/dist/tableStyler.d.ts +310 -0
  33. package/dist/tableStyler.d.ts.map +1 -0
  34. package/dist/tableStyler.js +665 -0
  35. package/dist/tableStyler.js.map +1 -0
  36. package/dist/tableStyler.test.d.ts +2 -0
  37. package/dist/tableStyler.test.d.ts.map +1 -0
  38. package/dist/tableStyler.test.js +225 -0
  39. package/dist/tableStyler.test.js.map +1 -0
  40. package/dist/tableSvg.d.ts +41 -0
  41. package/dist/tableSvg.d.ts.map +1 -0
  42. package/dist/tableSvg.js +634 -0
  43. package/dist/tableSvg.js.map +1 -0
  44. package/dist/tableUtils.d.ts +14 -0
  45. package/dist/tableUtils.d.ts.map +1 -0
  46. package/dist/tableUtils.js +18 -0
  47. package/dist/tableUtils.js.map +1 -0
  48. package/eslint.config.js +23 -0
  49. package/index.ts +82 -0
  50. package/jest.config.js +5 -0
  51. package/package.json +44 -0
  52. package/stylings.ts +311 -0
  53. package/svg-table-0.0.1-snapshot.tgz +0 -0
  54. package/tableData.test.ts +290 -0
  55. package/tableData.ts +359 -0
  56. package/tableFormatter.test.ts +122 -0
  57. package/tableFormatter.ts +306 -0
  58. package/tableStyler.test.ts +268 -0
  59. package/tableStyler.ts +798 -0
  60. package/tableSvg.ts +820 -0
  61. package/tableUtils.ts +20 -0
  62. package/tsconfig.json +102 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableData.test.js","sourceRoot":"","sources":["../tableData.test.ts"],"names":[],"mappings":";;AAAA,+CAAwC;AACxC,yCAAsC;AAGtC,QAAQ,CAAC,sCAAsC,EAAE;IAE7C,IAAI,CAAC,wEAAwE,EAAE;QAC3E,IAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;QAC9C,IAAM,SAAS,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QACjD,IAAM,IAAI,GAAG,yBAAS,CAAC,IAAI,CAAC;YACxB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;YAC9B,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;YAC9B,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;YAC9B,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;SACjC,CAAC,CAAC,UAA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C,CAAC,CAAA"}
@@ -0,0 +1,179 @@
1
+ import { DataFrame, type Tag, type TagCoordinate, type TagValue } from "data-frame-ts";
2
+ import { type Result } from "result-fn";
3
+ import { TableData } from "./tableData";
4
+ /**
5
+ * Type representing a formatter function
6
+ */
7
+ export type Formatter<D> = (value: D) => string;
8
+ /**
9
+ * Default formatter that converts a {@link value} of type `V` to a string
10
+ * @param value The value to convert
11
+ * @return a string representation of the {@link value}
12
+ */
13
+ export declare function defaultFormatter<D>(value: D): string;
14
+ export type Formatting<V> = {
15
+ formatter: Formatter<V>;
16
+ priority: number;
17
+ };
18
+ export declare function defaultFormatting<D>(): Formatting<D>;
19
+ export declare enum TableFormatterType {
20
+ CELL = "cell-formatter",
21
+ COLUMN = "column-formatter",
22
+ ROW = "row-formatter"
23
+ }
24
+ export declare function isFormattingTag(tag: Tag<TagValue, TagCoordinate>): boolean;
25
+ /**
26
+ * Represents a formatter used to apply row, column, and cell formatting to a data table.
27
+ * This class is used to define custom formatters for specific rows, columns, or cells,
28
+ * with support for priority-based selection of formatters.
29
+ */
30
+ export declare class TableFormatter<V> {
31
+ private readonly dataFrame;
32
+ /**
33
+ * @param dataFrame A data-frame that will be tagged with the row, column, and
34
+ * cell formatters.
35
+ * @private
36
+ */
37
+ private constructor();
38
+ /**
39
+ * Constructs a new {@link TableFormatter} from a {@link TableData} object. Underneath,
40
+ * this factory method merely unwraps the {@link DataFrame} from the {@link TableData}
41
+ * and hands it to the constructor.
42
+ * @param tableData The table data object from which to construct the table formatter
43
+ * @return A new {@link TableFormatter} based on the {@link TableData}
44
+ * @see TableFormatter.fromDataFrame
45
+ */
46
+ static fromTableData<V>(tableData: TableData<V>): TableFormatter<V>;
47
+ /**
48
+ * Constructs a new {@link TableFormatter} from a {@link DataFrame} object
49
+ * @param dataFrame The data-frame object from which to construct the table formatter
50
+ * @return A new {@link TableFormatter} based on the {@link DataFrame}
51
+ @see TableFormatter.fromTableData
52
+ */
53
+ static fromDataFrame<V>(dataFrame: DataFrame<V>): TableFormatter<V>;
54
+ /**
55
+ * Formatters convert the column value types to formatted strings. The formatter used to format a given
56
+ * cell depends on the priority of each formatter associated with that cell. The formatter with the
57
+ * highest priority is used. If two or more formatters for a given cell have the same priority, the selected
58
+ * formatter is indeterminant.
59
+ * @param columnIndex The index of the column to which to add the formatter
60
+ * @param formatter The formatter
61
+ * @param [priority = 0] The priority of this formatter. If cells have more than one associated formatter,
62
+ * the one with the highest priority number is used.
63
+ * @example
64
+ * ```typescript
65
+ * // create the data
66
+ * const data = DataFrame.from<string | number | Date>([
67
+ * [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
68
+ * [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
69
+ * [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
70
+ * [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
71
+ * ]).getOrThrow()
72
+ *
73
+ * // create the table-data object from the data, and then hand the table-data
74
+ * // to the table formatter, add column formats, and format the table, getting
75
+ * // back a new TableData<string>
76
+ * const tableData: TableData<string> = TableData.fromDataFrame<string | number | Date>(data)
77
+ * // from the table-data, create a table-formatter
78
+ * .flatMap(tableData => createTableFormatterFrom(tableData)
79
+ * // add a column formatter for the first column of dates
80
+ * .addColumnFormatter(0, value => (value as Date).toLocaleDateString())
81
+ * // add a column formatter to the second column of number
82
+ * .flatMap(tf => tf.addColumnFormatter(1, value => defaultFormatter(value)))
83
+ * // add a column formatter to the fourth column of currencies
84
+ * .flatMap(tf => tf.addColumnFormatter(3, value => `$ ${(value as number).toFixed(2)}`))
85
+ * .flatMap(tf => tf.addColumnFormatter(4, value => `${(value as number).toFixed(0)}`))
86
+ * // format the table into a new TableData<string> object
87
+ * .flatMap(tf => tf.formatTable())
88
+ * )
89
+ * .getOrThrow()
90
+ *
91
+ * // we expect the data-frame in the table data to be the following
92
+ * const expectedData = DataFrame.from<string>([
93
+ * ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
94
+ * ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
95
+ * ['2/3/2021', '34567', 'GNM-H234', '$ 3.65', '40'],
96
+ * ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
97
+ * ]).getOrThrow()
98
+ * ```
99
+ */
100
+ addColumnFormatter(columnIndex: number, formatter: Formatter<V>, priority?: number): Result<TableFormatter<V>, string>;
101
+ addColumnFormatters(columnIndexes: Array<number>, formatter: Formatter<V>, priority?: number): Result<TableFormatter<V>, string>;
102
+ private static addColumnFormatters;
103
+ addRowFormatter(rowIndex: number, formatter: Formatter<V>, priority?: number): Result<TableFormatter<V>, string>;
104
+ addRowFormatters(rowIndexes: Array<number>, formatter: Formatter<V>, priority?: number): Result<TableFormatter<V>, string>;
105
+ private static addRowFormatters;
106
+ addCellFormatter(rowIndex: number, columnIndex: number, formatter: Formatter<V>, priority?: number): Result<TableFormatter<V>, string>;
107
+ addCellFormatters(cellIndexes: Array<[x: number, y: number]>, formatter: Formatter<V>, priority?: number): Result<TableFormatter<V>, string>;
108
+ private static addCellFormatters;
109
+ /**
110
+ * Formats the table headers, footer, and values using the formatters that have been added
111
+ * to this `TableData<V>` object and returns a new `TableData<string>` object where all the
112
+ * elements have been converted to a formatted string.
113
+ * @return a new `TableData<string>` object where all the elements have been converted to a
114
+ * formatted string.
115
+ * @example
116
+ * ```typescript
117
+ * function dateTimeFor(day: number, hour: number): Date {
118
+ * return new Date(2021, 1, day, hour, 0, 0, 0);
119
+ * }
120
+ *
121
+ * // the headers for the table
122
+ * const columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount']
123
+ * const rowHeader = [1, 2, 3, 4]
124
+ *
125
+ * // this is the actual data used to creat the data table (in row-form)
126
+ * const data = DataFrame.from<string | number | Date>([
127
+ * [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
128
+ * [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
129
+ * [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
130
+ * [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
131
+ * ]).getOrThrow()
132
+ *
133
+ * // this is what we expect that formatted data to look like
134
+ * const expectedData = DataFrame.from<string>([
135
+ * ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
136
+ * ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
137
+ * ['2/3/2021', '34567', 'gnm-h234', '$ 3.65', '40'],
138
+ * ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
139
+ * ]).getOrThrow()
140
+ *
141
+ * // 1. create a data-table that has a column-header and a row-header and mixed-type
142
+ * // data (number, string, Date)
143
+ * // 2. add formatters for the row and column headers (at highest priority)
144
+ * // 3. add formatters for some of the other data columns
145
+ * // 4. format the table
146
+ * const tableData = TableData.fromDataFrame<string | number | Date>(data)
147
+ * .withColumnHeader(columnHeader)
148
+ * .flatMap(table => table.withRowHeader(rowHeader))
149
+ * // add the default formatter for the column header, at the highest priority so that
150
+ * // it is the one that applies to the row representing the column header
151
+ * .flatMap(td => td.addRowFormatter(0, defaultFormatter, Infinity))
152
+ * // add the default formatter for the row header, at the highest priority so that
153
+ * // it is the one that applies to the column representing the row header
154
+ * .flatMap(td => td.addColumnFormatter(0, defaultFormatter, Infinity))
155
+ * // add the column formatters for each column at the default (lowest) priority
156
+ * // (notice that the columns are shifted by one for the columns because the row-header
157
+ * // occupies the first column (index=0))
158
+ * .flatMap(td => td.addColumnFormatter(1, value => (value as Date).toLocaleDateString()))
159
+ * .flatMap(td => td.addColumnFormatter(2, value => defaultFormatter(value)))
160
+ * .flatMap(td => td.addColumnFormatter(4, value => `$ ${(value as number).toFixed(2)}`))
161
+ * .flatMap(td => td.addColumnFormatter(5, value => `${(value as number).toFixed(0)}`))
162
+ * // format the table data and get back a TableData<string>
163
+ * .map(td => td.formatTable())
164
+ * .getOrThrow()
165
+ *
166
+ * // the column header of the formatted table should be the same as the one specified
167
+ * expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader)
168
+ *
169
+ * // the row header of the formatted table should be the same as the one specified
170
+ * expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader.map(hdr => defaultFormatter(hdr)))
171
+ *
172
+ * // the data should be equal to the expected data
173
+ * expect(tableData.data().map(df => df.equals(expectedData)).getOrThrow()).toBeTruthy()
174
+ * ```
175
+ */
176
+ formatTable<C extends TagCoordinate>(): Result<TableData<string>, string>;
177
+ formatTableInto<C extends TagCoordinate, D = TableData<string>>(mapper: (dataFrame: DataFrame<string>) => D): Result<D, string>;
178
+ }
179
+ //# sourceMappingURL=tableFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableFormatter.d.ts","sourceRoot":"","sources":["../tableFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,KAAK,GAAG,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAC,MAAM,eAAe,CAAC;AACrF,OAAO,EAAgB,KAAK,MAAM,EAAgB,MAAM,WAAW,CAAC;AACpE,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAA;AAE/C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAEpD;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;IACxB,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,iBAAiB,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAKpD;AAED,oBAAY,kBAAkB;IAC1B,IAAI,mBAAmB;IACvB,MAAM,qBAAqB;IAC3B,GAAG,kBAAkB;CACxB;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE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OAAO,CAAC,MAAM,CAAC,gBAAgB;IAiB/B,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAMzI,iBAAiB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC;IAI/I,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAiBhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkEG;IACH,WAAW,CAAC,CAAC,SAAS,aAAa,KAAK,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAIzE,eAAe,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC;CA0BlI"}
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.TableFormatter = exports.TableFormatterType = void 0;
20
+ exports.defaultFormatter = defaultFormatter;
21
+ exports.defaultFormatting = defaultFormatting;
22
+ exports.isFormattingTag = isFormattingTag;
23
+ var result_fn_1 = require("result-fn");
24
+ var tableData_1 = require("./tableData");
25
+ /**
26
+ * Default formatter that converts a {@link value} of type `V` to a string
27
+ * @param value The value to convert
28
+ * @return a string representation of the {@link value}
29
+ */
30
+ function defaultFormatter(value) {
31
+ return value === undefined || value === null ? '' : "".concat(value);
32
+ }
33
+ function defaultFormatting() {
34
+ return {
35
+ formatter: (defaultFormatter),
36
+ priority: 0
37
+ };
38
+ }
39
+ var TableFormatterType;
40
+ (function (TableFormatterType) {
41
+ TableFormatterType["CELL"] = "cell-formatter";
42
+ TableFormatterType["COLUMN"] = "column-formatter";
43
+ TableFormatterType["ROW"] = "row-formatter";
44
+ })(TableFormatterType || (exports.TableFormatterType = TableFormatterType = {}));
45
+ function isFormattingTag(tag) {
46
+ return (tag.name === TableFormatterType.COLUMN ||
47
+ tag.name === TableFormatterType.ROW ||
48
+ tag.name === TableFormatterType.CELL) &&
49
+ tag.value.hasOwnProperty("formatter") &&
50
+ tag.value.hasOwnProperty("priority");
51
+ }
52
+ /**
53
+ * Represents a formatter used to apply row, column, and cell formatting to a data table.
54
+ * This class is used to define custom formatters for specific rows, columns, or cells,
55
+ * with support for priority-based selection of formatters.
56
+ */
57
+ var TableFormatter = /** @class */ (function () {
58
+ /**
59
+ * @param dataFrame A data-frame that will be tagged with the row, column, and
60
+ * cell formatters.
61
+ * @private
62
+ */
63
+ function TableFormatter(dataFrame) {
64
+ this.dataFrame = dataFrame;
65
+ }
66
+ /**
67
+ * Constructs a new {@link TableFormatter} from a {@link TableData} object. Underneath,
68
+ * this factory method merely unwraps the {@link DataFrame} from the {@link TableData}
69
+ * and hands it to the constructor.
70
+ * @param tableData The table data object from which to construct the table formatter
71
+ * @return A new {@link TableFormatter} based on the {@link TableData}
72
+ * @see TableFormatter.fromDataFrame
73
+ */
74
+ TableFormatter.fromTableData = function (tableData) {
75
+ return new TableFormatter(tableData.unwrapDataFrame());
76
+ };
77
+ /**
78
+ * Constructs a new {@link TableFormatter} from a {@link DataFrame} object
79
+ * @param dataFrame The data-frame object from which to construct the table formatter
80
+ * @return A new {@link TableFormatter} based on the {@link DataFrame}
81
+ @see TableFormatter.fromTableData
82
+ */
83
+ TableFormatter.fromDataFrame = function (dataFrame) {
84
+ return new TableFormatter(dataFrame.copy());
85
+ };
86
+ /**
87
+ * Formatters convert the column value types to formatted strings. The formatter used to format a given
88
+ * cell depends on the priority of each formatter associated with that cell. The formatter with the
89
+ * highest priority is used. If two or more formatters for a given cell have the same priority, the selected
90
+ * formatter is indeterminant.
91
+ * @param columnIndex The index of the column to which to add the formatter
92
+ * @param formatter The formatter
93
+ * @param [priority = 0] The priority of this formatter. If cells have more than one associated formatter,
94
+ * the one with the highest priority number is used.
95
+ * @example
96
+ * ```typescript
97
+ * // create the data
98
+ * const data = DataFrame.from<string | number | Date>([
99
+ * [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
100
+ * [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
101
+ * [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
102
+ * [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
103
+ * ]).getOrThrow()
104
+ *
105
+ * // create the table-data object from the data, and then hand the table-data
106
+ * // to the table formatter, add column formats, and format the table, getting
107
+ * // back a new TableData<string>
108
+ * const tableData: TableData<string> = TableData.fromDataFrame<string | number | Date>(data)
109
+ * // from the table-data, create a table-formatter
110
+ * .flatMap(tableData => createTableFormatterFrom(tableData)
111
+ * // add a column formatter for the first column of dates
112
+ * .addColumnFormatter(0, value => (value as Date).toLocaleDateString())
113
+ * // add a column formatter to the second column of number
114
+ * .flatMap(tf => tf.addColumnFormatter(1, value => defaultFormatter(value)))
115
+ * // add a column formatter to the fourth column of currencies
116
+ * .flatMap(tf => tf.addColumnFormatter(3, value => `$ ${(value as number).toFixed(2)}`))
117
+ * .flatMap(tf => tf.addColumnFormatter(4, value => `${(value as number).toFixed(0)}`))
118
+ * // format the table into a new TableData<string> object
119
+ * .flatMap(tf => tf.formatTable())
120
+ * )
121
+ * .getOrThrow()
122
+ *
123
+ * // we expect the data-frame in the table data to be the following
124
+ * const expectedData = DataFrame.from<string>([
125
+ * ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
126
+ * ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
127
+ * ['2/3/2021', '34567', 'GNM-H234', '$ 3.65', '40'],
128
+ * ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
129
+ * ]).getOrThrow()
130
+ * ```
131
+ */
132
+ TableFormatter.prototype.addColumnFormatter = function (columnIndex, formatter, priority) {
133
+ if (priority === void 0) { priority = 0; }
134
+ return this.dataFrame
135
+ .tagColumn(columnIndex, TableFormatterType.COLUMN, { formatter: formatter, priority: priority })
136
+ .map(function (data) { return new TableFormatter(data); });
137
+ };
138
+ TableFormatter.prototype.addColumnFormatters = function (columnIndexes, formatter, priority) {
139
+ if (priority === void 0) { priority = 0; }
140
+ return TableFormatter.addColumnFormatters(this, columnIndexes, formatter, priority);
141
+ };
142
+ TableFormatter.addColumnFormatters = function (tableFormatter, columnIndexes, formatter, priority) {
143
+ if (priority === void 0) { priority = 0; }
144
+ if (columnIndexes.length > 0) {
145
+ var columnIndex = columnIndexes.slice().shift();
146
+ if (columnIndex != null) {
147
+ return tableFormatter
148
+ .addColumnFormatter(columnIndex, formatter, priority)
149
+ .flatMap(function (tf) { return TableFormatter.addColumnFormatters(tf, columnIndexes, formatter, priority); });
150
+ }
151
+ }
152
+ return (0, result_fn_1.successResult)(tableFormatter);
153
+ };
154
+ TableFormatter.prototype.addRowFormatter = function (rowIndex, formatter, priority) {
155
+ if (priority === void 0) { priority = 0; }
156
+ return this.dataFrame
157
+ .tagRow(rowIndex, TableFormatterType.ROW, { formatter: formatter, priority: priority })
158
+ .map(function (data) { return new TableFormatter(data); });
159
+ };
160
+ TableFormatter.prototype.addRowFormatters = function (rowIndexes, formatter, priority) {
161
+ if (priority === void 0) { priority = 0; }
162
+ return TableFormatter.addRowFormatters(this, rowIndexes.slice(), formatter, priority);
163
+ };
164
+ TableFormatter.addRowFormatters = function (tableFormatter, rowIndexes, formatter, priority) {
165
+ if (priority === void 0) { priority = 0; }
166
+ if (rowIndexes.length > 0) {
167
+ var rowIndex = rowIndexes.shift();
168
+ if (rowIndex != null) {
169
+ return tableFormatter
170
+ .addRowFormatter(rowIndex, formatter, priority)
171
+ .flatMap(function (tf) { return TableFormatter.addRowFormatters(tf, rowIndexes, formatter, priority); });
172
+ }
173
+ }
174
+ return (0, result_fn_1.successResult)(tableFormatter);
175
+ };
176
+ TableFormatter.prototype.addCellFormatter = function (rowIndex, columnIndex, formatter, priority) {
177
+ if (priority === void 0) { priority = 0; }
178
+ return this.dataFrame
179
+ .tagCell(rowIndex, columnIndex, TableFormatterType.CELL, { formatter: formatter, priority: priority })
180
+ .map(function (data) { return new TableFormatter(data); });
181
+ };
182
+ TableFormatter.prototype.addCellFormatters = function (cellIndexes, formatter, priority) {
183
+ if (priority === void 0) { priority = 0; }
184
+ return TableFormatter.addCellFormatters(this, cellIndexes, formatter, priority);
185
+ };
186
+ TableFormatter.addCellFormatters = function (tableFormatter, cellIndexes, formatter, priority) {
187
+ var _a;
188
+ if (priority === void 0) { priority = 0; }
189
+ if (cellIndexes.length > 0) {
190
+ var _b = __read((_a = cellIndexes.slice().shift()) !== null && _a !== void 0 ? _a : [undefined, undefined], 2), columnIndex = _b[0], rowIndex = _b[1];
191
+ if (rowIndex != null && columnIndex != null) {
192
+ return tableFormatter
193
+ .addCellFormatter(rowIndex, columnIndex, formatter, priority)
194
+ .flatMap(function (tf) { return TableFormatter.addCellFormatters(tf, cellIndexes, formatter, priority); });
195
+ }
196
+ }
197
+ return (0, result_fn_1.successResult)(tableFormatter);
198
+ };
199
+ /**
200
+ * Formats the table headers, footer, and values using the formatters that have been added
201
+ * to this `TableData<V>` object and returns a new `TableData<string>` object where all the
202
+ * elements have been converted to a formatted string.
203
+ * @return a new `TableData<string>` object where all the elements have been converted to a
204
+ * formatted string.
205
+ * @example
206
+ * ```typescript
207
+ * function dateTimeFor(day: number, hour: number): Date {
208
+ * return new Date(2021, 1, day, hour, 0, 0, 0);
209
+ * }
210
+ *
211
+ * // the headers for the table
212
+ * const columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount']
213
+ * const rowHeader = [1, 2, 3, 4]
214
+ *
215
+ * // this is the actual data used to creat the data table (in row-form)
216
+ * const data = DataFrame.from<string | number | Date>([
217
+ * [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
218
+ * [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
219
+ * [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
220
+ * [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
221
+ * ]).getOrThrow()
222
+ *
223
+ * // this is what we expect that formatted data to look like
224
+ * const expectedData = DataFrame.from<string>([
225
+ * ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
226
+ * ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
227
+ * ['2/3/2021', '34567', 'gnm-h234', '$ 3.65', '40'],
228
+ * ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
229
+ * ]).getOrThrow()
230
+ *
231
+ * // 1. create a data-table that has a column-header and a row-header and mixed-type
232
+ * // data (number, string, Date)
233
+ * // 2. add formatters for the row and column headers (at highest priority)
234
+ * // 3. add formatters for some of the other data columns
235
+ * // 4. format the table
236
+ * const tableData = TableData.fromDataFrame<string | number | Date>(data)
237
+ * .withColumnHeader(columnHeader)
238
+ * .flatMap(table => table.withRowHeader(rowHeader))
239
+ * // add the default formatter for the column header, at the highest priority so that
240
+ * // it is the one that applies to the row representing the column header
241
+ * .flatMap(td => td.addRowFormatter(0, defaultFormatter, Infinity))
242
+ * // add the default formatter for the row header, at the highest priority so that
243
+ * // it is the one that applies to the column representing the row header
244
+ * .flatMap(td => td.addColumnFormatter(0, defaultFormatter, Infinity))
245
+ * // add the column formatters for each column at the default (lowest) priority
246
+ * // (notice that the columns are shifted by one for the columns because the row-header
247
+ * // occupies the first column (index=0))
248
+ * .flatMap(td => td.addColumnFormatter(1, value => (value as Date).toLocaleDateString()))
249
+ * .flatMap(td => td.addColumnFormatter(2, value => defaultFormatter(value)))
250
+ * .flatMap(td => td.addColumnFormatter(4, value => `$ ${(value as number).toFixed(2)}`))
251
+ * .flatMap(td => td.addColumnFormatter(5, value => `${(value as number).toFixed(0)}`))
252
+ * // format the table data and get back a TableData<string>
253
+ * .map(td => td.formatTable())
254
+ * .getOrThrow()
255
+ *
256
+ * // the column header of the formatted table should be the same as the one specified
257
+ * expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader)
258
+ *
259
+ * // the row header of the formatted table should be the same as the one specified
260
+ * expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader.map(hdr => defaultFormatter(hdr)))
261
+ *
262
+ * // the data should be equal to the expected data
263
+ * expect(tableData.data().map(df => df.equals(expectedData)).getOrThrow()).toBeTruthy()
264
+ * ```
265
+ */
266
+ TableFormatter.prototype.formatTable = function () {
267
+ return this.formatTableInto(function (dataFrame) { return tableData_1.TableData.fromDataFrame(dataFrame); });
268
+ };
269
+ TableFormatter.prototype.formatTableInto = function (mapper) {
270
+ var _this = this;
271
+ var formattingFailures = [];
272
+ var formattedDataFrame = this.dataFrame
273
+ .mapElements(function (elem, row, col) {
274
+ var tags = _this.dataFrame
275
+ .tagsFor(row, col)
276
+ .filter(function (tag) { return isFormattingTag(tag); });
277
+ var sorted = tags
278
+ .sort(function (t1, t2) { return t2.value.priority - t1.value.priority; });
279
+ if (sorted.length > 0) {
280
+ var formatter = sorted[0].value.formatter;
281
+ try {
282
+ return formatter(elem);
283
+ }
284
+ catch (e) {
285
+ formattingFailures.push("(TableData::formatTable) Failed to format cell (".concat(row, ", ").concat(col, "); value: ").concat(elem, "; error: ").concat(e));
286
+ }
287
+ }
288
+ return defaultFormatter(elem);
289
+ });
290
+ if (formattingFailures.length === 0) {
291
+ return (0, result_fn_1.successResult)(mapper(formattedDataFrame));
292
+ }
293
+ return (0, result_fn_1.failureResult)(formattingFailures.concat('').join('\n'));
294
+ };
295
+ return TableFormatter;
296
+ }());
297
+ exports.TableFormatter = TableFormatter;
298
+ //# sourceMappingURL=tableFormatter.js.map
@@ -0,0 +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,EAAE,CAAC;KACd,CAAA;AACL,CAAC;AAED,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC1B,6CAAuB,CAAA;IACvB,iDAA2B,CAAA;IAC3B,2CAAqB,CAAA;AACzB,CAAC,EAJW,kBAAkB,kCAAlB,kBAAkB,QAI7B;AAED,SAAgB,eAAe,CAAC,GAAiC;IAC7D,OAAO,CAAC,GAAG,CAAC,IAAI,KAAK,kBAAkB,CAAC,MAAM;QACtC,GAAG,CAAC,IAAI,KAAK,kBAAkB,CAAC,GAAG;QACnC,GAAG,CAAC,IAAI,KAAK,kBAAkB,CAAC,IAAI,CAAC;QACzC,GAAG,CAAC,KA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AAC,SAAS,CAAA;gBAC3C,IAAI,CAAC;oBACD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;gBAC1B,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,kBAAkB,CAAC,IAAI,CACnB,0DAAmD,GAAG,eAAK,GAAG,uBAAa,IAAI,sBAAY,CAAC,CAAE,CACjG,CAAA;gBACL,CAAC;YACL,CAAC;YACD,OAAO,gBAAgB,CAAI,IAAI,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;QACN,IAAI,kBAAkB,CAAC,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,AAhQD,IAgQC;AAhQY,wCAAc"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=tableFormatter.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tableFormatter.test.d.ts","sourceRoot":"","sources":["../tableFormatter.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tableData_1 = require("./tableData");
4
+ var data_frame_ts_1 = require("data-frame-ts");
5
+ var tableFormatter_1 = require("./tableFormatter");
6
+ describe('creating tables with mixed data types', function () {
7
+ function dateTimeFor(day, hour) {
8
+ return new Date(2021, 1, day, hour, 0, 0, 0);
9
+ }
10
+ var data = data_frame_ts_1.DataFrame.from([
11
+ [dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
12
+ [dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
13
+ [dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
14
+ [dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
15
+ ]).getOrThrow();
16
+ var columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount'];
17
+ var rowHeader = [1, 2, 3, 4];
18
+ test('should be able to create a table with string headers and numeric values', function () {
19
+ var expectedData = data_frame_ts_1.DataFrame.from([
20
+ ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
21
+ ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
22
+ ['2/3/2021', '34567', 'GNM-H234', '$ 3.65', '40'],
23
+ ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
24
+ ]).getOrThrow();
25
+ var tableData = tableData_1.TableData.fromDataFrame(data)
26
+ .withColumnHeader(columnHeader)
27
+ .flatMap(function (tableData) { return tableFormatter_1.TableFormatter.fromTableData(tableData)
28
+ // add the default formatter for the column header, at the highest priority so that
29
+ // it is the one that applies to the row representing the column header
30
+ .addRowFormatter(0, tableFormatter_1.defaultFormatter, 100)
31
+ // add the column formatters for each column at the default (lowest) priority
32
+ .flatMap(function (tf) { return tf.addColumnFormatter(0, function (value) { return value.toLocaleDateString(); }); })
33
+ .flatMap(function (tf) { return tf.addColumnFormatter(1, function (value) { return (0, tableFormatter_1.defaultFormatter)(value); }); })
34
+ .flatMap(function (tf) { return tf.addColumnFormatter(3, function (value) { return "$ ".concat(value.toFixed(2)); }); })
35
+ .flatMap(function (tf) { return tf.addColumnFormatter(4, function (value) { return "".concat(value.toFixed(0)); }); })
36
+ .flatMap(function (tf) { return tf.addCellFormatter(3, 2, function (value) { return value.toUpperCase(); }, 1); })
37
+ // format the table into a new TableData object
38
+ .flatMap(function (tf) { return tf.formatTable(); }); })
39
+ .getOrThrow();
40
+ expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
41
+ expect(tableData.data().map(function (df) { return df.equals(expectedData); }).getOrThrow()).toBeTruthy();
42
+ expect(tableData.tableColumnCount()).toEqual(5);
43
+ expect(tableData.tableRowCount()).toEqual(/*data*/ 4 + /*header*/ 1);
44
+ expect(tableData.hasColumnHeader()).toBeTruthy();
45
+ expect(tableData.hasRowHeader()).toBeFalsy();
46
+ expect(tableData.hasFooter()).toBeFalsy();
47
+ });
48
+ test('should be able to create a table with string column and row headers and numeric values', function () {
49
+ var expectedData = data_frame_ts_1.DataFrame.from([
50
+ ['2/1/2021', '12345', 'gnm-f234', '$ 123.45', '4'],
51
+ ['2/2/2021', '23456', 'gnm-g234', '$ 23.45', '5'],
52
+ ['2/3/2021', '34567', 'gnm-h234', '$ 3.65', '40'],
53
+ ['2/4/2021', '45678', 'gnm-i234', '$ 314.15', '9'],
54
+ ]).getOrThrow();
55
+ var tableData = tableData_1.TableData.fromDataFrame(data)
56
+ .withColumnHeader(columnHeader)
57
+ .flatMap(function (td) { return td.withRowHeader(rowHeader); })
58
+ .flatMap(function (tableData) { return tableFormatter_1.TableFormatter.fromTableData(tableData)
59
+ // add the default formatter for the column header, at the highest priority so that
60
+ // it is the one that applies to the row representing the column header
61
+ .addRowFormatter(0, tableFormatter_1.defaultFormatter, Infinity)
62
+ // add the default formatter for the row header, at the highest priority so that
63
+ // it is the one that applies to the column representing the row header
64
+ .flatMap(function (tf) { return tf.addColumnFormatter(0, tableFormatter_1.defaultFormatter, Infinity); })
65
+ // add the column formatters for each column at the default (lowest) priority
66
+ // (notice that the columns are shifted by one for the columns because the row-header
67
+ // occupies the first column (index=0))
68
+ .flatMap(function (tf) { return tf.addColumnFormatter(1, function (value) { return value.toLocaleDateString(); }); })
69
+ .flatMap(function (tf) { return tf.addColumnFormatter(2, function (value) { return (0, tableFormatter_1.defaultFormatter)(value); }); })
70
+ .flatMap(function (tf) { return tf.addColumnFormatter(4, function (value) { return "$ ".concat(value.toFixed(2)); }); })
71
+ .flatMap(function (tf) { return tf.addColumnFormatter(5, function (value) { return "".concat(value.toFixed(0)); }); })
72
+ // format the table data and get back a TableData<string>
73
+ .flatMap(function (tf) { return tf.formatTable(); }); })
74
+ .getOrThrow();
75
+ expect(tableData.columnHeader().getOrThrow()).toEqual(columnHeader);
76
+ expect(tableData.rowHeader().getOrThrow()).toEqual(rowHeader.map(function (hdr) { return (0, tableFormatter_1.defaultFormatter)(hdr); }));
77
+ expect(tableData.data().map(function (df) { return df.equals(expectedData); }).getOrThrow()).toBeTruthy();
78
+ expect(tableData.tableColumnCount()).toEqual(5 + 1); // data + row-header
79
+ expect(tableData.tableRowCount()).toEqual(4 + 1); // data + column-header
80
+ expect(tableData.hasColumnHeader()).toBeTruthy();
81
+ expect(tableData.hasRowHeader()).toBeTruthy();
82
+ expect(tableData.hasFooter()).toBeFalsy();
83
+ });
84
+ test('should be report failures when formatting function fails', function () {
85
+ var columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount'];
86
+ var result = tableData_1.TableData.fromDataFrame(data)
87
+ .withColumnHeader(columnHeader)
88
+ .flatMap(function (tableData) { return tableFormatter_1.TableFormatter.fromDataFrame(tableData.unwrapDataFrame())
89
+ // add the default formatter for the column header, at the highest priority so that
90
+ // it is the one that applies to the row representing the column header
91
+ .addRowFormatter(0, tableFormatter_1.defaultFormatter, 100)
92
+ // add a column formatter to the incorrect column (data-type is a number) and attempt to
93
+ // format it as if it where a string. errors will be collected for each format error
94
+ .flatMap(function (tf) { return tf.addColumnFormatter(3, function (value) { return value.toUpperCase(); }); })
95
+ // format the table data and get back a TableData<string>
96
+ .flatMap(function (tf) { return tf.formatTable(); }); });
97
+ expect(result.failed).toBeTruthy();
98
+ expect(result.error).toEqual("(TableData::formatTable) Failed to format cell (1, 3); value: 123.45; error: TypeError: value.toUpperCase is not a function\n(TableData::formatTable) Failed to format cell (2, 3); value: 23.45; error: TypeError: value.toUpperCase is not a function\n(TableData::formatTable) Failed to format cell (3, 3); value: 3.65; error: TypeError: value.toUpperCase is not a function\n(TableData::formatTable) Failed to format cell (4, 3); value: 314.15; error: TypeError: value.toUpperCase is not a function\n");
99
+ });
100
+ });
101
+ //# sourceMappingURL=tableFormatter.test.js.map