gifted-charts-core 0.1.5 → 0.1.6

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.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Mathematical and logical utilities used by react-gifted-charts and react-native-gifted-charts",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -3,12 +3,12 @@ import { type lineConfigType, type BarChartPropsType, type barDataItem, type sta
3
3
  import { type BarAndLineChartsWrapperTypes, type secondaryYAxisType } from '../utils/types';
4
4
  import { type Animated } from 'react-native';
5
5
  export interface extendedBarChartPropsType extends BarChartPropsType {
6
+ parentWidth: number;
6
7
  heightValue?: Animated.Value;
7
8
  widthValue?: Animated.Value;
8
9
  opacValue?: Animated.Value;
9
10
  verticalLinesUptoDataPoint?: boolean;
10
11
  secondaryYAxis?: secondaryYAxisType | boolean;
11
- screenWidth?: number;
12
12
  }
13
13
  export declare const useBarChart: (props: extendedBarChartPropsType) => {
14
14
  lineConfig: lineConfigType;
@@ -30,11 +30,11 @@ import { getArrowPoints, getAxesAndRulesProps, getExtendedContainerHeightWithPad
30
30
  import { AxesAndRulesDefaults, BarDefaults, chartTypes, defaultLineConfig, defaultPointerConfig } from '../utils/constants';
31
31
  export var useBarChart = function (props) {
32
32
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47;
33
- var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue, yAxisOffset = props.yAxisOffset, adjustToWidth = props.adjustToWidth, _48 = props.screenWidth, screenWidth = _48 === void 0 ? 300 : _48;
34
- var _49 = __read(useState(''), 2), points = _49[0], setPoints = _49[1];
35
- var _50 = __read(useState(''), 2), points2 = _50[0], setPoints2 = _50[1];
36
- var _51 = __read(useState(''), 2), arrowPoints = _51[0], setArrowPoints = _51[1];
37
- var _52 = __read(useState(-1), 2), selectedIndex = _52[0], setSelectedIndex = _52[1];
33
+ var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue, yAxisOffset = props.yAxisOffset, adjustToWidth = props.adjustToWidth, parentWidth = props.parentWidth;
34
+ var _48 = __read(useState(''), 2), points = _48[0], setPoints = _48[1];
35
+ var _49 = __read(useState(''), 2), points2 = _49[0], setPoints2 = _49[1];
36
+ var _50 = __read(useState(''), 2), arrowPoints = _50[0], setArrowPoints = _50[1];
37
+ var _51 = __read(useState(-1), 2), selectedIndex = _51[0], setSelectedIndex = _51[1];
38
38
  var showLine = (_a = props.showLine) !== null && _a !== void 0 ? _a : BarDefaults.showLine;
39
39
  var data = useMemo(function () {
40
40
  if (!props.data) {
@@ -51,11 +51,15 @@ export var useBarChart = function (props) {
51
51
  var yAxisLabelWidth = (_b = props.yAxisLabelWidth) !== null && _b !== void 0 ? _b : (props.hideYAxisText
52
52
  ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
53
53
  : AxesAndRulesDefaults.yAxisLabelWidth);
54
- var autoComputedSectionWidth = (screenWidth - yAxisLabelWidth) / (data.length + 1);
55
- var autoComputedBarWidth = autoComputedSectionWidth * .6;
56
- var defaultBarWidth = adjustToWidth ? autoComputedBarWidth : BarDefaults.barWidth;
54
+ var autoComputedSectionWidth = props.initialSpacing !== undefined
55
+ ? (parentWidth - yAxisLabelWidth) / data.length - props.initialSpacing
56
+ : (parentWidth - yAxisLabelWidth) / (data.length + 0.5);
57
+ var autoComputedBarWidth = autoComputedSectionWidth * 0.6;
58
+ var defaultBarWidth = adjustToWidth
59
+ ? autoComputedBarWidth
60
+ : BarDefaults.barWidth;
57
61
  var barWidth = (_c = props.barWidth) !== null && _c !== void 0 ? _c : defaultBarWidth;
58
- var autoComputedSpacing = autoComputedSectionWidth * .4;
62
+ var autoComputedSpacing = autoComputedSectionWidth * 0.4;
59
63
  var spacing = (_d = props.spacing) !== null && _d !== void 0 ? _d : (adjustToWidth ? autoComputedSpacing : BarDefaults.spacing);
60
64
  var initialSpacing = (_e = props.initialSpacing) !== null && _e !== void 0 ? _e : spacing;
61
65
  var endSpacing = (_f = props.endSpacing) !== null && _f !== void 0 ? _f : spacing;
@@ -119,7 +123,8 @@ export var useBarChart = function (props) {
119
123
  minItem = stackSumMin;
120
124
  }
121
125
  totalWidth +=
122
- ((_b = (_a = stackItem.stacks[0].barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth) + spacing;
126
+ ((_b = (_a = stackItem.stacks[0].barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth) +
127
+ spacing;
123
128
  });
124
129
  }
125
130
  else {
@@ -177,12 +182,12 @@ export var useBarChart = function (props) {
177
182
  var barBorderColor = (_13 = props.barBorderColor) !== null && _13 !== void 0 ? _13 : BarDefaults.barBorderColor;
178
183
  var extendedContainerHeight = getExtendedContainerHeightWithPadding(containerHeight, 0);
179
184
  var containerHeightIncludingBelowXAxis = extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight;
180
- var _53 = __read(useState(-1), 2), pointerIndex = _53[0], setPointerIndex = _53[1];
181
- var _54 = __read(useState(0), 2), pointerX = _54[0], setPointerX = _54[1];
182
- var _55 = __read(useState(0), 2), pointerY = _55[0], setPointerY = _55[1];
183
- var _56 = __read(useState(), 2), pointerItem = _56[0], setPointerItem = _56[1];
184
- var _57 = __read(useState(0), 2), responderStartTime = _57[0], setResponderStartTime = _57[1];
185
- var _58 = __read(useState(false), 2), responderActive = _58[0], setResponderActive = _58[1];
185
+ var _52 = __read(useState(-1), 2), pointerIndex = _52[0], setPointerIndex = _52[1];
186
+ var _53 = __read(useState(0), 2), pointerX = _53[0], setPointerX = _53[1];
187
+ var _54 = __read(useState(0), 2), pointerY = _54[0], setPointerY = _54[1];
188
+ var _55 = __read(useState(), 2), pointerItem = _55[0], setPointerItem = _55[1];
189
+ var _56 = __read(useState(0), 2), responderStartTime = _56[0], setResponderStartTime = _56[1];
190
+ var _57 = __read(useState(false), 2), responderActive = _57[0], setResponderActive = _57[1];
186
191
  var pointerConfig = props.pointerConfig;
187
192
  var getPointerProps = (_14 = props.getPointerProps) !== null && _14 !== void 0 ? _14 : null;
188
193
  var pointerHeight = (_15 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.height) !== null && _15 !== void 0 ? _15 : defaultPointerConfig.height;
@@ -32,16 +32,23 @@ import {
32
32
  import { type Animated } from 'react-native'
33
33
 
34
34
  export interface extendedBarChartPropsType extends BarChartPropsType {
35
+ parentWidth: number,
35
36
  heightValue?: Animated.Value
36
37
  widthValue?: Animated.Value
37
38
  opacValue?: Animated.Value
38
39
  verticalLinesUptoDataPoint?: boolean
39
40
  secondaryYAxis?: secondaryYAxisType | boolean
40
- screenWidth?: number
41
41
  }
42
42
 
43
43
  export const useBarChart = (props: extendedBarChartPropsType) => {
44
- const { heightValue, widthValue, opacValue, yAxisOffset, adjustToWidth, screenWidth=300 } = props
44
+ const {
45
+ heightValue,
46
+ widthValue,
47
+ opacValue,
48
+ yAxisOffset,
49
+ adjustToWidth,
50
+ parentWidth,
51
+ } = props
45
52
  const [points, setPoints] = useState('')
46
53
  const [points2, setPoints2] = useState('')
47
54
  const [arrowPoints, setArrowPoints] = useState('')
@@ -66,16 +73,22 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
66
73
  (props.hideYAxisText
67
74
  ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
68
75
  : AxesAndRulesDefaults.yAxisLabelWidth)
69
-
70
- const autoComputedSectionWidth = (screenWidth - yAxisLabelWidth) / (data.length + 1)
71
- const autoComputedBarWidth = autoComputedSectionWidth * .6
72
76
 
73
- const defaultBarWidth = adjustToWidth ? autoComputedBarWidth : BarDefaults.barWidth
77
+ const autoComputedSectionWidth =
78
+ props.initialSpacing !== undefined
79
+ ? (parentWidth - yAxisLabelWidth) / data.length - props.initialSpacing
80
+ : (parentWidth - yAxisLabelWidth) / (data.length + 0.5)
81
+
82
+ const autoComputedBarWidth = autoComputedSectionWidth * 0.6
83
+ const defaultBarWidth = adjustToWidth
84
+ ? autoComputedBarWidth
85
+ : BarDefaults.barWidth
74
86
  const barWidth = props.barWidth ?? defaultBarWidth
75
87
 
76
- const autoComputedSpacing = autoComputedSectionWidth * .4
88
+ const autoComputedSpacing = autoComputedSectionWidth * 0.4
77
89
 
78
- const spacing = props.spacing ?? ( adjustToWidth ? autoComputedSpacing : BarDefaults.spacing)
90
+ const spacing =
91
+ props.spacing ?? (adjustToWidth ? autoComputedSpacing : BarDefaults.spacing)
79
92
  const initialSpacing = props.initialSpacing ?? spacing
80
93
  const endSpacing = props.endSpacing ?? spacing
81
94
  const showFractionalValues =
@@ -93,7 +106,6 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
93
106
  const animationDuration =
94
107
  props.animationDuration ?? BarDefaults.animationDuration
95
108
 
96
-
97
109
  const secondaryData = getSecondaryDataWithOffsetIncluded(
98
110
  props.secondaryData,
99
111
  props.secondaryYAxis
@@ -168,9 +180,8 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
168
180
  minItem = stackSumMin
169
181
  }
170
182
  totalWidth +=
171
- (stackItem.stacks[0].barWidth ??
172
- props.barWidth ??
173
- defaultBarWidth) + spacing
183
+ (stackItem.stacks[0].barWidth ?? props.barWidth ?? defaultBarWidth) +
184
+ spacing
174
185
  })
175
186
  } else {
176
187
  data.forEach((item: barDataItem) => {
@@ -279,6 +279,7 @@ export interface BarChartPropsType {
279
279
  focusBarOnPress?: boolean;
280
280
  focusedBarConfig?: FocusedBarConfig;
281
281
  adjustToWidth?: boolean;
282
+ parentWidth?: number;
282
283
  }
283
284
  export interface FocusedBarConfig {
284
285
  color?: ColorValue;
@@ -465,7 +466,7 @@ export interface RenderBarsPropsType {
465
466
  spacing: number;
466
467
  propSpacing?: number;
467
468
  data?: any;
468
- barWidth?: number;
469
+ barWidth: number;
469
470
  sideWidth?: number;
470
471
  labelWidth?: number;
471
472
  isThreeD?: boolean;
@@ -315,6 +315,7 @@ export interface BarChartPropsType {
315
315
  focusedBarConfig?: FocusedBarConfig
316
316
 
317
317
  adjustToWidth?: boolean
318
+ parentWidth?: number
318
319
  }
319
320
 
320
321
  export interface FocusedBarConfig {
@@ -508,7 +509,7 @@ export interface RenderBarsPropsType {
508
509
  spacing: number
509
510
  propSpacing?: number
510
511
  data?: any
511
- barWidth?: number
512
+ barWidth: number
512
513
  sideWidth?: number
513
514
  labelWidth?: number
514
515
 
@@ -5,7 +5,10 @@ interface Points {
5
5
  points: string;
6
6
  color: string;
7
7
  }
8
- export declare const useLineChartBiColor: (props: LineChartBicolorPropsType) => {
8
+ interface extendedLineChartBicolorPropsType extends LineChartBicolorPropsType {
9
+ parentWidth: number;
10
+ }
11
+ export declare const useLineChartBiColor: (props: extendedLineChartBicolorPropsType) => {
9
12
  toggle: boolean;
10
13
  setToggle: import("react").Dispatch<import("react").SetStateAction<boolean>>;
11
14
  pointsArray: Points[];
@@ -19,7 +19,11 @@ interface Points {
19
19
  color: string
20
20
  }
21
21
 
22
- export const useLineChartBiColor = (props: LineChartBicolorPropsType) => {
22
+ interface extendedLineChartBicolorPropsType extends LineChartBicolorPropsType {
23
+ parentWidth: number
24
+ }
25
+
26
+ export const useLineChartBiColor = (props: extendedLineChartBicolorPropsType) => {
23
27
  const [toggle, setToggle] = useState(false)
24
28
  const [pointsArray, setPointsArray] = useState<Points[]>([])
25
29
  const [fillPointsArray, setFillPointsArray] = useState<Points[]>([])
@@ -4,7 +4,7 @@ import { type BarAndLineChartsWrapperTypes, EdgePosition, type LineSegment } fro
4
4
  import { type Animated } from 'react-native';
5
5
  export interface extendedLineChartPropsType extends LineChartPropsType {
6
6
  animations?: Animated.Value[];
7
- screenWidth: number;
7
+ parentWidth: number;
8
8
  }
9
9
  export declare const useLineChart: (props: extendedLineChartPropsType) => {
10
10
  curvature: number;
@@ -31,7 +31,7 @@ import { adjustToOffset, computeMaxAndMinItems, getAllArrowProperties, getArrowP
31
31
  import { EdgePosition } from '../utils/types';
32
32
  export var useLineChart = function (props) {
33
33
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, _108, _109, _110, _111, _112, _113, _114, _115, _116, _117, _118, _119, _120, _121, _122, _123, _124, _125, _126, _127, _128, _129, _130, _131, _132, _133, _134, _135, _136, _137, _138, _139, _140, _141, _142, _143, _144, _145, _146, _147, _148, _149, _150, _151, _152, _153, _154, _155, _156, _157, _158, _159, _160, _161, _162, _163, _164, _165, _166, _167, _168, _169, _170, _171, _172, _173, _174, _175, _176, _177, _178, _179, _180, _181, _182, _183, _184, _185, _186, _187, _188, _189, _190, _191, _192, _193, _194, _195, _196, _197, _198, _199, _200, _201, _202, _203, _204, _205, _206, _207, _208, _209, _210, _211, _212, _213, _214, _215, _216, _217, _218, _219, _220, _221, _222, _223, _224, _225, _226, _227, _228, _229, _230, _231, _232, _233, _234, _235, _236, _237, _238, _239, _240, _241, _242, _243, _244, _245, _246, _247, _248, _249, _250, _251, _252, _253, _254, _255, _256, _257, _258, _259, _260, _261, _262, _263, _264, _265, _266, _267, _268, _269, _270, _271, _272, _273, _274, _275, _276, _277, _278, _279, _280, _281, _282, _283, _284, _285, _286, _287, _288, _289, _290, _291;
34
- var animations = props.animations, showDataPointsForMissingValues = props.showDataPointsForMissingValues, _292 = props.interpolateMissingValues, interpolateMissingValues = _292 === void 0 ? true : _292, onlyPositive = props.onlyPositive, yAxisOffset = props.yAxisOffset, screenWidth = props.screenWidth;
34
+ var animations = props.animations, showDataPointsForMissingValues = props.showDataPointsForMissingValues, _292 = props.interpolateMissingValues, interpolateMissingValues = _292 === void 0 ? true : _292, onlyPositive = props.onlyPositive, yAxisOffset = props.yAxisOffset, parentWidth = props.parentWidth;
35
35
  var curvature = (_a = props.curvature) !== null && _a !== void 0 ? _a : LineDefaults.curvature;
36
36
  var curveType = (_b = props.curveType) !== null && _b !== void 0 ? _b : LineDefaults.curveType;
37
37
  var _293 = __read(useState(0), 2), scrollX = _293[0], setScrollX = _293[1];
@@ -156,7 +156,7 @@ export var useLineChart = function (props) {
156
156
  ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
157
157
  : AxesAndRulesDefaults.yAxisLabelWidth);
158
158
  var spacing = (_5 = props.spacing) !== null && _5 !== void 0 ? _5 : (adjustToWidth
159
- ? (((_6 = props.width) !== null && _6 !== void 0 ? _6 : screenWidth - yAxisLabelWidth) - initialSpacing) /
159
+ ? (((_6 = props.width) !== null && _6 !== void 0 ? _6 : parentWidth - yAxisLabelWidth) - initialSpacing) /
160
160
  Math.max((data0 !== null && data0 !== void 0 ? data0 : data).length - 1, 1)
161
161
  : LineDefaults.spacing);
162
162
  var xAxisThickness = (_7 = props.xAxisThickness) !== null && _7 !== void 0 ? _7 : AxesAndRulesDefaults.xAxisThickness;
@@ -43,7 +43,7 @@ export interface extendedLineChartPropsType extends LineChartPropsType {
43
43
  // heightValue: Animated.Value
44
44
  // widthValue: Animated.Value
45
45
  // opacValue: Animated.Value
46
- screenWidth: number
46
+ parentWidth: number
47
47
  }
48
48
 
49
49
  export const useLineChart = (props: extendedLineChartPropsType) => {
@@ -53,7 +53,7 @@ export const useLineChart = (props: extendedLineChartPropsType) => {
53
53
  interpolateMissingValues = true,
54
54
  onlyPositive,
55
55
  yAxisOffset,
56
- screenWidth
56
+ parentWidth
57
57
  } = props
58
58
  const curvature = props.curvature ?? LineDefaults.curvature
59
59
  const curveType = props.curveType ?? LineDefaults.curveType
@@ -245,7 +245,7 @@ export const useLineChart = (props: extendedLineChartPropsType) => {
245
245
  const spacing =
246
246
  props.spacing ??
247
247
  (adjustToWidth
248
- ? ((props.width ?? screenWidth - yAxisLabelWidth) - initialSpacing) /
248
+ ? ((props.width ?? parentWidth - yAxisLabelWidth) - initialSpacing) /
249
249
  Math.max((data0 ?? data).length - 1, 1)
250
250
  : LineDefaults.spacing)
251
251
 
@@ -292,6 +292,7 @@ export interface LineChartPropsType {
292
292
  showDataPointsForMissingValues?: boolean;
293
293
  interpolateMissingValues?: boolean;
294
294
  onlyPositive?: boolean;
295
+ parentWidth?: number;
295
296
  }
296
297
  export interface lineDataItem {
297
298
  value: number;
@@ -522,6 +523,7 @@ export interface LineChartBicolorPropsType {
522
523
  formatYLabel?: (label: string) => string;
523
524
  onScroll?: Function;
524
525
  endReachedOffset?: number;
526
+ parentWidth?: number;
525
527
  }
526
528
  export interface IDataSanitisationProps {
527
529
  showDataPointsForMissingValues: boolean | undefined;
@@ -325,6 +325,7 @@ export interface LineChartPropsType {
325
325
  showDataPointsForMissingValues?: boolean
326
326
  interpolateMissingValues?: boolean
327
327
  onlyPositive?: boolean
328
+ parentWidth?: number
328
329
  }
329
330
 
330
331
  export interface lineDataItem {
@@ -584,6 +585,7 @@ export interface LineChartBicolorPropsType {
584
585
  formatYLabel?: (label: string) => string
585
586
  onScroll?: Function
586
587
  endReachedOffset?: number
588
+ parentWidth?: number
587
589
  }
588
590
 
589
591
  export interface IDataSanitisationProps {
@@ -531,6 +531,7 @@ export var getAxesAndRulesProps = function (props, stepValue, maxValue) {
531
531
  verticalLinesHeight: props.verticalLinesHeight,
532
532
  verticalLinesColor: props.verticalLinesColor,
533
533
  verticalLinesShift: props.verticalLinesShift,
534
+ verticalLinesStrokeDashArray: props.verticalLinesStrokeDashArray,
534
535
  verticalLinesZIndex: props.verticalLinesZIndex,
535
536
  verticalLinesSpacing: props.verticalLinesSpacing,
536
537
  noOfVerticalLines: props.noOfVerticalLines,
@@ -711,6 +711,7 @@ export const getAxesAndRulesProps = (
711
711
  verticalLinesHeight: props.verticalLinesHeight,
712
712
  verticalLinesColor: props.verticalLinesColor,
713
713
  verticalLinesShift: props.verticalLinesShift,
714
+ verticalLinesStrokeDashArray: props.verticalLinesStrokeDashArray,
714
715
  verticalLinesZIndex: props.verticalLinesZIndex,
715
716
  verticalLinesSpacing: props.verticalLinesSpacing,
716
717
  noOfVerticalLines: props.noOfVerticalLines,