Kaydet (Commit) 3af8a4fa authored tarafından Vasily Melenchuk's avatar Vasily Melenchuk Kaydeden (comit) Thorsten Behrens

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/44755Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 1f4a1b74
...@@ -241,8 +241,8 @@ vector<ScTokenRef> TokenTable::getAllRanges() const ...@@ -241,8 +241,8 @@ vector<ScTokenRef> TokenTable::getAllRanges() const
return aTokens; return aTokens;
} }
typedef std::map<sal_uInt32, FormulaToken*> FormulaTokenMap; typedef std::map<SCROW, FormulaToken*> FormulaTokenMap;
typedef std::map<sal_uInt32, FormulaTokenMap*> FormulaTokenMapMap; typedef std::map<SCCOL, FormulaTokenMap*> FormulaTokenMapMap;
class Chart2PositionMap class Chart2PositionMap
{ {
...@@ -286,67 +286,66 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount, SCROW nAllRowCount, ...@@ -286,67 +286,66 @@ Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount, SCROW nAllRowCount,
SCROW nHeaderRowCount = (bFillColumnHeader && nAllColCount && nAllRowCount) ? 1 : 0; SCROW nHeaderRowCount = (bFillColumnHeader && nAllColCount && nAllRowCount) ? 1 : 0;
SCCOL nHeaderColCount = (bFillRowHeader && 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 //check whether there is more than one text column or row that should be added to the headers
SCROW nSmallestValueRowIndex = nAllRowCount; SCROW nMaxHeaderRow = nAllRowCount;
bool bFoundValues = false; for ( const auto & rCol : rCols )
bool bFoundAnything = false;
FormulaTokenMapMap::const_iterator it1 = rCols.begin();
for (SCCOL nCol = 0; nCol < nAllColCount; ++nCol)
{ {
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; // Skip header rows
FormulaTokenMap* pCol = it1->second; if (rCell.first < nHeaderRowCount )
FormulaTokenMap::const_iterator it2 = pCol->begin(); continue;
for (SCROW nRow = 0; !bFoundValuesInRow && nRow < nSmallestValueRowIndex && it2 != pCol->end(); ++nRow)
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; // Found some numeric data
if (pToken && nRow>=nHeaderRowCount) bFoundValuesInCol = true;
{ nMaxHeaderRow = std::min(nMaxHeaderRow, nRow1);
ScRange aRange; break;
bool bExternal = false; }
StackVar eType = pToken->GetType(); if ( pDoc->HasData( nCol1, nRow1, nTab1 ) )
if( eType==svExternal || eType==svExternalSingleRef || eType==svExternalDoubleRef || eType==svExternalName ) {
bExternal = true;//lllll todo correct? // Found some other data (non-numeric)
ScTokenRef pSharedToken(pToken->Clone()); bFoundAnythingInCol = true;
ScRefTokenHelper::getRangeFromToken(aRange, pSharedToken, ScAddress(), bExternal); }
SCCOL nCol1=0, nCol2=0; else
SCROW nRow1=0, nRow2=0; {
SCTAB nTab1=0, nTab2=0; // If cell is empty, it belongs to data
aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); nMaxHeaderRow = std::min(nMaxHeaderRow, nRow1);
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;
} }
if(!bFoundValues && nHeaderColCount>0)
nHeaderColCount++;
} }
++it1;
} if (nHeaderColCount && !bFoundValuesInCol && bFoundAnythingInCol && rCol.first == nHeaderColCount)
if( bFoundAnything )
{
if(nHeaderRowCount>0)
{ {
if( bFoundValues ) // There is no values in row, but some data. And this column is next to header
nHeaderRowCount = nSmallestValueRowIndex; // So lets put it to header
else if( nAllRowCount>1 ) nHeaderColCount++;
nHeaderRowCount = nAllRowCount-1;
} }
} }
else //if the cells are completely empty, just use single header rows and columns
nHeaderColCount = nInitialHeaderColCount; if (nHeaderRowCount)
{
nHeaderRowCount = nMaxHeaderRow;
}
} }
mnDataColCount = nAllColCount - nHeaderColCount; mnDataColCount = nAllColCount - nHeaderColCount;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment