Skip to content

Commit

Permalink
merge the parameter maskshape -> mask
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Dec 10, 2021
1 parent 6e52df6 commit c523503
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/gathering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using WordCloud
wc = wordcloud(
processtext(open(pkgdir(WordCloud) * "/res/alice.txt"), stopwords=WordCloud.stopwords_en ["said"]),
angles=0, density=0.55,
maskshape=squircle, rt=2.5 * rand(),
mask=squircle, rt=2.5 * rand(),
state=initwords!)
placewords!(wc, style=:gathering, level=5, centerlargestword=true)
pin(wc, "Alice") do # keep "Alice" in the center
Expand Down
2 changes: 1 addition & 1 deletion examples/nomask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using WordCloud
wc = wordcloud(
processtext(open(pkgdir(WordCloud) * "/res/Donald Trump's Inaugural Address.txt"), maxweight=1, minweight=0),
density=0.3,
maskshape=box,
mask=box,
cornerradius=0,
masksize=(1200, 900),
backgroundcolor=:maskcolor,
Expand Down
2 changes: 1 addition & 1 deletion examples/outline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ weights = (1:200) .% 11 .+ 1
#md# ```julia
#md# wc1 = wordcloud(
#md# words, weights,
#md# maskshape = squircle, rt=0.5,
#md# mask = squircle, rt=0.5,
#md# masksize = (300, 200),
#md# maskcolor = "AliceBlue",
#md# outline = 6, linecolor = "navy"
Expand Down
2 changes: 1 addition & 1 deletion examples/semantic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ embedded = tsne(vectors', 2)
#md#
wc = wordcloud(
words_weights,
maskshape=box,
mask=box,
masksize=(1000, 1000),
cornerradius=0,
density=0.3,
Expand Down
3 changes: 2 additions & 1 deletion src/artist.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ equalwh(sz::Number=800) = sz, sz
equalwh(sz::Tuple) = sz
equalwh(arg...) = arg
function randommask(args...; maskshape=:rand, kargs...)
ran = Dict(squircle => 0.4, box => 0.6, ellipse => 0.8, ngon => 0.9, star => 1, :rand => rand())[maskshape]
rd = Dict(squircle => 0.4, box => 0.6, ellipse => 0.8, ngon => 0.9, star => 1)
ran = get(rd, maskshape, rand())
if ran <= 0.4
return randomsquircle(randomwh(args...)...; kargs...)
elseif ran <= 0.6
Expand Down
13 changes: 7 additions & 6 deletions src/wc-class.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ Positional arguments are used to specify words and weights, and can be in differ
* spacing = 1 #minimum spacing between words
### mask keyword arguments
* mask = loadmask("res/heart.jpg", 256, 256) #see doc of `loadmask`
* mask = loadmask("res/heart.jpg", color="red", ratio=2) #see doc of `loadmask`
* mask = shape(ellipse, 800, 600, color="white", backgroundcolor=(0,0,0,0)) #see doc of `shape`
* maskshape: `box`, `ellipse`, `squircle`, `ngon` or `star`. See `shape`.
* mask = loadmask("res/heart.jpg", 256, 256) #see the doc of `loadmask`
* mask = loadmask("res/heart.jpg", color="red", ratio=2) #see the doc of `loadmask`
* mask = "res/heart.jpg" #shorthand for loadmask("res/heart.jpg")
* mask = shape(ellipse, 800, 600, color="white", backgroundcolor=(0,0,0,0)) #See the doc of `shape`.
* mask = box #mask can alse be one of `box`, `ellipse`, `squircle`, `ngon` and `star`. See the doc of `shape`.
* masksize: Can be a tuple `(width, height)` or just a single number as a side length hint.
* backgroundsize: See `shape`. Need to be used with `masksize` to specify the padding size.
* maskcolor: like "black", "#ff0000", (0.5,0.5,0.7), 0.2, or :default, :original (keep it unchanged), :auto (auto recolor the mask).
Expand Down Expand Up @@ -124,7 +125,7 @@ function getstylescheme(words, weights; colors=:auto, angles=:auto, mask=:auto,
colors isa Symbol && (colors = (colorschemes[colors].colors...,))
colors = Iterators.take(iter_expand(colors), length(words)) |> collect
angles = Iterators.take(iter_expand(angles), length(words)) |> collect
if mask == :auto
if mask == :auto || mask isa Function
if maskcolor in DEFAULTSYMBOLS
if backgroundcolor in DEFAULTSYMBOLS || backgroundcolor == :maskcolor
maskcolor = randommaskcolor(colors)
Expand Down Expand Up @@ -156,7 +157,7 @@ function getstylescheme(words, weights; colors=:auto, angles=:auto, mask=:auto,
push!(kg, :linecolor => linecolor)
end
padding in DEFAULTSYMBOLS && (padding = round(Int, maximum(masksize) ÷ 10))
mask = randommask(masksize, color=maskcolor; padding=padding, keeparea=keepmaskarea, kg..., kargs...)
mask = randommask(masksize; maskshape=mask ,color=maskcolor, padding=padding, keeparea=keepmaskarea, kg..., kargs...)
else
ms = masksize in DEFAULTSYMBOLS ? () : masksize
if maskcolor == :auto && !issvg(loadmask(mask))
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include("test_textprocessing.jl")
words = ["." for i in 1:500]
weights = [1 for i in 1:length(words)]
@test_throws ErrorException begin # no room
wc = wordcloud(words, weights, maskshape=ellipse, masksize=(5, 5), backgroundsize=(10, 10), density=1000, angles=0)
wc = wordcloud(words, weights, mask=ellipse, masksize=(5, 5), backgroundsize=(10, 10), density=1000, angles=0)
placewords!(wc)
end

Expand Down

0 comments on commit c523503

Please sign in to comment.