Commit e21a8f85 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix axis.y.padding

parent cb9459cb
...@@ -31,7 +31,10 @@ ...@@ -31,7 +31,10 @@
function Chart(config) { function Chart(config) {
var $$ = this.internal = new ChartInternal(this); var $$ = this.internal = new ChartInternal(this);
$$.loadConfig(config); $$.loadConfig(config);
$$.beforeInit();
$$.init(); $$.init();
$$.afterInit();
// bind "this" to nested API // bind "this" to nested API
(function bindThis(fn, target, argThis) { (function bindThis(fn, target, argThis) {
...@@ -71,6 +74,12 @@ ...@@ -71,6 +74,12 @@
c3_chart_internal_fn = c3.chart.internal.fn; c3_chart_internal_fn = c3.chart.internal.fn;
c3_chart_internal_axis_fn = c3.chart.internal.axis.fn; c3_chart_internal_axis_fn = c3.chart.internal.axis.fn;
c3_chart_internal_fn.beforeInit = function () {
// can do something
};
c3_chart_internal_fn.afterInit = function () {
// can do something
};
c3_chart_internal_fn.init = function () { c3_chart_internal_fn.init = function () {
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
...@@ -4582,14 +4591,15 @@ ...@@ -4582,14 +4591,15 @@
.text(this.textForY2AxisLabel.bind(this)); .text(this.textForY2AxisLabel.bind(this));
}; };
Axis.prototype.getPadding = function getPadding(padding, key, defaultValue, domainLength) { Axis.prototype.getPadding = function getPadding(padding, key, defaultValue, domainLength) {
if (!isValue(padding[key])) { var p = typeof padding === 'number' ? padding : padding[key];
if (!isValue(p)) {
return defaultValue; return defaultValue;
} }
if (padding.unit === 'ratio') { if (padding.unit === 'ratio') {
return padding[key] * domainLength; return padding[key] * domainLength;
} }
// assume padding is pixels if unit is not specified // assume padding is pixels if unit is not specified
return this.convertPixelsToAxisPadding(padding[key], domainLength); return this.convertPixelsToAxisPadding(p, domainLength);
}; };
Axis.prototype.convertPixelsToAxisPadding = function convertPixelsToAxisPadding(pixels, domainLength) { Axis.prototype.convertPixelsToAxisPadding = function convertPixelsToAxisPadding(pixels, domainLength) {
var $$ = this.owner, var $$ = this.owner,
...@@ -5957,10 +5967,10 @@ ...@@ -5957,10 +5967,10 @@
return d[1] - d[0]; return d[1] - d[0];
}, },
isEmpty = c3_chart_internal_fn.isEmpty = function (o) { isEmpty = c3_chart_internal_fn.isEmpty = function (o) {
return !o || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); return typeof o === 'undefined' || o === null || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0);
}, },
notEmpty = c3_chart_internal_fn.notEmpty = function (o) { notEmpty = c3_chart_internal_fn.notEmpty = function (o) {
return Object.keys(o).length > 0; return !c3_chart_internal_fn.isEmpty(o);
}, },
getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) {
return isDefined(options[key]) ? options[key] : defaultValue; return isDefined(options[key]) ? options[key] : defaultValue;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -89,6 +89,29 @@ describe('c3 chart domain', function () { ...@@ -89,6 +89,29 @@ describe('c3 chart domain', function () {
}, },
axis: { axis: {
y: { y: {
padding: 200,
}
}
};
expect(true).toBeTruthy();
});
it('should be set properly when bigger than min of data', function () {
var domain = chart.internal.y.domain();
expect(domain[0]).toBeCloseTo(-9, -1);
expect(domain[1]).toBeCloseTo(69, -1);
});
it('should change axis.y.max to 1000 with top/bottom padding', function () {
args = {
data: {
columns: [
['data1', 10, 20, 10, 40, 15, 25],
['data2', 50, 40, 30, 45, 25, 45]
]
},
axis: {
y: {
padding: { padding: {
top: 200, top: 200,
bottom: 200 bottom: 200
......
...@@ -321,14 +321,15 @@ Axis.prototype.updateLabels = function updateLabels(withTransition) { ...@@ -321,14 +321,15 @@ Axis.prototype.updateLabels = function updateLabels(withTransition) {
.text(this.textForY2AxisLabel.bind(this)); .text(this.textForY2AxisLabel.bind(this));
}; };
Axis.prototype.getPadding = function getPadding(padding, key, defaultValue, domainLength) { Axis.prototype.getPadding = function getPadding(padding, key, defaultValue, domainLength) {
if (!isValue(padding[key])) { var p = typeof padding === 'number' ? padding : padding[key];
if (!isValue(p)) {
return defaultValue; return defaultValue;
} }
if (padding.unit === 'ratio') { if (padding.unit === 'ratio') {
return padding[key] * domainLength; return padding[key] * domainLength;
} }
// assume padding is pixels if unit is not specified // assume padding is pixels if unit is not specified
return this.convertPixelsToAxisPadding(padding[key], domainLength); return this.convertPixelsToAxisPadding(p, domainLength);
}; };
Axis.prototype.convertPixelsToAxisPadding = function convertPixelsToAxisPadding(pixels, domainLength) { Axis.prototype.convertPixelsToAxisPadding = function convertPixelsToAxisPadding(pixels, domainLength) {
var $$ = this.owner, var $$ = this.owner,
......
...@@ -23,10 +23,10 @@ var isValue = c3_chart_internal_fn.isValue = function (v) { ...@@ -23,10 +23,10 @@ var isValue = c3_chart_internal_fn.isValue = function (v) {
return d[1] - d[0]; return d[1] - d[0];
}, },
isEmpty = c3_chart_internal_fn.isEmpty = function (o) { isEmpty = c3_chart_internal_fn.isEmpty = function (o) {
return !o || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0); return typeof o === 'undefined' || o === null || (isString(o) && o.length === 0) || (typeof o === 'object' && Object.keys(o).length === 0);
}, },
notEmpty = c3_chart_internal_fn.notEmpty = function (o) { notEmpty = c3_chart_internal_fn.notEmpty = function (o) {
return Object.keys(o).length > 0; return !c3_chart_internal_fn.isEmpty(o);
}, },
getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) { getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) {
return isDefined(options[key]) ? options[key] : defaultValue; return isDefined(options[key]) ? options[key] : defaultValue;
......
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