diff options
author | Vasily Melenchuk <Vasily.Melenchuk@cib.de> | 2017-11-15 13:10:40 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-11-18 11:15:51 +0100 |
commit | 3af8a4faf5e20ccae2386052697713da160afb16 (patch) | |
tree | dc93627db033cc96ef24ac04f3dfd8dddca66a7c | |
parent | 1f4a1b74369caa1a61026b7776abe13f24ed48c1 (diff) |
tdf#113861: Less aggressive expansion of chart headers.
For sheets with low data density (many empty cells) created charts with
checked "First row as label" or "First column as label" can get too much
extra rows/columns from data range (if they contain no data).
New approach is to treat empty cells as belonging to data, not to headers.
Change-Id: Ib5fd47636b80e0b8807f75d9eb582eed0ef68627
Reviewed-on: https://gerrit.libreoffice.org/44755
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | sc/source/ui/unoobj/chart2uno.cxx | 105 |
1 files changed, 52 insertions, 53 deletions
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx index 454a2f3de9e1..f280a14c42fd 100644 --- a/sc/source/ui/unoobj/chart2uno.cxx +++ b/sc/source/ui/unoobj/chart2uno.cxx @@ -241,8 +241,8 @@ vector<ScTokenRef> TokenTable::getAllRanges() const return aTokens; } -typedef std::map<sal_uInt32, FormulaToken*> FormulaTokenMap; -typedef std::map<sal_uInt32, FormulaTokenMap*> FormulaTokenMapMap; +typedef std::map<SCROW, FormulaToken*> FormulaTokenMap; +typedef std::map<SCCOL, FormulaTokenMap*> FormulaTokenMapMap; class Chart2PositionMap { @@ -286,67 +286,66 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount, SCROW nAllRowCount, SCROW nHeaderRowCount = (bFillColumnHeader && nAllColCount && nAllRowCount) ? 1 : 0; SCCOL nHeaderColCount = (bFillRowHeader && nAllColCount && nAllRowCount) ? 1 : 0; - if( nHeaderColCount || nHeaderRowCount ) + if( pDoc && (nHeaderColCount || nHeaderRowCount ) ) { - const SCCOL nInitialHeaderColCount = nHeaderColCount; //check whether there is more than one text column or row that should be added to the headers - SCROW nSmallestValueRowIndex = nAllRowCount; - bool bFoundValues = false; - bool bFoundAnything = false; - FormulaTokenMapMap::const_iterator it1 = rCols.begin(); - for (SCCOL nCol = 0; nCol < nAllColCount; ++nCol) + SCROW nMaxHeaderRow = nAllRowCount; + for ( const auto & rCol : rCols ) { - if (it1 != rCols.end() && nCol>=nHeaderColCount) + // Skip header columns + if ( rCol.first < nHeaderColCount ) + continue; + + bool bFoundValuesInCol = false; + bool bFoundAnythingInCol = false; + for ( const auto & rCell : *rCol.second ) { - bool bFoundValuesInRow = false; - FormulaTokenMap* pCol = it1->second; - FormulaTokenMap::const_iterator it2 = pCol->begin(); - for (SCROW nRow = 0; !bFoundValuesInRow && nRow < nSmallestValueRowIndex && it2 != pCol->end(); ++nRow) + // Skip header rows + if (rCell.first < nHeaderRowCount ) + continue; + + ScRange aRange; + bool bExternal = false; + StackVar eType = rCell.second->GetType(); + if( eType==svExternal || eType==svExternalSingleRef || eType==svExternalDoubleRef || eType==svExternalName ) + bExternal = true;//lllll todo correct? + ScTokenRef pSharedToken(rCell.second->Clone()); + ScRefTokenHelper::getRangeFromToken(aRange, pSharedToken, ScAddress(), bExternal); + SCCOL nCol1=0, nCol2=0; + SCROW nRow1=0, nRow2=0; + SCTAB nTab1=0, nTab2=0; + aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); + if ( pDoc->HasValueData( nCol1, nRow1, nTab1 ) ) { - FormulaToken* pToken = it2->second; - if (pToken && nRow>=nHeaderRowCount) - { - ScRange aRange; - bool bExternal = false; - StackVar eType = pToken->GetType(); - if( eType==svExternal || eType==svExternalSingleRef || eType==svExternalDoubleRef || eType==svExternalName ) - bExternal = true;//lllll todo correct? - ScTokenRef pSharedToken(pToken->Clone()); - ScRefTokenHelper::getRangeFromToken(aRange, pSharedToken, ScAddress(), bExternal); - SCCOL nCol1=0, nCol2=0; - SCROW nRow1=0, nRow2=0; - SCTAB nTab1=0, nTab2=0; - aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); - if (pDoc && pDoc->HasValueData( nCol1, nRow1, nTab1 )) - { - bFoundValuesInRow = bFoundValues = bFoundAnything = true; - nSmallestValueRowIndex = std::min( nSmallestValueRowIndex, nRow ); - } - if( !bFoundAnything ) - { - if (pDoc && pDoc->HasData( nCol1, nRow1, nTab1 ) ) - bFoundAnything = true; - } - } - ++it2; + // Found some numeric data + bFoundValuesInCol = true; + nMaxHeaderRow = std::min(nMaxHeaderRow, nRow1); + break; + } + if ( pDoc->HasData( nCol1, nRow1, nTab1 ) ) + { + // Found some other data (non-numeric) + bFoundAnythingInCol = true; + } + else + { + // If cell is empty, it belongs to data + nMaxHeaderRow = std::min(nMaxHeaderRow, nRow1); } - if(!bFoundValues && nHeaderColCount>0) - nHeaderColCount++; } - ++it1; - } - if( bFoundAnything ) - { - if(nHeaderRowCount>0) + + if (nHeaderColCount && !bFoundValuesInCol && bFoundAnythingInCol && rCol.first == nHeaderColCount) { - if( bFoundValues ) - nHeaderRowCount = nSmallestValueRowIndex; - else if( nAllRowCount>1 ) - nHeaderRowCount = nAllRowCount-1; + // There is no values in row, but some data. And this column is next to header + // So lets put it to header + nHeaderColCount++; } } - else //if the cells are completely empty, just use single header rows and columns - nHeaderColCount = nInitialHeaderColCount; + + if (nHeaderRowCount) + { + nHeaderRowCount = nMaxHeaderRow; + } } mnDataColCount = nAllColCount - nHeaderColCount; |