Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/component/axis/AxisBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {isRadianAroundZero, remRadian} from '../../util/number';
import {createSymbol} from '../../util/symbol';
import * as matrixUtil from 'zrender/src/core/matrix';
import {applyTransform as v2ApplyTransform} from 'zrender/src/core/vector';
import {shouldShowAllLabels} from '../../coord/axisHelper';
import {shouldShowAllLabels, estimateLabelUnionRect} from '../../coord/axisHelper';


var PI = Math.PI;
Expand Down Expand Up @@ -269,7 +269,22 @@ var builders = {
var nameLocation = axisModel.get('nameLocation');
var nameDirection = opt.nameDirection;
var textStyleModel = axisModel.getModel('nameTextStyle');
var gap = axisModel.get('nameGap') || 0;
// label + gap
var distanceToAxis = calcDistanceToAxis();
function calcDistanceToAxis() {
var axis = axisModel.axis;
if (axis.grid.model.get('containLabel') && !axis.model.get('axisLabel.inside')) {
var labelUnionRect = estimateLabelUnionRect(axis);
Copy link
Contributor

@pissang pissang Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AxisBuilder can also be used on coordinate systems other than grids. In which case, axis.grid may be null. And access grid model in the axis builder is an abstraction leak.

It's better to pass the extra gap calculated from labels from the top. Which can be a parameter in https://github.com/apache/incubator-echarts/blob/master/src/component/axis/CartesianAxisView.js#L60

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I don't have time looking into this for now, can you make a fix if the issue is still relevant?

if (!labelUnionRect) {
return 0;
}
var dim = axis.isHorizontal() ? 'height' : 'width';
var margin = axisModel.get('axisLabel.margin');
return labelUnionRect[dim] + margin;
}
return 0;
}
var gap = (axisModel.get('nameGap') || 0) + distanceToAxis;

var extent = this.axisModel.axis.getExtent();
var gapSignal = extent[0] > extent[1] ? -1 : 1;
Expand Down