gifted-charts-core 0.1.21 → 0.1.23

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.
Files changed (86) hide show
  1. package/{src → dist}/LineChart/index.d.ts +0 -3
  2. package/{src → dist}/LineChart/index.js +5 -54
  3. package/{src → dist}/components/common/types.d.ts +9 -8
  4. package/{src → dist}/index.d.ts +1 -0
  5. package/{src → dist}/utils/index.js +8 -2
  6. package/package.json +4 -4
  7. package/src/BarChart/Animated2DWithGradient.js.map +0 -1
  8. package/src/BarChart/Animated2DWithGradient.ts +0 -192
  9. package/src/BarChart/RenderStackBars.js.map +0 -1
  10. package/src/BarChart/RenderStackBars.ts +0 -160
  11. package/src/BarChart/index.js.map +0 -1
  12. package/src/BarChart/index.ts +0 -909
  13. package/src/BarChart/types.js.map +0 -1
  14. package/src/BarChart/types.ts +0 -668
  15. package/src/LineChart/LineChartBiColor.js.map +0 -1
  16. package/src/LineChart/LineChartBiColor.ts +0 -613
  17. package/src/LineChart/index.js.map +0 -1
  18. package/src/LineChart/index.ts +0 -2205
  19. package/src/LineChart/types.js.map +0 -1
  20. package/src/LineChart/types.ts +0 -616
  21. package/src/PieChart/index.js.map +0 -1
  22. package/src/PieChart/index.ts +0 -180
  23. package/src/PieChart/main.js.map +0 -1
  24. package/src/PieChart/main.ts +0 -173
  25. package/src/PieChart/pro.ts +0 -309
  26. package/src/PieChart/types.js.map +0 -1
  27. package/src/PieChart/types.ts +0 -105
  28. package/src/PopulationPyramid/index.js.map +0 -1
  29. package/src/PopulationPyramid/index.ts +0 -365
  30. package/src/PopulationPyramid/types.js.map +0 -1
  31. package/src/PopulationPyramid/types.ts +0 -258
  32. package/src/components/AnimatedThreeDBar/index.js.map +0 -1
  33. package/src/components/AnimatedThreeDBar/index.ts +0 -60
  34. package/src/components/BarAndLineChartsWrapper/getHorizSectionsVals.js.map +0 -1
  35. package/src/components/BarAndLineChartsWrapper/getHorizSectionsVals.ts +0 -408
  36. package/src/components/BarAndLineChartsWrapper/index.js.map +0 -1
  37. package/src/components/BarAndLineChartsWrapper/index.ts +0 -408
  38. package/src/components/common/StripAndLabel.js.map +0 -1
  39. package/src/components/common/StripAndLabel.ts +0 -80
  40. package/src/components/common/types.ts +0 -32
  41. package/src/index.ts +0 -153
  42. package/src/utils/constants.js.map +0 -1
  43. package/src/utils/constants.ts +0 -349
  44. package/src/utils/index.js.map +0 -1
  45. package/src/utils/index.ts +0 -1563
  46. package/src/utils/types.js.map +0 -1
  47. package/src/utils/types.ts +0 -442
  48. /package/{src → dist}/BarChart/Animated2DWithGradient.d.ts +0 -0
  49. /package/{src → dist}/BarChart/Animated2DWithGradient.js +0 -0
  50. /package/{src → dist}/BarChart/RenderStackBars.d.ts +0 -0
  51. /package/{src → dist}/BarChart/RenderStackBars.js +0 -0
  52. /package/{src → dist}/BarChart/index.d.ts +0 -0
  53. /package/{src → dist}/BarChart/index.js +0 -0
  54. /package/{src → dist}/BarChart/types.d.ts +0 -0
  55. /package/{src → dist}/BarChart/types.js +0 -0
  56. /package/{src → dist}/LineChart/LineChartBiColor.d.ts +0 -0
  57. /package/{src → dist}/LineChart/LineChartBiColor.js +0 -0
  58. /package/{src → dist}/LineChart/types.d.ts +0 -0
  59. /package/{src → dist}/LineChart/types.js +0 -0
  60. /package/{src → dist}/PieChart/index.d.ts +0 -0
  61. /package/{src → dist}/PieChart/index.js +0 -0
  62. /package/{src → dist}/PieChart/main.d.ts +0 -0
  63. /package/{src → dist}/PieChart/main.js +0 -0
  64. /package/{src → dist}/PieChart/pro.d.ts +0 -0
  65. /package/{src → dist}/PieChart/pro.js +0 -0
  66. /package/{src → dist}/PieChart/types.d.ts +0 -0
  67. /package/{src → dist}/PieChart/types.js +0 -0
  68. /package/{src → dist}/PopulationPyramid/index.d.ts +0 -0
  69. /package/{src → dist}/PopulationPyramid/index.js +0 -0
  70. /package/{src → dist}/PopulationPyramid/types.d.ts +0 -0
  71. /package/{src → dist}/PopulationPyramid/types.js +0 -0
  72. /package/{src → dist}/components/AnimatedThreeDBar/index.d.ts +0 -0
  73. /package/{src → dist}/components/AnimatedThreeDBar/index.js +0 -0
  74. /package/{src → dist}/components/BarAndLineChartsWrapper/getHorizSectionsVals.d.ts +0 -0
  75. /package/{src → dist}/components/BarAndLineChartsWrapper/getHorizSectionsVals.js +0 -0
  76. /package/{src → dist}/components/BarAndLineChartsWrapper/index.d.ts +0 -0
  77. /package/{src → dist}/components/BarAndLineChartsWrapper/index.js +0 -0
  78. /package/{src → dist}/components/common/StripAndLabel.d.ts +0 -0
  79. /package/{src → dist}/components/common/StripAndLabel.js +0 -0
  80. /package/{src → dist}/components/common/types.js +0 -0
  81. /package/{src → dist}/index.js +0 -0
  82. /package/{src → dist}/utils/constants.d.ts +0 -0
  83. /package/{src → dist}/utils/constants.js +0 -0
  84. /package/{src → dist}/utils/index.d.ts +0 -0
  85. /package/{src → dist}/utils/types.d.ts +0 -0
  86. /package/{src → dist}/utils/types.js +0 -0
@@ -1,180 +0,0 @@
1
- import { useEffect, useState } from 'react'
2
- import { type pieDataItem, type PieChartPropsType } from './types'
3
- import { getTextSizeForPieLabels } from '../utils'
4
- import { type ColorValue } from 'react-native'
5
-
6
- interface IusePieChart {
7
- radius: number
8
- extraRadiusForFocused: number
9
- pi: number
10
- selectedIndex: number
11
- setSelectedIndex: (index: number) => void
12
- startAngle: number
13
- endAngle: number
14
- setStartAngle: (angle: number) => void
15
- total: number
16
- setTotal: (total: number) => void
17
- data: pieDataItem[]
18
- donut?: boolean
19
- isThreeD?: boolean
20
- semiCircle?: boolean
21
- inwardExtraLengthForFocused: number
22
- canvasWidth: number
23
- canvasHeight: number
24
- strokeWidth: number
25
- innerRadius: number
26
- innerCircleColor: ColorValue
27
- innerCircleBorderWidth: number
28
- innerCircleBorderColor: ColorValue
29
- shiftInnerCenterX: number
30
- shiftInnerCenterY: number
31
- tiltAngle: string
32
- isDataShifted: boolean
33
- paddingHorizontal: number
34
- paddingVertical: number
35
- }
36
-
37
- interface IPieChartPropsType extends PieChartPropsType {
38
- pro?: boolean
39
- }
40
-
41
- export const usePieChart = (props: IPieChartPropsType): IusePieChart => {
42
- const radius = props.radius ?? 120
43
- const extraRadiusForFocused =
44
- props.extraRadiusForFocused ??
45
- (props.focusOnPress ?? props.sectionAutoFocus ? radius / 10 : 0)
46
- const pi = props.semiCircle ? Math.PI / 2 : Math.PI
47
- const [selectedIndex, setSelectedIndex] = useState(
48
- props.focusedPieIndex ?? -1
49
- ) // at the start, nothing is selected
50
- // because we're going to use a useEffect, we need startAngle and total to be state variables
51
- const [startAngle, setStartAngle] = useState(
52
- props.initialAngle ?? (props.semiCircle ? -pi : 0)
53
- )
54
- const [total, setTotal] = useState(0)
55
-
56
- useEffect(() => {
57
- setSelectedIndex(props.focusedPieIndex ?? -1)
58
- }, [props.focusedPieIndex])
59
-
60
- useEffect(() => {
61
- // Update the total, this could be use to replace the forEach : const newTotal = props.data.reduce((acc, item) => acc + item.value, 0);
62
- let newTotal = 0
63
- props.data.forEach((item) => {
64
- newTotal += item.value
65
- })
66
- setTotal(newTotal)
67
-
68
- // Update selectedIndex based on focused item
69
- const newSelectedIndex = props.data.findIndex(
70
- (item) => item.focused === true
71
- )
72
- setSelectedIndex(newSelectedIndex)
73
-
74
- // Calculate the new start angle
75
- const newStartAngle = props.initialAngle ?? (props.semiCircle ? -pi : 0)
76
- if (newSelectedIndex !== -1) {
77
- // it was !== 0 here before, which would not work, it's either !==-1 or >=0
78
- // This could be used to replace the for loop that was used before
79
- const sumBeforeSelectedIndex = props.data
80
- .slice(0, newSelectedIndex)
81
- .reduce((acc, item) => acc + item.value, 0)
82
- setStartAngle(
83
- newStartAngle + (2 * pi * sumBeforeSelectedIndex) / (newTotal || 1)
84
- )
85
- } else {
86
- setStartAngle(newStartAngle)
87
- }
88
- }, [props.data, props.initialAngle, props.semiCircle])
89
-
90
- useEffect(() => {
91
- if (selectedIndex !== -1) {
92
- const newStartAngle = props.initialAngle ?? (props.semiCircle ? -pi : 0)
93
- let start = 0
94
- for (let i = 0; i < selectedIndex; i++) {
95
- start += props.data[i].value
96
- }
97
- if (total) {
98
- setStartAngle(newStartAngle + (2 * pi * start) / (total || 1))
99
- }
100
- }
101
- }, [selectedIndex])
102
-
103
- const {
104
- pro,
105
- data,
106
- donut,
107
- isThreeD,
108
- semiCircle,
109
- inwardExtraLengthForFocused = 0,
110
- isAnimated = false,
111
- edgesRadius
112
- } = props
113
-
114
- let endAngle = props.endAngle ?? startAngle + Math.PI * (semiCircle ? 1 : 2)
115
-
116
- const canvasWidth = radius * 2
117
- const canvasHeight = isThreeD ? radius * 2.3 : radius * 2
118
-
119
- const strokeWidth = props.strokeWidth ?? 0
120
- const innerRadius = props.innerRadius ?? radius / 2.5
121
- const innerCircleColor =
122
- props.innerCircleColor ?? props.backgroundColor ?? 'white'
123
- const innerCircleBorderWidth =
124
- props.innerCircleBorderWidth ??
125
- (props.innerCircleBorderColor ? strokeWidth || 2 : 0)
126
- const innerCircleBorderColor = props.innerCircleBorderColor ?? 'lightgray'
127
- const shiftInnerCenterX = props.shiftInnerCenterX ?? 0
128
- const shiftInnerCenterY = props.shiftInnerCenterY ?? 0
129
-
130
- const tiltAngle = props.tiltAngle ?? '55deg'
131
-
132
- let isDataShifted = false
133
-
134
- data.forEach((item: any) => {
135
- if (item.shiftX || item.shiftY) {
136
- isDataShifted = true
137
- }
138
- })
139
- const textSize = getTextSizeForPieLabels(props.textSize ?? 0, radius)
140
-
141
- const paddingHorizontal =
142
- props.paddingHorizontal ?? props.labelsPosition === 'onBorder'
143
- ? (props.textBackgroundRadius ?? textSize) * 2 + 6
144
- : 0
145
- const paddingVertical =
146
- props.paddingVertical ?? props.labelsPosition === 'onBorder'
147
- ? (props.textBackgroundRadius ?? textSize) * 2 + 6
148
- : 0
149
-
150
- return {
151
- radius,
152
- extraRadiusForFocused,
153
- pi,
154
- selectedIndex,
155
- setSelectedIndex,
156
- startAngle,
157
- endAngle,
158
- setStartAngle,
159
- total,
160
- setTotal,
161
- data,
162
- donut,
163
- isThreeD,
164
- semiCircle,
165
- inwardExtraLengthForFocused,
166
- canvasWidth,
167
- canvasHeight,
168
- strokeWidth,
169
- innerRadius,
170
- innerCircleColor,
171
- innerCircleBorderWidth,
172
- innerCircleBorderColor,
173
- shiftInnerCenterX,
174
- shiftInnerCenterY,
175
- tiltAngle,
176
- isDataShifted,
177
- paddingHorizontal,
178
- paddingVertical
179
- }
180
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAGA,kCAAa,oBAAoB,GAAG,UAAC,KAAwB;;gBAEzD,IAAA,QAAQ,GAKN,KAAK,SALC,EACR,WAAW,GAIT,KAAK,YAJI,EACX,iBAAiB,GAGf,KAAK,kBAHU,EACjB,eAAe,GAEb,KAAK,gBAFQ,EACf,qBAAqB,GACnB,KAAK,sBADc,CACb;gBACV,IAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC;gBAC5B,IAAM,IAAI,GAAuB,EAAE,CAAC;gBACpC,IAAI,qBAAqB,GAAG,KAAK,CAAC;gBAClC,IAAI,QAAQ,EAAE,CAAC;oBACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;wBACzC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,iBAAiB;4BAAE,qBAAqB,GAAG,IAAI,CAAC;wBAChE,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;4BAC5B,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;wBACzB,CAAC;6BAAM,CAAC;4BACN,IAAI,CAAC,IAAI,uBACJ,QAAQ,CAAC,CAAC,CAAC,KACd,KAAK,EACH,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,UAAC,IAAI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T,KAAK,OAAA;oBACL,eAAe,iBAAA;oBACf,cAAc,gBAAA;oBACd,EAAE,IAAA;oBACF,EAAE,IAAA;oBACF,KAAK,OAAA;oBACL,KAAK,OAAA;oBACL,GAAG,KAAA;oBACH,iBAAiB,mBAAA;oBACjB,eAAe,iBAAA;oBACf,qBAAqB,uBAAA;iBACtB,CAAC;YACJ,CAAC,EAAC;QACF,CAAC"}
@@ -1,173 +0,0 @@
1
- import { getTextSizeForPieLabels } from '../utils'
2
- import { type PieChartMainProps, type pieDataItem } from './types'
3
-
4
- export const getPieChartMainProps = (props: PieChartMainProps) => {
5
- const {
6
- isThreeD,
7
- isBiggerPie,
8
- paddingHorizontal,
9
- paddingVertical,
10
- extraRadiusForFocused
11
- } = props
12
- const propData = props.data
13
- const data: pieDataItem[] = []
14
- let itemHasInnerComponent = false
15
- if (propData) {
16
- for (let i = 0; i < propData.length; i++) {
17
- if (propData[i].pieInnerComponent) itemHasInnerComponent = true
18
- if (propData[i].value !== 0) {
19
- data.push(propData[i])
20
- } else {
21
- data.push({
22
- ...propData[i],
23
- value:
24
- props.data.map((item) => item.value).reduce((v, a) => v + a) /
25
- 160000
26
- })
27
- }
28
- }
29
- }
30
- const showInnerComponent = !!props.pieInnerComponent || itemHasInnerComponent
31
-
32
- const radius = props.radius ?? 120
33
- const canvasWidth = radius * 2
34
- const canvasHeight = isThreeD ? radius * 2.3 : radius * 2
35
- const shadowWidth = props.shadowWidth ?? radius / 5
36
- const backgroundColor = props.backgroundColor ?? 'transparent'
37
- const shadowColor = props.shadowColor ?? 'lightgray'
38
- const semiCircle = props.semiCircle ?? false
39
-
40
- let pi = Math.PI
41
- const initialAngle = props.initialAngle ?? (semiCircle ? pi / -2 : 0)
42
- const shadow = props.shadow ?? false
43
- const donut = props.donut ?? false
44
- const strokeWidth = props.strokeWidth ?? 0
45
- const strokeColor =
46
- props.strokeColor ?? (strokeWidth ? 'gray' : 'transparent')
47
- const innerRadius = props.innerRadius ?? radius / 2.5
48
-
49
- const showText = props.showText ?? false
50
- const textColor = props.textColor ?? ''
51
- const textSize = getTextSizeForPieLabels(props.textSize ?? 0, radius)
52
- let tiltAngle = props.tiltAngle ?? '55deg'
53
- if (
54
- tiltAngle &&
55
- !isNaN(Number(tiltAngle)) &&
56
- !(tiltAngle + '').endsWith('deg')
57
- ) {
58
- tiltAngle += 'deg'
59
- }
60
-
61
- // const tilt = props.tilt ? Math.min(props.tilt, 1) : props.isThreeD ? 0.5 : 1;
62
- const labelsPosition = props.labelsPosition
63
- ? props.labelsPosition
64
- : donut || props.centerLabelComponent
65
- ? 'outward'
66
- : 'mid'
67
-
68
- const showTextBackground = props.showTextBackground ?? false
69
- const textBackgroundColor = props.textBackgroundColor ?? 'white'
70
- const showValuesAsLabels = props.showValuesAsLabels ?? false
71
- const showGradient = props.showGradient ?? false
72
- const gradientCenterColor = props.gradientCenterColor ?? 'white'
73
- const toggleFocusOnPress = props.toggleFocusOnPress ?? true
74
-
75
- let minShiftX = 0
76
- let maxShiftX = 0
77
- let minShiftY = 0
78
- let maxShiftY = 0
79
- let total = 0
80
-
81
- data.forEach((item: any) => {
82
- if (item.shiftX || item.shiftY) {
83
- if (minShiftX > item.shiftX) {
84
- minShiftX = item.shiftX
85
- }
86
- if (minShiftY > item.shiftY) {
87
- minShiftY = item.shiftY
88
- }
89
- if (maxShiftX < item.shiftX) {
90
- maxShiftX = item.shiftX
91
- }
92
- if (maxShiftY < item.shiftY) {
93
- maxShiftY = item.shiftY
94
- }
95
- }
96
- })
97
-
98
- const horizAdjustment = maxShiftX - minShiftX
99
- const vertAdjustment = maxShiftY - minShiftY
100
-
101
- if (semiCircle) {
102
- pi = Math.PI / 2
103
- }
104
-
105
- const cx = radius
106
- const cy = radius
107
-
108
- total =
109
- data && data.length > 0
110
- ? data.map((item) => item.value).reduce((v, a) => v + a)
111
- : 0
112
- let acc = 0
113
- let pData = data.map((item) => {
114
- acc += item.value / total
115
- return acc
116
- })
117
- acc = 0
118
- const mData = data.map((item) => {
119
- const pAcc = acc
120
- acc += item.value / total
121
- return pAcc + (acc - pAcc) / 2
122
- })
123
- pData = [0, ...pData]
124
-
125
- return {
126
- isThreeD,
127
- isBiggerPie,
128
- propData,
129
- data,
130
- itemHasInnerComponent,
131
- showInnerComponent,
132
- radius,
133
- canvasWidth,
134
- canvasHeight,
135
- shadowWidth,
136
- backgroundColor,
137
- shadowColor,
138
- semiCircle,
139
- pi,
140
- initialAngle,
141
- shadow,
142
- donut,
143
- strokeWidth,
144
- strokeColor,
145
- innerRadius,
146
- showText,
147
- textColor,
148
- textSize,
149
- tiltAngle,
150
- labelsPosition,
151
- showTextBackground,
152
- textBackgroundColor,
153
- showValuesAsLabels,
154
- showGradient,
155
- gradientCenterColor,
156
- toggleFocusOnPress,
157
- minShiftX,
158
- maxShiftX,
159
- minShiftY,
160
- maxShiftY,
161
- total,
162
- horizAdjustment,
163
- vertAdjustment,
164
- cx,
165
- cy,
166
- pData,
167
- mData,
168
- acc,
169
- paddingHorizontal,
170
- paddingVertical,
171
- extraRadiusForFocused
172
- }
173
- }
@@ -1,309 +0,0 @@
1
- import { defaultAnimationDuration } from '../utils/constants'
2
- import { PieChartPropsType, pieDataItem } from './types'
3
- import { LabelsPosition } from '../utils/types'
4
-
5
- interface IsvgProps {
6
- height: number
7
- width: number
8
- viewBox: string
9
- }
10
-
11
- interface IusePiePro {
12
- radius: number
13
- total: number
14
- donut?: boolean
15
- strokeWidth: number
16
- maxStrokeWidth: number
17
- isAnimated?: boolean
18
- animationDuration: number
19
- initial: string
20
- dInitial: string[]
21
- dFinal: string[]
22
- getStartCaps: (index: number, item: pieDataItem) => string
23
- getEndCaps: (index: number, item: pieDataItem) => string
24
- getTextCoordinates: (
25
- index: number,
26
- labelPos?: LabelsPosition
27
- ) => { x: number; y: number }
28
- labelsPosition: LabelsPosition
29
- heightFactor: number
30
- height: number
31
- svgProps: IsvgProps
32
- }
33
-
34
- export const usePiePro = (props: PieChartPropsType): IusePiePro => {
35
- const {
36
- data,
37
- isAnimated,
38
- donut,
39
- semiCircle,
40
- radius = 120,
41
- innerRadius = donut ? radius / 2.5 : 0,
42
- strokeWidth = props.ring ? 10 : 0,
43
- edgesRadius = 0,
44
- startAngle = 0,
45
- ring
46
- } = props
47
- let endAngle = props.endAngle ?? startAngle + Math.PI * (semiCircle ? 1 : 2)
48
- const total = data.reduce((acc, item) => acc + item?.value, 0)
49
- const animationDuration = props.animationDuration ?? defaultAnimationDuration
50
-
51
- const maxStrokeWidth = Math.max(
52
- ...data.map((item) => item.strokeWidth ?? 0),
53
- strokeWidth
54
- )
55
-
56
- const heightFactor = semiCircle ? 1 : 2
57
- const height = radius + maxStrokeWidth
58
-
59
- const svgProps = {
60
- height: height * 2,
61
- width: height * 2,
62
- viewBox: `${-maxStrokeWidth * 1.5} ${
63
- -maxStrokeWidth - (semiCircle ? height / 2 : 0)
64
- } ${height * 2} ${height * 2}`
65
- }
66
-
67
- // let endAngleLocal = 0
68
-
69
- const addValues = (index: number) => {
70
- if (index < 0) return 0
71
- let sum = 0
72
- for (let i = 0; i <= index; i++) sum += data[i]?.value
73
- return sum
74
- }
75
- const labelsPosition = props.labelsPosition
76
- ? props.labelsPosition
77
- : donut || props.centerLabelComponent
78
- ? 'outward'
79
- : 'mid'
80
-
81
- const getCoordinates = (
82
- index: number,
83
- additionalValue?: number,
84
- addInOnlyStart?: boolean,
85
- addInOnlyEnd?: boolean,
86
- totalParam?: number
87
- ) => {
88
- const addedValue =
89
- addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue ?? 0)
90
- let angle = (addedValue / (totalParam ?? total)) * endAngle + startAngle
91
- const startInnerX = radius + Math.cos(angle) * innerRadius
92
- const startInnerY = radius - Math.sin(angle) * innerRadius
93
- const startOuterX = radius + Math.cos(angle) * radius
94
- const startOuterY = radius - Math.sin(angle) * radius
95
-
96
- const value =
97
- addValues(index - 1) +
98
- data[index]?.value +
99
- (addInOnlyStart ? 0 : additionalValue ?? 0)
100
- angle = (value / (totalParam ?? total)) * endAngle + startAngle
101
-
102
- const endOuterX = radius + Math.cos(angle) * radius
103
- const endOuterY = radius - Math.sin(angle) * radius
104
-
105
- const endInnerX = radius + Math.cos(angle) * innerRadius
106
- const endInnerY = radius - Math.sin(angle) * innerRadius
107
-
108
- return {
109
- startInnerX,
110
- startInnerY,
111
- startOuterX,
112
- startOuterY,
113
- endOuterX,
114
- endOuterY,
115
- endInnerX,
116
- endInnerY
117
- }
118
- }
119
-
120
- const getTextCoordinates = (index: number, labelPos?: LabelsPosition) => {
121
- const value = addValues(index - 1) + data[index]?.value / 2
122
- const angle = (value / total) * endAngle + startAngle
123
-
124
- const labelPosition: LabelsPosition = labelPos || labelsPosition
125
-
126
- let x =
127
- radius +
128
- Math.cos(angle) *
129
- radius *
130
- (labelPosition === 'inward'
131
- ? 0.25
132
- : labelPosition === 'mid'
133
- ? 0.5
134
- : labelPosition === 'outward'
135
- ? 0.75
136
- : 1)
137
- let y =
138
- radius -
139
- Math.sin(angle) *
140
- radius *
141
- (labelPosition === 'inward'
142
- ? 0.25
143
- : labelPosition === 'mid'
144
- ? 0.5
145
- : labelPosition === 'outward'
146
- ? 0.75
147
- : 1)
148
-
149
- return { x, y }
150
- }
151
-
152
- var initial = ''
153
- const getInitial = (item: pieDataItem) => {
154
- if (item.isStartEdgeCurved || item.startEdgeRadius) {
155
- const { startInnerX, startInnerY, startOuterX, startOuterY } =
156
- getCoordinates(0, (radius - innerRadius) / (radius / 20))
157
-
158
- return `M${startInnerX},${startInnerY} L${startOuterX},${startOuterY} `
159
- }
160
- return ring
161
- ? `M${radius * 2},${radius}`
162
- : `M${radius + innerRadius},${radius} h${radius - innerRadius} `
163
- }
164
- const getPath = (index: number, totalParam?: number) => {
165
- const { endOuterX, endOuterY } = getCoordinates(
166
- index,
167
- 0,
168
- false,
169
- false,
170
- totalParam
171
- )
172
-
173
- const isLargeArc = semiCircle
174
- ? 0
175
- : data[index]?.value / (totalParam ?? total) > 0.5
176
- ? 1
177
- : 0
178
-
179
- const arc = `A${
180
- radius + (props.strokeWidth ?? 0) / 2
181
- },${radius} 0 ${isLargeArc} 0 `
182
- let path = `${arc} ${endOuterX}, ${endOuterY} `
183
-
184
- if (!ring) {
185
- path += `L${radius},${radius} `
186
- }
187
-
188
- initial = ring
189
- ? `M${endOuterX},${endOuterY} `
190
- : `M${radius},${radius} L${endOuterX},${endOuterY}`
191
-
192
- return path
193
- }
194
- const getDonutPath = (
195
- index: number,
196
- item: pieDataItem,
197
- totalParam?: number
198
- ) => {
199
- const additionalForStart =
200
- item.isStartEdgeCurved || item.startEdgeRadius
201
- ? (radius - innerRadius) / (radius / 20)
202
- : 0
203
-
204
- const additionalForEnd =
205
- item.isEndEdgeCurved || item.endEdgeRadius
206
- ? (radius - innerRadius) / (radius / -20)
207
- : 0
208
-
209
- const cropAtEnd = !!(
210
- index === data.length - 1 &&
211
- (item.isEndEdgeCurved || item.endEdgeRadius)
212
- )
213
- const {
214
- startInnerX,
215
- startInnerY,
216
- endOuterX,
217
- endOuterY,
218
- endInnerX,
219
- endInnerY
220
- } = getCoordinates(
221
- index,
222
- cropAtEnd ? additionalForEnd : additionalForStart,
223
- !cropAtEnd,
224
- cropAtEnd,
225
- totalParam
226
- )
227
- const isLargeArc = semiCircle
228
- ? 0
229
- : data[index]?.value / (totalParam ?? total) > 0.5
230
- ? 1
231
- : 0
232
-
233
- const innerArc = `A${innerRadius},${innerRadius} 0 ${isLargeArc} 1 `
234
- const outerArc = `A${
235
- radius + (props.strokeWidth ?? 0) / 2
236
- },${radius} 0 ${isLargeArc} 0 `
237
- const path = `${outerArc} ${endOuterX}, ${endOuterY}
238
- L${endInnerX},${endInnerY} M${endInnerX},${endInnerY} ${innerArc} ${startInnerX},${startInnerY}`
239
-
240
- initial = `M${endInnerX},${endInnerY} L${endOuterX},${endOuterY} `
241
-
242
- return path
243
- }
244
- const getStartCaps = (index: number, item: pieDataItem) => {
245
- const edgeRadius = item.startEdgeRadius ?? edgesRadius ?? 1
246
- const additional =
247
- (item.isStartEdgeCurved || item.startEdgeRadius
248
- ? (radius - innerRadius) / (radius / 20)
249
- : 0) +
250
- strokeWidth / 2
251
- const { startInnerX, startInnerY, startOuterX, startOuterY } =
252
- getCoordinates(index, additional)
253
-
254
- const path = `M${startInnerX},${startInnerY} A${edgeRadius},${edgeRadius} 0 0 0 ${startOuterX},${startOuterY}`
255
- return path
256
- }
257
- const getEndCaps = (index: number, item: pieDataItem) => {
258
- const edgeRadius = item.endEdgeRadius ?? edgesRadius ?? 1
259
- const additional =
260
- (item.isEndEdgeCurved || item.endEdgeRadius
261
- ? (radius - innerRadius) / (radius / 20)
262
- : 0) -
263
- strokeWidth / 2
264
- const { endInnerX, endInnerY, endOuterX, endOuterY } = getCoordinates(
265
- index,
266
- -additional
267
- )
268
-
269
- const path = `M${endInnerX},${endInnerY} A${edgeRadius},${edgeRadius} 0 0 1 ${endOuterX},${endOuterY}`
270
- return path
271
- }
272
-
273
- const dInitial = data.map(
274
- (item, index) =>
275
- `${initial || getInitial(item)} ${
276
- donut
277
- ? getDonutPath(index, item, total * 101)
278
- : getPath(index, total * 101)
279
- }`
280
- )
281
-
282
- initial = ''
283
- const dFinal = data.map(
284
- (item, index) =>
285
- `${initial || getInitial(item)} ${
286
- donut ? getDonutPath(index, item) : getPath(index)
287
- }`
288
- )
289
-
290
- return {
291
- radius,
292
- total,
293
- donut,
294
- strokeWidth,
295
- maxStrokeWidth,
296
- isAnimated,
297
- animationDuration,
298
- initial,
299
- dInitial,
300
- dFinal,
301
- getStartCaps,
302
- getEndCaps,
303
- getTextCoordinates,
304
- labelsPosition,
305
- heightFactor,
306
- height,
307
- svgProps
308
- }
309
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":";;;;;;QAuFA,CAAC"}