Skip to content

Commit c7cd5ec

Browse files
committed
auto spacing
1 parent 6af4f17 commit c7cd5ec

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

WordCloudApp.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ begin
5959
(n -> n^2) => "",
6060
expm1 => "exp x",
6161
]
62-
md"**scale:** $(@bind rescale_func Select(weightscale_funcs))  **word length balance:** $(@bind word_length_balance Slider(-1:0.01:1, default=0, show_value=true))"
62+
md"**weight scale:** $(@bind rescale_func Select(weightscale_funcs))  **word length balance:** $(@bind word_length_balance Slider(-1:0.01:1, default=0, show_value=true))"
6363
end
6464

6565
# ╔═╡ b199e23c-de37-4bcf-b563-70bccb59ba4e
@@ -69,18 +69,19 @@ md"""###### ✿ Overall Layout"""
6969
md"**layout style:** $(@bind style Select([:auto, :uniform, :gathering]))"
7070

7171
# ╔═╡ 1e8947ee-5f2a-4bed-99d5-f24ebc6cfbf3
72-
md"""**text density:** $(@bind density NumberField(0.1:0.01:10.0, default=0.5))  **min word spacing:** $(@bind spacing NumberField(0:100, default=2))"""
72+
md"""**text density:** $(@bind density NumberField(0.1:0.01:10.0, default=0.5))  **min word spacing:** $(@bind spacing NumberField(-1:100, default=-1)) *-1 means auto*"""
7373

7474
# ╔═╡ f1b1e1f5-cfcb-4645-8eb6-93c9b5c0140e
75-
md"""**average text size:** $(@bind avgfontsize NumberField(1:100, default=12)) *You can use it to manage the size of output image*"""
75+
md"""**average font size:** $(@bind avgfontsize NumberField(1:100, default=12)) *You can use "average font size" or "mask size" to manage the output image size*
76+
77+
**mask size:** $(@bind masksize_ TextField(default="auto")) *e.g. 400,300*"""
7678

7779
# ╔═╡ 9bb3b69a-fd5b-469a-998f-23b6c9e23e5d
7880
md"""###### ✿ Mask Style"""
7981

8082
# ╔═╡ f4844a5f-260b-4713-84bf-69cd8123c7fc
8183
md"""**mask shape:** $(@bind mask_ Select([:auto, :customsvg, box, ellipse, squircle, ngon, star, bezingon, bezistar])) $(@bind configshape  CheckBox(default=false))additional config
82-
83-
**mask size:** $(@bind masksize_ TextField(default="auto")) *e.g. 400,300*"""
84+
"""
8485

8586
# ╔═╡ 1aa632dc-b3e8-4a9d-9b9e-c13cd05cf97e
8687
begin
@@ -411,7 +412,7 @@ begin
411412
backgroundcolor=backgroundcolor,
412413
outline=olw,
413414
density=density,
414-
spacing=spacing,
415+
spacing=spacing < 0 ? :auto : spacing,
415416
style=style,
416417
maskkwargs...
417418
) |> generate!

src/wc-class.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ For more sophisticated text processing, please utilize the function [`processtex
4141
* maxfontsize: The maximum font size in pixel.
4242
* avgfontsize: The average font size in pixel, default is 12. It is used to control the size of the generated picture when `masksize` is not specified.
4343
* density = 0.55 # default is 0.5
44-
* spacing = 1 # minimum spacing between words, default is 2
44+
* spacing = 1 # minimum spacing between words, default is :auto
4545
4646
### mask-related keyword arguments
4747
* mask = loadmask("res/heart.jpg", 256, 256) # refer to the documentation of [`loadmask`](@ref)
@@ -82,9 +82,9 @@ end
8282
wordcloud(words, weight::Number; kargs...) = wordcloud(words, repeat([weight], length(words)); kargs...)
8383
function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVector{<:Real};
8484
colors=:auto, angles=:auto,
85-
mask=:auto, fonts=:auto, language=:auto,
85+
mask=:auto, masksize=:auto, fonts=:auto, language=:auto,
8686
transparent=:auto, minfontsize=:auto, maxfontsize=:auto, avgfontsize=12,
87-
spacing::Integer=2, density=0.5,
87+
spacing=:auto, density=0.5,
8888
state=layout!, style=:auto, centralword=:auto, reorder=:auto, level=:auto, kargs...)
8989
@assert length(words) == length(weights) > 0
9090
params = Dict{Symbol,Any}()
@@ -95,7 +95,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
9595
params[:reorder] = reorder
9696
params[:level] = level
9797

98-
colors, angles, mask, svgmask, fonts, transparent = getstylescheme(words, weights; colors=colors, angles=angles, mask=mask,
98+
colors, angles, mask, svgmask, fonts, transparent = getstylescheme(words, weights; colors=colors, angles=angles, mask=mask, masksize=masksize,
9999
fonts=fonts, avgfontsize=avgfontsize, language=language, transparent=transparent, params=params, kargs...)
100100
params[:colors] = Any[colors...]
101101
params[:angles] = angles
@@ -123,6 +123,9 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
123123
params[:maxfontsize] = maxfontsize
124124
params[:avgfontsize] = avgfontsize
125125

126+
if spacing == :auto
127+
spacing = Int(masksize == :auto ? avgfontsize ÷ 6 : 2)
128+
end
126129
params[:spacing] = spacing
127130
params[:density] = density
128131
params[:fonts] = fonts

0 commit comments

Comments
 (0)