Commit 4766795d authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix empty pie chart - #952

parent 35e5a63d
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
"describe": false, "describe": false,
"beforeEach": false, "beforeEach": false,
"it": false, "it": false,
"expect": false "expect": false,
"d3": false
} }
} }
...@@ -4568,6 +4568,9 @@ ...@@ -4568,6 +4568,9 @@
} }
index++; index++;
}); });
if (isNaN(d.startAngle)) {
d.startAngle = 0;
}
if (isNaN(d.endAngle)) { if (isNaN(d.endAngle)) {
d.endAngle = d.startAngle; d.endAngle = d.startAngle;
} }
...@@ -4840,6 +4843,9 @@ ...@@ -4840,6 +4843,9 @@
// endAngle: Math.PI*2, // endAngle: Math.PI*2,
// }; // };
// } // }
if (isNaN(this._current.startAngle)) {
this._current.startAngle = 0;
}
if (isNaN(this._current.endAngle)) { if (isNaN(this._current.endAngle)) {
this._current.endAngle = this._current.startAngle; this._current.endAngle = this._current.startAngle;
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
describe('c3 chart arc', function () {
describe('c3 chart axis', function () {
'use strict'; 'use strict';
var chart, d3, args; var chart, args;
beforeEach(function (done) { beforeEach(function (done) {
if (typeof chart === 'undefined') { chart = window.initChart(chart, args, done);
window.initDom();
}
chart = window.c3.generate(args);
d3 = chart.internal.d3;
chart.internal.d3.select('.jasmine_html-reporter')
.style('position', 'absolute')
.style('right', 0);
window.setTimeout(function () {
done();
}, 50);
}); });
describe('show pie chart', function () { describe('show pie chart', function () {
args = { it('should update args to have pie chart', function () {
data: { args = {
columns: [ data: {
['data1', 30], columns: [
['data2', 150], ['data1', 30],
['data3', 120] ['data2', 150],
], ['data3', 120]
type: 'pie' ],
} type: 'pie'
}; }
};
expect(true).toBeTruthy();
});
it('should have correct classes', function () { it('should have correct classes', function () {
var chartArc = d3.select('.c3-chart-arcs'), var chartArc = d3.select('.c3-chart-arcs'),
...@@ -69,6 +60,38 @@ describe('c3 chart axis', function () { ...@@ -69,6 +60,38 @@ describe('c3 chart axis', function () {
expect(d3.select('.c3-arc-black').attr('d')).toMatch(/M-124\..+,-171\..+A211\..+,211\..+ 0 0,1 -3\..+,-211\..+L0,0Z/); expect(d3.select('.c3-arc-black').attr('d')).toMatch(/M-124\..+,-171\..+A211\..+,211\..+ 0 0,1 -3\..+,-211\..+L0,0Z/);
}); });
it('should update args to have empty pie chart', function () {
args = {
data: {
columns: [
['data1', null],
['data2', null],
['data3', null]
],
type: 'pie'
}
};
expect(true).toBeTruthy();
});
it('should have correct d attribute', function () {
var chartArc = d3.select('.c3-chart-arcs'),
arcs = {
data1: chartArc.select('.c3-chart-arc.c3-target.c3-target-data1')
.select('g.c3-shapes.c3-shapes-data1.c3-arcs.c3-arcs-data1')
.select('path.c3-shape.c3-shape.c3-arc.c3-arc-data1'),
data2: chartArc.select('.c3-chart-arc.c3-target.c3-target-data2')
.select('g.c3-shapes.c3-shapes-data2.c3-arcs.c3-arcs-data2')
.select('path.c3-shape.c3-shape.c3-arc.c3-arc-data2'),
data3: chartArc.select('.c3-chart-arc.c3-target.c3-target-data3')
.select('g.c3-shapes.c3-shapes-data3.c3-arcs.c3-arcs-data3')
.select('path.c3-shape.c3-shape.c3-arc.c3-arc-data3')
};
expect(arcs.data1.attr('d').indexOf('NaN')).toBe(-1);
expect(arcs.data2.attr('d').indexOf('NaN')).toBe(-1);
expect(arcs.data3.attr('d').indexOf('NaN')).toBe(-1);
});
}); });
}); });
...@@ -29,10 +29,13 @@ function initChart(chart, args, done) { ...@@ -29,10 +29,13 @@ function initChart(chart, args, done) {
if (typeof chart === 'undefined') { if (typeof chart === 'undefined') {
window.initDom(); window.initDom();
} }
chart = window.c3.generate(args); if (args) {
chart.internal.d3.select('.jasmine_html-reporter') chart = window.c3.generate(args);
.style('position', 'absolute') window.d3 = chart.internal.d3;
.style('right', 0); window.d3.select('.jasmine_html-reporter')
.style('position', 'absolute')
.style('right', 0);
}
window.setTimeout(function () { window.setTimeout(function () {
done(); done();
......
...@@ -36,6 +36,9 @@ c3_chart_internal_fn.updateAngle = function (d) { ...@@ -36,6 +36,9 @@ c3_chart_internal_fn.updateAngle = function (d) {
} }
index++; index++;
}); });
if (isNaN(d.startAngle)) {
d.startAngle = 0;
}
if (isNaN(d.endAngle)) { if (isNaN(d.endAngle)) {
d.endAngle = d.startAngle; d.endAngle = d.startAngle;
} }
...@@ -308,6 +311,9 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf ...@@ -308,6 +311,9 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
// endAngle: Math.PI*2, // endAngle: Math.PI*2,
// }; // };
// } // }
if (isNaN(this._current.startAngle)) {
this._current.startAngle = 0;
}
if (isNaN(this._current.endAngle)) { if (isNaN(this._current.endAngle)) {
this._current.endAngle = this._current.startAngle; this._current.endAngle = this._current.startAngle;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment