Skip to content

Commit 729263e

Browse files
authored
Merge pull request apache#6903 from lanyuechen/master
Fixed apache#4170
2 parents 00e351c + 53e28bd commit 729263e

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/component/timeline/TimelineAxis.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ TimelineAxis.prototype = {
6363
zrUtil.map(this.scale.getTicks(), this.dataToCoord, this),
6464
axisHelper.getFormattedLabels(this, labelModel.get('formatter')),
6565
labelModel.getFont(),
66-
timelineModel.get('orient') === 'horizontal'
66+
timelineModel.get('orient') === 'horizontal',
67+
labelModel.get('rotate')
6768
);
6869
}
6970

src/coord/Axis.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ Axis.prototype = {
250250
zrUtil.map(this.scale.getTicks(), this.dataToCoord, this),
251251
axisModel.getFormattedLabels(),
252252
labelModel.getFont(),
253-
this.isHorizontal()
253+
this.isHorizontal(),
254+
labelModel.get('rotate')
254255
);
255256
}
256257
this._labelInterval = labelInterval;

src/coord/axisHelper.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export function ifAxisCrossZero(axis) {
186186
* @param {boolean} isAxisHorizontal
187187
* @return {number}
188188
*/
189-
export function getAxisLabelInterval(tickCoords, labels, font, isAxisHorizontal) {
189+
export function getAxisLabelInterval(tickCoords, labels, font, isAxisHorizontal, rotate) {
190190
// FIXME
191191
// 不同角的axis和label,不只是horizontal和vertical.
192192

@@ -200,12 +200,24 @@ export function getAxisLabelInterval(tickCoords, labels, font, isAxisHorizontal)
200200
step = Math.floor(labels.length / 40);
201201
}
202202

203+
// 计算旋转后的label所占的宽度或高度
204+
function rotateLableWidth(w, h, r) {
205+
r = Math.abs(r / 360 * 2 * Math.PI) || 0;
206+
var s = Math.sin(r);
207+
var c = Math.cos(r);
208+
return h * c < w * s ? h / s : w * c;
209+
}
210+
203211
for (var i = 0; i < tickCoords.length; i += step) {
204212
var tickCoord = tickCoords[i];
205213
var rect = textContain.getBoundingRect(
206214
labels[i], font, 'center', 'top'
207215
);
208216
rect[isAxisHorizontal ? 'x' : 'y'] += tickCoord;
217+
218+
rect['width'] = rotateLableWidth(rect['width'], rect['height'], rotate);
219+
rect['height'] = rotateLableWidth(rect['width'], rect['height'], 90 - Math.abs(rotate));
220+
209221
// FIXME Magic number 1.5
210222
rect[isAxisHorizontal ? 'width' : 'height'] *= 1.3;
211223
if (!textSpaceTakenRect) {

0 commit comments

Comments
 (0)