D3 Tag Cloud
by Steve Thompson
HTML
<script src="//rawgithub.com/Caged/d3-tip/v0.6.2/index.js"></script>
<script src="//s3.amazonaws.com/nd-cdn/d3.layout.cloud.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700' rel='stylesheet' type='text/css'>
<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">
<svg xmlns="http://www.w3.org/2000/svg" id="chart2" width="100%" height="100%"></svg>
</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
body {
font-family: 'Open Sans', sans-serif;
}
.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;
}
.chart-container svg text:hover {
opacity: 0.75;
}
.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...
JavaScript
var colors = d3.scale.linear()
.domain([0,1,2,3,4,5,6,10,15,20,100])
.range(["#bbb", "#aaa", "#999", "#888", "#777", "#666", "#555", "#444", "#333", "#222"]);
var svg = d3.select('#chart1').select('svg');
var bbox = d3.select('svg').node().getBoundingClientRect();
console.log(bbox);
var frequency_list =...