Skip to content

Commit

Permalink
Fix y axis padding when data label shown - #799
Browse files Browse the repository at this point in the history
  • Loading branch information
masayuki0812 committed Dec 6, 2014
1 parent bfac88c commit dceeaf2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions c3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1369,8 +1369,8 @@
padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1]));
} else if (showVerticalDataLabel) {
lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height');
padding_top += lengths[1];
padding_bottom += lengths[0];
padding_top += domainLength * (lengths[1] / $$.height);
padding_bottom += domainLength * (lengths[0] / $$.height);
}
if (axisId === 'y' && notEmpty(config.axis_y_padding)) {
padding_top = $$.getAxisPadding(config.axis_y_padding, 'top', padding, domainLength);
Expand Down
4 changes: 2 additions & 2 deletions c3.min.js

Large diffs are not rendered by default.

33 changes: 24 additions & 9 deletions spec/data-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,8 @@ describe('c3 chart data', function () {
};

beforeEach(function (done) {
if (typeof chart === 'undefined') {
window.initDom();
}
chart = window.c3.generate(args);
chart = window.initChart(chart, args, done);
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 () {
Expand Down Expand Up @@ -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 changes: 2 additions & 2 deletions src/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ c3_chart_internal_fn.getYDomain = function (targets, axisId, xDomain) {
padding_bottom += domainLength * (ratio[0] / (1 - ratio[0] - ratio[1]));
} else if (showVerticalDataLabel) {
lengths = $$.getDataLabelLength(yDomainMin, yDomainMax, axisId, 'height');
padding_top += lengths[1];
padding_bottom += lengths[0];
padding_top += domainLength * (lengths[1] / $$.height);
padding_bottom += domainLength * (lengths[0] / $$.height);
}
if (axisId === 'y' && notEmpty(config.axis_y_padding)) {
padding_top = $$.getAxisPadding(config.axis_y_padding, 'top', padding, domainLength);
Expand Down

0 comments on commit dceeaf2

Please sign in to comment.