@@ -81,10 +81,10 @@ function wordcloud(text; language=:auto, stopwords=:auto, stopwords_extra=nothin
81
81
wordcloud (processtext (text, language= language, stopwords= stopwords, stopwords_extra= stopwords_extra, maxnum= maxnum); language= language, kargs... )
82
82
end
83
83
wordcloud (words, weight:: Number ; kargs... ) = wordcloud (words, repeat ([weight], length (words)); kargs... )
84
- function wordcloud (words:: AbstractVector{<:AbstractString} , weights:: AbstractVector{<:Real} ;
85
- colors= :auto , angles= :auto ,
86
- mask= :auto , svgmask= nothing , editmask= true , masksize = :auto , fonts = :auto , language = :auto ,
87
- transparent = :auto , minfontsize= :auto , maxfontsize= :auto , avgfontsize = 12 ,
84
+ function wordcloud (words:: AbstractVector{<:AbstractString} , weights:: AbstractVector{<:Real} ;
85
+ colors= :auto , angles= :auto , fonts = :auto , language = :auto ,
86
+ mask= :auto , svgmask= nothing , editmask= true , transparent = :auto , masksize = :auto ,
87
+ avgfontsize = 12 , minfontsize= :auto , maxfontsize= :auto ,
88
88
spacing= :auto , density= 0.5 , state= layout!,
89
89
style= :auto , centralword= :auto , reorder= :auto , level= :auto , rt= :auto , kargs... )
90
90
@assert length (words) == length (weights) > 0
@@ -97,10 +97,12 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
97
97
level != :auto && (params[:level ] = level)
98
98
rt != :auto && (params[:rt ] = rt)
99
99
100
- colors, angles, mask, svgmask, fonts, transparent = processscheme (words, weights; colors= colors, angles= angles, mask= mask, svgmask= svgmask, editmask= editmask, masksize= masksize,
101
- fonts= fonts, avgfontsize= avgfontsize, language= language, transparent= transparent, params= params, kargs... )
100
+ colors, angles, fonts, mask, svgmask, transparent = processscheme (words, weights; colors= colors, angles= angles, fonts= fonts, language= language,
101
+ mask= mask, svgmask= svgmask, editmask= editmask, transparent= transparent, masksize= masksize,
102
+ avgfontsize= avgfontsize, params= params, kargs... )
102
103
params[:colors ] = Any[colors... ]
103
104
params[:angles ] = angles
105
+ params[:fonts ] = fonts
104
106
params[:transparent ] = transparent
105
107
mask, maskqtree, groundsize, volume = preparemask (mask, transparent)
106
108
params[:groundsize ] = groundsize
@@ -130,8 +132,7 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
130
132
end
131
133
params[:spacing ] = spacing
132
134
params[:density ] = density
133
- params[:fonts ] = fonts
134
-
135
+
135
136
params[:state ] = nameof (wordcloud)
136
137
params[:epoch ] = 0
137
138
params[:word2index ] = nothing
@@ -140,31 +141,35 @@ function wordcloud(words::AbstractVector{<:AbstractString}, weights::AbstractVec
140
141
params[:scale ] = - 1
141
142
params[:wordids ] = collect (1 : length (words))
142
143
l = length (words)
143
- wc = WC (copy (words), float .(weights), Vector (undef, l), Vector {SVG} (undef, l),
144
+ wc = WC (copy (words), float .(weights), Vector (undef, l), Vector {SVG} (undef, l),
144
145
mask, svgmask, Vector {Stuffing.QTrees.U8SQTree} (undef, l), maskqtree, params)
145
146
if state != wordcloud
146
147
state (wc)
147
148
end
148
149
wc
149
150
end
150
- function processscheme (words, weights; colors= :auto , angles= :auto , mask = :auto , svgmask = nothing , editmask = true ,
151
- masksize = :auto , maskcolor = :default , keepmaskarea = :auto ,
152
- backgroundcolor = :default , padding = :default ,
153
- outline = :default , linecolor = :auto , fonts = :auto , avgfontsize = 12 , language = :auto ,
154
- transparent = :auto , params= Dict {Symbol,Any} (), kargs... )
151
+ function processscheme (words, weights; colors= :auto , angles= :auto , fonts = :auto , language = :auto ,
152
+ mask = :auto , svgmask = nothing , editmask = true , transparent = :auto ,
153
+ masksize = :auto , maskcolor = :default , keepmaskarea = :auto , avgfontsize = 12 ,
154
+ backgroundcolor = :default , padding = :default , outline = :default , linecolor = :auto ,
155
+ params= Dict {Symbol,Any} (), kargs... )
155
156
merge! (params, kargs)
156
- colors in DEFAULTSYMBOLS && (colors = randomscheme (weights))
157
- angles in DEFAULTSYMBOLS && (angles = randomangles ())
158
- fonts in DEFAULTSYMBOLS && (fonts = randomfonts (detect_language (words, language)))
157
+
159
158
maskcolor0 = maskcolor
160
159
backgroundcolor0 = backgroundcolor
160
+
161
+ colors in DEFAULTSYMBOLS && (colors = randomscheme (weights))
162
+ angles in DEFAULTSYMBOLS && (angles = randomangles ())
163
+ fonts in DEFAULTSYMBOLS && (language = detect_language (words, language); fonts = randomfonts (language))
161
164
colors isa Symbol && (colors = (colorschemes[colors]. colors... ,))
162
165
params[:colors_scheme ] = colors
163
166
params[:angles_scheme ] = angles
164
167
params[:fonts_scheme ] = fonts
168
+ params[:language ] = language
165
169
colors = Iterators. take (iter_expand (colors), length (words)) |> collect
166
170
angles = Iterators. take (iter_expand (angles), length (words)) |> collect
167
171
fonts = Iterators. take (iter_expand (fonts), length (words)) |> collect
172
+
168
173
if mask == :auto || mask isa Function
169
174
if maskcolor in DEFAULTSYMBOLS
170
175
if backgroundcolor in DEFAULTSYMBOLS || backgroundcolor == :maskcolor
@@ -243,10 +248,10 @@ function processscheme(words, weights; colors=:auto, angles=:auto, mask=:auto, s
243
248
end
244
249
padding in DEFAULTSYMBOLS && (padding = outline)
245
250
if svgmask != = nothing
246
- svgmask = loadmask (svgmask, ms... ; color= maskcolor, transparent= transparent, backgroundcolor= bc,
251
+ svgmask = loadmask (svgmask, ms... ; color= maskcolor, transparent= transparent, backgroundcolor= bc,
247
252
outline= outline, linecolor= linecolor, padding= padding, preservevolume= keepmaskarea, kargs... )
248
253
end
249
- mask, binarymask = loadmask (mask, ms... ; color= maskcolor, transparent= transparent, backgroundcolor= bc,
254
+ mask, binarymask = loadmask (mask, ms... ; color= maskcolor, transparent= transparent, backgroundcolor= bc,
250
255
outline= outline, linecolor= linecolor, padding= padding, return_bitmask= true , preservevolume= keepmaskarea, kargs... )
251
256
binarymask === nothing || (transparent = .! binarymask)
252
257
else
@@ -275,7 +280,7 @@ function processscheme(words, weights; colors=:auto, angles=:auto, mask=:auto, s
275
280
Render. recolor! (mask, maskcolor) # tobitmap后有杂色 https://github.com/JuliaGraphics/Luxor.jl/issues/160
276
281
end
277
282
end
278
- colors, angles, mask, svgmask, fonts , transparent
283
+ colors, angles, fonts, mask, svgmask , transparent
279
284
end
280
285
281
286
"""
@@ -309,7 +314,7 @@ Base.lastindex(wc::WC) = lastindex(wc.words)
309
314
Base. broadcastable (wc:: WC ) = Ref (wc)
310
315
getstate (wc:: WC ) = wc. params[:state ]
311
316
setstate! (wc:: WC , st:: Symbol ) = wc. params[:state ] = st
312
- struct ID{T}
317
+ struct ID{T}
313
318
id:: T
314
319
end
315
320
wordids (wc, i:: Integer ) = wc. params[:wordids ][i]
@@ -355,7 +360,7 @@ setdoc = "This function accepts three positional arguments: a wordcloud object,
355
360
function setfonts! (wc:: WC , w, v:: Union{AbstractString,AbstractVector{<:AbstractString}} )
356
361
@view (wc. params[:fonts ][index (wc, w)]) .= v
357
362
end
358
- @doc setdoc
363
+ @doc setdoc
359
364
function setwords! (wc:: WC , w, v:: Union{AbstractString,AbstractVector{<:AbstractString}} )
360
365
m = word2index (wc)
361
366
@assert ! any (v .∈ Ref (keys (m)))
368
373
@doc getdoc getimages (wc:: WC , w= :) = wc. imgs[index (wc, w)]
369
374
@doc getdoc getsvgimages (wc:: WC , w= :) = wc. svgs[index (wc, w)]
370
375
371
- @doc setdoc
376
+ @doc setdoc
372
377
function setimages! (wc:: WC , w, v:: AbstractMatrix )
373
378
@view (wc. imgs[index (wc, w)]) .= Ref (v)
374
379
initqtree! (wc, w)
0 commit comments