consolidation / output-formatters

Apply transformations to structured data to write output in different formats.
Other
193 stars 13 forks source link

Improve cell rendering #74

Open greg-1-anderson opened 5 years ago

greg-1-anderson commented 5 years ago

NumericCellRenderer currently exists in StructuredData, and includes facilities both for formatting numbers and for right-justifying content in a cell.

Instead, we should have a Render directory. It should have a class that allows different decorators to be attached to cells either by field name or by cell data type. A number of renderers should be available, including numeric, date, right-justification and so on.

wimleers commented 3 years ago

I had to resort to things like

sprintf("%6d", $number)

to get right-justifying numeric columns. Am I doing something wrong? 🤔

greg-1-anderson commented 3 years ago

Were you using a custom renderer? Did you try NumericCellRenderer?

manarth commented 7 months ago

I've not been able to get the NumericCellRenderer to work (with Drush 12.4.3.0).

    $result = new RowsOfFields($data);
    $result = $result->addRenderer(new NumericCellRenderer($data, ['count']));
    return $result;

I would expect the count column to be right-aligned and have commas as a thousands separator. The number is displayed unformatted.

I'm going to have a look at the test for the NumericCellRenderer to see if that sheds light on the issue.