Skip to content

Commit

Permalink
less print
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyongzhi committed May 8, 2024
1 parent 2394dde commit cd9d95d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/strategy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function findscale!(wc::WC; initialscale=0, density=0.3, maxiter=5, tolerance=0.
setparameter!(wc, sc1, :scale)
tg1 = wordsoccupancy!(wc)
dens = tg1 / area
println("⋯scale=$(getparameter(wc, :scale)), density=$dens\t", dens > density ? "" : "")
@debug "⋯scale=$(getparameter(wc, :scale)), density=$dens\t" * (dens > density ? "" : "")
if tg1 > target
if best_tar_H > tg1
best_tar_H = tg1
Expand All @@ -169,18 +169,18 @@ function findscale!(wc::WC; initialscale=0, density=0.3, maxiter=5, tolerance=0.
if !(best_scale_L < sc2 < best_scale_H)
if isfinite(best_tar_H + best_tar_L)
sc2_ = ((best_scale_H^2 + best_scale_L^2) / 2.)
println("bisection search takes effect: scale $sc2 -> $sc2_")
@debug "bisection search takes effect: scale $sc2 -> $sc2_"
sc2 = sc2_
# @show best_scale_L best_scale_H
elseif isfinite(best_tar_H)
sc2_ = sc1 * (0.95^oneway_count)
oneway_count += 1
println("one-way search takes effect: scale $sc2 -> $sc2_")
@debug "one-way search takes effect: scale $sc2 -> $sc2_"
sc2 = sc2_
elseif isfinite(best_tar_L)
sc2_ = sc1 / (0.95^oneway_count)
oneway_count += 1
println("one-way search takes effect: scale $sc2 -> $sc2_")
@debug "one-way search takes effect: scale $sc2 -> $sc2_"
sc2 = sc2_
else
error("`findscale!` failed")
Expand Down
6 changes: 3 additions & 3 deletions src/wc-class.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
error("Have you set the right `transparent`? e.g. `transparent=mask[1,1]`")
end
avgsize = round(Int, sqrt(volume / length(words)))
println("mask size: $(size(mask, 1))×$(size(mask, 2)), volume: $(round(Int, volume))² ($(avgsize)²/word)")
@debug "mask size: $(size(mask, 1))×$(size(mask, 2)), volume: $(round(Int, volume))² ($(avgsize)²/word)"
params[:maxfontsize0] = maxfontsize
if maxfontsize == :auto
maxfontsize = minimum(size(mask))
Expand All @@ -103,7 +103,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
minfontsize = min(maxfontsize, 8, sqrt(volume / length(words) / 8))
# 只和单词数量有关,和单词长度无关。不管单词多长,字号小了依然看不见。
end
println("set fontsize ∈ [$minfontsize, $maxfontsize]")
@debug "set fontsize ∈ [$minfontsize, $maxfontsize]"
params[:minfontsize] = minfontsize
params[:maxfontsize] = maxfontsize
params[:spacing] = spacing
Expand Down Expand Up @@ -359,7 +359,7 @@ end

Base.show(io::IO, m::MIME"image/png", wc::WC) = Base.show(io, m, paint(wc::WC))
Base.show(io::IO, m::MIME"image/svg+xml", wc::WC) = Base.show(io, m, paintsvg(wc::WC))
Base.show(io::IO, m::MIME"text/plain", wc::WC) = print(io, "wordcloud(", wc.words, ") # ", length(wc), "words")
Base.show(io::IO, m::MIME"text/plain", wc::WC) = println(io, "wordcloud(", wc.words, ") # ", length(wc), "words")
function Base.showable(::MIME"image/png", wc::WC)
STATEIDS[getstate(wc)] >= STATEIDS[:initialize!] && showable("image/png", zeros(ARGB, (1, 1)))
end
Expand Down
6 changes: 3 additions & 3 deletions src/wc-method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function initialize!(wc::WC; maxiter=5, tolerance=0.02)
wc.params[:wordids] = @view wc.params[:wordids][si]
wc.params[:word2index] = nothing
wc.params[:id2index] = nothing
println("set density = $(params[:density])")
@debug "set density = $(params[:density])"
findscale!(wc, density=params[:density], maxiter=maxiter, tolerance=tolerance)
printfontsizes(wc)
initialize!(wc, :)
Expand All @@ -46,10 +46,10 @@ end
function printfontsizes(wc)
nsmall = findlast(i->getfontsizes(wc, i)<=wc.params[:minfontsize], length(wc):-1:1)
nsmall === nothing && (nsmall = 0)
println("fontsize ∈ [$(getfontsizes(wc, length(wc))), $(getfontsizes(wc, 1))]")
@debug "fontsize ∈ [$(getfontsizes(wc, length(wc))), $(getfontsizes(wc, 1))]"
if nsmall > 0
perc = round(Int, nsmall/length(wc)*100)
println("$nsmall words($perc%) are limited to the minimum font size.")
@debug "$nsmall words($perc%) are limited to the minimum font size."
if perc > 70
msg = "It seems too crowded. Word size may be seriously distorted. You need to reduce the number of words or set a larger mask."
ratio = volumeproposal(wc.words, wc.weights) / getparameter(wc, :volume)
Expand Down

0 comments on commit cd9d95d

Please sign in to comment.