Skip to content

Commit fe8cb8f

Browse files
committed
Fix issue regarding piecharts with only single slice
Fixed failing tests. This fixes #4
1 parent d40c59e commit fe8cb8f

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
.bowerrc
1+
bower_components

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svg-piechart",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"authors": ["Uemit Seren <uemit.seren@gmail.com>"],
55
"description": "Element to draw a piechart on a SVG.",
66
"keywords": "svg, piechart, polymer, web-components",

svg-piechart.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,18 @@
167167

168168
startAngle = endAngle;
169169
endAngle = startAngle + angle;
170-
171-
arcs.push({
170+
var arc = {
172171
x1: 180 + 180*Math.cos(Math.PI*startAngle/180),
173172
y1: 180 + 180*Math.sin(Math.PI*startAngle/180),
174173
x2: 180 + 180*Math.cos(Math.PI*endAngle/180),
175174
y2: 180 + 180*Math.sin(Math.PI*endAngle/180),
176175
largeArcFlag: largeArcFlag,
177176
color: colors[i]
178-
});
177+
};
178+
if (arc.x2 > 179.9 && arc.y2 === 0 && arc.largeArcFlag === 1) {
179+
arc.x2 = 179.99;
180+
}
181+
arcs.push(arc);
179182
}
180183

181184
return arcs;

test/basic-test.html

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
test('defaults', function() {
4040
assert.equal(myEl.colors.length,0);
41-
assert.equal(myEl.size,50);
41+
assert.equal(myEl.size,150);
4242
assert.equal(myEl.data.length,0);
4343
});
4444

@@ -49,14 +49,19 @@
4949
assert.equal(myEl._getColors(customColors),customColors);
5050
});
5151

52-
test('get 10 colors when slices <=10',function() {
52+
test('get 4 colors when slices <8',function() {
5353
assert.equal(myEl.colors.length,0);
54-
assert.equal(myEl._getColors([]).length,10);
54+
assert.equal(myEl._getColors([]).length,4);
5555
});
56-
test('get 20 colors when slices > 10',function() {
56+
test('get 8 colors when slices > 4',function() {
5757
assert.equal(myEl.colors.length,0);
58-
myEl.data = [1,2,3,4,5,6,7,8,9,10,11];
59-
assert.equal(myEl._getColors().length,20);
58+
myEl.data = [1,2,3,4,5];
59+
assert.equal(myEl._getColors().length,8);
60+
});
61+
test('get 16 colors when slices > 8',function() {
62+
assert.equal(myEl.colors.length,0);
63+
myEl.data = [1,2,3,4,5,6,7,8,9];
64+
assert.equal(myEl._getColors().length,16);
6065
});
6166
test('calculate total',function() {
6267
var data = [1,2,4,5,6,7,8,9,10];
@@ -71,6 +76,14 @@
7176
var arcs = myEl._calculateArcs(colors,data);
7277
assert.equal(arcs.length,3);
7378
assert.deepEqual(arcs,arcsToCheck);
79+
});
80+
test('compute arcs for full circle', function() {
81+
var arcsToCheck = [{color:'green',x1:180,x2:179.99,largeArcFlag:1,y1:0,y2:0}]
82+
var data = [0,20,0];
83+
var colors = ['red','green','blue'];
84+
var arcs = myEl._calculateArcs(colors,data);
85+
assert.equal(arcs.length,3);
86+
assert.deepEqual(arcs[1],arcsToCheck[0])
7487
});
7588
test('test DOM', function(done) {
7689
myEl.data = [20,40,40];

0 commit comments

Comments
 (0)