gifted-charts-core 0.0.22 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/BarChart/index.ts +33 -21
- package/src/BarChart/types.ts +8 -8
- package/src/utils/index.ts +14 -13
package/package.json
CHANGED
package/src/BarChart/index.ts
CHANGED
|
@@ -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
|
|
120
|
-
|
|
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 (
|
|
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
|
-
|
|
357
|
+
? props.stackData[i].stacks.reduce(
|
|
357
358
|
(total, item) => total + item.value,
|
|
358
359
|
0
|
|
359
360
|
)
|
|
360
|
-
|
|
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 (
|
|
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
|
-
|
|
417
|
+
? props.stackData[i].stacks.reduce(
|
|
412
418
|
(total, item) => total + item.value,
|
|
413
419
|
0
|
|
414
420
|
)
|
|
415
|
-
|
|
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 (
|
|
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 (
|
|
481
|
+
if (
|
|
482
|
+
i < (lineConfig2.startIndex ?? 0) ||
|
|
483
|
+
i > (lineConfig2.endIndex ?? 0)
|
|
484
|
+
) {
|
|
473
485
|
continue
|
|
474
486
|
}
|
|
475
487
|
const currentBarWidth =
|
package/src/BarChart/types.ts
CHANGED
|
@@ -46,7 +46,7 @@ export interface stackDataItem {
|
|
|
46
46
|
barWidth?: number
|
|
47
47
|
innerBarComponent?: Function
|
|
48
48
|
}>
|
|
49
|
-
barBackgroundPattern?:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
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?:
|
|
467
|
+
barBackgroundPattern?: () => ReactNode
|
|
468
468
|
patternId?: string
|
|
469
469
|
barMarginBottom?: number
|
|
470
470
|
barStyle?: object
|
|
@@ -534,7 +534,7 @@ export interface RenderBarsPropsType {
|
|
|
534
534
|
barBorderBottomRightRadius?: number
|
|
535
535
|
barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode
|
|
536
536
|
autoShiftLabels?: boolean
|
|
537
|
-
barBackgroundPattern?:
|
|
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?:
|
|
583
|
+
barBackgroundPattern?: () => ReactNode
|
|
584
584
|
barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode
|
|
585
585
|
patternId?: string
|
|
586
586
|
barStyle?: object
|
|
@@ -592,7 +592,7 @@ export interface animatedBarPropTypes {
|
|
|
592
592
|
}
|
|
593
593
|
|
|
594
594
|
export interface CommonPropsFor2Dand3DbarsType {
|
|
595
|
-
barBackgroundPattern:
|
|
595
|
+
barBackgroundPattern: () => ReactNode
|
|
596
596
|
barInnerComponent: (item?: barDataItem, index?: number) => ReactNode
|
|
597
597
|
patternId: string
|
|
598
598
|
barWidth: number
|
package/src/utils/index.ts
CHANGED
|
@@ -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
|
-
|
|
241
|
-
|
|
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
|
-
|
|
268
|
-
|
|
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 = { ...
|
|
742
|
+
axesAndRulesProps.secondaryYAxis = { ...secondaryYAxis, maxValue }
|
|
742
743
|
}
|
|
743
744
|
|
|
744
745
|
return axesAndRulesProps
|
|
@@ -1357,8 +1358,8 @@ 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
1365
|
(item) => typeof item.value === 'number'
|
|
@@ -1381,7 +1382,7 @@ 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
1387
|
(item) => typeof item.value === 'number'
|
|
1387
1388
|
)
|
|
@@ -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
|
)
|