diff --git a/src/component/axis/cartesianAxisHelper.js b/src/component/axis/cartesianAxisHelper.js index c05fa1819a..461c871dcd 100644 --- a/src/component/axis/cartesianAxisHelper.js +++ b/src/component/axis/cartesianAxisHelper.js @@ -12,9 +12,10 @@ export function layout(gridModel, axisModel, opt) { var grid = gridModel.coordinateSystem; var axis = axisModel.axis; var layout = {}; + var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0]; var rawAxisPosition = axis.position; - var axisPosition = axis.onZero ? 'onZero' : rawAxisPosition; + var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition; var axisDim = axis.dim; var rect = grid.getRect(); @@ -26,9 +27,8 @@ export function layout(gridModel, axisModel, opt) { ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset] : [rectBound[0] - axisOffset, rectBound[1] + axisOffset]; - if (axis.onZero) { - var otherAxis = grid.getAxis(axisDim === 'x' ? 'y' : 'x', axis.onZeroAxisIndex); - var onZeroCoord = otherAxis.toGlobalCoord(otherAxis.dataToCoord(0)); + if (otherAxisOnZeroOf) { + var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0)); posBound[idx['onZero']] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]); } @@ -45,7 +45,7 @@ export function layout(gridModel, axisModel, opt) { var dirMap = {top: -1, bottom: 1, left: -1, right: 1}; layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition]; - layout.labelOffset = axis.onZero ? posBound[idx[rawAxisPosition]] - posBound[idx['onZero']] : 0; + layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx['onZero']] : 0; if (axisModel.get('axisTick.inside')) { layout.tickDirection = -layout.tickDirection; diff --git a/src/coord/cartesian/Axis2D.js b/src/coord/cartesian/Axis2D.js index 90e027fe27..5de8dc6424 100644 --- a/src/coord/cartesian/Axis2D.js +++ b/src/coord/cartesian/Axis2D.js @@ -41,11 +41,14 @@ Axis2D.prototype = { * Index of axis, can be used as key */ index: 0, + /** - * If axis is on the zero position of the other axis - * @type {boolean} + * Implemented in . + * @return {Array.} + * If not on zero of other axis, return null/undefined. + * If no axes, return an empty array. */ - onZero: false, + getAxesOnZeroOf: null, /** * Axis model diff --git a/src/coord/cartesian/Grid.js b/src/coord/cartesian/Grid.js index 339cda8ec9..39a53e64c3 100644 --- a/src/coord/cartesian/Grid.js +++ b/src/coord/cartesian/Grid.js @@ -127,44 +127,45 @@ gridProto.update = function (ecModel, api) { }; function fixAxisOnZero(axesMap, otherAxisDim, axis) { + + axis.getAxesOnZeroOf = function () { + // TODO: onZero of multiple axes. + return otherAxis ? [otherAxis] : []; + }; + // onZero can not be enabled in these two situations: // 1. When any other axis is a category axis. // 2. When no axis is cross 0 point. - var axes = axesMap[otherAxisDim]; + var otherAxes = axesMap[otherAxisDim]; + + var otherAxis; + var axisModel = axis.model; + var onZero = axisModel.get('axisLine.onZero'); + var onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex'); - if (!axis.onZero) { + if (!onZero) { return; } - var onZeroAxisIndex = axis.onZeroAxisIndex; - // If target axis is specified. if (onZeroAxisIndex != null) { - var otherAxis = axes[onZeroAxisIndex]; - if (otherAxis && canNotOnZeroToAxis(otherAxis)) { - axis.onZero = false; + if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) { + otherAxis = otherAxes[onZeroAxisIndex]; } return; } - for (var idx in axes) { - if (axes.hasOwnProperty(idx)) { - var otherAxis = axes[idx]; - if (otherAxis && !canNotOnZeroToAxis(otherAxis)) { - onZeroAxisIndex = +idx; - break; - } + // Find the first available other axis. + for (var idx in otherAxes) { + if (otherAxes.hasOwnProperty(idx) && canOnZeroToAxis(otherAxes[idx])) { + otherAxis = otherAxes[idx]; + break; } } - - if (onZeroAxisIndex == null) { - axis.onZero = false; - } - axis.onZeroAxisIndex = onZeroAxisIndex; } -function canNotOnZeroToAxis(axis) { - return axis.type === 'category' || axis.type === 'time' || !ifAxisCrossZero(axis); +function canOnZeroToAxis(axis) { + return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis); } /** @@ -447,9 +448,6 @@ gridProto._initCartesian = function (gridModel, ecModel, api) { axis.onBand = isCategory && axisModel.get('boundaryGap'); axis.inverse = axisModel.get('inverse'); - axis.onZero = axisModel.get('axisLine.onZero'); - axis.onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex'); - // Inject axis into axisModel axisModel.axis = axis; diff --git a/src/layout/barGrid.js b/src/layout/barGrid.js index 37c3358b12..ba07b6dfbb 100644 --- a/src/layout/barGrid.js +++ b/src/layout/barGrid.js @@ -244,7 +244,10 @@ export function layout(seriesType, ecModel, api) { var stacked = isDimensionStacked(data, valueDim, baseDim); var isValueAxisH = valueAxis.isHorizontal(); - var valueAxisStart = (baseAxis.onZero || stacked) + var valueAxisStart = ( + zrUtil.indexOf(baseAxis.getAxesOnZeroOf(), valueAxis) >= 0 + || stacked + ) ? valueAxis.toGlobalCoord(valueAxis.dataToCoord(0)) : valueAxis.getGlobalExtent()[0]; diff --git a/test/lib/reset.css b/test/lib/reset.css index b9f7118a50..02adc19782 100644 --- a/test/lib/reset.css +++ b/test/lib/reset.css @@ -39,6 +39,7 @@ body > .main { background: #fff; z-index: 99; width: 300px; + max-height: 99%; border-left: 1px solid #ddd; border-bottom: 1px solid #ddd; }