@@ -16,6 +16,7 @@ import {
16
16
ChildProps ,
17
17
LineChartPoints ,
18
18
CustomizedCalloutData ,
19
+ CustomizedCalloutDataPoint ,
19
20
Margins ,
20
21
RefArrayData ,
21
22
ColorFillBarsProps ,
@@ -195,6 +196,9 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
195
196
const [ stackCalloutProps , setStackCalloutProps ] = React . useState < CustomizedCalloutData > ( ) ;
196
197
const [ clickPosition , setClickPosition ] = React . useState ( { x : 0 , y : 0 } ) ;
197
198
const [ isPopoverOpen , setPopoverOpen ] = React . useState ( false ) ;
199
+ const [ YValue , setYValue ] = React . useState < number | string > ( '' ) ;
200
+ const [ legendVal , setLegendVal ] = React . useState < string > ( '' ) ;
201
+ const [ lineColor , setLineColor ] = React . useState < string > ( '' ) ;
198
202
199
203
const pointsRef = React . useRef < LineChartDataWithIndex [ ] | [ ] > ( [ ] ) ;
200
204
const calloutPointsRef = React . useRef < any [ ] > ( [ ] ) ;
@@ -586,6 +590,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
586
590
xAxisCalloutAccessibilityData ,
587
591
event ,
588
592
yScale ,
593
+ legendVal ,
594
+ lineColor ,
589
595
)
590
596
}
591
597
onMouseMove = { ( event : React . MouseEvent < SVGElement > ) =>
@@ -598,6 +604,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
598
604
xAxisCalloutAccessibilityData ,
599
605
event ,
600
606
yScale ,
607
+ legendVal ,
608
+ lineColor ,
601
609
)
602
610
}
603
611
onMouseOut = { _handleMouseOut }
@@ -779,6 +787,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
779
787
xAxisCalloutAccessibilityData ,
780
788
event ,
781
789
yScale ,
790
+ legendVal ,
791
+ lineColor ,
782
792
)
783
793
}
784
794
onMouseMove = { event =>
@@ -791,6 +801,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
791
801
xAxisCalloutAccessibilityData ,
792
802
event ,
793
803
yScale ,
804
+ legendVal ,
805
+ lineColor ,
794
806
)
795
807
}
796
808
onMouseOut = { _handleMouseOut }
@@ -838,6 +850,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
838
850
xAxisCalloutAccessibilityData ,
839
851
event ,
840
852
yScale ,
853
+ legendVal ,
854
+ lineColor ,
841
855
)
842
856
}
843
857
onMouseMove = { ( event : React . MouseEvent < SVGElement > ) =>
@@ -850,6 +864,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
850
864
xAxisCalloutAccessibilityData ,
851
865
event ,
852
866
yScale ,
867
+ legendVal ,
868
+ lineColor ,
853
869
)
854
870
}
855
871
onMouseOut = { _handleMouseOut }
@@ -902,6 +918,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
902
918
lastCirlceXCalloutAccessibilityData ,
903
919
event ,
904
920
yScale ,
921
+ legendVal ,
922
+ lineColor ,
905
923
)
906
924
}
907
925
onMouseMove = { event =>
@@ -914,6 +932,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
914
932
lastCirlceXCalloutAccessibilityData ,
915
933
event ,
916
934
yScale ,
935
+ legendVal ,
936
+ lineColor ,
917
937
)
918
938
}
919
939
onMouseOut = { _handleMouseOut }
@@ -967,6 +987,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
967
987
lastCirlceXCalloutAccessibilityData ,
968
988
event ,
969
989
yScale ,
990
+ legendVal ,
991
+ lineColor ,
970
992
)
971
993
}
972
994
onMouseMove = { ( event : React . MouseEvent < SVGElement > ) =>
@@ -979,6 +1001,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
979
1001
lastCirlceXCalloutAccessibilityData ,
980
1002
event ,
981
1003
yScale ,
1004
+ legendVal ,
1005
+ lineColor ,
982
1006
)
983
1007
}
984
1008
onMouseOut = { _handleMouseOut }
@@ -1022,6 +1046,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1022
1046
lastCirlceXCalloutAccessibilityData ,
1023
1047
event ,
1024
1048
yScale ,
1049
+ legendVal ,
1050
+ lineColor ,
1025
1051
)
1026
1052
}
1027
1053
onMouseMove = { ( event : React . MouseEvent < SVGElement > ) =>
@@ -1034,6 +1060,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1034
1060
lastCirlceXCalloutAccessibilityData ,
1035
1061
event ,
1036
1062
yScale ,
1063
+ legendVal ,
1064
+ lineColor ,
1037
1065
)
1038
1066
}
1039
1067
onFocus = { event =>
@@ -1094,6 +1122,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1094
1122
xAxisCalloutAccessibilityData ,
1095
1123
event ,
1096
1124
yScale ,
1125
+ legendVal ,
1126
+ lineColor ,
1097
1127
)
1098
1128
}
1099
1129
onMouseMove = { event =>
@@ -1106,6 +1136,8 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1106
1136
xAxisCalloutAccessibilityData ,
1107
1137
event ,
1108
1138
yScale ,
1139
+ legendVal ,
1140
+ lineColor ,
1109
1141
)
1110
1142
}
1111
1143
onMouseOut = { _handleMouseOut }
@@ -1399,11 +1431,25 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1399
1431
xAxisCalloutAccessibilityData : AccessibilityProps | undefined ,
1400
1432
mouseEvent : React . MouseEvent < SVGElement > ,
1401
1433
yScale : ScaleLinear < number , number > ,
1434
+ legendVal : string ,
1435
+ lineColor : string ,
1402
1436
) {
1403
1437
mouseEvent ?. persist ( ) ;
1404
1438
const formattedData = x instanceof Date ? formatDate ( x , props . useUTC ) : x ;
1405
1439
const xVal = x instanceof Date ? x . getTime ( ) : x ;
1440
+ const yVal = y instanceof Date ? y . getTime ( ) : y ;
1406
1441
const found = find ( _calloutPoints , ( element : { x : string | number } ) => element . x === xVal ) ;
1442
+ let hoverDp : CustomizedCalloutData | undefined = undefined ;
1443
+
1444
+ if ( props . isCalloutForStack === false && found ?. values ) {
1445
+ const dp = find ( found . values , ( val : CustomizedCalloutDataPoint ) => val ?. y === yVal ) ;
1446
+ if ( dp ) {
1447
+ hoverDp = {
1448
+ x : xVal ,
1449
+ values : [ dp ] ,
1450
+ } ;
1451
+ }
1452
+ }
1407
1453
// if no points need to be called out then don't show vertical line and callout card
1408
1454
1409
1455
if ( found ) {
@@ -1417,8 +1463,11 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1417
1463
updatePosition ( mouseEvent . clientX , mouseEvent . clientY ) ;
1418
1464
xAxisCalloutData ? setHoverXValue ( xAxisCalloutData ) : setHoverXValue ( '' + formattedData ) ;
1419
1465
setYValueHover ( found . values ) ;
1466
+ setYValue ( yVal ) ;
1467
+ setLegendVal ( legendVal ) ;
1468
+ setLineColor ( lineColor ) ;
1420
1469
setStackCalloutProps ( found ! ) ;
1421
- setDataPointCalloutProps ( found ! ) ;
1470
+ setDataPointCalloutProps ( hoverDp ) ;
1422
1471
setActivePoint ( circleId ) ;
1423
1472
setNearestCircleToHighlight ( null ) ;
1424
1473
}
@@ -1686,6 +1735,10 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1686
1735
const calloutProps = {
1687
1736
YValueHover : YValueHover ,
1688
1737
hoverXValue : hoverXValue ,
1738
+ YValue : YValue ,
1739
+ legend : legendVal ,
1740
+ color : lineColor ,
1741
+ XValue : hoverXValue ! as string ,
1689
1742
descriptionMessage :
1690
1743
props . getCalloutDescriptionMessage && stackCalloutProps
1691
1744
? props . getCalloutDescriptionMessage ( stackCalloutProps )
@@ -1695,7 +1748,7 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1695
1748
...props . calloutProps ,
1696
1749
clickPosition : clickPosition ,
1697
1750
isPopoverOpen : isPopoverOpen ,
1698
- isCalloutForStack : true ,
1751
+ isCalloutForStack : props . isCalloutForStack ,
1699
1752
culture : props . culture ?? 'en-us' ,
1700
1753
isCartesian : true ,
1701
1754
customCallout : {
@@ -1776,3 +1829,6 @@ export const LineChart: React.FunctionComponent<LineChartProps> = React.forwardR
1776
1829
} ,
1777
1830
) ;
1778
1831
LineChart . displayName = 'LineChart' ;
1832
+ LineChart . defaultProps = {
1833
+ isCalloutForStack : true ,
1834
+ } ;
0 commit comments