Skip to content

Commit 1bf50f5

Browse files
committed
fix ui for chart label's
1 parent b06236e commit 1bf50f5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

scripts/chart/chart-core.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function donutChart() {
4444
.attr('height', height + margin.top + margin.bottom)
4545
.attr('class', 'backColorChart')
4646
.append('g')
47-
.attr('transform', 'translate(' + width / 2 + ',' + height / 2 + ')');
47+
.attr('transform', 'translate(' + (width / 2 + 30) + ',' + (height / 2 + 30) + ')');
4848
// ===========================================================================================
4949

5050
// ===========================================================================================
@@ -83,6 +83,12 @@ function donutChart() {
8383

8484
// changes the point to be on left or right depending on where label is.
8585
pos[0] = radius * 0.95 * (midAngle(d) < Math.PI ? 1 : -1);
86+
87+
if (d.data.percentage < 0.10 || d.data.url == 'Others' ){
88+
pos[0] = pos[0] * 1.1;
89+
pos[1] = pos[1] * 1.15;
90+
}
91+
8692
return 'translate(' + pos + ')';
8793
})
8894
.style('text-anchor', function (d) {
@@ -98,10 +104,14 @@ function donutChart() {
98104
.data(pie)
99105
.enter().append('polyline')
100106
.attr('points', function (d) {
101-
102107
// see label transform function for explanations of these three lines.
103108
var pos = outerArc.centroid(d);
104109
pos[0] = radius * 0.95 * (midAngle(d) < Math.PI ? 1 : -1);
110+
111+
if (d.data.percentage < 0.10 || d.data.url == 'Others'){
112+
pos[0] = pos[0] * 1.1;
113+
pos[1] = pos[1] * 1.15;
114+
}
105115
return [arc.centroid(d), outerArc.centroid(d), pos]
106116
});
107117
// ===========================================================================================

0 commit comments

Comments
 (0)