D3 Tag Cloud (Colors)

HTML

<script src="https://jardindesconnaissances.googlecode.com/svn-history/r82/trunk/public/js/d3.layout.cloud.js"></script>
<script src="https://jardindesconnaissances.googlecode.com/svn-history/r82/trunk/public/js/d3.layout.cloud.js"></script>
<div class="container">
  <div class="cont-box-shadow">
    <div class="info">
      <div class="var-icon">
        <div class="var-structure var-blue">
          (
        </div>
        <div class="var-type var-blue">
          A
        </div>
        <div class="var-structure var-blue">
          )
        </div>
      </div>
      <div class="var-name">Square Feet</div>
      <a href="#">
        <div class="info-icon"></div>
      </a>
      <a href="#">
        <div class="alert-icon"></div>
      </a>
    </div>
    <div class="chart-container">
      <div id="chart1"></div>
    </div>
    <div class="menu-tools">
      <a href="#">
        <div class="nD-edit sm-icons" title="Edit"></div>
      </a>
      <a href="#">
        <div class="nD-trash sm-icons" title="Delete"></div>
      </a>
    </div>
  </div>
</div>

CSS

.container {
  width: 196px;
  height: 196px;
  background-color: #eceded;
  position: relative;
  padding: 2px;
  overflow: hidden;
}

.cont-box-shadow {
  width: 100%;
  height: 100%;
  background-color: white;
  -webkit-box-shadow: 0px 1px 1px 1px rgba(171, 172, 172, 1);
  -moz-box-shadow: 0px 1px 1px 1px rgba(171, 172, 172, 1);
  box-shadow: 0px 1px 1px 1px rgba(171, 172, 172, 1);
}

.info {
  width: 100%;
  height: 25px;
  background-color: #555555;
  margin: 0 auto;
}

.var-icon {
  position: relative;
  float: left;
  margin: 5px;
  width: 19px;
  height: 14px;
  font-size: 12px;
}

.var-blue {
  color: #42a5f5;
}

.var-structure {
  position: relative;
  float: left;
}

.var-type {
  position: relative;
  float: left;
}

.var-name {
  font-size: 12px;
  color: white;
  position: relative;
  float: left;
  margin-top: 5px;
}

.alert-icon {
  display: none;
  background: url(http://i.imgur.com/TcAIU77.png) no-repeat;
  position: relative;
  float: right;
  margin: 5px 3px;
  width: 16px;
  height: 14px;
}

.info-icon {
  background: url(http://i.imgur.com/NhumKdn.png) no-repeat;
  position: relative;
  float: right;
  margin: 5px 5px 5px 0;
  width: 14px;
  height: 14px;
}

.info-icon:hover {
  background: url(http://i.imgur.com/Y4NJcU5.png) no-repeat;
}

.chart-container {
  width: 100%;
  height: 77%;
}

#chart1 {
  cursor: pointer;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.chart-container svg {
  width: 100%;
  height: 100%;
  transform-origin: 0;
}

.jqx-tag-cloud ul {
  margin: 0 !important;
}

.jqx-tag-cloud-item {
  padding: 2px !important;
}

.menu-tools {
  display: none;
  position: relative;
  float: right;
  margin-right: 5px;
}

.container:hover .menu-tools {
  display: block;
}

.sm-icons {
  width: 15px;
  height: 15px;
  position: relative;
  float: left;
  margin-right: 5px;
}

.nD-edit {
  background: url(http://i.imgur.com/2JA9xGB.png) no-repeat;
}

.nD-edit:hover {
  background:...

JavaScript

var colors = d3.scale.linear()
    .domain([0, 10])
    .range(["#333", "#888"]);

  d3.layout.cloud()
    .words([
      "#FF0000", "#FF00FF", "#B0171F", "#DC143C", "#FFB6C1", "#FFAEB9", "#CD8C95", "#CDC1C5", "#CD3278", "#8B7B8B", "#EE00EE", "#EEAEEE", "#607B8B", "#87CEEB", "#8DB6CD", "#33A1C9", "#4EEE94", "#E0EEE0", "#C1FFC1", "#CDC9A5", "#EE7942", "#B7B7B7", "#FFF8DC", "#808080", "#BDBDBD"
    ].map(function(d) {
      return {
        text: d,
        size: 10 + Math.random() * 10
      };
    }))
    .rotate(function() {
      return 0;
    })
    .font("Impact")
    .fontSize(function(d) {
      return d.size;
    })
    .on("end", draw)
    .start();

  function draw(words) {
    d3.select("#chart1").append("svg")
    	.attr("width", "100%")
      .attr("height", "100%")
      .append("g")
      .attr("transform", "translate(85,85)")
      .selectAll("text")
      .data(words)
      .enter().append("text")
      .style("font-size", function(d) {
        return d.size + "px";
      })
      .style("font-family", "Impact")
      .style("fill", function(d, i) {
        return colors(i);
      })
      .attr("text-anchor", "middle")
      .attr("transform", function(d) {
        return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
      })
      .on("mouseover", function(d) {
      	d3.select(this).style("fill", function(d) {
        return d.text;
      });
			})                  
      .on("mouseout", function(d) {
        d3.select(this).style("fill", function(d, i) {
        return colors(i);
      });
      })
      .text(function(d) {
        return d.text;
      });
  }