gifted-charts-core 0.1.20 → 0.1.22

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}/BarChart/types.d.ts +2 -1
  2. package/{src → dist}/LineChart/index.d.ts +0 -3
  3. package/{src → dist}/LineChart/index.js +5 -54
  4. package/{src → dist}/LineChart/types.d.ts +2 -1
  5. package/{src → dist}/PopulationPyramid/index.js +4 -3
  6. package/{src → dist}/PopulationPyramid/types.d.ts +3 -1
  7. package/{src → dist}/components/BarAndLineChartsWrapper/index.d.ts +1 -0
  8. package/{src → dist}/components/BarAndLineChartsWrapper/index.js +6 -4
  9. package/{src → dist}/components/common/types.d.ts +9 -8
  10. package/{src → dist}/index.d.ts +2 -1
  11. package/{src → dist}/utils/constants.d.ts +2 -0
  12. package/{src → dist}/utils/constants.js +2 -0
  13. package/{src → dist}/utils/index.js +1 -0
  14. package/{src → dist}/utils/types.d.ts +1 -0
  15. package/package.json +4 -4
  16. package/src/BarChart/Animated2DWithGradient.js.map +0 -1
  17. package/src/BarChart/Animated2DWithGradient.ts +0 -192
  18. package/src/BarChart/RenderStackBars.js.map +0 -1
  19. package/src/BarChart/RenderStackBars.ts +0 -160
  20. package/src/BarChart/index.js.map +0 -1
  21. package/src/BarChart/index.ts +0 -909
  22. package/src/BarChart/types.js.map +0 -1
  23. package/src/BarChart/types.ts +0 -666
  24. package/src/LineChart/LineChartBiColor.js.map +0 -1
  25. package/src/LineChart/LineChartBiColor.ts +0 -613
  26. package/src/LineChart/index.js.map +0 -1
  27. package/src/LineChart/index.ts +0 -2205
  28. package/src/LineChart/types.js.map +0 -1
  29. package/src/LineChart/types.ts +0 -614
  30. package/src/PieChart/index.js.map +0 -1
  31. package/src/PieChart/index.ts +0 -180
  32. package/src/PieChart/main.js.map +0 -1
  33. package/src/PieChart/main.ts +0 -173
  34. package/src/PieChart/pro.ts +0 -309
  35. package/src/PieChart/types.js.map +0 -1
  36. package/src/PieChart/types.ts +0 -105
  37. package/src/PopulationPyramid/index.js.map +0 -1
  38. package/src/PopulationPyramid/index.ts +0 -358
  39. package/src/PopulationPyramid/types.js.map +0 -1
  40. package/src/PopulationPyramid/types.ts +0 -256
  41. package/src/components/AnimatedThreeDBar/index.js.map +0 -1
  42. package/src/components/AnimatedThreeDBar/index.ts +0 -60
  43. package/src/components/BarAndLineChartsWrapper/getHorizSectionsVals.js.map +0 -1
  44. package/src/components/BarAndLineChartsWrapper/getHorizSectionsVals.ts +0 -408
  45. package/src/components/BarAndLineChartsWrapper/index.js.map +0 -1
  46. package/src/components/BarAndLineChartsWrapper/index.ts +0 -404
  47. package/src/components/common/StripAndLabel.js.map +0 -1
  48. package/src/components/common/StripAndLabel.ts +0 -80
  49. package/src/components/common/types.ts +0 -32
  50. package/src/index.ts +0 -152
  51. package/src/utils/constants.js.map +0 -1
  52. package/src/utils/constants.ts +0 -347
  53. package/src/utils/index.js.map +0 -1
  54. package/src/utils/index.ts +0 -1562
  55. package/src/utils/types.js.map +0 -1
  56. package/src/utils/types.ts +0 -436
  57. /package/{src → dist}/BarChart/Animated2DWithGradient.d.ts +0 -0
  58. /package/{src → dist}/BarChart/Animated2DWithGradient.js +0 -0
  59. /package/{src → dist}/BarChart/RenderStackBars.d.ts +0 -0
  60. /package/{src → dist}/BarChart/RenderStackBars.js +0 -0
  61. /package/{src → dist}/BarChart/index.d.ts +0 -0
  62. /package/{src → dist}/BarChart/index.js +0 -0
  63. /package/{src → dist}/BarChart/types.js +0 -0
  64. /package/{src → dist}/LineChart/LineChartBiColor.d.ts +0 -0
  65. /package/{src → dist}/LineChart/LineChartBiColor.js +0 -0
  66. /package/{src → dist}/LineChart/types.js +0 -0
  67. /package/{src → dist}/PieChart/index.d.ts +0 -0
  68. /package/{src → dist}/PieChart/index.js +0 -0
  69. /package/{src → dist}/PieChart/main.d.ts +0 -0
  70. /package/{src → dist}/PieChart/main.js +0 -0
  71. /package/{src → dist}/PieChart/pro.d.ts +0 -0
  72. /package/{src → dist}/PieChart/pro.js +0 -0
  73. /package/{src → dist}/PieChart/types.d.ts +0 -0
  74. /package/{src → dist}/PieChart/types.js +0 -0
  75. /package/{src → dist}/PopulationPyramid/index.d.ts +0 -0
  76. /package/{src → dist}/PopulationPyramid/types.js +0 -0
  77. /package/{src → dist}/components/AnimatedThreeDBar/index.d.ts +0 -0
  78. /package/{src → dist}/components/AnimatedThreeDBar/index.js +0 -0
  79. /package/{src → dist}/components/BarAndLineChartsWrapper/getHorizSectionsVals.d.ts +0 -0
  80. /package/{src → dist}/components/BarAndLineChartsWrapper/getHorizSectionsVals.js +0 -0
  81. /package/{src → dist}/components/common/StripAndLabel.d.ts +0 -0
  82. /package/{src → dist}/components/common/StripAndLabel.js +0 -0
  83. /package/{src → dist}/components/common/types.js +0 -0
  84. /package/{src → dist}/index.js +0 -0
  85. /package/{src → dist}/utils/index.d.ts +0 -0
  86. /package/{src → dist}/utils/types.js +0 -0
@@ -1,909 +0,0 @@
1
- import { useEffect, useMemo, useState } from 'react'
2
- import {
3
- type lineConfigType,
4
- type BarChartPropsType,
5
- type barDataItem,
6
- type stackDataItem
7
- } from './types'
8
- import {
9
- getArrowPoints,
10
- getAxesAndRulesProps,
11
- getExtendedContainerHeightWithPadding,
12
- getLineConfigForBarChart,
13
- getMaxValue,
14
- getMostNegativeValue,
15
- getNoOfSections,
16
- getSecondaryDataWithOffsetIncluded,
17
- getXForLineInBar,
18
- getYForLineInBar,
19
- maxAndMinUtil,
20
- svgPath
21
- } from '../utils'
22
- import {
23
- AxesAndRulesDefaults,
24
- BarDefaults,
25
- chartTypes,
26
- defaultLineConfig,
27
- defaultPointerConfig
28
- } from '../utils/constants'
29
- import {
30
- type BarAndLineChartsWrapperTypes,
31
- type secondaryYAxisType
32
- } from '../utils/types'
33
- import { type Animated } from 'react-native'
34
-
35
- export interface extendedBarChartPropsType extends BarChartPropsType {
36
- parentWidth: number
37
- heightValue?: Animated.Value
38
- widthValue?: Animated.Value
39
- opacValue?: Animated.Value
40
- verticalLinesUptoDataPoint?: boolean
41
- secondaryYAxis?: secondaryYAxisType | boolean
42
- }
43
-
44
- export const useBarChart = (props: extendedBarChartPropsType) => {
45
- const {
46
- heightValue,
47
- widthValue,
48
- opacValue,
49
- yAxisOffset,
50
- adjustToWidth,
51
- parentWidth,
52
- labelsDistanceFromXaxis,
53
- autoShiftLabelsForNegativeStacks,
54
- focusedBarIndex,
55
- negativeStepValue,
56
- autoCenterTooltip
57
- } = props
58
- const [points, setPoints] = useState('')
59
- const [points2, setPoints2] = useState('')
60
- const [arrowPoints, setArrowPoints] = useState('')
61
- const [selectedIndex, setSelectedIndex] = useState(focusedBarIndex ?? -1)
62
- const showLine = props.showLine ?? BarDefaults.showLine
63
-
64
- useEffect(() => {
65
- setSelectedIndex(focusedBarIndex ?? -1)
66
- }, [focusedBarIndex])
67
-
68
- const data = useMemo(() => {
69
- if (!props.data) {
70
- return []
71
- }
72
- if (yAxisOffset) {
73
- return props.data.map((item) => ({
74
- ...item,
75
- value: (item.value ?? 0) - (yAxisOffset ?? 0)
76
- }))
77
- }
78
- return props.data
79
- }, [yAxisOffset, props.data])
80
-
81
- const yAxisLabelWidth =
82
- props.yAxisLabelWidth ??
83
- (props.hideYAxisText
84
- ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
85
- : AxesAndRulesDefaults.yAxisLabelWidth)
86
-
87
- const autoComputedSectionWidth =
88
- props.initialSpacing !== undefined
89
- ? (parentWidth - yAxisLabelWidth) / data.length - props.initialSpacing
90
- : (parentWidth - yAxisLabelWidth) / (data.length + 0.5)
91
-
92
- const autoComputedBarWidth = autoComputedSectionWidth * 0.6
93
- const defaultBarWidth = adjustToWidth
94
- ? autoComputedBarWidth
95
- : BarDefaults.barWidth
96
- const barWidth = props.barWidth ?? defaultBarWidth
97
-
98
- const autoComputedSpacing = autoComputedSectionWidth * 0.4
99
-
100
- const spacing =
101
- props.spacing ?? (adjustToWidth ? autoComputedSpacing : BarDefaults.spacing)
102
- const initialSpacing = props.initialSpacing ?? spacing
103
- const endSpacing = props.endSpacing ?? spacing
104
- const showFractionalValues =
105
- props.showFractionalValues ?? AxesAndRulesDefaults.showFractionalValues
106
-
107
- const horizontal = props.horizontal ?? BarDefaults.horizontal
108
- const rtl = props.rtl ?? BarDefaults.rtl
109
- const yAxisAtTop = props.yAxisAtTop ?? BarDefaults.yAxisAtTop
110
- const intactTopLabel = props.intactTopLabel ?? BarDefaults.intactTopLabel
111
-
112
- const heightFromProps = horizontal ? props.width : props.height
113
- const widthFromProps = horizontal ? props.height : props.width
114
-
115
- const isAnimated = props.isAnimated ?? BarDefaults.isAnimated
116
- const animationDuration =
117
- props.animationDuration ?? BarDefaults.animationDuration
118
-
119
- const secondaryData = getSecondaryDataWithOffsetIncluded(
120
- props.secondaryData,
121
- props.secondaryYAxis
122
- )
123
-
124
- const lineData = useMemo(() => {
125
- if (!props.lineData) {
126
- return props.stackData ?? data
127
- }
128
- if (yAxisOffset) {
129
- return props.lineData.map((item) => ({
130
- ...item,
131
- value: (item.value ?? 0) - (yAxisOffset ?? 0)
132
- }))
133
- }
134
- return props.lineData
135
- }, [yAxisOffset, props.lineData, data, props.stackData])
136
-
137
- const lineData2 = props.lineData2
138
-
139
- const lineBehindBars = props.lineBehindBars ?? BarDefaults.lineBehindBars
140
-
141
- defaultLineConfig.initialSpacing = initialSpacing
142
- defaultLineConfig.endIndex = lineData.length - 1
143
- defaultLineConfig.animationDuration = animationDuration
144
-
145
- const lineConfig: lineConfigType = props.lineConfig
146
- ? getLineConfigForBarChart(props.lineConfig, initialSpacing)
147
- : defaultLineConfig
148
- const lineConfig2: lineConfigType = props.lineConfig2
149
- ? getLineConfigForBarChart(props.lineConfig2, initialSpacing)
150
- : defaultLineConfig
151
- const noOfSections = getNoOfSections(
152
- props.noOfSections,
153
- props.maxValue,
154
- props.stepValue
155
- )
156
- const containerHeight =
157
- heightFromProps ??
158
- (props.stepHeight
159
- ? props.stepHeight * noOfSections
160
- : AxesAndRulesDefaults.containerHeight)
161
- const horizSections = [{ value: '0' }]
162
- const stepHeight = props.stepHeight ?? containerHeight / noOfSections
163
- const labelWidth = props.labelWidth ?? AxesAndRulesDefaults.labelWidth
164
- const scrollToEnd = props.scrollToEnd ?? BarDefaults.scrollToEnd
165
- const scrollAnimation = props.scrollAnimation ?? BarDefaults.scrollAnimation
166
- const scrollEventThrottle =
167
- props.scrollEventThrottle ?? BarDefaults.scrollEventThrottle
168
- const labelsExtraHeight =
169
- props.labelsExtraHeight ?? AxesAndRulesDefaults.labelsExtraHeight
170
-
171
- let totalWidth = initialSpacing + endSpacing
172
- let maxItem = 0
173
- let minItem = 0
174
- if (props.stackData) {
175
- props.stackData.forEach((stackItem, index) => {
176
- const stackSumMax = stackItem.stacks.reduce(
177
- (acc, stack) => acc + (stack.value >= 0 ? stack.value : 0),
178
- 0
179
- )
180
- const stackSumMin = stackItem.stacks.reduce(
181
- (acc, stack) => acc + (stack.value < 0 ? stack.value : 0),
182
- 0
183
- )
184
-
185
- if (stackSumMax > maxItem) {
186
- maxItem = stackSumMax
187
- }
188
-
189
- if (stackSumMin < minItem) {
190
- minItem = stackSumMin
191
- }
192
- totalWidth +=
193
- (stackItem.stacks[0].barWidth ?? props.barWidth ?? defaultBarWidth) +
194
- (index === data.length - 1 ? 0 : stackItem.spacing ?? spacing)
195
- })
196
- } else {
197
- data.forEach((item: barDataItem, index) => {
198
- if (item.value > maxItem) {
199
- maxItem = item.value
200
- }
201
- if (item.value < minItem) {
202
- minItem = item.value
203
- }
204
- totalWidth +=
205
- (item.barWidth ?? props.barWidth ?? defaultBarWidth) +
206
- (index === data.length - 1 ? spacing : item.spacing ?? spacing)
207
- })
208
- }
209
-
210
- let secondaryMaxItem = 0
211
- let secondaryMinItem = 0
212
-
213
- if (lineConfig.isSecondary) {
214
- lineData.forEach((item) => {
215
- if ((item.value ?? 0) > secondaryMaxItem) {
216
- secondaryMaxItem = item.value ?? 0
217
- }
218
- if ((item.value ?? 0) < secondaryMinItem) {
219
- secondaryMinItem = item.value ?? 0
220
- }
221
- })
222
- }
223
-
224
- const maxAndMin = maxAndMinUtil(
225
- maxItem,
226
- minItem,
227
- props.roundToDigits,
228
- props.showFractionalValues
229
- )
230
-
231
- const secondaryMaxAndMin = maxAndMinUtil(
232
- secondaryMaxItem,
233
- secondaryMinItem,
234
- props.roundToDigits,
235
- props.showFractionalValues
236
- )
237
-
238
- const maxValue = getMaxValue(
239
- props.maxValue,
240
- props.stepValue,
241
- noOfSections,
242
- maxAndMin.maxItem
243
- )
244
- const secondaryMaxValue = lineConfig.isSecondary
245
- ? typeof props.secondaryYAxis !== 'boolean'
246
- ? (props.secondaryYAxis as secondaryYAxisType).maxValue ??
247
- secondaryMaxAndMin.maxItem
248
- : secondaryMaxAndMin.maxItem
249
- : maxValue
250
- const mostNegativeValue = getMostNegativeValue(
251
- props.mostNegativeValue,
252
- props.negativeStepValue,
253
- props.noOfSectionsBelowXAxis,
254
- maxAndMin.minItem
255
- )
256
-
257
- const stepValue = props.stepValue ?? maxValue / noOfSections
258
- const noOfSectionsBelowXAxis =
259
- props.noOfSectionsBelowXAxis ??
260
- Math.round(Math.ceil(-mostNegativeValue / (negativeStepValue ?? stepValue)))
261
- const showScrollIndicator =
262
- props.showScrollIndicator ?? BarDefaults.showScrollIndicator
263
- const side = props.side ?? BarDefaults.side
264
- const rotateLabel = props.rotateLabel ?? AxesAndRulesDefaults.rotateLabel
265
- const opacity = props.opacity ?? BarDefaults.opacity
266
- const isThreeD = props.isThreeD ?? BarDefaults.isThreeD
267
-
268
- const showXAxisIndices =
269
- props.showXAxisIndices ?? AxesAndRulesDefaults.showXAxisIndices
270
- const xAxisIndicesHeight =
271
- props.xAxisIndicesHeight ?? AxesAndRulesDefaults.xAxisIndicesHeight
272
- const xAxisIndicesWidth =
273
- props.xAxisIndicesWidth ?? AxesAndRulesDefaults.xAxisIndicesWidth
274
- const xAxisIndicesColor =
275
- props.xAxisIndicesColor ?? AxesAndRulesDefaults.xAxisIndicesColor
276
-
277
- const xAxisThickness =
278
- props.xAxisThickness ?? AxesAndRulesDefaults.xAxisThickness
279
-
280
- const xAxisTextNumberOfLines =
281
- props.xAxisTextNumberOfLines ?? AxesAndRulesDefaults.xAxisTextNumberOfLines
282
- const xAxisLabelsVerticalShift =
283
- props.xAxisLabelsVerticalShift ??
284
- AxesAndRulesDefaults.xAxisLabelsVerticalShift
285
- const horizontalRulesStyle = props.horizontalRulesStyle
286
-
287
- const autoShiftLabels = props.autoShiftLabels ?? false
288
- const barBorderColor = props.barBorderColor ?? BarDefaults.barBorderColor
289
-
290
- const extendedContainerHeight = getExtendedContainerHeightWithPadding(
291
- containerHeight,
292
- 0
293
- )
294
-
295
- const containerHeightIncludingBelowXAxis =
296
- extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight
297
-
298
- const [pointerIndex, setPointerIndex] = useState(-1)
299
- const [pointerX, setPointerX] = useState(0)
300
- const [pointerY, setPointerY] = useState(0)
301
- const [pointerItem, setPointerItem] = useState<barDataItem | stackDataItem>()
302
- const [responderStartTime, setResponderStartTime] = useState(0)
303
- const [responderActive, setResponderActive] = useState(false)
304
-
305
- const pointerConfig = props.pointerConfig
306
- const getPointerProps = props.getPointerProps ?? null
307
- const pointerHeight = pointerConfig?.height ?? defaultPointerConfig.height
308
- const pointerWidth = pointerConfig?.width ?? defaultPointerConfig.width
309
- const pointerRadius = pointerConfig?.radius ?? defaultPointerConfig.radius
310
- const pointerColor =
311
- pointerConfig?.pointerColor ?? defaultPointerConfig.pointerColor
312
- const pointerComponent =
313
- pointerConfig?.pointerComponent ?? defaultPointerConfig.pointerComponent
314
-
315
- const showPointerStrip =
316
- pointerConfig?.showPointerStrip === false
317
- ? false
318
- : defaultPointerConfig.showPointerStrip
319
- const pointerStripHeight =
320
- pointerConfig?.pointerStripHeight ?? defaultPointerConfig.pointerStripHeight
321
- const pointerStripWidth =
322
- pointerConfig?.pointerStripWidth ?? defaultPointerConfig.pointerStripWidth
323
- const pointerStripColor =
324
- pointerConfig?.pointerStripColor ?? defaultPointerConfig.pointerStripColor
325
- const pointerStripUptoDataPoint =
326
- pointerConfig?.pointerStripUptoDataPoint ??
327
- defaultPointerConfig.pointerStripUptoDataPoint
328
- const pointerLabelComponent =
329
- pointerConfig?.pointerLabelComponent ??
330
- defaultPointerConfig.pointerLabelComponent
331
- const stripOverPointer =
332
- pointerConfig?.stripOverPointer ?? defaultPointerConfig.stripOverPointer
333
- const shiftPointerLabelX =
334
- pointerConfig?.shiftPointerLabelX ?? defaultPointerConfig.shiftPointerLabelX
335
- const shiftPointerLabelY =
336
- pointerConfig?.shiftPointerLabelY ?? defaultPointerConfig.shiftPointerLabelY
337
- const pointerLabelWidth =
338
- pointerConfig?.pointerLabelWidth ?? defaultPointerConfig.pointerLabelWidth
339
- const pointerLabelHeight =
340
- pointerConfig?.pointerLabelHeight ?? defaultPointerConfig.pointerLabelHeight
341
- const autoAdjustPointerLabelPosition =
342
- pointerConfig?.autoAdjustPointerLabelPosition ??
343
- defaultPointerConfig.autoAdjustPointerLabelPosition
344
- const pointerVanishDelay =
345
- pointerConfig?.pointerVanishDelay ?? defaultPointerConfig.pointerVanishDelay
346
- const activatePointersOnLongPress =
347
- pointerConfig?.activatePointersOnLongPress ??
348
- defaultPointerConfig.activatePointersOnLongPress
349
- const activatePointersDelay =
350
- pointerConfig?.activatePointersDelay ??
351
- defaultPointerConfig.activatePointersDelay
352
- const initialPointerIndex =
353
- pointerConfig?.initialPointerIndex ??
354
- defaultPointerConfig.initialPointerIndex
355
- const initialPointerAppearDelay =
356
- pointerConfig?.initialPointerAppearDelay ??
357
- (isAnimated
358
- ? animationDuration
359
- : defaultPointerConfig.initialPointerAppearDelay)
360
- const persistPointer =
361
- pointerConfig?.persistPointer ?? defaultPointerConfig.persistPointer
362
- const hidePointer1 =
363
- pointerConfig?.hidePointer1 ?? defaultPointerConfig.hidePointer1
364
- const pointerEvents = pointerConfig?.pointerEvents
365
- const stripBehindBars =
366
- pointerConfig?.stripBehindBars ?? defaultPointerConfig.stripBehindBars
367
-
368
- const disableScroll =
369
- props.disableScroll ??
370
- (pointerConfig
371
- ? activatePointersOnLongPress
372
- ? !!responderActive
373
- : true
374
- : false)
375
-
376
- const yAxisExtraHeightAtTop = props.trimYAxisAtTop
377
- ? 0
378
- : props.yAxisExtraHeight ?? containerHeight / 20
379
-
380
- const barInnerComponent = props.barInnerComponent
381
-
382
- useEffect(() => {
383
- if (showLine) {
384
- let pp = ''
385
- let pp2 = ''
386
- const firstBarWidth =
387
- (props.stackData ?? data)?.[0].barWidth ?? props.barWidth ?? 30
388
- if (!lineConfig.curved) {
389
- for (let i = 0; i < lineData.length; i++) {
390
- if (
391
- i < (lineConfig.startIndex ?? 0) ||
392
- i > (lineConfig.endIndex ?? 0)
393
- ) {
394
- continue
395
- }
396
- const currentBarWidth =
397
- data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
398
- const currentValue = props.lineData
399
- ? props.lineData[i].value
400
- : props.stackData
401
- ? props.stackData[i].stacks.reduce(
402
- (total, item) => total + item.value,
403
- 0
404
- )
405
- : data[i].value
406
- pp +=
407
- 'L' +
408
- getXForLineInBar(
409
- i,
410
- firstBarWidth,
411
- currentBarWidth,
412
- yAxisLabelWidth,
413
- lineConfig,
414
- spacing
415
- ) +
416
- ' ' +
417
- getYForLineInBar(
418
- currentValue,
419
- lineConfig.shiftY,
420
- containerHeight,
421
- lineConfig.isSecondary ? secondaryMaxValue : maxValue
422
- ) +
423
- ' '
424
- }
425
- setPoints(pp.replace('L', 'M'))
426
- if (lineData.length > 1 && lineConfig.showArrow) {
427
- const ppArray = pp.trim().split(' ')
428
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
429
- const arrowTipX = parseInt(
430
- ppArray[ppArray.length - 2].replace('L', '')
431
- )
432
- const y1 = parseInt(ppArray[ppArray.length - 3])
433
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
434
-
435
- const arrowPoints = getArrowPoints(
436
- arrowTipX,
437
- arrowTipY,
438
- x1,
439
- y1,
440
- lineConfig.arrowConfig?.length,
441
- lineConfig.arrowConfig?.width,
442
- lineConfig.arrowConfig?.showArrowBase
443
- )
444
-
445
- setArrowPoints(arrowPoints)
446
- }
447
- } else {
448
- const p1Array: number[][] = []
449
- for (let i = 0; i < lineData.length; i++) {
450
- if (
451
- i < (lineConfig.startIndex ?? 0) ||
452
- i > (lineConfig.endIndex ?? 0)
453
- ) {
454
- continue
455
- }
456
- const currentBarWidth =
457
- data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
458
- const currentValue = props.lineData
459
- ? props.lineData[i].value
460
- : props.stackData
461
- ? props.stackData[i].stacks.reduce(
462
- (total, item) => total + item.value,
463
- 0
464
- )
465
- : data[i].value
466
- p1Array.push([
467
- getXForLineInBar(
468
- i,
469
- firstBarWidth,
470
- currentBarWidth,
471
- yAxisLabelWidth,
472
- lineConfig,
473
- spacing
474
- ),
475
- getYForLineInBar(
476
- currentValue,
477
- lineConfig.shiftY,
478
- containerHeight,
479
- lineConfig.isSecondary ? secondaryMaxValue : maxValue
480
- )
481
- ])
482
- const xx = svgPath(
483
- p1Array,
484
- lineConfig.curveType,
485
- lineConfig.curvature
486
- )
487
- setPoints(xx)
488
- }
489
- }
490
- if (lineData2?.length) {
491
- if (!lineConfig2?.curved) {
492
- for (let i = 0; i < lineData2.length; i++) {
493
- if (
494
- i < (lineConfig2.startIndex ?? 0) ||
495
- i > (lineConfig2.endIndex ?? 0)
496
- ) {
497
- continue
498
- }
499
- const currentBarWidth =
500
- data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
501
- const currentValue = lineData2[i].value
502
- pp2 +=
503
- 'L' +
504
- getXForLineInBar(
505
- i,
506
- firstBarWidth,
507
- currentBarWidth,
508
- yAxisLabelWidth,
509
- lineConfig2,
510
- spacing
511
- ) +
512
- ' ' +
513
- getYForLineInBar(
514
- currentValue,
515
- lineConfig2.shiftY,
516
- containerHeight,
517
- lineConfig2.isSecondary ? secondaryMaxValue : maxValue
518
- ) +
519
- ' '
520
- }
521
- setPoints2(pp2.replace('L', 'M'))
522
- } else {
523
- const p2Array: number[][] = []
524
- for (let i = 0; i < lineData2.length; i++) {
525
- if (
526
- i < (lineConfig2.startIndex ?? 0) ||
527
- i > (lineConfig2.endIndex ?? 0)
528
- ) {
529
- continue
530
- }
531
- const currentBarWidth =
532
- data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
533
- const currentValue = lineData2[i].value
534
- p2Array.push([
535
- getXForLineInBar(
536
- i,
537
- firstBarWidth,
538
- currentBarWidth,
539
- yAxisLabelWidth,
540
- lineConfig2,
541
- spacing
542
- ),
543
- getYForLineInBar(
544
- currentValue,
545
- lineConfig2.shiftY,
546
- containerHeight,
547
- lineConfig2.isSecondary ? secondaryMaxValue : maxValue
548
- )
549
- ])
550
- const xx = svgPath(
551
- p2Array,
552
- lineConfig2.curveType,
553
- lineConfig2.curvature
554
- )
555
- setPoints2(xx)
556
- }
557
- }
558
- }
559
- }
560
- }, [
561
- animationDuration,
562
- containerHeight,
563
- data,
564
- lineData,
565
- initialSpacing,
566
- lineConfig.initialSpacing,
567
- lineConfig.curved,
568
- lineConfig.dataPointsWidth,
569
- lineConfig.shiftY,
570
- lineConfig.isAnimated,
571
- lineConfig.delay,
572
- lineConfig.startIndex,
573
- lineConfig.endIndex,
574
- maxValue,
575
- props.barWidth,
576
- showLine,
577
- spacing,
578
- yAxisLabelWidth,
579
- lineConfig.showArrow,
580
- lineConfig.arrowConfig?.length,
581
- lineConfig.arrowConfig?.width,
582
- lineConfig.arrowConfig?.showArrowBase
583
- ])
584
- useEffect(() => {
585
- if (initialPointerIndex !== -1) {
586
- const item = (props.stackData ?? data)?.[initialPointerIndex]
587
- const stackItem = props.stackData?.[initialPointerIndex]
588
- const stackSum = stackItem?.stacks?.reduce(
589
- (acc, stack) => acc + (stack.value ?? 0),
590
- 0
591
- )
592
- const x =
593
- initialSpacing +
594
- (spacing + barWidth) * initialPointerIndex -
595
- (pointerRadius ?? pointerWidth / 2) +
596
- barWidth / 2
597
- const y =
598
- containerHeight -
599
- ((stackSum ?? data[initialPointerIndex].value) * containerHeight) /
600
- maxValue -
601
- (pointerRadius ?? pointerHeight / 2) +
602
- 10
603
- if (initialPointerAppearDelay) {
604
- setTimeout(() => {
605
- setPointerConfig(initialPointerIndex, item, x, y)
606
- }, initialPointerAppearDelay)
607
- } else {
608
- setPointerConfig(initialPointerIndex, item, x, y)
609
- }
610
- }
611
- }, [])
612
-
613
- const setPointerConfig = (
614
- initialPointerIndex: number,
615
- item: barDataItem | stackDataItem,
616
- x: number,
617
- y: number
618
- ): void => {
619
- setPointerIndex(initialPointerIndex)
620
- setPointerItem(item)
621
- setPointerX(x)
622
- setPointerY(y)
623
- }
624
-
625
- const animatedHeight = heightValue?.interpolate({
626
- inputRange: [0, 1],
627
- outputRange: ['0%', '100%']
628
- })
629
- const appearingOpacity = opacValue?.interpolate({
630
- inputRange: [0, 1],
631
- outputRange: [0, 1]
632
- })
633
-
634
- const animatedWidth = widthValue?.interpolate({
635
- inputRange: [0, 1],
636
- outputRange: [0, initialSpacing + totalWidth]
637
- })
638
-
639
- const getPropsCommonForBarAndStack = (item: any, index: number) => {
640
- return {
641
- item,
642
- index,
643
- containerHeight,
644
- maxValue,
645
- spacing: item.spacing ?? spacing,
646
- propSpacing: spacing,
647
- xAxisThickness,
648
- barWidth: props.barWidth ?? defaultBarWidth,
649
- opacity,
650
- disablePress: item.disablePress ?? props.disablePress,
651
- rotateLabel,
652
- showXAxisIndices,
653
- xAxisIndicesHeight,
654
- xAxisIndicesWidth,
655
- xAxisIndicesColor,
656
- labelsDistanceFromXaxis:
657
- item.labelsDistanceFromXaxis ?? labelsDistanceFromXaxis,
658
- horizontal,
659
- rtl,
660
- intactTopLabel,
661
- showValuesAsTopLabel: props.showValuesAsTopLabel,
662
- topLabelContainerStyle: props.topLabelContainerStyle,
663
- topLabelTextStyle: props.topLabelTextStyle,
664
- barBorderWidth: props.barBorderWidth,
665
- barBorderColor,
666
- barBorderRadius: props.barBorderRadius,
667
- barBorderTopLeftRadius: props.barBorderTopLeftRadius,
668
- barBorderTopRightRadius: props.barBorderTopRightRadius,
669
- barBorderBottomLeftRadius: props.barBorderBottomLeftRadius,
670
- barBorderBottomRightRadius: props.barBorderBottomRightRadius,
671
- barInnerComponent,
672
- color: props.color,
673
- showGradient: props.showGradient,
674
- gradientColor: props.gradientColor,
675
- barBackgroundPattern: props.barBackgroundPattern,
676
- patternId: props.patternId,
677
- onPress: props.onPress,
678
- onLongPress: props.onLongPress,
679
- onPressOut: props.onPressOut,
680
- focusBarOnPress: props.focusBarOnPress,
681
- focusedBarConfig: props.focusedBarConfig,
682
- xAxisTextNumberOfLines,
683
- xAxisLabelsHeight: props.xAxisLabelsHeight,
684
- xAxisLabelsVerticalShift,
685
- renderTooltip: props.renderTooltip,
686
- leftShiftForTooltip: props.leftShiftForTooltip ?? 0,
687
- autoCenterTooltip,
688
- initialSpacing,
689
- selectedIndex,
690
- setSelectedIndex,
691
- activeOpacity: props.activeOpacity ?? 0.2,
692
- noOfSectionsBelowXAxis,
693
-
694
- leftShiftForLastIndexTooltip: props.leftShiftForLastIndexTooltip ?? 0,
695
- label:
696
- item.label ??
697
- (props.xAxisLabelTexts?.[index] ? props.xAxisLabelTexts[index] : ''),
698
- secondaryLabel:
699
- item.secondaryLabel ?? props.secondaryXAxis?.labelTexts?.[index] ?? '',
700
- labelTextStyle: item.labelTextStyle ?? props.xAxisLabelTextStyle,
701
- secondaryLabelTextStyle:
702
- item.secondaryLabelTextStyle ??
703
- props.secondaryXAxis?.labelsTextStyle ??
704
- item.labelTextStyle ??
705
- props.xAxisLabelTextStyle,
706
- pointerConfig,
707
- yAxisExtraHeightAtTop,
708
- yAxisOffset: yAxisOffset ?? 0,
709
- focusedBarIndex,
710
- stepHeight,
711
- stepValue,
712
- negativeStepHeight: props.negativeStepHeight ?? stepHeight,
713
- negativeStepValue: props.negativeStepValue ?? stepValue,
714
- secondaryXAxis: props.secondaryXAxis
715
- }
716
- }
717
-
718
- const barAndLineChartsWrapperProps: BarAndLineChartsWrapperTypes = {
719
- chartType: chartTypes.BAR,
720
- containerHeight,
721
- noOfSectionsBelowXAxis,
722
- stepHeight,
723
- negativeStepHeight: props.negativeStepHeight ?? stepHeight,
724
- labelsExtraHeight,
725
- yAxisLabelWidth,
726
- horizontal,
727
- rtl,
728
- shiftX: props.shiftX ?? 0,
729
- shiftY: props.shiftY ?? 0,
730
- yAxisAtTop,
731
- initialSpacing,
732
- data,
733
- stackData: props.stackData,
734
- secondaryData,
735
- barWidth: props.barWidth ?? defaultBarWidth,
736
- xAxisThickness,
737
- totalWidth,
738
- disableScroll,
739
- showScrollIndicator,
740
- scrollToEnd,
741
- scrollToIndex: props.scrollToIndex,
742
- scrollAnimation,
743
- scrollEventThrottle,
744
- indicatorColor: props.indicatorColor,
745
- selectedIndex,
746
- setSelectedIndex,
747
- spacing,
748
- showLine,
749
- lineConfig,
750
- lineConfig2,
751
- maxValue,
752
- lineData,
753
- lineData2,
754
- animatedWidth,
755
- lineBehindBars,
756
- points,
757
- points2,
758
- arrowPoints,
759
-
760
- // horizSectionProps-
761
- width: widthFromProps,
762
- horizSections,
763
- endSpacing,
764
- horizontalRulesStyle,
765
- noOfSections,
766
- sectionColors: props.sectionColors,
767
- showFractionalValues,
768
-
769
- axesAndRulesProps: getAxesAndRulesProps(
770
- props,
771
- stepValue,
772
- negativeStepValue,
773
- secondaryMaxValue
774
- ),
775
-
776
- yAxisLabelTexts: props.yAxisLabelTexts,
777
- yAxisOffset: yAxisOffset,
778
- rotateYAxisTexts: props.rotateYAxisTexts,
779
- hideAxesAndRules: props.hideAxesAndRules,
780
-
781
- showXAxisIndices,
782
- xAxisIndicesHeight,
783
- xAxisIndicesWidth,
784
- xAxisIndicesColor,
785
-
786
- // These are Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
787
- pointerConfig,
788
- getPointerProps,
789
- pointerIndex,
790
- pointerX,
791
- pointerY,
792
-
793
- onEndReached: props.onEndReached,
794
- onStartReached: props.onStartReached,
795
- endReachedOffset: props.endReachedOffset ?? BarDefaults.endReachedOffset,
796
- onMomentumScrollEnd: props.onMomentumScrollEnd
797
- }
798
-
799
- return {
800
- lineConfig,
801
- hidePointer1,
802
- pointerItem,
803
- pointerY,
804
- pointerConfig,
805
- pointerColor,
806
- pointerX,
807
- pointerComponent,
808
- pointerHeight,
809
- pointerRadius,
810
- pointerWidth,
811
- autoAdjustPointerLabelPosition,
812
- pointerLabelWidth,
813
- activatePointersOnLongPress,
814
- yAxisLabelWidth,
815
- shiftPointerLabelX,
816
- pointerLabelHeight,
817
- pointerStripUptoDataPoint,
818
- pointerStripHeight,
819
- shiftPointerLabelY,
820
- showPointerStrip,
821
- pointerStripWidth,
822
- containerHeight,
823
- xAxisThickness,
824
- pointerStripColor,
825
- pointerEvents,
826
- setResponderStartTime,
827
- setPointerY,
828
- setPointerItem,
829
- initialSpacing,
830
- spacing,
831
- data,
832
- barWidth,
833
- setPointerX,
834
- setPointerIndex,
835
- maxValue,
836
- maxItem,
837
- responderStartTime,
838
- responderActive,
839
- setResponderActive,
840
- activatePointersDelay,
841
- persistPointer,
842
- pointerVanishDelay,
843
- containerHeightIncludingBelowXAxis,
844
- extendedContainerHeight,
845
- totalWidth,
846
- stripBehindBars,
847
- noOfSectionsBelowXAxis,
848
- stepHeight,
849
- xAxisLabelsVerticalShift,
850
- labelsExtraHeight,
851
- stripOverPointer,
852
- pointerLabelComponent,
853
- opacity,
854
- rotateLabel,
855
- showXAxisIndices,
856
- xAxisIndicesHeight,
857
- xAxisIndicesWidth,
858
- xAxisIndicesColor,
859
- autoShiftLabelsForNegativeStacks,
860
- horizontal,
861
- rtl,
862
- intactTopLabel,
863
- barBorderColor,
864
- barInnerComponent,
865
- xAxisTextNumberOfLines,
866
- selectedIndex,
867
- setSelectedIndex,
868
- isAnimated,
869
- animationDuration,
870
- side,
871
- labelWidth,
872
- isThreeD,
873
- animatedHeight,
874
- appearingOpacity,
875
- autoShiftLabels,
876
- yAxisAtTop,
877
- secondaryData,
878
- disableScroll,
879
- showScrollIndicator,
880
- scrollToEnd,
881
- scrollAnimation,
882
- scrollEventThrottle,
883
- showLine,
884
- lineConfig2,
885
- lineData,
886
- lineData2,
887
- animatedWidth,
888
- lineBehindBars,
889
- points,
890
- setPoints,
891
- points2,
892
- setPoints2,
893
- arrowPoints,
894
- setArrowPoints,
895
- horizSections,
896
- endSpacing,
897
- horizontalRulesStyle,
898
- noOfSections,
899
- showFractionalValues,
900
- widthFromProps,
901
- stepValue,
902
- secondaryMaxValue,
903
- getPointerProps,
904
- pointerIndex,
905
- getPropsCommonForBarAndStack,
906
- barAndLineChartsWrapperProps,
907
- yAxisExtraHeightAtTop
908
- }
909
- }