()
| 127 | } |
| 128 | |
| 129 | validate() { |
| 130 | const {table} = this; |
| 131 | // set defaults and check is valid |
| 132 | const assign = (o, name, dflt) => { |
| 133 | if (o[name] === undefined) { |
| 134 | o[name] = dflt; |
| 135 | } |
| 136 | }; |
| 137 | assign(table, 'headerRow', true); |
| 138 | assign(table, 'totalsRow', false); |
| 139 | |
| 140 | assign(table, 'style', {}); |
| 141 | assign(table.style, 'theme', 'TableStyleMedium2'); |
| 142 | assign(table.style, 'showFirstColumn', false); |
| 143 | assign(table.style, 'showLastColumn', false); |
| 144 | assign(table.style, 'showRowStripes', false); |
| 145 | assign(table.style, 'showColumnStripes', false); |
| 146 | |
| 147 | const assert = (test, message) => { |
| 148 | if (!test) { |
| 149 | throw new Error(message); |
| 150 | } |
| 151 | }; |
| 152 | assert(table.ref, 'Table must have ref'); |
| 153 | assert(table.columns, 'Table must have column definitions'); |
| 154 | assert(table.rows, 'Table must have row definitions'); |
| 155 | |
| 156 | table.tl = colCache.decodeAddress(table.ref); |
| 157 | const {row, col} = table.tl; |
| 158 | assert(row > 0, 'Table must be on valid row'); |
| 159 | assert(col > 0, 'Table must be on valid col'); |
| 160 | |
| 161 | const {width, filterHeight, tableHeight} = this; |
| 162 | |
| 163 | // autoFilterRef is a range that includes optional headers only |
| 164 | table.autoFilterRef = colCache.encode(row, col, row + filterHeight - 1, col + width - 1); |
| 165 | |
| 166 | // tableRef is a range that includes optional headers and totals |
| 167 | table.tableRef = colCache.encode(row, col, row + tableHeight - 1, col + width - 1); |
| 168 | |
| 169 | table.columns.forEach((column, i) => { |
| 170 | assert(column.name, `Column ${i} must have a name`); |
| 171 | if (i === 0) { |
| 172 | assign(column, 'totalsRowLabel', 'Total'); |
| 173 | } else { |
| 174 | assign(column, 'totalsRowFunction', 'none'); |
| 175 | column.totalsRowFormula = this.getFormula(column); |
| 176 | } |
| 177 | }); |
| 178 | } |
| 179 | |
| 180 | store() { |
| 181 | // where the table needs to store table data, headers, footers in |
no test coverage detected