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.test.js
CHANGED
|
@@ -1,69 +1,47 @@
|
|
|
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
|
-
var __values = (this && this.__values) || function(o) {
|
|
14
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
15
|
-
if (m) return m.call(o);
|
|
16
|
-
if (o && typeof o.length === "number") return {
|
|
17
|
-
next: function () {
|
|
18
|
-
if (o && i >= o.length) o = void 0;
|
|
19
|
-
return { value: o && o[i++], done: !o };
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
23
|
-
};
|
|
24
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
describe('styling data tables',
|
|
3
|
+
const TableData_1 = require("./TableData");
|
|
4
|
+
const data_frame_ts_1 = require("data-frame-ts");
|
|
5
|
+
const TableFormatter_1 = require("./TableFormatter");
|
|
6
|
+
const stylings_1 = require("./stylings");
|
|
7
|
+
const TableStyler_1 = require("./TableStyler");
|
|
8
|
+
describe('styling data tables', () => {
|
|
31
9
|
function dateTimeFor(day, hour) {
|
|
32
10
|
return new Date(2021, 1, day, hour, 0, 0, 0);
|
|
33
11
|
}
|
|
34
|
-
|
|
12
|
+
const data = data_frame_ts_1.DataFrame.from([
|
|
35
13
|
[dateTimeFor(1, 1), 12345, 'gnm-f234', 123.45, 4],
|
|
36
14
|
[dateTimeFor(2, 2), 23456, 'gnm-g234', 23.45, 5],
|
|
37
15
|
[dateTimeFor(3, 3), 34567, 'gnm-h234', 3.65, 40],
|
|
38
16
|
[dateTimeFor(4, 4), 45678, 'gnm-i234', 314.15, 9],
|
|
39
17
|
[dateTimeFor(5, 5), 56789, 'gnm-j234', 618.3, 10],
|
|
40
18
|
]).getOrThrow();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
describe('adding basic table styles',
|
|
45
|
-
|
|
19
|
+
const columnHeader = ['Date-Time', 'Customer ID', 'Product ID', 'Purchase Price', 'Amount'];
|
|
20
|
+
const rowHeader = [1, 2, 3, 4, 5];
|
|
21
|
+
const footer = ['A', 'B', 'C', 'D', 'E'];
|
|
22
|
+
describe('adding basic table styles', () => {
|
|
23
|
+
const formattedTableData = TableData_1.TableData.fromDataFrame(data)
|
|
46
24
|
.withColumnHeader(columnHeader)
|
|
47
|
-
.flatMap(
|
|
48
|
-
.flatMap(
|
|
49
|
-
.flatMap(
|
|
25
|
+
.flatMap(td => td.withRowHeader(rowHeader))
|
|
26
|
+
.flatMap(td => td.withFooter(footer))
|
|
27
|
+
.flatMap(td => TableFormatter_1.TableFormatter.fromTableData(td)
|
|
50
28
|
// add the default formatter for the column header, at the highest priority so that
|
|
51
29
|
// it is the one that applies to the row representing the column header
|
|
52
30
|
.addRowFormatter(0, TableFormatter_1.defaultFormatter, 100)
|
|
53
31
|
// formatter for the footer
|
|
54
|
-
.flatMap(
|
|
55
|
-
.flatMap(
|
|
32
|
+
.flatMap(tf => tf.addRowFormatter(5, TableFormatter_1.defaultFormatter, 100))
|
|
33
|
+
.flatMap(tf => tf.addColumnFormatter(0, TableFormatter_1.defaultFormatter, 100))
|
|
56
34
|
// add the column formatters for each column at the default (lowest) priority
|
|
57
|
-
.flatMap(
|
|
58
|
-
.flatMap(
|
|
59
|
-
.flatMap(
|
|
60
|
-
.flatMap(
|
|
61
|
-
.flatMap(
|
|
35
|
+
.flatMap(tf => tf.addColumnFormatter(1, value => value.toLocaleDateString()))
|
|
36
|
+
.flatMap(tf => tf.addColumnFormatter(2, value => (0, TableFormatter_1.defaultFormatter)(value)))
|
|
37
|
+
.flatMap(tf => tf.addColumnFormatter(4, value => `$ ${value.toFixed(2)}`))
|
|
38
|
+
.flatMap(tf => tf.addColumnFormatter(5, value => `${value.toFixed(0)}`))
|
|
39
|
+
.flatMap(tf => tf.addCellFormatter(3, 3, value => value.toUpperCase(), 1))
|
|
62
40
|
// format the table into a new TableData object
|
|
63
|
-
.flatMap(
|
|
41
|
+
.flatMap(tf => tf.formatTable()))
|
|
64
42
|
.getOrThrow();
|
|
65
|
-
describe('set and retrieve global table styles',
|
|
66
|
-
|
|
43
|
+
describe('set and retrieve global table styles', () => {
|
|
44
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
67
45
|
.withTableBackground({ color: 'grey', opacity: 0.15 })
|
|
68
46
|
.withTableFont({ color: 'blue', size: 13.5 })
|
|
69
47
|
.withBorder({ top: { opacity: 0 } })
|
|
@@ -71,368 +49,232 @@ describe('styling data tables', function () {
|
|
|
71
49
|
.withPadding({ top: 10 })
|
|
72
50
|
.withMargin({ left: 10, right: 10 })
|
|
73
51
|
.styleTable();
|
|
74
|
-
test('should be able to retrieve the background',
|
|
52
|
+
test('should be able to retrieve the background', () => {
|
|
75
53
|
expect(styledTable.tableBackground()).toEqual({ color: 'grey', opacity: 0.15 });
|
|
76
54
|
});
|
|
77
|
-
test('should be able to retrieve the font',
|
|
78
|
-
expect(styledTable.tableFont()).toEqual(
|
|
55
|
+
test('should be able to retrieve the font', () => {
|
|
56
|
+
expect(styledTable.tableFont()).toEqual(Object.assign(Object.assign({}, stylings_1.defaultTableFont), { color: 'blue', size: 13.5 }));
|
|
79
57
|
});
|
|
80
|
-
test('should be able to retrieve the border',
|
|
81
|
-
expect(styledTable.tableBorder()).toEqual(
|
|
58
|
+
test('should be able to retrieve the border', () => {
|
|
59
|
+
expect(styledTable.tableBorder()).toEqual(Object.assign(Object.assign({}, stylings_1.defaultBorder), { top: { opacity: 0 } }));
|
|
82
60
|
});
|
|
83
|
-
test('should be able to retrieve the dimensions',
|
|
61
|
+
test('should be able to retrieve the dimensions', () => {
|
|
84
62
|
expect(styledTable.tableDimensions()).toEqual({ width: 1300, height: 500 });
|
|
85
63
|
});
|
|
86
|
-
test('should be able to retrieve the padding',
|
|
87
|
-
expect(styledTable.tablePadding()).toEqual(
|
|
64
|
+
test('should be able to retrieve the padding', () => {
|
|
65
|
+
expect(styledTable.tablePadding()).toEqual(Object.assign(Object.assign({}, stylings_1.defaultTablePadding), { top: 10 }));
|
|
88
66
|
});
|
|
89
|
-
test('should be able to retrieve the margin',
|
|
90
|
-
expect(styledTable.tableMargin()).toEqual(
|
|
67
|
+
test('should be able to retrieve the margin', () => {
|
|
68
|
+
expect(styledTable.tableMargin()).toEqual(Object.assign(Object.assign({}, stylings_1.defaultTableMargin), { left: 10, right: 10 }));
|
|
91
69
|
});
|
|
92
|
-
test('should be able to get a copy of the data-frame from the styler',
|
|
93
|
-
|
|
70
|
+
test('should be able to get a copy of the data-frame from the styler', () => {
|
|
71
|
+
const dataFrame = styledTable.data();
|
|
94
72
|
expect(dataFrame.equals(formattedTableData.unwrapDataFrame())).toBeTruthy();
|
|
95
73
|
});
|
|
96
|
-
test('should be able to report whether styled table has a row header',
|
|
74
|
+
test('should be able to report whether styled table has a row header', () => {
|
|
97
75
|
expect(styledTable.hasRowHeader()).toBeTruthy();
|
|
98
76
|
});
|
|
99
|
-
test('should be able to report whether styled table has a column header',
|
|
77
|
+
test('should be able to report whether styled table has a column header', () => {
|
|
100
78
|
expect(styledTable.hasColumnHeader()).toBeTruthy();
|
|
101
79
|
});
|
|
102
|
-
test('should be able to report whether styled table has a footer',
|
|
80
|
+
test('should be able to report whether styled table has a footer', () => {
|
|
103
81
|
expect(styledTable.hasFooter()).toBeTruthy();
|
|
104
82
|
});
|
|
105
83
|
});
|
|
106
|
-
test('should be able to set and retrieve style for the column header',
|
|
107
|
-
|
|
108
|
-
.withColumnHeaderStyle({ font:
|
|
84
|
+
test('should be able to set and retrieve style for the column header', () => {
|
|
85
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
86
|
+
.withColumnHeaderStyle({ font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) })
|
|
109
87
|
.styleTable();
|
|
110
88
|
expect(styledTable.columnHeaderStyle().getOrThrow()).toEqual({
|
|
111
|
-
style:
|
|
89
|
+
style: Object.assign(Object.assign({}, stylings_1.defaultColumnHeaderStyle), { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) }),
|
|
112
90
|
priority: Infinity
|
|
113
91
|
});
|
|
114
92
|
});
|
|
115
|
-
test('should be able to set and retrieve style for the row header',
|
|
116
|
-
|
|
117
|
-
.withRowHeaderStyle({ font:
|
|
93
|
+
test('should be able to set and retrieve style for the row header', () => {
|
|
94
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
95
|
+
.withRowHeaderStyle({ font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) })
|
|
118
96
|
.styleTable();
|
|
119
97
|
expect(styledTable.rowHeaderStyle().getOrThrow()).toEqual({
|
|
120
|
-
style:
|
|
98
|
+
style: Object.assign(Object.assign({}, stylings_1.defaultRowHeaderStyle), { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) }),
|
|
121
99
|
priority: Infinity
|
|
122
100
|
});
|
|
123
101
|
});
|
|
124
|
-
test('should be able to set and retrieve style for the footer',
|
|
125
|
-
|
|
126
|
-
.withFooterStyle({ font:
|
|
102
|
+
test('should be able to set and retrieve style for the footer', () => {
|
|
103
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
104
|
+
.withFooterStyle({ font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) })
|
|
127
105
|
.styleTable();
|
|
128
106
|
expect(styledTable.footerStyle().getOrThrow()).toEqual({
|
|
129
|
-
style:
|
|
107
|
+
style: Object.assign(Object.assign({}, stylings_1.defaultFooterStyle), { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) }),
|
|
130
108
|
priority: Infinity
|
|
131
109
|
});
|
|
132
110
|
});
|
|
133
|
-
describe('retrieve the cell style with highest priority',
|
|
134
|
-
|
|
135
|
-
.withColumnHeaderStyle({ font:
|
|
136
|
-
.withCellStyle(2, 3, { font:
|
|
137
|
-
.withRowStyle(2, { font:
|
|
138
|
-
.withRowHeaderStyle({ font:
|
|
111
|
+
describe('retrieve the cell style with highest priority', () => {
|
|
112
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
113
|
+
.withColumnHeaderStyle({ font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) })
|
|
114
|
+
.withCellStyle(2, 3, { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 12, weight: 600 }) }, 100)
|
|
115
|
+
.withRowStyle(2, { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 14, weight: 700 }) }, 50)
|
|
116
|
+
.withRowHeaderStyle({ font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 15, weight: 650 }) })
|
|
139
117
|
.withColumnStyle(4, { padding: { left: 1000, right: 1111 } }, 75)
|
|
140
118
|
.styleTable();
|
|
141
119
|
function expectDefaultCellStyleFor(row, column) {
|
|
142
120
|
expect(styledTable.stylesForTableCoordinates(row, column).getOrThrow()).toEqual(stylings_1.defaultCellStyle);
|
|
143
121
|
}
|
|
144
|
-
test('should get the default cell style for cells with no available style',
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var row = unstyledRows_1_1.value;
|
|
151
|
-
try {
|
|
152
|
-
for (var unstyledColumns_1 = (e_2 = void 0, __values(unstyledColumns)), unstyledColumns_1_1 = unstyledColumns_1.next(); !unstyledColumns_1_1.done; unstyledColumns_1_1 = unstyledColumns_1.next()) {
|
|
153
|
-
var column = unstyledColumns_1_1.value;
|
|
154
|
-
expectDefaultCellStyleFor(row, column);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
158
|
-
finally {
|
|
159
|
-
try {
|
|
160
|
-
if (unstyledColumns_1_1 && !unstyledColumns_1_1.done && (_b = unstyledColumns_1.return)) _b.call(unstyledColumns_1);
|
|
161
|
-
}
|
|
162
|
-
finally { if (e_2) throw e_2.error; }
|
|
163
|
-
}
|
|
122
|
+
test('should get the default cell style for cells with no available style', () => {
|
|
123
|
+
const unstyledRows = [1, 3, 4, 5]; // row 0 is the column header, row 2 has a row-style
|
|
124
|
+
const unstyledColumns = [1, 2, 3, 5]; // column 0 is the row header, column 4 has a column-style
|
|
125
|
+
for (const row of unstyledRows) {
|
|
126
|
+
for (const column of unstyledColumns) {
|
|
127
|
+
expectDefaultCellStyleFor(row, column);
|
|
164
128
|
}
|
|
165
129
|
}
|
|
166
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
167
|
-
finally {
|
|
168
|
-
try {
|
|
169
|
-
if (unstyledRows_1_1 && !unstyledRows_1_1.done && (_a = unstyledRows_1.return)) _a.call(unstyledRows_1);
|
|
170
|
-
}
|
|
171
|
-
finally { if (e_1) throw e_1.error; }
|
|
172
|
-
}
|
|
173
130
|
});
|
|
174
|
-
test('should get cell style for (2, 3) is the highest priority',
|
|
175
|
-
expect(styledTable.stylesForTableCoordinates(2, 3).getOrThrow()).toEqual(
|
|
131
|
+
test('should get cell style for (2, 3) is the highest priority', () => {
|
|
132
|
+
expect(styledTable.stylesForTableCoordinates(2, 3).getOrThrow()).toEqual(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 12, weight: 600 }) }));
|
|
176
133
|
});
|
|
177
|
-
test('should get column header style for (0, 3) is the highest priority',
|
|
134
|
+
test('should get column header style for (0, 3) is the highest priority', () => {
|
|
178
135
|
// column header style for (0, 3) is the highest priority
|
|
179
|
-
expect(styledTable.stylesForTableCoordinates(0, 3).getOrThrow()).toEqual(
|
|
136
|
+
expect(styledTable.stylesForTableCoordinates(0, 3).getOrThrow()).toEqual(Object.assign(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), stylings_1.defaultColumnStyle), {
|
|
180
137
|
// these come from the default column header style
|
|
181
|
-
dimension:
|
|
138
|
+
dimension: Object.assign(Object.assign({}, stylings_1.defaultDimension), { height: 20, minHeight: 15 }),
|
|
182
139
|
// these come from setting the column header style
|
|
183
|
-
font:
|
|
140
|
+
font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) }));
|
|
184
141
|
});
|
|
185
|
-
test('should return a failure when getting a style for a column index that is too large',
|
|
186
|
-
|
|
142
|
+
test('should return a failure when getting a style for a column index that is too large', () => {
|
|
143
|
+
const result = styledTable.stylesForTableCoordinates(1, 6);
|
|
187
144
|
expect(result.failed).toBeTruthy();
|
|
188
145
|
expect(result.error).toEqual("(StyledTable::stylesFor) Invalid row and/or column index; row_index: 1; column_index: 6; valid_row_index: [0, 7); valid_column_index: [0, 6)");
|
|
189
146
|
});
|
|
190
|
-
test('should return a failure when getting a style for a column index that is less than 0',
|
|
191
|
-
|
|
147
|
+
test('should return a failure when getting a style for a column index that is less than 0', () => {
|
|
148
|
+
const result = styledTable.stylesForTableCoordinates(3, -1);
|
|
192
149
|
expect(result.failed).toBeTruthy();
|
|
193
150
|
expect(result.error).toEqual("(StyledTable::stylesFor) Invalid row and/or column index; row_index: 3; column_index: -1; valid_row_index: [0, 7); valid_column_index: [0, 6)");
|
|
194
151
|
});
|
|
195
|
-
test('should return a failure when getting a style for a row index that is less than 0',
|
|
196
|
-
|
|
152
|
+
test('should return a failure when getting a style for a row index that is less than 0', () => {
|
|
153
|
+
const result = styledTable.stylesForTableCoordinates(-1, 3);
|
|
197
154
|
expect(result.failed).toBeTruthy();
|
|
198
155
|
expect(result.error).toEqual("(StyledTable::stylesFor) Invalid row and/or column index; row_index: -1; column_index: 3; valid_row_index: [0, 7); valid_column_index: [0, 6)");
|
|
199
156
|
});
|
|
200
|
-
test('should return a failure when getting a style for a row index that is too large',
|
|
201
|
-
|
|
157
|
+
test('should return a failure when getting a style for a row index that is too large', () => {
|
|
158
|
+
const result = styledTable.stylesForTableCoordinates(7, 3);
|
|
202
159
|
expect(result.failed).toBeTruthy();
|
|
203
160
|
expect(result.error).toEqual("(StyledTable::stylesFor) Invalid row and/or column index; row_index: 7; column_index: 3; valid_row_index: [0, 7); valid_column_index: [0, 6)");
|
|
204
161
|
});
|
|
205
|
-
test('should get the row header style for (1, 0) because table has row header style',
|
|
206
|
-
expect(styledTable.stylesForTableCoordinates(1, 0).getOrThrow()).toEqual(
|
|
162
|
+
test('should get the row header style for (1, 0) because table has row header style', () => {
|
|
163
|
+
expect(styledTable.stylesForTableCoordinates(1, 0).getOrThrow()).toEqual(Object.assign(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), stylings_1.defaultRowHeaderStyle), { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 15, weight: 650 }) }));
|
|
207
164
|
});
|
|
208
|
-
test('should get column header style for (0, 4) because table has column header style',
|
|
209
|
-
expect(styledTable.stylesForTableCoordinates(0, 4).getOrThrow()).toEqual(
|
|
165
|
+
test('should get column header style for (0, 4) because table has column header style', () => {
|
|
166
|
+
expect(styledTable.stylesForTableCoordinates(0, 4).getOrThrow()).toEqual(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), {
|
|
210
167
|
// these come from the default column header style rather than the column style for
|
|
211
168
|
// the 4th column because the column header style has a higher priority
|
|
212
|
-
dimension:
|
|
169
|
+
dimension: Object.assign(Object.assign({}, stylings_1.defaultDimension), { height: 20, minHeight: 15 }),
|
|
213
170
|
// these come from setting the column header style
|
|
214
|
-
font:
|
|
171
|
+
font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 16, weight: 800 }) }));
|
|
215
172
|
});
|
|
216
|
-
test('should get column style for (1, 4) because table has column style',
|
|
217
|
-
expect(styledTable.stylesForTableCoordinates(1, 4).getOrThrow()).toEqual(
|
|
173
|
+
test('should get column style for (1, 4) because table has column style', () => {
|
|
174
|
+
expect(styledTable.stylesForTableCoordinates(1, 4).getOrThrow()).toEqual(Object.assign(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), stylings_1.defaultColumnStyle), { padding: Object.assign(Object.assign({}, stylings_1.defaultTablePadding), { left: 1000, right: 1111 }) }));
|
|
218
175
|
});
|
|
219
|
-
test('should get column style for (2, 4) because table has column style with higher priority than row-style',
|
|
220
|
-
expect(styledTable.stylesForTableCoordinates(2, 4).getOrThrow()).toEqual(
|
|
176
|
+
test('should get column style for (2, 4) because table has column style with higher priority than row-style', () => {
|
|
177
|
+
expect(styledTable.stylesForTableCoordinates(2, 4).getOrThrow()).toEqual(Object.assign(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), stylings_1.defaultColumnStyle), {
|
|
221
178
|
// the row style sets the font (column style doesn't) have font, and so the column style
|
|
222
179
|
// that overrides the row style doesn't change the font
|
|
223
|
-
font:
|
|
180
|
+
font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 14, weight: 700 }),
|
|
224
181
|
// and the column style sets the padding
|
|
225
|
-
padding:
|
|
182
|
+
padding: Object.assign(Object.assign({}, stylings_1.defaultTablePadding), { left: 1000, right: 1111 }) }));
|
|
226
183
|
});
|
|
227
|
-
test('should get column style for (3, 4) because table has column style with higher priority than row-style',
|
|
228
|
-
expect(styledTable.stylesForTableCoordinates(3, 4).getOrThrow()).toEqual(
|
|
184
|
+
test('should get column style for (3, 4) because table has column style with higher priority than row-style', () => {
|
|
185
|
+
expect(styledTable.stylesForTableCoordinates(3, 4).getOrThrow()).toEqual(Object.assign(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), stylings_1.defaultColumnStyle), { padding: Object.assign(Object.assign({}, stylings_1.defaultTablePadding), { left: 1000, right: 1111 }) }));
|
|
229
186
|
});
|
|
230
|
-
test('should be able to retrieve cell styles using data row and column indices',
|
|
187
|
+
test('should be able to retrieve cell styles using data row and column indices', () => {
|
|
231
188
|
// cell (2 ,3) in table coordinates translates to cell (1, 2) in data coordinates because
|
|
232
189
|
// the table has a column header and a row header. in this case the data coordinates are
|
|
233
190
|
// (table_row - 1, table_column - 1).
|
|
234
|
-
expect(styledTable.stylesForDataCoordinates(2 - 1, 3 - 1).getOrThrow()).toEqual(
|
|
191
|
+
expect(styledTable.stylesForDataCoordinates(2 - 1, 3 - 1).getOrThrow()).toEqual(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), { font: Object.assign(Object.assign({}, stylings_1.defaultTableFont), { size: 12, weight: 600 }) }));
|
|
235
192
|
});
|
|
236
193
|
});
|
|
237
|
-
describe('set styles for multiple rows, columns, and cells',
|
|
194
|
+
describe('set styles for multiple rows, columns, and cells', () => {
|
|
238
195
|
function expectDefaultCellStyleFor(styledTable, row, column) {
|
|
239
196
|
expect(styledTable.stylesForTableCoordinates(row, column).getOrThrow()).toEqual(stylings_1.defaultCellStyle);
|
|
240
197
|
}
|
|
241
|
-
test('should be able to set the style for multiple columns at once',
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
198
|
+
test('should be able to set the style for multiple columns at once', () => {
|
|
199
|
+
const styledColumns = [1, 3, 4];
|
|
200
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
245
201
|
.withColumnStyles(styledColumns, { padding: { left: 1000, right: 1111 } }, 75)
|
|
246
202
|
.styleTable();
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
for (
|
|
251
|
-
|
|
252
|
-
try {
|
|
253
|
-
for (var unstyledColumns_2 = (e_4 = void 0, __values(unstyledColumns)), unstyledColumns_2_1 = unstyledColumns_2.next(); !unstyledColumns_2_1.done; unstyledColumns_2_1 = unstyledColumns_2.next()) {
|
|
254
|
-
var column = unstyledColumns_2_1.value;
|
|
255
|
-
expectDefaultCellStyleFor(styledTable, row, column);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
259
|
-
finally {
|
|
260
|
-
try {
|
|
261
|
-
if (unstyledColumns_2_1 && !unstyledColumns_2_1.done && (_b = unstyledColumns_2.return)) _b.call(unstyledColumns_2);
|
|
262
|
-
}
|
|
263
|
-
finally { if (e_4) throw e_4.error; }
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
268
|
-
finally {
|
|
269
|
-
try {
|
|
270
|
-
if (unstyledRows_2_1 && !unstyledRows_2_1.done && (_a = unstyledRows_2.return)) _a.call(unstyledRows_2);
|
|
271
|
-
}
|
|
272
|
-
finally { if (e_3) throw e_3.error; }
|
|
273
|
-
}
|
|
274
|
-
try {
|
|
275
|
-
for (var styledColumns_1 = __values(styledColumns), styledColumns_1_1 = styledColumns_1.next(); !styledColumns_1_1.done; styledColumns_1_1 = styledColumns_1.next()) {
|
|
276
|
-
var column = styledColumns_1_1.value;
|
|
277
|
-
expect(styledTable.columnStyleFor(column).map(function (styling) { return styling.style; }).getOrThrow())
|
|
278
|
-
.toEqual(__assign(__assign({}, stylings_1.defaultColumnStyle), { padding: { left: 1000, right: 1111 } }));
|
|
203
|
+
const unstyledRows = [1, 3, 4, 5];
|
|
204
|
+
const unstyledColumns = [0, 2, 5];
|
|
205
|
+
for (const row of unstyledRows) {
|
|
206
|
+
for (const column of unstyledColumns) {
|
|
207
|
+
expectDefaultCellStyleFor(styledTable, row, column);
|
|
279
208
|
}
|
|
280
209
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
if (styledColumns_1_1 && !styledColumns_1_1.done && (_c = styledColumns_1.return)) _c.call(styledColumns_1);
|
|
285
|
-
}
|
|
286
|
-
finally { if (e_5) throw e_5.error; }
|
|
210
|
+
for (const column of styledColumns) {
|
|
211
|
+
expect(styledTable.columnStyleFor(column).map(styling => styling.style).getOrThrow())
|
|
212
|
+
.toEqual(Object.assign(Object.assign({}, stylings_1.defaultColumnStyle), { padding: { left: 1000, right: 1111 } }));
|
|
287
213
|
}
|
|
288
214
|
});
|
|
289
|
-
test('should be able to set the style for all columns at once',
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
var styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
215
|
+
test('should be able to set the style for all columns at once', () => {
|
|
216
|
+
const styledColumns = [0, 1, 2, 3, 4, 5];
|
|
217
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
293
218
|
// an empty array means that all the columns should be styled
|
|
294
219
|
.withColumnStyles([], { padding: { left: 1000, right: 1111 } }, 75)
|
|
295
220
|
.styleTable();
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
expect(styledTable.columnStyleFor(column).map(function (styling) { return styling.style; }).getOrThrow())
|
|
300
|
-
.toEqual(__assign(__assign({}, stylings_1.defaultColumnStyle), { padding: { left: 1000, right: 1111 } }));
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
304
|
-
finally {
|
|
305
|
-
try {
|
|
306
|
-
if (styledColumns_2_1 && !styledColumns_2_1.done && (_a = styledColumns_2.return)) _a.call(styledColumns_2);
|
|
307
|
-
}
|
|
308
|
-
finally { if (e_6) throw e_6.error; }
|
|
221
|
+
for (const column of styledColumns) {
|
|
222
|
+
expect(styledTable.columnStyleFor(column).map(styling => styling.style).getOrThrow())
|
|
223
|
+
.toEqual(Object.assign(Object.assign({}, stylings_1.defaultColumnStyle), { padding: { left: 1000, right: 1111 } }));
|
|
309
224
|
}
|
|
310
225
|
});
|
|
311
|
-
test('should be able to set the style for multiple rows at once',
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
var styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
226
|
+
test('should be able to set the style for multiple rows at once', () => {
|
|
227
|
+
const styledRows = [1, 3, 4];
|
|
228
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
315
229
|
.withRowStyles(styledRows, { padding: { top: 1000, bottom: 1111 } }, 75)
|
|
316
230
|
.styleTable();
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
for (
|
|
321
|
-
|
|
322
|
-
try {
|
|
323
|
-
for (var unstyledColumns_3 = (e_8 = void 0, __values(unstyledColumns)), unstyledColumns_3_1 = unstyledColumns_3.next(); !unstyledColumns_3_1.done; unstyledColumns_3_1 = unstyledColumns_3.next()) {
|
|
324
|
-
var column = unstyledColumns_3_1.value;
|
|
325
|
-
expectDefaultCellStyleFor(styledTable, row, column);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
329
|
-
finally {
|
|
330
|
-
try {
|
|
331
|
-
if (unstyledColumns_3_1 && !unstyledColumns_3_1.done && (_b = unstyledColumns_3.return)) _b.call(unstyledColumns_3);
|
|
332
|
-
}
|
|
333
|
-
finally { if (e_8) throw e_8.error; }
|
|
334
|
-
}
|
|
231
|
+
const unstyledRows = [0, 2];
|
|
232
|
+
const unstyledColumns = [0, 1, 2, 3, 4, 5];
|
|
233
|
+
for (const row of unstyledRows) {
|
|
234
|
+
for (const column of unstyledColumns) {
|
|
235
|
+
expectDefaultCellStyleFor(styledTable, row, column);
|
|
335
236
|
}
|
|
336
237
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (unstyledRows_3_1 && !unstyledRows_3_1.done && (_a = unstyledRows_3.return)) _a.call(unstyledRows_3);
|
|
341
|
-
}
|
|
342
|
-
finally { if (e_7) throw e_7.error; }
|
|
343
|
-
}
|
|
344
|
-
try {
|
|
345
|
-
for (var styledRows_1 = __values(styledRows), styledRows_1_1 = styledRows_1.next(); !styledRows_1_1.done; styledRows_1_1 = styledRows_1.next()) {
|
|
346
|
-
var row = styledRows_1_1.value;
|
|
347
|
-
expect(styledTable.rowStyleFor(row).map(function (styling) { return styling.style; }).getOrThrow())
|
|
348
|
-
.toEqual(__assign(__assign({}, stylings_1.defaultRowStyle), { padding: { top: 1000, bottom: 1111 } }));
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
352
|
-
finally {
|
|
353
|
-
try {
|
|
354
|
-
if (styledRows_1_1 && !styledRows_1_1.done && (_c = styledRows_1.return)) _c.call(styledRows_1);
|
|
355
|
-
}
|
|
356
|
-
finally { if (e_9) throw e_9.error; }
|
|
238
|
+
for (const row of styledRows) {
|
|
239
|
+
expect(styledTable.rowStyleFor(row).map(styling => styling.style).getOrThrow())
|
|
240
|
+
.toEqual(Object.assign(Object.assign({}, stylings_1.defaultRowStyle), { padding: { top: 1000, bottom: 1111 } }));
|
|
357
241
|
}
|
|
358
242
|
});
|
|
359
|
-
test('should be able to set the style for all rows at once',
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
var styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
243
|
+
test('should be able to set the style for all rows at once', () => {
|
|
244
|
+
const styledRows = [0, 1, 2, 3, 4];
|
|
245
|
+
const styledTable = TableStyler_1.TableStyler.fromTableData(formattedTableData)
|
|
363
246
|
// an empty array means that all the columns should be styled
|
|
364
247
|
.withRowStyles([], { padding: { top: 1000, bottom: 1111 } }, 75)
|
|
365
248
|
.styleTable();
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
expect(styledTable.rowStyleFor(row).map(function (styling) { return styling.style; }).getOrThrow())
|
|
370
|
-
.toEqual(__assign(__assign({}, stylings_1.defaultRowStyle), { padding: { top: 1000, bottom: 1111 } }));
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
374
|
-
finally {
|
|
375
|
-
try {
|
|
376
|
-
if (styledRows_2_1 && !styledRows_2_1.done && (_a = styledRows_2.return)) _a.call(styledRows_2);
|
|
377
|
-
}
|
|
378
|
-
finally { if (e_10) throw e_10.error; }
|
|
249
|
+
for (const row of styledRows) {
|
|
250
|
+
expect(styledTable.rowStyleFor(row).map(styling => styling.style).getOrThrow())
|
|
251
|
+
.toEqual(Object.assign(Object.assign({}, stylings_1.defaultRowStyle), { padding: { top: 1000, bottom: 1111 } }));
|
|
379
252
|
}
|
|
380
253
|
});
|
|
381
254
|
});
|
|
382
|
-
describe('conditionally set styles for cells',
|
|
255
|
+
describe('conditionally set styles for cells', () => {
|
|
383
256
|
function expectDefaultCellStyleFor(styledTable, row, column) {
|
|
384
257
|
expect(styledTable.stylesForTableCoordinates(row, column).getOrThrow()).toEqual(stylings_1.defaultCellStyle);
|
|
385
258
|
}
|
|
386
|
-
test('should be able to set the style for multiple columns at once',
|
|
387
|
-
var e_11, _a, e_12, _b, e_13, _c;
|
|
259
|
+
test('should be able to set the style for multiple columns at once', () => {
|
|
388
260
|
// const styledTable: StyledTable<string> = TableStyler.fromTableData(formattedTableData)
|
|
389
|
-
|
|
390
|
-
.withCellStyleWhen(
|
|
261
|
+
const styledTable = TableStyler_1.TableStyler.fromDataFrame(formattedTableData.unwrapDataFrame())
|
|
262
|
+
.withCellStyleWhen((value, _row, column) => parseInt(value) >= 45678 && column === 2, { padding: Object.assign(Object.assign({}, stylings_1.defaultTablePadding), { left: 1000, right: 1111 }) }, 75)
|
|
391
263
|
.styleTable();
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
for (
|
|
396
|
-
|
|
397
|
-
try {
|
|
398
|
-
for (var unstyledColumns_4 = (e_12 = void 0, __values(unstyledColumns)), unstyledColumns_4_1 = unstyledColumns_4.next(); !unstyledColumns_4_1.done; unstyledColumns_4_1 = unstyledColumns_4.next()) {
|
|
399
|
-
var column = unstyledColumns_4_1.value;
|
|
400
|
-
expectDefaultCellStyleFor(styledTable, row, column);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
404
|
-
finally {
|
|
405
|
-
try {
|
|
406
|
-
if (unstyledColumns_4_1 && !unstyledColumns_4_1.done && (_b = unstyledColumns_4.return)) _b.call(unstyledColumns_4);
|
|
407
|
-
}
|
|
408
|
-
finally { if (e_12) throw e_12.error; }
|
|
409
|
-
}
|
|
264
|
+
const unstyledColumns = [0, 1, 3, 4];
|
|
265
|
+
const unstyledRows = [0, 1, 2, 3, 4, 5];
|
|
266
|
+
for (const row of unstyledRows) {
|
|
267
|
+
for (const column of unstyledColumns) {
|
|
268
|
+
expectDefaultCellStyleFor(styledTable, row, column);
|
|
410
269
|
}
|
|
411
270
|
}
|
|
412
|
-
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
413
|
-
finally {
|
|
414
|
-
try {
|
|
415
|
-
if (unstyledRows_4_1 && !unstyledRows_4_1.done && (_a = unstyledRows_4.return)) _a.call(unstyledRows_4);
|
|
416
|
-
}
|
|
417
|
-
finally { if (e_11) throw e_11.error; }
|
|
418
|
-
}
|
|
419
271
|
expectDefaultCellStyleFor(styledTable, 0, 2);
|
|
420
272
|
expectDefaultCellStyleFor(styledTable, 1, 2);
|
|
421
273
|
expectDefaultCellStyleFor(styledTable, 2, 2);
|
|
422
274
|
expectDefaultCellStyleFor(styledTable, 3, 2);
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
expect(styledTable.cellStyleFor(row, 2).map(function (styling) { return styling.style; }).getOrThrow())
|
|
427
|
-
.toEqual(__assign(__assign({}, stylings_1.defaultCellStyle), { padding: __assign(__assign({}, stylings_1.defaultTablePadding), { left: 1000, right: 1111 }) }));
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
431
|
-
finally {
|
|
432
|
-
try {
|
|
433
|
-
if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
|
|
434
|
-
}
|
|
435
|
-
finally { if (e_13) throw e_13.error; }
|
|
275
|
+
for (const row of [4, 5]) {
|
|
276
|
+
expect(styledTable.cellStyleFor(row, 2).map(styling => styling.style).getOrThrow())
|
|
277
|
+
.toEqual(Object.assign(Object.assign({}, stylings_1.defaultCellStyle), { padding: Object.assign(Object.assign({}, stylings_1.defaultTablePadding), { left: 1000, right: 1111 }) }));
|
|
436
278
|
}
|
|
437
279
|
});
|
|
438
280
|
});
|