Browse Source

Fix empty pie chart - #952

pull/1003/head
Masayuki Tanaka 10 years ago
parent
commit
4766795d91
  1. 3
      .jshintrc
  2. 6
      c3.js
  3. 6
      c3.min.js
  4. 73
      spec/arc-spec.js
  5. 11
      spec/c3-helper.js
  6. 6
      src/arc.js

3
.jshintrc

@ -22,7 +22,8 @@
"describe": false,
"beforeEach": false,
"it": false,
"expect": false
"expect": false,
"d3": false
}
}

6
c3.js

@ -4568,6 +4568,9 @@
}
index++;
});
if (isNaN(d.startAngle)) {
d.startAngle = 0;
}
if (isNaN(d.endAngle)) {
d.endAngle = d.startAngle;
}
@ -4840,6 +4843,9 @@
// endAngle: Math.PI*2,
// };
// }
if (isNaN(this._current.startAngle)) {
this._current.startAngle = 0;
}
if (isNaN(this._current.endAngle)) {
this._current.endAngle = this._current.startAngle;
}

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

73
spec/arc-spec.js

@ -1,36 +1,27 @@
describe('c3 chart axis', function () {
describe('c3 chart arc', function () {
'use strict';
var chart, d3, args;
var chart, args;
beforeEach(function (done) {
if (typeof chart === 'undefined') {
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);
chart = window.initChart(chart, args, done);
});
describe('show pie chart', function () {
args = {
data: {
columns: [
['data1', 30],
['data2', 150],
['data3', 120]
],
type: 'pie'
}
};
it('should update args to have pie chart', function () {
args = {
data: {
columns: [
['data1', 30],
['data2', 150],
['data3', 120]
],
type: 'pie'
}
};
expect(true).toBeTruthy();
});
it('should have correct classes', function () {
var chartArc = d3.select('.c3-chart-arcs'),
@ -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/);
});
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);
});
});
});

11
spec/c3-helper.js

@ -29,10 +29,13 @@ function initChart(chart, args, done) {
if (typeof chart === 'undefined') {
window.initDom();
}
chart = window.c3.generate(args);
chart.internal.d3.select('.jasmine_html-reporter')
.style('position', 'absolute')
.style('right', 0);
if (args) {
chart = window.c3.generate(args);
window.d3 = chart.internal.d3;
window.d3.select('.jasmine_html-reporter')
.style('position', 'absolute')
.style('right', 0);
}
window.setTimeout(function () {
done();

6
src/arc.js

@ -36,6 +36,9 @@ c3_chart_internal_fn.updateAngle = function (d) {
}
index++;
});
if (isNaN(d.startAngle)) {
d.startAngle = 0;
}
if (isNaN(d.endAngle)) {
d.endAngle = d.startAngle;
}
@ -308,6 +311,9 @@ c3_chart_internal_fn.redrawArc = function (duration, durationForExit, withTransf
// endAngle: Math.PI*2,
// };
// }
if (isNaN(this._current.startAngle)) {
this._current.startAngle = 0;
}
if (isNaN(this._current.endAngle)) {
this._current.endAngle = this._current.startAngle;
}

Loading…
Cancel
Save