Skip to content

Commit

Permalink
set to state placement! when unfitted
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyongzhi committed Jun 1, 2021
1 parent f119b54 commit da0906f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "WordCloud"
uuid = "6385f0a0-cb03-45b6-9089-4e0acc74b26b"
authors = ["guoyongzhi <[email protected]>"]
version = "0.6.9"
version = "0.6.10"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
6 changes: 2 additions & 4 deletions src/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function load(fn)
end

function svg2bitmap(svg::Drawing)
d = Drawing(svg.width, svg.height, :image)
Drawing(svg.width, svg.height, :image)
placeimage(svg)
m=image_as_matrix()
m = image_as_matrix()
finish()
m
end
Expand Down Expand Up @@ -195,8 +195,6 @@ function overlay(color1::T, color2::T) where {T}
end
"put img2 on img1 at (x, y)"
function overlay!(img1::AbstractMatrix, img2::AbstractMatrix, x=1, y=1)#左上角重合时(x=1,y=1)
h1, w1 = size(img1)
h2, w2 = size(img2)
img1v, img2v = overlappingarea(img1, img2, x, y)
# @show (h1, w1),(h2, w2),(x,y)
img1v .= overlay.(img1v, img2v)
Expand Down
16 changes: 11 additions & 5 deletions src/wc-method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ end
initimages!(wc, i; kargs...) = initimage!.(wc, index(wc, i); kargs...)
function initimages!(wc::WC; maxiter=5, error=0.02)
params = wc.params
mask = wc.mask

si = sortperm(wc.weights, rev=true)
words = wc.words[si]
Expand Down Expand Up @@ -151,7 +150,14 @@ function recolor!(wc, args...; style=:average, kargs...)
end
nothing
end

"""
# Positional Args
* wc: the wordcloud to fit
* nepoch: training epoch nums
# Keyword Args
* patient: number of epochs before teleporting, set to `-1` to disable teleporting
* trainer: appoint a training engine
"""
function fit!(wc, args...; krags...)
if STATEIDS[getstate(wc)] < STATEIDS[:placement!]
placement!(wc)
Expand All @@ -161,6 +167,8 @@ function fit!(wc, args...; krags...)
wc.params[:epoch] += ep
if nc == 0
setstate!(wc, nameof(fit!))
else
setstate!(wc, nameof(placement!))
end
wc
end
Expand All @@ -177,7 +185,7 @@ function printcollisions(wc)
end
"""
# Positional Args
* wc: the wordcloud to train
* wc: the wordcloud to fit
* nepoch: training epoch nums
# Keyword Args
* retry: shrink & retrain times, defaults to 3, set to `1` to disable shrinking
Expand All @@ -188,11 +196,9 @@ function generate!(wc::WC, args...; retry=3, krags...)
if STATEIDS[getstate(wc)] < STATEIDS[:placement!]
placement!(wc)
end
ep, nc = -1, -1
for r in 1:retry
if r != 1
rescale!(wc, 0.97)
qtrees = [wc.maskqtree, wc.qtrees...]
dens = textoccupied(getwords(wc), getfontsizes(wc), getfonts(wc))/wc.params[:groundoccupied]
println("#$r. try scale = $(wc.params[:scale]). The density is reduced to $dens")
else
Expand Down

2 comments on commit da0906f

@guo-yong-zhi
Copy link
Owner

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/38028

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 v0.6.10 -m "<description of version>" da0906fffe0e9d97de34b93837654605466297e3
git push origin v0.6.10

Please sign in to comment.