angular-d3-word-cloud
Run examples with server
$ npm install
$ npm run test
$ npm run dev //default server port is 8000
$ npm run release //build release files
Dependencies
Demo
Watch the wordcloud component in action on the demo page.
How to use
Install
bower
$ bower install angular-d3-word-cloud
angular.js, d3.js, d3.layout.cloud.js would be install as dependencies auto. If it won't for some error, install it manually.
$ bower install angular
$ bower install d3
$ bower install d3-cloud
npm
$ npm install angular-d3-word-cloud
Inject scripts
Add dependencies to the section of your index html:
<!-- it's important for d3.js -->
Options
Note: if words element not contains color property, default will use d3 schemeCategory20
words=[array]
-> [{text: '',size: 0, color: '#6d989e', tooltipText: ''}]height=[number]
width=[number]
padding=[number]
-> [optional] padding for each word, defaults to5
rotate=[number, function]
-> [optional] rotation for each word, default to~~(Math.random() * 2) * 60
random=[function]
-> [optional] default toMath.random
, If specified, sets the internal random number generator, used for selecting the initial position of each word, and the clockwise/counterclockwise direction of the spiral for each word. This should return a number in the range [0, 1).use-tooltip=[boolean]
default tooltip templateuse-transition=[boolean]
transition with font sizeon-click=[function]
-> word clicked callback
Directive Usage
Basic usage
Inject angular-d3-word-cloud
into angular module, set up some options to our controller
{ angular { var self = this; selfheight = $windowinnerHeight * 05; selfwidth = $element0offsetWidth; selfwordClicked = wordClicked; selfrotate = rotate; selfuseTooltip = true; selfuseTransition = false; selfwords = text: 'Angular'size: 25 color: '#6d989e' tooltipText: 'Angular Tooltip' text: 'Angular2'size: 35 color: '#473fa3' tooltipText: 'Angular2 Tooltip' selfrandom = random; { return 04; // a constant value here will ensure the word position is fixed upon each page refresh. } { return ~~Math * 2 * 90; } { ; } }}
Advanced usage
Define some content and split(/\s+/g)
var content = 'Angular Angular2 Angular3 Express Nodejs'; originWords = selfcontent; originWords = originWords
Font size calculations
var element = document; var height = $windowinnerHeight * 075; elementstyleheight = height + 'px'; var width = elementwidth; var maxCount = originWords0count; var minCount = originWordsoriginWordslength - 1count; var maxWordSize = width * 015; var minWordSize = maxWordSize / 5; var spread = maxCount - minCount; if spread <= 0 spread = 1; var step = maxWordSize - minWordSize / spread; selfwords = originWords selfwidth = width; selfheight = height;