{"version":3,"file":"BulletChart-CCil-Lyf.cjs","names":[],"sources":["../src/Components/Graphs/BulletChart/Graph.tsx","../src/Components/Graphs/BulletChart/index.tsx"],"sourcesContent":["import { cn } from '@undp/design-system-react/cn';\r\nimport { scaleBand, scaleLinear } from 'd3-scale';\r\nimport isEqual from 'fast-deep-equal';\r\nimport sum from 'lodash.sum';\r\nimport { AnimatePresence, motion, useInView } from 'motion/react';\r\nimport { useMemo, useRef, useState } from 'react';\r\nimport { Axis } from '@/Components/Elements/Axes/Axis';\r\nimport { AxisTitle } from '@/Components/Elements/Axes/AxisTitle';\r\nimport { XAxesLabels } from '@/Components/Elements/Axes/XAxesLabels';\r\nimport { XTicksAndGridLines } from '@/Components/Elements/Axes/XTicksAndGridLines';\r\nimport { YAxesLabels } from '@/Components/Elements/Axes/YAxesLabels';\r\nimport { YTicksAndGridLines } from '@/Components/Elements/Axes/YTicksAndGridLines';\r\nimport { DetailsModal } from '@/Components/Elements/DetailsModal';\r\nimport { RefLineX, RefLineY } from '@/Components/Elements/ReferenceLine';\r\nimport { Tooltip } from '@/Components/Elements/Tooltip';\r\nimport type {\r\n  AnimateDataType,\r\n  BulletChartDataType,\r\n  ClassNameObject,\r\n  CustomLayerDataType,\r\n  PadZerosTypes,\r\n  ReferenceDataType,\r\n  StyleObject,\r\n} from '@/Types';\r\nimport { checkIfNullOrUndefined } from '@/Utils/checkIfNullOrUndefined';\r\nimport { getGraphDimensions } from '@/Utils/getGraphDimensions';\r\nimport { numberFormattingFunction } from '@/Utils/numberFormattingFunction';\r\n\r\ninterface Props {\r\n  data: BulletChartDataType[];\r\n  width: number;\r\n  height: number;\r\n  barColor: string;\r\n  suffix: string;\r\n  prefix: string;\r\n  barPadding: number;\r\n  showLabels: boolean;\r\n  showValues: boolean;\r\n  showTicks: boolean;\r\n  truncateBy: number;\r\n  leftMargin?: number;\r\n  rightMargin?: number;\r\n  topMargin?: number;\r\n  bottomMargin?: number;\r\n  refValues?: ReferenceDataType[];\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  tooltip?: string | ((_d: any) => React.ReactNode);\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  onSeriesMouseOver?: (_d: any) => void;\r\n  maxValue?: number;\r\n  minValue?: number;\r\n  highlightedDataPoints?: (string | number)[];\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  onSeriesMouseClick?: (_d: any) => void;\r\n  labelOrder?: (string | number)[];\r\n  maxBarThickness?: number;\r\n  minBarThickness?: number;\r\n  resetSelectionOnDoubleClick: boolean;\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  detailsOnClick?: string | ((_d: any) => React.ReactNode);\r\n  barAxisTitle?: string;\r\n  noOfTicks: number;\r\n  valueColor?: string;\r\n  styles?: StyleObject;\r\n  classNames?: ClassNameObject;\r\n  targetColor: string;\r\n  targetStyle: 'background' | 'line';\r\n  qualitativeRangeColors: string[];\r\n  measureBarWidthFactor: number;\r\n  animate: AnimateDataType;\r\n  dimmedOpacity: number;\r\n  precision: number;\r\n  customLayers: CustomLayerDataType[];\r\n  naLabel: string;\r\n  rtl: boolean;\r\n  targetLineThickness: number;\r\n  hideAxisLine: boolean;\r\n  locale: string;\r\n  padZeros: PadZerosTypes;\r\n}\r\n\r\nexport function VerticalGraph(props: Props) {\r\n  const {\r\n    data,\r\n    width,\r\n    height,\r\n    barColor,\r\n    suffix,\r\n    prefix,\r\n    barPadding,\r\n    showLabels,\r\n    showValues,\r\n    showTicks,\r\n    truncateBy,\r\n    leftMargin = 20,\r\n    rightMargin = 20,\r\n    topMargin = 20,\r\n    bottomMargin = 25,\r\n    tooltip,\r\n    onSeriesMouseOver,\r\n    refValues,\r\n    maxValue,\r\n    minValue,\r\n    highlightedDataPoints,\r\n    onSeriesMouseClick,\r\n    labelOrder,\r\n    maxBarThickness,\r\n    minBarThickness,\r\n    resetSelectionOnDoubleClick,\r\n    detailsOnClick,\r\n    barAxisTitle,\r\n    valueColor,\r\n    noOfTicks,\r\n    styles,\r\n    classNames,\r\n    targetStyle,\r\n    targetColor,\r\n    qualitativeRangeColors,\r\n    measureBarWidthFactor,\r\n    animate,\r\n    dimmedOpacity,\r\n    precision,\r\n    customLayers,\r\n    naLabel,\r\n    targetLineThickness,\r\n    hideAxisLine,\r\n    locale,\r\n    padZeros,\r\n  } = props;\r\n  const svgRef = useRef(null);\r\n  const isInView = useInView(svgRef, {\r\n    once: animate.once,\r\n    amount: animate.amount,\r\n  });\r\n  const margin = {\r\n    top: topMargin,\r\n    bottom: bottomMargin,\r\n    left: barAxisTitle ? leftMargin + 30 : leftMargin,\r\n    right: rightMargin,\r\n  };\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  const [mouseOverData, setMouseOverData] = useState<any>(undefined);\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  const [mouseClickData, setMouseClickData] = useState<any>(undefined);\r\n  const [eventX, setEventX] = useState<number | undefined>(undefined);\r\n  const [eventY, setEventY] = useState<number | undefined>(undefined);\r\n  const { graphHeight, graphWidth } = getGraphDimensions({ width, height }, margin);\r\n\r\n  const barMaxValue =\r\n    Math.max(...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number)) <\r\n    0\r\n      ? 0\r\n      : Math.max(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number),\r\n        );\r\n  const targetMaxValue =\r\n    Math.max(\r\n      ...data.filter((d) => !checkIfNullOrUndefined(d.target)).map((d) => d.target as number),\r\n    ) < 0\r\n      ? 0\r\n      : Math.max(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.target as number),\r\n        );\r\n  const qualitativeRangeMaxValue = Math.max(\r\n    ...data.map(\r\n      (d) => sum((d.qualitativeRange || []).filter((l) => !checkIfNullOrUndefined(l))) || 0,\r\n    ),\r\n  );\r\n  const xMaxValue = !checkIfNullOrUndefined(maxValue)\r\n    ? (maxValue as number)\r\n    : Math.max(...[barMaxValue, targetMaxValue, qualitativeRangeMaxValue].filter(Number.isFinite)) <\r\n        0\r\n      ? 0\r\n      : Math.max(\r\n          ...[barMaxValue, targetMaxValue, qualitativeRangeMaxValue].filter(Number.isFinite),\r\n        );\r\n  const barMinValue =\r\n    Math.min(...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number)) >=\r\n    0\r\n      ? 0\r\n      : Math.min(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number),\r\n        );\r\n\r\n  const targetMinValue =\r\n    Math.min(\r\n      ...data.filter((d) => !checkIfNullOrUndefined(d.target)).map((d) => d.target as number),\r\n    ) >= 0\r\n      ? 0\r\n      : Math.min(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.target)).map((d) => d.target as number),\r\n        );\r\n  const xMinValue = !checkIfNullOrUndefined(minValue)\r\n    ? (minValue as number)\r\n    : Math.min(...[barMinValue, targetMinValue].filter(Number.isFinite)) >= 0\r\n      ? 0\r\n      : Math.min(...[barMinValue, targetMinValue].filter(Number.isFinite));\r\n\r\n  const dataWithId = useMemo(() => {\r\n    const idSet = new Set<string | number>();\r\n\r\n    const dataWithIdWithoutMissingIds = data.map((d, i) => {\r\n      const id = labelOrder ? d.label : `${i}`;\r\n      idSet.add(id);\r\n      return { ...d, id };\r\n    });\r\n\r\n    const missingIds = labelOrder ? labelOrder.filter((id) => !idSet.has(id)) : [];\r\n\r\n    return [\r\n      ...dataWithIdWithoutMissingIds,\r\n      ...missingIds.map((id) => ({\r\n        id,\r\n        label: id,\r\n        size: null,\r\n        target: null,\r\n        qualitativeRange: null,\r\n      })),\r\n    ];\r\n  }, [data, labelOrder]);\r\n\r\n  const barOrder = useMemo(() => {\r\n    return labelOrder ?? dataWithId.map((d) => `${d.id}`);\r\n  }, [labelOrder, dataWithId]);\r\n\r\n  const y = scaleLinear().domain([xMinValue, xMaxValue]).range([graphHeight, 0]).nice();\r\n\r\n  const x = scaleBand<string | number>()\r\n    .domain(barOrder)\r\n    .range([\r\n      0,\r\n      minBarThickness\r\n        ? Math.max(graphWidth, minBarThickness * barOrder.length)\r\n        : maxBarThickness\r\n          ? Math.min(graphWidth, maxBarThickness * barOrder.length)\r\n          : graphWidth,\r\n    ])\r\n    .paddingInner(barPadding);\r\n  const yTicks = y.ticks(noOfTicks);\r\n  return (\r\n    <>\r\n      <motion.svg\r\n        width={`${width}px`}\r\n        height={`${height}px`}\r\n        viewBox={`0 0 ${width} ${height}`}\r\n        direction='ltr'\r\n        ref={svgRef}\r\n      >\r\n        <g transform={`translate(${margin.left},${margin.top})`}>\r\n          <Axis\r\n            hideAxisLine={hideAxisLine}\r\n            y1={y(xMinValue < 0 ? 0 : xMinValue)}\r\n            y2={y(xMinValue < 0 ? 0 : xMinValue)}\r\n            x1={0 - leftMargin}\r\n            x2={graphWidth + margin.right}\r\n            label={\r\n              showTicks\r\n                ? numberFormattingFunction(\r\n                    xMinValue < 0 ? 0 : xMinValue,\r\n                    naLabel,\r\n                    precision,\r\n                    prefix,\r\n                    suffix,\r\n                    locale,\r\n                    padZeros,\r\n                  )\r\n                : undefined\r\n            }\r\n            labelPos={{\r\n              x: 0 - leftMargin,\r\n              dx: 0,\r\n              dy: xMaxValue < 0 ? '1em' : -5,\r\n              y: y(xMinValue < 0 ? 0 : xMinValue),\r\n            }}\r\n            classNames={{\r\n              axis: classNames?.xAxis?.axis,\r\n              label: classNames?.yAxis?.labels,\r\n            }}\r\n            styles={{ axis: styles?.xAxis?.axis, label: styles?.yAxis?.labels }}\r\n          />\r\n          {showTicks ? (\r\n            <YTicksAndGridLines\r\n              values={yTicks.filter((d) => d !== 0)}\r\n              y={yTicks.filter((d) => d !== 0).map((d) => y(d))}\r\n              x1={0 - leftMargin}\r\n              x2={graphWidth + margin.right}\r\n              styles={{\r\n                gridLines: styles?.yAxis?.gridLines,\r\n                labels: styles?.yAxis?.labels,\r\n              }}\r\n              classNames={{\r\n                gridLines: classNames?.yAxis?.gridLines,\r\n                labels: classNames?.yAxis?.labels,\r\n              }}\r\n              suffix={suffix}\r\n              prefix={prefix}\r\n              labelType='secondary'\r\n              showGridLines\r\n              labelPos='vertical'\r\n              precision={precision}\r\n              locale={locale}\r\n              padZeros={padZeros}\r\n            />\r\n          ) : null}\r\n          <AxisTitle\r\n            x={0 - leftMargin - 15}\r\n            y={graphHeight / 2}\r\n            style={styles?.yAxis?.title}\r\n            className={classNames?.yAxis?.title}\r\n            text={barAxisTitle}\r\n            rotate90\r\n          />\r\n          {customLayers.filter((d) => d.position === 'before').map((d) => d.layer)}\r\n          <AnimatePresence>\r\n            {dataWithId.map((d) =>\r\n              !checkIfNullOrUndefined(x(d.id)) ? (\r\n                <motion.g\r\n                  className='undp-viz-g-with-hover'\r\n                  key={d.label}\r\n                  onMouseEnter={(event) => {\r\n                    setMouseOverData(d);\r\n                    setEventY(event.clientY);\r\n                    setEventX(event.clientX);\r\n                    onSeriesMouseOver?.(d);\r\n                  }}\r\n                  onClick={() => {\r\n                    if (onSeriesMouseClick || detailsOnClick) {\r\n                      if (isEqual(mouseClickData, d) && resetSelectionOnDoubleClick) {\r\n                        setMouseClickData(undefined);\r\n                        onSeriesMouseClick?.(undefined);\r\n                      } else {\r\n                        setMouseClickData(d);\r\n                        onSeriesMouseClick?.(d);\r\n                      }\r\n                    }\r\n                  }}\r\n                  onMouseMove={(event) => {\r\n                    setMouseOverData(d);\r\n                    setEventY(event.clientY);\r\n                    setEventX(event.clientX);\r\n                  }}\r\n                  onMouseLeave={() => {\r\n                    setMouseOverData(undefined);\r\n                    setEventX(undefined);\r\n                    setEventY(undefined);\r\n                    onSeriesMouseOver?.(undefined);\r\n                  }}\r\n                  exit={{ opacity: 0, transition: { duration: animate.duration } }}\r\n                  variants={{\r\n                    initial: {\r\n                      x: x(`${d.id}`),\r\n                      y: 0,\r\n                      opacity: highlightedDataPoints\r\n                        ? highlightedDataPoints.indexOf(d.label) !== -1\r\n                          ? 0.85\r\n                          : dimmedOpacity\r\n                        : 0.85,\r\n                    },\r\n                    whileInView: {\r\n                      x: x(`${d.id}`),\r\n                      y: 0,\r\n                      opacity: highlightedDataPoints\r\n                        ? highlightedDataPoints.indexOf(d.label) !== -1\r\n                          ? 0.85\r\n                          : dimmedOpacity\r\n                        : 0.85,\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.qualitativeRange\r\n                    ? d.qualitativeRange.map((_el, j) => (\r\n                        <motion.rect\r\n                          // biome-ignore lint/suspicious/noArrayIndexKey: index is the unique identifier\r\n                          key={j}\r\n                          x={0}\r\n                          exit={{\r\n                            height: 0,\r\n                            y: y(0),\r\n                            transition: { duration: animate.duration },\r\n                          }}\r\n                          variants={{\r\n                            initial: {\r\n                              height: 0,\r\n                              y: y(0),\r\n                              fill: qualitativeRangeColors[j],\r\n                            },\r\n                            whileInView: {\r\n                              height: Math.abs(\r\n                                y(\r\n                                  sum(\r\n                                    (d.qualitativeRange as number[]).filter(\r\n                                      (element, k) => k <= j && element,\r\n                                    ),\r\n                                  ),\r\n                                ) -\r\n                                  y(\r\n                                    sum(\r\n                                      (d.qualitativeRange as number[]).filter(\r\n                                        (element, k) => k < j && element,\r\n                                      ),\r\n                                    ),\r\n                                  ),\r\n                              ),\r\n                              y: y(\r\n                                sum(\r\n                                  (d.qualitativeRange as number[]).filter(\r\n                                    (element, k) => k <= j && element,\r\n                                  ),\r\n                                ),\r\n                              ),\r\n                              fill: qualitativeRangeColors[j],\r\n                              transition: { duration: animate.duration },\r\n                            },\r\n                          }}\r\n                          initial='initial'\r\n                          animate={isInView ? 'whileInView' : 'initial'}\r\n                          width={x.bandwidth()}\r\n                        />\r\n                      ))\r\n                    : null}\r\n                  {d.target && targetStyle === 'background' ? (\r\n                    <motion.rect\r\n                      x={0}\r\n                      width={x.bandwidth()}\r\n                      exit={{\r\n                        height: 0,\r\n                        y: y(0),\r\n                        fill: targetColor,\r\n                        transition: { duration: animate.duration },\r\n                      }}\r\n                      variants={{\r\n                        initial: {\r\n                          height: 0,\r\n                          fill: targetColor,\r\n                          y: y(0),\r\n                        },\r\n                        whileInView: {\r\n                          height: Math.abs(y(d.target) - y(0)),\r\n                          fill: targetColor,\r\n                          y: d.target > 0 ? y(d.target) : y(0),\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                    />\r\n                  ) : null}\r\n                  {d.size ? (\r\n                    <motion.rect\r\n                      x={x.bandwidth() * ((1 - measureBarWidthFactor) / 2)}\r\n                      width={x.bandwidth() * measureBarWidthFactor}\r\n                      style={{\r\n                        fill: barColor,\r\n                      }}\r\n                      exit={{\r\n                        height: 0,\r\n                        y: y(0),\r\n                        transition: { duration: animate.duration },\r\n                      }}\r\n                      variants={{\r\n                        initial: {\r\n                          height: 0,\r\n                          y: y(0),\r\n                        },\r\n                        whileInView: {\r\n                          height: Math.abs(y(d.size) - y(0)),\r\n                          y: d.size > 0 ? y(d.size) : y(0),\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                    />\r\n                  ) : null}\r\n                  {d.target && targetStyle === 'line' ? (\r\n                    <motion.rect\r\n                      x={0}\r\n                      width={x.bandwidth()}\r\n                      exit={{\r\n                        y: y(0),\r\n                        opacity: 0,\r\n                        fill: targetColor,\r\n                        transition: { duration: animate.duration },\r\n                      }}\r\n                      variants={{\r\n                        initial: {\r\n                          y: y(0),\r\n                          opacity: 0,\r\n                          fill: targetColor,\r\n                        },\r\n                        whileInView: {\r\n                          y: y(d.target) - targetLineThickness / 2,\r\n                          opacity: 1,\r\n                          fill: targetColor,\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                      height={targetLineThickness}\r\n                    />\r\n                  ) : null}\r\n                  {showLabels ? (\r\n                    <XAxesLabels\r\n                      value={\r\n                        `${d.label}`.length < truncateBy\r\n                          ? `${d.label}`\r\n                          : `${`${d.label}`.substring(0, truncateBy)}...`\r\n                      }\r\n                      y={(d.size || 0) < 0 ? 0 : y(0) + 5}\r\n                      x={0}\r\n                      width={x.bandwidth()}\r\n                      height={(d.size || 0) < 0 ? y(0) - 5 : margin.bottom}\r\n                      style={styles?.xAxis?.labels}\r\n                      className={classNames?.xAxis?.labels}\r\n                      alignment={(d.size || 0) < 0 ? 'bottom' : 'top'}\r\n                      animate={animate}\r\n                      isInView={isInView}\r\n                    />\r\n                  ) : null}\r\n                  {showValues ? (\r\n                    <motion.text\r\n                      x={x.bandwidth() / 2}\r\n                      style={{\r\n                        textAnchor: 'middle',\r\n                        ...(styles?.graphObjectValues || {}),\r\n                      }}\r\n                      className={cn('graph-value text-sm', classNames?.graphObjectValues)}\r\n                      dy={d.size ? (d.size >= 0 ? '-5px' : '1em') : '-5px'}\r\n                      exit={{ opacity: 0, transition: { duration: animate.duration } }}\r\n                      variants={{\r\n                        initial: {\r\n                          y: y(0),\r\n                          opacity: 0,\r\n                          fill: valueColor || barColor,\r\n                        },\r\n                        whileInView: {\r\n                          y: y(d.size || 0),\r\n                          opacity: 1,\r\n                          fill: valueColor || barColor,\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                    >\r\n                      {numberFormattingFunction(\r\n                        d.size,\r\n                        naLabel,\r\n                        precision,\r\n                        prefix,\r\n                        suffix,\r\n                        locale,\r\n                        padZeros,\r\n                      )}\r\n                    </motion.text>\r\n                  ) : null}\r\n                </motion.g>\r\n              ) : null,\r\n            )}\r\n            {refValues?.map((el) => (\r\n              <RefLineY\r\n                key={el.text}\r\n                text={el.text}\r\n                color={el.color}\r\n                y={y(el.value as number)}\r\n                x1={0 - leftMargin}\r\n                x2={graphWidth + margin.right}\r\n                classNames={el.classNames}\r\n                styles={el.styles}\r\n                animate={animate}\r\n                isInView={isInView}\r\n              />\r\n            ))}\r\n          </AnimatePresence>\r\n          {customLayers.filter((d) => d.position === 'after').map((d) => d.layer)}\r\n        </g>\r\n      </motion.svg>\r\n      {mouseOverData && tooltip && eventX && eventY ? (\r\n        <Tooltip\r\n          data={mouseOverData}\r\n          body={tooltip}\r\n          xPos={eventX}\r\n          yPos={eventY}\r\n          backgroundStyle={styles?.tooltip}\r\n          className={classNames?.tooltip}\r\n        />\r\n      ) : null}\r\n      {detailsOnClick && mouseClickData !== undefined ? (\r\n        <DetailsModal\r\n          body={detailsOnClick}\r\n          data={mouseClickData}\r\n          setData={setMouseClickData}\r\n          className={classNames?.modal}\r\n        />\r\n      ) : null}\r\n    </>\r\n  );\r\n}\r\n\r\nexport function HorizontalGraph(props: Props) {\r\n  const {\r\n    data,\r\n    topMargin = 25,\r\n    bottomMargin = 10,\r\n    leftMargin = 100,\r\n    rightMargin = 40,\r\n    barColor,\r\n    suffix,\r\n    prefix,\r\n    barPadding,\r\n    showValues,\r\n    showTicks,\r\n    truncateBy,\r\n    width,\r\n    height,\r\n    showLabels,\r\n    tooltip,\r\n    onSeriesMouseOver,\r\n    refValues,\r\n    highlightedDataPoints,\r\n    maxValue,\r\n    minValue,\r\n    onSeriesMouseClick,\r\n    labelOrder,\r\n    rtl,\r\n    maxBarThickness,\r\n    minBarThickness,\r\n    resetSelectionOnDoubleClick,\r\n    detailsOnClick,\r\n    barAxisTitle,\r\n    valueColor,\r\n    noOfTicks,\r\n    styles,\r\n    classNames,\r\n    targetStyle,\r\n    targetColor,\r\n    qualitativeRangeColors,\r\n    measureBarWidthFactor,\r\n    animate,\r\n    dimmedOpacity,\r\n    precision,\r\n    customLayers,\r\n    naLabel,\r\n    targetLineThickness,\r\n    hideAxisLine,\r\n    locale,\r\n    padZeros,\r\n  } = props;\r\n  const svgRef = useRef(null);\r\n  const isInView = useInView(svgRef, {\r\n    once: animate.once,\r\n    amount: animate.amount,\r\n  });\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  const [mouseOverData, setMouseOverData] = useState<any>(undefined);\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  const [mouseClickData, setMouseClickData] = useState<any>(undefined);\r\n  const [eventX, setEventX] = useState<number | undefined>(undefined);\r\n  const [eventY, setEventY] = useState<number | undefined>(undefined);\r\n  const margin = {\r\n    top: barAxisTitle ? topMargin + 25 : topMargin,\r\n    bottom: bottomMargin,\r\n    left: leftMargin,\r\n    right: rightMargin,\r\n  };\r\n  const { graphHeight, graphWidth } = getGraphDimensions({ width, height }, margin);\r\n\r\n  const barMaxValue =\r\n    Math.max(...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number)) <\r\n    0\r\n      ? 0\r\n      : Math.max(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number),\r\n        );\r\n  const targetMaxValue =\r\n    Math.max(\r\n      ...data.filter((d) => !checkIfNullOrUndefined(d.target)).map((d) => d.target as number),\r\n    ) < 0\r\n      ? 0\r\n      : Math.max(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.target)).map((d) => d.target as number),\r\n        );\r\n  const qualitativeRangeMaxValue = Math.max(\r\n    ...data.map(\r\n      (d) => sum((d.qualitativeRange || []).filter((l) => !checkIfNullOrUndefined(l))) || 0,\r\n    ),\r\n  );\r\n  const xMaxValue = !checkIfNullOrUndefined(maxValue)\r\n    ? (maxValue as number)\r\n    : Math.max(...[barMaxValue, targetMaxValue, qualitativeRangeMaxValue].filter(Number.isFinite)) <\r\n        0\r\n      ? 0\r\n      : Math.max(\r\n          ...[barMaxValue, targetMaxValue, qualitativeRangeMaxValue].filter(Number.isFinite),\r\n        );\r\n  const barMinValue =\r\n    Math.min(...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number)) >=\r\n    0\r\n      ? 0\r\n      : Math.min(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.size)).map((d) => d.size as number),\r\n        );\r\n\r\n  const targetMinValue =\r\n    Math.min(\r\n      ...data.filter((d) => !checkIfNullOrUndefined(d.target)).map((d) => d.target as number),\r\n    ) >= 0\r\n      ? 0\r\n      : Math.min(\r\n          ...data.filter((d) => !checkIfNullOrUndefined(d.target)).map((d) => d.target as number),\r\n        );\r\n  const xMinValue = !checkIfNullOrUndefined(minValue)\r\n    ? (minValue as number)\r\n    : Math.min(...[barMinValue, targetMinValue].filter(Number.isFinite)) >= 0\r\n      ? 0\r\n      : Math.min(...[barMinValue, targetMinValue].filter(Number.isFinite));\r\n\r\n  const dataWithId = useMemo(() => {\r\n    const idSet = new Set<string | number>();\r\n\r\n    const dataWithIdWithoutMissingIds = data.map((d, i) => {\r\n      const id = labelOrder ? d.label : `${i}`;\r\n      idSet.add(id);\r\n      return { ...d, id };\r\n    });\r\n\r\n    const missingIds = labelOrder ? labelOrder.filter((id) => !idSet.has(id)) : [];\r\n\r\n    return [\r\n      ...dataWithIdWithoutMissingIds,\r\n      ...missingIds.map((id) => ({\r\n        id,\r\n        label: id,\r\n        size: null,\r\n        target: null,\r\n        qualitativeRange: null,\r\n      })),\r\n    ];\r\n  }, [data, labelOrder]);\r\n\r\n  const barOrder = useMemo(() => {\r\n    return labelOrder ?? dataWithId.map((d) => `${d.id}`);\r\n  }, [labelOrder, dataWithId]);\r\n\r\n  const x = scaleLinear().domain([xMinValue, xMaxValue]).range([0, graphWidth]).nice();\r\n  const y = scaleBand<string | number>()\r\n    .domain(barOrder)\r\n    .range([\r\n      0,\r\n      minBarThickness\r\n        ? Math.max(graphHeight, minBarThickness * barOrder.length)\r\n        : maxBarThickness\r\n          ? Math.min(graphHeight, maxBarThickness * barOrder.length)\r\n          : graphHeight,\r\n    ])\r\n    .paddingInner(barPadding);\r\n  const xTicks = x.ticks(noOfTicks);\r\n\r\n  return (\r\n    <>\r\n      <motion.svg\r\n        width={`${width}px`}\r\n        height={`${height}px`}\r\n        viewBox={`0 0 ${width} ${height}`}\r\n        direction='ltr'\r\n        ref={svgRef}\r\n      >\r\n        <g transform={`translate(${margin.left},${margin.top})`}>\r\n          {showTicks ? (\r\n            <XTicksAndGridLines\r\n              values={xTicks.filter((d) => d !== 0)}\r\n              x={xTicks.filter((d) => d !== 0).map((d) => x(d))}\r\n              y1={0 - topMargin}\r\n              y2={graphHeight + margin.bottom}\r\n              styles={{\r\n                gridLines: styles?.xAxis?.gridLines,\r\n                labels: styles?.xAxis?.labels,\r\n              }}\r\n              classNames={{\r\n                gridLines: classNames?.xAxis?.gridLines,\r\n                labels: classNames?.xAxis?.labels,\r\n              }}\r\n              suffix={suffix}\r\n              prefix={prefix}\r\n              labelType='secondary'\r\n              showGridLines\r\n              precision={precision}\r\n              locale={locale}\r\n              padZeros={padZeros}\r\n            />\r\n          ) : null}\r\n          <AxisTitle\r\n            x={graphWidth / 2}\r\n            y={0 - margin.top + 15}\r\n            style={styles?.xAxis?.title}\r\n            className={classNames?.xAxis?.title}\r\n            text={barAxisTitle}\r\n          />\r\n          <Axis\r\n            hideAxisLine={hideAxisLine}\r\n            x1={x(xMinValue < 0 ? 0 : xMinValue)}\r\n            x2={x(xMinValue < 0 ? 0 : xMinValue)}\r\n            y1={-2.5}\r\n            y2={graphHeight + margin.bottom}\r\n            classNames={{ axis: classNames?.yAxis?.axis }}\r\n            styles={{ axis: styles?.yAxis?.axis }}\r\n          />\r\n          {customLayers.filter((d) => d.position === 'before').map((d) => d.layer)}\r\n          <AnimatePresence>\r\n            {dataWithId.map((d) =>\r\n              !checkIfNullOrUndefined(y(d.id)) ? (\r\n                <motion.g\r\n                  className='undp-viz-g-with-hover'\r\n                  key={d.label}\r\n                  onMouseEnter={(event) => {\r\n                    setMouseOverData(d);\r\n                    setEventY(event.clientY);\r\n                    setEventX(event.clientX);\r\n                    onSeriesMouseOver?.(d);\r\n                  }}\r\n                  onClick={() => {\r\n                    if (onSeriesMouseClick || detailsOnClick) {\r\n                      if (isEqual(mouseClickData, d) && resetSelectionOnDoubleClick) {\r\n                        setMouseClickData(undefined);\r\n                        onSeriesMouseClick?.(undefined);\r\n                      } else {\r\n                        setMouseClickData(d);\r\n                        onSeriesMouseClick?.(d);\r\n                      }\r\n                    }\r\n                  }}\r\n                  onMouseMove={(event) => {\r\n                    setMouseOverData(d);\r\n                    setEventY(event.clientY);\r\n                    setEventX(event.clientX);\r\n                  }}\r\n                  onMouseLeave={() => {\r\n                    setMouseOverData(undefined);\r\n                    setEventX(undefined);\r\n                    setEventY(undefined);\r\n                    onSeriesMouseOver?.(undefined);\r\n                  }}\r\n                  exit={{ opacity: 0, transition: { duration: animate.duration } }}\r\n                  variants={{\r\n                    initial: {\r\n                      x: 0,\r\n                      y: y(`${d.id}`),\r\n                      opacity: highlightedDataPoints\r\n                        ? highlightedDataPoints.indexOf(d.label) !== -1\r\n                          ? 0.85\r\n                          : dimmedOpacity\r\n                        : 0.85,\r\n                    },\r\n                    whileInView: {\r\n                      x: 0,\r\n                      y: y(`${d.id}`),\r\n                      opacity: highlightedDataPoints\r\n                        ? highlightedDataPoints.indexOf(d.label) !== -1\r\n                          ? 0.85\r\n                          : dimmedOpacity\r\n                        : 0.85,\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.qualitativeRange\r\n                    ? d.qualitativeRange.map((el, j) => (\r\n                        <motion.rect\r\n                          // biome-ignore lint/suspicious/noArrayIndexKey: index is the identifier\r\n                          key={j}\r\n                          exit={{\r\n                            width: 0,\r\n                            x: x(0),\r\n                            transition: { duration: animate.duration },\r\n                          }}\r\n                          variants={{\r\n                            initial: {\r\n                              x: x(0),\r\n                              width: 0,\r\n                              fill: qualitativeRangeColors[j],\r\n                            },\r\n                            whileInView: {\r\n                              x: x(\r\n                                j === 0\r\n                                  ? 0\r\n                                  : sum(\r\n                                      (d.qualitativeRange as number[]).filter(\r\n                                        (element, k) => k < j && element,\r\n                                      ),\r\n                                    ),\r\n                              ),\r\n                              width: x(el),\r\n                              fill: qualitativeRangeColors[j],\r\n                              transition: { duration: animate.duration },\r\n                            },\r\n                          }}\r\n                          initial='initial'\r\n                          animate={isInView ? 'whileInView' : 'initial'}\r\n                          y={0}\r\n                          height={y.bandwidth()}\r\n                        />\r\n                      ))\r\n                    : null}\r\n                  {d.target && targetStyle === 'background' ? (\r\n                    <motion.rect\r\n                      y={0}\r\n                      x={d.target >= 0 ? x(0) : x(d.target)}\r\n                      height={y.bandwidth()}\r\n                      exit={{\r\n                        width: 0,\r\n                        x: x(0),\r\n                        fill: targetColor,\r\n                        transition: { duration: animate.duration },\r\n                      }}\r\n                      variants={{\r\n                        initial: {\r\n                          x: x(0),\r\n                          fill: targetColor,\r\n                          width: 0,\r\n                        },\r\n                        whileInView: {\r\n                          x: d.target >= 0 ? x(0) : x(d.target),\r\n                          fill: targetColor,\r\n                          width: d.target >= 0 ? x(d.target) - x(0) : x(0) - x(d.target),\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                    />\r\n                  ) : null}\r\n                  {d.size ? (\r\n                    <motion.rect\r\n                      y={y.bandwidth() * ((1 - measureBarWidthFactor) / 2)}\r\n                      style={{\r\n                        fill: barColor,\r\n                      }}\r\n                      height={y.bandwidth() * measureBarWidthFactor}\r\n                      exit={{\r\n                        width: 0,\r\n                        x: x(0),\r\n                        transition: { duration: animate.duration },\r\n                      }}\r\n                      variants={{\r\n                        initial: {\r\n                          x: x(0),\r\n                          width: 0,\r\n                        },\r\n                        whileInView: {\r\n                          x: d.size >= 0 ? x(0) : x(d.size),\r\n                          width: d.size >= 0 ? x(d.size) - x(0) : x(0) - x(d.size),\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                    />\r\n                  ) : null}\r\n                  {d.target && targetStyle === 'line' ? (\r\n                    <motion.rect\r\n                      y={0}\r\n                      height={y.bandwidth()}\r\n                      width={targetLineThickness}\r\n                      exit={{\r\n                        opacity: 0,\r\n                        x: x(0),\r\n                        fill: targetColor,\r\n                        transition: { duration: animate.duration },\r\n                      }}\r\n                      variants={{\r\n                        initial: {\r\n                          x: x(0),\r\n                          opacity: 0,\r\n                          fill: targetColor,\r\n                        },\r\n                        whileInView: {\r\n                          x: x(d.target) - targetLineThickness / 2,\r\n                          opacity: 1,\r\n                          fill: targetColor,\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                    />\r\n                  ) : null}\r\n                  {showLabels ? (\r\n                    <YAxesLabels\r\n                      value={\r\n                        `${d.label}`.length < truncateBy\r\n                          ? `${d.label}`\r\n                          : `${`${d.label}`.substring(0, truncateBy)}...`\r\n                      }\r\n                      y={0}\r\n                      x={(d.size || 0) < 0 ? x(0) : 0 - margin.left}\r\n                      width={(d.size || 0) < 0 ? width - x(0) : x(0) + margin.left}\r\n                      height={y.bandwidth()}\r\n                      alignment={d.size ? (d.size < 0 ? 'left' : 'right') : 'right'}\r\n                      style={styles?.yAxis?.labels}\r\n                      className={classNames?.yAxis?.labels}\r\n                      animate={animate}\r\n                      isInView={isInView}\r\n                    />\r\n                  ) : null}\r\n                  {showValues ? (\r\n                    <motion.text\r\n                      y={y.bandwidth() / 2}\r\n                      style={{\r\n                        textAnchor: d.size ? (d.size < 0 ? 'end' : 'start') : 'start',\r\n                        ...(styles?.graphObjectValues || {}),\r\n                      }}\r\n                      className={cn('graph-value text-sm', classNames?.graphObjectValues)}\r\n                      dx={d.size ? (d.size < 0 ? -5 : 5) : 5}\r\n                      dy='0.33em'\r\n                      exit={{ opacity: 0, transition: { duration: animate.duration } }}\r\n                      variants={{\r\n                        initial: {\r\n                          x: x(0),\r\n                          opacity: 0,\r\n                          fill: valueColor || barColor,\r\n                        },\r\n                        whileInView: {\r\n                          x: d.size ? x(d.size) : x(0),\r\n                          opacity: 1,\r\n                          fill: valueColor || barColor,\r\n                          transition: { duration: animate.duration },\r\n                        },\r\n                      }}\r\n                      initial='initial'\r\n                      animate={isInView ? 'whileInView' : 'initial'}\r\n                    >\r\n                      {numberFormattingFunction(\r\n                        d.size,\r\n                        naLabel,\r\n                        precision,\r\n                        prefix,\r\n                        suffix,\r\n                        locale,\r\n                        padZeros,\r\n                      )}\r\n                    </motion.text>\r\n                  ) : null}\r\n                </motion.g>\r\n              ) : null,\r\n            )}\r\n            {refValues?.map((el) => (\r\n              <RefLineX\r\n                key={el.text}\r\n                text={el.text}\r\n                color={el.color}\r\n                x={x(el.value as number)}\r\n                y1={0 - margin.top}\r\n                y2={graphHeight + margin.bottom}\r\n                textSide={x(el.value as number) > graphWidth * 0.75 || rtl ? 'left' : 'right'}\r\n                classNames={el.classNames}\r\n                styles={el.styles}\r\n                animate={animate}\r\n                isInView={isInView}\r\n              />\r\n            ))}\r\n          </AnimatePresence>\r\n          {customLayers.filter((d) => d.position === 'after').map((d) => d.layer)}\r\n        </g>\r\n      </motion.svg>\r\n      {mouseOverData && tooltip && eventX && eventY ? (\r\n        <Tooltip\r\n          data={mouseOverData}\r\n          body={tooltip}\r\n          xPos={eventX}\r\n          yPos={eventY}\r\n          backgroundStyle={styles?.tooltip}\r\n          className={classNames?.tooltip}\r\n        />\r\n      ) : null}\r\n      {detailsOnClick && mouseClickData !== undefined ? (\r\n        <DetailsModal\r\n          body={detailsOnClick}\r\n          data={mouseClickData}\r\n          setData={setMouseClickData}\r\n          className={classNames?.modal}\r\n        />\r\n      ) : null}\r\n    </>\r\n  );\r\n}\r\n","import orderBy from 'lodash.orderby';\r\nimport { useRef } from 'react';\r\nimport { Colors } from '@/Components/ColorPalette';\r\nimport { ColorLegend } from '@/Components/Elements/ColorLegend';\r\nimport { EmptyState } from '@/Components/Elements/EmptyState';\r\nimport { GraphArea, GraphContainer } from '@/Components/Elements/GraphContainer';\r\nimport { GraphFooter } from '@/Components/Elements/GraphFooter';\r\nimport { GraphHeader } from '@/Components/Elements/GraphHeader';\r\nimport { Timeline } from '@/Components/Elements/Timeline';\r\nimport { useElementSize } from '@/hooks/useElementSize';\r\nimport { useTimeline } from '@/hooks/useTimeline';\r\nimport type {\r\n  AnimateDataType,\r\n  BulletChartDataType,\r\n  ClassNameObject,\r\n  CustomLayerDataType,\r\n  Languages,\r\n  NumberFormatOptions,\r\n  ReferenceDataType,\r\n  SourcesDataType,\r\n  StyleObject,\r\n  TimelineDataType,\r\n} from '@/Types';\r\nimport { checkIfNullOrUndefined } from '@/Utils/checkIfNullOrUndefined';\r\nimport { ensureCompleteDataForBulletChart } from '@/Utils/ensureCompleteData';\r\nimport { HorizontalGraph, VerticalGraph } from './Graph';\r\n\r\ninterface Props {\r\n  // Data\r\n  /** Array of data objects */\r\n  data: BulletChartDataType[];\r\n\r\n  /** Orientation of the graph */\r\n  orientation?: 'vertical' | 'horizontal';\r\n\r\n  // Titles, Labels, and Sources\r\n  /** Title of the graph */\r\n  graphTitle?: string | React.ReactNode;\r\n  /** Description of the graph */\r\n  graphDescription?: string | React.ReactNode;\r\n  /** Footnote for the graph */\r\n  footNote?: string | React.ReactNode;\r\n  /** Source data for the graph */\r\n  sources?: SourcesDataType[];\r\n  /** Accessibility label */\r\n  ariaLabel?: string;\r\n\r\n  // Colors and Styling\r\n  /** Color for bars */\r\n  barColor?: string;\r\n  /** Domain of colors for the qualitative range bars */\r\n  colorDomain?: string[];\r\n  /** Colors for the qualitative range bars */\r\n  qualitativeRangeColors?: string[];\r\n  /** Title for the color legend */\r\n  colorLegendTitle?: string;\r\n  /** Color of value labels */\r\n  valueColor?: string;\r\n  /** Background color of the graph */\r\n  backgroundColor?: string | boolean;\r\n  /** Custom styles for the graph. Each object should be a valid React CSS style object. */\r\n  styles?: StyleObject;\r\n  /** Custom class names */\r\n  classNames?: ClassNameObject;\r\n\r\n  // Size and Spacing\r\n  /** Width of the graph */\r\n  width?: number;\r\n  /** Height of the graph */\r\n  height?: number;\r\n  /** Minimum height of the graph */\r\n  minHeight?: number;\r\n  /** Relative height scaling factor. This overwrites the height props */\r\n  relativeHeight?: number;\r\n  /** Padding around the graph. Defaults to 0 if no backgroundColor is mentioned else defaults to 1rem */\r\n  padding?: string;\r\n  /** Left margin of the graph */\r\n  leftMargin?: number;\r\n  /** Right margin of the graph */\r\n  rightMargin?: number;\r\n  /** Top margin of the graph */\r\n  topMargin?: number;\r\n  /** Bottom margin of the graph */\r\n  bottomMargin?: number;\r\n  /** Padding between bars */\r\n  barPadding?: number;\r\n  /** Maximum thickness of bars */\r\n  maxBarThickness?: number;\r\n  /** Minimum thickness of bars */\r\n  minBarThickness?: number;\r\n  /** Maximum number of bars shown in the graph */\r\n  maxNumberOfBars?: number;\r\n\r\n  // Values and Ticks\r\n  /** Prefix for values */\r\n  prefix?: string;\r\n  /** Suffix for values */\r\n  suffix?: string;\r\n  /** Maximum value for the chart */\r\n  maxValue?: number;\r\n  /** Minimum value for the chart */\r\n  minValue?: number;\r\n  /** Truncate labels by specified length */\r\n  truncateBy?: number;\r\n  /** Reference values for comparison */\r\n  refValues?: ReferenceDataType[];\r\n  /** Number of ticks on the axis */\r\n  noOfTicks?: number;\r\n\r\n  // Graph Parameters\r\n  /** Toggle visibility of labels */\r\n  showLabels?: boolean;\r\n  /** Toggle visibility of values */\r\n  showValues?: boolean;\r\n  /** Defines the style of the target bar */\r\n  targetStyle?: 'background' | 'line';\r\n  /** Defines the color of the target bar */\r\n  targetColor?: string;\r\n  /** Defines the thickness if the target is of style line */\r\n  targetLineThickness?: number;\r\n  /** Defines the width of the measure bar in relation with available width */\r\n  measureBarWidthFactor?: number;\r\n  /** Custom order for labels */\r\n  labelOrder?: (string | number)[];\r\n  /** Toggle visibility of axis ticks */\r\n  showTicks?: boolean;\r\n  /** Toggle visibility of axis line for the  main axis */\r\n  hideAxisLine?: boolean;\r\n  /** Toggle visibility of color scale. This is only applicable if the data props hae color parameter */\r\n  showColorScale?: boolean;\r\n  /** Configuration options for controlling number formatting, localization, prefixes/suffixes, precision, and zero padding. */\r\n  numberDisplayOptions?: Omit<NumberFormatOptions, 'suffix' | 'prefix'>;\r\n  /** Data points to highlight. Use the label value from data to highlight the data point */\r\n  highlightedDataPoints?: (string | number)[];\r\n  /** Defines the opacity of the non-highlighted data */\r\n  dimmedOpacity?: number;\r\n  /** Defines how “NA” values should be displayed/labelled in the graph */\r\n  naLabel?: string;\r\n  /** Title for the bar axis */\r\n  barAxisTitle?: string;\r\n  /** Sorting order for data. This is overwritten by labelOrder prop. */\r\n  sortData?: 'asc' | 'desc';\r\n  /** Toggles if data point which are undefined or has value null are filtered out.  */\r\n  filterNA?: boolean;\r\n  /** Toggles if the graph animates in when loaded.  */\r\n  animate?: boolean | AnimateDataType;\r\n  /** Configures playback and slider controls for animating the chart over time. The data must have a key date for it to work properly. */\r\n  timeline?: TimelineDataType;\r\n  /** Optional SVG <g> element or function that renders custom content behind or in front of the graph. */\r\n  customLayers?: CustomLayerDataType[];\r\n  /** Enable graph download option as png */\r\n  graphDownload?: boolean;\r\n  /** Enable data download option as a csv */\r\n  dataDownload?: boolean;\r\n  /** Reset selection on double-click. Only applicable when used in a dashboard context with filters. */\r\n  resetSelectionOnDoubleClick?: boolean;\r\n\r\n  // Interactions and Callbacks\r\n  /** Tooltip content. If the type is string then this uses the [handlebar](../?path=/docs/misc-handlebars-templates-and-custom-helpers--docs) template to display the data */\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  tooltip?: string | ((_d: any) => React.ReactNode);\r\n  /** Details displayed on the modal when user clicks of a data point. If the type is string then this uses the [handlebar](../?path=/docs/misc-handlebars-templates-and-custom-helpers--docs) template to display the data */\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  detailsOnClick?: string | ((_d: any) => React.ReactNode);\r\n  /** Callback for mouse over event */\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  onSeriesMouseOver?: (_d: any) => void;\r\n  /** Callback for mouse click event */\r\n  // biome-ignore lint/suspicious/noExplicitAny: undefined data type\r\n  onSeriesMouseClick?: (_d: any) => void;\r\n\r\n  // Configuration and Options\r\n  /** Language setting  */\r\n  language?: Languages;\r\n  /** Color theme */\r\n  theme?: 'light' | 'dark';\r\n  /** Unique ID for the graph */\r\n  graphID?: string;\r\n}\r\n\r\nexport function BulletChart(props: Props) {\r\n  const {\r\n    data,\r\n    graphTitle,\r\n    barColor = Colors.primaryColors['blue-600'],\r\n    barPadding = 0.25,\r\n    showTicks = true,\r\n    leftMargin,\r\n    rightMargin,\r\n    topMargin,\r\n    bottomMargin,\r\n    truncateBy = 999,\r\n    showLabels = true,\r\n    showValues = true,\r\n    backgroundColor = false,\r\n    suffix = '',\r\n    prefix = '',\r\n    sources,\r\n    graphDescription,\r\n    height,\r\n    width,\r\n    footNote,\r\n    colorDomain,\r\n    colorLegendTitle,\r\n    padding,\r\n    relativeHeight,\r\n    tooltip,\r\n    onSeriesMouseOver,\r\n    refValues,\r\n    showColorScale = true,\r\n    graphID,\r\n    maxValue,\r\n    minValue,\r\n    highlightedDataPoints,\r\n    onSeriesMouseClick,\r\n    valueColor,\r\n    orientation = 'vertical',\r\n    styles,\r\n    classNames,\r\n    qualitativeRangeColors,\r\n    targetColor = Colors.light.grays['gray-700'],\r\n    filterNA = true,\r\n    targetStyle = 'line',\r\n    measureBarWidthFactor = 0.4,\r\n    animate = false,\r\n    dimmedOpacity = 0.3,\r\n    customLayers = [],\r\n    naLabel = 'NA',\r\n    graphDownload = false,\r\n    dataDownload = false,\r\n    language = 'en',\r\n    theme = 'light',\r\n    sortData,\r\n    labelOrder,\r\n    minHeight = 0,\r\n    maxBarThickness,\r\n    maxNumberOfBars,\r\n    minBarThickness,\r\n    ariaLabel,\r\n    resetSelectionOnDoubleClick = true,\r\n    detailsOnClick,\r\n    barAxisTitle,\r\n    noOfTicks = 5,\r\n    targetLineThickness = 2,\r\n    timeline = { enabled: false, autoplay: false, showOnlyActiveDate: true },\r\n    hideAxisLine = false,\r\n    numberDisplayOptions,\r\n  } = props;\r\n\r\n  const { graphDiv, svgWidth, svgHeight } = useElementSize<HTMLDivElement>();\r\n  const { uniqDatesSorted, index, setIndex, play, setPlay, markObj, activeDate, dateFormat } =\r\n    useTimeline(data, timeline);\r\n  const graphParentDiv = useRef<HTMLDivElement>(null);\r\n  const Comp = orientation === 'horizontal' ? HorizontalGraph : VerticalGraph;\r\n  return (\r\n    <GraphContainer\r\n      className={classNames?.graphContainer}\r\n      style={styles?.graphContainer}\r\n      id={graphID}\r\n      ref={graphParentDiv}\r\n      aria-label={ariaLabel}\r\n      backgroundColor={backgroundColor}\r\n      theme={theme}\r\n      language={language}\r\n      minHeight={minHeight}\r\n      width={width}\r\n      height={height}\r\n      relativeHeight={relativeHeight}\r\n      padding={padding}\r\n    >\r\n      {graphTitle || graphDescription || graphDownload || dataDownload ? (\r\n        <GraphHeader\r\n          styles={{\r\n            title: styles?.title,\r\n            description: styles?.description,\r\n          }}\r\n          classNames={{\r\n            title: classNames?.title,\r\n            description: classNames?.description,\r\n          }}\r\n          graphTitle={graphTitle}\r\n          graphDescription={graphDescription}\r\n          width={width}\r\n          graphDownload={graphDownload ? graphParentDiv : undefined}\r\n          dataDownload={\r\n            dataDownload\r\n              ? data.map((d) => d.data).filter((d) => d !== undefined).length > 0\r\n                ? data.map((d) => d.data).filter((d) => d !== undefined)\r\n                : data.filter((d) => d !== undefined)\r\n              : null\r\n          }\r\n        />\r\n      ) : null}\r\n      {timeline.enabled && uniqDatesSorted.length > 0 && markObj ? (\r\n        <Timeline\r\n          play={play}\r\n          setPlay={setPlay}\r\n          uniqDatesSorted={uniqDatesSorted}\r\n          markObj={markObj}\r\n          index={index}\r\n          setIndex={setIndex}\r\n          color={timeline.color}\r\n        />\r\n      ) : null}\r\n      {showColorScale &&\r\n      data.filter((el) => el.qualitativeRange).length !== 0 &&\r\n      colorDomain &&\r\n      data.length > 0 ? (\r\n        <ColorLegend\r\n          width={width}\r\n          colorLegendTitle={colorLegendTitle}\r\n          colors={qualitativeRangeColors || Colors[theme].sequentialColors.positiveColorsx10}\r\n          colorDomain={colorDomain}\r\n          showNAColor={false}\r\n          className={classNames?.colorLegend}\r\n        />\r\n      ) : null}\r\n      <GraphArea ref={graphDiv}>\r\n        {data.length === 0 && <EmptyState />}\r\n        {svgWidth && svgHeight && data.length > 0 ? (\r\n          <Comp\r\n            hideAxisLine={hideAxisLine}\r\n            data={\r\n              sortData\r\n                ? orderBy(\r\n                    ensureCompleteDataForBulletChart(data, dateFormat)\r\n                      .filter((d) => (timeline.enabled ? `${d.date}` === activeDate : d))\r\n                      .filter((d) => (filterNA ? !checkIfNullOrUndefined(d.size) : d)),\r\n                    [\r\n                      (d) =>\r\n                        d.size === undefined\r\n                          ? sortData === 'asc'\r\n                            ? (orientation === 'horizontal' ? 1 : -1) * Infinity\r\n                            : (orientation === 'horizontal' ? -1 : 1) * Infinity\r\n                          : d.size,\r\n                    ],\r\n                    [sortData],\r\n                  ).filter((_d, i) => (maxNumberOfBars ? i < maxNumberOfBars : true))\r\n                : ensureCompleteDataForBulletChart(data, dateFormat)\r\n                    .filter((d) => (timeline.enabled ? `${d.date}` === activeDate : d))\r\n                    .filter((d) => (filterNA ? !checkIfNullOrUndefined(d.size) : d))\r\n                    .filter((_d, i) => (maxNumberOfBars ? i < maxNumberOfBars : true))\r\n            }\r\n            barColor={barColor}\r\n            targetColor={targetColor}\r\n            width={svgWidth}\r\n            refValues={refValues}\r\n            height={svgHeight}\r\n            suffix={suffix}\r\n            prefix={prefix}\r\n            barPadding={barPadding}\r\n            showLabels={showLabels}\r\n            showValues={showValues}\r\n            showTicks={showTicks}\r\n            truncateBy={truncateBy}\r\n            leftMargin={leftMargin}\r\n            rightMargin={rightMargin}\r\n            qualitativeRangeColors={\r\n              qualitativeRangeColors || Colors[theme].sequentialColors.positiveColorsx10\r\n            }\r\n            topMargin={topMargin}\r\n            bottomMargin={bottomMargin}\r\n            tooltip={tooltip}\r\n            onSeriesMouseOver={onSeriesMouseOver}\r\n            maxValue={maxValue}\r\n            minValue={minValue}\r\n            highlightedDataPoints={highlightedDataPoints}\r\n            onSeriesMouseClick={onSeriesMouseClick}\r\n            labelOrder={labelOrder}\r\n            maxBarThickness={maxBarThickness}\r\n            minBarThickness={minBarThickness}\r\n            resetSelectionOnDoubleClick={resetSelectionOnDoubleClick}\r\n            detailsOnClick={detailsOnClick}\r\n            barAxisTitle={barAxisTitle}\r\n            noOfTicks={noOfTicks}\r\n            valueColor={valueColor}\r\n            styles={styles}\r\n            classNames={classNames}\r\n            targetStyle={targetStyle}\r\n            dimmedOpacity={dimmedOpacity}\r\n            measureBarWidthFactor={measureBarWidthFactor}\r\n            animate={\r\n              animate === true\r\n                ? { duration: 0.5, once: true, amount: 0.5 }\r\n                : animate || { duration: 0, once: true, amount: 0 }\r\n            }\r\n            customLayers={customLayers}\r\n            naLabel={naLabel}\r\n            targetLineThickness={targetLineThickness}\r\n            rtl={language === 'ar' || language === 'he'}\r\n            locale={numberDisplayOptions?.locale || 'en'}\r\n            padZeros={numberDisplayOptions?.padZeros || 'none'}\r\n            precision={numberDisplayOptions?.precision ?? 2}\r\n          />\r\n        ) : null}\r\n      </GraphArea>\r\n      {sources || footNote ? (\r\n        <GraphFooter\r\n          styles={{ footnote: styles?.footnote, source: styles?.source }}\r\n          classNames={{\r\n            footnote: classNames?.footnote,\r\n            source: classNames?.source,\r\n          }}\r\n          sources={sources}\r\n          footNote={footNote}\r\n          width={width}\r\n        />\r\n      ) : null}\r\n    </GraphContainer>\r\n  );\r\n}\r\n"],"mappings":"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"}