55 */
66
77import * as zrUtil from 'zrender/src/core/util' ;
8+ import * as BoundingRect from 'zrender/src/core/BoundingRect' ;
89import { getLayoutRect } from '../../util/layout' ;
910import * as axisHelper from '../../coord/axisHelper' ;
1011import Cartesian2D from './Cartesian2D' ;
@@ -26,6 +27,18 @@ function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
2627 return axisModel . getCoordSysModel ( ) === gridModel ;
2728}
2829
30+ function rotateTextRect ( textRect , rotate ) {
31+ var rotateRadians = rotate * Math . PI / 180 ;
32+ var boundingBox = textRect . plain ( ) ;
33+ var beforeWidth = boundingBox . width ;
34+ var beforeHeight = boundingBox . height ;
35+ var afterWidth = beforeWidth * Math . cos ( rotateRadians ) + beforeHeight * Math . sin ( rotateRadians ) ;
36+ var afterHeight = beforeWidth * Math . sin ( rotateRadians ) + beforeHeight * Math . cos ( rotateRadians ) ;
37+ var rotatedRect = new BoundingRect ( boundingBox . x , boundingBox . y , afterWidth , afterHeight ) ;
38+
39+ return rotatedRect ;
40+ }
41+
2942function getLabelUnionRect ( axis ) {
3043 var axisModel = axis . model ;
3144 var labels = axisModel . getFormattedLabels ( ) ;
@@ -39,8 +52,9 @@ function getLabelUnionRect(axis) {
3952 }
4053 for ( var i = 0 ; i < labelCount ; i += step ) {
4154 if ( ! axis . isLabelIgnored ( i ) ) {
42- var singleRect = axisLabelModel . getTextRect ( labels [ i ] ) ;
43- // FIXME consider label rotate
55+ var unrotatedSingleRect = axisLabelModel . getTextRect ( labels [ i ] ) ;
56+ var singleRect = rotateTextRect ( unrotatedSingleRect , axisLabelModel . get ( 'rotate' ) || 0 ) ;
57+
4458 rect ? rect . union ( singleRect ) : ( rect = singleRect ) ;
4559 }
4660 }
@@ -625,4 +639,4 @@ Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
625639
626640CoordinateSystem . register ( 'cartesian2d' , Grid ) ;
627641
628- export default Grid ;
642+ export default Grid ;
0 commit comments