Skip to content

Commit

Permalink
auto spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Jul 12, 2024
1 parent 6af4f17 commit c7cd5ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
13 changes: 7 additions & 6 deletions WordCloudApp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ begin
(n -> n^2) => "",
expm1 => "exp x",
]
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))"
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))"
end

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

# ╔═╡ 1e8947ee-5f2a-4bed-99d5-f24ebc6cfbf3
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))"""
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*"""

# ╔═╡ f1b1e1f5-cfcb-4645-8eb6-93c9b5c0140e
md"""**average text size:** $(@bind avgfontsize NumberField(1:100, default=12)) *You can use it to manage the size of output image*"""
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*
**mask size:** $(@bind masksize_ TextField(default="auto")) *e.g. 400,300*"""

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

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

# ╔═╡ 1aa632dc-b3e8-4a9d-9b9e-c13cd05cf97e
begin
Expand Down Expand Up @@ -411,7 +412,7 @@ begin
backgroundcolor=backgroundcolor,
outline=olw,
density=density,
spacing=spacing,
spacing=spacing < 0 ? :auto : spacing,
style=style,
maskkwargs...
) |> generate!
Expand Down
11 changes: 7 additions & 4 deletions src/wc-class.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ For more sophisticated text processing, please utilize the function [`processtex
* maxfontsize: The maximum font size in pixel.
* 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.
* density = 0.55 # default is 0.5
* spacing = 1 # minimum spacing between words, default is 2
* spacing = 1 # minimum spacing between words, default is :auto
### mask-related keyword arguments
* mask = loadmask("res/heart.jpg", 256, 256) # refer to the documentation of [`loadmask`](@ref)
Expand Down Expand Up @@ -82,9 +82,9 @@ end
wordcloud(words, weight::Number; kargs...) = wordcloud(words, repeat([weight], length(words)); kargs...)
function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVector{<:Real};
colors=:auto, angles=:auto,
mask=:auto, fonts=:auto, language=:auto,
mask=:auto, masksize=:auto, fonts=:auto, language=:auto,
transparent=:auto, minfontsize=:auto, maxfontsize=:auto, avgfontsize=12,
spacing::Integer=2, density=0.5,
spacing=:auto, density=0.5,
state=layout!, style=:auto, centralword=:auto, reorder=:auto, level=:auto, kargs...)
@assert length(words) == length(weights) > 0
params = Dict{Symbol,Any}()
Expand All @@ -95,7 +95,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
params[:reorder] = reorder
params[:level] = level

colors, angles, mask, svgmask, fonts, transparent = getstylescheme(words, weights; colors=colors, angles=angles, mask=mask,
colors, angles, mask, svgmask, fonts, transparent = getstylescheme(words, weights; colors=colors, angles=angles, mask=mask, masksize=masksize,
fonts=fonts, avgfontsize=avgfontsize, language=language, transparent=transparent, params=params, kargs...)
params[:colors] = Any[colors...]
params[:angles] = angles
Expand Down Expand Up @@ -123,6 +123,9 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
params[:maxfontsize] = maxfontsize
params[:avgfontsize] = avgfontsize

if spacing == :auto
spacing = Int(masksize == :auto ? avgfontsize ÷ 6 : 2)
end
params[:spacing] = spacing
params[:density] = density
params[:fonts] = fonts
Expand Down

2 comments on commit c7cd5ec

@guo-yong-zhi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110940

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.0 -m "<description of version>" c7cd5ec67e6e8e3bbfbe368061c782aa1bd061ff
git push origin v1.0.0

Please sign in to comment.