gifted-charts-core 0.0.22 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gifted-charts-core",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "Mathematical and logical utilities used by react-gifted-charts and react-native-gifted-charts",
5
5
  "main": "index.ts",
6
6
  "files": [
@@ -9,18 +9,18 @@ import {
9
9
  } from './types'
10
10
  import { type ReactNode } from 'react'
11
11
 
12
- interface Animated2dWithFradientPropsType extends BarChartPropsType {
12
+ interface Animated2dWithGradientPropsType extends BarChartPropsType {
13
13
  item: barDataItem
14
14
  index: number
15
15
  barHeight: number
16
16
  selectedIndex: number
17
- barBackgroundPattern: () => ReactNode
18
- barInnerComponent: (
17
+ barBackgroundPattern?: () => ReactNode
18
+ barInnerComponent?: (
19
19
  item?: stackDataItem | barDataItem,
20
20
  index?: number
21
21
  ) => ReactNode
22
- patternId: string
23
- barStyle: object
22
+ patternId?: string
23
+ barStyle?: object
24
24
  intactTopLabel: boolean
25
25
  }
26
26
 
@@ -34,7 +34,7 @@ interface IgetPropsForAnimated2DWithGradientReturnType {
34
34
  }
35
35
 
36
36
  export const getPropsForAnimated2DWithGradient = (
37
- props: Animated2dWithFradientPropsType
37
+ props: Animated2dWithGradientPropsType
38
38
  ): IgetPropsForAnimated2DWithGradientReturnType => {
39
39
  const {
40
40
  barBorderWidth,
@@ -36,7 +36,7 @@ export interface extendedBarChartPropsType extends BarChartPropsType {
36
36
  widthValue: Animated.Value
37
37
  opacValue: Animated.Value
38
38
  verticalLinesUptoDataPoint?: boolean
39
- secondaryYAxis?: secondaryYAxisType
39
+ secondaryYAxis?: secondaryYAxisType | boolean
40
40
  }
41
41
 
42
42
  export const useBarChart = (props: extendedBarChartPropsType) => {
@@ -116,8 +116,9 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
116
116
  )
117
117
  const containerHeight =
118
118
  heightFromProps ??
119
- (props.stepHeight ?? 0) * noOfSections ??
120
- AxesAndRulesDefaults.containerHeight
119
+ (props.stepHeight
120
+ ? props.stepHeight * noOfSections
121
+ : AxesAndRulesDefaults.containerHeight)
121
122
  const horizSections = [{ value: '0' }]
122
123
  const stepHeight = props.stepHeight ?? containerHeight / noOfSections
123
124
  const labelWidth = props.labelWidth ?? AxesAndRulesDefaults.labelWidth
@@ -276,8 +277,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
276
277
  ? false
277
278
  : defaultPointerConfig.showPointerStrip
278
279
  const pointerStripHeight =
279
- pointerConfig?.pointerStripHeight ??
280
- defaultPointerConfig.pointerStripHeight
280
+ pointerConfig?.pointerStripHeight ?? defaultPointerConfig.pointerStripHeight
281
281
  const pointerStripWidth =
282
282
  pointerConfig?.pointerStripWidth ?? defaultPointerConfig.pointerStripWidth
283
283
  const pointerStripColor =
@@ -291,22 +291,18 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
291
291
  const stripOverPointer =
292
292
  pointerConfig?.stripOverPointer ?? defaultPointerConfig.stripOverPointer
293
293
  const shiftPointerLabelX =
294
- pointerConfig?.shiftPointerLabelX ??
295
- defaultPointerConfig.shiftPointerLabelX
294
+ pointerConfig?.shiftPointerLabelX ?? defaultPointerConfig.shiftPointerLabelX
296
295
  const shiftPointerLabelY =
297
- pointerConfig?.shiftPointerLabelY ??
298
- defaultPointerConfig.shiftPointerLabelY
296
+ pointerConfig?.shiftPointerLabelY ?? defaultPointerConfig.shiftPointerLabelY
299
297
  const pointerLabelWidth =
300
298
  pointerConfig?.pointerLabelWidth ?? defaultPointerConfig.pointerLabelWidth
301
299
  const pointerLabelHeight =
302
- pointerConfig?.pointerLabelHeight ??
303
- defaultPointerConfig.pointerLabelHeight
300
+ pointerConfig?.pointerLabelHeight ?? defaultPointerConfig.pointerLabelHeight
304
301
  const autoAdjustPointerLabelPosition =
305
302
  pointerConfig?.autoAdjustPointerLabelPosition ??
306
303
  defaultPointerConfig.autoAdjustPointerLabelPosition
307
304
  const pointerVanishDelay =
308
- pointerConfig?.pointerVanishDelay ??
309
- defaultPointerConfig.pointerVanishDelay
305
+ pointerConfig?.pointerVanishDelay ?? defaultPointerConfig.pointerVanishDelay
310
306
  const activatePointersOnLongPress =
311
307
  pointerConfig?.activatePointersOnLongPress ??
312
308
  defaultPointerConfig.activatePointersOnLongPress
@@ -347,17 +343,22 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
347
343
  (props.stackData ?? data)?.[0].barWidth ?? props.barWidth ?? 30
348
344
  if (!lineConfig.curved) {
349
345
  for (let i = 0; i < lineData.length; i++) {
350
- if (i < (lineConfig.startIndex ?? 0) || i > (lineConfig.endIndex ?? 0)) continue
346
+ if (
347
+ i < (lineConfig.startIndex ?? 0) ||
348
+ i > (lineConfig.endIndex ?? 0)
349
+ ) {
350
+ continue
351
+ }
351
352
  const currentBarWidth =
352
353
  data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
353
354
  const currentValue = props.lineData
354
355
  ? props.lineData[i].value
355
356
  : props.stackData
356
- ? props.stackData[i].stacks.reduce(
357
+ ? props.stackData[i].stacks.reduce(
357
358
  (total, item) => total + item.value,
358
359
  0
359
360
  )
360
- : data[i].value
361
+ : data[i].value
361
362
  pp +=
362
363
  'L' +
363
364
  getXForLineInBar(
@@ -402,17 +403,22 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
402
403
  } else {
403
404
  const p1Array: number[][] = []
404
405
  for (let i = 0; i < lineData.length; i++) {
405
- if (i < (lineConfig.startIndex ?? 0) || i > (lineConfig.endIndex ?? 0)) continue
406
+ if (
407
+ i < (lineConfig.startIndex ?? 0) ||
408
+ i > (lineConfig.endIndex ?? 0)
409
+ ) {
410
+ continue
411
+ }
406
412
  const currentBarWidth =
407
413
  data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
408
414
  const currentValue = props.lineData
409
415
  ? props.lineData[i].value
410
416
  : props.stackData
411
- ? props.stackData[i].stacks.reduce(
417
+ ? props.stackData[i].stacks.reduce(
412
418
  (total, item) => total + item.value,
413
419
  0
414
420
  )
415
- : data[i].value
421
+ : data[i].value
416
422
  p1Array.push([
417
423
  getXForLineInBar(
418
424
  i,
@@ -440,7 +446,10 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
440
446
  if (lineData2?.length) {
441
447
  if (!lineConfig2?.curved) {
442
448
  for (let i = 0; i < lineData2.length; i++) {
443
- if (i < (lineConfig2.startIndex ?? 0) || i > (lineConfig2.endIndex ?? 0)) {
449
+ if (
450
+ i < (lineConfig2.startIndex ?? 0) ||
451
+ i > (lineConfig2.endIndex ?? 0)
452
+ ) {
444
453
  continue
445
454
  }
446
455
  const currentBarWidth =
@@ -469,7 +478,10 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
469
478
  } else {
470
479
  const p2Array: number[][] = []
471
480
  for (let i = 0; i < lineData2.length; i++) {
472
- if (i < (lineConfig2.startIndex ?? 0) || i > (lineConfig2.endIndex ?? 0)) {
481
+ if (
482
+ i < (lineConfig2.startIndex ?? 0) ||
483
+ i > (lineConfig2.endIndex ?? 0)
484
+ ) {
473
485
  continue
474
486
  }
475
487
  const currentBarWidth =
@@ -581,7 +593,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
581
593
  })
582
594
 
583
595
  const getPropsCommonForBarAndStack = (
584
- item: stackDataItem | barDataItem,
596
+ item: any,
585
597
  index: number
586
598
  ) => {
587
599
  return {
@@ -46,7 +46,7 @@ export interface stackDataItem {
46
46
  barWidth?: number
47
47
  innerBarComponent?: Function
48
48
  }>
49
- barBackgroundPattern?: Function
49
+ barBackgroundPattern?: () => ReactNode
50
50
  borderRadius?: number
51
51
  borderTopLeftRadius?: number
52
52
  borderTopRightRadius?: number
@@ -106,7 +106,7 @@ export interface StackedBarChartPropsType {
106
106
  stackBorderBottomLeftRadius?: number
107
107
  stackBorderBottomRightRadius?: number
108
108
  xAxisThickness: number
109
- barBackgroundPattern?: Function
109
+ barBackgroundPattern?: () => ReactNode
110
110
  patternId?: string
111
111
  xAxisTextNumberOfLines: number
112
112
  xAxisLabelsHeight?: number
@@ -279,7 +279,7 @@ export interface BarChartPropsType {
279
279
  scrollAnimation?: boolean
280
280
  scrollEventThrottle?: number
281
281
  labelsExtraHeight?: number
282
- barBackgroundPattern?: Function
282
+ barBackgroundPattern?: () => ReactNode
283
283
  patternId?: string
284
284
  barMarginBottom?: number
285
285
  onPress?: Function
@@ -423,7 +423,7 @@ export interface barDataItem {
423
423
  topLabelComponentHeight?: number
424
424
  spacing?: number
425
425
  labelWidth?: number
426
- barBackgroundPattern?: Function
426
+ barBackgroundPattern?: () => ReactNode
427
427
  patternId?: string
428
428
  barMarginBottom?: number
429
429
  leftShiftForTooltip?: number
@@ -464,7 +464,7 @@ export interface Animated2DWithGradientPropsType {
464
464
  barBorderBottomRightRadius?: number
465
465
  containerHeight?: number
466
466
  maxValue?: number
467
- barBackgroundPattern?: Function
467
+ barBackgroundPattern?: () => ReactNode
468
468
  patternId?: string
469
469
  barMarginBottom?: number
470
470
  barStyle?: object
@@ -532,9 +532,9 @@ export interface RenderBarsPropsType {
532
532
  barBorderTopRightRadius?: number
533
533
  barBorderBottomLeftRadius?: number
534
534
  barBorderBottomRightRadius?: number
535
- barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode
535
+ barInnerComponent?: (item?: barDataItem | stackDataItem, index?: number) => ReactNode
536
536
  autoShiftLabels?: boolean
537
- barBackgroundPattern?: Function
537
+ barBackgroundPattern?: () => ReactNode
538
538
  patternId?: string
539
539
  barMarginBottom?: number
540
540
  onPress?: Function
@@ -580,7 +580,7 @@ export interface animatedBarPropTypes {
580
580
  showValuesAsTopLabel: boolean
581
581
  topLabelContainerStyle?: any
582
582
  topLabelTextStyle?: any
583
- barBackgroundPattern?: Function
583
+ barBackgroundPattern?: () => ReactNode
584
584
  barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode
585
585
  patternId?: string
586
586
  barStyle?: object
@@ -592,11 +592,11 @@ export interface animatedBarPropTypes {
592
592
  }
593
593
 
594
594
  export interface CommonPropsFor2Dand3DbarsType {
595
- barBackgroundPattern: Function
596
- barInnerComponent: (item?: barDataItem, index?: number) => ReactNode
597
- patternId: string
595
+ barBackgroundPattern?: () => ReactNode
596
+ barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode
597
+ patternId?: string
598
598
  barWidth: number
599
- barStyle: object
599
+ barStyle?: object
600
600
  item: barDataItem
601
601
  index: number
602
602
 
@@ -18,8 +18,7 @@ import {
18
18
  CurveType,
19
19
  type HighlightedRange,
20
20
  type LineProperties,
21
- type LineSegment,
22
- type secondaryYAxisType
21
+ type LineSegment
23
22
  } from './types'
24
23
  import {
25
24
  type lineConfigType,
@@ -237,8 +236,8 @@ export const getPreviousSegmentsLastPoint = (
237
236
  const prevSegmentLastPoint = isCurved
238
237
  ? previousSegment.substring(previousSegment.trim().lastIndexOf(' '))
239
238
  : previousSegment
240
- .substring(previousSegment.lastIndexOf('L'))
241
- .replace('L', 'M')
239
+ .substring(previousSegment.lastIndexOf('L'))
240
+ .replace('L', 'M')
242
241
 
243
242
  return (
244
243
  (prevSegmentLastPoint.trim()[0] === 'M' ? '' : 'M') + prevSegmentLastPoint
@@ -264,8 +263,8 @@ export const getPathWithHighlight = (
264
263
  data[i + 1].value < from
265
264
  ? loc.DOWN
266
265
  : data[i + 1].value > to
267
- ? loc.UP
268
- : loc.IN
266
+ ? loc.UP
267
+ : loc.IN
269
268
  if (
270
269
  currentPointRegion !== nextPointRegion ||
271
270
  (i === startIndex && currentPointRegion === loc.IN)
@@ -499,7 +498,6 @@ export const getSegmentedPathObjects = (
499
498
  strokeDashArray: number[],
500
499
  isCurved: boolean,
501
500
  startDelimeter: string,
502
- stop: string,
503
501
  endDelimeter: string
504
502
  ): LineProperties[] => {
505
503
  const ar: [LineProperties] = [{ d: '', color: '', strokeWidth: 0 }]
@@ -661,7 +659,6 @@ export const getArrowPoints = (
661
659
 
662
660
  interface IgetAxesAndRulesProps extends BarChartPropsType {
663
661
  verticalLinesUptoDataPoint?: boolean
664
- secondaryYAxis?: secondaryYAxisType
665
662
  }
666
663
 
667
664
  export const getAxesAndRulesProps = (
@@ -669,6 +666,10 @@ export const getAxesAndRulesProps = (
669
666
  stepValue: number,
670
667
  maxValue?: number
671
668
  ): IgetAxesAndRulesProps => {
669
+ const secondaryYAxis =
670
+ !props.secondaryYAxis || props.secondaryYAxis === true
671
+ ? {}
672
+ : props.secondaryYAxis
672
673
  const axesAndRulesProps = {
673
674
  yAxisSide: props.yAxisSide,
674
675
  yAxisLabelContainerStyle: props.yAxisLabelContainerStyle,
@@ -738,7 +739,7 @@ export const getAxesAndRulesProps = (
738
739
  (props.secondaryYAxis ?? props.lineConfig?.isSecondary) &&
739
740
  maxValue !== undefined
740
741
  ) {
741
- axesAndRulesProps.secondaryYAxis = { ...props.secondaryYAxis, maxValue }
742
+ axesAndRulesProps.secondaryYAxis = { ...secondaryYAxis, maxValue }
742
743
  }
743
744
 
744
745
  return axesAndRulesProps
@@ -1357,11 +1358,11 @@ export const getInterpolatedData = (
1357
1358
  // 3. Only post has valid value
1358
1359
  // 4. None has valid value -> this is already handled in preprocessing
1359
1360
 
1360
- const pre = data.slice(0, index)
1361
- const post = data.slice(index + 1, n)
1361
+ const pre: lineDataItem[] = data.slice(0, index)
1362
+ const post: lineDataItem[] = data.slice(index + 1, n)
1362
1363
 
1363
1364
  const preValidIndex = pre.findLastIndex(
1364
- (item) => typeof item.value === 'number'
1365
+ (item: lineDataItem) => typeof item.value === 'number'
1365
1366
  )
1366
1367
  const postValidInd = post.findIndex(
1367
1368
  (item) => typeof item.value === 'number'
@@ -1381,9 +1382,9 @@ export const getInterpolatedData = (
1381
1382
  // Now there are 2 possibilities-
1382
1383
  // 1. There's only 1 valid value in the pre -> this is already handled in preprocessing
1383
1384
  // 2. There are more than valid values in pre
1384
- const secondPre = data.slice(0, preValidIndex)
1385
+ const secondPre: lineDataItem[] = data.slice(0, preValidIndex)
1385
1386
  const secondPreIndex = secondPre.findLastIndex(
1386
- (item) => typeof item.value === 'number'
1387
+ (item: lineDataItem) => typeof item.value === 'number'
1387
1388
  )
1388
1389
 
1389
1390
  count = preValidIndex - secondPreIndex
@@ -1396,7 +1397,7 @@ export const getInterpolatedData = (
1396
1397
  // 1. There's only 1 valid value in the post -> this is already handled in preprocessing
1397
1398
  // 2. There are more than valid values in post
1398
1399
 
1399
- const secondPost = data.slice(postValidIndex + 1, n)
1400
+ const secondPost: lineDataItem[] = data.slice(postValidIndex + 1, n)
1400
1401
  const secondPostInd = secondPost.findIndex(
1401
1402
  (item) => typeof item.value === 'number'
1402
1403
  )