Skip to content

Commit 9cbafe0

Browse files
zzktadrhill
andauthored
Improve line wrapping in HTML output (#9)
Improve line wrapping in HTML output by adding a flexbox using inlined CSS. --------- Co-authored-by: adrhill <[email protected]>
1 parent a762289 commit 9cbafe0

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TextHeatmaps"
22
uuid = "2dd6718a-6083-4824-b9f7-90e4a57f72d2"
33
authors = ["Adrian Hill <[email protected]>"]
4-
version = "1.2.2"
4+
version = "1.2.3-DEV"
55

66
[deps]
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"

src/heatmap.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ luma(c::RGB) = 0.2126 * c.r + 0.7152 * c.g + 0.0722 * c.b # using BT. 709 coeffi
8787

8888
# Used e.g. in Pluto notebooks
8989
function Base.show(io::IO, ::MIME"text/html", h::TextHeatmap)
90-
print(io, "<p><heatmap>")
90+
# wrap lines and break on whitespace
91+
div_style = "display: flex; flex-wrap: wrap; gap: 5px 0px; align-items: flex-start;"
92+
print(io, """<div id="heatmap" style="$div_style">""")
9193
for (word, color) in zip(h.words, h.colors)
9294
bg = hex(color)
9395
fg = is_background_bright(color) ? "black" : "white"
94-
95-
style = "background-color: #$bg; color: $fg; padding: 0.2em; margin: 0.2em;"
96-
print(io, """<heatmap-word style="$style">$word</heatmap-word>""")
96+
word_style = "background-color: #$bg; color: $fg; padding: 0.1em 0.3em;"
97+
print(io, """<heatmap-word style="$word_style">$word</heatmap-word>""")
9798
end
98-
print(io, "</heatmap></p>")
99+
print(io, "</div>")
99100
end

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
88
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
99
XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7"
1010

11+
[compat]
12+
JuliaFormatter = "1"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<p><heatmap><heatmap-word style="background-color: #800000; color: white; padding: 0.2em; margin: 0.2em;">Test</heatmap-word><heatmap-word style="background-color: #8686FF; color: black; padding: 0.2em; margin: 0.2em;">TextHeatmaps</heatmap-word></heatmap></p>
1+
<div id="heatmap" style="display: flex; flex-wrap: wrap; gap: 5px 0px; align-items: flex-start;"><heatmap-word style="background-color: #800000; color: white; padding: 0.1em 0.3em;">Test</heatmap-word><heatmap-word style="background-color: #8686FF; color: black; padding: 0.1em 0.3em;">TextHeatmaps</heatmap-word></div>

0 commit comments

Comments
 (0)