WordCloud.isSupported
will evaluates to false
if the browser doesn't supply necessary functionalities for wordcloud2.js to run.
Some browsers come with restrictions on minimum font size preference on, and the preference will also impact canvas. wordcloud2.js works around it by scaling the canvas, but you may be interested to know value of the preference. The value detected is accessible at
WordCloud.miniumFontSize
WordCloud(canvas, options);
canvas
is the DOM Element of the canvas, i.e. document.getElementById('my_canvas')
or $('#my_canvas')[0]
in jQuery.
Available options as the property of the options
object are:
list
: List of words/text to paint on the canvas in a 2-d array, in the form of[word, size]
, e.g.[['foo', 12], ['bar', 6]]
.fontFamily
: font to use.fontWeight
: font weight to use, e.g.normal
,bold
or600
color
: color of the text, can be any CSS color, or acallback(word, weight, fontSize, distance, theta)
specifies different color for each item in the list. You may also specify colors with built-in keywords:random-dark
andrandom-light
.minSize
: minimum font size to draw on the canvas.weightFactor
: function to call or number to multiply forsize
of each word in the list.clearCanvas
: paint the entire canvas with background color and consider it empty before start.backgroundColor
: color of the background.
gridSize
: size of the grid in pixels for marking the availability of the canvas — the larger the grid size, the bigger the gap between words.origin
: origin of the “cloud” in[x, y]
.
drawMask
: visualize the grid by draw squares to mask the drawn areas.maskColor
: color of the mask squares.maskGapWidth
: width of the gaps between mask squares.
wait
: Wait for x milliseconds before start drawn the next item usingsetTimeout
.abortThreshold
: If the call with in the loop takes more than x milliseconds (and blocks the browser), abort immediately.abort
: callback function to call when abort.
minRotation
: If the word should rotate, the minimum rotation (in rad) the text should rotate.maxRotation
: If the word should rotate, the maximum rotation (in rad) the text should rotate. Set the two value equal to keep all text in one angle.
shuffle
: Shuffle the points to draw so the result will be different each time for the same list and settings.rotateRatio
: Probability for the word to rotate. Set the number to 1 to always rotate.
shape
: The shape of the "cloud" to draw. Can be any polar equation represented as a callback function, or a keyword present. Available presents arecircle
(default),cardioid
(apple or heart shape curve, the most known polar equation),diamond
(alias ofsquare
),triangle-forward
,triangle
, (alias oftriangle-upright
,pentagon
, andstar
.ellipticity
: degree of "flatness" of the shape wordcloud2.js should draw.
hover
: callback to call when the cursor enters or leaves a region occupied by a word. The callback will take arugmentscallback(item, dimension, event)
, whereevent
is the originalmousemove
event.click
: callback to call when the user clicks on a word. The callback will take arugmentscallback(item, dimension, event)
, whereevent
is the originalclick
event.
You can listen to those custom DOM events filed from the canvas element, instead of using callbacks for taking the appropriate action. Cancel the first two events causes the operation to stop immediately.
wordcloudstart
wordclouddrawn
wordcloudstop
wordcloudabort
wordcloud2.js itself will stop at wordcloudstart
event.