Skip to content

Commit

Permalink
Add HTML show (#55)
Browse files Browse the repository at this point in the history
* Add HTML show

* Apply suggestions

* Add tests

* Update tests

* Apply suggestions

* Apply suggestions

* Apply suggestions

* Update src/abstractgeotable.jl

* Update src/abstractgeotable.jl

---------

Co-authored-by: Júlio Hoffimann <[email protected]>
  • Loading branch information
eliascarv and juliohm authored Sep 5, 2023
1 parent 87115dd commit 72cbf3e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 24 deletions.
42 changes: 20 additions & 22 deletions src/abstractgeotable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,26 @@ end
Base.show(io::IO, geotable::AbstractGeoTable) = summary(io, geotable)

function Base.show(io::IO, ::MIME"text/plain", geotable::AbstractGeoTable)
summary(io, geotable)
println(io)
pretty_table(
io,
geotable;
backend=Val(:text),
_common_kwargs(geotable)...,
newline_at_end=false,
header_crayon=crayon"bold (0,128,128)"
)
end

function Base.show(io::IO, ::MIME"text/html", geotable::AbstractGeoTable)
pretty_table(
io,
geotable;
backend=Val(:html),
_common_kwargs(geotable)...
)
end

function _common_kwargs(geotable)
dom = domain(geotable)
tab = values(geotable)
cols = Tables.columns(tab)
Expand Down Expand Up @@ -377,24 +394,5 @@ function Base.show(io::IO, ::MIME"text/plain", geotable::AbstractGeoTable)
types = first.(tuples)
units = last.(tuples)

# print etable
pretty_table(
io,
geotable;
header=(colnames, types, units),
vcrop_mode=:middle,
max_num_of_rows=20,
newline_at_end=false,
header_crayon=crayon"bold (0,128,128)"
)

# info about other tables
rank = paramdim(dom)
if rank > 0
others = filter(r -> !isnothing(values(geotable, r)), 0:(rank - 1))
if !isempty(others)
println(io)
print(io, "Additional tables encountered for the following ranks: $(join(others, " ,"))")
end
end
(title=summary(geotable), header=(colnames, types, units), vcrop_mode=:middle, max_num_of_rows=20)
end
86 changes: 84 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ dummymeta(domain, table) = GeoTable(domain, Dict(paramdim(domain) => table))
│ 2 │ 0.11 │ txt7 │ Quadrangle(Point(0.0, 2.0), Point(1.0, 2.0), Point(1.0, 3.0), Point(0.0, 3.0)) │
│ 2 │ 0.64 │ txt8 │ Quadrangle(Point(1.0, 2.0), Point(2.0, 2.0), Point(2.0, 3.0), Point(1.0, 3.0)) │
│ 8 │ 8.46 │ txt9 │ Quadrangle(Point(2.0, 2.0), Point(3.0, 2.0), Point(3.0, 3.0), Point(2.0, 3.0)) │
└─────────┴────────────┴─────────┴────────────────────────────────────────────────────────────────────────────────┘
Additional tables encountered for the following ranks: 0"""
└─────────┴────────────┴─────────┴────────────────────────────────────────────────────────────────────────────────┘"""

gtb = georef((a=[missing; a[2:9]], b=[b[1:4]; missing; b[6:9]], c=[c[1:8]; missing]), pset)
@test sprint(show, gtb) == "9×4 GeoTable over 9 PointSet{2,Float64}"
Expand All @@ -365,6 +364,89 @@ dummymeta(domain, table) = GeoTable(domain, Dict(paramdim(domain) => table))
│ 2 │ 0.64 │ txt8 │ Point(8.0, 8.0) │
│ 8 │ 8.46 │ missing │ Point(9.0, 9.0) │
└─────────┴────────────┴─────────┴─────────────────┘"""

gtb = georef((; a, b, c), pset)
@test sprint(show, MIME("text/html"), gtb) == """
<table>
<caption style = "text-align: left;">9×4 GeoTable over 9 PointSet{2,Float64}</caption>
<thead>
<tr class = "header">
<th style = "text-align: right;">a</th>
<th style = "text-align: right;">b</th>
<th style = "text-align: right;">c</th>
<th style = "text-align: right;">geometry</th>
</tr>
<tr class = "subheader">
<th style = "text-align: right;">Count</th>
<th style = "text-align: right;">Continuous</th>
<th style = "text-align: right;">Textual</th>
<th style = "text-align: right;">Point2</th>
</tr>
<tr class = "subheader headerLastRow">
<th style = "text-align: right;">NoUnits</th>
<th style = "text-align: right;">NoUnits</th>
<th style = "text-align: right;">NoUnits</th>
<th style = "text-align: right;"></th>
</tr>
</thead>
<tbody>
<tr>
<td style = "text-align: right;">0</td>
<td style = "text-align: right;">2.34</td>
<td style = "text-align: right;">txt1</td>
<td style = "text-align: right;">Point(1.0, 1.0)</td>
</tr>
<tr>
<td style = "text-align: right;">6</td>
<td style = "text-align: right;">7.5</td>
<td style = "text-align: right;">txt2</td>
<td style = "text-align: right;">Point(2.0, 2.0)</td>
</tr>
<tr>
<td style = "text-align: right;">6</td>
<td style = "text-align: right;">0.06</td>
<td style = "text-align: right;">txt3</td>
<td style = "text-align: right;">Point(3.0, 3.0)</td>
</tr>
<tr>
<td style = "text-align: right;">3</td>
<td style = "text-align: right;">1.29</td>
<td style = "text-align: right;">txt4</td>
<td style = "text-align: right;">Point(4.0, 4.0)</td>
</tr>
<tr>
<td style = "text-align: right;">9</td>
<td style = "text-align: right;">3.64</td>
<td style = "text-align: right;">txt5</td>
<td style = "text-align: right;">Point(5.0, 5.0)</td>
</tr>
<tr>
<td style = "text-align: right;">5</td>
<td style = "text-align: right;">8.05</td>
<td style = "text-align: right;">txt6</td>
<td style = "text-align: right;">Point(6.0, 6.0)</td>
</tr>
<tr>
<td style = "text-align: right;">2</td>
<td style = "text-align: right;">0.11</td>
<td style = "text-align: right;">txt7</td>
<td style = "text-align: right;">Point(7.0, 7.0)</td>
</tr>
<tr>
<td style = "text-align: right;">2</td>
<td style = "text-align: right;">0.64</td>
<td style = "text-align: right;">txt8</td>
<td style = "text-align: right;">Point(8.0, 8.0)</td>
</tr>
<tr>
<td style = "text-align: right;">8</td>
<td style = "text-align: right;">8.46</td>
<td style = "text-align: right;">txt9</td>
<td style = "text-align: right;">Point(9.0, 9.0)</td>
</tr>
</tbody>
</table>
"""
end
end
end

0 comments on commit 72cbf3e

Please sign in to comment.