react-minimal-pie-chart 8.2.0 → 8.4.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 +17 -11
- package/dist/index.js +104 -128
- package/dist/index.js.map +1 -1
- package/es/index.js +97 -116
- package/es/index.js.map +1 -1
- package/lib/index.js +102 -126
- package/lib/index.js.map +1 -1
- package/package.json +39 -36
- package/types/Chart/Chart.d.ts +14 -30
- package/types/Chart/extendData.d.ts +2 -2
- package/types/Chart/index.d.ts +2 -1
- package/types/Chart/renderLabels.d.ts +2 -2
- package/types/Chart/renderSegments.d.ts +2 -2
- package/types/Label.d.ts +8 -7
- package/types/commonTypes.d.ts +7 -8
- package/types/index.d.ts +2 -1
- package/types/utils.d.ts +1 -0
- package/CHANGELOG.md +0 -254
package/dist/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 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":";;;;;;;;;;EAAO,SAASA,gBAAT,CAA0BC,OAA1B,EAA2C;EAChD,SAAQA,OAAO,GAAGC,IAAI,CAACC,EAAhB,GAAsB,GAA7B;EACD;EAEM,SAASC,YAAT,CAAsBC,KAAtB,EAAqCC,GAArC,EAAkDC,GAAlD,EAA+D;EACpE,MAAIF,KAAK,GAAGE,GAAZ,E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AAhC;EACAC,QAAAA,cAAc,IAAII,oBAAoB,CAACJ,cAAD,CAAtC;EACD,OAHD;EAID;EACF,GArBQ,EAqBN,EArBM,CAAT;EAuBA,MAAMvG,YAAY,GAAGd,UAAU,CAACsB,KAAD,CAA/B;EACA,sBACEC;EACE,IAAA,OAAO,WAASD,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAAT,SAAiCxF,KAAK,CAACwF,WAAN,CAAkB,CAAlB,CAD1C;EAEE,IAAA,KAAK,EAAC,MAFR;EAGE,IAAA,MAAM,EAAC,MAHT;EAIE,IAAA,SAAS,EAAExF,KAAK,CAACoG,SAJnB;EAKE,IAAA,KAAK,EAAEpG,KAAK,CAAC8B;EALf,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;EAaD;EAEDZ,oBAAoB,CAACF,YAArB,GAAoCA,YAApC;;;;;;;;;;"}
|
|
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\nexport function makePropsWithDefaults<Result extends Object>(\n props: Partial<Result>,\n defaultProps: Result\n): Result {\n const result: Result = Object.assign({}, defaultProps, props);\n\n // @NOTE Object.assign doesn't default properties with undefined value (like React defaultProps does)\n for (const key in defaultProps) {\n if (props[key] === undefined) {\n result[key] = defaultProps[key];\n }\n }\n\n return result;\n}\n","import { extractPercentage, valueBetween } from '../utils';\nimport type { Data, BaseDataEntry, ExtendedData } from '../commonTypes';\nimport type { PropsWithDefaults as ChartProps } from './Chart';\n\nfunction sumValues<DataEntry extends BaseDataEntry>(\n data: Data<DataEntry>\n): 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<DataEntry extends BaseDataEntry>({\n data,\n lengthAngle: totalAngle,\n totalValue,\n paddingAngle,\n startAngle: chartStartAngle,\n}: ChartProps<DataEntry>): ExtendedData<DataEntry> {\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: ExtendedData<DataEntry> = [];\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 {\n ExtendedData,\n BaseDataEntry,\n LabelRenderFunction,\n} from './commonTypes';\n\nexport type LabelRenderProps<DataEntry extends BaseDataEntry> = {\n x: number;\n y: number;\n dx: number;\n dy: number;\n textAnchor: string;\n dataEntry: ExtendedData<DataEntry>[number];\n dataIndex: number;\n style?: CSSProperties;\n};\n\nexport default function ReactMinimalPieChartLabel<\n DataEntry extends BaseDataEntry\n>({\n renderLabel,\n labelProps,\n}: {\n renderLabel: LabelRenderFunction<DataEntry>;\n labelProps: LabelRenderProps<DataEntry>;\n}) {\n const label = renderLabel(labelProps);\n\n // Default label\n if (typeof label === 'string' || typeof label === 'number') {\n const { dataEntry, dataIndex, ...props } = labelProps;\n return (\n <text dominantBaseline=\"central\" {...props}>\n {label}\n </text>\n );\n }\n\n if (React.isValidElement(label)) {\n return label;\n }\n\n return null;\n}\n","import React from 'react';\nimport Label 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, BaseDataEntry } 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 makeLabelRenderProps<DataEntry extends BaseDataEntry>(\n data: ExtendedData<DataEntry>,\n props: ChartProps<DataEntry>\n): LabelRenderProps<DataEntry>[] {\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: LabelRenderProps<DataEntry> = {\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 labelRenderProps;\n });\n}\n\nexport default function renderLabels<DataEntry extends BaseDataEntry>(\n data: ExtendedData<DataEntry>,\n props: ChartProps<DataEntry>\n) {\n const { label } = props;\n if (label) {\n return makeLabelRenderProps(data, props).map((labelRenderProps, index) => (\n <Label\n key={`label-${labelRenderProps.dataEntry.key || index}`}\n renderLabel={label}\n labelProps={labelRenderProps}\n />\n ));\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, SyntheticEvent } from 'react';\nimport Path from '../Path';\nimport { extractPercentage, functionProp, isNumber } from '../utils';\nimport type { ExtendedData, BaseDataEntry } 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<\n Event extends SyntheticEvent,\n Payload,\n EventHandler extends (event: Event, payload: Payload) => void\n>(eventHandler: undefined | EventHandler, payload: Payload) {\n return (\n eventHandler &&\n ((e: Event) => {\n eventHandler(e, payload);\n })\n );\n}\n\nexport default function renderSegments<DataEntry extends BaseDataEntry>(\n data: ExtendedData<DataEntry>,\n props: ChartProps<DataEntry>,\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, BaseDataEntry, LabelRenderFunction } from '../commonTypes';\nimport { makePropsWithDefaults } from '../utils';\n\nexport type Props<DataEntry extends BaseDataEntry = BaseDataEntry> = {\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<DataEntry>;\n lengthAngle?: number;\n lineWidth?: number;\n label?: LabelRenderFunction<DataEntry>;\n labelPosition?: number;\n labelStyle?:\n | CSSProperties\n | ((dataIndex: number) => CSSProperties | undefined);\n onBlur?: (event: FocusEvent, dataIndex: number) => void;\n onClick?: (event: MouseEvent, dataIndex: number) => void;\n onFocus?: (event: FocusEvent, dataIndex: number) => void;\n onKeyDown?: (event: KeyboardEvent, dataIndex: number) => void;\n onMouseOut?: (event: MouseEvent, dataIndex: number) => void;\n onMouseOver?: (event: MouseEvent, dataIndex: number) => void;\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\nexport const 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<\n DataEntry extends BaseDataEntry\n> = Props<DataEntry> & typeof defaultProps;\n\nexport function ReactMinimalPieChart<DataEntry extends BaseDataEntry>(\n originalProps: Props<DataEntry>\n) {\n const props = makePropsWithDefaults<PropsWithDefaults<DataEntry>>(\n originalProps,\n // @ts-expect-error: defaultProps.data is typed as BaseDataEntry\n defaultProps\n );\n const [revealOverride, setRevealOverride] = useState(\n props.animate ? 0 : null\n );\n\n useEffect(() => {\n if (props.animate) {\n // Trigger initial animation\n setRevealOverride(null);\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 {renderLabels(extendedData, props)}\n {props.children}\n </svg>\n );\n}\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","makePropsWithDefaults","props","defaultProps","result","Object","assign","key","undefined","sumValues","data","sum","i","length","extendData","totalAngle","totalValue","paddingAngle","chartStartAngle","total","normalizedTotalAngle","numberOfPaddings","abs","singlePaddingDegrees","sign","degreesTakenByPadding","degreesTakenByPaths","lastSegmentEnd","extendedData","dataEntry","valueInPercentage","push","ReactMinimalPieChartLabel","renderLabel","labelProps","label","dataIndex","React","isValidElement","round","number","divisor","Number","EPSILON","evaluateTextAnchorPosition","labelPosition","lineWidth","labelHorizontalShift","innerRadius","makeLabelRenderProps","map","index","segmentsShift","distanceFromCenter","radius","labelRenderProps","x","center","y","textAnchor","style","labelStyle","renderLabels","Label","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","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","viewBoxSize","ReactMinimalPieChart","originalProps","useState","setRevealOverride","useEffect","className","children"],"mappings":";;;;;;EAAO,SAASA,gBAAgB,CAACC,OAAe,EAAE;EAChD,EAAA,OAAQA,OAAO,GAAGC,IAAI,CAACC,EAAE,GAAI,GAAG,CAAA;EAClC,CAAA;EAEO,SAASC,YAAY,CAACC,KAAa,EAAEC,GAAW,EAAEC,GAAW,EAAE;EACpE,EAAA,IAAIF,KAAK,GAAGE,GAAG,EAAE,OAAOA,GAAG,CAAA;EAC3B,EAAA,IAAIF,KAAK,GAAGC,GAAG,EAAE,OAAOA,GAAG,CAAA;EAC3B,EAAA,OAAOD,KAAK,CAAA;EACd,CAAA;EAEO,SAASG,iBAAiB,CAACH,KAAa,EAAEI,UAAkB,EAAE;EACnE,EAAA,OAAQA,UAAU,GAAG,GAAG,GAAIJ,KAAK,CAAA;EACnC,CAAA;EAEO,SAASK,aAAa,CAACC,UAAkB,EAAEC,WAAmB,EAAE;EACrE,EAAA,OAAOD,UAAU,GAAGC,WAAW,GAAG,CAAC,CAAA;EACrC,CAAA;EAEO,SAASC,qBAAqB,CAACC,KAAa,EAAEC,QAAgB,EAAE;EACrE,EAAA,IAAMC,YAA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vH,KAAK,CAAC+F,OAAO,GAAG,CAAC,GAAG,IAAI,CACzB;MAFMK,cAAc,GAAA,SAAA,CAAA,CAAA,CAAA;MAAEoB,iBAAiB,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;EAIxCC,EAAAA,eAAS,CAAC,YAAM;MACd,IAAIzH,KAAK,CAAC+F,OAAO,EAAE;EACjB;QACAyB,iBAAiB,CAAC,IAAI,CAAC,CAAA;EACzB,KAAA;KACD,EAAE,EAAE,CAAC,CAAA;EAEN,EAAA,IAAM9F,YAAY,GAAGd,UAAU,CAACZ,KAAK,CAAC,CAAA;IACtC,oBACE,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;EACE,IAAA,OAAO,EAASA,MAAAA,GAAAA,KAAK,CAACoH,WAAW,CAAC,CAAC,CAAC,GAAA,GAAA,GAAIpH,KAAK,CAACoH,WAAW,CAAC,CAAC,CAAI;EAC/D,IAAA,KAAK,EAAC,MAAM;EACZ,IAAA,MAAM,EAAC,MAAM;MACb,SAAS,EAAEpH,KAAK,CAAC0H,SAAU;MAC3B,KAAK,EAAE1H,KAAK,CAAC0D,KAAAA;EAAM,GAAA,EAElByC,cAAc,CAACzE,YAAY,EAAE1B,KAAK,EAAEoG,cAAc,CAAC,EACnDxC,YAAY,CAAClC,YAAY,EAAE1B,KAAK,CAAC,EACjCA,KAAK,CAAC2H,QAAQ,CACX,CAAA;EAEV;;;;;;;;;"}
|
package/es/index.js
CHANGED
|
@@ -27,24 +27,33 @@ function isNumber(value) {
|
|
|
27
27
|
function functionProp(prop, payload) {
|
|
28
28
|
return typeof prop === 'function' ? prop(payload) : prop;
|
|
29
29
|
}
|
|
30
|
+
function makePropsWithDefaults(props, defaultProps) {
|
|
31
|
+
var result = Object.assign({}, defaultProps, props);
|
|
32
|
+
|
|
33
|
+
// @NOTE Object.assign doesn't default properties with undefined value (like React defaultProps does)
|
|
34
|
+
for (var key in defaultProps) {
|
|
35
|
+
if (props[key] === undefined) {
|
|
36
|
+
result[key] = defaultProps[key];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
30
41
|
|
|
31
42
|
function sumValues(data) {
|
|
32
43
|
var sum = 0;
|
|
33
|
-
|
|
34
44
|
for (var i = 0; i < data.length; i++) {
|
|
35
45
|
sum += data[i].value;
|
|
36
46
|
}
|
|
37
|
-
|
|
38
47
|
return sum;
|
|
39
|
-
}
|
|
40
|
-
|
|
48
|
+
}
|
|
41
49
|
|
|
50
|
+
// Append "percentage", "degrees" and "startAngle" to each data entry
|
|
42
51
|
function extendData(_ref) {
|
|
43
52
|
var data = _ref.data,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
totalAngle = _ref.lengthAngle,
|
|
54
|
+
totalValue = _ref.totalValue,
|
|
55
|
+
paddingAngle = _ref.paddingAngle,
|
|
56
|
+
chartStartAngle = _ref.startAngle;
|
|
48
57
|
var total = totalValue || sumValues(data);
|
|
49
58
|
var normalizedTotalAngle = valueBetween(totalAngle, -360, 360);
|
|
50
59
|
var numberOfPaddings = Math.abs(normalizedTotalAngle) === 360 ? data.length : data.length - 1;
|
|
@@ -52,8 +61,9 @@ function extendData(_ref) {
|
|
|
52
61
|
var degreesTakenByPadding = singlePaddingDegrees * numberOfPaddings;
|
|
53
62
|
var degreesTakenByPaths = normalizedTotalAngle - degreesTakenByPadding;
|
|
54
63
|
var lastSegmentEnd = 0;
|
|
55
|
-
var extendedData = [];
|
|
64
|
+
var extendedData = [];
|
|
56
65
|
|
|
66
|
+
// @NOTE: Shall we evaluate percentage accordingly to dataEntry.value's sign?
|
|
57
67
|
for (var i = 0; i < data.length; i++) {
|
|
58
68
|
var dataEntry = data[i];
|
|
59
69
|
var valueInPercentage = total === 0 ? 0 : dataEntry.value / total * 100;
|
|
@@ -66,7 +76,6 @@ function extendData(_ref) {
|
|
|
66
76
|
degrees: degrees
|
|
67
77
|
}, dataEntry));
|
|
68
78
|
}
|
|
69
|
-
|
|
70
79
|
return extendedData;
|
|
71
80
|
}
|
|
72
81
|
|
|
@@ -75,86 +84,67 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
75
84
|
var target = {};
|
|
76
85
|
var sourceKeys = Object.keys(source);
|
|
77
86
|
var key, i;
|
|
78
|
-
|
|
79
87
|
for (i = 0; i < sourceKeys.length; i++) {
|
|
80
88
|
key = sourceKeys[i];
|
|
81
89
|
if (excluded.indexOf(key) >= 0) continue;
|
|
82
90
|
target[key] = source[key];
|
|
83
91
|
}
|
|
84
|
-
|
|
85
92
|
return target;
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
function ReactMinimalPieChartLabel(_ref) {
|
|
89
|
-
_ref.
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
var renderLabel = _ref.renderLabel,
|
|
97
|
+
labelProps = _ref.labelProps;
|
|
98
|
+
var label = renderLabel(labelProps);
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
// Default label
|
|
101
|
+
if (typeof label === 'string' || typeof label === 'number') {
|
|
102
|
+
labelProps.dataEntry;
|
|
103
|
+
labelProps.dataIndex;
|
|
104
|
+
var props = _objectWithoutPropertiesLoose(labelProps, ["dataEntry", "dataIndex"]);
|
|
105
|
+
return /*#__PURE__*/React.createElement("text", Object.assign({
|
|
106
|
+
dominantBaseline: "central"
|
|
107
|
+
}, props), label);
|
|
108
|
+
}
|
|
109
|
+
if (React.isValidElement(label)) {
|
|
110
|
+
return label;
|
|
111
|
+
}
|
|
112
|
+
return null;
|
|
96
113
|
}
|
|
97
114
|
|
|
98
115
|
function round(number) {
|
|
99
116
|
var divisor = 1e14; // 14 decimals
|
|
100
|
-
|
|
101
117
|
return Math.round((number + Number.EPSILON) * divisor) / divisor;
|
|
102
118
|
}
|
|
103
|
-
|
|
104
119
|
function evaluateTextAnchorPosition(_ref) {
|
|
105
120
|
var labelPosition = _ref.labelPosition,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var dx = round(labelHorizontalShift);
|
|
109
|
-
|
|
121
|
+
lineWidth = _ref.lineWidth,
|
|
122
|
+
labelHorizontalShift = _ref.labelHorizontalShift;
|
|
123
|
+
var dx = round(labelHorizontalShift);
|
|
124
|
+
// Label in the vertical center
|
|
110
125
|
if (dx === 0) {
|
|
111
126
|
return 'middle';
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
127
|
+
}
|
|
128
|
+
// Outward label
|
|
115
129
|
if (labelPosition > 100) {
|
|
116
130
|
return dx > 0 ? 'start' : 'end';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
131
|
+
}
|
|
132
|
+
// Inward label
|
|
120
133
|
var innerRadius = 100 - lineWidth;
|
|
121
|
-
|
|
122
134
|
if (labelPosition < innerRadius) {
|
|
123
135
|
return dx > 0 ? 'end' : 'start';
|
|
124
|
-
} // Overlying label
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return 'middle';
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function renderLabelElement(renderLabel, labelProps) {
|
|
131
|
-
var label = renderLabel(labelProps);
|
|
132
|
-
|
|
133
|
-
if (typeof label === 'string' || typeof label === 'number') {
|
|
134
|
-
return /*#__PURE__*/React.createElement(ReactMinimalPieChartLabel, Object.assign({
|
|
135
|
-
key: "label-" + (labelProps.dataEntry.key || labelProps.dataIndex)
|
|
136
|
-
}, labelProps), label);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (React.isValidElement(label)) {
|
|
140
|
-
return label;
|
|
141
136
|
}
|
|
142
|
-
|
|
143
|
-
return
|
|
137
|
+
// Overlying label
|
|
138
|
+
return 'middle';
|
|
144
139
|
}
|
|
145
|
-
|
|
146
|
-
function renderLabels(data, props) {
|
|
140
|
+
function makeLabelRenderProps(data, props) {
|
|
147
141
|
return data.map(function (dataEntry, index) {
|
|
148
142
|
var _functionProp;
|
|
149
|
-
|
|
150
143
|
var segmentsShift = (_functionProp = functionProp(props.segmentsShift, index)) != null ? _functionProp : 0;
|
|
151
144
|
var distanceFromCenter = extractPercentage(props.radius, props.labelPosition) + segmentsShift;
|
|
152
|
-
|
|
153
145
|
var _shiftVectorAlongAngl = shiftVectorAlongAngle(bisectorAngle(dataEntry.startAngle, dataEntry.degrees), distanceFromCenter),
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
dx = _shiftVectorAlongAngl.dx,
|
|
147
|
+
dy = _shiftVectorAlongAngl.dy; // This object is passed as argument to the "label" function prop
|
|
158
148
|
var labelRenderProps = {
|
|
159
149
|
x: props.center[0],
|
|
160
150
|
y: props.center[1],
|
|
@@ -169,10 +159,23 @@ function renderLabels(data, props) {
|
|
|
169
159
|
dataIndex: index,
|
|
170
160
|
style: functionProp(props.labelStyle, index)
|
|
171
161
|
};
|
|
172
|
-
return
|
|
162
|
+
return labelRenderProps;
|
|
173
163
|
});
|
|
174
164
|
}
|
|
165
|
+
function renderLabels(data, props) {
|
|
166
|
+
var label = props.label;
|
|
167
|
+
if (label) {
|
|
168
|
+
return makeLabelRenderProps(data, props).map(function (labelRenderProps, index) {
|
|
169
|
+
return /*#__PURE__*/React.createElement(ReactMinimalPieChartLabel, {
|
|
170
|
+
key: "label-" + (labelRenderProps.dataEntry.key || index),
|
|
171
|
+
renderLabel: label,
|
|
172
|
+
labelProps: labelRenderProps
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
175
177
|
|
|
178
|
+
// from http://stackoverflow.com/a/18473154
|
|
176
179
|
var partialCircle = function partialCircle(cx, cy, r, start, end) {
|
|
177
180
|
var length = end - start;
|
|
178
181
|
if (length === 0) return [];
|
|
@@ -184,47 +187,47 @@ var partialCircle = function partialCircle(cx, cy, r, start, end) {
|
|
|
184
187
|
var sweep = length < 0 ? '0' : '1';
|
|
185
188
|
return [['M', fromX, fromY], ['A', r, r, 0, large, sweep, toX, toY]];
|
|
186
189
|
};
|
|
187
|
-
|
|
188
190
|
var svgPartialCircle = partialCircle;
|
|
189
191
|
|
|
192
|
+
var partialCircle$1 = svgPartialCircle;
|
|
193
|
+
|
|
190
194
|
function makePathCommands(cx, cy, startAngle, lengthAngle, radius) {
|
|
191
195
|
var patchedLengthAngle = valueBetween(lengthAngle, -359.999, 359.999);
|
|
192
|
-
return
|
|
196
|
+
return partialCircle$1(cx, cy,
|
|
197
|
+
// center X and Y
|
|
193
198
|
radius, degreesToRadians(startAngle), degreesToRadians(startAngle + patchedLengthAngle)).map(function (command) {
|
|
194
199
|
return command.join(' ');
|
|
195
200
|
}).join(' ');
|
|
196
201
|
}
|
|
197
202
|
function ReactMinimalPieChartPath(_ref) {
|
|
198
203
|
var cx = _ref.cx,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
204
|
+
cy = _ref.cy,
|
|
205
|
+
lengthAngle = _ref.lengthAngle,
|
|
206
|
+
lineWidth = _ref.lineWidth,
|
|
207
|
+
radius = _ref.radius,
|
|
208
|
+
_ref$shift = _ref.shift,
|
|
209
|
+
shift = _ref$shift === void 0 ? 0 : _ref$shift,
|
|
210
|
+
reveal = _ref.reveal,
|
|
211
|
+
rounded = _ref.rounded,
|
|
212
|
+
startAngle = _ref.startAngle,
|
|
213
|
+
title = _ref.title,
|
|
214
|
+
props = _objectWithoutPropertiesLoose(_ref, ["cx", "cy", "lengthAngle", "lineWidth", "radius", "shift", "reveal", "rounded", "startAngle", "title"]);
|
|
215
|
+
var pathRadius = radius - lineWidth / 2;
|
|
216
|
+
//@NOTE This shift might be rendered as a translation in future
|
|
213
217
|
var _shiftVectorAlongAngl = shiftVectorAlongAngle(bisectorAngle(startAngle, lengthAngle), shift),
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
dx = _shiftVectorAlongAngl.dx,
|
|
219
|
+
dy = _shiftVectorAlongAngl.dy;
|
|
217
220
|
var pathCommands = makePathCommands(cx + dx, cy + dy, startAngle, lengthAngle, pathRadius);
|
|
218
221
|
var strokeDasharray;
|
|
219
|
-
var strokeDashoffset;
|
|
220
|
-
// https://css-tricks.com/svg-line-animation-works/
|
|
222
|
+
var strokeDashoffset;
|
|
221
223
|
|
|
224
|
+
// Animate/hide paths with "stroke-dasharray" + "stroke-dashoffset"
|
|
225
|
+
// https://css-tricks.com/svg-line-animation-works/
|
|
222
226
|
if (isNumber(reveal)) {
|
|
223
227
|
var pathLength = degreesToRadians(pathRadius) * lengthAngle;
|
|
224
228
|
strokeDasharray = Math.abs(pathLength);
|
|
225
229
|
strokeDashoffset = strokeDasharray - extractPercentage(strokeDasharray, reveal);
|
|
226
230
|
}
|
|
227
|
-
|
|
228
231
|
return /*#__PURE__*/React.createElement("path", Object.assign({
|
|
229
232
|
d: pathCommands,
|
|
230
233
|
fill: "none",
|
|
@@ -238,38 +241,32 @@ function ReactMinimalPieChartPath(_ref) {
|
|
|
238
241
|
function combineSegmentTransitionsStyle(duration, easing, customStyle) {
|
|
239
242
|
// Merge chart's animation CSS transition with "transition" found to customStyle
|
|
240
243
|
var transition = "stroke-dashoffset " + duration + "ms " + easing;
|
|
241
|
-
|
|
242
244
|
if (customStyle && customStyle.transition) {
|
|
243
245
|
transition = transition + "," + customStyle.transition;
|
|
244
246
|
}
|
|
245
|
-
|
|
246
247
|
return {
|
|
247
248
|
transition: transition
|
|
248
249
|
};
|
|
249
250
|
}
|
|
250
|
-
|
|
251
251
|
function getRevealValue(props) {
|
|
252
252
|
//@NOTE When animation is on, chart has to be fully revealed when reveal is not set
|
|
253
253
|
if (props.animate && !isNumber(props.reveal)) {
|
|
254
254
|
return 100;
|
|
255
255
|
}
|
|
256
|
-
|
|
257
256
|
return props.reveal;
|
|
258
257
|
}
|
|
259
|
-
|
|
260
258
|
function makeEventHandler(eventHandler, payload) {
|
|
261
259
|
return eventHandler && function (e) {
|
|
262
260
|
eventHandler(e, payload);
|
|
263
261
|
};
|
|
264
262
|
}
|
|
265
|
-
|
|
266
263
|
function renderSegments(data, props, revealOverride) {
|
|
267
264
|
// @NOTE this should go in Path component. Here for performance reasons
|
|
268
265
|
var reveal = revealOverride != null ? revealOverride : getRevealValue(props);
|
|
269
266
|
var radius = props.radius,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
267
|
+
_props$center = props.center,
|
|
268
|
+
cx = _props$center[0],
|
|
269
|
+
cy = _props$center[1];
|
|
273
270
|
var lineWidth = extractPercentage(radius, props.lineWidth);
|
|
274
271
|
var paths = data.map(function (dataEntry, index) {
|
|
275
272
|
var segmentsStyle = functionProp(props.segmentsStyle, index);
|
|
@@ -296,7 +293,6 @@ function renderSegments(data, props, revealOverride) {
|
|
|
296
293
|
onMouseOut: makeEventHandler(props.onMouseOut, index)
|
|
297
294
|
});
|
|
298
295
|
});
|
|
299
|
-
|
|
300
296
|
if (props.background) {
|
|
301
297
|
paths.unshift( /*#__PURE__*/React.createElement(ReactMinimalPieChartPath, {
|
|
302
298
|
cx: cx,
|
|
@@ -310,7 +306,6 @@ function renderSegments(data, props, revealOverride) {
|
|
|
310
306
|
stroke: props.background
|
|
311
307
|
}));
|
|
312
308
|
}
|
|
313
|
-
|
|
314
309
|
return paths;
|
|
315
310
|
}
|
|
316
311
|
|
|
@@ -327,30 +322,17 @@ var defaultProps = {
|
|
|
327
322
|
startAngle: 0,
|
|
328
323
|
viewBoxSize: [100, 100]
|
|
329
324
|
};
|
|
330
|
-
function ReactMinimalPieChart(
|
|
325
|
+
function ReactMinimalPieChart(originalProps) {
|
|
326
|
+
var props = makePropsWithDefaults(originalProps,
|
|
327
|
+
// @ts-expect-error: defaultProps.data is typed as BaseDataEntry
|
|
328
|
+
defaultProps);
|
|
331
329
|
var _useState = useState(props.animate ? 0 : null),
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
revealOverride = _useState[0],
|
|
331
|
+
setRevealOverride = _useState[1];
|
|
335
332
|
useEffect(function () {
|
|
336
333
|
if (props.animate) {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
function startInitialAnimation() {
|
|
341
|
-
var animationTimerId;
|
|
342
|
-
var animationRAFId;
|
|
343
|
-
animationTimerId = setTimeout(function () {
|
|
344
|
-
animationTimerId = null;
|
|
345
|
-
animationRAFId = requestAnimationFrame(function () {
|
|
346
|
-
animationRAFId = null;
|
|
347
|
-
setRevealOverride(null); // Start animation
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
return function () {
|
|
351
|
-
animationTimerId && clearTimeout(animationTimerId);
|
|
352
|
-
animationRAFId && cancelAnimationFrame(animationRAFId);
|
|
353
|
-
};
|
|
334
|
+
// Trigger initial animation
|
|
335
|
+
setRevealOverride(null);
|
|
354
336
|
}
|
|
355
337
|
}, []);
|
|
356
338
|
var extendedData = extendData(props);
|
|
@@ -360,9 +342,8 @@ function ReactMinimalPieChart(props) {
|
|
|
360
342
|
height: "100%",
|
|
361
343
|
className: props.className,
|
|
362
344
|
style: props.style
|
|
363
|
-
}, renderSegments(extendedData, props, revealOverride),
|
|
345
|
+
}, renderSegments(extendedData, props, revealOverride), renderLabels(extendedData, props), props.children);
|
|
364
346
|
}
|
|
365
|
-
ReactMinimalPieChart.defaultProps = defaultProps;
|
|
366
347
|
|
|
367
|
-
export { ReactMinimalPieChart as PieChart };
|
|
348
|
+
export { ReactMinimalPieChart as PieChart, defaultProps as pieChartDefaultProps };
|
|
368
349
|
//# sourceMappingURL=index.js.map
|