Skip to content

asupian/d3-wordcloud

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easy Word Cloud using D3

There is an amazing D3 wordcloud plugin for creating beautiful wordclouds. But it's not trivial for everyone to put it to use. This plugin makes it easy to create such a wordcloud.

Usage

A simple html page with a wordcloud might contain:

<html>
  <head>
    <title>Word Cloud</title>
    <script src="lib/d3/d3.js"></script>
    <script src="lib/d3/d3.layout.cloud.js"></script>
    <script src="d3.wordcloud.js"></script>
  </head>
  <body>
    <div id='cloud'></div>
    <script>
      d3.wordcloud()
        .size([800, 400])
        .selector('#cloud')
        .words([{text: 'word', size: 5}, {text: 'cloud', size: 15}])
        .start();
    </script>
  </body>
</html>

That's all! The following properties are accepted:

  • selector() which css selector to create the wordcloud on
  • element() an element instead of the previous selector
  • scale() a d3 scale for sizing words, e.g. sqrt, log or linear
  • fill() a d3 scale for coloring words, e.g. d3.scale.category20b()
  • transitionDuration() how many milliseconds a resize transation takes

In addition to this, the following d3-cloud properties are accepted:

  • size() dimensions [width, height]
  • words() array of {text: 'word', size: 1} hashes
  • font()
  • fontStyle()
  • fontWeight()
  • spiral(), which can be archimedean or rectangular
  • padding()

As a bonus, if a word contains a href key, the word will link to the value, and the word will become slightly larger when the mouse hovers over (to indicate that it is clickable, in addition to the mouse hand pointer).

Links

About

Plug-and-play wordcloud with D3

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 98.5%
  • HTML 1.5%