Browse Source

Fix y axis padding when data label shown - #799

pull/813/head
Masayuki Tanaka 10 years ago
parent
commit
dceeaf28d6
  1. 4
      c3.js
  2. 4
      c3.min.js
  3. 33
      spec/data-spec.js
  4. 4
      src/domain.js

4
c3.js

@ -1369,8 +1369,8 @@
padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1]));
} else if (showVerticalDataLabel) { } else if (showVerticalDataLabel) {
lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height');
padding_top += lengths[1]; padding_top += domainLength * (lengths[1] / $$.height);
padding_bottom += lengths[0]; padding_bottom += domainLength * (lengths[0] / $$.height);
} }
if (axisId === 'y' && notEmpty(config.axis_y_padding)) { if (axisId === 'y' && notEmpty(config.axis_y_padding)) {
padding_top = $$.getAxisPadding(config.axis_y_padding, 'top', padding, domainLength); padding_top = $$.getAxisPadding(config.axis_y_padding, 'top', padding, domainLength);

4
c3.min.js vendored

File diff suppressed because one or more lines are too long

33
spec/data-spec.js

@ -22,16 +22,8 @@ describe('c3 chart data', function () {
}; };
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; d3 = chart.internal.d3;
chart.internal.d3.select('.jasmine_html-reporter').style('display', 'none');
window.setTimeout(function () {
done();
}, 10);
}); });
describe('function in data.order', function () { describe('function in data.order', function () {
@ -147,4 +139,27 @@ describe('c3 chart data', function () {
}); });
}); });
describe('data.label', function () {
it('should update args to show data label', function () {
args = {
data: {
columns: [
['data1', 0.03, 0.2, 0.1, 0.4, 0.15, 0.250]
],
labels: true
}
};
expect(true).toBeTruthy();
});
it('should have proper y domain', function () {
var domain = chart.internal.y.domain();
expect(domain[0]).toBeCloseTo(-0.02);
expect(domain[1]).toBeCloseTo(0.45);
});
});
}); });

4
src/domain.js

@ -126,8 +126,8 @@ c3_chart_internal_fn.getYDomain = function (targets, axisId, xDomain) {
padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1])); padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1]));
} else if (showVerticalDataLabel) { } else if (showVerticalDataLabel) {
lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height'); lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height');
padding_top += lengths[1]; padding_top += domainLength * (lengths[1] / $$.height);
padding_bottom += lengths[0]; padding_bottom += domainLength * (lengths[0] / $$.height);
} }
if (axisId === 'y' && notEmpty(config.axis_y_padding)) { if (axisId === 'y' && notEmpty(config.axis_y_padding)) {
padding_top = $$.getAxisPadding(config.axis_y_padding, 'top', padding, domainLength); padding_top = $$.getAxisPadding(config.axis_y_padding, 'top', padding, domainLength);

Loading…
Cancel
Save