// (C) 2007-2019 GoodData Corporation /** * Calculates size of result from headers. Previously, code was calculating size from data - which is not * entirely correct as attribute-only AFM will generate headers and empty data and the total size will be that * of the number of headers. * * @param headers headers in dimensions - type is not really needed here, looking at cardinalities */ export function getSizeFromHeaders(headers: any[][][]): number[] { if (headers === undefined || headers.length === 0) { // we have tests asserting that empty result always has size of 1... return [1]; } const rowHeaders = headers[0]; const colHeaders = headers[1]; if ( (rowHeaders[0] === undefined || rowHeaders[0].length === 0) && (colHeaders[0] === undefined || colHeaders[0].length === 0) ) { // we have tests asserting that empty result always has size of 1... return [1]; } const result = []; result.push(rowHeaders !== undefined && rowHeaders[0] !== undefined ? rowHeaders[0].length : 1); if (colHeaders !== undefined && colHeaders[0] !== undefined) { // only add second dimension size in case the second dimension is there result.push(colHeaders[0].length); } return result; }