ronisbr / PrettyTables.jl

Print data in formatted tables.
MIT License
391 stars 38 forks source link

Cell display of user-defined type fallback to text/plain #226

Closed mojaie closed 7 months ago

mojaie commented 8 months ago

User-defined type does not always implement default show MIME types, so these data types can generate verbose output in table cells.

スクリーンショット 2023-11-11 11 06 51

A workaround is to provide a default show method, but I'm not sure if it is a good practice.

スクリーンショット 2023-11-11 11 08 01

How about calling user-defined show(io::IO, MIME"text/plain", x) instead of default show(io::IO, x), if defined?

https://github.com/ronisbr/PrettyTables.jl/blob/3d614c9294a6477a5f7cf09bdcacd4d50fd69d68/src/backends/html/parse_cell.jl#L91-L102

ronisbr commented 8 months ago

Hi @mojaie !

Wouldn't this be a bug in the type you are printing? I think it would not be a good move to render as text/plain since we are printing to HTML. We try first to render it using HTML, if it is not possible, we ask for the default one. I think we would break other types if we modify this behavior.

mojaie commented 8 months ago

Thank you very much.

SimpleGraph in Graphs.jl does not have show(io::IO, MIME"text/html", x). `show(io::IO, m::MIME"text/html", mol::SimpleMolGraph) in MolecularGraph.jl generates a div element including SVG of chemical structure drawing so that Pluto and Jupyter can easily display it. On the other hand, someone may prefer compact table view with summarized text in some cases.

So, my question may be which method should package developers implement to display good summary or visualization of API data types.

ronisbr commented 7 months ago

Hi @mojaie !

Sorry for the delay. In this case, you can always use a formatter to adjust the display only within PrettyTables.jl. Would it work?

mojaie commented 7 months ago

Yes, formatter works. Thank you very much.

スクリーンショット 2023-11-29 22 56 02

So, providing Base.show(io::IO, ::MIME"text/html") that returns this formatted table seems to be a solution.

ronisbr commented 7 months ago

Perfect! Thanks for the info! :)