JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://d3js.org/d3.v3.js"></script>
<div style="font-family: Verdana; font-size: 20px;">Lorem ipsum sample text</div>
CSS
text {
font-family: Verdana;
}
JavaScript
var dataset = {
"2":[{"degree1":0,"degree2":1.5707963267949,"label":"Sample Text Test"},
{"degree1":1.5707963267949,"degree2":3.1415926535898,"label":"Lorem ipsum sample text"},
{"degree1":3.1415926535898,"degree2":4.7123889803847,"label":"Sample Text Text"},
{"degree1":4.7123889803847,"degree2":6.2831853071796,"label":"Lorem ipsum"}],
"1":[{"degree1":0,"degree2":3.1415926535898,"label":"Sample"},
{"degree1":3.1415926535898,"degree2":6.2831853071796,"label":"Text"}],
"0":[{"degree1":0,"degree2":6.2831853071796,"label":""}]
},
width = 450,
height = 450,
radius = 75;
// Helper methods
var innerRadius = function(d, i, j) {
return 1 + radius * j;
};
var outerRadius = function(d, i, j) {
return radius * (j + 1);
};
var startAngle = function(d, i, j) {
return d.data.degree1;
};
var endAngle = function(d, i, j) {
return d.data.degree2;
};
var pie = d3.layout.pie()
.sort(null);
var arc = d3.svg.arc()
.innerRadius(innerRadius)
.outerRadius(outerRadius)
.startAngle(startAngle)
.endAngle(endAngle);
var svg = d3.select('body').append('svg')
.attr('width', width)
.attr('height', height)
.append('g')
.attr('transform', 'translate(' + (width >> 1) + ',' + (height >> 1) + ')');
var level = svg.selectAll('g')
.data(function(d) {
return d3.values(dataset);
})
.enter()
.append('g');
var entry = level.selectAll('g')
.data(function(d, i) {
return pie(d);
})
.enter()
.append('g');
entry.append('path')
.attr('fill', '#aaa')
.attr('d', arc)
.attr('id', function(d, i, j) {
return 'arc' + i + '-' + j;
});
var label = entry.append('text')
.style('font-size', '20px')
.attr('dx', function(d, i, j) {
return Math.round((d.data.degree2 - d.data.degree1) * 180 / Math.PI);
})
.attr('dy', function(d, i, j) {
return ((radius * (j + 1)) - (1 + radius * j)) >> 1;
...