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,2205 +0,0 @@
1
- import { useEffect, useMemo, useState } from 'react'
2
- import {
3
- AxesAndRulesDefaults,
4
- LineDefaults,
5
- SEGMENT_END,
6
- SEGMENT_START,
7
- chartTypes,
8
- defaultArrowConfig,
9
- defaultPointerConfig
10
- } from '../utils/constants'
11
- import {
12
- adjustToOffset,
13
- computeMaxAndMinItems,
14
- getAllArrowProperties,
15
- getArrowPoints,
16
- getAxesAndRulesProps,
17
- getCurvePathWithSegments,
18
- getExtendedContainerHeightWithPadding,
19
- getInterpolatedData,
20
- getLineSegmentsForMissingValues,
21
- getMaxValue,
22
- getNoOfSections,
23
- getPathWithHighlight,
24
- getSanitisedData,
25
- getSecondaryDataWithOffsetIncluded,
26
- getSegmentString,
27
- svgPath
28
- } from '../utils'
29
- import {
30
- type IDataSanitisationProps,
31
- type LineChartPropsType,
32
- type lineDataItem
33
- } from './types'
34
- import {
35
- type BarAndLineChartsWrapperTypes,
36
- EdgePosition,
37
- type LineSegment
38
- } from '../utils/types'
39
- import { type Animated } from 'react-native'
40
-
41
- export interface extendedLineChartPropsType extends LineChartPropsType {
42
- animations?: Animated.Value[]
43
- // heightValue: Animated.Value
44
- // widthValue: Animated.Value
45
- // opacValue: Animated.Value
46
- parentWidth: number
47
- }
48
-
49
- export const useLineChart = (props: extendedLineChartPropsType) => {
50
- const {
51
- animations,
52
- showDataPointsForMissingValues,
53
- interpolateMissingValues = true,
54
- onlyPositive,
55
- yAxisOffset,
56
- parentWidth
57
- } = props
58
- const curvature = props.curvature ?? LineDefaults.curvature
59
- const curveType = props.curveType ?? LineDefaults.curveType
60
- const [scrollX, setScrollX] = useState(0)
61
- const [arrow1Points, setArrow1Points] = useState('')
62
- const [arrow2Points, setArrow2Points] = useState('')
63
- const [arrow3Points, setArrow3Points] = useState('')
64
- const [arrow4Points, setArrow4Points] = useState('')
65
- const [arrow5Points, setArrow5Points] = useState('')
66
- const [secondaryArrowPoints, setSecondaryArrowPoints] = useState('')
67
- const [pointerIndex, setPointerIndex] = useState(-1)
68
- const [pointerX, setPointerX] = useState(0)
69
- const [pointerY, setPointerY] = useState(0)
70
- const [pointerItem, setPointerItem] = useState<lineDataItem>()
71
-
72
- const [pointerY2, setPointerY2] = useState(0)
73
- const [pointerItem2, setPointerItem2] = useState<lineDataItem>()
74
- const [pointerY3, setPointerY3] = useState(0)
75
- const [pointerItem3, setPointerItem3] = useState<lineDataItem>()
76
- const [pointerY4, setPointerY4] = useState(0)
77
- const [pointerItem4, setPointerItem4] = useState<lineDataItem>()
78
- const [pointerY5, setPointerY5] = useState(0)
79
- const [pointerYsForDataSet, setPointerYsForDataSet] = useState<number[]>([])
80
- const [pointerItem5, setPointerItem5] = useState<lineDataItem>()
81
- const [secondaryPointerY, setSecondaryPointerY] = useState(0)
82
- const [secondaryPointerItem, setSecondaryPointerItem] = useState()
83
-
84
- const [responderStartTime, setResponderStartTime] = useState(0)
85
- const [responderActive, setResponderActive] = useState(false)
86
- const [points, setPoints] = useState('')
87
- const [points2, setPoints2] = useState('')
88
- const [points3, setPoints3] = useState('')
89
- const [points4, setPoints4] = useState('')
90
- const [points5, setPoints5] = useState('')
91
- const [secondaryPoints, setSecondaryPoints] = useState('')
92
- const [fillPoints, setFillPoints] = useState('')
93
- const [fillPoints2, setFillPoints2] = useState('')
94
- const [fillPoints3, setFillPoints3] = useState('')
95
- const [fillPoints4, setFillPoints4] = useState('')
96
- const [fillPoints5, setFillPoints5] = useState('')
97
- const [secondaryFillPoints, setSecondaryFillPoints] = useState('')
98
-
99
- const [pointsFromSet, setPointsFromSet] = useState<string[]>([])
100
- const [fillPointsFromSet, setFillPointsFromSet] = useState<string[]>([])
101
- const [arrowPointsFromSet, setArrowPointsFromSet] = useState<string[]>([])
102
-
103
- const [selectedIndex, setSelectedIndex] = useState(
104
- props.focusedDataPointIndex ?? -1
105
- )
106
-
107
- useEffect(() => {
108
- setSelectedIndex(props.focusedDataPointIndex ?? -1)
109
- }, [props.focusedDataPointIndex])
110
-
111
- const noOfSections = getNoOfSections(
112
- props.noOfSections,
113
- props.maxValue,
114
- props.stepValue
115
- )
116
- const containerHeight =
117
- props.height ??
118
- ((props.stepHeight ?? 0) * noOfSections ||
119
- AxesAndRulesDefaults.containerHeight)
120
-
121
- const dataSanitisationProps: IDataSanitisationProps = {
122
- showDataPointsForMissingValues,
123
- interpolateMissingValues,
124
- onlyPositive,
125
- yAxisOffset
126
- }
127
- const data = useMemo(
128
- () => getSanitisedData(props.data, dataSanitisationProps),
129
- [yAxisOffset, props.data]
130
- )
131
- const data2 = useMemo(
132
- () => getSanitisedData(props.data2, dataSanitisationProps),
133
- [yAxisOffset, props.data2]
134
- )
135
- const data3 = useMemo(
136
- () => getSanitisedData(props.data3, dataSanitisationProps),
137
- [yAxisOffset, props.data3]
138
- )
139
- const data4 = useMemo(
140
- () => getSanitisedData(props.data4, dataSanitisationProps),
141
- [yAxisOffset, props.data4]
142
- )
143
- const data5 = useMemo(
144
- () => getSanitisedData(props.data5, dataSanitisationProps),
145
- [yAxisOffset, props.data5]
146
- )
147
-
148
- const secondaryData =
149
- getSecondaryDataWithOffsetIncluded(
150
- props.secondaryData,
151
- props.secondaryYAxis,
152
- showDataPointsForMissingValues,
153
- interpolateMissingValues,
154
- onlyPositive
155
- ) ?? []
156
-
157
- let dataSet = props.dataSet
158
- if (dataSet?.length) {
159
- dataSet = useMemo(() => {
160
- return dataSet?.map((dataSetItem) => {
161
- const nullishHandledDataItem = getInterpolatedData(
162
- dataSetItem.data,
163
- showDataPointsForMissingValues,
164
- interpolateMissingValues,
165
- onlyPositive
166
- )
167
- return {
168
- ...dataSetItem,
169
- data: adjustToOffset(nullishHandledDataItem, yAxisOffset)
170
- }
171
- })
172
- }, [yAxisOffset, dataSet])
173
- }
174
-
175
- const data0 = dataSet?.[0]?.data
176
-
177
- const scrollToEnd = props.scrollToEnd ?? LineDefaults.scrollToEnd
178
- const scrollAnimation = props.scrollAnimation ?? LineDefaults.scrollAnimation
179
- const scrollEventThrottle =
180
- props.scrollEventThrottle ?? LineDefaults.scrollEventThrottle
181
-
182
- const labelsExtraHeight = props.labelsExtraHeight ?? 0
183
-
184
- const animationDuration =
185
- props.animationDuration ?? LineDefaults.animationDuration
186
- const onDataChangeAnimationDuration =
187
- props.onDataChangeAnimationDuration ?? 400
188
- const animateTogether = props.animateTogether ?? LineDefaults.animateTogether
189
- const animateOnDataChange = yAxisOffset
190
- ? false
191
- : props.animateOnDataChange ?? false
192
-
193
- const startIndex1 = props.startIndex1 ?? props.startIndex ?? 0
194
-
195
- let endIndex1: number
196
- if (props.endIndex1 === undefined || props.endIndex1 === null) {
197
- if (props.endIndex === undefined || props.endIndex === null) {
198
- endIndex1 = data.length - 1
199
- } else {
200
- endIndex1 = props.endIndex
201
- }
202
- } else {
203
- endIndex1 = props.endIndex1
204
- }
205
-
206
- const startIndex2 = props.startIndex2 ?? 0
207
- const endIndex2 = props.endIndex2 ?? data2.length - 1
208
-
209
- const startIndex3 = props.startIndex3 ?? 0
210
- const endIndex3 = props.endIndex3 ?? data3.length - 1
211
- const startIndex4 = props.startIndex4 ?? 0
212
- const endIndex4 = props.endIndex4 ?? data4.length - 1
213
- const startIndex5 = props.startIndex5 ?? 0
214
- const endIndex5 = props.endIndex5 ?? data5.length - 1
215
-
216
- const lineSegments = !interpolateMissingValues
217
- ? getLineSegmentsForMissingValues(props.data)
218
- : props.lineSegments
219
- const lineSegments2 = !interpolateMissingValues
220
- ? getLineSegmentsForMissingValues(props.data2)
221
- : props.lineSegments2
222
- const lineSegments3 = !interpolateMissingValues
223
- ? getLineSegmentsForMissingValues(props.data3)
224
- : props.lineSegments3
225
- const lineSegments4 = !interpolateMissingValues
226
- ? getLineSegmentsForMissingValues(props.data4)
227
- : props.lineSegments4
228
- const lineSegments5 = !interpolateMissingValues
229
- ? getLineSegmentsForMissingValues(props.data5)
230
- : props.lineSegments5
231
-
232
- const highlightedRange = props.highlightedRange
233
-
234
- let newPoints = ''
235
- let newFillPoints = ''
236
- let counter = 0
237
-
238
- const adjustToWidth = props.adjustToWidth ?? false
239
-
240
- const initialSpacing = props.initialSpacing ?? LineDefaults.initialSpacing
241
- const endSpacing =
242
- props.endSpacing ?? (adjustToWidth ? 0 : LineDefaults.endSpacing)
243
-
244
- const thickness = props.thickness ?? LineDefaults.thickness
245
-
246
- const yAxisLabelWidth =
247
- props.yAxisLabelWidth ??
248
- (props.hideYAxisText
249
- ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
250
- : AxesAndRulesDefaults.yAxisLabelWidth)
251
-
252
- const spacing =
253
- props.spacing ??
254
- (adjustToWidth
255
- ? ((props.width ?? parentWidth - yAxisLabelWidth) - initialSpacing) /
256
- Math.max((data0 ?? data).length - 1, 1)
257
- : LineDefaults.spacing)
258
-
259
- const xAxisThickness =
260
- props.xAxisThickness ?? AxesAndRulesDefaults.xAxisThickness
261
- const dataPointsHeight1 =
262
- props.dataPointsHeight1 ??
263
- props.dataPointsHeight ??
264
- LineDefaults.dataPointsHeight
265
- const dataPointsWidth1 =
266
- props.dataPointsWidth1 ??
267
- props.dataPointsWidth ??
268
- LineDefaults.dataPointsWidth
269
- const dataPointsRadius1 =
270
- props.dataPointsRadius1 ??
271
- props.dataPointsRadius ??
272
- LineDefaults.dataPointsRadius
273
- const dataPointsColor1 =
274
- props.dataPointsColor1 ??
275
- props.dataPointsColor ??
276
- LineDefaults.dataPointsColor
277
- const dataPointsShape1 =
278
- props.dataPointsShape1 ??
279
- props.dataPointsShape ??
280
- LineDefaults.dataPointsShape
281
-
282
- const dataPointsHeight2 =
283
- props.dataPointsHeight2 ??
284
- props.dataPointsHeight ??
285
- LineDefaults.dataPointsHeight
286
- const dataPointsWidth2 =
287
- props.dataPointsWidth2 ??
288
- props.dataPointsWidth ??
289
- LineDefaults.dataPointsWidth
290
- const dataPointsRadius2 =
291
- props.dataPointsRadius2 ??
292
- props.dataPointsRadius ??
293
- LineDefaults.dataPointsRadius
294
- const dataPointsColor2 =
295
- props.dataPointsColor2 ??
296
- props.dataPointsColor ??
297
- LineDefaults.dataPointsColor2
298
- const dataPointsShape2 =
299
- props.dataPointsShape2 ??
300
- props.dataPointsShape ??
301
- LineDefaults.dataPointsShape
302
-
303
- const dataPointsHeight3 =
304
- props.dataPointsHeight3 ??
305
- props.dataPointsHeight ??
306
- LineDefaults.dataPointsHeight
307
- const dataPointsWidth3 =
308
- props.dataPointsWidth3 ??
309
- props.dataPointsWidth ??
310
- LineDefaults.dataPointsWidth
311
- const dataPointsRadius3 =
312
- props.dataPointsRadius3 ??
313
- props.dataPointsRadius ??
314
- LineDefaults.dataPointsRadius
315
- const dataPointsColor3 =
316
- props.dataPointsColor3 ??
317
- props.dataPointsColor ??
318
- LineDefaults.dataPointsColor3
319
- const dataPointsShape3 =
320
- props.dataPointsShape3 ??
321
- props.dataPointsShape ??
322
- LineDefaults.dataPointsShape
323
-
324
- const dataPointsHeight4 =
325
- props.dataPointsHeight4 ??
326
- props.dataPointsHeight ??
327
- LineDefaults.dataPointsHeight
328
- const dataPointsWidth4 =
329
- props.dataPointsWidth4 ??
330
- props.dataPointsWidth ??
331
- LineDefaults.dataPointsWidth
332
- const dataPointsRadius4 =
333
- props.dataPointsRadius4 ??
334
- props.dataPointsRadius ??
335
- LineDefaults.dataPointsRadius
336
- const dataPointsColor4 =
337
- props.dataPointsColor4 ??
338
- props.dataPointsColor ??
339
- LineDefaults.dataPointsColor
340
- const dataPointsShape4 =
341
- props.dataPointsShape4 ??
342
- props.dataPointsShape ??
343
- LineDefaults.dataPointsShape
344
-
345
- const dataPointsHeight5 =
346
- props.dataPointsHeight5 ??
347
- props.dataPointsHeight ??
348
- LineDefaults.dataPointsHeight
349
- const dataPointsWidth5 =
350
- props.dataPointsWidth5 ??
351
- props.dataPointsWidth ??
352
- LineDefaults.dataPointsWidth
353
- const dataPointsRadius5 =
354
- props.dataPointsRadius5 ??
355
- props.dataPointsRadius ??
356
- LineDefaults.dataPointsRadius
357
- const dataPointsColor5 =
358
- props.dataPointsColor5 ??
359
- props.dataPointsColor ??
360
- LineDefaults.dataPointsColor
361
- const dataPointsShape5 =
362
- props.dataPointsShape5 ??
363
- props.dataPointsShape ??
364
- LineDefaults.dataPointsShape
365
-
366
- const areaChart = props.areaChart ?? false
367
- const areaChart1 = props.areaChart1 ?? false
368
- const areaChart2 = props.areaChart2 ?? false
369
- const areaChart3 = props.areaChart3 ?? false
370
- const areaChart4 = props.areaChart4 ?? false
371
- const areaChart5 = props.areaChart5 ?? false
372
-
373
- const atLeastOneAreaChart =
374
- dataSet?.some((set) => set.areaChart) ??
375
- areaChart ??
376
- areaChart1 ??
377
- areaChart2 ??
378
- areaChart3 ??
379
- areaChart4 ??
380
- areaChart5
381
-
382
- const getIsNthAreaChart = (n: number): boolean => {
383
- if (areaChart) return true
384
- if (!dataSet?.length) {
385
- switch (n) {
386
- case 0:
387
- return areaChart1
388
- case 1:
389
- return areaChart2
390
- case 2:
391
- return areaChart3
392
- case 3:
393
- return areaChart4
394
- case 4:
395
- return areaChart5
396
- }
397
- }
398
- return false
399
- }
400
-
401
- const stepChart = props.stepChart ?? false
402
- const stepChart1 = props.stepChart1 ?? false
403
- const stepChart2 = props.stepChart2 ?? false
404
- const stepChart3 = props.stepChart3 ?? false
405
- const stepChart4 = props.stepChart4 ?? false
406
- const stepChart5 = props.stepChart5 ?? false
407
-
408
- const edgePosition = props.edgePosition ?? LineDefaults.edgePosition
409
-
410
- const textFontSize1 =
411
- props.textFontSize1 ?? props.textFontSize ?? LineDefaults.textFontSize
412
- const textFontSize2 =
413
- props.textFontSize2 ?? props.textFontSize ?? LineDefaults.textFontSize
414
- const textFontSize3 =
415
- props.textFontSize3 ?? props.textFontSize ?? LineDefaults.textFontSize
416
- const textFontSize4 =
417
- props.textFontSize4 ?? props.textFontSize ?? LineDefaults.textFontSize
418
- const textFontSize5 =
419
- props.textFontSize5 ?? props.textFontSize ?? LineDefaults.textFontSize
420
- const textColor1 =
421
- props.textColor1 ?? props.textColor ?? LineDefaults.textColor
422
- const textColor2 =
423
- props.textColor2 ?? props.textColor ?? LineDefaults.textColor
424
- const textColor3 =
425
- props.textColor3 ?? props.textColor ?? LineDefaults.textColor
426
- const textColor4 =
427
- props.textColor4 ?? props.textColor ?? LineDefaults.textColor
428
- const textColor5 =
429
- props.textColor5 ?? props.textColor ?? LineDefaults.textColor
430
-
431
- const totalWidth =
432
- initialSpacing + spacing * (data0 ?? data).length - 1 + endSpacing
433
-
434
- const { maxItem, minItem } = computeMaxAndMinItems(
435
- data0 ?? data,
436
- props.roundToDigits,
437
- props.showFractionalValues
438
- )
439
-
440
- const maxValue = getMaxValue(
441
- props.maxValue,
442
- props.stepValue,
443
- noOfSections,
444
- maxItem
445
- )
446
-
447
- const mostNegativeValue = props.mostNegativeValue ?? minItem
448
-
449
- const overflowTop =
450
- props.overflowTop ?? props.secondaryXAxis
451
- ? AxesAndRulesDefaults.overflowTopWithSecondaryXAxis
452
- : AxesAndRulesDefaults.overflowTop
453
-
454
- const extendedContainerHeight = getExtendedContainerHeightWithPadding(
455
- containerHeight,
456
- overflowTop
457
- )
458
- const getX = (index: number): number => initialSpacing + spacing * index - 1
459
- const getY = (value: number): number =>
460
- extendedContainerHeight - (value * containerHeight) / maxValue
461
-
462
- const { maxItem: secondaryMaxItem } = computeMaxAndMinItems(
463
- secondaryData,
464
- props.secondaryYAxis?.roundToDigits,
465
- props.secondaryYAxis?.showFractionalValues
466
- )
467
- const secondaryMaxValue =
468
- props.secondaryYAxis?.maxValue ?? (secondaryMaxItem || maxValue)
469
- const getSecondaryY = (value: number): number =>
470
- extendedContainerHeight - (value * containerHeight) / secondaryMaxValue
471
- const heightUptoXaxis = extendedContainerHeight - xAxisThickness
472
-
473
- if (animateOnDataChange && animations) {
474
- animations.forEach((item, index) => {
475
- item.addListener((val) => {
476
- if (typeof data[index] === 'undefined') {
477
- return
478
- }
479
-
480
- const temp = data[index]?.value ?? 0
481
- data[index].value = val?.value ?? 0
482
- let pp = ''
483
- let ppp = ''
484
- if (!(dataSet?.[0].curved ?? props.curved)) {
485
- for (let i = 0; i < (data0 ?? data).length; i++) {
486
- pp +=
487
- 'L' + getX(i) + ' ' + getY((data0 ?? data)[i]?.value ?? 0) + ' '
488
- }
489
- if (dataSet?.[0]?.areaChart ?? areaChart) {
490
- ppp = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
491
- ppp += pp
492
- ppp +=
493
- 'L' +
494
- (initialSpacing + spacing * (data.length - 1)) +
495
- ' ' +
496
- heightUptoXaxis
497
- ppp += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
498
- }
499
- newPoints = pp
500
- newFillPoints = ppp
501
- setPointsOnChange()
502
- }
503
- counter++
504
- data[index].value = temp
505
- })
506
- })
507
- }
508
-
509
- const setPointsOnChange = (): void => {
510
- if (counter === data.length) {
511
- if (!props.curved) {
512
- setPoints(newPoints.replace('L', 'M'))
513
- if (areaChart) {
514
- setFillPoints(newFillPoints.replace('L', 'M'))
515
- }
516
- }
517
- }
518
- }
519
-
520
- const showValuesAsDataPointsText =
521
- props.showValuesAsDataPointsText ?? LineDefaults.showValuesAsDataPointsText
522
-
523
- const thickness1 =
524
- props.thickness1 ?? props.thickness ?? LineDefaults.thickness
525
- const thickness2 =
526
- props.thickness2 ?? props.thickness ?? LineDefaults.thickness
527
- const thickness3 =
528
- props.thickness3 ?? props.thickness ?? LineDefaults.thickness
529
- const thickness4 =
530
- props.thickness4 ?? props.thickness ?? LineDefaults.thickness
531
- const thickness5 =
532
- props.thickness5 ?? props.thickness ?? LineDefaults.thickness
533
-
534
- const zIndex1 = props.zIndex1 ?? 0
535
- const zIndex2 = props.zIndex2 ?? 0
536
- const zIndex3 = props.zIndex3 ?? 0
537
- const zIndex4 = props.zIndex4 ?? 0
538
- const zIndex5 = props.zIndex5 ?? 0
539
-
540
- const strokeDashArray1 = props.strokeDashArray1 ?? props.strokeDashArray
541
- const strokeDashArray2 = props.strokeDashArray2 ?? props.strokeDashArray
542
- const strokeDashArray3 = props.strokeDashArray3 ?? props.strokeDashArray
543
- const strokeDashArray4 = props.strokeDashArray4 ?? props.strokeDashArray
544
- const strokeDashArray5 = props.strokeDashArray5 ?? props.strokeDashArray
545
-
546
- const rotateLabel = props.rotateLabel ?? false
547
- const isAnimated = props.isAnimated ?? false
548
- const hideDataPoints1 = props.hideDataPoints ?? props.hideDataPoints1 ?? false
549
- const hideDataPoints2 = props.hideDataPoints ?? props.hideDataPoints2 ?? false
550
- const hideDataPoints3 = props.hideDataPoints ?? props.hideDataPoints3 ?? false
551
- const hideDataPoints4 = props.hideDataPoints ?? props.hideDataPoints4 ?? false
552
- const hideDataPoints5 = props.hideDataPoints ?? props.hideDataPoints5 ?? false
553
-
554
- const color1 = props.color1 ?? props.color ?? LineDefaults.color
555
- const color2 = props.color2 ?? props.color ?? LineDefaults.color
556
- const color3 = props.color3 ?? props.color ?? LineDefaults.color
557
- const color4 = props.color4 ?? props.color ?? LineDefaults.color
558
- const color5 = props.color5 ?? props.color ?? LineDefaults.color
559
-
560
- const startFillColor1 =
561
- props.startFillColor1 ?? props.startFillColor ?? LineDefaults.startFillColor
562
- const endFillColor1 =
563
- props.endFillColor1 ?? props.endFillColor ?? LineDefaults.endFillColor
564
- const startOpacity = props.startOpacity ?? LineDefaults.startOpacity
565
- const endOpacity = props.endOpacity ?? LineDefaults.endOpacity
566
- const startOpacity1 = props.startOpacity1 ?? startOpacity
567
- const endOpacity1 = props.endOpacity1 ?? endOpacity
568
-
569
- const startFillColor2 =
570
- props.startFillColor2 ?? props.startFillColor ?? LineDefaults.startFillColor
571
- const endFillColor2 =
572
- props.endFillColor2 ?? props.endFillColor ?? LineDefaults.endFillColor
573
- const startOpacity2 = props.startOpacity2 ?? startOpacity
574
- const endOpacity2 = props.endOpacity2 ?? endOpacity
575
-
576
- const startFillColor3 =
577
- props.startFillColor3 ?? props.startFillColor ?? LineDefaults.startFillColor
578
- const endFillColor3 =
579
- props.endFillColor3 ?? props.endFillColor ?? LineDefaults.endFillColor
580
- const startOpacity3 = props.startOpacity3 ?? startOpacity
581
- const endOpacity3 = props.endOpacity3 ?? endOpacity
582
-
583
- const startFillColor4 =
584
- props.startFillColor4 ?? props.startFillColor ?? LineDefaults.startFillColor
585
- const endFillColor4 =
586
- props.endFillColor4 ?? props.endFillColor ?? LineDefaults.endFillColor
587
- const startOpacity4 = props.startOpacity4 ?? startOpacity
588
- const endOpacity4 = props.endOpacity4 ?? endOpacity
589
-
590
- const startFillColor5 =
591
- props.startFillColor5 ?? props.startFillColor ?? LineDefaults.startFillColor
592
- const endFillColor5 =
593
- props.endFillColor5 ?? props.endFillColor ?? LineDefaults.endFillColor
594
- const startOpacity5 = props.startOpacity5 ?? startOpacity
595
- const endOpacity5 = props.endOpacity5 ?? endOpacity
596
-
597
- defaultArrowConfig.strokeWidth = dataSet?.[0]?.thickness ?? thickness1
598
- defaultArrowConfig.strokeColor = dataSet?.[0]?.color ?? color1
599
- const {
600
- arrowLength1,
601
- arrowWidth1,
602
- arrowStrokeWidth1,
603
- arrowStrokeColor1,
604
- arrowFillColor1,
605
- showArrowBase1,
606
- arrowLength2,
607
- arrowWidth2,
608
- arrowStrokeWidth2,
609
- arrowStrokeColor2,
610
- arrowFillColor2,
611
- showArrowBase2,
612
- arrowLength3,
613
- arrowWidth3,
614
- arrowStrokeWidth3,
615
- arrowStrokeColor3,
616
- arrowFillColor3,
617
- showArrowBase3,
618
- arrowLength4,
619
- arrowWidth4,
620
- arrowStrokeWidth4,
621
- arrowStrokeColor4,
622
- arrowFillColor4,
623
- showArrowBase4,
624
- arrowLength5,
625
- arrowWidth5,
626
- arrowStrokeWidth5,
627
- arrowStrokeColor5,
628
- arrowFillColor5,
629
- showArrowBase5,
630
- arrowLengthsFromSet,
631
- arrowWidthsFromSet,
632
- arrowStrokeWidthsFromSet,
633
- arrowStrokeColorsFromSet,
634
- arrowFillColorsFromSet,
635
- showArrowBasesFromSet
636
- } = getAllArrowProperties(props, defaultArrowConfig)
637
-
638
- const secondaryLineConfig = {
639
- zIndex: props.secondaryLineConfig?.zIndex ?? zIndex1,
640
- curved: props.secondaryLineConfig?.curved ?? props.curved,
641
- curvature: props.secondaryLineConfig?.curvature ?? curvature,
642
- curveType: props.secondaryLineConfig?.curveType ?? curveType,
643
- areaChart: props.secondaryLineConfig?.areaChart ?? areaChart,
644
- color: props.secondaryLineConfig?.color ?? color1,
645
- thickness: props.secondaryLineConfig?.thickness ?? thickness1,
646
- zIndex1: props.secondaryLineConfig?.zIndex1 ?? zIndex1,
647
- strokeDashArray:
648
- props.secondaryLineConfig?.strokeDashArray ?? strokeDashArray1,
649
- startIndex: props.secondaryLineConfig?.startIndex ?? startIndex1,
650
- endIndex: props.secondaryLineConfig?.endIndex ?? endIndex1,
651
- hideDataPoints:
652
- props.secondaryLineConfig?.hideDataPoints ?? hideDataPoints1,
653
- dataPointsHeight:
654
- props.secondaryLineConfig?.dataPointsHeight ?? dataPointsHeight1,
655
- dataPointsWidth:
656
- props.secondaryLineConfig?.dataPointsWidth ?? dataPointsWidth1,
657
- dataPointsRadius:
658
- props.secondaryLineConfig?.dataPointsRadius ?? dataPointsRadius1,
659
- dataPointsColor:
660
- props.secondaryLineConfig?.dataPointsColor ?? dataPointsColor1,
661
- dataPointsShape:
662
- props.secondaryLineConfig?.dataPointsShape ?? dataPointsShape1,
663
- showValuesAsDataPointsText:
664
- props.secondaryLineConfig?.showValuesAsDataPointsText ??
665
- showValuesAsDataPointsText,
666
- startFillColor:
667
- props.secondaryLineConfig?.startFillColor ?? startFillColor1,
668
- endFillColor: props.secondaryLineConfig?.endFillColor ?? endFillColor1,
669
- startOpacity: props.secondaryLineConfig?.startOpacity ?? startOpacity1,
670
- endOpacity: props.secondaryLineConfig?.endOpacity ?? endOpacity1,
671
- textFontSize: props.secondaryLineConfig?.textFontSize ?? textFontSize1,
672
- textColor: props.secondaryLineConfig?.textColor ?? textColor1,
673
- showArrow: props.secondaryLineConfig?.showArrow ?? props.showArrows,
674
- arrowConfig: props.secondaryLineConfig?.arrowConfig ?? props.arrowConfig
675
- }
676
-
677
- const yAxisExtraHeightAtTop = props.trimYAxisAtTop
678
- ? 0
679
- : props.yAxisExtraHeight ?? containerHeight / 20
680
-
681
- const addLeadingAndTrailingPathForAreaFill = (
682
- initialPath: string,
683
- value: number,
684
- dataLength: number
685
- ): string => {
686
- return (
687
- 'M ' +
688
- initialSpacing +
689
- ',' +
690
- heightUptoXaxis +
691
- ' ' +
692
- 'L ' +
693
- initialSpacing +
694
- ',' +
695
- getY(value) +
696
- ' ' +
697
- initialPath +
698
- ' ' +
699
- 'L ' +
700
- (initialSpacing + spacing * (dataLength - 1)) +
701
- ',' +
702
- heightUptoXaxis +
703
- ' ' +
704
- 'L ' +
705
- initialSpacing +
706
- ',' +
707
- heightUptoXaxis +
708
- ' '
709
- )
710
- }
711
-
712
- const getNextPoint = (
713
- data: lineDataItem[],
714
- index: number,
715
- around: boolean,
716
- before: boolean
717
- ): string => {
718
- const isLast = index === data.length - 1
719
- return isLast && !(around || before)
720
- ? ' '
721
- : ' L' +
722
- (getX(index) +
723
- (around ? (isLast ? 0 : spacing / 2) : before ? 0 : spacing)) +
724
- ' ' +
725
- getY(data[index].value) +
726
- ' '
727
- }
728
- const getStepPath = (data: lineDataItem[], i: number): string => {
729
- const around = edgePosition === EdgePosition.AROUND_DATA_POINT
730
- const before = edgePosition === EdgePosition.BEFORE_DATA_POINT
731
- return (
732
- 'L' +
733
- (getX(i) -
734
- (around && i > 0 ? spacing / 2 : before && i > 0 ? spacing : 0)) +
735
- ' ' +
736
- getY(data[i].value) +
737
- getNextPoint(data, i, around, before)
738
- )
739
- }
740
-
741
- const getSegmentPath = (
742
- data: lineDataItem[],
743
- i: number,
744
- lineSegment: LineSegment[] | undefined,
745
- startIndex: number,
746
- endIndex: number,
747
- isSecondary?: boolean
748
- ): string => {
749
- let path =
750
- 'L' +
751
- getX(i) +
752
- ' ' +
753
- (isSecondary ? getSecondaryY(data[i].value) : getY(data[i].value)) +
754
- ' ' +
755
- getSegmentString(lineSegment, i, SEGMENT_START, SEGMENT_END)
756
-
757
- if (highlightedRange) {
758
- path += getPathWithHighlight(
759
- data,
760
- i,
761
- highlightedRange,
762
- startIndex,
763
- endIndex,
764
- getX,
765
- getY
766
- )
767
- }
768
- return path
769
- }
770
-
771
- useEffect(() => {
772
- if (dataSet) {
773
- const pointsArray: string[] = []
774
- const arrowPointsArray: string[] = []
775
- const fillPointsArray: string[] = []
776
- dataSet.map((set, index) => {
777
- if (set.curved ?? props.curved) {
778
- const pArray: number[][] = []
779
- for (let i = 0; i < set.data.length; i++) {
780
- if (
781
- i >= (set.startIndex ?? 0) &&
782
- i <= (set.endIndex ?? set.data.length - 1)
783
- ) {
784
- pArray.push([
785
- getX(i),
786
- set.isSecondary
787
- ? getSecondaryY(set.data[i].value)
788
- : getY(set.data[i].value)
789
- ])
790
- }
791
- }
792
- let xx = svgPath(
793
- pArray,
794
- set.curveType ?? curveType,
795
- set.curvature ?? curvature
796
- )
797
- pointsArray.push(
798
- getCurvePathWithSegments(
799
- xx,
800
- set.lineSegments,
801
- SEGMENT_START,
802
- SEGMENT_END
803
- )
804
- )
805
-
806
- // For Arrow-
807
- if (set.data.length > 1 && (set.showArrow ?? props.showArrows)) {
808
- const arrowTipY = pArray[pArray.length - 1][1]
809
- const arrowTipX = pArray[pArray.length - 1][0]
810
- const y1 = pArray[pArray.length - 2][1]
811
- const x1 = pArray[pArray.length - 2][0]
812
-
813
- const arrowPoints = getArrowPoints(
814
- arrowTipX,
815
- arrowTipY,
816
- x1,
817
- y1,
818
- arrowLengthsFromSet?.[index],
819
- arrowWidthsFromSet?.[index],
820
- showArrowBasesFromSet?.[index]
821
- )
822
-
823
- arrowPointsArray.push(arrowPoints)
824
- }
825
-
826
- // For Area charts-
827
- if ((set.areaChart ?? areaChart) && set.data.length > 0) {
828
- xx = addLeadingAndTrailingPathForAreaFill(
829
- xx,
830
- set.data[0].value,
831
- set.data.length
832
- )
833
- fillPointsArray.push(xx)
834
- }
835
- } else {
836
- let pp = ''
837
- for (let i = 0; i < set.data.length; i++) {
838
- if (
839
- i >= (set.startIndex ?? 0) &&
840
- i <= (set.endIndex ?? set.data.length - 1)
841
- ) {
842
- if (set.stepChart ?? stepChart) {
843
- pp += getStepPath(set.data, i)
844
- } else {
845
- pp += getSegmentPath(
846
- set.data,
847
- i,
848
- set.lineSegments,
849
- set.startIndex ?? 0,
850
- set.endIndex ?? set.data.length - 1,
851
- set.isSecondary
852
- )
853
- }
854
- }
855
- }
856
- pointsArray.push(pp.replace('L', 'M'))
857
-
858
- // For Arrow-
859
- if (set.data.length > 1 && (set.showArrow ?? props.showArrows)) {
860
- const ppArray = pp.trim().split(' ')
861
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
862
- const arrowTipX = parseInt(
863
- ppArray[ppArray.length - 2].replace('L', '')
864
- )
865
- const y1 = parseInt(ppArray[ppArray.length - 3])
866
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
867
-
868
- const arrowPoints = getArrowPoints(
869
- arrowTipX,
870
- arrowTipY,
871
- x1,
872
- y1,
873
- arrowLengthsFromSet?.[index],
874
- arrowWidthsFromSet?.[index],
875
- showArrowBasesFromSet?.[index]
876
- )
877
-
878
- arrowPointsArray.push(arrowPoints)
879
- }
880
-
881
- // For Area charts-
882
- if ((set.areaChart ?? areaChart) && set.data.length > 0) {
883
- let ppp = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
884
- ppp += pp
885
- ppp +=
886
- 'L' +
887
- (initialSpacing + spacing * (set.data.length - 1)) +
888
- ' ' +
889
- heightUptoXaxis
890
- ppp += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
891
- fillPointsArray.push(ppp.replace('L', 'M'))
892
- }
893
- }
894
-
895
- return null
896
- })
897
-
898
- setPointsFromSet(pointsArray)
899
- setArrowPointsFromSet(arrowPointsArray)
900
- setFillPointsFromSet(fillPointsArray)
901
- } else {
902
- let pp = ''
903
- let pp2 = ''
904
- let pp3 = ''
905
- let pp4 = ''
906
- let pp5 = ''
907
- if (!props.curved) {
908
- for (let i = 0; i < data.length; i++) {
909
- if (i >= startIndex1 && i <= endIndex1 && !animateOnDataChange) {
910
- if (stepChart ?? stepChart1) {
911
- pp += getStepPath(data, i)
912
- } else {
913
- pp += getSegmentPath(
914
- data,
915
- i,
916
- lineSegments,
917
- startIndex1,
918
- endIndex1
919
- )
920
- }
921
- }
922
- if (data2.length > 0 && i >= startIndex2 && i <= endIndex2) {
923
- if (stepChart ?? stepChart2) {
924
- pp2 += getStepPath(data2, i)
925
- } else {
926
- pp2 += getSegmentPath(
927
- data2,
928
- i,
929
- lineSegments2,
930
- startIndex2,
931
- endIndex2
932
- )
933
- }
934
- }
935
- if (data3.length > 0 && i >= startIndex3 && i <= endIndex3) {
936
- if (stepChart ?? stepChart3) {
937
- pp3 += getStepPath(data3, i)
938
- } else {
939
- pp3 += getSegmentPath(
940
- data3,
941
- i,
942
- lineSegments3,
943
- startIndex3,
944
- endIndex3
945
- )
946
- }
947
- }
948
- if (data4.length > 0 && i >= startIndex4 && i <= endIndex4) {
949
- if (stepChart ?? stepChart4) {
950
- pp4 += getStepPath(data4, i)
951
- } else {
952
- pp4 += getSegmentPath(
953
- data4,
954
- i,
955
- lineSegments4,
956
- startIndex4,
957
- endIndex4
958
- )
959
- }
960
- }
961
- if (data5.length > 0 && i >= startIndex5 && i <= endIndex5) {
962
- if (stepChart ?? stepChart5) {
963
- pp5 += getStepPath(data5, i)
964
- } else {
965
- pp5 += getSegmentPath(
966
- data5,
967
- i,
968
- lineSegments5,
969
- startIndex5,
970
- endIndex5
971
- )
972
- }
973
- }
974
- }
975
- setPoints2(pp2.replace('L', 'M'))
976
- setPoints3(pp3.replace('L', 'M'))
977
- setPoints4(pp4.replace('L', 'M'))
978
- setPoints5(pp5.replace('L', 'M'))
979
-
980
- setPoints(pp.replace('L', 'M'))
981
-
982
- if (data.length > 1 && (props.showArrow1 ?? props.showArrows)) {
983
- const ppArray = pp.trim().split(' ')
984
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
985
- const arrowTipX = parseInt(
986
- ppArray[ppArray.length - 2].replace('L', '')
987
- )
988
- const y1 = parseInt(ppArray[ppArray.length - 3])
989
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
990
-
991
- const arrowPoints = getArrowPoints(
992
- arrowTipX,
993
- arrowTipY,
994
- x1,
995
- y1,
996
- arrowLength1,
997
- arrowWidth1,
998
- showArrowBase1
999
- )
1000
-
1001
- setArrow1Points(arrowPoints)
1002
- }
1003
-
1004
- if (data2.length > 1 && (props.showArrow2 ?? props.showArrows)) {
1005
- const ppArray = pp2.trim().split(' ')
1006
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
1007
- const arrowTipX = parseInt(
1008
- ppArray[ppArray.length - 2].replace('L', '')
1009
- )
1010
- const y1 = parseInt(ppArray[ppArray.length - 3])
1011
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
1012
-
1013
- const arrowPoints = getArrowPoints(
1014
- arrowTipX,
1015
- arrowTipY,
1016
- x1,
1017
- y1,
1018
- arrowLength2,
1019
- arrowWidth2,
1020
- showArrowBase2
1021
- )
1022
-
1023
- setArrow2Points(arrowPoints)
1024
- }
1025
-
1026
- if (data3.length > 1 && (props.showArrow3 ?? props.showArrows)) {
1027
- const ppArray = pp3.trim().split(' ')
1028
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
1029
- const arrowTipX = parseInt(
1030
- ppArray[ppArray.length - 2].replace('L', '')
1031
- )
1032
- const y1 = parseInt(ppArray[ppArray.length - 3])
1033
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
1034
-
1035
- const arrowPoints = getArrowPoints(
1036
- arrowTipX,
1037
- arrowTipY,
1038
- x1,
1039
- y1,
1040
- arrowLength3,
1041
- arrowWidth3,
1042
- showArrowBase3
1043
- )
1044
-
1045
- setArrow3Points(arrowPoints)
1046
- }
1047
-
1048
- if (data4.length > 1 && (props.showArrow4 ?? props.showArrows)) {
1049
- const ppArray = pp4.trim().split(' ')
1050
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
1051
- const arrowTipX = parseInt(
1052
- ppArray[ppArray.length - 2].replace('L', '')
1053
- )
1054
- const y1 = parseInt(ppArray[ppArray.length - 3])
1055
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
1056
-
1057
- const arrowPoints = getArrowPoints(
1058
- arrowTipX,
1059
- arrowTipY,
1060
- x1,
1061
- y1,
1062
- arrowLength4,
1063
- arrowWidth4,
1064
- showArrowBase4
1065
- )
1066
-
1067
- setArrow4Points(arrowPoints)
1068
- }
1069
-
1070
- if (data5.length > 1 && (props.showArrow5 ?? props.showArrows)) {
1071
- const ppArray = pp5.trim().split(' ')
1072
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
1073
- const arrowTipX = parseInt(
1074
- ppArray[ppArray.length - 2].replace('L', '')
1075
- )
1076
- const y1 = parseInt(ppArray[ppArray.length - 3])
1077
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
1078
-
1079
- const arrowPoints = getArrowPoints(
1080
- arrowTipX,
1081
- arrowTipY,
1082
- x1,
1083
- y1,
1084
- arrowLength5,
1085
- arrowWidth5,
1086
- showArrowBase5
1087
- )
1088
-
1089
- setArrow5Points(arrowPoints)
1090
- }
1091
-
1092
- /** ************************* For Area Charts *************************/
1093
- if (atLeastOneAreaChart) {
1094
- let ppp = ''
1095
- let ppp2 = ''
1096
- let ppp3 = ''
1097
- let ppp4 = ''
1098
- let ppp5 = ''
1099
-
1100
- if (
1101
- (areaChart ?? areaChart1) &&
1102
- data.length > 0 &&
1103
- !animateOnDataChange
1104
- ) {
1105
- ppp = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1106
- ppp += pp
1107
- ppp +=
1108
- 'L' +
1109
- (initialSpacing + spacing * (data.length - 1)) +
1110
- ' ' +
1111
- heightUptoXaxis
1112
- ppp += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1113
- setFillPoints(ppp.replace('L', 'M'))
1114
- }
1115
-
1116
- if ((areaChart ?? areaChart2) && data2.length > 0) {
1117
- ppp2 = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1118
- ppp2 += pp2
1119
- ppp2 +=
1120
- 'L' +
1121
- (initialSpacing + spacing * (data.length - 1)) +
1122
- ' ' +
1123
- heightUptoXaxis
1124
- ppp2 += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1125
- setFillPoints2(ppp2.replace('L', 'M'))
1126
- }
1127
-
1128
- if ((areaChart ?? areaChart3) && data3.length > 0) {
1129
- ppp3 = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1130
- ppp3 += pp3
1131
- ppp3 +=
1132
- 'L' +
1133
- (initialSpacing + spacing * (data.length - 1)) +
1134
- ' ' +
1135
- heightUptoXaxis
1136
- ppp3 += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1137
- setFillPoints3(ppp3.replace('L', 'M'))
1138
- }
1139
- if ((areaChart ?? areaChart4) && data4.length > 0) {
1140
- ppp4 = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1141
- ppp4 += pp4
1142
- ppp4 +=
1143
- 'L' +
1144
- (initialSpacing + spacing * (data.length - 1)) +
1145
- ' ' +
1146
- heightUptoXaxis
1147
- ppp4 += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1148
- setFillPoints4(ppp4.replace('L', 'M'))
1149
- }
1150
-
1151
- if ((areaChart ?? areaChart5) && data5.length > 0) {
1152
- ppp5 = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1153
- ppp5 += pp5
1154
- ppp5 +=
1155
- 'L' +
1156
- (initialSpacing + spacing * (data.length - 1)) +
1157
- ' ' +
1158
- heightUptoXaxis
1159
- ppp5 += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1160
- setFillPoints5(ppp5.replace('L', 'M'))
1161
- }
1162
- }
1163
-
1164
- /*************************************************************************************/
1165
- } else {
1166
- const p1Array: number[][] = []
1167
- const p2Array: number[][] = []
1168
- const p3Array: number[][] = []
1169
- const p4Array: number[][] = []
1170
- const p5Array: number[][] = []
1171
- for (let i = 0; i < data.length; i++) {
1172
- if (i >= startIndex1 && i <= endIndex1) {
1173
- p1Array.push([getX(i), getY(data[i].value)])
1174
- }
1175
- if (data2.length > 0 && i >= startIndex2 && i <= endIndex2) {
1176
- p2Array.push([getX(i), getY(data2[i].value)])
1177
- }
1178
- if (data3.length > 0 && i >= startIndex3 && i <= endIndex3) {
1179
- p3Array.push([getX(i), getY(data3[i].value)])
1180
- }
1181
- if (data4.length > 0 && i >= startIndex4 && i <= endIndex4) {
1182
- p4Array.push([getX(i), getY(data4[i].value)])
1183
- }
1184
- if (data5.length > 0 && i >= startIndex5 && i <= endIndex5) {
1185
- p5Array.push([getX(i), getY(data5[i].value)])
1186
- }
1187
- }
1188
-
1189
- let xx = svgPath(p1Array, curveType, curvature)
1190
- let xx2 = svgPath(p2Array, curveType, curvature)
1191
- let xx3 = svgPath(p3Array, curveType, curvature)
1192
- let xx4 = svgPath(p4Array, curveType, curvature)
1193
- let xx5 = svgPath(p5Array, curveType, curvature)
1194
-
1195
- setPoints(
1196
- getCurvePathWithSegments(xx, lineSegments, SEGMENT_START, SEGMENT_END)
1197
- )
1198
- setPoints2(
1199
- getCurvePathWithSegments(
1200
- xx2,
1201
- lineSegments2,
1202
- SEGMENT_START,
1203
- SEGMENT_END
1204
- )
1205
- )
1206
- setPoints3(
1207
- getCurvePathWithSegments(
1208
- xx3,
1209
- lineSegments3,
1210
- SEGMENT_START,
1211
- SEGMENT_END
1212
- )
1213
- )
1214
- setPoints4(
1215
- getCurvePathWithSegments(
1216
- xx4,
1217
- lineSegments4,
1218
- SEGMENT_START,
1219
- SEGMENT_END
1220
- )
1221
- )
1222
- setPoints5(
1223
- getCurvePathWithSegments(
1224
- xx5,
1225
- lineSegments5,
1226
- SEGMENT_START,
1227
- SEGMENT_END
1228
- )
1229
- )
1230
-
1231
- if (data.length > 1 && (props.showArrow1 ?? props.showArrows)) {
1232
- const arrowTipY = p1Array[p1Array.length - 1][1]
1233
- const arrowTipX = p1Array[p1Array.length - 1][0]
1234
- const y1 = p1Array[p1Array.length - 2][1]
1235
- const x1 = p1Array[p1Array.length - 2][0]
1236
-
1237
- const arrowPoints = getArrowPoints(
1238
- arrowTipX,
1239
- arrowTipY,
1240
- x1,
1241
- y1,
1242
- arrowLength1,
1243
- arrowWidth1,
1244
- showArrowBase1
1245
- )
1246
-
1247
- setArrow1Points(arrowPoints)
1248
- }
1249
-
1250
- if (data2.length > 1 && (props.showArrow2 ?? props.showArrows)) {
1251
- const arrowTipY = p2Array[p2Array.length - 1][1]
1252
- const arrowTipX = p2Array[p2Array.length - 1][0]
1253
- const y1 = p2Array[p2Array.length - 2][1]
1254
- const x1 = p2Array[p2Array.length - 2][0]
1255
-
1256
- const arrowPoints = getArrowPoints(
1257
- arrowTipX,
1258
- arrowTipY,
1259
- x1,
1260
- y1,
1261
- arrowLength2,
1262
- arrowWidth2,
1263
- showArrowBase2
1264
- )
1265
-
1266
- setArrow2Points(arrowPoints)
1267
- }
1268
-
1269
- if (data3.length > 1 && (props.showArrow3 ?? props.showArrows)) {
1270
- const arrowTipY = p3Array[p3Array.length - 1][1]
1271
- const arrowTipX = p3Array[p3Array.length - 1][0]
1272
- const y1 = p3Array[p3Array.length - 2][1]
1273
- const x1 = p3Array[p3Array.length - 2][0]
1274
-
1275
- const arrowPoints = getArrowPoints(
1276
- arrowTipX,
1277
- arrowTipY,
1278
- x1,
1279
- y1,
1280
- arrowLength3,
1281
- arrowWidth3,
1282
- showArrowBase3
1283
- )
1284
-
1285
- setArrow2Points(arrowPoints)
1286
- }
1287
-
1288
- if (data4.length > 1 && (props.showArrow4 ?? props.showArrows)) {
1289
- const arrowTipY = p4Array[p4Array.length - 1][1]
1290
- const arrowTipX = p4Array[p4Array.length - 1][0]
1291
- const y1 = p4Array[p4Array.length - 2][1]
1292
- const x1 = p4Array[p4Array.length - 2][0]
1293
-
1294
- const arrowPoints = getArrowPoints(
1295
- arrowTipX,
1296
- arrowTipY,
1297
- x1,
1298
- y1,
1299
- arrowLength4,
1300
- arrowWidth4,
1301
- showArrowBase4
1302
- )
1303
-
1304
- setArrow2Points(arrowPoints)
1305
- }
1306
-
1307
- if (data5.length > 1 && (props.showArrow5 ?? props.showArrows)) {
1308
- const arrowTipY = p5Array[p5Array.length - 1][1]
1309
- const arrowTipX = p5Array[p5Array.length - 1][0]
1310
- const y1 = p5Array[p5Array.length - 2][1]
1311
- const x1 = p5Array[p5Array.length - 2][0]
1312
-
1313
- const arrowPoints = getArrowPoints(
1314
- arrowTipX,
1315
- arrowTipY,
1316
- x1,
1317
- y1,
1318
- arrowLength5,
1319
- arrowWidth5,
1320
- showArrowBase5
1321
- )
1322
-
1323
- setArrow2Points(arrowPoints)
1324
- }
1325
-
1326
- /** ************************* For Area Charts *************************/
1327
-
1328
- if (atLeastOneAreaChart) {
1329
- if ((areaChart ?? areaChart1) && data.length > 0) {
1330
- xx = addLeadingAndTrailingPathForAreaFill(
1331
- xx,
1332
- data[0].value,
1333
- data.length
1334
- )
1335
- setFillPoints(xx)
1336
- }
1337
-
1338
- if ((areaChart ?? areaChart2) && data2.length > 0) {
1339
- xx2 = addLeadingAndTrailingPathForAreaFill(
1340
- xx2,
1341
- data2[0].value,
1342
- data2.length
1343
- )
1344
- setFillPoints2(xx2)
1345
- }
1346
-
1347
- if ((areaChart ?? areaChart3) && data3.length > 0) {
1348
- xx3 = addLeadingAndTrailingPathForAreaFill(
1349
- xx3,
1350
- data3[0].value,
1351
- data3.length
1352
- )
1353
- setFillPoints3(xx3)
1354
- }
1355
-
1356
- if ((areaChart ?? areaChart4) && data4.length > 0) {
1357
- xx4 = addLeadingAndTrailingPathForAreaFill(
1358
- xx4,
1359
- data4[0].value,
1360
- data4.length
1361
- )
1362
- setFillPoints4(xx4)
1363
- }
1364
-
1365
- if ((areaChart ?? areaChart5) && data5.length > 0) {
1366
- xx5 = addLeadingAndTrailingPathForAreaFill(
1367
- xx5,
1368
- data5[0].value,
1369
- data5.length
1370
- )
1371
- setFillPoints5(xx5)
1372
- }
1373
- }
1374
-
1375
- /*************************************************************************************/
1376
- }
1377
- }
1378
- }, [
1379
- animateOnDataChange,
1380
- areaChart,
1381
- areaChart1,
1382
- areaChart2,
1383
- containerHeight,
1384
- data,
1385
- data2,
1386
- data3,
1387
- data4,
1388
- data5,
1389
- // data0,
1390
- dataPointsWidth1,
1391
- dataPointsWidth2,
1392
- dataPointsWidth3,
1393
- dataPointsWidth4,
1394
- dataPointsWidth5,
1395
- initialSpacing,
1396
- maxValue,
1397
- props.curved,
1398
- spacing,
1399
- xAxisThickness,
1400
- startIndex1,
1401
- endIndex1,
1402
- startIndex2,
1403
- endIndex2,
1404
- startIndex3,
1405
- endIndex3,
1406
- startIndex4,
1407
- endIndex4,
1408
- startIndex5,
1409
- endIndex5,
1410
- arrowLength1,
1411
- arrowWidth1,
1412
- showArrowBase1,
1413
- props.showArrow1,
1414
- props.showArrows,
1415
- props.showArrow2,
1416
- props.showArrow3,
1417
- props.showArrow4,
1418
- props.showArrow5,
1419
- arrowLength2,
1420
- arrowWidth2,
1421
- showArrowBase2,
1422
- arrowLength3,
1423
- arrowWidth3,
1424
- showArrowBase3,
1425
- arrowLength4,
1426
- arrowWidth4,
1427
- showArrowBase4,
1428
- arrowLength5,
1429
- arrowWidth5,
1430
- showArrowBase5
1431
- ])
1432
-
1433
- useEffect(() => {
1434
- let pp = ''
1435
- if (!secondaryLineConfig.curved) {
1436
- for (let i = 0; i < secondaryData.length; i++) {
1437
- if (
1438
- i >= secondaryLineConfig.startIndex &&
1439
- i <= secondaryLineConfig.endIndex &&
1440
- !animateOnDataChange
1441
- ) {
1442
- pp +=
1443
- 'L' + getX(i) + ' ' + getSecondaryY(secondaryData[i].value) + ' '
1444
- }
1445
- }
1446
-
1447
- setSecondaryPoints(pp.replace('L', 'M'))
1448
-
1449
- if (secondaryData.length > 1 && secondaryLineConfig.showArrow) {
1450
- const ppArray = pp.trim().split(' ')
1451
- const arrowTipY = parseInt(ppArray[ppArray.length - 1])
1452
- const arrowTipX = parseInt(ppArray[ppArray.length - 2].replace('L', ''))
1453
- const y1 = parseInt(ppArray[ppArray.length - 3])
1454
- const x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''))
1455
-
1456
- const arrowPoints = getArrowPoints(
1457
- arrowTipX,
1458
- arrowTipY,
1459
- x1,
1460
- y1,
1461
- secondaryLineConfig.arrowConfig?.length,
1462
- secondaryLineConfig.arrowConfig?.width,
1463
- secondaryLineConfig.arrowConfig?.showArrowBase
1464
- )
1465
-
1466
- setSecondaryArrowPoints(arrowPoints)
1467
- }
1468
-
1469
- /** ************************* For Area Chart *************************/
1470
- if (secondaryLineConfig.areaChart) {
1471
- let ppp = ''
1472
-
1473
- if (secondaryData.length > 0 && !animateOnDataChange) {
1474
- ppp = 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1475
- ppp += pp
1476
- ppp +=
1477
- 'L' +
1478
- (initialSpacing + spacing * (secondaryData.length - 1)) +
1479
- ' ' +
1480
- heightUptoXaxis
1481
- ppp += 'L' + initialSpacing + ' ' + heightUptoXaxis + ' '
1482
- setSecondaryFillPoints(ppp.replace('L', 'M'))
1483
- }
1484
- }
1485
- } else {
1486
- /** ************************* For Curved Charts *************************/
1487
- const p1Array: number[][] = []
1488
- for (let i = 0; i < secondaryData.length; i++) {
1489
- if (
1490
- i >= secondaryLineConfig.startIndex &&
1491
- i <= secondaryLineConfig.endIndex
1492
- ) {
1493
- p1Array.push([getX(i), getSecondaryY(secondaryData[i].value)])
1494
- }
1495
- }
1496
-
1497
- let xx = svgPath(
1498
- p1Array,
1499
- secondaryLineConfig.curveType,
1500
- secondaryLineConfig.curvature
1501
- )
1502
-
1503
- setSecondaryPoints(xx)
1504
-
1505
- if (secondaryData.length > 1 && (props.showArrow1 ?? props.showArrows)) {
1506
- const arrowTipY = p1Array[p1Array.length - 1][1]
1507
- const arrowTipX = p1Array[p1Array.length - 1][0]
1508
- const y1 = p1Array[p1Array.length - 2][1]
1509
- const x1 = p1Array[p1Array.length - 2][0]
1510
-
1511
- const arrowPoints = getArrowPoints(
1512
- arrowTipX,
1513
- arrowTipY,
1514
- x1,
1515
- y1,
1516
- arrowLength1,
1517
- arrowWidth1,
1518
- showArrowBase1
1519
- )
1520
-
1521
- setSecondaryArrowPoints(arrowPoints)
1522
- }
1523
-
1524
- /** ************************* For Curved Area Charts *************************/
1525
-
1526
- if (secondaryLineConfig.areaChart) {
1527
- if (secondaryData.length > 0) {
1528
- xx = addLeadingAndTrailingPathForAreaFill(
1529
- xx,
1530
- secondaryData[0].value,
1531
- secondaryData.length
1532
- )
1533
- setSecondaryFillPoints(xx)
1534
- }
1535
- }
1536
- }
1537
- }, [secondaryData, secondaryLineConfig])
1538
-
1539
- const gradientDirection = props.gradientDirection ?? 'vertical'
1540
- const horizSections = [{ value: '0' }]
1541
- const stepHeight = props.stepHeight ?? containerHeight / noOfSections
1542
- const stepValue = props.stepValue ?? maxValue / noOfSections
1543
- const noOfSectionsBelowXAxis =
1544
- props.noOfSectionsBelowXAxis ??
1545
- Math.round(Math.ceil(-mostNegativeValue / stepValue))
1546
-
1547
- const showXAxisIndices =
1548
- props.showXAxisIndices ?? AxesAndRulesDefaults.showXAxisIndices
1549
- const xAxisIndicesHeight =
1550
- props.xAxisIndicesHeight ?? AxesAndRulesDefaults.xAxisIndicesHeight
1551
- const xAxisIndicesWidth =
1552
- props.xAxisIndicesWidth ?? AxesAndRulesDefaults.xAxisIndicesWidth
1553
- const xAxisIndicesColor =
1554
- props.xAxisIndicesColor ?? AxesAndRulesDefaults.xAxisIndicesColor
1555
-
1556
- const xAxisTextNumberOfLines =
1557
- props.xAxisTextNumberOfLines ?? AxesAndRulesDefaults.xAxisTextNumberOfLines
1558
- const xAxisLabelsVerticalShift =
1559
- props.xAxisLabelsVerticalShift ??
1560
- AxesAndRulesDefaults.xAxisLabelsVerticalShift
1561
- const horizontalRulesStyle = props.horizontalRulesStyle
1562
- const showFractionalValues =
1563
- props.showFractionalValues ?? AxesAndRulesDefaults.showFractionalValues
1564
-
1565
- const horizontal = false
1566
- const yAxisAtTop = false
1567
-
1568
- defaultPointerConfig.pointerStripHeight = containerHeight
1569
-
1570
- const pointerConfig = props.pointerConfig
1571
- const getPointerProps = props.getPointerProps ?? null
1572
- const pointerHeight = pointerConfig?.height ?? defaultPointerConfig.height
1573
- const pointerWidth = pointerConfig?.width ?? defaultPointerConfig.width
1574
- const pointerRadius = pointerConfig?.radius ?? defaultPointerConfig.radius
1575
- const pointerColor =
1576
- pointerConfig?.pointerColor ?? defaultPointerConfig.pointerColor
1577
- const pointerComponent =
1578
- pointerConfig?.pointerComponent ?? defaultPointerConfig.pointerComponent
1579
-
1580
- const showPointerStrip =
1581
- pointerConfig?.showPointerStrip === false
1582
- ? false
1583
- : defaultPointerConfig.showPointerStrip
1584
- const pointerStripHeight =
1585
- pointerConfig?.pointerStripHeight ?? defaultPointerConfig.pointerStripHeight
1586
- const pointerStripWidth =
1587
- pointerConfig?.pointerStripWidth ?? defaultPointerConfig.pointerStripWidth
1588
- const pointerStripColor =
1589
- pointerConfig?.pointerStripColor ?? defaultPointerConfig.pointerStripColor
1590
- const pointerStripUptoDataPoint =
1591
- pointerConfig?.pointerStripUptoDataPoint ??
1592
- defaultPointerConfig.pointerStripUptoDataPoint
1593
- const pointerLabelComponent =
1594
- pointerConfig?.pointerLabelComponent ??
1595
- defaultPointerConfig.pointerLabelComponent
1596
- const stripOverPointer =
1597
- pointerConfig?.stripOverPointer ?? defaultPointerConfig.stripOverPointer
1598
- const shiftPointerLabelX =
1599
- pointerConfig?.shiftPointerLabelX ?? defaultPointerConfig.shiftPointerLabelX
1600
- const shiftPointerLabelY =
1601
- pointerConfig?.shiftPointerLabelY ?? defaultPointerConfig.shiftPointerLabelY
1602
- const pointerLabelWidth =
1603
- pointerConfig?.pointerLabelWidth ?? defaultPointerConfig.pointerLabelWidth
1604
- const pointerLabelHeight =
1605
- pointerConfig?.pointerLabelHeight ?? defaultPointerConfig.pointerLabelHeight
1606
- const autoAdjustPointerLabelPosition =
1607
- pointerConfig?.autoAdjustPointerLabelPosition ??
1608
- defaultPointerConfig.autoAdjustPointerLabelPosition
1609
- const pointerVanishDelay =
1610
- pointerConfig?.pointerVanishDelay ?? defaultPointerConfig.pointerVanishDelay
1611
- const activatePointersOnLongPress =
1612
- pointerConfig?.activatePointersOnLongPress ??
1613
- defaultPointerConfig.activatePointersOnLongPress
1614
- const activatePointersDelay =
1615
- pointerConfig?.activatePointersDelay ??
1616
- defaultPointerConfig.activatePointersDelay
1617
- const initialPointerIndex =
1618
- pointerConfig?.initialPointerIndex ??
1619
- defaultPointerConfig.initialPointerIndex
1620
- const initialPointerAppearDelay =
1621
- pointerConfig?.initialPointerAppearDelay ??
1622
- (isAnimated
1623
- ? animationDuration
1624
- : defaultPointerConfig.initialPointerAppearDelay)
1625
- const persistPointer =
1626
- pointerConfig?.persistPointer ?? defaultPointerConfig.persistPointer
1627
- const hidePointer1 =
1628
- pointerConfig?.hidePointer1 ?? defaultPointerConfig.hidePointer1
1629
- const hidePointer2 =
1630
- pointerConfig?.hidePointer2 ?? defaultPointerConfig.hidePointer2
1631
- const hidePointer3 =
1632
- pointerConfig?.hidePointer3 ?? defaultPointerConfig.hidePointer3
1633
- const hidePointer4 =
1634
- pointerConfig?.hidePointer4 ?? defaultPointerConfig.hidePointer4
1635
- const hidePointer5 =
1636
- pointerConfig?.hidePointer5 ?? defaultPointerConfig.hidePointer5
1637
- const hideSecondaryPointer =
1638
- pointerConfig?.hideSecondaryPointer ??
1639
- defaultPointerConfig.hideSecondaryPointer
1640
- const resetPointerOnDataChange =
1641
- pointerConfig?.resetPointerOnDataChange ??
1642
- defaultPointerConfig.resetPointerOnDataChange
1643
- const pointerEvents = pointerConfig?.pointerEvents
1644
- const disableScroll =
1645
- props.disableScroll ??
1646
- (pointerConfig
1647
- ? activatePointersOnLongPress
1648
- ? !!responderActive
1649
- : true
1650
- : false)
1651
- const showScrollIndicator =
1652
- props.showScrollIndicator ?? LineDefaults.showScrollIndicator
1653
-
1654
- const focusEnabled = props.focusEnabled ?? LineDefaults.focusEnabled
1655
- const showDataPointOnFocus =
1656
- props.showDataPointOnFocus ?? LineDefaults.showDataPointOnFocus
1657
- const showStripOnFocus =
1658
- props.showStripOnFocus ?? LineDefaults.showStripOnFocus
1659
- const showTextOnFocus = props.showTextOnFocus ?? LineDefaults.showTextOnFocus
1660
- const showDataPointLabelOnFocus =
1661
- props.showDataPointLabelOnFocus ?? LineDefaults.showDataPointLabelOnFocus
1662
- const stripHeight = props.stripHeight
1663
- const stripWidth = props.stripWidth ?? LineDefaults.stripWidth
1664
- const stripColor = props.stripColor ?? color1
1665
- const stripOpacity = props.stripOpacity ?? (startOpacity1 + endOpacity1) / 2
1666
- const stripStrokeDashArray = props.stripStrokeDashArray
1667
- const unFocusOnPressOut =
1668
- props.unFocusOnPressOut ?? LineDefaults.unFocusOnPressOut
1669
- const delayBeforeUnFocus =
1670
- props.delayBeforeUnFocus ?? LineDefaults.delayBeforeUnFocus
1671
-
1672
- const containerHeightIncludingBelowXAxis =
1673
- extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight
1674
-
1675
- const lineGradient = props.lineGradient ?? LineDefaults.lineGradient
1676
- const lineGradientDirection = props.lineGradientDirection ?? 'vertical'
1677
- const lineGradientStartColor =
1678
- props.lineGradientStartColor ?? LineDefaults.lineGradientStartColor
1679
- const lineGradientEndColor =
1680
- props.lineGradientEndColor ?? LineDefaults.lineGradientEndColor
1681
-
1682
- const getPointerY = (value: number): number =>
1683
- value
1684
- ? containerHeight -
1685
- (value * containerHeight) / maxValue -
1686
- (pointerRadius || pointerHeight / 2) +
1687
- 10
1688
- : 0
1689
-
1690
- const initialisePointers = (): void => {
1691
- if (initialPointerIndex !== -1) {
1692
- const x =
1693
- initialSpacing +
1694
- spacing * initialPointerIndex -
1695
- (pointerRadius || pointerWidth / 2) -
1696
- 1
1697
- if (dataSet?.length) {
1698
- const item = dataSet[0].data[initialPointerIndex]
1699
- if (initialPointerAppearDelay) {
1700
- setTimeout(() => {
1701
- setPointerConfigForDataSet(initialPointerIndex, item, x)
1702
- }, initialPointerAppearDelay)
1703
- } else {
1704
- setPointerConfigForDataSet(initialPointerIndex, item, x)
1705
- }
1706
- } else {
1707
- const item = (data0 ?? data)[initialPointerIndex]
1708
- const y = getPointerY(item.value)
1709
- const y2 = getPointerY(data2?.[initialPointerIndex]?.value)
1710
- const y3 = getPointerY(data3?.[initialPointerIndex]?.value)
1711
- const y4 = getPointerY(data4?.[initialPointerIndex]?.value)
1712
- const y5 = getPointerY(data5?.[initialPointerIndex]?.value)
1713
-
1714
- if (initialPointerAppearDelay) {
1715
- setTimeout(() => {
1716
- setPointerConfig(initialPointerIndex, item, x, y, y2, y3, y4, y5)
1717
- }, initialPointerAppearDelay)
1718
- } else {
1719
- setPointerConfig(initialPointerIndex, item, x, y, y2, y3, y4, y5)
1720
- }
1721
- }
1722
- }
1723
- }
1724
-
1725
- useEffect(() => {
1726
- initialisePointers()
1727
- }, [])
1728
-
1729
- useEffect(() => {
1730
- if (resetPointerOnDataChange) {
1731
- initialisePointers()
1732
- }
1733
- }, [data])
1734
-
1735
- const setPointerConfig = (
1736
- initialPointerIndex: number,
1737
- item: lineDataItem,
1738
- x: number,
1739
- y: number,
1740
- y2: number,
1741
- y3: number,
1742
- y4: number,
1743
- y5: number
1744
- ): void => {
1745
- setPointerIndex(initialPointerIndex)
1746
- setPointerItem(item)
1747
- setPointerX(x)
1748
- setPointerY(y)
1749
- setPointerY2(y2)
1750
- setPointerY3(y3)
1751
- setPointerY4(y4)
1752
- setPointerY5(y5)
1753
- }
1754
-
1755
- const setPointerConfigForDataSet = (
1756
- initialPointerIndex: number,
1757
- item: lineDataItem,
1758
- x: number
1759
- ) => {
1760
- setPointerIndex(initialPointerIndex)
1761
- setPointerItem(item)
1762
- setPointerX(x)
1763
-
1764
- const initialPointerYs =
1765
- dataSet?.map((set) => getPointerY(set.data[initialPointerIndex].value)) ??
1766
- []
1767
- setPointerYsForDataSet(initialPointerYs)
1768
- }
1769
-
1770
- const dataPointsRadius =
1771
- props.dataPointsRadius1 ??
1772
- props.dataPointsRadius ??
1773
- LineDefaults.dataPointsRadius
1774
- const dataPointsWidth =
1775
- props.dataPointsWidth1 ??
1776
- props.dataPointsWidth ??
1777
- LineDefaults.dataPointsWidth
1778
-
1779
- const extraWidthDueToDataPoint = props.hideDataPoints
1780
- ? 0
1781
- : dataPointsRadius ?? dataPointsWidth
1782
-
1783
- const barAndLineChartsWrapperProps: BarAndLineChartsWrapperTypes = {
1784
- chartType: chartTypes.LINE,
1785
- containerHeight,
1786
- noOfSectionsBelowXAxis,
1787
- stepHeight,
1788
- negativeStepHeight: stepHeight,
1789
- labelsExtraHeight,
1790
- yAxisLabelWidth,
1791
- horizontal,
1792
- rtl: false,
1793
- shiftX: 0,
1794
- shiftY: 0,
1795
- yAxisAtTop,
1796
- initialSpacing,
1797
- data: data0 ?? data,
1798
- stackData: undefined, // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1799
- secondaryData,
1800
- barWidth: 0, // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1801
- xAxisThickness,
1802
- totalWidth,
1803
- disableScroll,
1804
- showScrollIndicator,
1805
- scrollToEnd,
1806
- scrollToIndex: props.scrollToIndex,
1807
- scrollAnimation,
1808
- scrollEventThrottle,
1809
- indicatorColor: props.indicatorColor,
1810
- selectedIndex,
1811
- setSelectedIndex,
1812
- spacing,
1813
- showLine: false,
1814
- lineConfig: null, // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1815
- lineConfig2: null, // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1816
- maxValue,
1817
- lineData: [], // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1818
- lineData2: [], // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1819
- lineBehindBars: false,
1820
- points,
1821
- points2: '', // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1822
- arrowPoints: [], // Not needed but passing this prop to maintain consistency (between LineChart and BarChart props)
1823
-
1824
- // horizSectionProps-
1825
- width: props.width,
1826
- horizSections,
1827
- endSpacing,
1828
- horizontalRulesStyle,
1829
- noOfSections,
1830
- sectionColors: props.sectionColors,
1831
- showFractionalValues,
1832
-
1833
- axesAndRulesProps: getAxesAndRulesProps(props, stepValue, undefined),
1834
-
1835
- yAxisLabelTexts: props.yAxisLabelTexts,
1836
- yAxisOffset,
1837
- rotateYAxisTexts: 0,
1838
- hideAxesAndRules: props.hideAxesAndRules,
1839
-
1840
- showXAxisIndices,
1841
- xAxisIndicesHeight,
1842
- xAxisIndicesWidth,
1843
- xAxisIndicesColor,
1844
- pointerConfig,
1845
- getPointerProps,
1846
- pointerIndex,
1847
- pointerX,
1848
- pointerY,
1849
-
1850
- onEndReached: props.onEndReached,
1851
- onStartReached: props.onStartReached,
1852
- endReachedOffset: props.endReachedOffset ?? LineDefaults.endReachedOffset,
1853
- onMomentumScrollEnd: props.onMomentumScrollEnd,
1854
- extraWidthDueToDataPoint
1855
- }
1856
-
1857
- return {
1858
- curvature,
1859
- curveType,
1860
- scrollX,
1861
- setScrollX,
1862
- arrow1Points,
1863
- setArrow1Points,
1864
- arrow2Points,
1865
- setArrow2Points,
1866
- arrow3Points,
1867
- setArrow3Points,
1868
- arrow4Points,
1869
- setArrow4Points,
1870
- arrow5Points,
1871
- setArrow5Points,
1872
- secondaryArrowPoints,
1873
- setSecondaryArrowPoints,
1874
- pointerIndex,
1875
- setPointerIndex,
1876
- pointerX,
1877
- setPointerX,
1878
- pointerY,
1879
- setPointerY,
1880
- pointerItem,
1881
- setPointerItem,
1882
- pointerY2,
1883
- setPointerY2,
1884
- pointerItem2,
1885
- setPointerItem2,
1886
- pointerY3,
1887
- setPointerY3,
1888
- pointerItem3,
1889
- setPointerItem3,
1890
- pointerY4,
1891
- setPointerY4,
1892
- pointerItem4,
1893
- setPointerItem4,
1894
- pointerY5,
1895
- setPointerY5,
1896
- pointerYsForDataSet,
1897
- setPointerYsForDataSet,
1898
- pointerItem5,
1899
- setPointerItem5,
1900
- secondaryPointerY,
1901
- setSecondaryPointerY,
1902
- secondaryPointerItem,
1903
- setSecondaryPointerItem,
1904
- responderStartTime,
1905
- setResponderStartTime,
1906
- responderActive,
1907
- setResponderActive,
1908
- points,
1909
- setPoints,
1910
- points2,
1911
- setPoints2,
1912
- points3,
1913
- setPoints3,
1914
- points4,
1915
- setPoints4,
1916
- points5,
1917
- setPoints5,
1918
- secondaryPoints,
1919
- setSecondaryPoints,
1920
- fillPoints,
1921
- setFillPoints,
1922
- fillPoints2,
1923
- setFillPoints2,
1924
- fillPoints3,
1925
- setFillPoints3,
1926
- fillPoints4,
1927
- setFillPoints4,
1928
- fillPoints5,
1929
- setFillPoints5,
1930
- secondaryFillPoints,
1931
- setSecondaryFillPoints,
1932
- pointsFromSet,
1933
- setPointsFromSet,
1934
- fillPointsFromSet,
1935
- setFillPointsFromSet,
1936
- arrowPointsFromSet,
1937
- setArrowPointsFromSet,
1938
- selectedIndex,
1939
- setSelectedIndex,
1940
- noOfSections,
1941
- containerHeight,
1942
- data,
1943
- data2,
1944
- data3,
1945
- data4,
1946
- data5,
1947
- secondaryData,
1948
- dataSet,
1949
- data0,
1950
- scrollToEnd,
1951
- scrollAnimation,
1952
- scrollEventThrottle,
1953
- labelsExtraHeight,
1954
- animationDuration,
1955
- onDataChangeAnimationDuration,
1956
- animateTogether,
1957
- animateOnDataChange,
1958
- startIndex1,
1959
- startIndex2,
1960
- endIndex1,
1961
- endIndex2,
1962
- startIndex3,
1963
- endIndex3,
1964
- startIndex4,
1965
- endIndex4,
1966
- startIndex5,
1967
- endIndex5,
1968
- lineSegments,
1969
- lineSegments2,
1970
- lineSegments3,
1971
- lineSegments4,
1972
- lineSegments5,
1973
- highlightedRange,
1974
- adjustToWidth,
1975
- initialSpacing,
1976
- endSpacing,
1977
- thickness,
1978
- yAxisLabelWidth,
1979
- spacing,
1980
- xAxisThickness,
1981
- dataPointsHeight1,
1982
- dataPointsWidth1,
1983
- dataPointsRadius1,
1984
- dataPointsColor1,
1985
- dataPointsShape1,
1986
- dataPointsHeight2,
1987
- dataPointsWidth2,
1988
- dataPointsRadius2,
1989
- dataPointsColor2,
1990
- dataPointsShape2,
1991
- dataPointsHeight3,
1992
- dataPointsWidth3,
1993
- dataPointsRadius3,
1994
- dataPointsColor3,
1995
- dataPointsShape3,
1996
- dataPointsHeight4,
1997
- dataPointsWidth4,
1998
- dataPointsRadius4,
1999
- dataPointsColor4,
2000
- dataPointsShape4,
2001
- dataPointsHeight5,
2002
- dataPointsWidth5,
2003
- dataPointsRadius5,
2004
- dataPointsColor5,
2005
- dataPointsShape5,
2006
- areaChart,
2007
- areaChart1,
2008
- areaChart2,
2009
- areaChart3,
2010
- areaChart4,
2011
- areaChart5,
2012
- atLeastOneAreaChart,
2013
- getIsNthAreaChart,
2014
- stepChart,
2015
- stepChart1,
2016
- stepChart2,
2017
- stepChart3,
2018
- stepChart4,
2019
- stepChart5,
2020
- edgePosition,
2021
- textFontSize1,
2022
- textFontSize2,
2023
- textFontSize3,
2024
- textFontSize4,
2025
- textFontSize5,
2026
- textColor1,
2027
- textColor2,
2028
- textColor3,
2029
- textColor4,
2030
- textColor5,
2031
- totalWidth,
2032
- maxValue,
2033
- mostNegativeValue,
2034
- overflowTop,
2035
- extendedContainerHeight,
2036
- getX,
2037
- getY,
2038
- secondaryMaxValue,
2039
- getSecondaryY,
2040
- heightUptoXaxis,
2041
- setPointsOnChange,
2042
- showValuesAsDataPointsText,
2043
- thickness1,
2044
- thickness2,
2045
- thickness3,
2046
- thickness4,
2047
- thickness5,
2048
- zIndex1,
2049
- zIndex2,
2050
- zIndex3,
2051
- zIndex4,
2052
- zIndex5,
2053
- strokeDashArray1,
2054
- strokeDashArray2,
2055
- strokeDashArray3,
2056
- strokeDashArray4,
2057
- strokeDashArray5,
2058
- rotateLabel,
2059
- isAnimated,
2060
- hideDataPoints1,
2061
- hideDataPoints2,
2062
- hideDataPoints3,
2063
- hideDataPoints4,
2064
- hideDataPoints5,
2065
- color1,
2066
- color2,
2067
- color3,
2068
- color4,
2069
- color5,
2070
- startFillColor1,
2071
- endFillColor1,
2072
- startOpacity,
2073
- endOpacity,
2074
- startOpacity1,
2075
- endOpacity1,
2076
- startFillColor2,
2077
- endFillColor2,
2078
- startOpacity2,
2079
- endOpacity2,
2080
- startFillColor3,
2081
- endFillColor3,
2082
- startOpacity3,
2083
- endOpacity3,
2084
- startFillColor4,
2085
- endFillColor4,
2086
- startOpacity4,
2087
- endOpacity4,
2088
- startFillColor5,
2089
- endFillColor5,
2090
- startOpacity5,
2091
- endOpacity5,
2092
- arrowLength1,
2093
- arrowWidth1,
2094
- arrowStrokeWidth1,
2095
- arrowStrokeColor1,
2096
- arrowFillColor1,
2097
- showArrowBase1,
2098
- arrowLength2,
2099
- arrowWidth2,
2100
- arrowStrokeWidth2,
2101
- arrowStrokeColor2,
2102
- arrowFillColor2,
2103
- showArrowBase2,
2104
- arrowLength3,
2105
- arrowWidth3,
2106
- arrowStrokeWidth3,
2107
- arrowStrokeColor3,
2108
- arrowFillColor3,
2109
- showArrowBase3,
2110
- arrowLength4,
2111
- arrowWidth4,
2112
- arrowStrokeWidth4,
2113
- arrowStrokeColor4,
2114
- arrowFillColor4,
2115
- showArrowBase4,
2116
- arrowLength5,
2117
- arrowWidth5,
2118
- arrowStrokeWidth5,
2119
- arrowStrokeColor5,
2120
- arrowFillColor5,
2121
- showArrowBase5,
2122
- arrowLengthsFromSet,
2123
- arrowWidthsFromSet,
2124
- arrowStrokeWidthsFromSet,
2125
- arrowStrokeColorsFromSet,
2126
- arrowFillColorsFromSet,
2127
- showArrowBasesFromSet,
2128
- secondaryLineConfig,
2129
- addLeadingAndTrailingPathForAreaFill,
2130
- getNextPoint,
2131
- getStepPath,
2132
- getSegmentPath,
2133
- gradientDirection,
2134
- horizSections,
2135
- stepHeight,
2136
- stepValue,
2137
- noOfSectionsBelowXAxis,
2138
- showXAxisIndices,
2139
- xAxisIndicesHeight,
2140
- xAxisIndicesWidth,
2141
- xAxisIndicesColor,
2142
- xAxisTextNumberOfLines,
2143
- xAxisLabelsVerticalShift,
2144
- horizontalRulesStyle,
2145
- showFractionalValues,
2146
- horizontal,
2147
- yAxisAtTop,
2148
- pointerConfig,
2149
- getPointerProps,
2150
- pointerHeight,
2151
- pointerWidth,
2152
- pointerRadius,
2153
- pointerColor,
2154
- pointerComponent,
2155
- showPointerStrip,
2156
- pointerStripHeight,
2157
- pointerStripWidth,
2158
- pointerStripColor,
2159
- pointerStripUptoDataPoint,
2160
- pointerLabelComponent,
2161
- stripOverPointer,
2162
- shiftPointerLabelX,
2163
- shiftPointerLabelY,
2164
- pointerLabelWidth,
2165
- pointerLabelHeight,
2166
- autoAdjustPointerLabelPosition,
2167
- pointerVanishDelay,
2168
- activatePointersOnLongPress,
2169
- activatePointersDelay,
2170
- initialPointerIndex,
2171
- initialPointerAppearDelay,
2172
- persistPointer,
2173
- hidePointer1,
2174
- hidePointer2,
2175
- hidePointer3,
2176
- hidePointer4,
2177
- hidePointer5,
2178
- hideSecondaryPointer,
2179
- resetPointerOnDataChange,
2180
- pointerEvents,
2181
- disableScroll,
2182
- showScrollIndicator,
2183
- focusEnabled,
2184
- showDataPointOnFocus,
2185
- showStripOnFocus,
2186
- showTextOnFocus,
2187
- showDataPointLabelOnFocus,
2188
- stripHeight,
2189
- stripWidth,
2190
- stripColor,
2191
- stripOpacity,
2192
- stripStrokeDashArray,
2193
- unFocusOnPressOut,
2194
- delayBeforeUnFocus,
2195
- containerHeightIncludingBelowXAxis,
2196
- lineGradient,
2197
- lineGradientDirection,
2198
- lineGradientStartColor,
2199
- lineGradientEndColor,
2200
- getPointerY,
2201
- initialisePointers,
2202
- barAndLineChartsWrapperProps,
2203
- yAxisExtraHeightAtTop
2204
- }
2205
- }