vega-lite icon indicating copy to clipboard operation
vega-lite copied to clipboard

Introduce macro/composite mark for creating tables

Open joelostblom opened this issue 2 years ago • 7 comments

I think it would be quite useful with a mark_table to quickly create tables in Vega-Lite. I often do this myself to troubleshoot complex transforms, where I want the intermediate output to be printed so that I understand what is going on. It can also be useful to display on its own, or together with filtering on another chart.

I think a sensible default would be to include all columns in the data, with a parameter to reduce the selection, e.g. mark_table(table_columns=['col1', 'col2'). I have found a few different ways tables could be created with Vega-Lite, that could be called when this composite mark is used:

Using repeat

The issue here is the spacing between the columns (due to https://github.com/vega/vega-lite/issues/8062) and that I am not aware of an easy way to show the column names on top:

image Open the Chart in the Vega Editor

Using facet

While the spacing between charts/table columns can be adjusted here (both via spacing and resolve_scale(x='independent'), I am not aware of a way to automatically adjust to the width of the column/header name:

image Open the Chart in the Vega Editor

Using hconcat

This is the visually most pleasing option, but it would involve a loop outside the Vega-Lite spec to create the charts that are to be concatenated:

image Open the Chart in the Vega Editor


One complications is making this mark work together with selections in a chart as in this example. The reason is that there needs to be a filter transform with the selection and a window transform injected before the transform that limits the number of rows displayed in the table by default. One workaround could be to not limit the number of rows as a default but that takes away much of the convenience of this function since it now requires the user to manually write out the two transforms to display less than the max number of rows (and displaying all rows is rarely desired).

joelostblom avatar Mar 24 '22 06:03 joelostblom