1
1
/* eslint-disable jsdoc/require-returns */
2
2
/* eslint-disable valid-jsdoc */
3
3
/* 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' ;
5
5
import { markerAnimate , appendChildElement , getVisiblePoints } from '../../common/utils/helper' ;
6
6
import { getLabelText , convertHexToColor , calculateRect , textElement , colorNameToHex } from '../../common/utils/helper' ;
7
7
import { Chart } from '../chart' ;
@@ -39,7 +39,7 @@ export class DataLabel {
39
39
private inverted : boolean ;
40
40
private errorHeight : number = 0 ;
41
41
private chartBackground : string ;
42
-
42
+ private extraSpace : number ;
43
43
/**
44
44
* Constructor for the data label module.
45
45
*
@@ -147,7 +147,6 @@ export class DataLabel {
147
147
this . yAxisInversed = series . yAxis . isAxisInverse ;
148
148
const redraw : boolean = chart . redraw ;
149
149
let isDataLabelOverlap : boolean = false ;
150
- let coordinatesAfterRotation : ChartLocation [ ] = [ ] ;
151
150
const templateId : string = chart . element . id + '_Series_' +
152
151
( series . index === undefined ? series . category : series . index ) + '_DataLabelCollections' ;
153
152
const element : HTMLElement = createElement ( 'div' , {
@@ -199,7 +198,12 @@ export class DataLabel {
199
198
if ( argsData . template !== null ) {
200
199
this . createDataLabelTemplate ( element , series , dataLabel , point , argsData , i , redraw ) ;
201
200
} 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
+ }
203
207
rect = this . calculateTextPosition ( point , series , textSize , dataLabel , i ) ;
204
208
// To check whether the polar radar chart datalabel intersects the axis label or not
205
209
if ( chart . chartAreaType === 'PolarRadar' ) {
@@ -216,10 +220,9 @@ export class DataLabel {
216
220
const rectCoordinates : ChartLocation [ ] = this . getRectanglePoints ( rect ) ;
217
221
rectCenterX = rect . x + ( rect . width / 2 ) ;
218
222
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 ) ;
221
224
if ( ! isDataLabelOverlap ) {
222
- this . chart . rotatedDataLabelCollections . push ( coordinatesAfterRotation ) ;
225
+ this . chart . rotatedDataLabelCollections . push ( rectCoordinates ) ;
223
226
const currentPointIndex : number = this . chart . rotatedDataLabelCollections . length - 1 ;
224
227
for ( let index : number = currentPointIndex ; index >= 0 ; index -- ) {
225
228
if ( this . chart . rotatedDataLabelCollections [ currentPointIndex as number ] &&
@@ -256,7 +259,7 @@ export class DataLabel {
256
259
rgbValue = convertHexToColor ( colorNameToHex ( backgroundColor ) ) ;
257
260
contrast = Math . round ( ( rgbValue . r * 299 + rgbValue . g * 587 + rgbValue . b * 114 ) / 1000 ) ;
258
261
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 ;
260
263
labelLocation = { x : 0 , y : 0 } ;
261
264
if ( angle !== 0 && dataLabel . enableRotation ) {
262
265
// xValue = xPos - (dataLabel.margin.left) / 2 + (dataLabel.margin.right / 2);
@@ -584,8 +587,8 @@ export class DataLabel {
584
587
}
585
588
const padding : number = 5 ;
586
589
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 &&
589
592
( Math . abs ( rect . height - textSize . height ) < padding ) ? 0 : padding ) ;
590
593
if ( series . type === 'StackingColumn100' || series . type === 'StackingBar100' ) {
591
594
position = ( position === 'Outer' ) ? 'Top' : position ;
@@ -598,10 +601,10 @@ export class DataLabel {
598
601
switch ( position ) {
599
602
case 'Bottom' :
600
603
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 ) ;
605
608
break ;
606
609
case 'Middle' :
607
610
labelLocation = labelLocation = ! this . inverted ?
@@ -612,8 +615,8 @@ export class DataLabel {
612
615
labelLocation = this . calculateRectActualPosition ( labelLocation , rect , isMinus , series , textSize , labelIndex , point ) ;
613
616
break ;
614
617
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 ) ;
617
620
618
621
break ;
619
622
}
@@ -697,8 +700,14 @@ export class DataLabel {
697
700
labelLocation , rect , isMinus , actualPosition ,
698
701
series , size , labelIndex , point ) ;
699
702
if ( ! this . inverted ) {
703
+ if ( series . marker . dataLabel . enableRotation ) {
704
+ size . width = size . width - point . regions [ 0 ] . width / 10 ;
705
+ }
700
706
labelRect = calculateRect ( new ChartLocation ( this . locationX , location ) , size , this . margin ) ;
701
707
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
+ }
702
711
} else {
703
712
labelRect = calculateRect ( new ChartLocation ( location , this . locationY ) , size , this . margin ) ;
704
713
isOverLap = labelRect . x < 0 || isCollide ( labelRect , collection , series . clipRect ) ||
0 commit comments