提交 a03481d0 编写于 作者: O Ovilia

Enhance boundaryGap policy. Fixes and closes #4417

上级 32f5c8ea
......@@ -23,6 +23,15 @@ define(function (require) {
var fixMin = min != null;
var fixMax = max != null;
var originalExtent = scale.getExtent();
if (originalExtent[1] === originalExtent[0]) {
// Min and max values are the same, scale from 0
if (originalExtent[0] > 0) {
originalExtent[0] = 0;
}
else {
originalExtent[1] = 0;
}
}
var axisDataLen;
var boundaryGap;
......@@ -35,6 +44,15 @@ define(function (require) {
if (!zrUtil.isArray(boundaryGap)) {
boundaryGap = [boundaryGap || 0, boundaryGap || 0];
}
if (typeof boundaryGap[0] === 'boolean') {
if (__DEV__) {
console.warn('Boolean type for boundaryGap is only '
+ 'allowed for ordinal axis. Please use string in '
+ 'percentage instead, e.g., "20%". Currently, '
+ 'boundaryGap is set to be 0.');
}
boundaryGap = [0, 0];
}
boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], 1);
boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], 1);
span = originalExtent[1] - originalExtent[0];
......@@ -43,12 +61,18 @@ define(function (require) {
if (min == null) {
min = scaleType === 'ordinal'
? (axisDataLen ? 0 : NaN)
: originalExtent[0] - boundaryGap[0] * span;
: (originalExtent[0] < 0
// Don't show negative gap for all-positive data
? originalExtent[0] - boundaryGap[0] * span
: 0);
}
if (max == null) {
max = scaleType === 'ordinal'
? (axisDataLen ? axisDataLen - 1 : NaN)
: originalExtent[1] + boundaryGap[1] * span;
: (originalExtent[1] > 0
// Don't show positive gap for all-negative data
? originalExtent[1] + boundaryGap[1] * span
: 0);
}
if (min === 'dataMin') {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册