Comparing version 1.1.2 to 1.2.0
27
API.md
@@ -16,2 +16,19 @@ # wordcloud2.js APIs | ||
## Stop the renderring | ||
Sometimes we need to stop wordcloud2.js renderring, to optimize the component renderring performance, especially in some FE libraries like 'React'. | ||
In this scenario, you can just call the function below | ||
WordCloud.stop | ||
```js | ||
useEffect(() => { | ||
... | ||
return () => { | ||
// stop the renderring | ||
WordCloud.stop(); | ||
}; | ||
}, [deps]); | ||
``` | ||
## Usage | ||
@@ -34,6 +51,6 @@ | ||
* e.g. `[['foo', 12], ['bar', 6]]` | ||
* Optionally, you can send additional data as array elements, in the form of `[word, size, data1, data2, ... ]` which can then be used in the callback functions of `click` and `hover` interactions. | ||
* Optionally, you can send additional data as array elements, in the form of `[word, size, data1, data2, ... ]` which can then be used in the callback functions of `click`, `hover` interactions and fontWeight, color and classes callbacks. | ||
* e.g. `[['foo', 12, 'http://google.com?q=foo'], ['bar', 6, 'http://google.com?q=bar']]`. | ||
* `fontFamily`: font to use. | ||
* `fontWeight`: font weight to use, can be, as an example, `normal`, `bold` or `600` or a `callback(word, weight, fontSize)` specifies different font-weight for each item in the list. | ||
* `fontWeight`: font weight to use, can be, as an example, `normal`, `bold` or `600` or a `callback(word, weight, fontSize, extraData)` specifies different font-weight for each item in the list. | ||
* `color`: color of the text, can be any CSS color, or a `callback(word, weight, fontSize, distance, theta)` specifies different color for each item in the list. | ||
@@ -43,3 +60,3 @@ You may also specify colors with built-in keywords: `random-dark` and `random-light`. If this is a DOM cloud, color can also be `null` to disable hardcoding of | ||
* `classes`: for DOM clouds, allows the user to define the class of the span elements. Can be a normal class string, | ||
applying the same class to every span or a `callback(word, weight, fontSize, distance, theta)` for per-span class definition. | ||
applying the same class to every span or a `callback(word, weight, fontSize, extraData)` for per-span class definition. | ||
In canvas clouds or if equals `null`, this option has no effect. | ||
@@ -84,3 +101,3 @@ * `minSize`: minimum font size to draw on the canvas. | ||
* `shape`: The shape of the "cloud" to draw. Can be any polar equation represented as a callback function, or a keyword present. | ||
Available presents are `circle` (default), `cardioid` (apple or heart shape curve, the most known polar equation), `diamond`, `square`, `triangle-forward`, `triangle`, (alias of `triangle-upright`, `pentagon`, and `star`. | ||
Available presents are `circle` (default), `cardioid` (apple or heart shape curve, the most known polar equation), `diamond`, `square`, `triangle-forward`, `triangle`, (alias of `triangle-upright`), `pentagon`, and `star`. | ||
* `ellipticity`: degree of "flatness" of the shape wordcloud2.js should draw. | ||
@@ -90,4 +107,2 @@ | ||
Notice: `hover` and `click` are currently only for HTML5 canvas word clouds. | ||
* `hover`: callback to call when the cursor enters or leaves a region occupied by a word. The callback will take arguments `callback(item, dimension, event)`, where `event` is the original `mousemove` event. | ||
@@ -94,0 +109,0 @@ * `click`: callback to call when the user clicks on a word. The callback will take arguments `callback(item, dimension, event)`, where `event` is the original `click` event. |
@@ -9,3 +9,2 @@ 'use strict'; | ||
var BASE_COMMIT = grunt.option('base-commit') || | ||
process.env.TRAVIS_BRANCH || | ||
''; | ||
@@ -45,18 +44,9 @@ | ||
} | ||
}, | ||
jshint: { | ||
options: { | ||
jshintrc: true, | ||
reporterOutput: "" // Workaround jshint/jshint#2922 | ||
}, | ||
all: ['src/*.js'] | ||
} | ||
}); | ||
grunt.loadNpmTasks('grunt-contrib-jshint'); | ||
grunt.loadNpmTasks('grunt-shell'); | ||
grunt.loadNpmTasks('grunt-contrib-connect'); | ||
grunt.registerTask('test', ['jshint','test-slimerjs']); | ||
grunt.registerTask('test', ['test-slimerjs']); | ||
grunt.registerTask('compare', ['compare-slimerjs']); | ||
@@ -70,13 +60,2 @@ | ||
['connect', 'shell:compare-slimerjs']); | ||
grunt.registerTask('travis-ci', function() { | ||
if (process.env.TRAVIS_PULL_REQUEST === 'false') { | ||
// Not working on pull requests -- simply run test job. | ||
grunt.task.run(['test']); | ||
} else { | ||
// Running on pull requests -- check linting, and compare the images with | ||
// the branch to merge. | ||
grunt.task.run(['jshint', 'compare']); | ||
} | ||
}); | ||
}; |
{ | ||
"name": "wordcloud", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "Tag cloud/Wordle presentation on 2D canvas or HTML", | ||
@@ -36,5 +36,4 @@ "homepage": "http://timdream.org/wordcloud2.js/", | ||
"grunt-contrib-connect": "^2.1.0", | ||
"grunt-contrib-jshint": "^2.1.0", | ||
"grunt-shell": "^0.6.4" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# wordcloud2.js [![Build Status](https://travis-ci.org/timdream/wordcloud2.js.svg?branch=gh-pages)](https://travis-ci.org/timdream/wordcloud2.js) [![npm version](https://badge.fury.io/js/wordcloud.svg)](http://badge.fury.io/js/wordcloud) | ||
# wordcloud2.js [![npm version](https://badge.fury.io/js/wordcloud.svg)](http://badge.fury.io/js/wordcloud) | ||
@@ -3,0 +3,0 @@ Create a tag cloud/[Wordle](http://www.wordle.net/) presentation on 2D canvas or HTML. |
@@ -149,2 +149,13 @@ /*! | ||
var getItemExtraData = function (item) { | ||
if (Array.isArray(item)) { | ||
var itemCopy = item.slice() | ||
// remove data we already have (word and weight) | ||
itemCopy.splice(0, 2) | ||
return itemCopy | ||
} else { | ||
return [] | ||
} | ||
} | ||
// Based on http://jsfromhell.com/array/shuffle | ||
@@ -161,2 +172,3 @@ var shuffleArray = function shuffleArray (arr) { | ||
var timer; | ||
var WordCloud = function WordCloud (elements, options) { | ||
@@ -511,3 +523,3 @@ if (!isSupported) { | ||
var getTextInfo = function getTextInfo (word, weight, rotateDeg) { | ||
var getTextInfo = function getTextInfo (word, weight, rotateDeg, extraDataArray) { | ||
// calculate the acutal font size | ||
@@ -539,3 +551,3 @@ // fontSize === 0 means weightFactor function wants the text skipped, | ||
if (getTextFontWeight) { | ||
fontWeight = getTextFontWeight(word, weight, fontSize) | ||
fontWeight = getTextFontWeight(word, weight, fontSize, extraDataArray) | ||
} else { | ||
@@ -728,7 +740,7 @@ fontWeight = settings.fontWeight | ||
/* Actually draw the text on the grid */ | ||
var drawText = function drawText (gx, gy, info, word, weight, distance, theta, rotateDeg, attributes) { | ||
var drawText = function drawText (gx, gy, info, word, weight, distance, theta, rotateDeg, attributes, extraDataArray) { | ||
var fontSize = info.fontSize | ||
var color | ||
if (getTextColor) { | ||
color = getTextColor(word, weight, fontSize, distance, theta) | ||
color = getTextColor(word, weight, fontSize, distance, theta, extraDataArray) | ||
} else { | ||
@@ -741,3 +753,3 @@ color = settings.color | ||
if (getTextFontWeight) { | ||
fontWeight = getTextFontWeight(word, weight, fontSize) | ||
fontWeight = getTextFontWeight(word, weight, fontSize, extraDataArray) | ||
} else { | ||
@@ -749,3 +761,3 @@ fontWeight = settings.fontWeight | ||
if (getTextClasses) { | ||
classes = getTextClasses(word, weight, fontSize) | ||
classes = getTextClasses(word, weight, fontSize, extraDataArray) | ||
} else { | ||
@@ -919,4 +931,6 @@ classes = settings.classes | ||
var extraDataArray = getItemExtraData(item) | ||
// get info needed to put the text onto the canvas | ||
var info = getTextInfo(word, weight, rotateDeg) | ||
var info = getTextInfo(word, weight, rotateDeg, extraDataArray) | ||
@@ -961,3 +975,3 @@ // not getting the info means we shouldn't be drawing this one. | ||
drawText(gx, gy, info, word, weight, | ||
(maxRadius - r), gxy[2], rotateDeg, attributes) | ||
(maxRadius - r), gxy[2], rotateDeg, attributes, extraDataArray) | ||
@@ -1180,4 +1194,3 @@ // Mark the spaces on the grid as filled | ||
addEventListener('wordcloudstart', anotherWordCloudStart) | ||
var timer = loopingFunction(function loop () { | ||
timer = loopingFunction(function loop () { | ||
if (i >= settings.list.length) { | ||
@@ -1215,2 +1228,7 @@ stoppingFunction(timer) | ||
WordCloud.minFontSize = minFontSize | ||
WordCloud.stop = function stop () { | ||
if (timer) { | ||
window.clearImmediate(timer) | ||
} | ||
} | ||
@@ -1217,0 +1235,0 @@ // Expose the library as an AMD module |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
332186
6
2419