Skip to content

Commit db1b14a

Browse files
committed
feat(paintcloud): add quiet argrument and allow WC object
1 parent 85795bb commit db1b14a

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "WordCloud"
22
uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b"
33
authors = ["guoyongzhi <guo-yong-zhi@outlook.com>"]
4-
version = "1.3.0"
4+
version = "1.3.1"
55

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

src/wc-class.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ For more sophisticated text processing, please utilize the function [`processtex
7474
* You can skip `initialize!` and/or `layout!`, and these operations will be automatically performed with default parameters
7575
* You can use [`paintcloud`](@ref) and [`paintsvgcloud`](@ref) to obtain the final picture directly.
7676
"""
77+
wordcloud(wc::WC) = wc
7778
wordcloud(wordsweights::Tuple; kargs...) = wordcloud(wordsweights...; kargs...)
7879
wordcloud(counter::AbstractDict; kargs...) = wordcloud(keys(counter) |> collect, values(counter) |> collect; kargs...)
7980
wordcloud(counter::AbstractVector{<:Union{Pair,Tuple,AbstractVector}}; kargs...) = wordcloud(first.(counter), [v[2] for v in counter]; kargs...)

src/wc-helper.jl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,18 +163,19 @@ function paint(wc::WC, file, args...; kargs...)
163163
end
164164

165165
"""
166-
Generate a word cloud image from text. This function serves as a shortcut for `paint(generate!(wordcloud(...))...)`.
167-
For details on supported arguments, see:
168-
- [`wordcloud`](@ref)
169-
- [`paint`](@ref)
166+
Generate a word cloud image from text. This function acts as a convenient shortcut for `paint(generate!(wordcloud(...))...)`.
167+
It accepts the same arguments as [`wordcloud`](@ref) and [`paint`](@ref).
168+
# other arguments
169+
- quiet: suppresses the output of the generation process. defaults to true.
170+
170171
See also: [`paintsvgcloud`](@ref)
171172
# Examples
172173
* paintcloud("holly bible")
173-
* paintcloud("holly bible", "result.svg")
174+
* paintcloud("holly bible", "result.svg", quiet=false)
174175
* paintcloud(["holly", "bible"], [0.7, 0.3], "result.png", background=false)
175176
* paintcloud("holly bible", angles=(0, 90), ratio=0.5)
176177
"""
177-
function paintcloud(args...; paintfunc=paint, kargs...)
178+
function paintcloud(args...; quiet=true, paintfunc=paint, kargs...)
178179
if length(args) > 1 && last(args) isa AbstractString
179180
args_w, args_p = args[1:end-1], args[end:end]
180181
else
@@ -183,7 +184,11 @@ function paintcloud(args...; paintfunc=paint, kargs...)
183184
pkw = (:background, :ratio)
184185
kargs_w = filter(kw -> first(kw) pkw, kargs)
185186
kargs_p = filter(kw -> first(kw) pkw, kargs)
186-
redirect_stdio(stdout=devnull, stderr=devnull) do
187+
if quiet
188+
redirect_stdio(stdout=devnull, stderr=devnull) do
189+
paintfunc(generate!(wordcloud(args_w...; kargs_w...)), args_p...; kargs_p...)
190+
end
191+
else
187192
paintfunc(generate!(wordcloud(args_w...; kargs_w...)), args_p...; kargs_p...)
188193
end
189194
end

src/wc-method.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ function printcollisions(wc)
277277
colllist = first.(totalcollisions(qtrees))
278278
get_text(i) = i > 1 ? wc.words[i - 1] : "#MASK#"
279279
if length(colllist) > 0
280-
@warn "Have $(length(colllist)) collisions. Try setting a larger `epochs` and `retry`, or lower `density` and `spacing` in `wordcloud` to fix it."
280+
@warn "There are $(length(colllist)) collisions detected. To address this, you might consider increasing the `epochs` or `retry` parameters within the `generate!` function, or reducing the `density` or `spacing` parameters in the `wordcloud` function."
281281
print("These words collide: ")
282282
foreach(ij->print(get_text(ij[1]), " & ", get_text(ij[2]), ", "), colllist)
283283
println()

0 commit comments

Comments
 (0)