Browse Source

Fix axis.y.padding

pull/1220/merge
Masayuki Tanaka 10 years ago
parent
commit
e21a8f85f0
  1. 18
      c3.js
  2. 6
      c3.min.js
  3. 23
      spec/domain-spec.js
  4. 5
      src/axis.js
  5. 4
      src/util.js

18
c3.js

@ -31,7 +31,10 @@
function Chart(config) {
var $$ = this.internal = new ChartInternal(this);
$$.loadConfig(config);
$$.beforeInit();
$$.init();
$$.afterInit();
// bind "this" to nested API
(function bindThis(fn, target, argThis) {
@ -71,6 +74,12 @@
c3_chart_internal_fn = c3.chart.internal.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 () {
var $$ = this, config = $$.config;
@ -4582,14 +4591,15 @@
.text(this.textForY2AxisLabel.bind(this));
};
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;
}
if (padding.unit === 'ratio') {
return padding[key] * domainLength;
}
// 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) {
var $$ = this.owner,
@ -5957,10 +5967,10 @@
return d[1] - d[0];
},
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) {
return Object.keys(o).length > 0;
return !c3_chart_internal_fn.isEmpty(o);
},
getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) {
return isDefined(options[key]) ? options[key] : defaultValue;

6
c3.min.js vendored

File diff suppressed because one or more lines are too long

23
spec/domain-spec.js

@ -80,6 +80,29 @@ describe('c3 chart domain', function () {
describe('axis.y.padding', function () {
it('should change axis.y.max to 1000', function () {
args = {
data: {
columns: [
['data1', 10, 20, 10, 40, 15, 25],
['data2', 50, 40, 30, 45, 25, 45]
]
},
axis: {
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: [

5
src/axis.js

@ -321,14 +321,15 @@ Axis.prototype.updateLabels = function updateLabels(withTransition) {
.text(this.textForY2AxisLabel.bind(this));
};
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;
}
if (padding.unit === 'ratio') {
return padding[key] * domainLength;
}
// 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) {
var $$ = this.owner,

4
src/util.js

@ -23,10 +23,10 @@ var isValue = c3_chart_internal_fn.isValue = function (v) {
return d[1] - d[0];
},
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) {
return Object.keys(o).length > 0;
return !c3_chart_internal_fn.isEmpty(o);
},
getOption = c3_chart_internal_fn.getOption = function (options, key, defaultValue) {
return isDefined(options[key]) ? options[key] : defaultValue;

Loading…
Cancel
Save