@undp/data-viz 1.5.7 → 1.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BarGraph.cjs +1 -1
- package/dist/BarGraph.cjs.map +1 -1
- package/dist/BarGraph.js +650 -648
- package/dist/BarGraph.js.map +1 -1
- package/dist/BulletChart.cjs +1 -1
- package/dist/BulletChart.cjs.map +1 -1
- package/dist/BulletChart.js +210 -208
- package/dist/BulletChart.js.map +1 -1
- package/dist/ButterflyChart.cjs +1 -1
- package/dist/ButterflyChart.cjs.map +1 -1
- package/dist/ButterflyChart.js +42 -40
- package/dist/ButterflyChart.js.map +1 -1
- package/dist/DifferenceLineChart.cjs +1 -1
- package/dist/DifferenceLineChart.cjs.map +1 -1
- package/dist/DifferenceLineChart.js +122 -120
- package/dist/DifferenceLineChart.js.map +1 -1
- package/dist/DualAxisLineChart.cjs +1 -1
- package/dist/DualAxisLineChart.cjs.map +1 -1
- package/dist/DualAxisLineChart.js +133 -113
- package/dist/DualAxisLineChart.js.map +1 -1
- package/dist/DumbbellChart.cjs +1 -1
- package/dist/DumbbellChart.cjs.map +1 -1
- package/dist/DumbbellChart.js +274 -274
- package/dist/DumbbellChart.js.map +1 -1
- package/dist/LineChartWithConfidenceInterval.cjs +1 -1
- package/dist/LineChartWithConfidenceInterval.cjs.map +1 -1
- package/dist/LineChartWithConfidenceInterval.js +194 -174
- package/dist/LineChartWithConfidenceInterval.js.map +1 -1
- package/dist/MultiLineAltChart.cjs +1 -1
- package/dist/MultiLineAltChart.cjs.map +1 -1
- package/dist/MultiLineAltChart.js +160 -161
- package/dist/MultiLineAltChart.js.map +1 -1
- package/dist/MultiLineChart.cjs +1 -1
- package/dist/MultiLineChart.cjs.map +1 -1
- package/dist/MultiLineChart.js +77 -66
- package/dist/MultiLineChart.js.map +1 -1
- package/dist/ParetoChart.cjs +1 -1
- package/dist/ParetoChart.cjs.map +1 -1
- package/dist/ParetoChart.js +166 -161
- package/dist/ParetoChart.js.map +1 -1
- package/dist/RadarChart.cjs +1 -1
- package/dist/RadarChart.cjs.map +1 -1
- package/dist/RadarChart.js +253 -241
- package/dist/RadarChart.js.map +1 -1
- package/dist/{RegressionLine-mH7UKOPi.js → RegressionLine-C2--oMQq.js} +10 -9
- package/dist/RegressionLine-C2--oMQq.js.map +1 -0
- package/dist/RegressionLine-Dj0GSiAp.cjs +2 -0
- package/dist/RegressionLine-Dj0GSiAp.cjs.map +1 -0
- package/dist/ScatterPlot.cjs +1 -1
- package/dist/ScatterPlot.cjs.map +1 -1
- package/dist/ScatterPlot.js +130 -129
- package/dist/ScatterPlot.js.map +1 -1
- package/dist/SimpleLineChart.cjs +1 -1
- package/dist/SimpleLineChart.cjs.map +1 -1
- package/dist/SimpleLineChart.js +43 -38
- package/dist/SimpleLineChart.js.map +1 -1
- package/dist/SlopeChart.cjs +1 -1
- package/dist/SlopeChart.cjs.map +1 -1
- package/dist/SlopeChart.js +113 -109
- package/dist/SlopeChart.js.map +1 -1
- package/dist/StripChart.cjs +1 -1
- package/dist/StripChart.cjs.map +1 -1
- package/dist/StripChart.js +282 -270
- package/dist/StripChart.js.map +1 -1
- package/dist/UnitChart.cjs +1 -1
- package/dist/UnitChart.cjs.map +1 -1
- package/dist/UnitChart.js +20 -21
- package/dist/UnitChart.js.map +1 -1
- package/dist/getCentroidCoordinates-Dfk6IqEG.js.map +1 -1
- package/dist/getCentroidCoordinates-DxTBqzp2.cjs.map +1 -1
- package/package.json +1 -1
- package/dist/RegressionLine-mH7UKOPi.js.map +0 -1
- package/dist/RegressionLine-xKdiJ8sw.cjs +0 -2
- package/dist/RegressionLine-xKdiJ8sw.cjs.map +0 -1
package/dist/UnitChart.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitChart.cjs","sources":["../src/Components/Graphs/UnitChart/index.tsx"],"sourcesContent":["import { useRef } from 'react';\r\nimport sum from 'lodash.sum';\r\nimport { H2, P } from '@undp/design-system-react/Typography';\r\nimport { AnimatePresence, motion, useInView } from 'motion/react';\r\nimport { cn } from '@undp/design-system-react/cn';\r\n\r\nimport { GraphFooter } from '@/Components/Elements/GraphFooter';\r\nimport { GraphHeader } from '@/Components/Elements/GraphHeader';\r\nimport { Colors } from '@/Components/ColorPalette';\r\nimport {\r\n UnitChartDataType,\r\n SourcesDataType,\r\n Languages,\r\n StyleObject,\r\n ClassNameObject,\r\n AnimateDataType,\r\n} from '@/Types';\r\nimport { numberFormattingFunction } from '@/Utils/numberFormattingFunction';\r\n\r\ninterface Props {\r\n // Data\r\n /** Array of data objects */\r\n data: UnitChartDataType[];\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 /** Note with h2 tag just above the graph. Can be used to highlight text */\r\n note?: string;\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 /** Colors of the highlighted circles */\r\n colors?: 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\r\n // Graph Parameters\r\n /** Size of the visualization */\r\n size?: number;\r\n /** No. of dots in a single row */\r\n gridSize?: number;\r\n /** Spacing between 2 dots */\r\n unitPadding?: number;\r\n /** Total no. of dot that are rendered in the chart */\r\n totalNoOfDots?: number;\r\n /** Toggle visibility of stroke for the unfilled dots */\r\n showStrokeForWhiteDots?: boolean;\r\n /** Toggles if the graph animates in when loaded. */\r\n animate?: boolean | AnimateDataType;\r\n /** Toggle visibility of color scale */\r\n showColorScale?: boolean;\r\n /** Specifies the number of decimal places to display in the value. */\r\n precision?: number;\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\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 UnitChart(props: Props) {\r\n const {\r\n data,\r\n size = 200,\r\n graphTitle,\r\n sources,\r\n colors = Colors.light.categoricalColors.colors,\r\n graphDescription,\r\n totalNoOfDots = 100,\r\n unitPadding = 3,\r\n gridSize = 10,\r\n footNote,\r\n padding,\r\n backgroundColor = false,\r\n graphID,\r\n graphDownload = false,\r\n language = 'en',\r\n showColorScale = true,\r\n showStrokeForWhiteDots = true,\r\n note,\r\n dataDownload = false,\r\n theme = 'light',\r\n width,\r\n height,\r\n minHeight = 0,\r\n relativeHeight,\r\n ariaLabel,\r\n styles,\r\n classNames,\r\n animate = false,\r\n precision = 2,\r\n } = props;\r\n const svgRef = useRef(null);\r\n const animateValue =\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 const isInView = useInView(svgRef, {\r\n once: animateValue.once,\r\n amount: animateValue.amount,\r\n });\r\n const totalValue = sum(data.map(d => d.value));\r\n const graphParentDiv = useRef<HTMLDivElement>(null);\r\n const gridDimension = size / gridSize;\r\n const radius = (gridDimension - unitPadding * 2) / 2;\r\n if (radius <= 0) {\r\n console.error(\r\n 'The size of single unit is less than or equal to zero. Check values for ((dimension / gridSize) - (padding * 2)) / 2 is not less than or equal to 0.',\r\n );\r\n return null;\r\n }\r\n\r\n const cellsData: { color: string }[] = [];\r\n data.forEach((item, index) => {\r\n const count = Math.round((item.value / totalValue) * totalNoOfDots);\r\n for (let i = 0; i < count; i += 1) {\r\n cellsData.push({ color: colors[index] });\r\n }\r\n });\r\n return (\r\n <div\r\n className={`${theme || 'light'} flex ${width ? 'w-fit grow-0' : 'w-full grow'}`}\r\n dir={language === 'he' || language === 'ar' ? 'rtl' : undefined}\r\n >\r\n <div\r\n className={cn(\r\n `${\r\n !backgroundColor\r\n ? 'bg-transparent '\r\n : backgroundColor === true\r\n ? 'bg-primary-gray-200 dark:bg-primary-gray-650 '\r\n : ''\r\n }ml-auto mr-auto flex flex-col grow h-inherit ${language || 'en'}`,\r\n width ? 'w-fit' : 'w-full',\r\n classNames?.graphContainer,\r\n )}\r\n style={{\r\n ...(styles?.graphContainer || {}),\r\n minHeight: 'inherit',\r\n ...(backgroundColor && backgroundColor !== true ? { backgroundColor } : {}),\r\n }}\r\n id={graphID}\r\n ref={graphParentDiv}\r\n aria-label={\r\n ariaLabel ||\r\n `${graphTitle ? `The graph shows ${graphTitle}. ` : ''}${\r\n graphDescription ? ` ${graphDescription}` : ''\r\n }`\r\n }\r\n >\r\n <div\r\n className='flex grow'\r\n style={{ padding: backgroundColor ? padding || '1rem' : padding || 0 }}\r\n >\r\n <div className='flex flex-col gap-3 w-full grow'>\r\n {graphTitle || graphDescription || graphDownload ? (\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.current : 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 {note ? (\r\n <H2\r\n marginBottom='2xs'\r\n className='text-primary-gray-700 dark:text-primary-gray-100 font-bold'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n >\r\n {note}\r\n </H2>\r\n ) : null}\r\n <div className='flex grow flex-col gap-4 justify-between'>\r\n <div>\r\n {showColorScale ? (\r\n <div\r\n className='mb-4 leading-0'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n aria-label='Color legend'\r\n >\r\n <div className='flex mb-0 flex-wrap gap-x-4 gap-y-1'>\r\n {data.map((d, i) => (\r\n <div className='flex gap-2 items-center' key={i}>\r\n <div\r\n className='w-3 h-3 rounded-full'\r\n style={{ backgroundColor: colors[i] }}\r\n />\r\n <P\r\n marginBottom='none'\r\n size='sm'\r\n className='text-primary-gray-700 dark:text-primary-gray-100'\r\n >\r\n {d.label}:{' '}\r\n <span className='font-bold'>\r\n {numberFormattingFunction(d.value, 'NA', precision)}\r\n </span>\r\n </P>\r\n </div>\r\n ))}\r\n </div>\r\n </div>\r\n ) : null}\r\n <div aria-label='Graph area'>\r\n <svg\r\n width={`${width || size}px`}\r\n height={`${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}px`}\r\n ref={svgRef}\r\n direction='ltr'\r\n viewBox={`0 0 ${width || size} ${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}`}\r\n >\r\n <AnimatePresence>\r\n <g>\r\n {cellsData.map((d, i) => (\r\n <motion.circle\r\n key={i}\r\n cx={(i % gridSize) * gridDimension + gridDimension / 2}\r\n cy={Math.floor(i / gridSize) * gridDimension + gridDimension / 2}\r\n style={{\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n }}\r\n variants={{\r\n initial: {\r\n fill: '#fff',\r\n opacity: 0,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n },\r\n whileInView: {\r\n fill: d.color,\r\n opacity: 1,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n transition: {\r\n duration: 0,\r\n delay: (animateValue.duration / cellsData.length) * i,\r\n },\r\n },\r\n }}\r\n initial='initial'\r\n animate={isInView ? 'whileInView' : 'initial'}\r\n className={\r\n (d.color.toLowerCase() === '#fff' ||\r\n d.color.toLowerCase() === '#ffffff' ||\r\n d.color.toLowerCase() === 'white') &&\r\n showStrokeForWhiteDots\r\n ? 'stroke-primary-gray-400 dark:stroke-primary-gray-500'\r\n : ''\r\n }\r\n r={radius}\r\n />\r\n ))}\r\n </g>\r\n </AnimatePresence>\r\n </svg>\r\n </div>\r\n </div>\r\n {sources || footNote ? (\r\n <GraphFooter\r\n styles={{\r\n footnote: styles?.footnote,\r\n source: styles?.source,\r\n }}\r\n sources={sources}\r\n footNote={footNote}\r\n width={width}\r\n />\r\n ) : null}\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n}\r\n"],"names":["UnitChart","props","data","size","graphTitle","sources","colors","Colors","graphDescription","totalNoOfDots","unitPadding","gridSize","footNote","padding","backgroundColor","graphID","graphDownload","language","showColorScale","showStrokeForWhiteDots","note","dataDownload","theme","width","height","minHeight","relativeHeight","ariaLabel","styles","classNames","animate","precision","svgRef","useRef","animateValue","isInView","useInView","totalValue","sum","d","graphParentDiv","gridDimension","radius","cellsData","item","index","count","i","jsx","cn","jsxs","GraphHeader","H2","P","AnimatePresence","motion","GraphFooter"],"mappings":"sdA2FO,SAASA,EAAUC,EAAc,CACtC,KAAM,CACJ,KA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N,SAAU5B,GAAQ,SAClB,OAAQA,GAAQ,MAAA,EAElB,QAAAvB,EACA,SAAAO,EACA,MAAAW,CAAA,CAAA,EAEA,IAAA,CAAA,CACN,CAAA,CAAA,CACF,CAAA,CAAA,CACF,CAAA,CACF,CAAA,CAGN"}
|
|
1
|
+
{"version":3,"file":"UnitChart.cjs","sources":["../src/Components/Graphs/UnitChart/index.tsx"],"sourcesContent":["import { useRef } from 'react';\r\nimport sum from 'lodash.sum';\r\nimport { H2, P } from '@undp/design-system-react/Typography';\r\nimport { AnimatePresence, motion, useInView } from 'motion/react';\r\nimport { cn } from '@undp/design-system-react/cn';\r\n\r\nimport { GraphFooter } from '@/Components/Elements/GraphFooter';\r\nimport { GraphHeader } from '@/Components/Elements/GraphHeader';\r\nimport { Colors } from '@/Components/ColorPalette';\r\nimport {\r\n UnitChartDataType,\r\n SourcesDataType,\r\n Languages,\r\n StyleObject,\r\n ClassNameObject,\r\n AnimateDataType,\r\n} from '@/Types';\r\nimport { numberFormattingFunction } from '@/Utils/numberFormattingFunction';\r\n\r\ninterface Props {\r\n // Data\r\n /** Array of data objects */\r\n data: UnitChartDataType[];\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 /** Note with h2 tag just above the graph. Can be used to highlight text */\r\n note?: string;\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 /** Colors of the highlighted circles */\r\n colors?: 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\r\n // Graph Parameters\r\n /** Size of the visualization */\r\n size?: number;\r\n /** No. of dots in a single row */\r\n gridSize?: number;\r\n /** Spacing between 2 dots */\r\n unitPadding?: number;\r\n /** Total no. of dot that are rendered in the chart */\r\n totalNoOfDots?: number;\r\n /** Toggle visibility of stroke for the unfilled dots */\r\n showStrokeForWhiteDots?: boolean;\r\n /** Toggles if the graph animates in when loaded. */\r\n animate?: boolean | AnimateDataType;\r\n /** Toggle visibility of color scale */\r\n showColorScale?: boolean;\r\n /** Specifies the number of decimal places to display in the value. */\r\n precision?: number;\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\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 UnitChart(props: Props) {\r\n const {\r\n data,\r\n size = 200,\r\n graphTitle,\r\n sources,\r\n colors = Colors.light.categoricalColors.colors,\r\n graphDescription,\r\n totalNoOfDots = 100,\r\n unitPadding = 3,\r\n gridSize = 10,\r\n footNote,\r\n padding,\r\n backgroundColor = false,\r\n graphID,\r\n graphDownload = false,\r\n language = 'en',\r\n showColorScale = true,\r\n showStrokeForWhiteDots = true,\r\n note,\r\n dataDownload = false,\r\n theme = 'light',\r\n width,\r\n height,\r\n minHeight = 0,\r\n relativeHeight,\r\n ariaLabel,\r\n styles,\r\n classNames,\r\n animate = false,\r\n precision = 2,\r\n } = props;\r\n const svgRef = useRef(null);\r\n const animateValue =\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 const isInView = useInView(svgRef, {\r\n once: animateValue.once,\r\n amount: animateValue.amount,\r\n });\r\n const totalValue = sum(data.map(d => d.value));\r\n const graphParentDiv = useRef<HTMLDivElement>(null);\r\n const gridDimension = size / gridSize;\r\n const radius = (gridDimension - unitPadding * 2) / 2;\r\n if (radius <= 0) {\r\n console.error(\r\n 'The size of single unit is less than or equal to zero. Check values for ((dimension / gridSize) - (padding * 2)) / 2 is not less than or equal to 0.',\r\n );\r\n return null;\r\n }\r\n\r\n const cellsData: { color: string }[] = [];\r\n data.forEach((item, index) => {\r\n const count = Math.round((item.value / totalValue) * totalNoOfDots);\r\n for (let i = 0; i < count; i += 1) {\r\n cellsData.push({ color: colors[index] });\r\n }\r\n });\r\n return (\r\n <div\r\n className={`${theme || 'light'} flex ${width ? 'w-fit grow-0' : 'w-full grow'}`}\r\n dir={language === 'he' || language === 'ar' ? 'rtl' : undefined}\r\n >\r\n <div\r\n className={cn(\r\n `${\r\n !backgroundColor\r\n ? 'bg-transparent '\r\n : backgroundColor === true\r\n ? 'bg-primary-gray-200 dark:bg-primary-gray-650 '\r\n : ''\r\n }ml-auto mr-auto flex flex-col grow h-inherit ${language || 'en'}`,\r\n width ? 'w-fit' : 'w-full',\r\n classNames?.graphContainer,\r\n )}\r\n style={{\r\n ...(styles?.graphContainer || {}),\r\n minHeight: 'inherit',\r\n ...(backgroundColor && backgroundColor !== true ? { backgroundColor } : {}),\r\n }}\r\n id={graphID}\r\n ref={graphParentDiv}\r\n aria-label={\r\n ariaLabel ||\r\n `${graphTitle ? `The graph shows ${graphTitle}. ` : ''}${\r\n graphDescription ? ` ${graphDescription}` : ''\r\n }`\r\n }\r\n >\r\n <div\r\n className='flex grow'\r\n style={{ padding: backgroundColor ? padding || '1rem' : padding || 0 }}\r\n >\r\n <div className='flex flex-col gap-3 w-full grow'>\r\n {graphTitle || graphDescription || graphDownload ? (\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.current : 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 {note ? (\r\n <H2\r\n marginBottom='2xs'\r\n className='text-primary-gray-700 dark:text-primary-gray-100 font-bold'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n >\r\n {note}\r\n </H2>\r\n ) : null}\r\n <div className='flex grow flex-col gap-4 justify-between'>\r\n <div>\r\n {showColorScale ? (\r\n <div\r\n className='mb-4 leading-0'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n aria-label='Color legend'\r\n >\r\n <div className='flex mb-0 flex-wrap gap-x-4 gap-y-1'>\r\n {data.map((d, i) => (\r\n <div className='flex gap-2 items-center' key={i}>\r\n <div\r\n className='w-3 h-3 rounded-full'\r\n style={{ backgroundColor: colors[i] }}\r\n />\r\n <P\r\n marginBottom='none'\r\n size='sm'\r\n className='text-primary-gray-700 dark:text-primary-gray-100'\r\n >\r\n {d.label}:{' '}\r\n <span className='font-bold'>\r\n {numberFormattingFunction(d.value, 'NA', precision)}\r\n </span>\r\n </P>\r\n </div>\r\n ))}\r\n </div>\r\n </div>\r\n ) : null}\r\n <div aria-label='Graph area'>\r\n <svg\r\n width={`${width || size}px`}\r\n height={`${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}px`}\r\n ref={svgRef}\r\n direction='ltr'\r\n viewBox={`0 0 ${width || size} ${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}`}\r\n >\r\n <AnimatePresence>\r\n <g>\r\n {cellsData.map((d, i) => (\r\n <motion.circle\r\n key={i}\r\n style={{\r\n strokeWidth: 1,\r\n }}\r\n variants={{\r\n initial: {\r\n fill: '#fff',\r\n opacity: 0,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n },\r\n whileInView: {\r\n fill: d.color,\r\n opacity: 1,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n cx: (i % gridSize) * gridDimension + gridDimension / 2,\r\n cy: Math.floor(i / gridSize) * gridDimension + gridDimension / 2,\r\n transition: {\r\n duration: 0,\r\n delay: (animateValue.duration / cellsData.length) * i,\r\n },\r\n },\r\n }}\r\n initial='initial'\r\n animate={isInView ? 'whileInView' : 'initial'}\r\n className={\r\n (d.color.toLowerCase() === '#fff' ||\r\n d.color.toLowerCase() === '#ffffff' ||\r\n d.color.toLowerCase() === 'white') &&\r\n showStrokeForWhiteDots\r\n ? 'stroke-primary-gray-400 dark:stroke-primary-gray-500'\r\n : ''\r\n }\r\n r={radius}\r\n />\r\n ))}\r\n </g>\r\n </AnimatePresence>\r\n </svg>\r\n </div>\r\n </div>\r\n {sources || footNote ? (\r\n <GraphFooter\r\n styles={{\r\n footnote: styles?.footnote,\r\n source: styles?.source,\r\n }}\r\n sources={sources}\r\n footNote={footNote}\r\n width={width}\r\n />\r\n ) : null}\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n}\r\n"],"names":["UnitChart","props","data","size","graphTitle","sources","colors","Colors","graphDescription","totalNoOfDots","unitPadding","gridSize","footNote","padding","backgroundColor","graphID","graphDownload","language","showColorScale","showStrokeForWhiteDots","note","dataDownload","theme","width","height","minHeight","relativeHeight","ariaLabel","styles","classNames","animate","precision","svgRef","useRef","animateValue","isInView","useInView","totalValue","sum","d","graphParentDiv","gridDimension","radius","cellsData","item","index","count","i","jsx","cn","jsxs","GraphHeader","H2","P","AnimatePresence","motion","GraphFooter"],"mappings":"sdA2FO,SAASA,EAAUC,EAAc,CACtC,KAAM,CACJ,KAAAC,EACA,KAAAC,EAAO,IACP,WAAAC,EACA,QAAAC,EACA,OAAAC,EAASC,EAAAA,OAAO,MAAM,kBAAkB,OACxC,iBAAAC,EACA,cAAAC,EAAgB,IAChB,YAAAC,EAAc,EACd,SAAAC,EAAW,GACX,SAAAC,EACA,QAAAC,EACA,gBAAAC,EAAkB,GAClB,QAAAC,EACA,cAAAC,EAAgB,GAChB,SAAAC,EAAW,KACX,eAAAC,EAAiB,GACjB,uBAAAC,EAAyB,GACzB,KAAAC,EACA,aAAAC,EAAe,GACf,MAAAC,EAAQ,QACR,MAAAC,EACA,OAAAC,EACA,UAAAC,EAAY,EACZ,eAAAC,EACA,UAAAC,EACA,OAAAC,EACA,WAAAC,EACA,QAAAC,EAAU,GACV,UAAAC,EAAY,CAAA,EACV9B,EACE+B,EAASC,EAAAA,OAAO,IAAI,EACpBC,EACJJ,IAAY,GACR,CAAE,SAAU,GAAK,KAAM,GAAM,OAAQ,IACrCA,GAAW,CAAE,SAAU,EAAG,KAAM,GAAM,OAAQ,CAAA,EAC9CK,EAAWC,EAAAA,UAAUJ,EAAQ,CACjC,KAAME,EAAa,KACnB,OAAQA,EAAa,MAAA,CACtB,EACKG,EAAaC,EAAAA,IAAIpC,EAAK,IAAIqC,GAAKA,EAAE,KAAK,CAAC,EACvCC,EAAiBP,EAAAA,OAAuB,IAAI,EAC5CQ,EAAgBtC,EAAOQ,EACvB+B,GAAUD,EAAgB/B,EAAc,GAAK,EACnD,GAAIgC,GAAU,EACZ,eAAQ,MACN,sJAAA,EAEK,KAGT,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WAC1BA,EAAE,MAAM,gBAAkB,UAC5BpB,EACI,uDACA,GAEN,EAAGuB,CAAA,EAlCE,CAAA,CAoCR,EACH,CAAA,CACF,CAAA,CAAA,CACF,CACF,CAAA,EACF,EACCrC,GAAWO,EACVoC,EAAAA,kBAAAA,IAACQ,EAAAA,YAAA,CACC,OAAQ,CACN,SAAU5B,GAAQ,SAClB,OAAQA,GAAQ,MAAA,EAElB,QAAAvB,EACA,SAAAO,EACA,MAAAW,CAAA,CAAA,EAEA,IAAA,CAAA,CACN,CAAA,CAAA,CACF,CAAA,CAAA,CACF,CAAA,CACF,CAAA,CAGN"}
|
package/dist/UnitChart.js
CHANGED
|
@@ -12,12 +12,12 @@ import { m as ee } from "./proxy-CkpFesk1.js";
|
|
|
12
12
|
function he(H) {
|
|
13
13
|
const {
|
|
14
14
|
data: s,
|
|
15
|
-
size:
|
|
15
|
+
size: g = 200,
|
|
16
16
|
graphTitle: d,
|
|
17
17
|
sources: N,
|
|
18
18
|
colors: b = X.light.categoricalColors.colors,
|
|
19
19
|
graphDescription: h,
|
|
20
|
-
totalNoOfDots:
|
|
20
|
+
totalNoOfDots: p = 100,
|
|
21
21
|
unitPadding: L = 3,
|
|
22
22
|
gridSize: c = 10,
|
|
23
23
|
footNote: k,
|
|
@@ -25,14 +25,14 @@ function he(H) {
|
|
|
25
25
|
backgroundColor: n = !1,
|
|
26
26
|
graphID: S,
|
|
27
27
|
graphDownload: C = !1,
|
|
28
|
-
language:
|
|
28
|
+
language: x = "en",
|
|
29
29
|
showColorScale: W = !0,
|
|
30
|
-
showStrokeForWhiteDots:
|
|
30
|
+
showStrokeForWhiteDots: w = !0,
|
|
31
31
|
note: D,
|
|
32
32
|
dataDownload: A = !1,
|
|
33
33
|
theme: B = "light",
|
|
34
34
|
width: o,
|
|
35
|
-
height:
|
|
35
|
+
height: f,
|
|
36
36
|
minHeight: i = 0,
|
|
37
37
|
relativeHeight: l,
|
|
38
38
|
ariaLabel: G,
|
|
@@ -43,26 +43,26 @@ function he(H) {
|
|
|
43
43
|
} = H, M = F(null), v = z === !0 ? { duration: 0.5, once: !0, amount: 0.5 } : z || { duration: 0, once: !0, amount: 0 }, R = Z(M, {
|
|
44
44
|
once: v.once,
|
|
45
45
|
amount: v.amount
|
|
46
|
-
}), T = O(s.map((e) => e.value)), V = F(null), a =
|
|
47
|
-
if (
|
|
46
|
+
}), T = O(s.map((e) => e.value)), V = F(null), a = g / c, u = (a - L * 2) / 2;
|
|
47
|
+
if (u <= 0)
|
|
48
48
|
return console.error(
|
|
49
49
|
"The size of single unit is less than or equal to zero. Check values for ((dimension / gridSize) - (padding * 2)) / 2 is not less than or equal to 0."
|
|
50
50
|
), null;
|
|
51
51
|
const j = [];
|
|
52
52
|
return s.forEach((e, t) => {
|
|
53
|
-
const q = Math.round(e.value / T *
|
|
53
|
+
const q = Math.round(e.value / T * p);
|
|
54
54
|
for (let I = 0; I < q; I += 1)
|
|
55
55
|
j.push({ color: b[t] });
|
|
56
56
|
}), /* @__PURE__ */ r.jsx(
|
|
57
57
|
"div",
|
|
58
58
|
{
|
|
59
59
|
className: `${B || "light"} flex ${o ? "w-fit grow-0" : "w-full grow"}`,
|
|
60
|
-
dir:
|
|
60
|
+
dir: x === "he" || x === "ar" ? "rtl" : void 0,
|
|
61
61
|
children: /* @__PURE__ */ r.jsx(
|
|
62
62
|
"div",
|
|
63
63
|
{
|
|
64
64
|
className: E(
|
|
65
|
-
`${n ? n === !0 ? "bg-primary-gray-200 dark:bg-primary-gray-650 " : "" : "bg-transparent "}ml-auto mr-auto flex flex-col grow h-inherit ${
|
|
65
|
+
`${n ? n === !0 ? "bg-primary-gray-200 dark:bg-primary-gray-650 " : "" : "bg-transparent "}ml-auto mr-auto flex flex-col grow h-inherit ${x || "en"}`,
|
|
66
66
|
o ? "w-fit" : "w-full",
|
|
67
67
|
y?.graphContainer
|
|
68
68
|
),
|
|
@@ -143,38 +143,37 @@ function he(H) {
|
|
|
143
143
|
/* @__PURE__ */ r.jsx("div", { "aria-label": "Graph area", children: /* @__PURE__ */ r.jsx(
|
|
144
144
|
"svg",
|
|
145
145
|
{
|
|
146
|
-
width: `${o ||
|
|
146
|
+
width: `${o || g}px`,
|
|
147
147
|
height: `${Math.max(
|
|
148
148
|
i,
|
|
149
|
-
|
|
149
|
+
f ? l && o ? i ? o * l > i ? o * l : i : o * l : f : Math.floor((p - 1) / c) * a + a / 2 + u + 5
|
|
150
150
|
)}px`,
|
|
151
151
|
ref: M,
|
|
152
152
|
direction: "ltr",
|
|
153
|
-
viewBox: `0 0 ${o ||
|
|
153
|
+
viewBox: `0 0 ${o || g} ${Math.max(
|
|
154
154
|
i,
|
|
155
|
-
|
|
155
|
+
f ? l && o ? i ? o * l > i ? o * l : i : o * l : f : Math.floor((p - 1) / c) * a + a / 2 + u + 5
|
|
156
156
|
)}`,
|
|
157
157
|
children: /* @__PURE__ */ r.jsx(_, { children: /* @__PURE__ */ r.jsx("g", { children: j.map((e, t) => /* @__PURE__ */ r.jsx(
|
|
158
158
|
ee.circle,
|
|
159
159
|
{
|
|
160
|
-
cx: t % c * a + a / 2,
|
|
161
|
-
cy: Math.floor(t / c) * a + a / 2,
|
|
162
160
|
style: {
|
|
163
|
-
...f ? {} : { stroke: e.color },
|
|
164
161
|
strokeWidth: 1
|
|
165
162
|
},
|
|
166
163
|
variants: {
|
|
167
164
|
initial: {
|
|
168
165
|
fill: "#fff",
|
|
169
166
|
opacity: 0,
|
|
170
|
-
...
|
|
167
|
+
...w ? {} : { stroke: e.color },
|
|
171
168
|
strokeWidth: 1
|
|
172
169
|
},
|
|
173
170
|
whileInView: {
|
|
174
171
|
fill: e.color,
|
|
175
172
|
opacity: 1,
|
|
176
|
-
...
|
|
173
|
+
...w ? {} : { stroke: e.color },
|
|
177
174
|
strokeWidth: 1,
|
|
175
|
+
cx: t % c * a + a / 2,
|
|
176
|
+
cy: Math.floor(t / c) * a + a / 2,
|
|
178
177
|
transition: {
|
|
179
178
|
duration: 0,
|
|
180
179
|
delay: v.duration / j.length * t
|
|
@@ -183,8 +182,8 @@ function he(H) {
|
|
|
183
182
|
},
|
|
184
183
|
initial: "initial",
|
|
185
184
|
animate: R ? "whileInView" : "initial",
|
|
186
|
-
className: (e.color.toLowerCase() === "#fff" || e.color.toLowerCase() === "#ffffff" || e.color.toLowerCase() === "white") &&
|
|
187
|
-
r:
|
|
185
|
+
className: (e.color.toLowerCase() === "#fff" || e.color.toLowerCase() === "#ffffff" || e.color.toLowerCase() === "white") && w ? "stroke-primary-gray-400 dark:stroke-primary-gray-500" : "",
|
|
186
|
+
r: u
|
|
188
187
|
},
|
|
189
188
|
t
|
|
190
189
|
)) }) })
|
package/dist/UnitChart.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UnitChart.js","sources":["../src/Components/Graphs/UnitChart/index.tsx"],"sourcesContent":["import { useRef } from 'react';\r\nimport sum from 'lodash.sum';\r\nimport { H2, P } from '@undp/design-system-react/Typography';\r\nimport { AnimatePresence, motion, useInView } from 'motion/react';\r\nimport { cn } from '@undp/design-system-react/cn';\r\n\r\nimport { GraphFooter } from '@/Components/Elements/GraphFooter';\r\nimport { GraphHeader } from '@/Components/Elements/GraphHeader';\r\nimport { Colors } from '@/Components/ColorPalette';\r\nimport {\r\n UnitChartDataType,\r\n SourcesDataType,\r\n Languages,\r\n StyleObject,\r\n ClassNameObject,\r\n AnimateDataType,\r\n} from '@/Types';\r\nimport { numberFormattingFunction } from '@/Utils/numberFormattingFunction';\r\n\r\ninterface Props {\r\n // Data\r\n /** Array of data objects */\r\n data: UnitChartDataType[];\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 /** Note with h2 tag just above the graph. Can be used to highlight text */\r\n note?: string;\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 /** Colors of the highlighted circles */\r\n colors?: 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\r\n // Graph Parameters\r\n /** Size of the visualization */\r\n size?: number;\r\n /** No. of dots in a single row */\r\n gridSize?: number;\r\n /** Spacing between 2 dots */\r\n unitPadding?: number;\r\n /** Total no. of dot that are rendered in the chart */\r\n totalNoOfDots?: number;\r\n /** Toggle visibility of stroke for the unfilled dots */\r\n showStrokeForWhiteDots?: boolean;\r\n /** Toggles if the graph animates in when loaded. */\r\n animate?: boolean | AnimateDataType;\r\n /** Toggle visibility of color scale */\r\n showColorScale?: boolean;\r\n /** Specifies the number of decimal places to display in the value. */\r\n precision?: number;\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\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 UnitChart(props: Props) {\r\n const {\r\n data,\r\n size = 200,\r\n graphTitle,\r\n sources,\r\n colors = Colors.light.categoricalColors.colors,\r\n graphDescription,\r\n totalNoOfDots = 100,\r\n unitPadding = 3,\r\n gridSize = 10,\r\n footNote,\r\n padding,\r\n backgroundColor = false,\r\n graphID,\r\n graphDownload = false,\r\n language = 'en',\r\n showColorScale = true,\r\n showStrokeForWhiteDots = true,\r\n note,\r\n dataDownload = false,\r\n theme = 'light',\r\n width,\r\n height,\r\n minHeight = 0,\r\n relativeHeight,\r\n ariaLabel,\r\n styles,\r\n classNames,\r\n animate = false,\r\n precision = 2,\r\n } = props;\r\n const svgRef = useRef(null);\r\n const animateValue =\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 const isInView = useInView(svgRef, {\r\n once: animateValue.once,\r\n amount: animateValue.amount,\r\n });\r\n const totalValue = sum(data.map(d => d.value));\r\n const graphParentDiv = useRef<HTMLDivElement>(null);\r\n const gridDimension = size / gridSize;\r\n const radius = (gridDimension - unitPadding * 2) / 2;\r\n if (radius <= 0) {\r\n console.error(\r\n 'The size of single unit is less than or equal to zero. Check values for ((dimension / gridSize) - (padding * 2)) / 2 is not less than or equal to 0.',\r\n );\r\n return null;\r\n }\r\n\r\n const cellsData: { color: string }[] = [];\r\n data.forEach((item, index) => {\r\n const count = Math.round((item.value / totalValue) * totalNoOfDots);\r\n for (let i = 0; i < count; i += 1) {\r\n cellsData.push({ color: colors[index] });\r\n }\r\n });\r\n return (\r\n <div\r\n className={`${theme || 'light'} flex ${width ? 'w-fit grow-0' : 'w-full grow'}`}\r\n dir={language === 'he' || language === 'ar' ? 'rtl' : undefined}\r\n >\r\n <div\r\n className={cn(\r\n `${\r\n !backgroundColor\r\n ? 'bg-transparent '\r\n : backgroundColor === true\r\n ? 'bg-primary-gray-200 dark:bg-primary-gray-650 '\r\n : ''\r\n }ml-auto mr-auto flex flex-col grow h-inherit ${language || 'en'}`,\r\n width ? 'w-fit' : 'w-full',\r\n classNames?.graphContainer,\r\n )}\r\n style={{\r\n ...(styles?.graphContainer || {}),\r\n minHeight: 'inherit',\r\n ...(backgroundColor && backgroundColor !== true ? { backgroundColor } : {}),\r\n }}\r\n id={graphID}\r\n ref={graphParentDiv}\r\n aria-label={\r\n ariaLabel ||\r\n `${graphTitle ? `The graph shows ${graphTitle}. ` : ''}${\r\n graphDescription ? ` ${graphDescription}` : ''\r\n }`\r\n }\r\n >\r\n <div\r\n className='flex grow'\r\n style={{ padding: backgroundColor ? padding || '1rem' : padding || 0 }}\r\n >\r\n <div className='flex flex-col gap-3 w-full grow'>\r\n {graphTitle || graphDescription || graphDownload ? (\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.current : 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 {note ? (\r\n <H2\r\n marginBottom='2xs'\r\n className='text-primary-gray-700 dark:text-primary-gray-100 font-bold'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n >\r\n {note}\r\n </H2>\r\n ) : null}\r\n <div className='flex grow flex-col gap-4 justify-between'>\r\n <div>\r\n {showColorScale ? (\r\n <div\r\n className='mb-4 leading-0'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n aria-label='Color legend'\r\n >\r\n <div className='flex mb-0 flex-wrap gap-x-4 gap-y-1'>\r\n {data.map((d, i) => (\r\n <div className='flex gap-2 items-center' key={i}>\r\n <div\r\n className='w-3 h-3 rounded-full'\r\n style={{ backgroundColor: colors[i] }}\r\n />\r\n <P\r\n marginBottom='none'\r\n size='sm'\r\n className='text-primary-gray-700 dark:text-primary-gray-100'\r\n >\r\n {d.label}:{' '}\r\n <span className='font-bold'>\r\n {numberFormattingFunction(d.value, 'NA', precision)}\r\n </span>\r\n </P>\r\n </div>\r\n ))}\r\n </div>\r\n </div>\r\n ) : null}\r\n <div aria-label='Graph area'>\r\n <svg\r\n width={`${width || size}px`}\r\n height={`${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}px`}\r\n ref={svgRef}\r\n direction='ltr'\r\n viewBox={`0 0 ${width || size} ${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}`}\r\n >\r\n <AnimatePresence>\r\n <g>\r\n {cellsData.map((d, i) => (\r\n <motion.circle\r\n key={i}\r\n cx={(i % gridSize) * gridDimension + gridDimension / 2}\r\n cy={Math.floor(i / gridSize) * gridDimension + gridDimension / 2}\r\n style={{\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n }}\r\n variants={{\r\n initial: {\r\n fill: '#fff',\r\n opacity: 0,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n },\r\n whileInView: {\r\n fill: d.color,\r\n opacity: 1,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n transition: {\r\n duration: 0,\r\n delay: (animateValue.duration / cellsData.length) * i,\r\n },\r\n },\r\n }}\r\n initial='initial'\r\n animate={isInView ? 'whileInView' : 'initial'}\r\n className={\r\n (d.color.toLowerCase() === '#fff' ||\r\n d.color.toLowerCase() === '#ffffff' ||\r\n d.color.toLowerCase() === 'white') &&\r\n showStrokeForWhiteDots\r\n ? 'stroke-primary-gray-400 dark:stroke-primary-gray-500'\r\n : ''\r\n }\r\n r={radius}\r\n />\r\n ))}\r\n </g>\r\n </AnimatePresence>\r\n </svg>\r\n </div>\r\n </div>\r\n {sources || footNote ? (\r\n <GraphFooter\r\n styles={{\r\n footnote: styles?.footnote,\r\n source: styles?.source,\r\n }}\r\n sources={sources}\r\n footNote={footNote}\r\n width={width}\r\n />\r\n ) : null}\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n}\r\n"],"names":["UnitChart","props","data","size","graphTitle","sources","colors","Colors","graphDescription","totalNoOfDots","unitPadding","gridSize","footNote","padding","backgroundColor","graphID","graphDownload","language","showColorScale","showStrokeForWhiteDots","note","dataDownload","theme","width","height","minHeight","relativeHeight","ariaLabel","styles","classNames","animate","precision","svgRef","useRef","animateValue","isInView","useInView","totalValue","sum","d","graphParentDiv","gridDimension","radius","cellsData","item","index","count","i","jsx","cn","jsxs","GraphHeader","H2","P","AnimatePresence","motion","GraphFooter"],"mappings":";;;;;;;;;;;AA2FO,SAASA,GAAUC,GAAc;AACtC,QAAM;AAAA,IACJ,MAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,YAAAC;AAAA,IACA,SAAAC;AAAA,IACA,QAAAC,IAASC,EAAO,MAAM,kBAAkB;AAAA,IACxC,kBAAAC;AAAA,IACA,eAAAC,IAAgB;AAAA,IAChB,aAAAC,IAAc;AAAA,IACd,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,SAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IAClB,SAAAC;AAAA,IACA,eAAAC,IAAgB;AAAA,IAChB,UAAAC,IAAW;AAAA,IACX,gBAAAC,IAAiB;AAAA,IACjB,wBAAAC,IAAyB;AAAA,IACzB,MAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,OAAAC,IAAQ;AAAA,IACR,OAAAC;AAAA,IACA,QAAAC;AAAA,IACA,WAAAC,IAAY;AAAA,IACZ,gBAAAC;AAAA,IACA,WAAAC;AAAA,IACA,QAAAC;AAAA,IACA,YAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV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AE,MAAA;AAAA,gCAC1C,aAAa;AAAA,gCACb,YAAY;AAAA,kCACV,UAAU;AAAA,kCACV,OAAQL,EAAa,WAAWS,EAAU,SAAUI;AAAA,gCAAA;AAAA,8BACtD;AAAA,4BACF;AAAA,4BAEF,SAAQ;AAAA,4BACR,SAASZ,IAAW,gBAAgB;AAAA,4BACpC,YACGI,EAAE,MAAM,YAAA,MAAkB,UACzBA,EAAE,MAAM,YAAA,MAAkB,aAC1BA,EAAE,MAAM,kBAAkB,YAC5BpB,IACI,yDACA;AAAA,4BAEN,GAAGuB;AAAA,0BAAA;AAAA,0BAnCEK;AAAA,wBAAA,CAqCR,GACH,EAAA,CACF;AAAA,sBAAA;AAAA,oBAAA,EACF,CACF;AAAA,kBAAA,GACF;AAAA,kBACC1C,KAAWO,IACVoC,gBAAAA,EAAAA;AAAAA,oBAACQ;AAAA,oBAAA;AAAA,sBACC,QAAQ;AAAA,wBACN,UAAU5B,GAAQ;AAAA,wBAClB,QAAQA,GAAQ;AAAA,sBAAA;AAAA,sBAElB,SAAAvB;AAAA,sBACA,UAAAO;AAAA,sBACA,OAAAW;AAAA,oBAAA;AAAA,kBAAA,IAEA;AAAA,gBAAA,EAAA,CACN;AAAA,cAAA,EAAA,CACF;AAAA,YAAA;AAAA,UAAA;AAAA,QACF;AAAA,MAAA;AAAA,IACF;AAAA,EAAA;AAGN;"}
|
|
1
|
+
{"version":3,"file":"UnitChart.js","sources":["../src/Components/Graphs/UnitChart/index.tsx"],"sourcesContent":["import { useRef } from 'react';\r\nimport sum from 'lodash.sum';\r\nimport { H2, P } from '@undp/design-system-react/Typography';\r\nimport { AnimatePresence, motion, useInView } from 'motion/react';\r\nimport { cn } from '@undp/design-system-react/cn';\r\n\r\nimport { GraphFooter } from '@/Components/Elements/GraphFooter';\r\nimport { GraphHeader } from '@/Components/Elements/GraphHeader';\r\nimport { Colors } from '@/Components/ColorPalette';\r\nimport {\r\n UnitChartDataType,\r\n SourcesDataType,\r\n Languages,\r\n StyleObject,\r\n ClassNameObject,\r\n AnimateDataType,\r\n} from '@/Types';\r\nimport { numberFormattingFunction } from '@/Utils/numberFormattingFunction';\r\n\r\ninterface Props {\r\n // Data\r\n /** Array of data objects */\r\n data: UnitChartDataType[];\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 /** Note with h2 tag just above the graph. Can be used to highlight text */\r\n note?: string;\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 /** Colors of the highlighted circles */\r\n colors?: 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\r\n // Graph Parameters\r\n /** Size of the visualization */\r\n size?: number;\r\n /** No. of dots in a single row */\r\n gridSize?: number;\r\n /** Spacing between 2 dots */\r\n unitPadding?: number;\r\n /** Total no. of dot that are rendered in the chart */\r\n totalNoOfDots?: number;\r\n /** Toggle visibility of stroke for the unfilled dots */\r\n showStrokeForWhiteDots?: boolean;\r\n /** Toggles if the graph animates in when loaded. */\r\n animate?: boolean | AnimateDataType;\r\n /** Toggle visibility of color scale */\r\n showColorScale?: boolean;\r\n /** Specifies the number of decimal places to display in the value. */\r\n precision?: number;\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\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 UnitChart(props: Props) {\r\n const {\r\n data,\r\n size = 200,\r\n graphTitle,\r\n sources,\r\n colors = Colors.light.categoricalColors.colors,\r\n graphDescription,\r\n totalNoOfDots = 100,\r\n unitPadding = 3,\r\n gridSize = 10,\r\n footNote,\r\n padding,\r\n backgroundColor = false,\r\n graphID,\r\n graphDownload = false,\r\n language = 'en',\r\n showColorScale = true,\r\n showStrokeForWhiteDots = true,\r\n note,\r\n dataDownload = false,\r\n theme = 'light',\r\n width,\r\n height,\r\n minHeight = 0,\r\n relativeHeight,\r\n ariaLabel,\r\n styles,\r\n classNames,\r\n animate = false,\r\n precision = 2,\r\n } = props;\r\n const svgRef = useRef(null);\r\n const animateValue =\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 const isInView = useInView(svgRef, {\r\n once: animateValue.once,\r\n amount: animateValue.amount,\r\n });\r\n const totalValue = sum(data.map(d => d.value));\r\n const graphParentDiv = useRef<HTMLDivElement>(null);\r\n const gridDimension = size / gridSize;\r\n const radius = (gridDimension - unitPadding * 2) / 2;\r\n if (radius <= 0) {\r\n console.error(\r\n 'The size of single unit is less than or equal to zero. Check values for ((dimension / gridSize) - (padding * 2)) / 2 is not less than or equal to 0.',\r\n );\r\n return null;\r\n }\r\n\r\n const cellsData: { color: string }[] = [];\r\n data.forEach((item, index) => {\r\n const count = Math.round((item.value / totalValue) * totalNoOfDots);\r\n for (let i = 0; i < count; i += 1) {\r\n cellsData.push({ color: colors[index] });\r\n }\r\n });\r\n return (\r\n <div\r\n className={`${theme || 'light'} flex ${width ? 'w-fit grow-0' : 'w-full grow'}`}\r\n dir={language === 'he' || language === 'ar' ? 'rtl' : undefined}\r\n >\r\n <div\r\n className={cn(\r\n `${\r\n !backgroundColor\r\n ? 'bg-transparent '\r\n : backgroundColor === true\r\n ? 'bg-primary-gray-200 dark:bg-primary-gray-650 '\r\n : ''\r\n }ml-auto mr-auto flex flex-col grow h-inherit ${language || 'en'}`,\r\n width ? 'w-fit' : 'w-full',\r\n classNames?.graphContainer,\r\n )}\r\n style={{\r\n ...(styles?.graphContainer || {}),\r\n minHeight: 'inherit',\r\n ...(backgroundColor && backgroundColor !== true ? { backgroundColor } : {}),\r\n }}\r\n id={graphID}\r\n ref={graphParentDiv}\r\n aria-label={\r\n ariaLabel ||\r\n `${graphTitle ? `The graph shows ${graphTitle}. ` : ''}${\r\n graphDescription ? ` ${graphDescription}` : ''\r\n }`\r\n }\r\n >\r\n <div\r\n className='flex grow'\r\n style={{ padding: backgroundColor ? padding || '1rem' : padding || 0 }}\r\n >\r\n <div className='flex flex-col gap-3 w-full grow'>\r\n {graphTitle || graphDescription || graphDownload ? (\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.current : 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 {note ? (\r\n <H2\r\n marginBottom='2xs'\r\n className='text-primary-gray-700 dark:text-primary-gray-100 font-bold'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n >\r\n {note}\r\n </H2>\r\n ) : null}\r\n <div className='flex grow flex-col gap-4 justify-between'>\r\n <div>\r\n {showColorScale ? (\r\n <div\r\n className='mb-4 leading-0'\r\n style={{ width: width ? `${width}px` : '100%' }}\r\n aria-label='Color legend'\r\n >\r\n <div className='flex mb-0 flex-wrap gap-x-4 gap-y-1'>\r\n {data.map((d, i) => (\r\n <div className='flex gap-2 items-center' key={i}>\r\n <div\r\n className='w-3 h-3 rounded-full'\r\n style={{ backgroundColor: colors[i] }}\r\n />\r\n <P\r\n marginBottom='none'\r\n size='sm'\r\n className='text-primary-gray-700 dark:text-primary-gray-100'\r\n >\r\n {d.label}:{' '}\r\n <span className='font-bold'>\r\n {numberFormattingFunction(d.value, 'NA', precision)}\r\n </span>\r\n </P>\r\n </div>\r\n ))}\r\n </div>\r\n </div>\r\n ) : null}\r\n <div aria-label='Graph area'>\r\n <svg\r\n width={`${width || size}px`}\r\n height={`${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}px`}\r\n ref={svgRef}\r\n direction='ltr'\r\n viewBox={`0 0 ${width || size} ${Math.max(\r\n minHeight,\r\n height\r\n ? relativeHeight && width\r\n ? minHeight\r\n ? width * relativeHeight > minHeight\r\n ? width * relativeHeight\r\n : minHeight\r\n : width * relativeHeight\r\n : height\r\n : Math.floor((totalNoOfDots - 1) / gridSize) * gridDimension +\r\n gridDimension / 2 +\r\n radius +\r\n 5,\r\n )}`}\r\n >\r\n <AnimatePresence>\r\n <g>\r\n {cellsData.map((d, i) => (\r\n <motion.circle\r\n key={i}\r\n style={{\r\n strokeWidth: 1,\r\n }}\r\n variants={{\r\n initial: {\r\n fill: '#fff',\r\n opacity: 0,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n },\r\n whileInView: {\r\n fill: d.color,\r\n opacity: 1,\r\n ...(!showStrokeForWhiteDots ? { stroke: d.color } : {}),\r\n strokeWidth: 1,\r\n cx: (i % gridSize) * gridDimension + gridDimension / 2,\r\n cy: Math.floor(i / gridSize) * gridDimension + gridDimension / 2,\r\n transition: {\r\n duration: 0,\r\n delay: (animateValue.duration / cellsData.length) * i,\r\n },\r\n },\r\n }}\r\n initial='initial'\r\n animate={isInView ? 'whileInView' : 'initial'}\r\n className={\r\n (d.color.toLowerCase() === '#fff' ||\r\n d.color.toLowerCase() === '#ffffff' ||\r\n d.color.toLowerCase() === 'white') &&\r\n showStrokeForWhiteDots\r\n ? 'stroke-primary-gray-400 dark:stroke-primary-gray-500'\r\n : ''\r\n }\r\n r={radius}\r\n />\r\n ))}\r\n </g>\r\n </AnimatePresence>\r\n </svg>\r\n </div>\r\n </div>\r\n {sources || footNote ? (\r\n <GraphFooter\r\n styles={{\r\n footnote: styles?.footnote,\r\n source: styles?.source,\r\n }}\r\n sources={sources}\r\n footNote={footNote}\r\n width={width}\r\n />\r\n ) : null}\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n </div>\r\n );\r\n}\r\n"],"names":["UnitChart","props","data","size","graphTitle","sources","colors","Colors","graphDescription","totalNoOfDots","unitPadding","gridSize","footNote","padding","backgroundColor","graphID","graphDownload","language","showColorScale","showStrokeForWhiteDots","note","dataDownload","theme","width","height","minHeight","relativeHeight","ariaLabel","styles","classNames","animate","precision","svgRef","useRef","animateValue","isInView","useInView","totalValue","sum","d","graphParentDiv","gridDimension","radius","cellsData","item","index","count","i","jsx","cn","jsxs","GraphHeader","H2","P","AnimatePresence","motion","GraphFooter"],"mappings":";;;;;;;;;;;AA2FO,SAASA,GAAUC,GAAc;AACtC,QAAM;AAAA,IACJ,MAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,YAAAC;AAAA,IACA,SAAAC;AAAA,IACA,QAAAC,IAASC,EAAO,MAAM,kBAAkB;AAAA,IACxC,kBAAAC;AAAA,IACA,eAAAC,IAAgB;AAAA,IAChB,aAAAC,IAAc;AAAA,IACd,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,SAAAC;AAAA,IACA,iBAAAC,IAAkB;AA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area/dist/esm/index.js","../src/Utils/getCentroidCoordinates.ts"],"sourcesContent":["// index.ts\nimport { earthRadius } from \"@turf/helpers\";\nimport { geomReduce } from \"@turf/meta\";\nfunction area(geojson) {\n return geomReduce(\n geojson,\n (value, geom) => {\n return value + calculateArea(geom);\n },\n 0\n );\n}\nfunction calculateArea(geom) {\n let total = 0;\n let i;\n switch (geom.type) {\n case \"Polygon\":\n return polygonArea(geom.coordinates);\n case \"MultiPolygon\":\n for (i = 0; i < geom.coordinates.length; i++) {\n total += polygonArea(geom.coordinates[i]);\n }\n return total;\n case \"Point\":\n case \"MultiPoint\":\n case \"LineString\":\n case \"MultiLineString\":\n return 0;\n }\n return 0;\n}\nfunction polygonArea(coords) {\n let total = 0;\n if (coords && coords.length > 0) {\n total += Math.abs(ringArea(coords[0]));\n for (let i = 1; i < coords.length; i++) {\n total -= Math.abs(ringArea(coords[i]));\n }\n }\n return total;\n}\nvar FACTOR = earthRadius * earthRadius / 2;\nvar PI_OVER_180 = Math.PI / 180;\nfunction ringArea(coords) {\n const coordsLength = coords.length - 1;\n if (coordsLength <= 2) return 0;\n let total = 0;\n let i = 0;\n while (i < coordsLength) {\n const lower = coords[i];\n const middle = coords[i + 1 === coordsLength ? 0 : i + 1];\n const upper = coords[i + 2 >= coordsLength ? (i + 2) % coordsLength : i + 2];\n const lowerX = lower[0] * PI_OVER_180;\n const middleY = middle[1] * PI_OVER_180;\n const upperX = upper[0] * PI_OVER_180;\n total += (upperX - lowerX) * Math.sin(middleY);\n i++;\n }\n return total * FACTOR;\n}\nvar turf_area_default = area;\nexport {\n area,\n turf_area_default as default\n};\n//# sourceMappingURL=index.js.map","import area from '@turf/area';\r\nimport centerOfMass from '@turf/center-of-mass';\r\nimport { Feature, Polygon, MultiPolygon, GeoJsonProperties } from 'geojson';\r\n\r\nexport function getCentroidCoordinates(\r\n multiPolygonFeature: Feature<Polygon | MultiPolygon, GeoJsonProperties>,\r\n centerLargestPolygon = true,\r\n) {\r\n
|
|
1
|
+
{"version":3,"file":"getCentroidCoordinates-Dfk6IqEG.js","sources":["../node_modules/@turf/area/dist/esm/index.js","../src/Utils/getCentroidCoordinates.ts"],"sourcesContent":["// index.ts\nimport { earthRadius } from \"@turf/helpers\";\nimport { geomReduce } from \"@turf/meta\";\nfunction area(geojson) {\n return geomReduce(\n geojson,\n (value, geom) => {\n return value + calculateArea(geom);\n },\n 0\n );\n}\nfunction calculateArea(geom) {\n let total = 0;\n let i;\n switch (geom.type) {\n case \"Polygon\":\n return polygonArea(geom.coordinates);\n case \"MultiPolygon\":\n for (i = 0; i < geom.coordinates.length; i++) {\n total += polygonArea(geom.coordinates[i]);\n }\n return total;\n case \"Point\":\n case \"MultiPoint\":\n case \"LineString\":\n case \"MultiLineString\":\n return 0;\n }\n return 0;\n}\nfunction polygonArea(coords) {\n let total = 0;\n if (coords && coords.length > 0) {\n total += Math.abs(ringArea(coords[0]));\n for (let i = 1; i < coords.length; i++) {\n total -= Math.abs(ringArea(coords[i]));\n }\n }\n return total;\n}\nvar FACTOR = earthRadius * earthRadius / 2;\nvar PI_OVER_180 = Math.PI / 180;\nfunction ringArea(coords) {\n const coordsLength = coords.length - 1;\n if (coordsLength <= 2) return 0;\n let total = 0;\n let i = 0;\n while (i < coordsLength) {\n const lower = coords[i];\n const middle = coords[i + 1 === coordsLength ? 0 : i + 1];\n const upper = coords[i + 2 >= coordsLength ? (i + 2) % coordsLength : i + 2];\n const lowerX = lower[0] * PI_OVER_180;\n const middleY = middle[1] * PI_OVER_180;\n const upperX = upper[0] * PI_OVER_180;\n total += (upperX - lowerX) * Math.sin(middleY);\n i++;\n }\n return total * FACTOR;\n}\nvar turf_area_default = area;\nexport {\n area,\n turf_area_default as default\n};\n//# sourceMappingURL=index.js.map","import area from '@turf/area';\r\nimport centerOfMass from '@turf/center-of-mass';\r\nimport { Feature, Polygon, MultiPolygon, GeoJsonProperties } from 'geojson';\r\n\r\nexport function getCentroidCoordinates(\r\n multiPolygonFeature: Feature<Polygon | MultiPolygon, GeoJsonProperties>,\r\n centerLargestPolygon = true,\r\n) {\r\n if (multiPolygonFeature.geometry.type === 'Polygon' || centerLargestPolygon === false) {\r\n return centerOfMass(multiPolygonFeature).geometry.coordinates;\r\n }\r\n\r\n if (multiPolygonFeature.geometry.type === 'MultiPolygon') {\r\n let maxArea = 0;\r\n let largestPolygon: Feature<Polygon, GeoJsonProperties> | null = null;\r\n\r\n for (const coords of multiPolygonFeature.geometry.coordinates) {\r\n const poly: Feature<Polygon, GeoJsonProperties> = {\r\n type: 'Feature',\r\n geometry: {\r\n type: 'Polygon',\r\n coordinates: coords,\r\n },\r\n properties: {},\r\n };\r\n\r\n const polyArea = area(poly);\r\n if (polyArea > maxArea) {\r\n maxArea = polyArea;\r\n largestPolygon = poly;\r\n }\r\n }\r\n\r\n return centerOfMass(largestPolygon).geometry.coordinates;\r\n }\r\n\r\n throw new Error('Unsupported geometry type');\r\n}\r\n"],"names":["area","geojson","geomReduce","value","geom","calculateArea","total","i","polygonArea","coords","ringArea","FACTOR","earthRadius","PI_OVER_180","coordsLength","lower","middle","upper","lowerX","middleY","upperX","turf_area_default","getCentroidCoordinates","multiPolygonFeature","centerLargestPolygon","centerOfMass","maxArea","largestPolygon","poly","polyArea"],"mappings":";AAGA,SAASA,EAAKC,GAAS;AACrB,SAAOC;AAAA,IACLD;AAAA,IACA,CAACE,GAAOC,MACCD,IAAQE,EAAcD,CAAI;AAAA,IAEnC;AAAA,EACJ;AACA;AACA,SAASC,EAAcD,GAAM;AAC3B,MAAIE,IAAQ,GACRC;AACJ,UAAQH,EAAK,MAAI;AAAA,IACf,KAAK;AACH,aAAOI,EAAYJ,EAAK,WAAW;AAAA,IACrC,KAAK;AACH,WAAKG,IAAI,GAAGA,IAAIH,EAAK,YAAY,QAAQG;AACvC,QAAAD,KAASE,EAAYJ,EAAK,YAAYG,CAAC,CAAC;AAE1C,aAAOD;AAAA,IACT,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK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AAM;AAAA,UACN,aAAanB;AAAA,QAAA;AAAA,QAEf,YAAY,CAAA;AAAA,MAAC,GAGToB,IAAW7B,EAAK4B,CAAI;AAC1B,MAAIC,IAAWH,MACbA,IAAUG,GACVF,IAAiBC;AAAA,IAErB;AAEA,WAAOH,EAAaE,CAAc,EAAE,SAAS;AAAA,EAC/C;AAEA,QAAM,IAAI,MAAM,2BAA2B;AAC7C;","x_google_ignoreList":[0]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCentroidCoordinates-DxTBqzp2.cjs","sources":["../node_modules/@turf/area/dist/esm/index.js","../src/Utils/getCentroidCoordinates.ts"],"sourcesContent":["// index.ts\nimport { earthRadius } from \"@turf/helpers\";\nimport { geomReduce } from \"@turf/meta\";\nfunction area(geojson) {\n return geomReduce(\n geojson,\n (value, geom) => {\n return value + calculateArea(geom);\n },\n 0\n );\n}\nfunction calculateArea(geom) {\n let total = 0;\n let i;\n switch (geom.type) {\n case \"Polygon\":\n return polygonArea(geom.coordinates);\n case \"MultiPolygon\":\n for (i = 0; i < geom.coordinates.length; i++) {\n total += polygonArea(geom.coordinates[i]);\n }\n return total;\n case \"Point\":\n case \"MultiPoint\":\n case \"LineString\":\n case \"MultiLineString\":\n return 0;\n }\n return 0;\n}\nfunction polygonArea(coords) {\n let total = 0;\n if (coords && coords.length > 0) {\n total += Math.abs(ringArea(coords[0]));\n for (let i = 1; i < coords.length; i++) {\n total -= Math.abs(ringArea(coords[i]));\n }\n }\n return total;\n}\nvar FACTOR = earthRadius * earthRadius / 2;\nvar PI_OVER_180 = Math.PI / 180;\nfunction ringArea(coords) {\n const coordsLength = coords.length - 1;\n if (coordsLength <= 2) return 0;\n let total = 0;\n let i = 0;\n while (i < coordsLength) {\n const lower = coords[i];\n const middle = coords[i + 1 === coordsLength ? 0 : i + 1];\n const upper = coords[i + 2 >= coordsLength ? (i + 2) % coordsLength : i + 2];\n const lowerX = lower[0] * PI_OVER_180;\n const middleY = middle[1] * PI_OVER_180;\n const upperX = upper[0] * PI_OVER_180;\n total += (upperX - lowerX) * Math.sin(middleY);\n i++;\n }\n return total * FACTOR;\n}\nvar turf_area_default = area;\nexport {\n area,\n turf_area_default as default\n};\n//# sourceMappingURL=index.js.map","import area from '@turf/area';\r\nimport centerOfMass from '@turf/center-of-mass';\r\nimport { Feature, Polygon, MultiPolygon, GeoJsonProperties } from 'geojson';\r\n\r\nexport function getCentroidCoordinates(\r\n multiPolygonFeature: Feature<Polygon | MultiPolygon, GeoJsonProperties>,\r\n centerLargestPolygon = true,\r\n) {\r\n
|
|
1
|
+
{"version":3,"file":"getCentroidCoordinates-DxTBqzp2.cjs","sources":["../node_modules/@turf/area/dist/esm/index.js","../src/Utils/getCentroidCoordinates.ts"],"sourcesContent":["// index.ts\nimport { earthRadius } from \"@turf/helpers\";\nimport { geomReduce } from \"@turf/meta\";\nfunction area(geojson) {\n return geomReduce(\n geojson,\n (value, geom) => {\n return value + calculateArea(geom);\n },\n 0\n );\n}\nfunction calculateArea(geom) {\n let total = 0;\n let i;\n switch (geom.type) {\n case \"Polygon\":\n return polygonArea(geom.coordinates);\n case \"MultiPolygon\":\n for (i = 0; i < geom.coordinates.length; i++) {\n total += polygonArea(geom.coordinates[i]);\n }\n return total;\n case \"Point\":\n case \"MultiPoint\":\n case \"LineString\":\n case \"MultiLineString\":\n return 0;\n }\n return 0;\n}\nfunction polygonArea(coords) {\n let total = 0;\n if (coords && coords.length > 0) {\n total += Math.abs(ringArea(coords[0]));\n for (let i = 1; i < coords.length; i++) {\n total -= Math.abs(ringArea(coords[i]));\n }\n }\n return total;\n}\nvar FACTOR = earthRadius * earthRadius / 2;\nvar PI_OVER_180 = Math.PI / 180;\nfunction ringArea(coords) {\n const coordsLength = coords.length - 1;\n if (coordsLength <= 2) return 0;\n let total = 0;\n let i = 0;\n while (i < coordsLength) {\n const lower = coords[i];\n const middle = coords[i + 1 === coordsLength ? 0 : i + 1];\n const upper = coords[i + 2 >= coordsLength ? (i + 2) % coordsLength : i + 2];\n const lowerX = lower[0] * PI_OVER_180;\n const middleY = middle[1] * PI_OVER_180;\n const upperX = upper[0] * PI_OVER_180;\n total += (upperX - lowerX) * Math.sin(middleY);\n i++;\n }\n return total * FACTOR;\n}\nvar turf_area_default = area;\nexport {\n area,\n turf_area_default as default\n};\n//# sourceMappingURL=index.js.map","import area from '@turf/area';\r\nimport centerOfMass from '@turf/center-of-mass';\r\nimport { Feature, Polygon, MultiPolygon, GeoJsonProperties } from 'geojson';\r\n\r\nexport function getCentroidCoordinates(\r\n multiPolygonFeature: Feature<Polygon | MultiPolygon, GeoJsonProperties>,\r\n centerLargestPolygon = true,\r\n) {\r\n if (multiPolygonFeature.geometry.type === 'Polygon' || centerLargestPolygon === false) {\r\n return centerOfMass(multiPolygonFeature).geometry.coordinates;\r\n }\r\n\r\n if (multiPolygonFeature.geometry.type === 'MultiPolygon') {\r\n let maxArea = 0;\r\n let largestPolygon: Feature<Polygon, GeoJsonProperties> | null = null;\r\n\r\n for (const coords of multiPolygonFeature.geometry.coordinates) {\r\n const poly: Feature<Polygon, GeoJsonProperties> = {\r\n type: 'Feature',\r\n geometry: {\r\n type: 'Polygon',\r\n coordinates: coords,\r\n },\r\n properties: {},\r\n };\r\n\r\n const polyArea = area(poly);\r\n if (polyArea > maxArea) {\r\n maxArea = polyArea;\r\n largestPolygon = poly;\r\n }\r\n }\r\n\r\n return centerOfMass(largestPolygon).geometry.coordinates;\r\n }\r\n\r\n throw new Error('Unsupported geometry type');\r\n}\r\n"],"names":["area","geojson","geomReduce","value","geom","calculateArea","total","i","polygonArea","coords","ringArea","FACTOR","earthRadius","PI_OVER_180","coordsLength","lower","middle","upper","lowerX","middleY","upperX","turf_area_default","getCentroidCoordinates","multiPolygonFeature","centerLargestPolygon","centerOfMass","maxArea","largestPolygon","poly","polyArea"],"mappings":"qDAGA,SAASA,EAAKC,EAAS,CACrB,OAAOC,EAAAA,WACLD,EACA,CAACE,EAAOC,IACCD,EAAQE,EAAcD,CAA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AC,EAAuB,GACvB,CACA,GAAID,EAAoB,SAAS,OAAS,WAAaC,IAAyB,GAC9E,OAAOC,8BAAaF,CAAmB,EAAE,SAAS,YAGpD,GAAIA,EAAoB,SAAS,OAAS,eAAgB,CACxD,IAAIG,EAAU,EACVC,EAA6D,KAEjE,UAAWlB,KAAUc,EAAoB,SAAS,YAAa,CAC7D,MAAMK,EAA4C,CAChD,KAAM,UACN,SAAU,CACR,KAAM,UACN,YAAanB,CAAA,EAEf,WAAY,CAAA,CAAC,EAGToB,EAAW7B,EAAK4B,CAAI,EACtBC,EAAWH,IACbA,EAAUG,EACVF,EAAiBC,EAErB,CAEA,OAAOH,8BAAaE,CAAc,EAAE,SAAS,WAC/C,CAEA,MAAM,IAAI,MAAM,2BAA2B,CAC7C","x_google_ignoreList":[0]}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RegressionLine-mH7UKOPi.js","sources":["../src/Components/Elements/RegressionLine.tsx"],"sourcesContent":["import { cn } from '@undp/design-system-react/cn';\r\nimport { AnimatePresence, motion } from 'motion/react';\r\n\r\nimport { AnimateDataType } from '@/Types';\r\nimport { generateRandomString } from '@/Utils/generateRandomString';\r\n\r\ninterface Props {\r\n color?: string;\r\n y1: number;\r\n y2: number;\r\n x1: number;\r\n x2: number;\r\n graphWidth: number;\r\n graphHeight: number;\r\n className?: string;\r\n style?: React.CSSProperties;\r\n animate: AnimateDataType;\r\n isInView: boolean;\r\n}\r\n\r\nexport function RegressionLine(props: Props) {\r\n const { color, x1, x2, y1, y2, className, style, animate, isInView, graphWidth, graphHeight } =\r\n props;\r\n const id = generateRandomString(8);\r\n return (\r\n <g>\r\n <defs>\r\n <clipPath id={id}>\r\n <rect x='0' y='0' width={graphWidth} height={graphHeight} />\r\n </clipPath>\r\n </defs>\r\n <AnimatePresence>\r\n <motion.line\r\n clipPath={`url(#${id})`}\r\n className={cn(\r\n 'undp-ref-line',\r\n !color ? 'stroke-primary-gray-700 dark:stroke-primary-gray-300' : undefined,\r\n className,\r\n )}\r\n style={{\r\n ...(color && { stroke: color }),\r\n fill: 'none',\r\n ...(style || {}),\r\n }}\r\n exit={{ opacity: 0, transition: { duration: animate.duration } }}\r\n variants={{\r\n initial: {\r\n y1,\r\n y2: y1,\r\n x1,\r\n x2: x1,\r\n },\r\n whileInView: {\r\n y1,\r\n y2,\r\n x1,\r\n x2,\r\n transition: { duration: animate.duration },\r\n },\r\n }}\r\n initial='initial'\r\n animate={isInView ? 'whileInView' : 'initial'}\r\n />\r\n </AnimatePresence>\r\n </g>\r\n );\r\n}\r\n"],"names":["RegressionLine","props","color","x1","x2","y1","y2","className","style","animate","isInView","graphWidth","graphHeight","id","generateRandomString","jsx","AnimatePresence","motion","cn"],"mappings":";;;;AAoBO,SAASA,EAAeC,GAAc;AAC3C,QAAM,EAAE,OAAAC,GAAO,IAAAC,GAAI,IAAAC,GAAI,IAAAC,GAAI,IAAAC,GAAI,WAAAC,GAAW,OAAAC,GAAO,SAAAC,GAAS,UAAAC,GAAU,YAAAC,GAAY,aAAAC,EAAA,IAC9EX,GACIY,IAAKC,EAAqB,CAAC;AACjC,gCACG,KAAA,EACC,UAAA;AAAA,IAAAC,gBAAAA,MAAC,QAAA,EACC,UAAAA,gBAAAA,EAAAA,IAAC,YAAA,EAAS,IAAAF,GACR,gCAAC,QAAA,EAAK,GAAE,KAAI,GAAE,KAAI,OAAOF,GAAY,QAAQC,EAAA,CAAa,GAC5D,GACF;AAAA,0BACCI,GAAA,EACC,UAAAD,gBAAAA,EAAAA;AAAAA,MAACE,EAAO;AAAA,MAAP;AAAA,QACC,UAAU,QAAQJ,CAAE;AAAA,QACpB,WAAWK;AAAAA,UACT;AAAA,UACChB,IAAiE,SAAzD;AAAA,UACTK;AAAA,QAAA;AAAA,QAEF,OAAO;AAAA,UACL,GAAIL,KAAS,EAAE,QAAQA,EAAA;AAAA,UACvB,MAAM;AAAA,UACN,GAAIM,KAAS,CAAA;AAAA,QAAC;AAAA,QAEhB,MAAM,EAAE,SAAS,GAAG,YAAY,EAAE,UAAUC,EAAQ,WAAS;AAAA,QAC7D,UAAU;AAAA,UACR,SAAS;AAAA,YACP,IAAAJ;AAAA,YACA,IAAIA;AAAA,YACJ,IAAAF;AAAA,YACA,IAAIA;AAAA,UAAA;AAAA,UAEN,aAAa;AAAA,YACX,IAAAE;AAAA,YACA,IAAAC;AAAA,YACA,IAAAH;AAAA,YACA,IAAAC;AAAA,YACA,YAAY,EAAE,UAAUK,EAAQ,SAAA;AAAA,UAAS;AAAA,QAC3C;AAAA,QAEF,SAAQ;AAAA,QACR,SAASC,IAAW,gBAAgB;AAAA,MAAA;AAAA,IAAA,EACtC,CACF;AAAA,EAAA,GACF;AAEJ;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const i=require("./index-CHPV5EwG-DDoeWRVt.cjs"),h=require("./generateRandomString-B5zBiJzS.cjs"),p=require("./index-BW8iNx7E.cjs"),g=require("./proxy-BHRoeZgd.cjs");function j(a){const{color:e,x1:n,x2:o,y1:t,y2:x,className:l,style:c,animate:r,isInView:d,graphWidth:u,graphHeight:m}=a,s=h.generateRandomString(8);return i.jsxRuntimeExports.jsxs("g",{children:[i.jsxRuntimeExports.jsx("defs",{children:i.jsxRuntimeExports.jsx("clipPath",{id:s,children:i.jsxRuntimeExports.jsx("rect",{x:"0",y:"0",width:u,height:m})})}),i.jsxRuntimeExports.jsx(p.AnimatePresence,{children:i.jsxRuntimeExports.jsx(g.motion.line,{clipPath:`url(#${s})`,className:i.mo("undp-ref-line",e?void 0:"stroke-primary-gray-700 dark:stroke-primary-gray-300",l),style:{...e&&{stroke:e},fill:"none",...c||{}},exit:{opacity:0,transition:{duration:r.duration}},variants:{initial:{y1:t,y2:t,x1:n,x2:n},whileInView:{y1:t,y2:x,x1:n,x2:o,transition:{duration:r.duration}}},initial:"initial",animate:d?"whileInView":"initial"})})]})}exports.RegressionLine=j;
|
|
2
|
-
//# sourceMappingURL=RegressionLine-xKdiJ8sw.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RegressionLine-xKdiJ8sw.cjs","sources":["../src/Components/Elements/RegressionLine.tsx"],"sourcesContent":["import { cn } from '@undp/design-system-react/cn';\r\nimport { AnimatePresence, motion } from 'motion/react';\r\n\r\nimport { AnimateDataType } from '@/Types';\r\nimport { generateRandomString } from '@/Utils/generateRandomString';\r\n\r\ninterface Props {\r\n color?: string;\r\n y1: number;\r\n y2: number;\r\n x1: number;\r\n x2: number;\r\n graphWidth: number;\r\n graphHeight: number;\r\n className?: string;\r\n style?: React.CSSProperties;\r\n animate: AnimateDataType;\r\n isInView: boolean;\r\n}\r\n\r\nexport function RegressionLine(props: Props) {\r\n const { color, x1, x2, y1, y2, className, style, animate, isInView, graphWidth, graphHeight } =\r\n props;\r\n const id = generateRandomString(8);\r\n return (\r\n <g>\r\n <defs>\r\n <clipPath id={id}>\r\n <rect x='0' y='0' width={graphWidth} height={graphHeight} />\r\n </clipPath>\r\n </defs>\r\n <AnimatePresence>\r\n <motion.line\r\n clipPath={`url(#${id})`}\r\n className={cn(\r\n 'undp-ref-line',\r\n !color ? 'stroke-primary-gray-700 dark:stroke-primary-gray-300' : undefined,\r\n className,\r\n )}\r\n style={{\r\n ...(color && { stroke: color }),\r\n fill: 'none',\r\n ...(style || {}),\r\n }}\r\n exit={{ opacity: 0, transition: { duration: animate.duration } }}\r\n variants={{\r\n initial: {\r\n y1,\r\n y2: y1,\r\n x1,\r\n x2: x1,\r\n },\r\n whileInView: {\r\n y1,\r\n y2,\r\n x1,\r\n x2,\r\n transition: { duration: animate.duration },\r\n },\r\n }}\r\n initial='initial'\r\n animate={isInView ? 'whileInView' : 'initial'}\r\n />\r\n </AnimatePresence>\r\n </g>\r\n );\r\n}\r\n"],"names":["RegressionLine","props","color","x1","x2","y1","y2","className","style","animate","isInView","graphWidth","graphHeight","id","generateRandomString","jsx","AnimatePresence","motion","cn"],"mappings":"mLAoBO,SAASA,EAAeC,EAAc,CAC3C,KAAM,CAAE,MAAAC,EAAO,GAAAC,EAAI,GAAAC,EAAI,GAAAC,EAAI,GAAAC,EAAI,UAAAC,EAAW,MAAAC,EAAO,QAAAC,EAAS,SAAAC,EAAU,WAAAC,EAAY,YAAAC,CAAA,EAC9EX,EACIY,EAAKC,EAAAA,qBAAqB,CAAC,EACjC,gCACG,IAAA,CACC,SAAA,CAAAC,wBAAC,OAAA,CACC,SAAAA,EAAAA,kBAAAA,IAAC,WAAA,CAAS,GAAAF,EACR,iCAAC,OAAA,CAAK,EAAE,IAAI,EAAE,IAAI,MAAOF,EAAY,OAAQC,CAAA,CAAa,EAC5D,EACF,0BACCI,EAAAA,gBAAA,CACC,SAAAD,EAAAA,kBAAAA,IAACE,EAAAA,OAAO,KAAP,CACC,SAAU,QAAQJ,CAAE,IACpB,UAAWK,EAAAA,GACT,gBACChB,EAAiE,OAAzD,uDACTK,CAAA,EAEF,MAAO,CACL,GAAIL,GAAS,CAAE,OAAQA,CAAA,EACvB,KAAM,OACN,GAAIM,GAAS,CAAA,CAAC,EAEhB,KAAM,CAAE,QAAS,EAAG,WAAY,CAAE,SAAUC,EAAQ,SAAS,EAC7D,SAAU,CACR,QAAS,CACP,GAAAJ,EACA,GAAIA,EACJ,GAAAF,EACA,GAAIA,CAAA,EAEN,YAAa,CACX,GAAAE,EACA,GAAAC,EACA,GAAAH,EACA,GAAAC,EACA,WAAY,CAAE,SAAUK,EAAQ,QAAA,CAAS,CAC3C,EAEF,QAAQ,UACR,QAASC,EAAW,cAAgB,SAAA,CAAA,CACtC,CACF,CAAA,EACF,CAEJ"}
|