react-minimal-pie-chart 8.0.1 → 8.3.0
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/README.md +29 -22
- package/dist/index.js +20 -21
- package/dist/index.js.map +1 -1
- package/es/index.js +11 -14
- package/es/index.js.map +1 -1
- package/lib/index.js +20 -22
- package/lib/index.js.map +1 -1
- package/package.json +35 -36
- package/types/Chart/Chart.d.ts +2 -3
- package/types/Chart/index.d.ts +1 -1
- package/types/Label.d.ts +2 -5
- package/types/Path.d.ts +2 -5
- package/CHANGELOG.md +0 -244
package/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/Chart/extendData.ts","../src/Label.tsx","../src/Chart/renderLabels.tsx","../node_modules/svg-partial-circle/index.js","../src/Path.tsx","../src/Chart/renderSegments.tsx","../src/Chart/Chart.tsx"],"sourcesContent":["export function degreesToRadians(degrees: number) {\n return (degrees * Math.PI) / 180;\n}\n\nexport function valueBetween(value: number, min: number, max: number) {\n if (value > max) return max;\n if (value < min) return min;\n return value;\n}\n\nexport function extractPercentage(value: number, percentage: number) {\n return (percentage / 100) * value;\n}\n\nexport function bisectorAngle(startAngle: number, lengthAngle: number) {\n return startAngle + lengthAngle / 2;\n}\n\nexport function shiftVectorAlongAngle(angle: number, distance: number) {\n const angleRadians = degreesToRadians(angle);\n return {\n dx: distance * Math.cos(angleRadians),\n dy: distance * Math.sin(angleRadians),\n };\n}\n\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number';\n}\n\nexport function functionProp<Prop, Payload>(\n prop: Prop,\n payload?: Payload\n): Prop extends (...args: any) => any ? ReturnType<Prop> : Prop {\n return typeof prop === 'function' ? prop(payload) : prop;\n}\n","import { extractPercentage, valueBetween } from '../utils';\nimport type { Data, ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction sumValues(data: Data): number {\n let sum = 0;\n for (let i = 0; i < data.length; i++) {\n sum += data[i].value;\n }\n return sum;\n}\n\n// Append \"percentage\", \"degrees\" and \"startAngle\" to each data entry\nexport default function extendData({\n data,\n lengthAngle: totalAngle,\n totalValue,\n paddingAngle,\n startAngle: chartStartAngle,\n}: ChartProps): ExtendedData {\n const total = totalValue || sumValues(data);\n const normalizedTotalAngle = valueBetween(totalAngle, -360, 360);\n const numberOfPaddings =\n Math.abs(normalizedTotalAngle) === 360 ? data.length : data.length - 1;\n const singlePaddingDegrees = Math.abs(paddingAngle) * Math.sign(totalAngle);\n const degreesTakenByPadding = singlePaddingDegrees * numberOfPaddings;\n const degreesTakenByPaths = normalizedTotalAngle - degreesTakenByPadding;\n let lastSegmentEnd = 0;\n const extendedData = [];\n\n // @NOTE: Shall we evaluate percentage accordingly to dataEntry.value's sign?\n for (let i = 0; i < data.length; i++) {\n const dataEntry = data[i];\n const valueInPercentage = total === 0 ? 0 : (dataEntry.value / total) * 100;\n const degrees = extractPercentage(degreesTakenByPaths, valueInPercentage);\n const startAngle = lastSegmentEnd + chartStartAngle;\n lastSegmentEnd = lastSegmentEnd + degrees + singlePaddingDegrees;\n extendedData.push(\n Object.assign(\n {\n percentage: valueInPercentage,\n startAngle,\n degrees,\n },\n dataEntry\n )\n );\n }\n return extendedData;\n}\n","import React from 'react';\nimport type { CSSProperties, SVGProps } from 'react';\nimport type { ExtendedDataEntry } from './commonTypes';\n\nexport type LabelRenderProps = {\n x: number;\n y: number;\n dx: number;\n dy: number;\n textAnchor: string;\n dataEntry: ExtendedDataEntry;\n dataIndex: number;\n style?: CSSProperties;\n};\n\ntype Props = SVGProps<SVGTextElement> & LabelRenderProps;\n\nexport default function Label({ dataEntry, dataIndex, ...props }: Props) {\n return <text dominantBaseline=\"central\" {...props} />;\n}\n\nLabel.displayName = 'ReactMinimalPieChartLabel';\n","import React from 'react';\nimport DefaultLabel from '../Label';\nimport {\n bisectorAngle,\n extractPercentage,\n functionProp,\n shiftVectorAlongAngle,\n} from '../utils';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\nimport type { LabelRenderProps } from '../Label';\nimport type { ExtendedData, LabelRenderFunction } from '../commonTypes';\n\nfunction round(number: number): number {\n const divisor = 1e14; // 14 decimals\n return Math.round((number + Number.EPSILON) * divisor) / divisor;\n}\n\nfunction evaluateTextAnchorPosition({\n labelPosition,\n lineWidth,\n labelHorizontalShift,\n}: {\n labelPosition: number;\n lineWidth: number;\n labelHorizontalShift: number;\n}) {\n const dx = round(labelHorizontalShift);\n // Label in the vertical center\n if (dx === 0) {\n return 'middle';\n }\n // Outward label\n if (labelPosition > 100) {\n return dx > 0 ? 'start' : 'end';\n }\n // Inward label\n const innerRadius = 100 - lineWidth;\n if (labelPosition < innerRadius) {\n return dx > 0 ? 'end' : 'start';\n }\n // Overlying label\n return 'middle';\n}\n\nfunction renderLabelElement(\n renderLabel: LabelRenderFunction,\n labelProps: LabelRenderProps\n): JSX.Element | null {\n const label = renderLabel(labelProps);\n if (typeof label === 'string' || typeof label === 'number') {\n return (\n <DefaultLabel\n key={`label-${labelProps.dataEntry.key || labelProps.dataIndex}`}\n {...labelProps}\n >\n {label}\n </DefaultLabel>\n );\n }\n\n if (React.isValidElement(label)) {\n return label;\n }\n return null;\n}\n\nexport default function renderLabels(data: ExtendedData, props: ChartProps) {\n return data.map((dataEntry, index) => {\n const segmentsShift = functionProp(props.segmentsShift, index) ?? 0;\n const distanceFromCenter =\n extractPercentage(props.radius, props.labelPosition) + segmentsShift;\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(dataEntry.startAngle, dataEntry.degrees),\n distanceFromCenter\n );\n\n // This object is passed as argument to the \"label\" function prop\n const labelRenderProps = {\n x: props.center[0],\n y: props.center[1],\n dx,\n dy,\n textAnchor: evaluateTextAnchorPosition({\n labelPosition: props.labelPosition,\n lineWidth: props.lineWidth,\n labelHorizontalShift: dx,\n }),\n dataEntry,\n dataIndex: index,\n style: functionProp(props.labelStyle, index),\n };\n\n return props.label && renderLabelElement(props.label, labelRenderProps);\n });\n}\n","'use strict'\n\n// from http://stackoverflow.com/a/18473154\nconst partialCircle = (cx, cy, r, start, end) => {\n\tconst length = end - start\n\tif (length === 0) return []\n\n\tconst fromX = r * Math.cos(start) + cx\n\tconst fromY = r * Math.sin(start) + cy\n\tconst toX = r * Math.cos(end) + cx\n\tconst toY = r * Math.sin(end) + cy\n\tconst large = Math.abs(length) <= Math.PI ? '0' : '1'\n\tconst sweep = length < 0 ? '0' : '1'\n\n\treturn [\n\t\t['M', fromX, fromY],\n\t\t['A', r, r, 0, large, sweep, toX, toY]\n\t]\n}\n\nmodule.exports = partialCircle\n","import React from 'react';\nimport type { SVGProps } from 'react';\nimport partialCircle from 'svg-partial-circle';\nimport {\n bisectorAngle,\n degreesToRadians,\n extractPercentage,\n isNumber,\n shiftVectorAlongAngle,\n valueBetween,\n} from './utils';\n\nexport function makePathCommands(\n cx: number,\n cy: number,\n startAngle: number,\n lengthAngle: number,\n radius: number\n): string {\n const patchedLengthAngle = valueBetween(lengthAngle, -359.999, 359.999);\n\n return partialCircle(\n cx,\n cy, // center X and Y\n radius,\n degreesToRadians(startAngle),\n degreesToRadians(startAngle + patchedLengthAngle)\n )\n .map((command) => command.join(' '))\n .join(' ');\n}\n\ntype Props = SVGProps<SVGPathElement> & {\n cx: number;\n cy: number;\n lengthAngle: number;\n lineWidth: number;\n radius: number;\n reveal?: number;\n rounded?: boolean;\n shift?: number;\n startAngle: number;\n title?: string | number;\n};\n\nexport default function Path({\n cx,\n cy,\n lengthAngle,\n lineWidth,\n radius,\n shift = 0,\n reveal,\n rounded,\n startAngle,\n title,\n ...props\n}: Props) {\n const pathRadius = radius - lineWidth / 2;\n //@NOTE This shift might be rendered as a translation in future\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(startAngle, lengthAngle),\n shift\n );\n\n const pathCommands = makePathCommands(\n cx + dx,\n cy + dy,\n startAngle,\n lengthAngle,\n pathRadius\n );\n let strokeDasharray;\n let strokeDashoffset;\n\n // Animate/hide paths with \"stroke-dasharray\" + \"stroke-dashoffset\"\n // https://css-tricks.com/svg-line-animation-works/\n if (isNumber(reveal)) {\n const pathLength = degreesToRadians(pathRadius) * lengthAngle;\n strokeDasharray = Math.abs(pathLength);\n strokeDashoffset =\n strokeDasharray - extractPercentage(strokeDasharray, reveal);\n }\n\n return (\n <path\n d={pathCommands}\n fill=\"none\"\n strokeWidth={lineWidth}\n strokeDasharray={strokeDasharray}\n strokeDashoffset={strokeDashoffset}\n strokeLinecap={rounded ? 'round' : undefined}\n {...props}\n >\n {title && <title>{title}</title>}\n </path>\n );\n}\n\nPath.displayName = 'ReactMinimalPieChartPath';\n","import React from 'react';\nimport type { CSSProperties } from 'react';\nimport Path from '../Path';\nimport { extractPercentage, functionProp, isNumber } from '../utils';\nimport type { ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction combineSegmentTransitionsStyle(\n duration: number,\n easing: string,\n customStyle?: CSSProperties\n): { transition: string } {\n // Merge chart's animation CSS transition with \"transition\" found to customStyle\n let transition = `stroke-dashoffset ${duration}ms ${easing}`;\n if (customStyle && customStyle.transition) {\n transition = `${transition},${customStyle.transition}`;\n }\n return {\n transition,\n };\n}\n\nfunction getRevealValue<Reveal>(props: { reveal?: Reveal; animate?: boolean }) {\n //@NOTE When animation is on, chart has to be fully revealed when reveal is not set\n if (props.animate && !isNumber(props.reveal)) {\n return 100;\n }\n return props.reveal;\n}\n\nfunction makeEventHandler<Event, EventHandler, Payload>(\n eventHandler: undefined | (EventHandler & Function),\n payload: Payload\n) {\n return (\n eventHandler &&\n ((e: Event) => {\n eventHandler(e, payload);\n })\n );\n}\n\nexport default function renderSegments(\n data: ExtendedData,\n props: ChartProps,\n revealOverride?: null | number\n) {\n // @NOTE this should go in Path component. Here for performance reasons\n const reveal = revealOverride ?? getRevealValue(props);\n const {\n radius,\n center: [cx, cy],\n } = props;\n const lineWidth = extractPercentage(radius, props.lineWidth);\n const paths = data.map((dataEntry, index) => {\n const segmentsStyle = functionProp(props.segmentsStyle, index);\n return (\n <Path\n cx={cx}\n cy={cy}\n key={dataEntry.key || index}\n lengthAngle={dataEntry.degrees}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n reveal={reveal}\n shift={functionProp(props.segmentsShift, index)}\n startAngle={dataEntry.startAngle}\n title={dataEntry.title}\n style={Object.assign(\n {},\n segmentsStyle,\n props.animate &&\n combineSegmentTransitionsStyle(\n props.animationDuration,\n props.animationEasing,\n segmentsStyle\n )\n )}\n stroke={dataEntry.color}\n tabIndex={props.segmentsTabIndex}\n onBlur={makeEventHandler(props.onBlur, index)}\n onClick={makeEventHandler(props.onClick, index)}\n onFocus={makeEventHandler(props.onFocus, index)}\n onKeyDown={makeEventHandler(props.onKeyDown, index)}\n onMouseOver={makeEventHandler(props.onMouseOver, index)}\n onMouseOut={makeEventHandler(props.onMouseOut, index)}\n />\n );\n });\n\n if (props.background) {\n paths.unshift(\n <Path\n cx={cx}\n cy={cy}\n key=\"bg\"\n lengthAngle={props.lengthAngle}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n startAngle={props.startAngle}\n stroke={props.background}\n />\n );\n }\n\n return paths;\n}\n","import React, { useState, useEffect } from 'react';\nimport type {\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from 'react';\nimport extendData from './extendData';\nimport renderLabels from './renderLabels';\nimport renderSegments from './renderSegments';\nimport type { Data, EventHandler, LabelRenderFunction } from '../commonTypes';\n\ntype Props = {\n animate?: boolean;\n animationDuration?: number;\n animationEasing?: string;\n background?: string;\n center?: [number, number];\n children?: ReactNode;\n className?: string;\n data: Data;\n lengthAngle?: number;\n lineWidth?: number;\n label?: LabelRenderFunction;\n labelPosition?: number;\n labelStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n onBlur?: EventHandler<FocusEvent>;\n onClick?: EventHandler<MouseEvent>;\n onFocus?: EventHandler<FocusEvent>;\n onKeyDown?: EventHandler<KeyboardEvent>;\n onMouseOut?: EventHandler<MouseEvent>;\n onMouseOver?: EventHandler<MouseEvent>;\n paddingAngle?: number;\n radius?: number;\n reveal?: number;\n rounded?: boolean;\n segmentsShift?: number | ((dataIndex: number) => number | undefined);\n segmentsStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n segmentsTabIndex?: number;\n startAngle?: number;\n style?: CSSProperties;\n totalValue?: number;\n viewBoxSize?: [number, number];\n};\n\nconst defaultProps = {\n animationDuration: 500,\n animationEasing: 'ease-out',\n center: [50, 50] as [number, number],\n data: [] as Data,\n labelPosition: 50,\n lengthAngle: 360,\n lineWidth: 100,\n paddingAngle: 0,\n radius: 50,\n startAngle: 0,\n viewBoxSize: [100, 100] as [number, number],\n};\n\nexport type PropsWithDefaults = Props & typeof defaultProps;\n\nexport function PieChart(props: PropsWithDefaults) {\n const [revealOverride, setRevealOverride] = useState(\n props.animate ? 0 : null\n );\n useEffect(() => {\n if (props.animate) {\n return startInitialAnimation();\n }\n\n function startInitialAnimation() {\n let animationTimerId: number | null;\n let animationRAFId: number | null;\n animationTimerId = setTimeout(() => {\n animationTimerId = null;\n animationRAFId = requestAnimationFrame(() => {\n animationRAFId = null;\n setRevealOverride(null); // Start animation\n });\n });\n\n return () => {\n animationTimerId && clearTimeout(animationTimerId);\n animationRAFId && cancelAnimationFrame(animationRAFId);\n };\n }\n }, []);\n\n const extendedData = extendData(props);\n return (\n <svg\n viewBox={`0 0 ${props.viewBoxSize[0]} ${props.viewBoxSize[1]}`}\n width=\"100%\"\n height=\"100%\"\n className={props.className}\n style={props.style}\n >\n {renderSegments(extendedData, props, revealOverride)}\n {props.label && renderLabels(extendedData, props)}\n {props.children}\n </svg>\n );\n}\n\nPieChart.defaultProps = defaultProps;\nPieChart.displayName = 'ReactMinimalPieChart';\n"],"names":["degreesToRadians","degrees","Math","PI","valueBetween","value","min","max","extractPercentage","percentage","bisectorAngle","startAngle","lengthAngle","shiftVectorAlongAngle","angle","distance","angleRadians","dx","cos","dy","sin","isNumber","functionProp","prop","payload","sumValues","data","sum","i","length","extendData","totalAngle","totalValue","paddingAngle","chartStartAngle","total","normalizedTotalAngle","numberOfPaddings","abs","singlePaddingDegrees","sign","degreesTakenByPadding","degreesTakenByPaths","lastSegmentEnd","extendedData","dataEntry","valueInPercentage","push","Object","assign","Label","dataIndex","props","displayName","round","number","divisor","Number","EPSILON","evaluateTextAnchorPosition","labelPosition","lineWidth","labelHorizontalShift","innerRadius","renderLabelElement","renderLabel","labelProps","label","DefaultLabel","key","React","isValidElement","renderLabels","map","index","segmentsShift","distanceFromCenter","radius","labelRenderProps","x","center","y","textAnchor","style","labelStyle","partialCircle","cx","cy","r","start","end","fromX","fromY","toX","toY","large","sweep","module","makePathCommands","patchedLengthAngle","command","join","Path","shift","reveal","rounded","title","pathRadius","pathCommands","strokeDasharray","strokeDashoffset","pathLength","undefined","combineSegmentTransitionsStyle","duration","easing","customStyle","transition","getRevealValue","animate","makeEventHandler","eventHandler","e","renderSegments","revealOverride","paths","segmentsStyle","animationDuration","animationEasing","color","segmentsTabIndex","onBlur","onClick","onFocus","onKeyDown","onMouseOver","onMouseOut","background","unshift","defaultProps","viewBoxSize","PieChart","useState","setRevealOverride","useEffect","startInitialAnimation","animationTimerId","animationRAFId","setTimeout","requestAnimationFrame","clearTimeout","cancelAnimationFrame","className","children"],"mappings":";;AAAO,SAASA,gBAAT,CAA0BC,OAA1B,EAA2C;SACxCA,OAAO,GAAGC,IAAI,CAACC,EAAhB,GAAsB,GAA7B;;AAGF,AAAO,SAASC,YAAT,CAAsBC,KAAtB,EAAqCC,GAArC,EAAkDC,GAAlD,EAA+D;MAChEF,KAAK,GAAGE,GAAZ,EAAiB,OAAOA,GAAP;MACbF,KAAK,GAAGC,GAAZ,EAAiB,OAAOA,GAAP;SACVD,KAAP;;AAGF,AAAO,SAASG,iBAAT,CAA2BH,KAA3B,EAA0CI,UAA1C,EAA8D;SAC3DA,UA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AEE,KAAK,EAAC,MAFR;IAGE,MAAM,EAAC,MAHT;IAIE,SAAS,EAAExF,KAAK,CAACoG,SAJnB;IAKE,KAAK,EAAEpG,KAAK,CAAC+B;KAEZwC,cAAc,CAAC/E,YAAD,EAAeQ,KAAf,EAAsBwE,cAAtB,CAPjB,EAQGxE,KAAK,CAACe,KAAN,IAAeK,YAAY,CAAC5B,YAAD,EAAeQ,KAAf,CAR9B,EASGA,KAAK,CAACqG,QATT,CADF;;AAeFZ,QAAQ,CAACF,YAAT,GAAwBA,YAAxB;AACAE,QAAQ,CAACxF,WAAT,GAAuB,sBAAvB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/Chart/extendData.ts","../src/Label.tsx","../src/Chart/renderLabels.tsx","../node_modules/svg-partial-circle/index.js","../src/Path.tsx","../src/Chart/renderSegments.tsx","../src/Chart/Chart.tsx"],"sourcesContent":["export function degreesToRadians(degrees: number) {\n return (degrees * Math.PI) / 180;\n}\n\nexport function valueBetween(value: number, min: number, max: number) {\n if (value > max) return max;\n if (value < min) return min;\n return value;\n}\n\nexport function extractPercentage(value: number, percentage: number) {\n return (percentage / 100) * value;\n}\n\nexport function bisectorAngle(startAngle: number, lengthAngle: number) {\n return startAngle + lengthAngle / 2;\n}\n\nexport function shiftVectorAlongAngle(angle: number, distance: number) {\n const angleRadians = degreesToRadians(angle);\n return {\n dx: distance * Math.cos(angleRadians),\n dy: distance * Math.sin(angleRadians),\n };\n}\n\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number';\n}\n\nexport function functionProp<Prop, Payload>(\n prop: Prop,\n payload?: Payload\n): Prop extends (...args: any) => any ? ReturnType<Prop> : Prop {\n return typeof prop === 'function' ? prop(payload) : prop;\n}\n","import { extractPercentage, valueBetween } from '../utils';\nimport type { Data, ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction sumValues(data: Data): number {\n let sum = 0;\n for (let i = 0; i < data.length; i++) {\n sum += data[i].value;\n }\n return sum;\n}\n\n// Append \"percentage\", \"degrees\" and \"startAngle\" to each data entry\nexport default function extendData({\n data,\n lengthAngle: totalAngle,\n totalValue,\n paddingAngle,\n startAngle: chartStartAngle,\n}: ChartProps): ExtendedData {\n const total = totalValue || sumValues(data);\n const normalizedTotalAngle = valueBetween(totalAngle, -360, 360);\n const numberOfPaddings =\n Math.abs(normalizedTotalAngle) === 360 ? data.length : data.length - 1;\n const singlePaddingDegrees = Math.abs(paddingAngle) * Math.sign(totalAngle);\n const degreesTakenByPadding = singlePaddingDegrees * numberOfPaddings;\n const degreesTakenByPaths = normalizedTotalAngle - degreesTakenByPadding;\n let lastSegmentEnd = 0;\n const extendedData = [];\n\n // @NOTE: Shall we evaluate percentage accordingly to dataEntry.value's sign?\n for (let i = 0; i < data.length; i++) {\n const dataEntry = data[i];\n const valueInPercentage = total === 0 ? 0 : (dataEntry.value / total) * 100;\n const degrees = extractPercentage(degreesTakenByPaths, valueInPercentage);\n const startAngle = lastSegmentEnd + chartStartAngle;\n lastSegmentEnd = lastSegmentEnd + degrees + singlePaddingDegrees;\n extendedData.push(\n Object.assign(\n {\n percentage: valueInPercentage,\n startAngle,\n degrees,\n },\n dataEntry\n )\n );\n }\n return extendedData;\n}\n","import React from 'react';\nimport type { CSSProperties, SVGProps } from 'react';\nimport type { ExtendedDataEntry } from './commonTypes';\n\nexport type LabelRenderProps = {\n x: number;\n y: number;\n dx: number;\n dy: number;\n textAnchor: string;\n dataEntry: ExtendedDataEntry;\n dataIndex: number;\n style?: CSSProperties;\n};\n\ntype Props = SVGProps<SVGTextElement> & LabelRenderProps;\n\nexport default function ReactMinimalPieChartLabel({\n dataEntry,\n dataIndex,\n ...props\n}: Props) {\n return <text dominantBaseline=\"central\" {...props} />;\n}\n","import React from 'react';\nimport DefaultLabel from '../Label';\nimport {\n bisectorAngle,\n extractPercentage,\n functionProp,\n shiftVectorAlongAngle,\n} from '../utils';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\nimport type { LabelRenderProps } from '../Label';\nimport type { ExtendedData, LabelRenderFunction } from '../commonTypes';\n\nfunction round(number: number): number {\n const divisor = 1e14; // 14 decimals\n return Math.round((number + Number.EPSILON) * divisor) / divisor;\n}\n\nfunction evaluateTextAnchorPosition({\n labelPosition,\n lineWidth,\n labelHorizontalShift,\n}: {\n labelPosition: number;\n lineWidth: number;\n labelHorizontalShift: number;\n}) {\n const dx = round(labelHorizontalShift);\n // Label in the vertical center\n if (dx === 0) {\n return 'middle';\n }\n // Outward label\n if (labelPosition > 100) {\n return dx > 0 ? 'start' : 'end';\n }\n // Inward label\n const innerRadius = 100 - lineWidth;\n if (labelPosition < innerRadius) {\n return dx > 0 ? 'end' : 'start';\n }\n // Overlying label\n return 'middle';\n}\n\nfunction renderLabelElement(\n renderLabel: LabelRenderFunction,\n labelProps: LabelRenderProps\n): JSX.Element | null {\n const label = renderLabel(labelProps);\n if (typeof label === 'string' || typeof label === 'number') {\n return (\n <DefaultLabel\n key={`label-${labelProps.dataEntry.key || labelProps.dataIndex}`}\n {...labelProps}\n >\n {label}\n </DefaultLabel>\n );\n }\n\n if (React.isValidElement(label)) {\n return label;\n }\n return null;\n}\n\nexport default function renderLabels(data: ExtendedData, props: ChartProps) {\n return data.map((dataEntry, index) => {\n const segmentsShift = functionProp(props.segmentsShift, index) ?? 0;\n const distanceFromCenter =\n extractPercentage(props.radius, props.labelPosition) + segmentsShift;\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(dataEntry.startAngle, dataEntry.degrees),\n distanceFromCenter\n );\n\n // This object is passed as argument to the \"label\" function prop\n const labelRenderProps = {\n x: props.center[0],\n y: props.center[1],\n dx,\n dy,\n textAnchor: evaluateTextAnchorPosition({\n labelPosition: props.labelPosition,\n lineWidth: props.lineWidth,\n labelHorizontalShift: dx,\n }),\n dataEntry,\n dataIndex: index,\n style: functionProp(props.labelStyle, index),\n };\n\n return props.label && renderLabelElement(props.label, labelRenderProps);\n });\n}\n","'use strict'\n\n// from http://stackoverflow.com/a/18473154\nconst partialCircle = (cx, cy, r, start, end) => {\n\tconst length = end - start\n\tif (length === 0) return []\n\n\tconst fromX = r * Math.cos(start) + cx\n\tconst fromY = r * Math.sin(start) + cy\n\tconst toX = r * Math.cos(end) + cx\n\tconst toY = r * Math.sin(end) + cy\n\tconst large = Math.abs(length) <= Math.PI ? '0' : '1'\n\tconst sweep = length < 0 ? '0' : '1'\n\n\treturn [\n\t\t['M', fromX, fromY],\n\t\t['A', r, r, 0, large, sweep, toX, toY]\n\t]\n}\n\nmodule.exports = partialCircle\n","import React from 'react';\nimport type { SVGProps } from 'react';\nimport partialCircle from 'svg-partial-circle';\nimport {\n bisectorAngle,\n degreesToRadians,\n extractPercentage,\n isNumber,\n shiftVectorAlongAngle,\n valueBetween,\n} from './utils';\n\nexport function makePathCommands(\n cx: number,\n cy: number,\n startAngle: number,\n lengthAngle: number,\n radius: number\n): string {\n const patchedLengthAngle = valueBetween(lengthAngle, -359.999, 359.999);\n\n return partialCircle(\n cx,\n cy, // center X and Y\n radius,\n degreesToRadians(startAngle),\n degreesToRadians(startAngle + patchedLengthAngle)\n )\n .map((command) => command.join(' '))\n .join(' ');\n}\n\ntype Props = SVGProps<SVGPathElement> & {\n cx: number;\n cy: number;\n lengthAngle: number;\n lineWidth: number;\n radius: number;\n reveal?: number;\n rounded?: boolean;\n shift?: number;\n startAngle: number;\n title?: string | number;\n};\n\nexport default function ReactMinimalPieChartPath({\n cx,\n cy,\n lengthAngle,\n lineWidth,\n radius,\n shift = 0,\n reveal,\n rounded,\n startAngle,\n title,\n ...props\n}: Props) {\n const pathRadius = radius - lineWidth / 2;\n //@NOTE This shift might be rendered as a translation in future\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(startAngle, lengthAngle),\n shift\n );\n\n const pathCommands = makePathCommands(\n cx + dx,\n cy + dy,\n startAngle,\n lengthAngle,\n pathRadius\n );\n let strokeDasharray;\n let strokeDashoffset;\n\n // Animate/hide paths with \"stroke-dasharray\" + \"stroke-dashoffset\"\n // https://css-tricks.com/svg-line-animation-works/\n if (isNumber(reveal)) {\n const pathLength = degreesToRadians(pathRadius) * lengthAngle;\n strokeDasharray = Math.abs(pathLength);\n strokeDashoffset =\n strokeDasharray - extractPercentage(strokeDasharray, reveal);\n }\n\n return (\n <path\n d={pathCommands}\n fill=\"none\"\n strokeWidth={lineWidth}\n strokeDasharray={strokeDasharray}\n strokeDashoffset={strokeDashoffset}\n strokeLinecap={rounded ? 'round' : undefined}\n {...props}\n >\n {title && <title>{title}</title>}\n </path>\n );\n}\n","import React from 'react';\nimport type { CSSProperties } from 'react';\nimport Path from '../Path';\nimport { extractPercentage, functionProp, isNumber } from '../utils';\nimport type { ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction combineSegmentTransitionsStyle(\n duration: number,\n easing: string,\n customStyle?: CSSProperties\n): { transition: string } {\n // Merge chart's animation CSS transition with \"transition\" found to customStyle\n let transition = `stroke-dashoffset ${duration}ms ${easing}`;\n if (customStyle && customStyle.transition) {\n transition = `${transition},${customStyle.transition}`;\n }\n return {\n transition,\n };\n}\n\nfunction getRevealValue<Reveal>(props: { reveal?: Reveal; animate?: boolean }) {\n //@NOTE When animation is on, chart has to be fully revealed when reveal is not set\n if (props.animate && !isNumber(props.reveal)) {\n return 100;\n }\n return props.reveal;\n}\n\nfunction makeEventHandler<Event, EventHandler, Payload>(\n eventHandler: undefined | (EventHandler & Function),\n payload: Payload\n) {\n return (\n eventHandler &&\n ((e: Event) => {\n eventHandler(e, payload);\n })\n );\n}\n\nexport default function renderSegments(\n data: ExtendedData,\n props: ChartProps,\n revealOverride?: null | number\n) {\n // @NOTE this should go in Path component. Here for performance reasons\n const reveal = revealOverride ?? getRevealValue(props);\n const {\n radius,\n center: [cx, cy],\n } = props;\n const lineWidth = extractPercentage(radius, props.lineWidth);\n const paths = data.map((dataEntry, index) => {\n const segmentsStyle = functionProp(props.segmentsStyle, index);\n return (\n <Path\n cx={cx}\n cy={cy}\n key={dataEntry.key || index}\n lengthAngle={dataEntry.degrees}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n reveal={reveal}\n shift={functionProp(props.segmentsShift, index)}\n startAngle={dataEntry.startAngle}\n title={dataEntry.title}\n style={Object.assign(\n {},\n segmentsStyle,\n props.animate &&\n combineSegmentTransitionsStyle(\n props.animationDuration,\n props.animationEasing,\n segmentsStyle\n )\n )}\n stroke={dataEntry.color}\n tabIndex={props.segmentsTabIndex}\n onBlur={makeEventHandler(props.onBlur, index)}\n onClick={makeEventHandler(props.onClick, index)}\n onFocus={makeEventHandler(props.onFocus, index)}\n onKeyDown={makeEventHandler(props.onKeyDown, index)}\n onMouseOver={makeEventHandler(props.onMouseOver, index)}\n onMouseOut={makeEventHandler(props.onMouseOut, index)}\n />\n );\n });\n\n if (props.background) {\n paths.unshift(\n <Path\n cx={cx}\n cy={cy}\n key=\"bg\"\n lengthAngle={props.lengthAngle}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n startAngle={props.startAngle}\n stroke={props.background}\n />\n );\n }\n\n return paths;\n}\n","import React, { useState, useEffect } from 'react';\nimport type {\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from 'react';\nimport extendData from './extendData';\nimport renderLabels from './renderLabels';\nimport renderSegments from './renderSegments';\nimport type { Data, EventHandler, LabelRenderFunction } from '../commonTypes';\n\ntype Props = {\n animate?: boolean;\n animationDuration?: number;\n animationEasing?: string;\n background?: string;\n center?: [number, number];\n children?: ReactNode;\n className?: string;\n data: Data;\n lengthAngle?: number;\n lineWidth?: number;\n label?: LabelRenderFunction;\n labelPosition?: number;\n labelStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n onBlur?: EventHandler<FocusEvent>;\n onClick?: EventHandler<MouseEvent>;\n onFocus?: EventHandler<FocusEvent>;\n onKeyDown?: EventHandler<KeyboardEvent>;\n onMouseOut?: EventHandler<MouseEvent>;\n onMouseOver?: EventHandler<MouseEvent>;\n paddingAngle?: number;\n radius?: number;\n reveal?: number;\n rounded?: boolean;\n segmentsShift?: number | ((dataIndex: number) => number | undefined);\n segmentsStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n segmentsTabIndex?: number;\n startAngle?: number;\n style?: CSSProperties;\n totalValue?: number;\n viewBoxSize?: [number, number];\n};\n\nconst defaultProps = {\n animationDuration: 500,\n animationEasing: 'ease-out',\n center: [50, 50] as [number, number],\n data: [] as Data,\n labelPosition: 50,\n lengthAngle: 360,\n lineWidth: 100,\n paddingAngle: 0,\n radius: 50,\n startAngle: 0,\n viewBoxSize: [100, 100] as [number, number],\n};\n\nexport type PropsWithDefaults = Props & typeof defaultProps;\n\nexport function ReactMinimalPieChart(props: PropsWithDefaults) {\n const [revealOverride, setRevealOverride] = useState(\n props.animate ? 0 : null\n );\n useEffect(() => {\n if (props.animate) {\n return startInitialAnimation();\n }\n\n function startInitialAnimation() {\n let animationTimerId: NodeJS.Timeout | null;\n let animationRAFId: number | null;\n animationTimerId = setTimeout(() => {\n animationTimerId = null;\n animationRAFId = requestAnimationFrame(() => {\n animationRAFId = null;\n setRevealOverride(null); // Start animation\n });\n });\n\n return () => {\n animationTimerId && clearTimeout(animationTimerId);\n animationRAFId && cancelAnimationFrame(animationRAFId);\n };\n }\n }, []);\n\n const extendedData = extendData(props);\n return (\n <svg\n viewBox={`0 0 ${props.viewBoxSize[0]} ${props.viewBoxSize[1]}`}\n width=\"100%\"\n height=\"100%\"\n className={props.className}\n style={props.style}\n >\n {renderSegments(extendedData, props, revealOverride)}\n {props.label && renderLabels(extendedData, props)}\n {props.children}\n </svg>\n );\n}\n\nReactMinimalPieChart.defaultProps = defaultProps;\n"],"names":["degreesToRadians","degrees","Math","PI","valueBetween","value","min","max","extractPercentage","percentage","bisectorAngle","startAngle","lengthAngle","shiftVectorAlongAngle","angle","distance","angleRadians","dx","cos","dy","sin","isNumber","functionProp","prop","payload","sumValues","data","sum","i","length","extendData","totalAngle","totalValue","paddingAngle","chartStartAngle","total","normalizedTotalAngle","numberOfPaddings","abs","singlePaddingDegrees","sign","degreesTakenByPadding","degreesTakenByPaths","lastSegmentEnd","extendedData","dataEntry","valueInPercentage","push","Object","assign","ReactMinimalPieChartLabel","dataIndex","props","round","number","divisor","Number","EPSILON","evaluateTextAnchorPosition","labelPosition","lineWidth","labelHorizontalShift","innerRadius","renderLabelElement","renderLabel","labelProps","label","DefaultLabel","key","React","isValidElement","renderLabels","map","index","segmentsShift","distanceFromCenter","radius","labelRenderProps","x","center","y","textAnchor","style","labelStyle","partialCircle","cx","cy","r","start","end","fromX","fromY","toX","toY","large","sweep","module","makePathCommands","patchedLengthAngle","command","join","ReactMinimalPieChartPath","shift","reveal","rounded","title","pathRadius","pathCommands","strokeDasharray","strokeDashoffset","pathLength","undefined","combineSegmentTransitionsStyle","duration","easing","customStyle","transition","getRevealValue","animate","makeEventHandler","eventHandler","e","renderSegments","revealOverride","paths","segmentsStyle","Path","animationDuration","animationEasing","color","segmentsTabIndex","onBlur","onClick","onFocus","onKeyDown","onMouseOver","onMouseOut","background","unshift","defaultProps","viewBoxSize","ReactMinimalPieChart","useState","setRevealOverride","useEffect","startInitialAnimation","animationTimerId","animationRAFId","setTimeout","requestAnimationFrame","clearTimeout","cancelAnimationFrame","className","children"],"mappings":";;AAAO,SAASA,gBAAT,CAA0BC,OAA1B,EAA2C;AAChD,SAAQA,OAAO,GAAGC,IAAI,CAACC,EAAhB,GAAsB,GAA7B;AACD;AAEM,SAASC,YAAT,CAAsBC,KAAtB,EAAqCC,GAArC,EAAkDC,GAAlD,EAA+D;AACpE,MAAIF,KAAK,GAAGE,GAAZ,EAAiB,OAAOA,GAAP;AACjB,MAAIF,KAAK,GAAGC,GAAZ,EAAiB,OAAOA,GAAP;AACjB,SAAOD,KAAP;AACD;AAEM,SAASG,iBAAT,CAA2BH,KAA3B,EAA0CI,UAA1C,EAA8D;AACnE,SAAQA,U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,IAAA,OAAO,WAASA,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAAT,SAAiCxF,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAD1C;AAEE,IAAA,KAAK,EAAC,MAFR;AAGE,IAAA,MAAM,EAAC,MAHT;AAIE,IAAA,SAAS,EAAExF,KAAK,CAACoG,SAJnB;AAKE,IAAA,KAAK,EAAEpG,KAAK,CAAC8B;AALf,KAOGwC,cAAc,CAAC9E,YAAD,EAAeQ,KAAf,EAAsBuE,cAAtB,CAPjB,EAQGvE,KAAK,CAACc,KAAN,IAAeK,YAAY,CAAC3B,YAAD,EAAeQ,KAAf,CAR9B,EASGA,KAAK,CAACqG,QATT,CADF;AAaD;AAEDZ,oBAAoB,CAACF,YAArB,GAAoCA,YAApC;;;;"}
|
package/lib/index.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
|
-
|
|
7
5
|
var React = require('react');
|
|
8
|
-
|
|
6
|
+
|
|
7
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
+
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
9
10
|
|
|
10
11
|
function degreesToRadians(degrees) {
|
|
11
12
|
return degrees * Math.PI / 180;
|
|
@@ -92,16 +93,15 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
92
93
|
return target;
|
|
93
94
|
}
|
|
94
95
|
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
props = _objectWithoutPropertiesLoose(_ref, ["dataEntry", "dataIndex"]);
|
|
96
|
+
function ReactMinimalPieChartLabel(_ref) {
|
|
97
|
+
_ref.dataEntry;
|
|
98
|
+
_ref.dataIndex;
|
|
99
|
+
var props = _objectWithoutPropertiesLoose(_ref, ["dataEntry", "dataIndex"]);
|
|
99
100
|
|
|
100
|
-
return /*#__PURE__*/React__default.createElement("text", Object.assign({
|
|
101
|
+
return /*#__PURE__*/React__default['default'].createElement("text", Object.assign({
|
|
101
102
|
dominantBaseline: "central"
|
|
102
103
|
}, props));
|
|
103
104
|
}
|
|
104
|
-
Label.displayName = 'ReactMinimalPieChartLabel';
|
|
105
105
|
|
|
106
106
|
function round(number) {
|
|
107
107
|
var divisor = 1e14; // 14 decimals
|
|
@@ -139,12 +139,12 @@ function renderLabelElement(renderLabel, labelProps) {
|
|
|
139
139
|
var label = renderLabel(labelProps);
|
|
140
140
|
|
|
141
141
|
if (typeof label === 'string' || typeof label === 'number') {
|
|
142
|
-
return /*#__PURE__*/React__default.createElement(
|
|
142
|
+
return /*#__PURE__*/React__default['default'].createElement(ReactMinimalPieChartLabel, Object.assign({
|
|
143
143
|
key: "label-" + (labelProps.dataEntry.key || labelProps.dataIndex)
|
|
144
144
|
}, labelProps), label);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
if (React__default.isValidElement(label)) {
|
|
147
|
+
if (React__default['default'].isValidElement(label)) {
|
|
148
148
|
return label;
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -202,7 +202,7 @@ function makePathCommands(cx, cy, startAngle, lengthAngle, radius) {
|
|
|
202
202
|
return command.join(' ');
|
|
203
203
|
}).join(' ');
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function ReactMinimalPieChartPath(_ref) {
|
|
206
206
|
var cx = _ref.cx,
|
|
207
207
|
cy = _ref.cy,
|
|
208
208
|
lengthAngle = _ref.lengthAngle,
|
|
@@ -233,16 +233,15 @@ function Path(_ref) {
|
|
|
233
233
|
strokeDashoffset = strokeDasharray - extractPercentage(strokeDasharray, reveal);
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
-
return /*#__PURE__*/React__default.createElement("path", Object.assign({
|
|
236
|
+
return /*#__PURE__*/React__default['default'].createElement("path", Object.assign({
|
|
237
237
|
d: pathCommands,
|
|
238
238
|
fill: "none",
|
|
239
239
|
strokeWidth: lineWidth,
|
|
240
240
|
strokeDasharray: strokeDasharray,
|
|
241
241
|
strokeDashoffset: strokeDashoffset,
|
|
242
242
|
strokeLinecap: rounded ? 'round' : undefined
|
|
243
|
-
}, props), title && /*#__PURE__*/React__default.createElement("title", null, title));
|
|
243
|
+
}, props), title && /*#__PURE__*/React__default['default'].createElement("title", null, title));
|
|
244
244
|
}
|
|
245
|
-
Path.displayName = 'ReactMinimalPieChartPath';
|
|
246
245
|
|
|
247
246
|
function combineSegmentTransitionsStyle(duration, easing, customStyle) {
|
|
248
247
|
// Merge chart's animation CSS transition with "transition" found to customStyle
|
|
@@ -282,7 +281,7 @@ function renderSegments(data, props, revealOverride) {
|
|
|
282
281
|
var lineWidth = extractPercentage(radius, props.lineWidth);
|
|
283
282
|
var paths = data.map(function (dataEntry, index) {
|
|
284
283
|
var segmentsStyle = functionProp(props.segmentsStyle, index);
|
|
285
|
-
return /*#__PURE__*/React__default.createElement(
|
|
284
|
+
return /*#__PURE__*/React__default['default'].createElement(ReactMinimalPieChartPath, {
|
|
286
285
|
cx: cx,
|
|
287
286
|
cy: cy,
|
|
288
287
|
key: dataEntry.key || index,
|
|
@@ -307,7 +306,7 @@ function renderSegments(data, props, revealOverride) {
|
|
|
307
306
|
});
|
|
308
307
|
|
|
309
308
|
if (props.background) {
|
|
310
|
-
paths.unshift( /*#__PURE__*/React__default.createElement(
|
|
309
|
+
paths.unshift( /*#__PURE__*/React__default['default'].createElement(ReactMinimalPieChartPath, {
|
|
311
310
|
cx: cx,
|
|
312
311
|
cy: cy,
|
|
313
312
|
key: "bg",
|
|
@@ -336,7 +335,7 @@ var defaultProps = {
|
|
|
336
335
|
startAngle: 0,
|
|
337
336
|
viewBoxSize: [100, 100]
|
|
338
337
|
};
|
|
339
|
-
function
|
|
338
|
+
function ReactMinimalPieChart(props) {
|
|
340
339
|
var _useState = React.useState(props.animate ? 0 : null),
|
|
341
340
|
revealOverride = _useState[0],
|
|
342
341
|
setRevealOverride = _useState[1];
|
|
@@ -363,7 +362,7 @@ function PieChart(props) {
|
|
|
363
362
|
}
|
|
364
363
|
}, []);
|
|
365
364
|
var extendedData = extendData(props);
|
|
366
|
-
return /*#__PURE__*/React__default.createElement("svg", {
|
|
365
|
+
return /*#__PURE__*/React__default['default'].createElement("svg", {
|
|
367
366
|
viewBox: "0 0 " + props.viewBoxSize[0] + " " + props.viewBoxSize[1],
|
|
368
367
|
width: "100%",
|
|
369
368
|
height: "100%",
|
|
@@ -371,8 +370,7 @@ function PieChart(props) {
|
|
|
371
370
|
style: props.style
|
|
372
371
|
}, renderSegments(extendedData, props, revealOverride), props.label && renderLabels(extendedData, props), props.children);
|
|
373
372
|
}
|
|
374
|
-
|
|
375
|
-
PieChart.displayName = 'ReactMinimalPieChart';
|
|
373
|
+
ReactMinimalPieChart.defaultProps = defaultProps;
|
|
376
374
|
|
|
377
|
-
exports.PieChart =
|
|
375
|
+
exports.PieChart = ReactMinimalPieChart;
|
|
378
376
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/Chart/extendData.ts","../src/Label.tsx","../src/Chart/renderLabels.tsx","../node_modules/svg-partial-circle/index.js","../src/Path.tsx","../src/Chart/renderSegments.tsx","../src/Chart/Chart.tsx"],"sourcesContent":["export function degreesToRadians(degrees: number) {\n return (degrees * Math.PI) / 180;\n}\n\nexport function valueBetween(value: number, min: number, max: number) {\n if (value > max) return max;\n if (value < min) return min;\n return value;\n}\n\nexport function extractPercentage(value: number, percentage: number) {\n return (percentage / 100) * value;\n}\n\nexport function bisectorAngle(startAngle: number, lengthAngle: number) {\n return startAngle + lengthAngle / 2;\n}\n\nexport function shiftVectorAlongAngle(angle: number, distance: number) {\n const angleRadians = degreesToRadians(angle);\n return {\n dx: distance * Math.cos(angleRadians),\n dy: distance * Math.sin(angleRadians),\n };\n}\n\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number';\n}\n\nexport function functionProp<Prop, Payload>(\n prop: Prop,\n payload?: Payload\n): Prop extends (...args: any) => any ? ReturnType<Prop> : Prop {\n return typeof prop === 'function' ? prop(payload) : prop;\n}\n","import { extractPercentage, valueBetween } from '../utils';\nimport type { Data, ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction sumValues(data: Data): number {\n let sum = 0;\n for (let i = 0; i < data.length; i++) {\n sum += data[i].value;\n }\n return sum;\n}\n\n// Append \"percentage\", \"degrees\" and \"startAngle\" to each data entry\nexport default function extendData({\n data,\n lengthAngle: totalAngle,\n totalValue,\n paddingAngle,\n startAngle: chartStartAngle,\n}: ChartProps): ExtendedData {\n const total = totalValue || sumValues(data);\n const normalizedTotalAngle = valueBetween(totalAngle, -360, 360);\n const numberOfPaddings =\n Math.abs(normalizedTotalAngle) === 360 ? data.length : data.length - 1;\n const singlePaddingDegrees = Math.abs(paddingAngle) * Math.sign(totalAngle);\n const degreesTakenByPadding = singlePaddingDegrees * numberOfPaddings;\n const degreesTakenByPaths = normalizedTotalAngle - degreesTakenByPadding;\n let lastSegmentEnd = 0;\n const extendedData = [];\n\n // @NOTE: Shall we evaluate percentage accordingly to dataEntry.value's sign?\n for (let i = 0; i < data.length; i++) {\n const dataEntry = data[i];\n const valueInPercentage = total === 0 ? 0 : (dataEntry.value / total) * 100;\n const degrees = extractPercentage(degreesTakenByPaths, valueInPercentage);\n const startAngle = lastSegmentEnd + chartStartAngle;\n lastSegmentEnd = lastSegmentEnd + degrees + singlePaddingDegrees;\n extendedData.push(\n Object.assign(\n {\n percentage: valueInPercentage,\n startAngle,\n degrees,\n },\n dataEntry\n )\n );\n }\n return extendedData;\n}\n","import React from 'react';\nimport type { CSSProperties, SVGProps } from 'react';\nimport type { ExtendedDataEntry } from './commonTypes';\n\nexport type LabelRenderProps = {\n x: number;\n y: number;\n dx: number;\n dy: number;\n textAnchor: string;\n dataEntry: ExtendedDataEntry;\n dataIndex: number;\n style?: CSSProperties;\n};\n\ntype Props = SVGProps<SVGTextElement> & LabelRenderProps;\n\nexport default function Label({ dataEntry, dataIndex, ...props }: Props) {\n return <text dominantBaseline=\"central\" {...props} />;\n}\n\nLabel.displayName = 'ReactMinimalPieChartLabel';\n","import React from 'react';\nimport DefaultLabel from '../Label';\nimport {\n bisectorAngle,\n extractPercentage,\n functionProp,\n shiftVectorAlongAngle,\n} from '../utils';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\nimport type { LabelRenderProps } from '../Label';\nimport type { ExtendedData, LabelRenderFunction } from '../commonTypes';\n\nfunction round(number: number): number {\n const divisor = 1e14; // 14 decimals\n return Math.round((number + Number.EPSILON) * divisor) / divisor;\n}\n\nfunction evaluateTextAnchorPosition({\n labelPosition,\n lineWidth,\n labelHorizontalShift,\n}: {\n labelPosition: number;\n lineWidth: number;\n labelHorizontalShift: number;\n}) {\n const dx = round(labelHorizontalShift);\n // Label in the vertical center\n if (dx === 0) {\n return 'middle';\n }\n // Outward label\n if (labelPosition > 100) {\n return dx > 0 ? 'start' : 'end';\n }\n // Inward label\n const innerRadius = 100 - lineWidth;\n if (labelPosition < innerRadius) {\n return dx > 0 ? 'end' : 'start';\n }\n // Overlying label\n return 'middle';\n}\n\nfunction renderLabelElement(\n renderLabel: LabelRenderFunction,\n labelProps: LabelRenderProps\n): JSX.Element | null {\n const label = renderLabel(labelProps);\n if (typeof label === 'string' || typeof label === 'number') {\n return (\n <DefaultLabel\n key={`label-${labelProps.dataEntry.key || labelProps.dataIndex}`}\n {...labelProps}\n >\n {label}\n </DefaultLabel>\n );\n }\n\n if (React.isValidElement(label)) {\n return label;\n }\n return null;\n}\n\nexport default function renderLabels(data: ExtendedData, props: ChartProps) {\n return data.map((dataEntry, index) => {\n const segmentsShift = functionProp(props.segmentsShift, index) ?? 0;\n const distanceFromCenter =\n extractPercentage(props.radius, props.labelPosition) + segmentsShift;\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(dataEntry.startAngle, dataEntry.degrees),\n distanceFromCenter\n );\n\n // This object is passed as argument to the \"label\" function prop\n const labelRenderProps = {\n x: props.center[0],\n y: props.center[1],\n dx,\n dy,\n textAnchor: evaluateTextAnchorPosition({\n labelPosition: props.labelPosition,\n lineWidth: props.lineWidth,\n labelHorizontalShift: dx,\n }),\n dataEntry,\n dataIndex: index,\n style: functionProp(props.labelStyle, index),\n };\n\n return props.label && renderLabelElement(props.label, labelRenderProps);\n });\n}\n","'use strict'\n\n// from http://stackoverflow.com/a/18473154\nconst partialCircle = (cx, cy, r, start, end) => {\n\tconst length = end - start\n\tif (length === 0) return []\n\n\tconst fromX = r * Math.cos(start) + cx\n\tconst fromY = r * Math.sin(start) + cy\n\tconst toX = r * Math.cos(end) + cx\n\tconst toY = r * Math.sin(end) + cy\n\tconst large = Math.abs(length) <= Math.PI ? '0' : '1'\n\tconst sweep = length < 0 ? '0' : '1'\n\n\treturn [\n\t\t['M', fromX, fromY],\n\t\t['A', r, r, 0, large, sweep, toX, toY]\n\t]\n}\n\nmodule.exports = partialCircle\n","import React from 'react';\nimport type { SVGProps } from 'react';\nimport partialCircle from 'svg-partial-circle';\nimport {\n bisectorAngle,\n degreesToRadians,\n extractPercentage,\n isNumber,\n shiftVectorAlongAngle,\n valueBetween,\n} from './utils';\n\nexport function makePathCommands(\n cx: number,\n cy: number,\n startAngle: number,\n lengthAngle: number,\n radius: number\n): string {\n const patchedLengthAngle = valueBetween(lengthAngle, -359.999, 359.999);\n\n return partialCircle(\n cx,\n cy, // center X and Y\n radius,\n degreesToRadians(startAngle),\n degreesToRadians(startAngle + patchedLengthAngle)\n )\n .map((command) => command.join(' '))\n .join(' ');\n}\n\ntype Props = SVGProps<SVGPathElement> & {\n cx: number;\n cy: number;\n lengthAngle: number;\n lineWidth: number;\n radius: number;\n reveal?: number;\n rounded?: boolean;\n shift?: number;\n startAngle: number;\n title?: string | number;\n};\n\nexport default function Path({\n cx,\n cy,\n lengthAngle,\n lineWidth,\n radius,\n shift = 0,\n reveal,\n rounded,\n startAngle,\n title,\n ...props\n}: Props) {\n const pathRadius = radius - lineWidth / 2;\n //@NOTE This shift might be rendered as a translation in future\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(startAngle, lengthAngle),\n shift\n );\n\n const pathCommands = makePathCommands(\n cx + dx,\n cy + dy,\n startAngle,\n lengthAngle,\n pathRadius\n );\n let strokeDasharray;\n let strokeDashoffset;\n\n // Animate/hide paths with \"stroke-dasharray\" + \"stroke-dashoffset\"\n // https://css-tricks.com/svg-line-animation-works/\n if (isNumber(reveal)) {\n const pathLength = degreesToRadians(pathRadius) * lengthAngle;\n strokeDasharray = Math.abs(pathLength);\n strokeDashoffset =\n strokeDasharray - extractPercentage(strokeDasharray, reveal);\n }\n\n return (\n <path\n d={pathCommands}\n fill=\"none\"\n strokeWidth={lineWidth}\n strokeDasharray={strokeDasharray}\n strokeDashoffset={strokeDashoffset}\n strokeLinecap={rounded ? 'round' : undefined}\n {...props}\n >\n {title && <title>{title}</title>}\n </path>\n );\n}\n\nPath.displayName = 'ReactMinimalPieChartPath';\n","import React from 'react';\nimport type { CSSProperties } from 'react';\nimport Path from '../Path';\nimport { extractPercentage, functionProp, isNumber } from '../utils';\nimport type { ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction combineSegmentTransitionsStyle(\n duration: number,\n easing: string,\n customStyle?: CSSProperties\n): { transition: string } {\n // Merge chart's animation CSS transition with \"transition\" found to customStyle\n let transition = `stroke-dashoffset ${duration}ms ${easing}`;\n if (customStyle && customStyle.transition) {\n transition = `${transition},${customStyle.transition}`;\n }\n return {\n transition,\n };\n}\n\nfunction getRevealValue<Reveal>(props: { reveal?: Reveal; animate?: boolean }) {\n //@NOTE When animation is on, chart has to be fully revealed when reveal is not set\n if (props.animate && !isNumber(props.reveal)) {\n return 100;\n }\n return props.reveal;\n}\n\nfunction makeEventHandler<Event, EventHandler, Payload>(\n eventHandler: undefined | (EventHandler & Function),\n payload: Payload\n) {\n return (\n eventHandler &&\n ((e: Event) => {\n eventHandler(e, payload);\n })\n );\n}\n\nexport default function renderSegments(\n data: ExtendedData,\n props: ChartProps,\n revealOverride?: null | number\n) {\n // @NOTE this should go in Path component. Here for performance reasons\n const reveal = revealOverride ?? getRevealValue(props);\n const {\n radius,\n center: [cx, cy],\n } = props;\n const lineWidth = extractPercentage(radius, props.lineWidth);\n const paths = data.map((dataEntry, index) => {\n const segmentsStyle = functionProp(props.segmentsStyle, index);\n return (\n <Path\n cx={cx}\n cy={cy}\n key={dataEntry.key || index}\n lengthAngle={dataEntry.degrees}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n reveal={reveal}\n shift={functionProp(props.segmentsShift, index)}\n startAngle={dataEntry.startAngle}\n title={dataEntry.title}\n style={Object.assign(\n {},\n segmentsStyle,\n props.animate &&\n combineSegmentTransitionsStyle(\n props.animationDuration,\n props.animationEasing,\n segmentsStyle\n )\n )}\n stroke={dataEntry.color}\n tabIndex={props.segmentsTabIndex}\n onBlur={makeEventHandler(props.onBlur, index)}\n onClick={makeEventHandler(props.onClick, index)}\n onFocus={makeEventHandler(props.onFocus, index)}\n onKeyDown={makeEventHandler(props.onKeyDown, index)}\n onMouseOver={makeEventHandler(props.onMouseOver, index)}\n onMouseOut={makeEventHandler(props.onMouseOut, index)}\n />\n );\n });\n\n if (props.background) {\n paths.unshift(\n <Path\n cx={cx}\n cy={cy}\n key=\"bg\"\n lengthAngle={props.lengthAngle}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n startAngle={props.startAngle}\n stroke={props.background}\n />\n );\n }\n\n return paths;\n}\n","import React, { useState, useEffect } from 'react';\nimport type {\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from 'react';\nimport extendData from './extendData';\nimport renderLabels from './renderLabels';\nimport renderSegments from './renderSegments';\nimport type { Data, EventHandler, LabelRenderFunction } from '../commonTypes';\n\ntype Props = {\n animate?: boolean;\n animationDuration?: number;\n animationEasing?: string;\n background?: string;\n center?: [number, number];\n children?: ReactNode;\n className?: string;\n data: Data;\n lengthAngle?: number;\n lineWidth?: number;\n label?: LabelRenderFunction;\n labelPosition?: number;\n labelStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n onBlur?: EventHandler<FocusEvent>;\n onClick?: EventHandler<MouseEvent>;\n onFocus?: EventHandler<FocusEvent>;\n onKeyDown?: EventHandler<KeyboardEvent>;\n onMouseOut?: EventHandler<MouseEvent>;\n onMouseOver?: EventHandler<MouseEvent>;\n paddingAngle?: number;\n radius?: number;\n reveal?: number;\n rounded?: boolean;\n segmentsShift?: number | ((dataIndex: number) => number | undefined);\n segmentsStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n segmentsTabIndex?: number;\n startAngle?: number;\n style?: CSSProperties;\n totalValue?: number;\n viewBoxSize?: [number, number];\n};\n\nconst defaultProps = {\n animationDuration: 500,\n animationEasing: 'ease-out',\n center: [50, 50] as [number, number],\n data: [] as Data,\n labelPosition: 50,\n lengthAngle: 360,\n lineWidth: 100,\n paddingAngle: 0,\n radius: 50,\n startAngle: 0,\n viewBoxSize: [100, 100] as [number, number],\n};\n\nexport type PropsWithDefaults = Props & typeof defaultProps;\n\nexport function PieChart(props: PropsWithDefaults) {\n const [revealOverride, setRevealOverride] = useState(\n props.animate ? 0 : null\n );\n useEffect(() => {\n if (props.animate) {\n return startInitialAnimation();\n }\n\n function startInitialAnimation() {\n let animationTimerId: number | null;\n let animationRAFId: number | null;\n animationTimerId = setTimeout(() => {\n animationTimerId = null;\n animationRAFId = requestAnimationFrame(() => {\n animationRAFId = null;\n setRevealOverride(null); // Start animation\n });\n });\n\n return () => {\n animationTimerId && clearTimeout(animationTimerId);\n animationRAFId && cancelAnimationFrame(animationRAFId);\n };\n }\n }, []);\n\n const extendedData = extendData(props);\n return (\n <svg\n viewBox={`0 0 ${props.viewBoxSize[0]} ${props.viewBoxSize[1]}`}\n width=\"100%\"\n height=\"100%\"\n className={props.className}\n style={props.style}\n >\n {renderSegments(extendedData, props, revealOverride)}\n {props.label && renderLabels(extendedData, props)}\n {props.children}\n </svg>\n );\n}\n\nPieChart.defaultProps = defaultProps;\nPieChart.displayName = 'ReactMinimalPieChart';\n"],"names":["degreesToRadians","degrees","Math","PI","valueBetween","value","min","max","extractPercentage","percentage","bisectorAngle","startAngle","lengthAngle","shiftVectorAlongAngle","angle","distance","angleRadians","dx","cos","dy","sin","isNumber","functionProp","prop","payload","sumValues","data","sum","i","length","extendData","totalAngle","totalValue","paddingAngle","chartStartAngle","total","normalizedTotalAngle","numberOfPaddings","abs","singlePaddingDegrees","sign","degreesTakenByPadding","degreesTakenByPaths","lastSegmentEnd","extendedData","dataEntry","valueInPercentage","push","Object","assign","Label","dataIndex","props","React","displayName","round","number","divisor","Number","EPSILON","evaluateTextAnchorPosition","labelPosition","lineWidth","labelHorizontalShift","innerRadius","renderLabelElement","renderLabel","labelProps","label","DefaultLabel","key","isValidElement","renderLabels","map","index","segmentsShift","distanceFromCenter","radius","labelRenderProps","x","center","y","textAnchor","style","labelStyle","partialCircle","cx","cy","r","start","end","fromX","fromY","toX","toY","large","sweep","module","makePathCommands","patchedLengthAngle","command","join","Path","shift","reveal","rounded","title","pathRadius","pathCommands","strokeDasharray","strokeDashoffset","pathLength","undefined","combineSegmentTransitionsStyle","duration","easing","customStyle","transition","getRevealValue","animate","makeEventHandler","eventHandler","e","renderSegments","revealOverride","paths","segmentsStyle","animationDuration","animationEasing","color","segmentsTabIndex","onBlur","onClick","onFocus","onKeyDown","onMouseOver","onMouseOut","background","unshift","defaultProps","viewBoxSize","PieChart","useState","setRevealOverride","useEffect","startInitialAnimation","animationTimerId","animationRAFId","setTimeout","requestAnimationFrame","clearTimeout","cancelAnimationFrame","className","children"],"mappings":";;;;;;;;;AAAO,SAASA,gBAAT,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CAAjB,CAF2C;SAAP,CAAtC;OAF2B,CAA7B;aAQO,YAAM;QACXG,gBAAgB,IAAII,YAAY,CAACJ,gBAAD,CAAhC;QACAC,cAAc,IAAII,oBAAoB,CAACJ,cAAD,CAAtC;OAFF;;GAhBK,EAqBN,EArBM,CAAT;MAuBMvG,YAAY,GAAGd,UAAU,CAACsB,KAAD,CAA/B;sBAEEC;IACE,OAAO,WAASD,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAAT,SAAiCxF,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAD1C;IAEE,KAAK,EAAC,MAFR;IAGE,MAAM,EAAC,MAHT;IAIE,SAAS,EAAExF,KAAK,CAACoG,SAJnB;IAKE,KAAK,EAAEpG,KAAK,CAAC+B;KAEZwC,cAAc,CAAC/E,YAAD,EAAeQ,KAAf,EAAsBwE,cAAtB,CAPjB,EAQGxE,KAAK,CAACgB,KAAN,IAAeI,YAAY,CAAC5B,YAAD,EAAeQ,KAAf,CAR9B,EASGA,KAAK,CAACqG,QATT,CADF;;AAeFZ,QAAQ,CAACF,YAAT,GAAwBA,YAAxB;AACAE,QAAQ,CAACvF,WAAT,GAAuB,sBAAvB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/Chart/extendData.ts","../src/Label.tsx","../src/Chart/renderLabels.tsx","../node_modules/svg-partial-circle/index.js","../src/Path.tsx","../src/Chart/renderSegments.tsx","../src/Chart/Chart.tsx"],"sourcesContent":["export function degreesToRadians(degrees: number) {\n return (degrees * Math.PI) / 180;\n}\n\nexport function valueBetween(value: number, min: number, max: number) {\n if (value > max) return max;\n if (value < min) return min;\n return value;\n}\n\nexport function extractPercentage(value: number, percentage: number) {\n return (percentage / 100) * value;\n}\n\nexport function bisectorAngle(startAngle: number, lengthAngle: number) {\n return startAngle + lengthAngle / 2;\n}\n\nexport function shiftVectorAlongAngle(angle: number, distance: number) {\n const angleRadians = degreesToRadians(angle);\n return {\n dx: distance * Math.cos(angleRadians),\n dy: distance * Math.sin(angleRadians),\n };\n}\n\nexport function isNumber(value: unknown): value is number {\n return typeof value === 'number';\n}\n\nexport function functionProp<Prop, Payload>(\n prop: Prop,\n payload?: Payload\n): Prop extends (...args: any) => any ? ReturnType<Prop> : Prop {\n return typeof prop === 'function' ? prop(payload) : prop;\n}\n","import { extractPercentage, valueBetween } from '../utils';\nimport type { Data, ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction sumValues(data: Data): number {\n let sum = 0;\n for (let i = 0; i < data.length; i++) {\n sum += data[i].value;\n }\n return sum;\n}\n\n// Append \"percentage\", \"degrees\" and \"startAngle\" to each data entry\nexport default function extendData({\n data,\n lengthAngle: totalAngle,\n totalValue,\n paddingAngle,\n startAngle: chartStartAngle,\n}: ChartProps): ExtendedData {\n const total = totalValue || sumValues(data);\n const normalizedTotalAngle = valueBetween(totalAngle, -360, 360);\n const numberOfPaddings =\n Math.abs(normalizedTotalAngle) === 360 ? data.length : data.length - 1;\n const singlePaddingDegrees = Math.abs(paddingAngle) * Math.sign(totalAngle);\n const degreesTakenByPadding = singlePaddingDegrees * numberOfPaddings;\n const degreesTakenByPaths = normalizedTotalAngle - degreesTakenByPadding;\n let lastSegmentEnd = 0;\n const extendedData = [];\n\n // @NOTE: Shall we evaluate percentage accordingly to dataEntry.value's sign?\n for (let i = 0; i < data.length; i++) {\n const dataEntry = data[i];\n const valueInPercentage = total === 0 ? 0 : (dataEntry.value / total) * 100;\n const degrees = extractPercentage(degreesTakenByPaths, valueInPercentage);\n const startAngle = lastSegmentEnd + chartStartAngle;\n lastSegmentEnd = lastSegmentEnd + degrees + singlePaddingDegrees;\n extendedData.push(\n Object.assign(\n {\n percentage: valueInPercentage,\n startAngle,\n degrees,\n },\n dataEntry\n )\n );\n }\n return extendedData;\n}\n","import React from 'react';\nimport type { CSSProperties, SVGProps } from 'react';\nimport type { ExtendedDataEntry } from './commonTypes';\n\nexport type LabelRenderProps = {\n x: number;\n y: number;\n dx: number;\n dy: number;\n textAnchor: string;\n dataEntry: ExtendedDataEntry;\n dataIndex: number;\n style?: CSSProperties;\n};\n\ntype Props = SVGProps<SVGTextElement> & LabelRenderProps;\n\nexport default function ReactMinimalPieChartLabel({\n dataEntry,\n dataIndex,\n ...props\n}: Props) {\n return <text dominantBaseline=\"central\" {...props} />;\n}\n","import React from 'react';\nimport DefaultLabel from '../Label';\nimport {\n bisectorAngle,\n extractPercentage,\n functionProp,\n shiftVectorAlongAngle,\n} from '../utils';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\nimport type { LabelRenderProps } from '../Label';\nimport type { ExtendedData, LabelRenderFunction } from '../commonTypes';\n\nfunction round(number: number): number {\n const divisor = 1e14; // 14 decimals\n return Math.round((number + Number.EPSILON) * divisor) / divisor;\n}\n\nfunction evaluateTextAnchorPosition({\n labelPosition,\n lineWidth,\n labelHorizontalShift,\n}: {\n labelPosition: number;\n lineWidth: number;\n labelHorizontalShift: number;\n}) {\n const dx = round(labelHorizontalShift);\n // Label in the vertical center\n if (dx === 0) {\n return 'middle';\n }\n // Outward label\n if (labelPosition > 100) {\n return dx > 0 ? 'start' : 'end';\n }\n // Inward label\n const innerRadius = 100 - lineWidth;\n if (labelPosition < innerRadius) {\n return dx > 0 ? 'end' : 'start';\n }\n // Overlying label\n return 'middle';\n}\n\nfunction renderLabelElement(\n renderLabel: LabelRenderFunction,\n labelProps: LabelRenderProps\n): JSX.Element | null {\n const label = renderLabel(labelProps);\n if (typeof label === 'string' || typeof label === 'number') {\n return (\n <DefaultLabel\n key={`label-${labelProps.dataEntry.key || labelProps.dataIndex}`}\n {...labelProps}\n >\n {label}\n </DefaultLabel>\n );\n }\n\n if (React.isValidElement(label)) {\n return label;\n }\n return null;\n}\n\nexport default function renderLabels(data: ExtendedData, props: ChartProps) {\n return data.map((dataEntry, index) => {\n const segmentsShift = functionProp(props.segmentsShift, index) ?? 0;\n const distanceFromCenter =\n extractPercentage(props.radius, props.labelPosition) + segmentsShift;\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(dataEntry.startAngle, dataEntry.degrees),\n distanceFromCenter\n );\n\n // This object is passed as argument to the \"label\" function prop\n const labelRenderProps = {\n x: props.center[0],\n y: props.center[1],\n dx,\n dy,\n textAnchor: evaluateTextAnchorPosition({\n labelPosition: props.labelPosition,\n lineWidth: props.lineWidth,\n labelHorizontalShift: dx,\n }),\n dataEntry,\n dataIndex: index,\n style: functionProp(props.labelStyle, index),\n };\n\n return props.label && renderLabelElement(props.label, labelRenderProps);\n });\n}\n","'use strict'\n\n// from http://stackoverflow.com/a/18473154\nconst partialCircle = (cx, cy, r, start, end) => {\n\tconst length = end - start\n\tif (length === 0) return []\n\n\tconst fromX = r * Math.cos(start) + cx\n\tconst fromY = r * Math.sin(start) + cy\n\tconst toX = r * Math.cos(end) + cx\n\tconst toY = r * Math.sin(end) + cy\n\tconst large = Math.abs(length) <= Math.PI ? '0' : '1'\n\tconst sweep = length < 0 ? '0' : '1'\n\n\treturn [\n\t\t['M', fromX, fromY],\n\t\t['A', r, r, 0, large, sweep, toX, toY]\n\t]\n}\n\nmodule.exports = partialCircle\n","import React from 'react';\nimport type { SVGProps } from 'react';\nimport partialCircle from 'svg-partial-circle';\nimport {\n bisectorAngle,\n degreesToRadians,\n extractPercentage,\n isNumber,\n shiftVectorAlongAngle,\n valueBetween,\n} from './utils';\n\nexport function makePathCommands(\n cx: number,\n cy: number,\n startAngle: number,\n lengthAngle: number,\n radius: number\n): string {\n const patchedLengthAngle = valueBetween(lengthAngle, -359.999, 359.999);\n\n return partialCircle(\n cx,\n cy, // center X and Y\n radius,\n degreesToRadians(startAngle),\n degreesToRadians(startAngle + patchedLengthAngle)\n )\n .map((command) => command.join(' '))\n .join(' ');\n}\n\ntype Props = SVGProps<SVGPathElement> & {\n cx: number;\n cy: number;\n lengthAngle: number;\n lineWidth: number;\n radius: number;\n reveal?: number;\n rounded?: boolean;\n shift?: number;\n startAngle: number;\n title?: string | number;\n};\n\nexport default function ReactMinimalPieChartPath({\n cx,\n cy,\n lengthAngle,\n lineWidth,\n radius,\n shift = 0,\n reveal,\n rounded,\n startAngle,\n title,\n ...props\n}: Props) {\n const pathRadius = radius - lineWidth / 2;\n //@NOTE This shift might be rendered as a translation in future\n const { dx, dy } = shiftVectorAlongAngle(\n bisectorAngle(startAngle, lengthAngle),\n shift\n );\n\n const pathCommands = makePathCommands(\n cx + dx,\n cy + dy,\n startAngle,\n lengthAngle,\n pathRadius\n );\n let strokeDasharray;\n let strokeDashoffset;\n\n // Animate/hide paths with \"stroke-dasharray\" + \"stroke-dashoffset\"\n // https://css-tricks.com/svg-line-animation-works/\n if (isNumber(reveal)) {\n const pathLength = degreesToRadians(pathRadius) * lengthAngle;\n strokeDasharray = Math.abs(pathLength);\n strokeDashoffset =\n strokeDasharray - extractPercentage(strokeDasharray, reveal);\n }\n\n return (\n <path\n d={pathCommands}\n fill=\"none\"\n strokeWidth={lineWidth}\n strokeDasharray={strokeDasharray}\n strokeDashoffset={strokeDashoffset}\n strokeLinecap={rounded ? 'round' : undefined}\n {...props}\n >\n {title && <title>{title}</title>}\n </path>\n );\n}\n","import React from 'react';\nimport type { CSSProperties } from 'react';\nimport Path from '../Path';\nimport { extractPercentage, functionProp, isNumber } from '../utils';\nimport type { ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction combineSegmentTransitionsStyle(\n duration: number,\n easing: string,\n customStyle?: CSSProperties\n): { transition: string } {\n // Merge chart's animation CSS transition with \"transition\" found to customStyle\n let transition = `stroke-dashoffset ${duration}ms ${easing}`;\n if (customStyle && customStyle.transition) {\n transition = `${transition},${customStyle.transition}`;\n }\n return {\n transition,\n };\n}\n\nfunction getRevealValue<Reveal>(props: { reveal?: Reveal; animate?: boolean }) {\n //@NOTE When animation is on, chart has to be fully revealed when reveal is not set\n if (props.animate && !isNumber(props.reveal)) {\n return 100;\n }\n return props.reveal;\n}\n\nfunction makeEventHandler<Event, EventHandler, Payload>(\n eventHandler: undefined | (EventHandler & Function),\n payload: Payload\n) {\n return (\n eventHandler &&\n ((e: Event) => {\n eventHandler(e, payload);\n })\n );\n}\n\nexport default function renderSegments(\n data: ExtendedData,\n props: ChartProps,\n revealOverride?: null | number\n) {\n // @NOTE this should go in Path component. Here for performance reasons\n const reveal = revealOverride ?? getRevealValue(props);\n const {\n radius,\n center: [cx, cy],\n } = props;\n const lineWidth = extractPercentage(radius, props.lineWidth);\n const paths = data.map((dataEntry, index) => {\n const segmentsStyle = functionProp(props.segmentsStyle, index);\n return (\n <Path\n cx={cx}\n cy={cy}\n key={dataEntry.key || index}\n lengthAngle={dataEntry.degrees}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n reveal={reveal}\n shift={functionProp(props.segmentsShift, index)}\n startAngle={dataEntry.startAngle}\n title={dataEntry.title}\n style={Object.assign(\n {},\n segmentsStyle,\n props.animate &&\n combineSegmentTransitionsStyle(\n props.animationDuration,\n props.animationEasing,\n segmentsStyle\n )\n )}\n stroke={dataEntry.color}\n tabIndex={props.segmentsTabIndex}\n onBlur={makeEventHandler(props.onBlur, index)}\n onClick={makeEventHandler(props.onClick, index)}\n onFocus={makeEventHandler(props.onFocus, index)}\n onKeyDown={makeEventHandler(props.onKeyDown, index)}\n onMouseOver={makeEventHandler(props.onMouseOver, index)}\n onMouseOut={makeEventHandler(props.onMouseOut, index)}\n />\n );\n });\n\n if (props.background) {\n paths.unshift(\n <Path\n cx={cx}\n cy={cy}\n key=\"bg\"\n lengthAngle={props.lengthAngle}\n lineWidth={lineWidth}\n radius={radius}\n rounded={props.rounded}\n startAngle={props.startAngle}\n stroke={props.background}\n />\n );\n }\n\n return paths;\n}\n","import React, { useState, useEffect } from 'react';\nimport type {\n CSSProperties,\n FocusEvent,\n KeyboardEvent,\n MouseEvent,\n ReactNode,\n} from 'react';\nimport extendData from './extendData';\nimport renderLabels from './renderLabels';\nimport renderSegments from './renderSegments';\nimport type { Data, EventHandler, LabelRenderFunction } from '../commonTypes';\n\ntype Props = {\n animate?: boolean;\n animationDuration?: number;\n animationEasing?: string;\n background?: string;\n center?: [number, number];\n children?: ReactNode;\n className?: string;\n data: Data;\n lengthAngle?: number;\n lineWidth?: number;\n label?: LabelRenderFunction;\n labelPosition?: number;\n labelStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n onBlur?: EventHandler<FocusEvent>;\n onClick?: EventHandler<MouseEvent>;\n onFocus?: EventHandler<FocusEvent>;\n onKeyDown?: EventHandler<KeyboardEvent>;\n onMouseOut?: EventHandler<MouseEvent>;\n onMouseOver?: EventHandler<MouseEvent>;\n paddingAngle?: number;\n radius?: number;\n reveal?: number;\n rounded?: boolean;\n segmentsShift?: number | ((dataIndex: number) => number | undefined);\n segmentsStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n segmentsTabIndex?: number;\n startAngle?: number;\n style?: CSSProperties;\n totalValue?: number;\n viewBoxSize?: [number, number];\n};\n\nconst defaultProps = {\n animationDuration: 500,\n animationEasing: 'ease-out',\n center: [50, 50] as [number, number],\n data: [] as Data,\n labelPosition: 50,\n lengthAngle: 360,\n lineWidth: 100,\n paddingAngle: 0,\n radius: 50,\n startAngle: 0,\n viewBoxSize: [100, 100] as [number, number],\n};\n\nexport type PropsWithDefaults = Props & typeof defaultProps;\n\nexport function ReactMinimalPieChart(props: PropsWithDefaults) {\n const [revealOverride, setRevealOverride] = useState(\n props.animate ? 0 : null\n );\n useEffect(() => {\n if (props.animate) {\n return startInitialAnimation();\n }\n\n function startInitialAnimation() {\n let animationTimerId: NodeJS.Timeout | null;\n let animationRAFId: number | null;\n animationTimerId = setTimeout(() => {\n animationTimerId = null;\n animationRAFId = requestAnimationFrame(() => {\n animationRAFId = null;\n setRevealOverride(null); // Start animation\n });\n });\n\n return () => {\n animationTimerId && clearTimeout(animationTimerId);\n animationRAFId && cancelAnimationFrame(animationRAFId);\n };\n }\n }, []);\n\n const extendedData = extendData(props);\n return (\n <svg\n viewBox={`0 0 ${props.viewBoxSize[0]} ${props.viewBoxSize[1]}`}\n width=\"100%\"\n height=\"100%\"\n className={props.className}\n style={props.style}\n >\n {renderSegments(extendedData, props, revealOverride)}\n {props.label && renderLabels(extendedData, props)}\n {props.children}\n </svg>\n );\n}\n\nReactMinimalPieChart.defaultProps = defaultProps;\n"],"names":["degreesToRadians","degrees","Math","PI","valueBetween","value","min","max","extractPercentage","percentage","bisectorAngle","startAngle","lengthAngle","shiftVectorAlongAngle","angle","distance","angleRadians","dx","cos","dy","sin","isNumber","functionProp","prop","payload","sumValues","data","sum","i","length","extendData","totalAngle","totalValue","paddingAngle","chartStartAngle","total","normalizedTotalAngle","numberOfPaddings","abs","singlePaddingDegrees","sign","degreesTakenByPadding","degreesTakenByPaths","lastSegmentEnd","extendedData","dataEntry","valueInPercentage","push","Object","assign","ReactMinimalPieChartLabel","dataIndex","props","React","round","number","divisor","Number","EPSILON","evaluateTextAnchorPosition","labelPosition","lineWidth","labelHorizontalShift","innerRadius","renderLabelElement","renderLabel","labelProps","label","DefaultLabel","key","isValidElement","renderLabels","map","index","segmentsShift","distanceFromCenter","radius","labelRenderProps","x","center","y","textAnchor","style","labelStyle","partialCircle","cx","cy","r","start","end","fromX","fromY","toX","toY","large","sweep","module","makePathCommands","patchedLengthAngle","command","join","ReactMinimalPieChartPath","shift","reveal","rounded","title","pathRadius","pathCommands","strokeDasharray","strokeDashoffset","pathLength","undefined","combineSegmentTransitionsStyle","duration","easing","customStyle","transition","getRevealValue","animate","makeEventHandler","eventHandler","e","renderSegments","revealOverride","paths","segmentsStyle","Path","animationDuration","animationEasing","color","segmentsTabIndex","onBlur","onClick","onFocus","onKeyDown","onMouseOver","onMouseOut","background","unshift","defaultProps","viewBoxSize","ReactMinimalPieChart","useState","setRevealOverride","useEffect","startInitialAnimation","animationTimerId","animationRAFId","setTimeout","requestAnimationFrame","clearTimeout","cancelAnimationFrame","className","children"],"mappings":";;;;;;;;;;AAAO,SAASA,gBAAT,CAA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C3CF,UAAAA,cAAc,GAAG,IAAjB;AACAJ,UAAAA,iBAAiB,CAAC,IAAD,CAAjB,CAF2C;AAG5C,SAHqC,CAAtC;AAID,OAN4B,CAA7B;AAQA,aAAO,YAAM;AACXG,QAAAA,gBAAgB,IAAII,YAAY,CAACJ,gBAAD,CAAhC;AACAC,QAAAA,cAAc,IAAII,oBAAoB,CAACJ,cAAD,CAAtC;AACD,OAHD;AAID;AACF,GArBQ,EAqBN,EArBM,CAAT;AAuBA,MAAMvG,YAAY,GAAGd,UAAU,CAACsB,KAAD,CAA/B;AACA,sBACEC;AACE,IAAA,OAAO,WAASD,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAAT,SAAiCxF,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAD1C;AAEE,IAAA,KAAK,EAAC,MAFR;AAGE,IAAA,MAAM,EAAC,MAHT;AAIE,IAAA,SAAS,EAAExF,KAAK,CAACoG,SAJnB;AAKE,IAAA,KAAK,EAAEpG,KAAK,CAAC8B;AALf,KAOGwC,cAAc,CAAC9E,YAAD,EAAeQ,KAAf,EAAsBuE,cAAtB,CAPjB,EAQGvE,KAAK,CAACe,KAAN,IAAeI,YAAY,CAAC3B,YAAD,EAAeQ,KAAf,CAR9B,EASGA,KAAK,CAACqG,QATT,CADF;AAaD;AAEDZ,oBAAoB,CAACF,YAArB,GAAoCA,YAApC;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-minimal-pie-chart",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "Lightweight but versatile SVG pie/donut charts for React",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"preversion": "npm run prepare",
|
|
35
35
|
"version": "git add package.json",
|
|
36
36
|
"postversion": "git push && git push --tags",
|
|
37
|
-
"prepare": "npm run test:source && npm run compile && npm run test:bundles",
|
|
37
|
+
"prepare": "npx simple-git-hooks && npm run test:source && npm run compile && npm run test:bundles",
|
|
38
38
|
"start": "start-storybook -p 9001 -c .storybook",
|
|
39
39
|
"storybook:deploy": "storybook-to-ghpages",
|
|
40
40
|
"storybook:build": "build-storybook"
|
|
@@ -54,47 +54,48 @@
|
|
|
54
54
|
"author": "Andrea Carraro <me@andreacarraro.it>",
|
|
55
55
|
"license": "MIT",
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"react": "^16.8.0",
|
|
58
|
-
"react-dom": "^16.8.0"
|
|
57
|
+
"react": "^16.8.0 || ^17.0.0 || ^18",
|
|
58
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@babel/core": "^7.
|
|
63
|
-
"@babel/plugin-transform-react-jsx": "^7.
|
|
64
|
-
"@babel/preset-env": "^7.
|
|
65
|
-
"@babel/preset-typescript": "^7.
|
|
62
|
+
"@babel/core": "^7.12.10",
|
|
63
|
+
"@babel/plugin-transform-react-jsx": "^7.12.12",
|
|
64
|
+
"@babel/preset-env": "^7.12.11",
|
|
65
|
+
"@babel/preset-typescript": "^7.12.7",
|
|
66
|
+
"@rollup/plugin-babel": "^5.3.0",
|
|
67
|
+
"@rollup/plugin-commonjs": "^19.0.0",
|
|
68
|
+
"@rollup/plugin-node-resolve": "^11.2.0",
|
|
66
69
|
"@schwingbat/relative-angle": "^1.0.0",
|
|
67
|
-
"@size-limit/preset-small-lib": "^
|
|
68
|
-
"@storybook/addon-actions": "^
|
|
69
|
-
"@storybook/react": "^
|
|
70
|
-
"@storybook/storybook-deployer": "^2.8.
|
|
71
|
-
"@testing-library/jest-dom": "^5.
|
|
72
|
-
"@testing-library/react": "^
|
|
73
|
-
"@types/react": "^
|
|
74
|
-
"all-contributors-cli": "^6.
|
|
75
|
-
"babel-jest": "^
|
|
76
|
-
"babel-loader": "^8.
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"lint-staged": "^10.1.1",
|
|
82
|
-
"prettier": "^2.0.2",
|
|
70
|
+
"@size-limit/preset-small-lib": "^5.0.2",
|
|
71
|
+
"@storybook/addon-actions": "^6.1.21",
|
|
72
|
+
"@storybook/react": "^6.1.21",
|
|
73
|
+
"@storybook/storybook-deployer": "^2.8.7",
|
|
74
|
+
"@testing-library/jest-dom": "^5.11.9",
|
|
75
|
+
"@testing-library/react": "^12.0.0",
|
|
76
|
+
"@types/react": "^17.0.2",
|
|
77
|
+
"all-contributors-cli": "^6.19.0",
|
|
78
|
+
"babel-jest": "^27.1.0",
|
|
79
|
+
"babel-loader": "^8.2.2",
|
|
80
|
+
"es-check": "^6.0.0",
|
|
81
|
+
"jest": "^27.1.0",
|
|
82
|
+
"lint-staged": "^11.1.2",
|
|
83
|
+
"prettier": "^2.2.1",
|
|
83
84
|
"prop-types": "^15.7.2",
|
|
84
|
-
"react": "^
|
|
85
|
-
"react-dom": "^
|
|
86
|
-
"react-tooltip": "^4.2.
|
|
87
|
-
"rollup": "^
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"rollup-plugin-node-resolve": "^5.2.0",
|
|
85
|
+
"react": "^17.0.1",
|
|
86
|
+
"react-dom": "^17.0.1",
|
|
87
|
+
"react-tooltip": "^4.2.7",
|
|
88
|
+
"rollup": "^2.40.0",
|
|
89
|
+
"simple-git-hooks": "^2.4.1",
|
|
90
|
+
"size-limit": "^5.0.2",
|
|
91
91
|
"svg-partial-circle": "1.0.0",
|
|
92
92
|
"svg-path-parser": "^1.1.0",
|
|
93
|
-
"typescript": "^
|
|
93
|
+
"typescript": "^4.2.3"
|
|
94
94
|
},
|
|
95
95
|
"jest": {
|
|
96
96
|
"testRegex": "/__tests__/.*\\.test\\.[jt]sx?$",
|
|
97
97
|
"testURL": "http://localhost/",
|
|
98
|
+
"testEnvironment": "jsdom",
|
|
98
99
|
"coverageReporters": [
|
|
99
100
|
"text",
|
|
100
101
|
"lcov"
|
|
@@ -116,10 +117,8 @@
|
|
|
116
117
|
]
|
|
117
118
|
}
|
|
118
119
|
],
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"pre-commit": "npm run test:source && lint-staged"
|
|
122
|
-
}
|
|
120
|
+
"simple-git-hooks": {
|
|
121
|
+
"pre-commit": "npm run test:source && npx lint-staged"
|
|
123
122
|
},
|
|
124
123
|
"lint-staged": {
|
|
125
124
|
"*.{js,ts,tsx}": [
|
package/types/Chart/Chart.d.ts
CHANGED
|
@@ -46,8 +46,8 @@ declare const defaultProps: {
|
|
|
46
46
|
viewBoxSize: [number, number];
|
|
47
47
|
};
|
|
48
48
|
export declare type PropsWithDefaults = Props & typeof defaultProps;
|
|
49
|
-
export declare function
|
|
50
|
-
export declare namespace
|
|
49
|
+
export declare function ReactMinimalPieChart(props: PropsWithDefaults): JSX.Element;
|
|
50
|
+
export declare namespace ReactMinimalPieChart {
|
|
51
51
|
var defaultProps: {
|
|
52
52
|
animationDuration: number;
|
|
53
53
|
animationEasing: string;
|
|
@@ -61,6 +61,5 @@ export declare namespace PieChart {
|
|
|
61
61
|
startAngle: number;
|
|
62
62
|
viewBoxSize: [number, number];
|
|
63
63
|
};
|
|
64
|
-
var displayName: string;
|
|
65
64
|
}
|
|
66
65
|
export {};
|
package/types/Chart/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { PieChart } from './Chart';
|
|
1
|
+
export { ReactMinimalPieChart as PieChart } from './Chart';
|
package/types/Label.d.ts
CHANGED
|
@@ -11,8 +11,5 @@ export declare type LabelRenderProps = {
|
|
|
11
11
|
style?: CSSProperties;
|
|
12
12
|
};
|
|
13
13
|
declare type Props = SVGProps<SVGTextElement> & LabelRenderProps;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var displayName: string;
|
|
17
|
-
}
|
|
18
|
-
export default Label;
|
|
14
|
+
export default function ReactMinimalPieChartLabel({ dataEntry, dataIndex, ...props }: Props): JSX.Element;
|
|
15
|
+
export {};
|
package/types/Path.d.ts
CHANGED
|
@@ -12,8 +12,5 @@ declare type Props = SVGProps<SVGPathElement> & {
|
|
|
12
12
|
startAngle: number;
|
|
13
13
|
title?: string | number;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var displayName: string;
|
|
18
|
-
}
|
|
19
|
-
export default Path;
|
|
15
|
+
export default function ReactMinimalPieChartPath({ cx, cy, lengthAngle, lineWidth, radius, shift, reveal, rounded, startAngle, title, ...props }: Props): JSX.Element;
|
|
16
|
+
export {};
|