@@ -29,6 +29,7 @@ import {
29
29
ILineChartStyles ,
30
30
ILineChartGap ,
31
31
ILineChartDataPoint ,
32
+ IYValueHover ,
32
33
} from '../../index' ;
33
34
import { DirectionalHint } from '@fluentui/react/lib/Callout' ;
34
35
import { formatDateToLocaleString } from '@fluentui/chart-utilities' ;
@@ -57,6 +58,7 @@ import {
57
58
getDomainPaddingForMarkers ,
58
59
isPlottable ,
59
60
getRangeForScatterMarkerSize ,
61
+ findCalloutPoints ,
60
62
} from '../../utilities/index' ;
61
63
import { IChart , IImageExportOptions } from '../../types/index' ;
62
64
import { toImage } from '../../utilities/image-export-utils' ;
@@ -178,8 +180,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
178
180
} ;
179
181
180
182
private _points : LineChartDataWithIndex [ ] ;
181
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
- private _calloutPoints : any [ ] ;
183
+ private _calloutPoints : Record < string , IYValueHover [ ] > ;
183
184
// eslint-disable-next-line @typescript-eslint/no-explicit-any
184
185
private _xAxisScale : any = '' ;
185
186
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -237,7 +238,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
237
238
this . _refArray = [ ] ;
238
239
this . _points = this . _injectIndexPropertyInLineChartData ( this . props . data . lineChartData ) ;
239
240
this . _colorFillBars = [ ] ;
240
- this . _calloutPoints = calloutData ( this . _points ) || [ ] ;
241
+ this . _calloutPoints = calloutData ( this . _points ) || { } ;
241
242
this . _circleId = getId ( 'circle' ) ;
242
243
this . _lineId = getId ( 'lineID' ) ;
243
244
this . _borderId = getId ( 'borderID' ) ;
@@ -278,7 +279,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
278
279
prevProps . data !== this . props . data
279
280
) {
280
281
this . _points = this . _injectIndexPropertyInLineChartData ( this . props . data . lineChartData ) ;
281
- this . _calloutPoints = calloutData ( this . _points ) || [ ] ;
282
+ this . _calloutPoints = calloutData ( this . _points ) || { } ;
282
283
}
283
284
}
284
285
@@ -1597,11 +1598,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
1597
1598
xPointToHighlight instanceof Date
1598
1599
? formatDateToLocaleString ( xPointToHighlight , this . props . culture , this . props . useUTC )
1599
1600
: xPointToHighlight ;
1600
- const modifiedXVal = xPointToHighlight instanceof Date ? xPointToHighlight . getTime ( ) : xPointToHighlight ;
1601
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1602
- const found : any = find ( this . _calloutPoints , ( element : { x : string | number } ) => {
1603
- return element . x === modifiedXVal ;
1604
- } ) ;
1601
+ const found = findCalloutPoints ( this . _calloutPoints , xPointToHighlight ) as ICustomizedCalloutData | undefined ;
1605
1602
const pointToHighlight : ILineChartDataPoint = lineChartData ! [ linenumber ] . data [ index ! ] ;
1606
1603
const pointToHighlightUpdated =
1607
1604
this . state . nearestCircleToHighlight === null ||
@@ -1657,8 +1654,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
1657
1654
) => {
1658
1655
this . _uniqueCallOutID = circleId ;
1659
1656
const formattedData = x instanceof Date ? formatDateToLocaleString ( x , this . props . culture , this . props . useUTC ) : x ;
1660
- const xVal = x instanceof Date ? x . getTime ( ) : x ;
1661
- const found = find ( this . _calloutPoints , ( element : { x : string | number } ) => element . x === xVal ) ;
1657
+ const found = findCalloutPoints ( this . _calloutPoints , x ) as ICustomizedCalloutData | undefined ;
1662
1658
// if no points need to be called out then don't show vertical line and callout card
1663
1659
1664
1660
if ( found ) {
@@ -1689,7 +1685,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
1689
1685
1690
1686
private _handleHover = (
1691
1687
x : number | Date ,
1692
- y : number | Date ,
1688
+ y : number ,
1693
1689
lineHeight : number ,
1694
1690
xAxisCalloutData : string | undefined ,
1695
1691
circleId : string ,
@@ -1701,17 +1697,15 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
1701
1697
) => {
1702
1698
mouseEvent . persist ( ) ;
1703
1699
const formattedData = x instanceof Date ? formatDateToLocaleString ( x , this . props . culture , this . props . useUTC ) : x ;
1704
- const xVal = x instanceof Date ? x . getTime ( ) : x ;
1705
- const yVal = y instanceof Date ? y . getTime ( ) : y ;
1706
1700
const _this = this ;
1707
- const found = find ( this . _calloutPoints , ( element : { x : string | number } ) => element . x === xVal ) ;
1701
+ const found = findCalloutPoints ( this . _calloutPoints , x ) as ICustomizedCalloutData | undefined ;
1708
1702
let hoverDp : ICustomizedCalloutData | undefined = undefined ;
1709
1703
1710
1704
if ( this . props . isCalloutForStack === false && found ?. values ) {
1711
- const dp = find ( found . values , ( val : ICustomizedCalloutDataPoint ) => val ?. y === yVal ) ;
1705
+ const dp = find ( found . values , ( val : ICustomizedCalloutDataPoint ) => val ?. y === y ) ;
1712
1706
if ( dp ) {
1713
1707
hoverDp = {
1714
- x : xVal ,
1708
+ x,
1715
1709
values : [ dp ] ,
1716
1710
} ;
1717
1711
}
@@ -1731,7 +1725,7 @@ export class LineChartBase extends React.Component<ILineChartProps, ILineChartSt
1731
1725
refSelected : `#${ circleId } ` ,
1732
1726
hoverXValue : xAxisCalloutData ? xAxisCalloutData : '' + formattedData ,
1733
1727
YValueHover : found . values ,
1734
- YValue : yVal ,
1728
+ YValue : y ,
1735
1729
legendVal : legendVal ! ,
1736
1730
lineColor,
1737
1731
stackCalloutProps : found ! ,
0 commit comments