Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Table subs division #3353

Closed
wants to merge 255 commits into from
Closed

feat: Table subs division #3353

wants to merge 255 commits into from

Conversation

arng40
Copy link
Contributor

@arng40 arng40 commented Sep 13, 2024

This PR allows the table to be subdivided, but also simplifies the declaration of the table.
Column declarations can be mixed with string and ColumnParam struct, I.E:

TableLayout const layoutTest( "Rank",
                             TableLayout::ColumnParam{"Nodes", TableLayout::Alignment::center},
                             "Edge",
                             TableLayout::ColumnParam{"Faces", TableLayout::Alignment::center},
                             TableLayout::ColumnParam{"Elems", TableLayout::Alignment::center} );

For an example with sub-columns, this will give the following result

TableLayout const layoutTest( "Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus ",
                             { "Rank",
                                TableLayout::ColumnParam{"Nodes", TableLayout::Alignment::center, true, {"local", "ghost"}},
                                "Edge",
                                TableLayout::ColumnParam{"Faces", {"local", "ghost"}},
                                TableLayout::ColumnParam{"Elems", TableLayout::Alignment::center, true, {"local", "ghost"}} 
   			      });

[data decleration]

Output :

               "--------------------------------------------------------------------------------------------------------------------------------------"
               "|  Cras egestas ipsum a nisl. Vivamus variu dolor utsisicdis parturient montes, nascetur ridiculus mus. Duis nascetur ridiculus mus  |"
               "--------------------------------------------------------------------------------------------------------------------------------------"
               "|                         Rank  |           Nodes           |      Edge      |           Faces           |           Elems           |"
               "--------------------------------------------------------------------------------------------------------------------------------------"
               "|                               |    local    |    ghost    |                |    local    |    ghost    |    local    |    ghost    |"
               "--------------------------------------------------------------------------------------------------------------------------------------"
               "|             min(local/total)  |      1      |      2      |       3        |      4      |      5      |      6      |      7      |"
               "|             min(local/total)  |      1      |      2      |       3        |      4      |      5      |      6      |      7      |"
               "--------------------------------------------------------------------------------------------------------------------------------------"

Also, column titles are now centered by default, regardless on the content alignement.

…feature/dudes/table-layout"

This reverts commit 8f74cfa.
Copy link
Contributor

@MelReyCG MelReyCG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass on test & general functionnalities

TableLayout::Column{{"CoordZ"}, TableLayout::Alignment::left},
TableLayout::Column{{"Prev\nelement"}, TableLayout::Alignment::right},
TableLayout::Column{{"Next\nelement"}, TableLayout::Alignment::right}} );
tableLayout.setValuesAlignment( TableLayout::Alignment::right );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal of this test to consolidate the setValuesAlignment() code?
If so,

  • keep tableLayout non-const,
  • use your builder pattern here,
  • no need to test that more that one time, it makes test heavier for no purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setValuesAlignment is for cellValues and alignement TableLayout::Column{} is for header alignment

Copy link
Contributor

@MelReyCG MelReyCG Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I see, this is not what we discussed at first, but it is good to be able to modify both setting by this way.
So two requests:

  • Keep in mind that the value alignement is more likely to be customised than the header alignement. So please modify the valueAlignment in the Column constructors.
  • Test the setValuesAlignment() only one time.
  • use your builder pattern here, and declare tableLayout constant.

Comment on lines 308 to 315
TEST( testTable, testLineWrap )
{
////////////
//////// If setMargin used elsewhere make it public and remove comments for this test
////////////
//test with tiny margin
// {
// TableLayout tableLayout( {
// TableLayout::ColumnParam{{"Colonne 1"}, TableLayout::Alignment::center},
// TableLayout::ColumnParam{{"Colonne 2"}, TableLayout::Alignment::center},
// TableLayout::ColumnParam{{"Colonne 3"}, TableLayout::Alignment::right},
// TableLayout::ColumnParam{{"Colonne 4"}, TableLayout::Alignment::right},
// TableLayout::ColumnParam{{"Prev\nelement"}, TableLayout::Alignment::right},
// TableLayout::ColumnParam{{"Next\nelement"}, TableLayout::Alignment::right},
// }, "InternalWellGenerator well_injector1" );

// //tableLayout.setMargin( TableLayout::MarginValue::tiny );

// TableData tableData;
// tableData.addRow( "value 1", "long value 1", "3.0034", 3.0129877, "" , 1 );
// tableData.addRow( "value 1", "long value 2", "100.45", 4.0129877, 1 , 2 );

// TableTextFormatter const tableText( tableLayout );
// EXPECT_EQ( tableText.toString( tableData ),
// "\n------------------------------------------------------------\n"
// "| InternalWellGenerator well_injector1 |\n"
// "------------------------------------------------------------\n"
// "|Colonne 1| Colonne 2 |Colonne 3|Colonne 4| Prev| Next|\n"
// "| | | | |element|element|\n"
// "------------------------------------------------------------\n"
// "| value 1 |long value 1| 3.0034|3.0129877| | 1|\n"
// "| value 1 |long value 2| 100.45|4.0129877| 1| 2|\n"
// "------------------------------------------------------------\n\n"
// );
// }
TableLayout tableLayout( {"Cras egestas", "CoordX", "C", "CoordZ", "Prev\nelement", "Next\nelement"} );
tableLayout.setTitle( "title" ).setMargin( TableLayout::MarginValue::tiny ).disableLineWrap();

TableData tableData;
tableData.addRow( "1", "2", "3.0", 3.0129877, 2.0f, 1 );
tableData.addRow( "1", "2", "3.0", 3.0129877, 2.0f, 1 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thing that we can use a line break in titles :)

  • testLineBreak would be more accurate as a name (line wrapping term is more dedicated for automatic line breaks).
  • I really think it should support line breaks within content lines:
  tableData.addRow( "1", "2", "one line text", 3.0129877, 2.0f, 1 );
  tableData.addRow( "1", "2", "three\nlines\ntext", 3.0129877, 2.0f, 1 );
  tableData.addRow( "1", "2", "one line text", 3.0129877, 2.0f, 1 );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can make line break for cell values if needed, not sure if right this is mandatory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered a scenario that needed this, but I forgot it :(
We can get back on this later.

Copy link
Contributor

@MelReyCG MelReyCG Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, what do you think of this?

-------------------------------------
|  stat name  | component |  value  |
-------------------------------------
|  pressure   |    all    | 123.456 |
| temperature |    all    | 123.456 |
-------------------------------------
|             |    oil    | 123.456 |
|    mass     |    gaz    | 123.456 |
|             |   water   | 123.456 |
-------------------------------------

I think it would need to be able to have a TableData::addSeparatorRow(), and we may need multiline for doing a tableData.addRow("mass","oil\ngaz\nwater","123.456\n123.456\n123.456")

MelReyCG

This comment was marked as duplicate.

Copy link
Contributor

@MelReyCG MelReyCG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2nd pass, format/table classes

src/coreComponents/common/format/table/TableFormatter.cpp Outdated Show resolved Hide resolved
src/coreComponents/common/format/table/TableFormatter.cpp Outdated Show resolved Hide resolved
src/coreComponents/common/format/table/TableFormatter.cpp Outdated Show resolved Hide resolved
src/coreComponents/common/format/table/TableLayout.hpp Outdated Show resolved Hide resolved
src/coreComponents/common/format/table/TableFormatter.hpp Outdated Show resolved Hide resolved
/// Vector containing substring column name delimited by "\n"
std::vector< string > splitColumnNameLines;
std::vector< string > splitColumnNames = {""};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a user mess with this parameter? It seems like it should be private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this parameter is assigned in tableFormatter function

Copy link
Contributor

@MelReyCG MelReyCG Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be annotated as an "internal computed value", as it is not dedicated to be modified (but public, in a set-up structure).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, either set it private or anotate it as an "internal computed value".

src/coreComponents/common/format/table/TableFormatter.cpp Outdated Show resolved Hide resolved
Comment on lines 292 to 294
void TableTextFormatter::splitAndMergeColumnHeaders( std::vector< TableLayout::TableColumnData > & tableColumnsData,
size_t & nbHeaderRows,
std::vector< std::vector< string > > & splitHeaders ) const
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Do you really use all those out-parameters?
  • Why nbHeaderRows does not take into account sub-columns? Can it cause issues? (is it tested?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed nbHeaderRows parameters in all signature, no issue for we add '\n' to subcolumn bc it's not implemented yet, it will just take the first part of the string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it needs more work to either fully implement what those lines tries to do:

    if( !tableColumnData.subColumn.empty())
    {
      std::vector< std::vector< string > > splitSubColHeaders;
      size_t nbHeaderSubColRows = 0;
      splitAndMergeColumnHeaders( tableColumnData.subColumn, nbHeaderSubColRows, splitSubColHeaders );
    }

Copy link
Contributor

@MelReyCG MelReyCG Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You seem to now correctly store the results of splitAndMergeColumnHeaders() in splitColumnNames.
So what is the use of allDividedHeaderParts out-parameter?

src/coreComponents/common/format/table/TableFormatter.cpp Outdated Show resolved Hide resolved
@MelReyCG
Copy link
Contributor

MelReyCG commented Oct 29, 2024

I must say that it is a good thing that your worked on renaming/refactoring some parts, it will helps a lot in understanding.

@MelReyCG MelReyCG self-requested a review October 31, 2024 10:26
Copy link
Contributor

@MelReyCG MelReyCG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some requests.

@arng40 arng40 requested a review from MelReyCG November 5, 2024 13:13
@arng40 arng40 requested a review from ryar9534 as a code owner November 8, 2024 10:33
@MelReyCG MelReyCG closed this Dec 20, 2024
@MelReyCG
Copy link
Contributor

Work merged in #3406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci: run code coverage enables running of the code coverage CI jobs ci: run CUDA builds Allows to triggers (costly) CUDA jobs ci: run integrated tests Allows to run the integrated tests in GEOS CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants