Skip to content

Commit

Permalink
renaming and doc adjustemnt
Browse files Browse the repository at this point in the history
  • Loading branch information
arng40 committed Dec 16, 2024
1 parent 68decb5 commit c1a2f06
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 75 deletions.
45 changes: 24 additions & 21 deletions src/coreComponents/common/format/table/TableFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,14 @@ void TableTextFormatter::populateHeaderCellsLayout( TableLayout & tableLayout,
for( size_t idxRow = currentLayer; idxRow < headerLayersCount - 1; idxRow++ )
{
TableLayout::CellLayout emptyCell{CellType::Header, "", TableLayout::Alignment::center};
emptyCell.m_maxLineWidth = it->m_header.m_maxLineWidth;
emptyCell.m_cellWidth = it->m_header.m_cellWidth;
cellsHeaderLayout[idxRow + 1].push_back( emptyCell );
}
}
currentCell.m_maxLineWidth = it->m_header.m_maxLineWidth;
currentCell.m_cellWidth = it->m_header.m_cellWidth;

if( it->hasParent() && it->getParent()->getNumberCellMerge() == 0 )
{

it->getParent()->incrementMergeHeaderCount();
}

Expand Down Expand Up @@ -369,14 +368,14 @@ void TableTextFormatter::updateColumnMaxLength( TableLayout & tableLayout,
{
if( previousCell && previousCell->m_cellType == CellType::MergeNext )
{
size_t const previousCellMaxLength = previousCell->m_maxLineWidth;
size_t const previousCellMaxLength = previousCell->m_cellWidth;
size_t const additionalMargin = tableLayout.getColumnMargin();
cell.m_maxLineWidth = maxColumnSize + previousCellMaxLength + additionalMargin;
previousCell->m_maxLineWidth = 0;
cell.m_cellWidth = maxColumnSize + previousCellMaxLength + additionalMargin;
previousCell->m_cellWidth = 0;
}
else
{
cell.m_maxLineWidth = maxColumnSize;
cell.m_cellWidth = maxColumnSize;
}
};

Expand All @@ -398,33 +397,37 @@ void TableTextFormatter::updateColumnMaxLength( TableLayout & tableLayout,
{
size_t const cellHeaderLength = getMaxLineLength( cellsHeaderLayout[rowIdx][idxColumn].m_lines );
maxColumnSize = std::max( {maxColumnSize, cellHeaderLength} );
cellsHeaderLayout[rowIdx][idxColumn].m_maxLineWidth = maxColumnSize;
cellsHeaderLayout[rowIdx][idxColumn].m_cellWidth = maxColumnSize;
}

// update maxColumnSize for data cell
for( size_t rowIdx = 0; rowIdx < cellsDataLayout.size(); ++rowIdx )
{
TableLayout::CellLayout & dataCell = cellsDataLayout[rowIdx][idxColumn];
TableLayout::CellLayout * previousDataCell = (idxColumn > 0) ? &cellsDataLayout[rowIdx][idxColumn - 1] : nullptr;
TableLayout::CellLayout * previousDataCell = (idxColumn > 0) ?
&cellsDataLayout[rowIdx][idxColumn - 1] :
nullptr;

if( dataCell.m_cellType == CellType::MergeNext )
{
accMaxStringColumn[rowIdx] += cellsHeaderLayout[0][idxColumn].m_maxLineWidth + tableLayout.getColumnMargin();
accMaxStringColumn[rowIdx] += cellsHeaderLayout[0][idxColumn].m_cellWidth + tableLayout.getColumnMargin();
}

if( idxColumn > 0 &&
previousDataCell->m_cellType == CellType::MergeNext && dataCell.m_cellType != CellType::MergeNext )
{
size_t sumOfMergingCell = accMaxStringColumn[rowIdx] + cellsHeaderLayout[0][idxColumn].m_maxLineWidth;
if( sumOfMergingCell < dataCell.m_maxLineWidth )
size_t sumOfMergingCell = accMaxStringColumn[rowIdx] + cellsHeaderLayout[0][idxColumn].m_cellWidth;
if( sumOfMergingCell < dataCell.m_cellWidth )
{
maxColumnSize += dataCell.m_maxLineWidth - sumOfMergingCell;
maxColumnSize += dataCell.m_cellWidth - sumOfMergingCell;
for( size_t rowIdx2 = 0; rowIdx2 < rowIdx; rowIdx2++ )
{
TableLayout::CellLayout * previousDataCellTemp = (idxColumn > 0) ? &cellsDataLayout[rowIdx2][idxColumn - 1] : nullptr;
TableLayout::CellLayout * previousDataCellTemp = (idxColumn > 0) ?
&cellsDataLayout[rowIdx2][idxColumn - 1] :
nullptr;
if( previousDataCellTemp )
{
previousDataCellTemp->m_maxLineWidth = cellsHeaderLayout[0][idxColumn - 1].m_maxLineWidth;
previousDataCellTemp->m_cellWidth = cellsHeaderLayout[0][idxColumn - 1].m_cellWidth;
}
updateCellMaxLength( cellsDataLayout[rowIdx2][idxColumn], maxColumnSize, previousDataCellTemp );
if( cellsDataLayout[rowIdx2][idxColumn].m_cellType == CellType::Separator )
Expand All @@ -449,7 +452,7 @@ void TableTextFormatter::updateColumnMaxLength( TableLayout & tableLayout,

if( dataCell.m_cellType == CellType::Separator )
{
size_t separatorLength = dataCell.m_maxLineWidth;
size_t separatorLength = dataCell.m_cellWidth;
separatorLength += (idxColumn == numColumns - 1) ?
tableLayout.getBorderMargin() * 2 + 2 :
tableLayout.getColumnMargin();
Expand Down Expand Up @@ -492,7 +495,7 @@ void TableTextFormatter::calculateTableSeparators( TableLayout & tableLayout,
}
if( column.m_cellType != CellType::Hidden && column.m_cellType != CellType::MergeNext )
{
sectionlineLength += column.m_maxLineWidth;
sectionlineLength += column.m_cellWidth;
nbColumns++;
}
}
Expand Down Expand Up @@ -541,15 +544,15 @@ void TableTextFormatter::adjustColumnWidths( CellLayoutRows & cells,
if( idxColumn > 0 && cells[idxRow][idxColumn - 1].m_cellType == CellType::MergeNext )
{
auto * previousCell = &cells[idxRow][idxColumn - 1];
currentCell.m_maxLineWidth += previousCell->m_maxLineWidth;
previousCell->m_maxLineWidth = 0;
currentCell.m_cellWidth += previousCell->m_cellWidth;
previousCell->m_cellWidth = 0;
}

size_t const additionalPadding = (isLastVisibleColumn || idxColumn == nbColumns - 1) ?
remainingPaddingForLastColumn :
0;

currentCell.m_maxLineWidth += paddingPerColumn + additionalPadding;
currentCell.m_cellWidth += paddingPerColumn + additionalPadding;
}
}
}
Expand Down Expand Up @@ -580,7 +583,7 @@ void TableTextFormatter::formatCell( TableLayout & tableLayout,
GEOS_UNUSED_VAR( tableLayout );
tableOutput << buildCell( cell.m_alignment,
cell.m_lines[idxLine],
cell.m_maxLineWidth );
cell.m_cellWidth );
}

void TableTextFormatter::outputLines( TableLayout & tableLayout,
Expand Down
11 changes: 7 additions & 4 deletions src/coreComponents/common/format/table/TableFormatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class TableTextFormatter : public TableFormatter

/// symbol for separator construction
static constexpr char m_verticalLine = '|';
/// for the extremity of a row
/// for the extremity of a row
static constexpr char m_horizontalLine = '-';


Expand Down Expand Up @@ -199,17 +199,20 @@ class TableTextFormatter : public TableFormatter
/**
* @brief Finds and sets the longest string for each column in the table.
* @param tableLayout The layout of the table,
* @param cellHeaderLength A reference to the collection of data cells. The function updates the maximum string
* @param cellHeaderLength A reference to the collection of data cells.
* The function updates the maximum string
* length for each cell based on the longest string found in the column.
* @param cellsDataLayout A reference to the collection of data cells. The function updates the maximum string
* @param cellsDataLayout A reference to the collection of data cells.
* The function updates the maximum string
* length for each cell based on the longest string found in the column.
*/
void updateColumnMaxLength( TableLayout & tableLayout,
CellLayoutRows & cellHeaderLength,
CellLayoutRows & cellsDataLayout ) const;

/**
* @brief Computes and constructs the separator lines for the table. Adjust columns if the title is the largest row
* @brief Computes and constructs the separator lines for the table.
* Adjust columns if the title is the largest row
* @param tableLayout The layout of the table,
* @param cellsHeaderLayout A reference to the collection of header cells that can be affected by column resizing.
* @param cellsDataLayout A reference to the collection of data cells that can be affected by column resizing.
Expand Down
56 changes: 17 additions & 39 deletions src/coreComponents/common/format/table/TableLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ TableLayout & TableLayout::setMargin( MarginValue marginValue )
}

bool TableLayout::isLineBreakEnabled() const
{
return m_wrapLine;
}
{ return m_wrapLine; }

size_t TableLayout::getMaxHeaderRow() const
{
Expand All @@ -86,49 +84,31 @@ size_t TableLayout::getMaxHeaderRow() const
}

std::vector< TableLayout::Column > & TableLayout::getColumns()
{
return m_tableColumnsData;
}
{ return m_tableColumnsData; }

std::vector< TableLayout::Column > const & TableLayout::getColumns() const
{
return m_tableColumnsData;
}
{ return m_tableColumnsData; }

string_view TableLayout::getTitle() const
{
return m_tableTitle;
}
{ return m_tableTitle; }

integer const & TableLayout::getBorderMargin() const
{
return m_borderMargin;
}
{ return m_borderMargin; }

integer const & TableLayout::getColumnMargin() const
{
return m_columnMargin;
}
{ return m_columnMargin; }

integer const & TableLayout::getMarginValue() const
{
return m_marginValue;
}
{ return m_marginValue; }

integer const & TableLayout::getMarginTitle() const
{
return m_titleMargin;
}
{ return m_titleMargin; }

std::vector< size_t > & TableLayout::getSublineInHeaderCounts()
{
return m_sublineHeaderCounts;
}
{ return m_sublineHeaderCounts; }

std::vector< size_t > & TableLayout::getNbSubDataLines()
{
return m_sublineDataCounts;
}
{ return m_sublineDataCounts; }

void divideCell( std::vector< string > & lines, string const & value )
{
Expand All @@ -150,7 +130,7 @@ TableLayout::CellLayout::CellLayout():
m_lines( {""} ),
m_cellType( CellType::Header ),
m_alignment( TableLayout::Alignment::center ),
m_maxLineWidth( 0 )
m_cellWidth( 0 )
{}

TableLayout::CellLayout::CellLayout( CellType type, string const & cellValue, TableLayout::Alignment alignment ):
Expand All @@ -160,14 +140,14 @@ TableLayout::CellLayout::CellLayout( CellType type, string const & cellValue, Ta
divideCell( m_lines, cellValue );
if( !m_lines.empty())
{
m_maxLineWidth = std::max_element( m_lines.begin(), m_lines.end(), []( const auto & a, const auto & b )
m_cellWidth = std::max_element( m_lines.begin(), m_lines.end(), []( const auto & a, const auto & b )
{
return a.length() < b.length();
} )->length();
}
else
{
m_maxLineWidth = 0;
m_cellWidth = 0;
}
}

Expand All @@ -181,9 +161,7 @@ TableLayout::Column::Column():

TableLayout::Column::Column( TableLayout::CellLayout cell ):
m_parent( nullptr ), m_next( nullptr )
{
m_header = cell;
}
{ m_header = cell; }


TableLayout::Column & TableLayout::Column::setName( string_view name )
Expand All @@ -194,9 +172,9 @@ TableLayout::Column & TableLayout::Column::setName( string_view name )
return *this;
}

TableLayout::Column & TableLayout::Column::hide()
TableLayout::Column & TableLayout::Column::setVisibility( CellType celltype )
{
m_header.m_cellType = CellType::Hidden;
m_header.m_cellType = celltype;
return *this;
}

Expand Down Expand Up @@ -243,7 +221,7 @@ TableLayout::Column & TableLayout::Column::setValuesAlignment( Alignment valueAl
size_t TableLayout::Column::getNumberCellMerge()
{ return m_headerMergeCount; }

void TableLayout::Column::incrementMergeHeaderCount()
void TableLayout::Column::incrementMergeHeaderCount()
{ m_headerMergeCount++;}

void TableLayout::Column::decrementMergeHeaderCount()
Expand Down
19 changes: 11 additions & 8 deletions src/coreComponents/common/format/table/TableLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class TableLayout
/// The alignment of the cell (left, center, right).
Alignment m_alignment;
/// Maximum length of the data in the cell.
size_t m_maxLineWidth;
size_t m_cellWidth;

/**
* @brief Constructor to initialize a Cell with a default settings.
Expand Down Expand Up @@ -141,10 +141,10 @@ class TableLayout
Column & setName( string_view name );

/**
* @brief Hides the column.
* @return The current column objec.
* @brief Set the column visibility.
* @return The current column .
*/
Column & hide();
Column & setVisibility( CellType celltype );

/**
* @brief Adds multiple sub-columns to the column.
Expand Down Expand Up @@ -218,7 +218,8 @@ class TableLayout
};

/**
* @brief An iterator for navigating through the leaf columns of a hierarchical column structure.
* @brief Iterator to loop over all columns, starting by the deepest sub columns,
* then to their parents, then to their siblings.
*/
class LeafIterator
{
Expand All @@ -227,7 +228,7 @@ class TableLayout

/**
* @brief Construct a new Leaf Iterator object
* @param columnPtr The first column/subColumn of the column vector
* @param columnPtr The first deepest column of vector
* @param idxLayer the layer associated with the column
*/
LeafIterator( ColumnType * columnPtr, size_t idxLayer ):
Expand Down Expand Up @@ -463,12 +464,14 @@ class TableLayout


/**
* @return The border margin, number of spaces at both left and right table sides plus vertical character
* @return The border margin,
* number of spaces at both left and right table sides plus vertical character
*/
integer const & getBorderMargin() const;

/**
* @return The column margin, numbers of spaces separating both left and right side from a vertical line
* @return The column margin,
* numbers of spaces separating both left and right side from a vertical line
*/
integer const & getColumnMargin() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TEST( testTable, tableHiddenColumn )
.setName( "CoordX" )
.setValuesAlignment( TableLayout::Alignment::left )
.setHeaderAlignment( TableLayout::Alignment::right )
.hide(),
.setVisibility( CellType::Hidden ),
TableLayout::Column()
.setName( "C" )
.setValuesAlignment( TableLayout::Alignment::left )
Expand All @@ -145,10 +145,10 @@ TEST( testTable, tableHiddenColumn )
.setHeaderAlignment( TableLayout::Alignment::left ),
TableLayout::Column()
.setName( "Prev\nelement" )
.hide(),
.setVisibility( CellType::Hidden ),
TableLayout::Column()
.setName( "Next\nelement" )
.hide()
.setVisibility( CellType::Hidden )
} );

TableData tableData;
Expand Down

0 comments on commit c1a2f06

Please sign in to comment.