All files / src/components/LineChart LineChart.base.tsx

76.25% Statements 350/459
64.78% Branches 276/426
71.42% Functions 50/70
74.75% Lines 308/412

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 143322x   22x 22x 22x 22x 22x 22x                               22x 22x 22x                             22x   22x 22x 22x       22x   22x   22x                 22x 446x                                                                                                         446x                                                     22x 22x               48x   48x                 48x                   48x     48x 48x                           48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 55x 48x 48x   48x         22x       21x                   58x 58x 58x   58x 58x 58x 6x 6x     58x       58x 55x   58x                                       58x         58x                                     77x 77x 77x                                                                                                     48x 182x 182x       445x 24x   421x     445x                 48x 57x             48x 77x     48x             77x 77x 77x 77x     48x 6x 2x 2x   4x 4x       48x               55x 55x 55x 55x 138x   138x       5x 2x   3x       1x     2x 2x                 138x     55x   16x   16x 16x       5x 2x   3x                         16x       55x                         48x           48x 446x 446x 446x 159x 6x 153x 108x   45x     287x 4x   283x         48x               446x 446x 446x 446x 446x   446x   48x 446x 446x 446x 159x 114x 6x   108x     45x     45x       287x 4x   283x       77x 77x 77x 4x   73x   181x 181x 181x 181x   181x 181x 181x 181x 181x 181x 3x 3x   3x 3x                                                                   6x                 181x 181x     181x                                                                                                                                                                                                               181x 268x 268x 268x 268x   268x 268x 268x 268x 268x 268x                 268x     268x   268x 268x                                                                       268x   178x 178x 178x 178x                 178x 178x 178x 178x                                                                                                                                                     268x   245x 243x     243x 80x                               243x                   483x                                                             23x 23x                                         181x   77x       77x 75x 75x         77x 2x 2x 2x     2x         2x   77x     48x 10x 10x 2x   8x     10x 10x 10x 19x 19x   19x   19x   9x     19x 19x 19x   19x     19x                             10x     48x     9x 9x                         48x 276x 276x   276x 3x     276x 4x   276x     22x 489x     48x                                                                                                                                                                                                             48x                                                                               48x                 9x 9x 9x 9x 26x     9x 9x 9x     9x 7x 7x                                                   48x 692x           692x     48x       48x 3x 3x             48x       10x         48x 2x 1x 1x             2x 2x             2x   2x               2x         2x           3x 2x     48x 2x 1x 1x             2x 2x               2x   2x               2x         2x           2x 3x   2x     48x                           48x 290x               48x 283x     48x 32x     48x 449x 449x 449x 449x 449x 449x 449x     22x 58x       141x     22x  
import * as React from 'react';
import { Axis as D3Axis } from 'd3-axis';
import { select as d3Select, pointer } from 'd3-selection';
import { bisector } from 'd3-array';
import { ILegend, Legends } from '../Legends/index';
import { line as d3Line, curveLinear as d3curveLinear } from 'd3-shape';
import { classNamesFunction, getId, find, memoizeFunction, getRTL } from '@fluentui/react/lib/Utilities';
import {
  IAccessibilityProps,
  CartesianChart,
  IBasestate,
  IChildProps,
  ILineChartProps,
  ILineChartPoints,
  ICustomizedCalloutData,
  IMargins,
  IRefArrayData,
  IColorFillBarsProps,
  ILineChartStyleProps,
  ILineChartStyles,
  ILineChartGap,
  ILineChartDataPoint,
} from '../../index';
import { DirectionalHint } from '@fluentui/react/lib/Callout';
import { EventsAnnotation } from './eventAnnotation/EventAnnotation';
import {
  calloutData,
  ChartTypes,
  getXAxisType,
  XAxisTypes,
  tooltipOfXAxislabels,
  Points,
  pointTypes,
  getMinMaxOfYAxis,
  getTypeOfAxis,
  getNextColor,
  getColorFromToken,
} from '../../utilities/index';
 
type NumericAxis = D3Axis<number | { valueOf(): number }>;
const getClassNames = classNamesFunction<ILineChartStyleProps, ILineChartStyles>();
 
enum PointSize {
  hoverSize = 11,
  invisibleSize = 1,
}
 
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const bisect = bisector((d: any) => d.x).left;
 
const DEFAULT_LINE_STROKE_SIZE = 4;
// The given shape of a icon must be 2.5 times bigger than line width (known as stroke width)
const PATH_MULTIPLY_SIZE = 2.5;
 
/**
 *
 * @param x units from origin
 * @param y units from origin
 * @param w is the legnth of the each side of a shape
 * @param index index to get the shape path
 */
const _getPointPath = (x: number, y: number, w: number, index: number): string => {
  const allPointPaths = [
    // circle path
    `M${x - w / 2} ${y}
     A${w / 2} ${w / 2} 0 1 0 ${x + w / 2} ${y}
     M${x - w / 2} ${y}
     A ${w / 2} ${w / 2} 0 1 1 ${x + w / 2} ${y}
     `,
    //square
    `M${x - w / 2} ${y - w / 2}
     L${x + w / 2} ${y - w / 2}
     L${x + w / 2} ${y + w / 2}
     L${x - w / 2} ${y + w / 2}
     Z`,
    //triangle
    `M${x - w / 2} ${y - 0.2886 * w}
     H ${x + w / 2}
     L${x} ${y + 0.5774 * w} Z`,
    //diamond
    `M${x} ${y - w / 2}
     L${x + w / 2} ${y}
     L${x} ${y + w / 2}
     L${x - w / 2} ${y}
     Z`,
    //pyramid
    `M${x} ${y - 0.5774 * w}
     L${x + w / 2} ${y + 0.2886 * w}
     L${x - w / 2} ${y + 0.2886 * w} Z`,
    //hexagon
    `M${x - 0.5 * w} ${y - 0.866 * w}
     L${x + 0.5 * w} ${y - 0.866 * w}
     L${x + w} ${y}
     L${x + 0.5 * w} ${y + 0.866 * w}
     L${x - 0.5 * w} ${y + 0.866 * w}
     L${x - w} ${y}
     Z`,
    //pentagon
    `M${x} ${y - 0.851 * w}
     L${x + 0.6884 * w} ${y - 0.2633 * w}
     L${x + 0.5001 * w} ${y + 0.6884 * w}
     L${x - 0.5001 * w} ${y + 0.6884 * w}
     L${x - 0.6884 * w} ${y - 0.2633 * w}
     Z`,
    //octagon
    `M${x - 0.5001 * w} ${y - 1.207 * w}
     L${x + 0.5001 * w} ${y - 1.207 * w}
     L${x + 1.207 * w} ${y - 0.5001 * w}
     L${x + 1.207 * w} ${y + 0.5001 * w}
     L${x + 0.5001 * w} ${y + 1.207 * w}
     L${x - 0.5001 * w} ${y + 1.207 * w}
     L${x - 1.207 * w} ${y + 0.5001 * w}
     L${x - 1.207 * w} ${y - 0.5001 * w}
     Z`,
  ];
  return allPointPaths[index];
};
 
type LineChartDataWithIndex = ILineChartPoints & { index: number };
 
export interface ILineChartState extends IBasestate {
  // This array contains data of selected legends for points
  selectedLegendPoints: LineChartDataWithIndex[];
  // This array contains data of selected legends for color bars
  selectedColorBarLegend: IColorFillBarsProps[];
  // This is a boolean value which is set to true
  // when at least one legend is selected
  isSelectedLegend: boolean;
  // This value will be used as customized callout props - point callout.
  dataPointCalloutProps?: ICustomizedCalloutData;
  // This value will be used as Customized callout props - For stack callout.
  stackCalloutProps?: ICustomizedCalloutData;
  // active or hovered point
  activePoint?: string;
  // x-axis callout accessibility data
  xAxisCalloutAccessibilityData?: IAccessibilityProps;
 
  nearestCircleToHighlight: ILineChartDataPoint | null;
 
  activeLine: number | null;
}
 
export class LineChartBase extends React.Component<ILineChartProps, ILineChartState> {
  public static defaultProps: Partial<ILineChartProps> = {
    enableReflow: true,
  };
 
  private _points: LineChartDataWithIndex[];
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  private _calloutPoints: any[];
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  private _xAxisScale: any = '';
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  private _yAxisScale: any = '';
  private _circleId: string;
  private _lineId: string;
  private _borderId: string;
  private _verticalLine: string;
  private _colorFillBarPatternId: string;
  private _uniqueCallOutID: string | null;
  private _refArray: IRefArrayData[];
  private margins: IMargins;
  private eventLabelHeight: number = 36;
  private lines: JSX.Element[];
  private _renderedColorFillBars: JSX.Element[];
  private _colorFillBars: IColorFillBarsProps[];
  private _tooltipId: string;
  private _rectId: string;
  private _staticHighlightCircle: string;
  private _createLegendsMemoized: (data: LineChartDataWithIndex[]) => JSX.Element;
  private _firstRenderOptimization: boolean;
  private _emptyChartId: string;
  private _isRTL: boolean = getRTL();
 
  constructor(props: ILineChartProps) {
    super(props);
    this.state = {
      hoverXValue: '',
      activeLegend: '',
      YValueHover: [],
      refSelected: '',
      selectedLegend: '',
      isCalloutVisible: false,
      selectedLegendPoints: [],
      selectedColorBarLegend: [],
      isSelectedLegend: false,
      activePoint: '',
      nearestCircleToHighlight: null,
      activeLine: null,
    };
    this._refArray = [];
    this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData);
    this._colorFillBars = [];
    this._calloutPoints = calloutData(this._points) || [];
    this._circleId = getId('circle');
    this._lineId = getId('lineID');
    this._borderId = getId('borderID');
    this._verticalLine = getId('verticalLine');
    this._colorFillBarPatternId = getId('colorFillBarPattern');
    this._tooltipId = getId('LineChartTooltipId_');
    this._rectId = getId('containerRectLD');
    this._staticHighlightCircle = getId('staticHighlightCircle');
    this._createLegendsMemoized = memoizeFunction((data: LineChartDataWithIndex[]) => this._createLegends(data));
    this._firstRenderOptimization = true;
    this._emptyChartId = getId('_LineChart_empty');
 
    props.eventAnnotationProps &&
      props.eventAnnotationProps.labelHeight &&
      (this.eventLabelHeight = props.eventAnnotationProps.labelHeight);
  }
 
  public componentDidUpdate(prevProps: ILineChartProps): void {
    /** note that height and width are not used to resize or set as dimesions of the chart,
     * fitParentContainer is responisble for setting the height and width or resizing of the svg/chart
     */
    Iif (
      prevProps.height !== this.props.height ||
      prevProps.width !== this.props.width ||
      prevProps.data !== this.props.data
    ) {
      this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData);
      this._calloutPoints = calloutData(this._points) || [];
    }
  }
 
  public render(): JSX.Element {
    const { tickValues, tickFormat, eventAnnotationProps, legendProps, data } = this.props;
    this._points = this._injectIndexPropertyInLineChartData(data.lineChartData);
 
    const isXAxisDateType = getXAxisType(this._points);
    let points = this._points;
    if (legendProps && !!legendProps.canSelectMultipleLegends) {
      points = this.state.selectedLegendPoints.length >= 1 ? this.state.selectedLegendPoints : this._points;
      this._calloutPoints = calloutData(points);
    }
 
    let legendBars = null;
    // reduce computation cost by only creating legendBars
    // if when hideLegend is false.
    // NOTE: they are rendered only when hideLegend is false in CartesianChart.
    if (!this.props.hideLegend) {
      legendBars = this._createLegendsMemoized(this._points!);
    }
    const calloutProps = {
      isCalloutVisible: this.state.isCalloutVisible,
      directionalHint: DirectionalHint.topAutoEdge,
      YValueHover: this.state.YValueHover,
      hoverXValue: this.state.hoverXValue,
      id: `toolTip${this._uniqueCallOutID}`,
      target: this.state.refSelected,
      isBeakVisible: false,
      gapSpace: 15,
      onDismiss: this._closeCallout,
      preventDismissOnEvent: () => true,
      hidden: !(!this.props.hideTooltip && this.state.isCalloutVisible),
      descriptionMessage:
        this.props.getCalloutDescriptionMessage && this.state.stackCalloutProps
          ? this.props.getCalloutDescriptionMessage(this.state.stackCalloutProps)
          : undefined,
      'data-is-focusable': true,
      xAxisCalloutAccessibilityData: this.state.xAxisCalloutAccessibilityData,
      ...this.props.calloutProps,
    };
    const tickParams = {
      tickValues,
      tickFormat,
    };
 
    return !this._isChartEmpty() ? (
      <CartesianChart
        {...this.props}
        chartTitle={data.chartTitle}
        points={points}
        chartType={ChartTypes.LineChart}
        isCalloutForStack
        calloutProps={calloutProps}
        tickParams={tickParams}
        legendBars={legendBars}
        getmargins={this._getMargins}
        getGraphData={this._initializeLineChartData}
        xAxisType={isXAxisDateType ? XAxisTypes.DateAxis : XAxisTypes.NumericAxis}
        customizedCallout={this._getCustomizedCallout()}
        onChartMouseLeave={this._handleChartMouseLeave}
        enableFirstRenderOptimization={this.props.enablePerfOptimization && this._firstRenderOptimization}
        /* eslint-disable react/jsx-no-bind */
        // eslint-disable-next-line react/no-children-prop
        children={(props: IChildProps) => {
          this._xAxisScale = props.xScale!;
          this._yAxisScale = props.yScale!;
          return (
            <>
              <g>
                <line
                  x1={0}
                  y1={0}
                  x2={0}
                  y2={props.containerHeight}
                  stroke={'#323130'}
                  id={this._verticalLine}
                  visibility={'hidden'}
                  strokeDasharray={'5,5'}
                />
                {this.props.optimizeLargeData ? (
                  <rect
                    id={this._rectId}
                    width={props.containerWidth}
                    height={props.containerHeight}
                    fill={'transparent'}
                  />
                ) : (
                  <></>
                )}
                <g>
                  {this._renderedColorFillBars}
                  {this.lines}
                </g>
                {eventAnnotationProps && (
                  <EventsAnnotation
                    theme={this.props.theme}
                    {...eventAnnotationProps}
                    scale={props.xScale!}
                    chartYTop={this.margins.top! + this.eventLabelHeight}
                    chartYBottom={props.containerHeight! - 35}
                  />
                )}
              </g>
            </>
          );
        }}
      />
    ) : (
      <div
        id={this._emptyChartId}
        role={'alert'}
        style={{ opacity: '0' }}
        aria-label={'Graph has no data to display'}
      />
    );
  }
 
  private _injectIndexPropertyInLineChartData = (lineChartData?: ILineChartPoints[]): LineChartDataWithIndex[] | [] => {
    const { allowMultipleShapesForPoints = false } = this.props;
    return lineChartData
      ? lineChartData.map((item: ILineChartPoints, index: number) => {
          let color: string;
          // isInverted property is applicable to v8 themes only
          if (typeof item.color === 'undefined') {
            color = getNextColor(index, 0, this.props.theme?.isInverted);
          } else {
            color = getColorFromToken(item.color, this.props.theme?.isInverted);
          }
 
          return {
            ...item,
            index: allowMultipleShapesForPoints ? index : -1,
            color,
          };
        })
      : [];
  };
 
  private _getCustomizedCallout = () => {
    return this.props.onRenderCalloutPerStack
      ? this.props.onRenderCalloutPerStack(this.state.stackCalloutProps)
      : this.props.onRenderCalloutPerDataPoint
      ? this.props.onRenderCalloutPerDataPoint(this.state.dataPointCalloutProps)
      : null;
  };
 
  private _getMargins = (margins: IMargins) => {
    this.margins = margins;
  };
 
  private _initializeLineChartData = (
    xScale: NumericAxis,
    yScale: NumericAxis,
    containerHeight: number,
    containerWidth: number,
    xElement: SVGElement | null,
  ) => {
    this._xAxisScale = xScale;
    this._yAxisScale = yScale;
    this._renderedColorFillBars = this.props.colorFillBars ? this._createColorFillBars(containerHeight) : [];
    this.lines = this._createLines(xElement!, containerHeight!);
  };
 
  private _handleSingleLegendSelectionAction = (lineChartItem: LineChartDataWithIndex | IColorFillBarsProps) => {
    if (this.state.selectedLegend === lineChartItem.legend) {
      this.setState({ selectedLegend: '' });
      this._handleLegendClick(lineChartItem, null);
    } else {
      this.setState({ selectedLegend: lineChartItem.legend });
      this._handleLegendClick(lineChartItem, lineChartItem.legend);
    }
  };
 
  private _onHoverCardHide = () => {
    this.setState({
      selectedLegendPoints: [],
      selectedColorBarLegend: [],
      isSelectedLegend: false,
    });
  };
 
  private _createLegends(data: LineChartDataWithIndex[]): JSX.Element {
    const { legendProps, allowMultipleShapesForPoints = false } = this.props;
    const isLegendMultiSelectEnabled = !!(legendProps && !!legendProps.canSelectMultipleLegends);
    const legendDataItems = data.map((point: LineChartDataWithIndex) => {
      const color: string = point.color!;
      // mapping data to the format Legends component needs
      const legend: ILegend = {
        title: point.legend!,
        color,
        action: () => {
          if (isLegendMultiSelectEnabled) {
            this._handleMultipleLineLegendSelectionAction(point);
          } else {
            this._handleSingleLegendSelectionAction(point);
          }
        },
        onMouseOutAction: () => {
          this.setState({ activeLegend: '' });
        },
        hoverAction: () => {
          this._handleChartMouseLeave();
          this.setState({ activeLegend: point.legend });
        },
        ...(point.legendShape && {
          shape: point.legendShape,
        }),
        ...(allowMultipleShapesForPoints && {
          shape: Points[point.index % Object.keys(pointTypes).length] as ILegend['shape'],
        }),
      };
      return legend;
    });
 
    const colorFillBarsLegendDataItems = this.props.colorFillBars
      ? this.props.colorFillBars.map((colorFillBar: IColorFillBarsProps, index: number) => {
          const title = colorFillBar.legend;
          // isInverted property is applicable to v8 themes only
          const color = getColorFromToken(colorFillBar.color, this.props.theme?.isInverted);
          const legend: ILegend = {
            title,
            color,
            action: () => {
              if (isLegendMultiSelectEnabled) {
                this._handleMultipleColorFillBarLegendSelectionAction(colorFillBar);
              } else {
                this._handleSingleLegendSelectionAction(colorFillBar);
              }
            },
            onMouseOutAction: () => {
              this.setState({ activeLegend: '' });
            },
            hoverAction: () => {
              this._handleChartMouseLeave();
              this.setState({ activeLegend: title });
            },
            opacity: this._getColorFillBarOpacity(colorFillBar),
            stripePattern: colorFillBar.applyPattern,
          };
          return legend;
        })
      : [];
 
    return (
      <Legends
        legends={[...legendDataItems, ...colorFillBarsLegendDataItems]}
        enabledWrapLines={this.props.enabledLegendsWrapLines}
        overflowProps={this.props.legendsOverflowProps}
        focusZonePropsInHoverCard={this.props.focusZonePropsForLegendsInHoverCard}
        overflowText={this.props.legendsOverflowText}
        {...(isLegendMultiSelectEnabled && { onLegendHoverCardLeave: this._onHoverCardHide })}
        {...this.props.legendProps}
      />
    );
  }
 
  private _closeCallout = () => {
    this.setState({
      isCalloutVisible: false,
    });
  };
 
  private _getBoxWidthOfShape = (pointId: string, pointIndex: number, isLastPoint: boolean) => {
    const { allowMultipleShapesForPoints = false, strokeWidth = DEFAULT_LINE_STROKE_SIZE } = this.props;
    const { activePoint } = this.state;
    if (allowMultipleShapesForPoints) {
      if (activePoint === pointId) {
        return PointSize.hoverSize;
      } else if (pointIndex === 1 || isLastPoint) {
        return strokeWidth * PATH_MULTIPLY_SIZE;
      } else {
        return PointSize.invisibleSize;
      }
    } else {
      if (activePoint === pointId) {
        return PointSize.hoverSize;
      } else {
        return PointSize.invisibleSize;
      }
    }
  };
 
  private _getPath = (
    xPos: number,
    yPos: number,
    pointId: string,
    pointIndex: number,
    isLastPoint: boolean,
    pointOftheLine: number,
  ): string => {
    const { allowMultipleShapesForPoints = false } = this.props;
    let w = this._getBoxWidthOfShape(pointId, pointIndex, isLastPoint);
    const index: number = allowMultipleShapesForPoints ? pointOftheLine % Object.keys(pointTypes).length : 0;
    const widthRatio = pointTypes[index].widthRatio;
    w = widthRatio > 1 ? w / widthRatio : w;
 
    return _getPointPath(xPos, yPos, w, index);
  };
  private _getPointFill = (lineColor: string, pointId: string, pointIndex: number, isLastPoint: boolean) => {
    const { activePoint } = this.state;
    const { theme, allowMultipleShapesForPoints = false } = this.props;
    if (allowMultipleShapesForPoints) {
      if (pointIndex === 1 || isLastPoint) {
        if (activePoint === pointId) {
          return theme!.semanticColors.bodyBackground;
        } else {
          return lineColor;
        }
      } else {
        Iif (activePoint === pointId) {
          return theme!.semanticColors.bodyBackground;
        } else {
          return lineColor;
        }
      }
    } else {
      if (activePoint === pointId) {
        return theme!.semanticColors.bodyBackground;
      } else {
        return lineColor;
      }
    }
  };
  private _createLines(xElement: SVGElement, containerHeight: number): JSX.Element[] {
    const lines: JSX.Element[] = [];
    if (this.state.isSelectedLegend) {
      this._points = this.state.selectedLegendPoints;
    } else {
      this._points = this._injectIndexPropertyInLineChartData(this.props.data.lineChartData);
    }
    for (let i = this._points.length - 1; i >= 0; i--) {
      const linesForLine: JSX.Element[] = [];
      const bordersForLine: JSX.Element[] = [];
      const pointsForLine: JSX.Element[] = [];
 
      const legendVal: string = this._points[i].legend;
      const lineColor: string = this._points[i].color!;
      const { activePoint } = this.state;
      const { theme } = this.props;
      const verticaLineHeight = containerHeight - this.margins.bottom! + 6;
      if (this._points[i].data.length === 1) {
        const { x: x1, y: y1, xAxisCalloutData, xAxisCalloutAccessibilityData } = this._points[i].data[0];
        const circleId = `${this._circleId}_${i}`;
        const isLegendSelected: boolean =
          this._legendHighlighted(legendVal) || this._noLegendHighlighted() || this.state.isSelectedLegend;
        pointsForLine.push(
          <circle
            id={circleId}
            key={circleId}
            r={activePoint === circleId ? 5.5 : 3.5}
            cx={this._xAxisScale(x1)}
            cy={this._yAxisScale(y1)}
            fill={activePoint === circleId ? theme!.semanticColors.bodyBackground : lineColor}
            opacity={isLegendSelected ? 1 : 0.1}
            onMouseOver={this._handleHover.bind(
              this,
              x1,
              y1,
              verticaLineHeight,
              xAxisCalloutData,
              circleId,
              xAxisCalloutAccessibilityData,
            )}
            onMouseMove={this._handleHover.bind(
              this,
              x1,
              y1,
              verticaLineHeight,
              xAxisCalloutData,
              circleId,
              xAxisCalloutAccessibilityData,
            )}
            onMouseOut={this._handleMouseOut}
            strokeWidth={activePoint === circleId ? DEFAULT_LINE_STROKE_SIZE : 0}
            stroke={activePoint === circleId ? lineColor : ''}
            role="img"
            aria-label={this._getAriaLabel(i, 0)}
            data-is-focusable={isLegendSelected}
            ref={(e: SVGCircleElement | null) => {
              this._refCallback(e!, circleId);
            }}
            onFocus={() => this._handleFocus(circleId, x1, xAxisCalloutData, circleId, xAxisCalloutAccessibilityData)}
            onBlur={this._handleMouseOut}
            {...this._getClickHandler(this._points[i].data[0].onDataPointClick)}
          />,
        );
      }
 
      let gapIndex = 0;
      const gaps = this._points[i].gaps?.sort((a, b) => a.startIndex - b.startIndex) ?? [];
 
      // Use path rendering technique for larger datasets to optimize performance.
      Iif (this.props.optimizeLargeData && this._points[i].data.length > 1) {
        const line = d3Line()
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
          .x((d: any) => this._xAxisScale(d[0]))
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
          .y((d: any) => this._yAxisScale(d[1]))
          .curve(d3curveLinear);
 
        const lineId = `${this._lineId}_${i}`;
        const borderId = `${this._borderId}_${i}`;
        const strokeWidth =
          this._points[i].lineOptions?.strokeWidth || this.props.strokeWidth || DEFAULT_LINE_STROKE_SIZE;
 
        const isLegendSelected: boolean =
          this._legendHighlighted(legendVal) || this._noLegendHighlighted() || this.state.isSelectedLegend;
 
        const lineData: [number, number][] = [];
        for (let k = 0; k < this._points[i].data.length; k++) {
          lineData.push([
            this._points[i].data[k].x instanceof Date
              ? (this._points[i].data[k].x as Date).getTime()
              : (this._points[i].data[k].x as number),
            this._points[i].data[k].y,
          ]);
        }
 
        if (isLegendSelected) {
          const lineBorderWidth = this._points[i].lineOptions?.lineBorderWidth
            ? Number.parseFloat(this._points[i].lineOptions!.lineBorderWidth!.toString())
            : 0;
          Iif (lineBorderWidth > 0) {
            bordersForLine.push(
              <path
                id={borderId}
                key={borderId}
                d={line(lineData)!}
                fill="transparent"
                strokeLinecap={this._points[i].lineOptions?.strokeLinecap ?? 'round'}
                strokeWidth={Number.parseFloat(strokeWidth.toString()) + lineBorderWidth}
                stroke={this._points[i].lineOptions?.lineBorderColor || theme!.semanticColors.bodyBackground}
                opacity={1}
              />,
            );
          }
 
          linesForLine.push(
            <path
              id={lineId}
              key={lineId}
              d={line(lineData)!}
              fill="transparent"
              data-is-focusable={true}
              stroke={lineColor}
              strokeWidth={strokeWidth}
              strokeLinecap={this._points[i].lineOptions?.strokeLinecap ?? 'round'}
              onMouseMove={this._onMouseOverLargeDataset.bind(this, i, verticaLineHeight)}
              onMouseOver={this._onMouseOverLargeDataset.bind(this, i, verticaLineHeight)}
              onMouseOut={this._handleMouseOut}
              {...this._getClickHandler(this._points[i].onLineClick)}
              opacity={1}
              role="img"
              aria-label={`${legendVal}, series ${i + 1} of ${this._points.length} with ${
                this._points[i].data.length
              } data points.`}
            />,
          );
        } else {
          linesForLine.push(
            <path
              id={lineId}
              key={lineId}
              d={line(lineData)!}
              fill="transparent"
              data-is-focusable={false}
              stroke={lineColor}
              strokeWidth={strokeWidth}
              strokeLinecap={this._points[i].lineOptions?.strokeLinecap ?? 'round'}
              opacity={0.1}
              role="img"
              aria-label={`${legendVal}, series ${i + 1} of ${this._points.length} with ${
                this._points[i].data.length
              } data points.`}
            />,
          );
        }
 
        const isPointHighlighted = this.state.activeLine !== null && this.state.activeLine === i;
 
        pointsForLine.push(
          <circle
            id={`${this._staticHighlightCircle}_${i}`}
            key={`${this._staticHighlightCircle}_${i}`}
            r={5.5}
            cx={0}
            cy={0}
            fill={theme!.semanticColors.bodyBackground}
            strokeWidth={DEFAULT_LINE_STROKE_SIZE}
            stroke={lineColor}
            visibility={isPointHighlighted ? 'visibility' : 'hidden'}
            onMouseMove={this._onMouseOverLargeDataset.bind(this, i, verticaLineHeight)}
            onMouseOver={this._onMouseOverLargeDataset.bind(this, i, verticaLineHeight)}
            onMouseOut={this._handleMouseOut}
          />,
        );
      } else if (!this.props.optimizeLargeData) {
        for (let j = 1; j < this._points[i].data.length; j++) {
          const gapResult = this._checkInGap(j, gaps, gapIndex);
          const isInGap = gapResult.isInGap;
          gapIndex = gapResult.gapIndex;
 
          const lineId = `${this._lineId}_${i}_${j}`;
          const borderId = `${this._borderId}_${i}_${j}`;
          const circleId = `${this._circleId}_${i}_${j}`;
          const { x: x1, y: y1, xAxisCalloutData, xAxisCalloutAccessibilityData } = this._points[i].data[j - 1];
          const { x: x2, y: y2 } = this._points[i].data[j];
          let path = this._getPath(
            this._xAxisScale(x1),
            this._yAxisScale(y1),
            circleId,
            j,
            false,
            this._points[i].index,
          );
          const strokeWidth =
            this._points[i].lineOptions?.strokeWidth || this.props.strokeWidth || DEFAULT_LINE_STROKE_SIZE;
 
          const isLegendSelected: boolean =
            this._legendHighlighted(legendVal) || this._noLegendHighlighted() || this.state.isSelectedLegend;
 
          const currentPointHidden = this._points[i].hideNonActiveDots && activePoint !== circleId;
          pointsForLine.push(
            <path
              id={circleId}
              key={circleId}
              d={path}
              data-is-focusable={isLegendSelected}
              onMouseOver={this._handleHover.bind(
                this,
                x1,
                y1,
                verticaLineHeight,
                xAxisCalloutData,
                circleId,
                xAxisCalloutAccessibilityData,
              )}
              onMouseMove={this._handleHover.bind(
                this,
                x1,
                y1,
                verticaLineHeight,
                xAxisCalloutData,
                circleId,
                xAxisCalloutAccessibilityData,
              )}
              onMouseOut={this._handleMouseOut}
              onFocus={() => this._handleFocus(lineId, x1, xAxisCalloutData, circleId, xAxisCalloutAccessibilityData)}
              onBlur={this._handleMouseOut}
              {...this._getClickHandler(this._points[i].data[j - 1].onDataPointClick)}
              opacity={isLegendSelected && !currentPointHidden ? 1 : 0.01}
              fill={this._getPointFill(lineColor, circleId, j, false)}
              stroke={lineColor}
              strokeWidth={strokeWidth}
              role="img"
              aria-label={this._getAriaLabel(i, j - 1)}
            />,
          );
          if (j + 1 === this._points[i].data.length) {
            // If this is last point of the line segment.
            const lastCircleId = `${circleId}${j}L`;
            const hiddenHoverCircleId = `${circleId}${j}D`;
            const lastPointHidden = this._points[i].hideNonActiveDots && activePoint !== lastCircleId;
            path = this._getPath(
              this._xAxisScale(x2),
              this._yAxisScale(y2),
              lastCircleId,
              j,
              true,
              this._points[i].index,
            );
            const {
              xAxisCalloutData: lastCirlceXCallout,
              xAxisCalloutAccessibilityData: lastCirlceXCalloutAccessibilityData,
            } = this._points[i].data[j];
            pointsForLine.push(
              <React.Fragment key={`${lastCircleId}_container`}>
                <path
                  id={lastCircleId}
                  key={lastCircleId}
                  d={path}
                  data-is-focusable={isLegendSelected}
                  onMouseOver={this._handleHover.bind(
                    this,
                    x2,
                    y2,
                    verticaLineHeight,
                    lastCirlceXCallout,
                    lastCircleId,
                    lastCirlceXCalloutAccessibilityData,
                  )}
                  onMouseMove={this._handleHover.bind(
                    this,
                    x2,
                    y2,
                    verticaLineHeight,
                    lastCirlceXCallout,
                    lastCircleId,
                    lastCirlceXCalloutAccessibilityData,
                  )}
                  onMouseOut={this._handleMouseOut}
                  onFocus={() =>
                    this._handleFocus(lineId, x2, lastCirlceXCallout, lastCircleId, lastCirlceXCalloutAccessibilityData)
                  }
                  onBlur={this._handleMouseOut}
                  {...this._getClickHandler(this._points[i].data[j].onDataPointClick)}
                  opacity={isLegendSelected && !lastPointHidden ? 1 : 0.01}
                  fill={this._getPointFill(lineColor, lastCircleId, j, true)}
                  stroke={lineColor}
                  strokeWidth={strokeWidth}
                  role="img"
                  aria-label={this._getAriaLabel(i, j)}
                />
                {/* Dummy circle acting as magnetic latch for last callout point */}
                <circle
                  id={hiddenHoverCircleId}
                  key={hiddenHoverCircleId}
                  r={8}
                  cx={this._xAxisScale(x2)}
                  cy={this._yAxisScale(y2)}
                  opacity={0}
                  width={0}
                  onMouseOver={this._handleHover.bind(
                    this,
                    x2,
                    y2,
                    verticaLineHeight,
                    lastCirlceXCallout,
                    lastCircleId,
                    lastCirlceXCalloutAccessibilityData,
                  )}
                  onMouseMove={this._handleHover.bind(
                    this,
                    x2,
                    y2,
                    verticaLineHeight,
                    lastCirlceXCallout,
                    lastCircleId,
                    lastCirlceXCalloutAccessibilityData,
                  )}
                  onMouseOut={this._handleMouseOut}
                  strokeWidth={0}
                  focusable={false}
                  onBlur={this._handleMouseOut}
                />
              </React.Fragment>,
            );
            /* eslint-enable react/jsx-no-bind */
          }
 
          if (isLegendSelected) {
            // don't draw line if it is in a gap
            if (!isInGap) {
              const lineBorderWidth = this._points[i].lineOptions?.lineBorderWidth
                ? Number.parseFloat(this._points[i].lineOptions!.lineBorderWidth!.toString())
                : 0;
              if (lineBorderWidth > 0) {
                bordersForLine.push(
                  <line
                    id={borderId}
                    key={borderId}
                    x1={this._xAxisScale(x1)}
                    y1={this._yAxisScale(y1)}
                    x2={this._xAxisScale(x2)}
                    y2={this._yAxisScale(y2)}
                    strokeLinecap={this._points[i].lineOptions?.strokeLinecap ?? 'round'}
                    strokeWidth={Number.parseFloat(strokeWidth.toString()) + lineBorderWidth}
                    stroke={this._points[i].lineOptions?.lineBorderColor || theme!.semanticColors.bodyBackground}
                    opacity={1}
                  />,
                );
              }
 
              linesForLine.push(
                <line
                  id={lineId}
                  key={lineId}
                  x1={this._xAxisScale(x1)}
                  y1={this._yAxisScale(y1)}
                  x2={this._xAxisScale(x2)}
                  y2={this._yAxisScale(y2)}
                  strokeWidth={strokeWidth}
                  ref={(e: SVGLineElement | null) => {
                    this._refCallback(e!, lineId);
                  }}
                  onMouseOver={this._handleHover.bind(
                    this,
                    x1,
                    y1,
                    verticaLineHeight,
                    xAxisCalloutData,
                    circleId,
                    xAxisCalloutAccessibilityData,
                  )}
                  onMouseMove={this._handleHover.bind(
                    this,
                    x1,
                    y1,
                    verticaLineHeight,
                    xAxisCalloutData,
                    circleId,
                    xAxisCalloutAccessibilityData,
                  )}
                  onMouseOut={this._handleMouseOut}
                  stroke={lineColor}
                  strokeLinecap={this._points[i].lineOptions?.strokeLinecap ?? 'round'}
                  strokeDasharray={this._points[i].lineOptions?.strokeDasharray}
                  strokeDashoffset={this._points[i].lineOptions?.strokeDashoffset}
                  opacity={1}
                  {...this._getClickHandler(this._points[i].onLineClick)}
                />,
              );
            }
          } else {
            if (!isInGap) {
              linesForLine.push(
                <line
                  id={lineId}
                  key={lineId}
                  x1={this._xAxisScale(x1)}
                  y1={this._yAxisScale(y1)}
                  x2={this._xAxisScale(x2)}
                  y2={this._yAxisScale(y2)}
                  strokeWidth={strokeWidth}
                  stroke={lineColor}
                  strokeLinecap={this._points[i].lineOptions?.strokeLinecap ?? 'round'}
                  strokeDasharray={this._points[i].lineOptions?.strokeDasharray}
                  strokeDashoffset={this._points[i].lineOptions?.strokeDashoffset}
                  opacity={0.1}
                />,
              );
            }
          }
        }
      }
 
      lines.push(...bordersForLine, ...linesForLine, ...pointsForLine);
    }
    const classNames = getClassNames(this.props.styles!, {
      theme: this.props.theme!,
    });
    // Removing un wanted tooltip div from DOM, when prop not provided.
    if (!this.props.showXAxisLablesTooltip) {
      try {
        document.getElementById(this._tooltipId) && document.getElementById(this._tooltipId)!.remove();
        // eslint-disable-next-line no-empty
      } catch (e) {}
    }
    // Used to display tooltip at x axis labels.
    if (!this.props.wrapXAxisLables && this.props.showXAxisLablesTooltip) {
      const xAxisElement = d3Select(xElement).call(this._xAxisScale);
      try {
        document.getElementById(this._tooltipId) && document.getElementById(this._tooltipId)!.remove();
        // eslint-disable-next-line no-empty
      } catch (e) {}
      const tooltipProps = {
        tooltipCls: classNames.tooltip!,
        id: this._tooltipId,
        xAxis: xAxisElement,
      };
      xAxisElement && tooltipOfXAxislabels(tooltipProps);
    }
    return lines;
  }
 
  private _createColorFillBars = (containerHeight: number) => {
    const colorFillBars: JSX.Element[] = [];
    if (this.state.isSelectedLegend) {
      this._colorFillBars = this.state.selectedColorBarLegend;
    } else {
      this._colorFillBars = this.props.colorFillBars!;
    }
 
    const yMinMaxValues = getMinMaxOfYAxis(this._points, ChartTypes.LineChart);
    const FILL_Y_PADDING = 3;
    for (let i = 0; i < this._colorFillBars.length; i++) {
      const colorFillBar = this._colorFillBars[i];
      const colorFillBarId = getId(colorFillBar.legend.replace(/\W/g, ''));
      // isInverted property is applicable to v8 themes only
      const color = getColorFromToken(colorFillBar.color, this.props.theme?.isInverted);
 
      if (colorFillBar.applyPattern) {
        // Using a pattern element because CSS was unable to render diagonal stripes for rect elements
        colorFillBars.push(this._getStripePattern(color, i));
      }
 
      for (let j = 0; j < colorFillBar.data.length; j++) {
        const startX = colorFillBar.data[j].startX;
        const endX = colorFillBar.data[j].endX;
        const opacity =
          this._legendHighlighted(colorFillBar.legend) || this._noLegendHighlighted() || this.state.isSelectedLegend
            ? this._getColorFillBarOpacity(colorFillBar)
            : 0.1;
        colorFillBars.push(
          <rect
            fill={colorFillBar.applyPattern ? `url(#${this._colorFillBarPatternId}_${i})` : color}
            fillOpacity={opacity}
            x={this._isRTL ? this._xAxisScale(endX) : this._xAxisScale(startX)}
            y={this._yAxisScale(yMinMaxValues.endValue) - FILL_Y_PADDING}
            width={Math.abs(this._xAxisScale(endX) - this._xAxisScale(startX))}
            height={
              this._yAxisScale(this.props.yMinValue || 0) - this._yAxisScale(yMinMaxValues.endValue) + FILL_Y_PADDING
            }
            key={`${colorFillBarId}${j}`}
          />,
        );
      }
    }
    return colorFillBars;
  };
 
  private _getStripePattern = (color: string, id: number) => {
    // This describes a tile pattern that resembles diagonal stripes
    // For more information: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d
    const stripePath = 'M-4,4 l8,-8 M0,16 l16,-16 M12,20 l8,-8';
    return (
      <pattern
        id={`${this._colorFillBarPatternId}_${id}`}
        width={16}
        height={16}
        key={`${this._colorFillBarPatternId}_${id}`}
        patternUnits={'userSpaceOnUse'}
      >
        <path d={stripePath} stroke={color} strokeWidth={1.25} />
      </pattern>
    );
  };
 
  private _checkInGap = (pointIndex: number, gaps: ILineChartGap[], currentGapIndex: number) => {
    let gapIndex = currentGapIndex;
    let isInGap = false;
 
    while (gapIndex < gaps.length && pointIndex > gaps[gapIndex].endIndex) {
      gapIndex++;
    }
 
    if (gapIndex < gaps.length && pointIndex > gaps[gapIndex].startIndex && pointIndex <= gaps[gapIndex].endIndex) {
      isInGap = true;
    }
    return { isInGap, gapIndex };
  };
 
  private _refCallback(element: SVGGElement, legendTitle: string): void {
    this._refArray.push({ index: legendTitle, refElement: element });
  }
 
  private _onMouseOverLargeDataset = (
    linenumber: number,
    lineHeight: number,
    mouseEvent: React.MouseEvent<SVGRectElement | SVGPathElement | SVGCircleElement>,
  ) => {
    mouseEvent.persist();
    const { data } = this.props;
    const { lineChartData } = data;
 
    // This will get the value of the X when mouse is on the chart
    const xOffset = this._xAxisScale.invert(pointer(mouseEvent)[0], document.getElementById(this._rectId)!);
    const i = bisect(lineChartData![linenumber].data, xOffset);
    const d0 = lineChartData![linenumber].data[i - 1] as ILineChartDataPoint;
    const d1 = lineChartData![linenumber].data[i] as ILineChartDataPoint;
    let axisType: XAxisTypes | null = null;
    let xPointToHighlight: string | Date | number | null = null;
    let index: null | number = null;
    if (d0 === undefined && d1 !== undefined) {
      xPointToHighlight = d1.x;
      index = i;
    } else if (d0 !== undefined && d1 === undefined) {
      xPointToHighlight = d0.x;
      index = i - 1;
    } else {
      axisType = getTypeOfAxis(lineChartData![linenumber].data[0].x, true) as XAxisTypes;
      let x0;
      let point0;
      let point1;
      switch (axisType) {
        case XAxisTypes.DateAxis:
          x0 = new Date(xOffset).getTime();
          point0 = (d0.x as Date).getTime();
          point1 = (d1.x as Date).getTime();
          xPointToHighlight = Math.abs(x0 - point0) > Math.abs(x0 - point1) ? d1.x : d0.x;
          index = Math.abs(x0 - point0) > Math.abs(x0 - point1) ? i : i - 1;
          break;
        case XAxisTypes.NumericAxis:
          x0 = xOffset as number;
          point0 = d0.x as number;
          point1 = d1.x as number;
          xPointToHighlight = Math.abs(x0 - point0) > Math.abs(x0 - point1) ? d1.x : d0.x;
          index = Math.abs(x0 - point0) > Math.abs(x0 - point1) ? i : i - 1;
          break;
        default:
          break;
      }
    }
 
    const { xAxisCalloutData, xAxisCalloutAccessibilityData } = lineChartData![linenumber].data[index as number];
    const formattedDate = xPointToHighlight instanceof Date ? xPointToHighlight.toLocaleString() : xPointToHighlight;
    const modifiedXVal = xPointToHighlight instanceof Date ? xPointToHighlight.getTime() : xPointToHighlight;
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const found: any = find(this._calloutPoints, (element: { x: string | number }) => {
      return element.x === modifiedXVal;
    });
    const pointToHighlight: ILineChartDataPoint = lineChartData![linenumber].data[index!];
    const pointToHighlightUpdated =
      this.state.nearestCircleToHighlight === null ||
      (this.state.nearestCircleToHighlight !== null &&
        pointToHighlight !== null &&
        (this.state.nearestCircleToHighlight.x !== pointToHighlight.x ||
          this.state.nearestCircleToHighlight.y !== pointToHighlight.y));
    // if no points need to be called out then don't show vertical line and callout card
    Iif (found && pointToHighlightUpdated) {
      this._uniqueCallOutID = `#${this._staticHighlightCircle}_${linenumber}`;
 
      d3Select(`#${this._staticHighlightCircle}_${linenumber}`)
        .attr('cx', `${this._xAxisScale(pointToHighlight.x)}`)
        .attr('cy', `${this._yAxisScale(pointToHighlight.y)}`)
        .attr('visibility', 'visibility');
 
      d3Select(`#${this._verticalLine}`)
        .attr(
          'transform',
          () => `translate(${this._xAxisScale(pointToHighlight.x)}, ${this._yAxisScale(pointToHighlight.y)})`,
        )
        .attr('visibility', 'visibility')
        .attr('y2', `${lineHeight - this._yAxisScale(pointToHighlight.y)}`);
 
      this.setState({
        nearestCircleToHighlight: pointToHighlight,
        isCalloutVisible: true,
        refSelected: `#${this._staticHighlightCircle}_${linenumber}`,
        stackCalloutProps: found!,
        YValueHover: found.values,
        dataPointCalloutProps: found!,
        hoverXValue: xAxisCalloutData ? xAxisCalloutData : formattedDate,
        xAxisCalloutAccessibilityData,
        activePoint: '',
        activeLine: linenumber,
      });
    }
 
    Iif (!found) {
      this.setState({
        isCalloutVisible: false,
        nearestCircleToHighlight: pointToHighlight,
        activePoint: '',
        activeLine: linenumber,
      });
    }
  };
 
  private _handleFocus = (
    lineId: string,
    x: number | Date,
 
    xAxisCalloutData: string | undefined,
    circleId: string,
    xAxisCalloutAccessibilityData?: IAccessibilityProps,
  ) => {
    this._uniqueCallOutID = circleId;
    const formattedData = x instanceof Date ? x.toLocaleDateString() : x;
    const xVal = x instanceof Date ? x.getTime() : x;
    const found = find(this._calloutPoints, (element: { x: string | number }) => element.x === xVal);
    // if no points need to be called out then don't show vertical line and callout card
 
    if (found) {
      const _this = this;
      d3Select(`#${this._verticalLine}`)
        .attr('transform', () => `translate(${_this._xAxisScale(x)}, 0)`)
        .attr('visibility', 'visibility');
      this._refArray.forEach((obj: IRefArrayData) => {
        Iif (obj.index === lineId) {
          this.setState({
            isCalloutVisible: true,
            refSelected: obj.refElement,
            hoverXValue: xAxisCalloutData ? xAxisCalloutData : '' + formattedData,
            YValueHover: found.values,
            stackCalloutProps: found!,
            dataPointCalloutProps: found!,
            activePoint: circleId,
            xAxisCalloutAccessibilityData,
          });
        }
      });
    } else {
      this.setState({
        activePoint: circleId,
      });
    }
  };
 
  private _handleHover = (
    x: number | Date,
    y: number | Date,
    lineHeight: number,
    xAxisCalloutData: string | undefined,
    circleId: string,
    xAxisCalloutAccessibilityData: IAccessibilityProps | undefined,
    mouseEvent: React.MouseEvent<SVGElement>,
  ) => {
    mouseEvent.persist();
    const formattedData = x instanceof Date ? x.toLocaleDateString() : x;
    const xVal = x instanceof Date ? x.getTime() : x;
    const _this = this;
    const found = find(this._calloutPoints, (element: { x: string | number }) => element.x === xVal);
    // if no points need to be called out then don't show vertical line and callout card
 
    if (found) {
      d3Select(`#${this._verticalLine}`)
        .attr('transform', () => `translate(${_this._xAxisScale(x)}, ${_this._yAxisScale(y)})`)
        .attr('visibility', 'visibility')
        .attr('y2', `${lineHeight - _this._yAxisScale(y)}`);
      if (this._uniqueCallOutID !== circleId) {
        this._uniqueCallOutID = circleId;
        this.setState({
          isCalloutVisible: true,
          refSelected: `#${circleId}`,
          hoverXValue: xAxisCalloutData ? xAxisCalloutData : '' + formattedData,
          YValueHover: found.values,
          stackCalloutProps: found!,
          dataPointCalloutProps: found!,
          activePoint: circleId,
          xAxisCalloutAccessibilityData,
          nearestCircleToHighlight: null,
          activeLine: null,
        });
      }
    } else E{
      this.setState({
        activePoint: circleId,
        nearestCircleToHighlight: null,
        activeLine: null,
      });
    }
  };
 
  /**
   * Screen readers announce an element as clickable if the onClick attribute is set.
   * This function sets the attribute only when a click event handler is provided.
   */
  private _getClickHandler = (func?: () => void): { onClick?: () => void } => {
    Iif (func) {
      return {
        onClick: func,
      };
    }
 
    return {};
  };
 
  private _handleMouseOut = () => {
    d3Select(`#${this._verticalLine}`).attr('visibility', 'hidden');
  };
 
  private _handleChartMouseLeave = () => {
    this._uniqueCallOutID = null;
    this.setState({
      isCalloutVisible: false,
      activePoint: '',
      activeLine: null,
    });
  };
 
  private _handleLegendClick = (
    lineChartItem: LineChartDataWithIndex | IColorFillBarsProps,
    selectedLegend: string | null | string[],
  ): void => {
    Iif (lineChartItem.onLegendClick) {
      lineChartItem.onLegendClick(selectedLegend);
    }
  };
 
  private _handleMultipleLineLegendSelectionAction = (selectedLine: LineChartDataWithIndex) => {
    const selectedLineIndex = this.state.selectedLegendPoints.reduce((acc, line, index) => {
      if (acc > -1 || line.legend !== selectedLine.legend) {
        return acc;
      } else E{
        return index;
      }
    }, -1);
 
    let selectedLines: LineChartDataWithIndex[];
    if (selectedLineIndex === -1) {
      selectedLines = [...this.state.selectedLegendPoints, selectedLine];
    } else E{
      selectedLines = this.state.selectedLegendPoints
        .slice(0, selectedLineIndex)
        .concat(this.state.selectedLegendPoints.slice(selectedLineIndex + 1));
    }
 
    const areAllLineLegendsSelected = this.props.data && selectedLines.length === this.props.data.lineChartData!.length;
 
    Iif (
      areAllLineLegendsSelected &&
      ((this.props.colorFillBars && this.props.colorFillBars.length === this.state.selectedColorBarLegend.length) ||
        !this.props.colorFillBars)
    ) {
      // Clear all legends if all legends including color fill bar legends are selected
      // Or clear all legends if all legends are selected and there are no color fill bars
      this._clearMultipleLegendSelections();
    } else Iif (!selectedLines.length && !this.state.selectedColorBarLegend.length) {
      // Clear all legends if no legends including color fill bar legends are selected
      this._clearMultipleLegendSelections();
    } else {
      // Otherwise, set state when one or more legends are selected, including color fill bar legends
      this.setState({
        selectedLegendPoints: selectedLines,
        isSelectedLegend: true,
      });
    }
 
    const selectedLegendTitlesToPass = selectedLines.map((line: LineChartDataWithIndex) => line.legend);
    this._handleLegendClick(selectedLine, selectedLegendTitlesToPass);
  };
 
  private _handleMultipleColorFillBarLegendSelectionAction = (selectedColorFillBar: IColorFillBarsProps) => {
    const selectedColorFillBarIndex = this.state.selectedColorBarLegend.reduce((acc, colorFillBar, index) => {
      if (acc > -1 || colorFillBar.legend !== selectedColorFillBar.legend) {
        return acc;
      } else E{
        return index;
      }
    }, -1);
 
    let selectedColorFillBars: IColorFillBarsProps[];
    if (selectedColorFillBarIndex === -1) {
      selectedColorFillBars = [...this.state.selectedColorBarLegend, selectedColorFillBar];
    } else E{
      selectedColorFillBars = this.state.selectedColorBarLegend
        .slice(0, selectedColorFillBarIndex)
        .concat(this.state.selectedColorBarLegend.slice(selectedColorFillBarIndex + 1));
    }
 
    const areAllColorFillBarLegendsSelected =
      selectedColorFillBars.length === (this.props.colorFillBars && this.props.colorFillBars!.length);
 
    Iif (
      areAllColorFillBarLegendsSelected &&
      ((this.props.data && this.props.data.lineChartData!.length === this.state.selectedLegendPoints.length) ||
        !this.props.data)
    ) {
      // Clear all legends if all legends, including line legends, are selected
      // Or clear all legends if all legends are selected and there is no line data
      this._clearMultipleLegendSelections();
    } else Iif (!selectedColorFillBars.length && !this.state.selectedLegendPoints.length) {
      // Clear all legends if no legends are selected, including line legends
      this._clearMultipleLegendSelections();
    } else {
      // set state when one or more legends are selected, including line legends
      this.setState({
        selectedColorBarLegend: selectedColorFillBars,
        isSelectedLegend: true,
      });
    }
 
    const selectedLegendTitlesToPass = selectedColorFillBars.map(
      (colorFillBar: IColorFillBarsProps) => colorFillBar.legend,
    );
    this._handleLegendClick(selectedColorFillBar, selectedLegendTitlesToPass);
  };
 
  private _clearMultipleLegendSelections = () => {
    this.setState({
      selectedColorBarLegend: [],
      selectedLegendPoints: [],
      isSelectedLegend: false,
    });
  };
 
  /**
   * This function checks if the given legend is highlighted or not.
   * A legend can be highlighted in 2 ways:
   * 1. selection: if the user clicks on it
   * 2. hovering: if there is no selected legend and the user hovers over it
   */
  private _legendHighlighted = (legend: string) => {
    return (
      this.state.selectedLegend === legend || (this.state.selectedLegend === '' && this.state.activeLegend === legend)
    );
  };
 
  /**
   * This function checks if none of the legends is selected or hovered.
   */
  private _noLegendHighlighted = () => {
    return this.state.selectedLegend === '' && this.state.activeLegend === '';
  };
 
  private _getColorFillBarOpacity = (colorFillBar: IColorFillBarsProps) => {
    return colorFillBar.applyPattern ? 1 : 0.4;
  };
 
  private _getAriaLabel = (lineIndex: number, pointIndex: number): string => {
    const line = this._points[lineIndex];
    const point = line.data[pointIndex];
    const formattedDate = point.x instanceof Date ? point.x.toLocaleString() : point.x;
    const xValue = point.xAxisCalloutData || formattedDate;
    const legend = line.legend;
    const yValue = point.yAxisCalloutData || point.y;
    return point.callOutAccessibilityData?.ariaLabel || `${xValue}. ${legend}, ${yValue}.`;
  };
 
  private _isChartEmpty(): boolean {
    return !(
      this.props.data &&
      this.props.data.lineChartData &&
      this.props.data.lineChartData.length > 0 &&
      this.props.data.lineChartData.filter((item: ILineChartPoints) => item.data.length).length > 0
    );
  }
}