gifted-charts-core 0.1.28 → 0.1.29

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.
@@ -81,6 +81,7 @@ export interface LineChartPropsType {
81
81
  showReferenceLine3?: boolean;
82
82
  referenceLine3Config?: referenceConfigType;
83
83
  referenceLine3Position?: number;
84
+ referenceLinesOverChartContent?: boolean;
84
85
  showVerticalLines?: boolean;
85
86
  verticalLinesUptoDataPoint?: boolean;
86
87
  verticalLinesThickness?: number;
@@ -2,7 +2,7 @@ import { type pieDataItem, type PieChartPropsType } from './types';
2
2
  import { type ColorValue } from 'react-native';
3
3
  interface IusePieChart {
4
4
  radius: number;
5
- extraRadiusForFocused: number;
5
+ extraRadius: number;
6
6
  pi: number;
7
7
  selectedIndex: number;
8
8
  setSelectedIndex: (index: number) => void;
@@ -19,7 +19,11 @@ import { getTextSizeForPieLabels } from '../utils';
19
19
  export var usePieChart = function (props) {
20
20
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
21
21
  var radius = (_a = props.radius) !== null && _a !== void 0 ? _a : 120;
22
- var extraRadiusForFocused = (_b = props.extraRadiusForFocused) !== null && _b !== void 0 ? _b : (((_c = props.focusOnPress) !== null && _c !== void 0 ? _c : props.sectionAutoFocus) ? radius / 10 : 0);
22
+ var extraRadius = (_b = props.extraRadius) !== null && _b !== void 0 ? _b : (props.showExternalLabels
23
+ ? 40
24
+ : ((_c = props.focusOnPress) !== null && _c !== void 0 ? _c : props.sectionAutoFocus)
25
+ ? radius / 10
26
+ : 0);
23
27
  var pi = props.semiCircle ? Math.PI / 2 : Math.PI;
24
28
  var _w = __read(useState((_d = props.focusedPieIndex) !== null && _d !== void 0 ? _d : -1), 2), selectedIndex = _w[0], setSelectedIndex = _w[1]; // at the start, nothing is selected
25
29
  // because we're going to use a useEffect, we need startAngle and total to be state variables
@@ -94,7 +98,7 @@ export var usePieChart = function (props) {
94
98
  : 0;
95
99
  return {
96
100
  radius: radius,
97
- extraRadiusForFocused: extraRadiusForFocused,
101
+ extraRadius: extraRadius,
98
102
  pi: pi,
99
103
  selectedIndex: selectedIndex,
100
104
  setSelectedIndex: setSelectedIndex,
@@ -45,5 +45,39 @@ export declare const getPieChartMainProps: (props: PieChartMainProps) => {
45
45
  acc: number;
46
46
  paddingHorizontal: number;
47
47
  paddingVertical: number;
48
- extraRadiusForFocused: number;
48
+ extraRadius: number;
49
+ showExternalLabels: boolean | undefined;
50
+ labelLineConfig: {
51
+ length: number;
52
+ tailLength: number;
53
+ color: import("react-native").ColorValue;
54
+ thickness: number;
55
+ labelComponentWidth: number;
56
+ labelComponentHeight: number;
57
+ labelComponentMargin: number;
58
+ };
59
+ externalLabelComponent: ((item?: pieDataItem, index?: number) => any) | undefined;
60
+ getExternaLabelProperties: (item: pieDataItem, mx: number, my: number, cx: number, cy: number) => {
61
+ labelLineColor: string;
62
+ labelLineThickness: number;
63
+ labelComponentHeight: number;
64
+ inX: number;
65
+ inY: number;
66
+ outX: number;
67
+ outY: number;
68
+ finalX: number;
69
+ labelComponentX: number;
70
+ localExternalLabelComponent: null;
71
+ } | {
72
+ labelLineColor: import("react-native").ColorValue;
73
+ labelLineThickness: number;
74
+ labelComponentHeight: number;
75
+ inX: number;
76
+ inY: number;
77
+ outX: number;
78
+ outY: number;
79
+ finalX: number;
80
+ labelComponentX: number;
81
+ localExternalLabelComponent: ((item?: pieDataItem, index?: number) => any) | undefined;
82
+ };
49
83
  };
@@ -34,10 +34,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
34
  }
35
35
  return to.concat(ar || Array.prototype.slice.call(from));
36
36
  };
37
- import { getTextSizeForPieLabels } from '../utils';
37
+ import { emptyExternaLabelProperties, getTextSizeForPieLabels } from '../utils';
38
38
  export var getPieChartMainProps = function (props) {
39
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
40
- var isThreeD = props.isThreeD, isBiggerPie = props.isBiggerPie, paddingHorizontal = props.paddingHorizontal, paddingVertical = props.paddingVertical, extraRadiusForFocused = props.extraRadiusForFocused;
39
+ 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;
40
+ var isThreeD = props.isThreeD, isBiggerPie = props.isBiggerPie, paddingHorizontal = props.paddingHorizontal, paddingVertical = props.paddingVertical, extraRadius = props.extraRadius, showExternalLabels = props.showExternalLabels, externalLabelComponent = props.externalLabelComponent;
41
41
  var propData = props.data;
42
42
  var data = [];
43
43
  var itemHasInnerComponent = false;
@@ -72,7 +72,16 @@ export var getPieChartMainProps = function (props) {
72
72
  var showText = (_m = props.showText) !== null && _m !== void 0 ? _m : false;
73
73
  var textColor = (_o = props.textColor) !== null && _o !== void 0 ? _o : '';
74
74
  var textSize = getTextSizeForPieLabels((_p = props.textSize) !== null && _p !== void 0 ? _p : 0, radius);
75
- var tiltAngle = (_q = props.tiltAngle) !== null && _q !== void 0 ? _q : '55deg';
75
+ var labelLineConfig = {
76
+ length: (_r = (_q = props.labelLineConfig) === null || _q === void 0 ? void 0 : _q.length) !== null && _r !== void 0 ? _r : 10,
77
+ tailLength: (_t = (_s = props.labelLineConfig) === null || _s === void 0 ? void 0 : _s.tailLength) !== null && _t !== void 0 ? _t : 8,
78
+ color: (_v = (_u = props.labelLineConfig) === null || _u === void 0 ? void 0 : _u.color) !== null && _v !== void 0 ? _v : 'black',
79
+ thickness: (_x = (_w = props.labelLineConfig) === null || _w === void 0 ? void 0 : _w.thickness) !== null && _x !== void 0 ? _x : 1,
80
+ labelComponentWidth: (_z = (_y = props.labelLineConfig) === null || _y === void 0 ? void 0 : _y.labelComponentWidth) !== null && _z !== void 0 ? _z : 20,
81
+ labelComponentHeight: (_1 = (_0 = props.labelLineConfig) === null || _0 === void 0 ? void 0 : _0.labelComponentHeight) !== null && _1 !== void 0 ? _1 : 10,
82
+ labelComponentMargin: (_3 = (_2 = props.labelLineConfig) === null || _2 === void 0 ? void 0 : _2.labelComponentMargin) !== null && _3 !== void 0 ? _3 : 4
83
+ };
84
+ var tiltAngle = (_4 = props.tiltAngle) !== null && _4 !== void 0 ? _4 : '55deg';
76
85
  if (tiltAngle &&
77
86
  !isNaN(Number(tiltAngle)) &&
78
87
  !(tiltAngle + '').endsWith('deg')) {
@@ -84,12 +93,12 @@ export var getPieChartMainProps = function (props) {
84
93
  : donut || props.centerLabelComponent
85
94
  ? 'outward'
86
95
  : 'mid';
87
- var showTextBackground = (_r = props.showTextBackground) !== null && _r !== void 0 ? _r : false;
88
- var textBackgroundColor = (_s = props.textBackgroundColor) !== null && _s !== void 0 ? _s : 'white';
89
- var showValuesAsLabels = (_t = props.showValuesAsLabels) !== null && _t !== void 0 ? _t : false;
90
- var showGradient = (_u = props.showGradient) !== null && _u !== void 0 ? _u : false;
91
- var gradientCenterColor = (_v = props.gradientCenterColor) !== null && _v !== void 0 ? _v : 'white';
92
- var toggleFocusOnPress = (_w = props.toggleFocusOnPress) !== null && _w !== void 0 ? _w : true;
96
+ var showTextBackground = (_5 = props.showTextBackground) !== null && _5 !== void 0 ? _5 : false;
97
+ var textBackgroundColor = (_6 = props.textBackgroundColor) !== null && _6 !== void 0 ? _6 : 'white';
98
+ var showValuesAsLabels = (_7 = props.showValuesAsLabels) !== null && _7 !== void 0 ? _7 : false;
99
+ var showGradient = (_8 = props.showGradient) !== null && _8 !== void 0 ? _8 : false;
100
+ var gradientCenterColor = (_9 = props.gradientCenterColor) !== null && _9 !== void 0 ? _9 : 'white';
101
+ var toggleFocusOnPress = (_10 = props.toggleFocusOnPress) !== null && _10 !== void 0 ? _10 : true;
93
102
  var minShiftX = 0;
94
103
  var maxShiftX = 0;
95
104
  var minShiftY = 0;
@@ -134,6 +143,50 @@ export var getPieChartMainProps = function (props) {
134
143
  return pAcc + (acc - pAcc) / 2;
135
144
  });
136
145
  pData = __spreadArray([0], __read(pData), false);
146
+ var getExternaLabelProperties = function (item, mx, my, cx, cy) {
147
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
148
+ if (!showExternalLabels)
149
+ return emptyExternaLabelProperties;
150
+ var labelLineLength = (_b = (_a = item.labelLineConfig) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : labelLineConfig.length;
151
+ var labelTailLength = (_d = (_c = item.labelLineConfig) === null || _c === void 0 ? void 0 : _c.tailLength) !== null && _d !== void 0 ? _d : labelLineConfig.tailLength;
152
+ var labelLineColor = (_f = (_e = item.labelLineConfig) === null || _e === void 0 ? void 0 : _e.color) !== null && _f !== void 0 ? _f : labelLineConfig.color;
153
+ var labelLineThickness = (_h = (_g = item.labelLineConfig) === null || _g === void 0 ? void 0 : _g.thickness) !== null && _h !== void 0 ? _h : labelLineConfig.thickness;
154
+ var labelComponentWidth = (_k = (_j = item.labelLineConfig) === null || _j === void 0 ? void 0 : _j.labelComponentWidth) !== null && _k !== void 0 ? _k : labelLineConfig.labelComponentWidth;
155
+ var labelComponentHeight = (_m = (_l = item.labelLineConfig) === null || _l === void 0 ? void 0 : _l.labelComponentHeight) !== null && _m !== void 0 ? _m : labelLineConfig.labelComponentHeight;
156
+ var labelComponentMargin = (_p = (_o = item.labelLineConfig) === null || _o === void 0 ? void 0 : _o.labelComponentMargin) !== null && _p !== void 0 ? _p : labelLineConfig.labelComponentMargin;
157
+ var isRightHalf = mx > cx;
158
+ var slope = (my - cy) / (mx - cx);
159
+ var xFactor = labelTailLength / Math.sqrt(1 + slope * slope);
160
+ var yFactor = (labelTailLength * slope) / Math.sqrt(1 + slope * slope);
161
+ var outX = mx + (isRightHalf ? xFactor : -xFactor);
162
+ var outY = my + (isRightHalf ? yFactor : -yFactor);
163
+ var inX = mx + (isRightHalf ? -xFactor : xFactor);
164
+ var inY = my + (isRightHalf ? -yFactor : yFactor);
165
+ var finalX = isRightHalf ? cx * 2 + labelLineLength : -labelLineLength;
166
+ finalX = isRightHalf
167
+ ? finalX > outX
168
+ ? finalX
169
+ : outX
170
+ : finalX < outX
171
+ ? finalX
172
+ : outX;
173
+ var labelComponentX = isRightHalf
174
+ ? finalX + labelComponentMargin
175
+ : finalX - labelComponentWidth - labelComponentMargin;
176
+ var localExternalLabelComponent = (_q = item.externalLabelComponent) !== null && _q !== void 0 ? _q : props.externalLabelComponent;
177
+ return {
178
+ labelLineColor: labelLineColor,
179
+ labelLineThickness: labelLineThickness,
180
+ labelComponentHeight: labelComponentHeight,
181
+ inX: inX,
182
+ inY: inY,
183
+ outX: outX,
184
+ outY: outY,
185
+ finalX: finalX,
186
+ labelComponentX: labelComponentX,
187
+ localExternalLabelComponent: localExternalLabelComponent
188
+ };
189
+ };
137
190
  return {
138
191
  isThreeD: isThreeD,
139
192
  isBiggerPie: isBiggerPie,
@@ -180,6 +233,10 @@ export var getPieChartMainProps = function (props) {
180
233
  acc: acc,
181
234
  paddingHorizontal: paddingHorizontal,
182
235
  paddingVertical: paddingVertical,
183
- extraRadiusForFocused: extraRadiusForFocused
236
+ extraRadius: extraRadius,
237
+ showExternalLabels: showExternalLabels,
238
+ labelLineConfig: labelLineConfig,
239
+ externalLabelComponent: externalLabelComponent,
240
+ getExternaLabelProperties: getExternaLabelProperties
184
241
  };
185
242
  };
@@ -1,6 +1,6 @@
1
1
  import { type ColorValue } from 'react-native';
2
2
  import { type FontStyle } from 'react-native-svg';
3
- import { LabelsPosition } from '../utils/types';
3
+ import { LabelLineConfig, LabelsPosition } from '../utils/types';
4
4
  export interface PieChartPropsType {
5
5
  radius?: number;
6
6
  isThreeD?: boolean;
@@ -44,7 +44,7 @@ export interface PieChartPropsType {
44
44
  setSelectedIndex?: Function;
45
45
  sectionAutoFocus?: boolean;
46
46
  onLabelPress?: Function;
47
- extraRadiusForFocused?: number;
47
+ extraRadius?: number;
48
48
  inwardExtraLengthForFocused?: number;
49
49
  pieInnerComponent?: (item?: pieDataItem, index?: number) => any;
50
50
  pieInnerComponentHeight?: number;
@@ -59,6 +59,9 @@ export interface PieChartPropsType {
59
59
  isAnimated?: boolean;
60
60
  animationDuration?: number;
61
61
  focusedPieIndex?: number;
62
+ showExternalLabels?: boolean;
63
+ labelLineConfig?: LabelLineConfig;
64
+ externalLabelComponent?: (item?: pieDataItem, index?: number) => any;
62
65
  }
63
66
  export interface pieDataItem {
64
67
  value: number;
@@ -91,11 +94,13 @@ export interface pieDataItem {
91
94
  isEndEdgeCurved?: boolean;
92
95
  startEdgeRadius?: number;
93
96
  endEdgeRadius?: number;
97
+ labelLineConfig?: LabelLineConfig;
98
+ externalLabelComponent?: (item?: pieDataItem, index?: number) => any;
94
99
  }
95
100
  export interface PieChartMainProps extends PieChartPropsType {
96
101
  setSelectedIndex: Function;
97
102
  isBiggerPie?: boolean;
98
103
  paddingHorizontal: number;
99
104
  paddingVertical: number;
100
- extraRadiusForFocused: number;
105
+ extraRadius: number;
101
106
  }
package/dist/index.d.ts CHANGED
@@ -36,4 +36,4 @@ export { type StripAndLabelProps } from './components/common/types';
36
36
  /***********************************************************************************************************************/
37
37
  export { getCumulativeWidth, getLighterColor, svgQuadraticCurvePath, svgPath, bezierCommand, getSegmentString, getCurvePathWithSegments, getPreviousSegmentsLastPoint, getPathWithHighlight, getRegionPathObjects, getSegmentedPathObjects, getArrowPoints, getAxesAndRulesProps, getExtendedContainerHeightWithPadding, getSecondaryDataWithOffsetIncluded, getArrowProperty, getAllArrowProperties, maxAndMinUtil, computeMaxAndMinItems, getLabelTextUtil, getXForLineInBar, getYForLineInBar, clone, getLineConfigForBarChart, adjustToOffset } from './utils';
38
38
  export { chartTypes, yAxisSides, loc, SEGMENT_START, SEGMENT_END, RANGE_ENTER, RANGE_EXIT, STOP, ruleTypes, AxesAndRulesDefaults, defaultArrowConfig, BarDefaults, defaultLineConfig, LineDefaults, defaultPointerConfig, pieColors, populationDefaults, defaultAnimationDuration } from './utils/constants';
39
- export { type RuleType, type RuleTypes, type RulesConfig, CurveType, EdgePosition, type LabelsPosition, type PointerEvents, type secondaryYAxisType, type secondaryLineConfigType, type referenceConfigType, type arrowConfigType, type horizSectionPropTypes, type HorizSectionsType, type BarAndLineChartsWrapperTypes, type Pointer, type HighlightedRange, type LineSegment, type LineSvgProps, type LineProperties, type DataSet, Framework, type XAxisConfig, type LineInBarChartPropsType, type DataPointProps, type Linecap, type IntersectionAreaConfig } from './utils/types';
39
+ export { type RuleType, type RuleTypes, type RulesConfig, CurveType, EdgePosition, type LabelsPosition, type PointerEvents, type secondaryYAxisType, type secondaryLineConfigType, type referenceConfigType, type arrowConfigType, type horizSectionPropTypes, type HorizSectionsType, type BarAndLineChartsWrapperTypes, type Pointer, type HighlightedRange, type LineSegment, type LineSvgProps, type LineProperties, type DataSet, Framework, type XAxisConfig, type LineInBarChartPropsType, type DataPointProps, type Linecap, type IntersectionAreaConfig, type LabelLineConfig } from './utils/types';
@@ -99,4 +99,25 @@ export declare const getTextSizeForPieLabels: (textSize: number, radius: number)
99
99
  export declare const adjustToOffset: (data: lineDataItem[], yAxisOffset?: number) => lineDataItem[];
100
100
  export declare const getSanitisedData: (data: lineDataItem[] | undefined, dataSanitisationProps: IDataSanitisationProps) => lineDataItem[];
101
101
  export declare const getStrokeDashArray: (strokeDash?: number[] | string, framework?: Framework) => number[] | string | undefined;
102
+ export declare const emptyExternaLabelProperties: {
103
+ labelLineColor: string;
104
+ labelLineThickness: number;
105
+ labelComponentHeight: number;
106
+ inX: number;
107
+ inY: number;
108
+ outX: number;
109
+ outY: number;
110
+ finalX: number;
111
+ labelComponentX: number;
112
+ localExternalLabelComponent: null;
113
+ };
114
+ export declare const defaultLabelLineConfig: {
115
+ length: number;
116
+ tailLength: number;
117
+ color: string;
118
+ thickness: number;
119
+ labelComponentWidth: number;
120
+ labelComponentHeight: number;
121
+ labelComponentMargin: number;
122
+ };
102
123
  export {};
@@ -910,7 +910,9 @@ export var getInterpolatedData = function (dataParam, showDataPointsForMissingVa
910
910
  .slice()
911
911
  .reverse()
912
912
  .findIndex(function (item) { return typeof item.value === 'number'; });
913
- var secondPreIndex = tempSecondPreIndex >= 0 ? secondPreCount - tempSecondPreIndex : tempSecondPreIndex;
913
+ var secondPreIndex = tempSecondPreIndex >= 0
914
+ ? secondPreCount - tempSecondPreIndex
915
+ : tempSecondPreIndex;
914
916
  count = preValidIndex - secondPreIndex;
915
917
  step = (data[secondPreIndex].value - data[preValidIndex].value) / count;
916
918
  data[index].value =
@@ -1024,3 +1026,24 @@ export var getStrokeDashArray = function (strokeDash, framework) {
1024
1026
  }
1025
1027
  return strokeDashArrayOrString;
1026
1028
  };
1029
+ export var emptyExternaLabelProperties = {
1030
+ labelLineColor: '',
1031
+ labelLineThickness: 0,
1032
+ labelComponentHeight: 0,
1033
+ inX: 0,
1034
+ inY: 0,
1035
+ outX: 0,
1036
+ outY: 0,
1037
+ finalX: 0,
1038
+ labelComponentX: 0,
1039
+ localExternalLabelComponent: null
1040
+ };
1041
+ export var defaultLabelLineConfig = {
1042
+ length: 10,
1043
+ tailLength: 8,
1044
+ color: 'black',
1045
+ thickness: 1,
1046
+ labelComponentWidth: 20,
1047
+ labelComponentHeight: 10,
1048
+ labelComponentMargin: 4
1049
+ };
@@ -400,4 +400,13 @@ export interface DataSet {
400
400
  export interface IntersectionAreaConfig {
401
401
  fillColor?: ColorValue;
402
402
  }
403
+ export interface LabelLineConfig {
404
+ length?: number;
405
+ tailLength?: number;
406
+ color?: ColorValue;
407
+ thickness?: number;
408
+ labelComponentWidth?: number;
409
+ labelComponentHeight?: number;
410
+ labelComponentMargin?: number;
411
+ }
403
412
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gifted-charts-core",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "Mathematical and logical utilities used by react-gifted-charts and react-native-gifted-charts",
5
5
  "main": "./dist/index.js",
6
6
  "files": [