diff --git a/src/data-table/index.jsx b/src/data-table/index.jsx index d7fb9ab..a64e43c 100644 --- a/src/data-table/index.jsx +++ b/src/data-table/index.jsx @@ -43,20 +43,42 @@ class DataTable extends React.PureComponent { return injectSeparatorsArray; } - let measurementDataRow = [], - index = 0; + const measurementDataRow = []; + let index = 0, + match; dimension2.forEach((dim2) => { - measurements.forEach((measure) => { + measurements.forEach((measure, mesInd) => { for (index = 0; index < injectSeparatorsArray.length; index++) { + match = false; if (injectSeparatorsArray[index].parents && dimension1[dimIndex].displayValue === injectSeparatorsArray[index].parents.dimension1.header) { if (dim2.displayValue === injectSeparatorsArray[index].parents.dimension2.header) { if (measure.name === injectSeparatorsArray[index].parents.measurement.header) { measurementDataRow.push(injectSeparatorsArray[index]); + match = true; break; } } } } + if (!match) { + measurementDataRow.push({ + displayValue: '', + parents: { + dimension1: { + elementNumber: dimension1[dimIndex].elementNumber, + header: dimension1[dimIndex].displayValue + }, + dimension2: { + elementNumber: dim2.elementNumber, + header: dim2.displayValue + }, + measurement: { + header: measure.name, + index: mesInd + } + } + }); + } }); }); return measurementDataRow; diff --git a/src/initialize-transformed.js b/src/initialize-transformed.js index b29207b..d89880b 100644 --- a/src/initialize-transformed.js +++ b/src/initialize-transformed.js @@ -127,30 +127,6 @@ function generateDataSet (component, dimensionsInformation, measurementsInformat dimension1 = distinctArray(dimension1); dimension2 = distinctArray(dimension2); - // Make sure all rows are saturated, otherwise data risks being displayed in the wrong column - matrix = matrix.map((row, rowIndex) => { - if ((hasSecondDimension && row.length == (dimension2.length * measurements.length)) - || (!hasSecondDimension && row.length == measurements.length)) { - // Row is saturated - return row; - } - - // Row is not saturated, so must add empty cells to fill the gaps - let newRow = []; - if (hasSecondDimension) { - // Got a second dimension, so need to add measurements for all values of the second dimension - let rowDataIndex = 0; - dimension2.forEach(dim => { - rowDataIndex = appendMissingCells( - row, newRow, rowDataIndex, measurements, rowIndex, dim, dimension1); - }); - } else { - appendMissingCells(row, newRow, 0, measurements, rowIndex); - } - - return newRow; - }); - return { dimension1: dimension1, dimension2: dimension2, @@ -159,45 +135,6 @@ function generateDataSet (component, dimensionsInformation, measurementsInformat }; } -/* - * Appends the cells of the source row, as well as those missing, to the destination row, starting - * from the given source index. Returns the source index of the next source cell after this has - * completed. If there is a second dimension the dim2ElementNumber should be set to the current - * index of the dimension2 value being processed. - */ -function appendMissingCells ( - sourceRow, destRow, sourceIndex, measurements, matrixIndex, dim2, dim1) { - - let index = sourceIndex; - measurements.forEach((measurement, measureIndex) => { - if (index < sourceRow.length) { - // Source contains the expected cell - destRow.push(sourceRow[index]); - index++; - } else { - // Source doesn't contain the expected cell, so add empty - destRow.push({ - displayValue: '', - parents: { - dimension1: { - elementNumber: dim1[matrixIndex].elementNumber, - header: dim1[matrixIndex].displayValue - }, - dimension2: { - elementNumber: dim2.elementNumber, - header: dim2.displayValue - }, - measurement: { - header: measurement.name, - index: measureIndex - } - } - }); - } - }); - return index; -} - function initializeTransformed ({ component, dataCube, designList, layout }) { const dimensionsInformation = component.backendApi.getDimensionInfos(); const measurementsInformation = component.backendApi.getMeasureInfos();