| 18 | } |
| 19 | |
| 20 | render(xmlStream, model) { |
| 21 | // eslint-disable-next-line no-unused-vars |
| 22 | const {rows, columns, values, metric, cacheFields, cacheId} = model; |
| 23 | |
| 24 | // Examples |
| 25 | // -------- |
| 26 | // rows: [0, 1], // only 2 items possible for now |
| 27 | // columns: [2], // only 1 item possible for now |
| 28 | // values: [4], // only 1 item possible for now |
| 29 | // metric: 'sum', // only 'sum' possible for now |
| 30 | // |
| 31 | // the numbers are indices into `cacheFields`. |
| 32 | |
| 33 | xmlStream.openXml(XmlStream.StdDocAttributes); |
| 34 | xmlStream.openNode(this.tag, { |
| 35 | ...PivotTableXform.PIVOT_TABLE_ATTRIBUTES, |
| 36 | 'xr:uid': '{267EE50F-B116-784D-8DC2-BA77DE3F4F4A}', |
| 37 | name: 'PivotTable2', |
| 38 | cacheId, |
| 39 | applyNumberFormats: '0', |
| 40 | applyBorderFormats: '0', |
| 41 | applyFontFormats: '0', |
| 42 | applyPatternFormats: '0', |
| 43 | applyAlignmentFormats: '0', |
| 44 | applyWidthHeightFormats: '1', |
| 45 | dataCaption: 'Values', |
| 46 | updatedVersion: '8', |
| 47 | minRefreshableVersion: '3', |
| 48 | useAutoFormatting: '1', |
| 49 | itemPrintTitles: '1', |
| 50 | createdVersion: '8', |
| 51 | indent: '0', |
| 52 | compact: '0', |
| 53 | compactData: '0', |
| 54 | multipleFieldFilters: '0', |
| 55 | }); |
| 56 | |
| 57 | // Note: keeping this pretty-printed and verbose for now to ease debugging. |
| 58 | // |
| 59 | // location: ref="A3:E15" |
| 60 | // pivotFields |
| 61 | // rowFields and rowItems |
| 62 | // colFields and colItems |
| 63 | // dataFields |
| 64 | // pivotTableStyleInfo |
| 65 | xmlStream.writeXml(` |
| 66 | <location ref="A3:E15" firstHeaderRow="1" firstDataRow="2" firstDataCol="1" /> |
| 67 | <pivotFields count="${cacheFields.length}"> |
| 68 | ${renderPivotFields(model)} |
| 69 | </pivotFields> |
| 70 | <rowFields count="${rows.length}"> |
| 71 | ${rows.map(rowIndex => `<field x="${rowIndex}" />`).join('\n ')} |
| 72 | </rowFields> |
| 73 | <rowItems count="1"> |
| 74 | <i t="grand"><x /></i> |
| 75 | </rowItems> |
| 76 | <colFields count="${columns.length}"> |
| 77 | ${columns.map(columnIndex => `<field x="${columnIndex}" />`).join('\n ')} |