{"version":3,"file":"getLineEndPoint-Ce8sRrNU.cjs","names":[],"sources":["../src/Components/Elements/Annotations.tsx","../src/Utils/getPathFromPoints.ts","../src/Components/Elements/HighlightArea/customArea.tsx","../src/Utils/getLineEndPoint.ts"],"sourcesContent":["import { cn } from '@undp/design-system-react/cn';\r\nimport { motion } from 'motion/react';\r\n\r\nimport type { AnimateDataType } from '@/Types';\r\n\r\ninterface Props {\r\n  color?: string;\r\n  connectorsSettings?: {\r\n    x1: number;\r\n    x2: number;\r\n    y1: number;\r\n    y2: number;\r\n    cx: number;\r\n    cy: number;\r\n    circleRadius: number;\r\n    strokeWidth: number;\r\n  };\r\n  labelSettings: {\r\n    x: number;\r\n    y: number;\r\n    width: number;\r\n    maxWidth?: number;\r\n    fontWeight?: 'regular' | 'bold' | 'medium';\r\n    align?: 'center' | 'left' | 'right';\r\n  };\r\n  text: string;\r\n  classNames?: {\r\n    connector?: string;\r\n    text?: string;\r\n  };\r\n  styles?: {\r\n    connector?: React.CSSProperties;\r\n    text?: React.CSSProperties;\r\n  };\r\n  animate: AnimateDataType;\r\n  isInView: boolean;\r\n}\r\n\r\nexport function Annotation(props: Props) {\r\n  const { connectorsSettings, text, color, labelSettings, classNames, styles, animate, isInView } =\r\n    props;\r\n  return (\r\n    <motion.g\r\n      exit={{ opacity: 0, transition: { duration: animate.duration } }}\r\n      variants={{\r\n        initial: {\r\n          opacity: 0,\r\n        },\r\n        whileInView: {\r\n          opacity: 1,\r\n          transition: { duration: animate.duration },\r\n        },\r\n      }}\r\n      initial='initial'\r\n      animate={isInView ? 'whileInView' : 'initial'}\r\n    >\r\n      {connectorsSettings ? (\r\n        <>\r\n          <circle\r\n            cy={connectorsSettings.cy}\r\n            cx={connectorsSettings.cx}\r\n            r={connectorsSettings.circleRadius}\r\n            className={cn(!color ? 'stroke-foreground-soft' : '', classNames?.connector)}\r\n            style={{\r\n              fill: 'none',\r\n              strokeWidth: connectorsSettings.strokeWidth,\r\n              ...(color ? { stroke: color } : {}),\r\n              ...(styles?.connector || {}),\r\n            }}\r\n          />\r\n          <line\r\n            y1={connectorsSettings.y1}\r\n            x1={connectorsSettings.x1}\r\n            y2={connectorsSettings.y2}\r\n            x2={connectorsSettings.x2}\r\n            className={cn(!color ? 'stroke-foreground-soft' : '', classNames?.connector)}\r\n            style={{\r\n              fill: 'none',\r\n              strokeWidth: connectorsSettings.strokeWidth,\r\n              ...(color ? { stroke: color } : {}),\r\n              ...(styles?.connector || {}),\r\n            }}\r\n          />\r\n        </>\r\n      ) : null}\r\n      <foreignObject\r\n        y={labelSettings.y}\r\n        x={labelSettings.x}\r\n        width={labelSettings.width}\r\n        height={1}\r\n        style={{ overflow: 'visible' }}\r\n      >\r\n        <p\r\n          className={cn(\r\n            'text-sm leading-sm m-0 whitespace-normal',\r\n            labelSettings.fontWeight === 'bold'\r\n              ? 'font-bold'\r\n              : labelSettings.fontWeight === 'medium'\r\n                ? 'font-medium'\r\n                : 'font-normal',\r\n            labelSettings.align === 'right'\r\n              ? 'text-right'\r\n              : labelSettings.align === 'center'\r\n                ? 'text-center'\r\n                : 'text-left',\r\n            !color ? 'text-content-primary' : undefined,\r\n            classNames?.text,\r\n          )}\r\n          style={{\r\n            maxWidth: labelSettings.maxWidth || 'auto',\r\n            ...(color ? { color } : {}),\r\n            ...(styles?.text || {}),\r\n          }}\r\n        >\r\n          {text}\r\n        </p>\r\n      </foreignObject>\r\n    </motion.g>\r\n  );\r\n}\r\n","export function getPathFromPoints(pointsArray: number[], closePath?: boolean) {\r\n  if (pointsArray.length < 4 || pointsArray.length % 2 !== 0) {\r\n    return ''; // Need at least two points (4 numbers) and an even number of coordinates\r\n  }\r\n\r\n  let path = `M ${pointsArray[0]} ${pointsArray[1]}`; // Move to the first point\r\n  for (let i = 2; i < pointsArray.length; i += 2) {\r\n    path += ` L ${pointsArray[i]} ${pointsArray[i + 1]}`; // Draw lines to subsequent points\r\n  }\r\n  if (closePath === false) return path;\r\n\r\n  path += ' Z'; // Close the path\r\n\r\n  return path;\r\n}\r\n","import { cn } from '@undp/design-system-react/cn';\r\nimport type { NumberValue } from 'd3-scale';\r\nimport { motion } from 'motion/react';\r\nimport type { AnimateDataType } from '@/Types';\r\nimport { getPathFromPoints } from '@/Utils/getPathFromPoints';\r\n\r\ninterface Props {\r\n  areaSettings: {\r\n    coordinates: (Date | number)[];\r\n    closePath?: boolean;\r\n    style?: React.CSSProperties;\r\n    className?: string;\r\n    color?: string;\r\n    strokeWidth?: number;\r\n  }[];\r\n  scaleX: (value: Date | NumberValue) => number;\r\n  scaleY: (value: Date | NumberValue) => number;\r\n  animate: AnimateDataType;\r\n  isInView: boolean;\r\n}\r\nexport function CustomArea(props: Props) {\r\n  const { areaSettings, scaleX, scaleY, animate, isInView } = props;\r\n  return (\r\n    <>\r\n      {areaSettings.map((d) => (\r\n        <motion.g\r\n          key={d.coordinates\r\n            .map((item) => (item instanceof Date ? item.toISOString() : item.toString()))\r\n            .join('~')}\r\n          variants={{\r\n            initial: {\r\n              opacity: 0,\r\n            },\r\n            whileInView: {\r\n              opacity: 1,\r\n              transition: { duration: animate.duration },\r\n            },\r\n          }}\r\n          initial='initial'\r\n          animate={isInView ? 'whileInView' : 'initial'}\r\n        >\r\n          {d.coordinates.length !== 4 ? (\r\n            <path\r\n              d={getPathFromPoints(\r\n                d.coordinates.map((el, j) => (j % 2 === 0 ? scaleX(el) : scaleY(el as number))),\r\n                d.closePath,\r\n              )}\r\n              style={{\r\n                strokeWidth: d.strokeWidth || 0,\r\n                ...(d.coordinates.length > 4 ? d.color && { fill: d.color } : { fill: 'none' }),\r\n                ...(d.color && { stroke: d.color }),\r\n                ...(d.style || {}),\r\n              }}\r\n              className={cn(!d.color ? 'stroke-stroke-sm fill-surface-sm' : '', d.className)}\r\n            />\r\n          ) : (\r\n            <line\r\n              x1={scaleX(d.coordinates[0])}\r\n              y1={scaleY(d.coordinates[1] as number)}\r\n              x2={scaleX(d.coordinates[2])}\r\n              y2={scaleY(d.coordinates[3] as number)}\r\n              style={{\r\n                ...(d.color && { stroke: d.color }),\r\n                fill: 'none',\r\n                strokeWidth: d.strokeWidth || 1,\r\n                ...(d.style || {}),\r\n              }}\r\n              className={cn(!d.color ? 'stroke-stroke-sm' : '', d.className)}\r\n            />\r\n          )}\r\n        </motion.g>\r\n      ))}\r\n    </>\r\n  );\r\n}\r\n","interface Coordinates {\r\n  x: number;\r\n  y: number;\r\n}\r\n\r\nexport function getLineEndPoint(startPoint: Coordinates, targetPoint: Coordinates, radius: number) {\r\n  const circleCenter = { x: targetPoint.x, y: targetPoint.y };\r\n  const directionVector = {\r\n    x: startPoint.x - circleCenter.x,\r\n    y: startPoint.y - circleCenter.y,\r\n  };\r\n  const magnitude = Math.sqrt(directionVector.x ** 2 + directionVector.y ** 2);\r\n  const unitVector = {\r\n    x: directionVector.x / magnitude,\r\n    y: directionVector.y / magnitude,\r\n  };\r\n  return {\r\n    x: circleCenter.x + radius * unitVector.x,\r\n    y: circleCenter.y + radius * unitVector.y,\r\n  };\r\n}\r\n"],"mappings":"qHAsCA,SAAgB,EAAW,EAAc,CACvC,GAAM,CAAE,qBAAoB,OAAM,QAAO,gBAAe,aAAY,SAAQ,UAAS,YACnF,EACF,OACE,EAAA,EAAA,MAAC,EAAA,EAAO,EAAR,CACE,KAAM,CAAE,QAAS,EAAG,WAAY,CAAE,SAAU,EAAQ,QAAS,CAAE,EAC/D,SAAU,CACR,QAAS,CACP,QAAS,CACX,EACA,YAAa,CACX,QAAS,EACT,WAAY,CAAE,SAAU,EAAQ,QAAS,CAC3C,CACF,EACA,QAAQ,UACR,QAAS,EAAW,cAAgB,mBAZtC,CAcG,GACC,EAAA,EAAA,MAAA,EAAA,SAAA,CAAA,SAAA,EACE,EAAA,EAAA,KAAC,SAAD,CACE,GAAI,EAAmB,GACvB,GAAI,EAAmB,GACvB,EAAG,EAAmB,aACtB,WAAA,EAAA,EAAA,IAAe,EAAmC,GAA3B,yBAA+B,GAAY,SAAS,EAC3E,MAAO,CACL,KAAM,OACN,YA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