104void RDisplay::EnsureCurrentColumnWidth(
size_t w)
108 if (
w > std::numeric_limits<unsigned short>::max()) {
109 w = std::numeric_limits<unsigned short>::max();
115void RDisplay::AddToRow(
const std::string &stringEle)
127void RDisplay::AddCollectionToRow(
const std::vector<std::string> &collection)
132 size_t collectionSize = collection.size();
134 auto stringEle = collection[
index];
155 if (
index != collectionSize - 1 &&
fTable.size() <= row) {
165void RDisplay::MovePosition()
177RDisplay::RDisplay(
const VecStr_t &columnNames,
const VecStr_t &types,
size_t nMaxCollectionElements)
178 : fTypes(types), fWidths(columnNames.
size(), 0), fRepresentations(columnNames.
size()),
179 fCollectionsRepresentations(columnNames.
size()), fNColumns(columnNames.
size()),
180 fNMaxCollectionElements(nMaxCollectionElements)
183 fTable.push_back(std::vector<DElement_t>(columnNames.size()));
185 for (
auto name = columnNames.begin() + 1;
name != columnNames.end(); ++
name) {
190size_t RDisplay::GetNColumnsToShorten()
const
192 size_t totalWidth = 0;
195 for (
size_t i = 0; i <
size; ++i) {
206std::string RDisplay::DashesBetweenLines(
size_t lastColToPrint,
bool allColumnsFit)
const
208 std::string DashesStr =
"+";
209 for (
size_t i = 0; i < lastColToPrint; ++i){
210 DashesStr += std::string(
fWidths[i] + 2,
'-');
214 DashesStr +=
"-----+";
231std::string RDisplay::AsStringInternal(
bool considerDots,
const RPrintOptions &options)
const
241std::string RDisplay::AsStringHtml()
const
243 std::stringstream ss;
245 ss <<
"<table style=\"border: 1px solid black; border-collapse: collapse;\">\n";
246 auto nrRows =
fTable.size();
247 std::string elemType =
"th";
249 for (
size_t rowIndex = 0; rowIndex < nrRows; ++rowIndex) {
250 const auto &row =
fTable[rowIndex];
252 bool isRowSeparator =
253 std::any_of(row[0].GetRepresentation().begin(), row[0].GetRepresentation().end(), ::isdigit);
256 static const char *bgColors[2] = {
"#fff",
"#eee"};
257 bgColorIdx = (bgColorIdx + isRowSeparator) & 1;
258 std::string bgColor = bgColors[bgColorIdx];
260 if (isRowSeparator) {
261 ss <<
" <tr style=\"border-top: 1px dotted; background: " + bgColor +
"\">\n";
263 ss <<
" <tr style=\"background: " + bgColor +
"\">\n";
266 for (
const auto &element : row) {
267 ss <<
" <" + elemType +
" style=\"padding: 1px 4px; border-right: 1px solid\">"
268 << element.GetRepresentation() <<
"</" + elemType +
">\n";
279std::string RDisplay::AsStringMarkdown(
bool considerDots)
const
281 std::stringstream ss;
285 bool allColumnsFit =
true;
286 if (
fNColumns > 2u && columnsToShorten > 0u){
290 columnsToPrint =
fNColumns - columnsToShorten;
296 Info(
"Print",
"Only showing %zu columns out of %zu\n", columnsToPrint,
fNColumns);
298 allColumnsFit =
false;
302 Info(
"Print",
"No collections shown since fNMaxCollectionElements is 0\n");
304 auto nrRows =
fTable.size();
306 for (
size_t rowIndex = 0; rowIndex < nrRows; ++rowIndex) {
307 const auto &row =
fTable[rowIndex];
309 std::stringstream stringRow;
310 bool isRowEmpty =
true;
312 if (std::any_of(row[0].GetRepresentation().begin(), row[0].GetRepresentation().end(), ::isdigit)) {
317 for (
size_t columnIndex = 0; columnIndex < columnsToPrint; ++columnIndex) {
318 const auto &element = row[columnIndex];
319 std::string printedElement =
"";
322 if (considerDots && element.IsDot()) {
323 printedElement =
"...";
324 }
else if (!considerDots || element.IsPrint()) {
325 printedElement = element.GetRepresentation();
329 if (!printedElement.empty()) {
334 stringRow << std::left << std::setw(
fWidths[columnIndex]) << std::setfill(
fgSeparator) << printedElement
338 if (!allColumnsFit) {
340 stringRow <<
"... | ";
342 ss << stringRow.str() <<
"\n";
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
bool IsIgnore() const
Return if the cell has to be skipped.
bool IsDot() const
Return if the cell has to be replaced by "...".
const std::string & GetRepresentation() const
bool IsPrint() const
Return if the cell has to be printed.
void SetDots()
Flag this cell to be replaced by "...".
PrintingAction fPrintingAction
void SetPrint()
Flag this cell as to be printed.
void SetIgnore()
Flag this cell as to be skipped.
std::string fRepresentation
RDisplayElement()
Constructor assuming an empty representation to be printed.
size_t fCurrentColumn
Column that is being filled.
ROOT::Internal::RDF::RDisplayElement DElement_t
size_t fNMaxCollectionElements
std::vector< std::vector< DElement_t > > fTable
String representation of the data to be printed.
std::string AsStringHtml() const
void AddToRow(const std::string &stringEle)
Adds a single element to the next slot in the table.
size_t fCurrentRow
Row that is being filled.
std::string AsStringMarkdown(bool considerDots) const
void MovePosition()
Moves to the next cell.
std::vector< unsigned short > fWidths
Tracks the maximum width of each column, based on the largest element.
static constexpr unsigned fgMaxWidth
Maximum width of the table that Print() displays.
void EnsureCurrentColumnWidth(size_t w)
size_t fNextRow
Next row to be filled.
std::string DashesBetweenLines(size_t lastColToPrint, bool allColumnsFit) const
Generate dashes between entries in Print() and AsString() Methods.
std::string AsStringInternal(bool considerDots, const RPrintOptions &options={EPrintFormat::kMarkdown}) const
std::vector< std::string > VecStr_t
size_t GetNColumnsToShorten() const
Get the number of columns that do NOT fit in the characters limit.
static constexpr char fgSeparator
Spacing used to align the table entries.
size_t fNColumns
Number of columns to be printed.