11/* eslint-disable jsdoc/require-returns */
22/* eslint-disable valid-jsdoc */
33/* eslint-disable jsdoc/require-param */
4- import { ChartLocation , ColorValue , RectOption , isCollide , isOverlap , LabelLocation } from '../../common/utils/helper' ;
4+ import { ChartLocation , ColorValue , RectOption , isCollide , isOverlap , LabelLocation , rotateTextSize } from '../../common/utils/helper' ;
55import { markerAnimate , appendChildElement , getVisiblePoints } from '../../common/utils/helper' ;
66import { getLabelText , convertHexToColor , calculateRect , textElement , colorNameToHex } from '../../common/utils/helper' ;
77import { Chart } from '../chart' ;
@@ -39,7 +39,7 @@ export class DataLabel {
3939 private inverted : boolean ;
4040 private errorHeight : number = 0 ;
4141 private chartBackground : string ;
42-
42+ private extraSpace : number ;
4343 /**
4444 * Constructor for the data label module.
4545 *
@@ -147,7 +147,6 @@ export class DataLabel {
147147 this . yAxisInversed = series . yAxis . isAxisInverse ;
148148 const redraw : boolean = chart . redraw ;
149149 let isDataLabelOverlap : boolean = false ;
150- let coordinatesAfterRotation : ChartLocation [ ] = [ ] ;
151150 const templateId : string = chart . element . id + '_Series_' +
152151 ( series . index === undefined ? series . category : series . index ) + '_DataLabelCollections' ;
153152 const element : HTMLElement = createElement ( 'div' , {
@@ -199,7 +198,12 @@ export class DataLabel {
199198 if ( argsData . template !== null ) {
200199 this . createDataLabelTemplate ( element , series , dataLabel , point , argsData , i , redraw ) ;
201200 } else {
202- textSize = measureText ( argsData . text , dataLabel . font , this . chart . themeStyle . datalabelFont ) ;
201+ if ( dataLabel . enableRotation ) {
202+ textSize = rotateTextSize ( dataLabel . font , argsData . text , dataLabel . angle , this . chart ) ;
203+ }
204+ else {
205+ textSize = measureText ( argsData . text , dataLabel . font , this . chart . themeStyle . datalabelFont ) ;
206+ }
203207 rect = this . calculateTextPosition ( point , series , textSize , dataLabel , i ) ;
204208 // To check whether the polar radar chart datalabel intersects the axis label or not
205209 if ( chart . chartAreaType === 'PolarRadar' ) {
@@ -216,10 +220,9 @@ export class DataLabel {
216220 const rectCoordinates : ChartLocation [ ] = this . getRectanglePoints ( rect ) ;
217221 rectCenterX = rect . x + ( rect . width / 2 ) ;
218222 rectCenterY = ( rect . y + ( rect . height / 2 ) ) ;
219- coordinatesAfterRotation = getRotatedRectangleCoordinates ( rectCoordinates , rectCenterX , rectCenterY , angle ) ;
220- isDataLabelOverlap = ( dataLabel . labelIntersectAction === 'Rotate90' || angle == - 90 ) ? false : this . isDataLabelOverlapWithChartBound ( coordinatesAfterRotation , chart , clip ) ;
223+ isDataLabelOverlap = ( dataLabel . labelIntersectAction === 'Rotate90' || angle == - 90 ) ? false : this . isDataLabelOverlapWithChartBound ( rectCoordinates , chart , clip ) ;
221224 if ( ! isDataLabelOverlap ) {
222- this . chart . rotatedDataLabelCollections . push ( coordinatesAfterRotation ) ;
225+ this . chart . rotatedDataLabelCollections . push ( rectCoordinates ) ;
223226 const currentPointIndex : number = this . chart . rotatedDataLabelCollections . length - 1 ;
224227 for ( let index : number = currentPointIndex ; index >= 0 ; index -- ) {
225228 if ( this . chart . rotatedDataLabelCollections [ currentPointIndex as number ] &&
@@ -256,7 +259,7 @@ export class DataLabel {
256259 rgbValue = convertHexToColor ( colorNameToHex ( backgroundColor ) ) ;
257260 contrast = Math . round ( ( rgbValue . r * 299 + rgbValue . g * 587 + rgbValue . b * 114 ) / 1000 ) ;
258261 xPos = ( rect . x + this . margin . left + textSize . width / 2 ) + labelLocation . x ;
259- yPos = ( rect . y + this . margin . top + textSize . height * 3 / 4 ) + labelLocation . y ;
262+ yPos = dataLabel . enableRotation && this . chart . chartAreaType !== 'PolarRadar' ? ( rect . y + this . margin . top + textSize . height / 2 + textSize . width / 4 + ( dataLabel . position === 'Auto' ? point . regions [ 0 ] . width / 10 : 0 ) ) + labelLocation . y : ( rect . y + this . margin . top + textSize . height * 3 / 4 ) + labelLocation . y ;
260263 labelLocation = { x : 0 , y : 0 } ;
261264 if ( angle !== 0 && dataLabel . enableRotation ) {
262265 // xValue = xPos - (dataLabel.margin.left) / 2 + (dataLabel.margin.right / 2);
@@ -584,8 +587,8 @@ export class DataLabel {
584587 }
585588 const padding : number = 5 ;
586589 const margin : MarginModel = this . margin ;
587- const textLength : number = ! this . inverted ? textSize . height : textSize . width ;
588- let extraSpace : number = this . borderWidth + textLength / 2 + ( position !== 'Outer' && series . type . indexOf ( 'Column' ) > - 1 &&
590+ const textLength : number = ( series . marker . dataLabel . enableRotation ? textSize . width : ( ! this . inverted ? textSize . height : textSize . width ) ) ;
591+ this . extraSpace = this . borderWidth + textLength / 2 + ( position !== 'Outer' && series . type . indexOf ( 'Column' ) > - 1 &&
589592 ( Math . abs ( rect . height - textSize . height ) < padding ) ? 0 : padding ) ;
590593 if ( series . type === 'StackingColumn100' || series . type === 'StackingBar100' ) {
591594 position = ( position === 'Outer' ) ? 'Top' : position ;
@@ -598,10 +601,10 @@ export class DataLabel {
598601 switch ( position ) {
599602 case 'Bottom' :
600603 labelLocation = ! this . inverted ?
601- isMinus ? ( labelLocation + ( series . type === 'Waterfall' ? ( - extraSpace - margin . top - this . markerHeight ) : ( - rect . height + extraSpace + margin . top ) ) ) :
602- ( labelLocation + rect . height - extraSpace - margin . bottom ) :
603- isMinus ? ( labelLocation + ( series . type === 'Waterfall' ? ( + extraSpace + margin . left + this . markerHeight ) : ( + rect . width - extraSpace - margin . left ) ) ) :
604- ( labelLocation - rect . width + extraSpace + margin . right ) ;
604+ isMinus ? ( labelLocation + ( series . type === 'Waterfall' ? ( - this . extraSpace - margin . top - this . markerHeight ) : ( - rect . height + this . extraSpace + margin . top ) ) ) :
605+ ( labelLocation + rect . height - this . extraSpace - margin . bottom ) :
606+ isMinus ? ( labelLocation + ( series . type === 'Waterfall' ? ( + this . extraSpace + margin . left + this . markerHeight ) : ( + rect . width - this . extraSpace - margin . left ) ) ) :
607+ ( labelLocation - rect . width + this . extraSpace + margin . right ) ;
605608 break ;
606609 case 'Middle' :
607610 labelLocation = labelLocation = ! this . inverted ?
@@ -612,8 +615,8 @@ export class DataLabel {
612615 labelLocation = this . calculateRectActualPosition ( labelLocation , rect , isMinus , series , textSize , labelIndex , point ) ;
613616 break ;
614617 default :
615- extraSpace += this . errorHeight ;
616- labelLocation = this . calculateTopAndOuterPosition ( labelLocation , rect , position , series , labelIndex , extraSpace , isMinus ) ;
618+ this . extraSpace += this . errorHeight ;
619+ labelLocation = this . calculateTopAndOuterPosition ( labelLocation , rect , position , series , labelIndex , this . extraSpace , isMinus ) ;
617620
618621 break ;
619622 }
@@ -697,8 +700,14 @@ export class DataLabel {
697700 labelLocation , rect , isMinus , actualPosition ,
698701 series , size , labelIndex , point ) ;
699702 if ( ! this . inverted ) {
703+ if ( series . marker . dataLabel . enableRotation ) {
704+ size . width = size . width - point . regions [ 0 ] . width / 10 ;
705+ }
700706 labelRect = calculateRect ( new ChartLocation ( this . locationX , location ) , size , this . margin ) ;
701707 isOverLap = labelRect . y < 0 || isCollide ( labelRect , collection , series . clipRect ) || labelRect . y > series . clipRect . height ;
708+ if ( series . marker . dataLabel . template === null && isOverLap != true ) {
709+ isOverLap = labelRect . y / 2 + size . height + ( actualPosition === 'Outer' ? point . regions [ 0 ] . height + this . extraSpace : point . regions [ 0 ] . height - 2 * this . extraSpace ) > series . clipRect . height ;
710+ }
702711 } else {
703712 labelRect = calculateRect ( new ChartLocation ( location , this . locationY ) , size , this . margin ) ;
704713 isOverLap = labelRect . x < 0 || isCollide ( labelRect , collection , series . clipRect ) ||
0 commit comments