Skip to content

Commit

Permalink
supports rotated labels
Browse files Browse the repository at this point in the history
  • Loading branch information
pshivale committed Sep 13, 2016
1 parent 6171dab commit 07aad56
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
14 changes: 12 additions & 2 deletions psd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ psd3.Graph = function(config) {
drilldownTransitionDuration: 0,
stroke: "white",
strokeWidth: 2,
highlightColor: "orange"
highlightColor: "orange",
rotateLabel: false
};
/*console.log("before defaults");
for(var property in config){
Expand Down Expand Up @@ -299,7 +300,16 @@ psd3.Pie.prototype.draw = function(svg, totalRadius, dataset, originalDataset, o
var a = [];
a[0] = arc.centroid(d)[0] - parentCentroid[0];
a[1] = arc.centroid(d)[1] - parentCentroid[1];
return "translate(" + a + ")";
var rotate = "";
if(_this.config.rotateLabel === true){
var rotateAngle = (d.endAngle + d.startAngle) / 2 * (180 / Math.PI) + 90;
//console.log("rotateAngle = " + rotateAngle);
var b = [];
b[0] = parentCentroid[0];
b[1] = parentCentroid[1];
rotate = "rotate( " + rotateAngle + ", " + b + ")";
}
return "translate(" + a + ")" + rotate;
})
.attr("text-anchor", "middle")
.text(_this.textText)
Expand Down
4 changes: 2 additions & 2 deletions psd3.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion samples/sunburst_chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ <h2><a href="../index.html">psd3</a> - Sunburst Chart</h2>
},
transition: "bounce",
transitionDuration: 1000,
donutRadius: 50
donutRadius: 50,
rotateLabel: true
};

var samplePie = new psd3.Pie(config);
Expand Down
3 changes: 2 additions & 1 deletion src/js/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ psd3.Graph = function(config) {
drilldownTransitionDuration: 0,
stroke: "white",
strokeWidth: 2,
highlightColor: "orange"
highlightColor: "orange",
rotateLabel: false
};
/*console.log("before defaults");
for(var property in config){
Expand Down
11 changes: 10 additions & 1 deletion src/js/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,16 @@ psd3.Pie.prototype.draw = function(svg, totalRadius, dataset, originalDataset, o
var a = [];
a[0] = arc.centroid(d)[0] - parentCentroid[0];
a[1] = arc.centroid(d)[1] - parentCentroid[1];
return "translate(" + a + ")";
var rotate = "";
if (_this.config.rotateLabel === true) {
var rotateAngle = (d.endAngle + d.startAngle) / 2 * (180 / Math.PI) + 90;
//console.log("rotateAngle = " + rotateAngle);
var b = [];
b[0] = parentCentroid[0];
b[1] = parentCentroid[1];
rotate = "rotate( " + rotateAngle + ", " + b + ")";
}
return "translate(" + a + ")" + rotate;
})
.attr("text-anchor", "middle")
.text(_this.textText)
Expand Down

0 comments on commit 07aad56

Please sign in to comment.