react-native-financial-charts 1.0.0
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/LICENSE +20 -0
- package/README.md +309 -0
- package/lib/module/ChartContext.js +269 -0
- package/lib/module/ChartContext.js.map +1 -0
- package/lib/module/components/AnimatedTextInput.js +24 -0
- package/lib/module/components/AnimatedTextInput.js.map +1 -0
- package/lib/module/components/ChartArea.js +31 -0
- package/lib/module/components/ChartArea.js.map +1 -0
- package/lib/module/components/ChartBaseline.js +121 -0
- package/lib/module/components/ChartBaseline.js.map +1 -0
- package/lib/module/components/ChartCanvas.js +36 -0
- package/lib/module/components/ChartCanvas.js.map +1 -0
- package/lib/module/components/ChartCursor.js +75 -0
- package/lib/module/components/ChartCursor.js.map +1 -0
- package/lib/module/components/ChartLine.js +37 -0
- package/lib/module/components/ChartLine.js.map +1 -0
- package/lib/module/components/ChartTooltipDate.js +100 -0
- package/lib/module/components/ChartTooltipDate.js.map +1 -0
- package/lib/module/components/ChartTooltipValue.js +102 -0
- package/lib/module/components/ChartTooltipValue.js.map +1 -0
- package/lib/module/index.js +24 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/interfaces.js +4 -0
- package/lib/module/interfaces.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/utils.js +30 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ChartContext.d.ts +16 -0
- package/lib/typescript/src/ChartContext.d.ts.map +1 -0
- package/lib/typescript/src/components/AnimatedTextInput.d.ts +8 -0
- package/lib/typescript/src/components/AnimatedTextInput.d.ts.map +1 -0
- package/lib/typescript/src/components/ChartArea.d.ts +9 -0
- package/lib/typescript/src/components/ChartArea.d.ts.map +1 -0
- package/lib/typescript/src/components/ChartBaseline.d.ts +10 -0
- package/lib/typescript/src/components/ChartBaseline.d.ts.map +1 -0
- package/lib/typescript/src/components/ChartCanvas.d.ts +7 -0
- package/lib/typescript/src/components/ChartCanvas.d.ts.map +1 -0
- package/lib/typescript/src/components/ChartCursor.d.ts +10 -0
- package/lib/typescript/src/components/ChartCursor.d.ts.map +1 -0
- package/lib/typescript/src/components/ChartLine.d.ts +10 -0
- package/lib/typescript/src/components/ChartLine.d.ts.map +1 -0
- package/lib/typescript/src/components/ChartTooltipDate.d.ts +9 -0
- package/lib/typescript/src/components/ChartTooltipDate.d.ts.map +1 -0
- package/lib/typescript/src/components/ChartTooltipValue.d.ts +9 -0
- package/lib/typescript/src/components/ChartTooltipValue.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +16 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/interfaces.d.ts +30 -0
- package/lib/typescript/src/interfaces.d.ts.map +1 -0
- package/lib/typescript/src/utils.d.ts +15 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- package/package.json +171 -0
- package/src/ChartContext.tsx +311 -0
- package/src/components/AnimatedTextInput.tsx +27 -0
- package/src/components/ChartArea.tsx +28 -0
- package/src/components/ChartBaseline.tsx +137 -0
- package/src/components/ChartCanvas.tsx +28 -0
- package/src/components/ChartCursor.tsx +84 -0
- package/src/components/ChartLine.tsx +34 -0
- package/src/components/ChartTooltipDate.tsx +110 -0
- package/src/components/ChartTooltipValue.tsx +109 -0
- package/src/index.tsx +23 -0
- package/src/interfaces.ts +51 -0
- package/src/utils.ts +33 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useDerivedValue, withSpring } from 'react-native-reanimated';
|
|
4
|
+
import { useChart } from "../ChartContext.js";
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { Circle, DashPathEffect, Group, matchFont, Path, RoundedRect, Skia, Text as SkiaText } from '@shopify/react-native-skia';
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
/**
|
|
9
|
+
* Draws the dotted line at the starting value (profit line)
|
|
10
|
+
*/
|
|
11
|
+
const ChartBaseline = ({
|
|
12
|
+
color = '#858CA2',
|
|
13
|
+
showLabel = true
|
|
14
|
+
}) => {
|
|
15
|
+
const {
|
|
16
|
+
width,
|
|
17
|
+
padding,
|
|
18
|
+
baselineY,
|
|
19
|
+
originalData,
|
|
20
|
+
isActive
|
|
21
|
+
} = useChart();
|
|
22
|
+
|
|
23
|
+
// Animation: Devired values automatically update when their dependencies change.
|
|
24
|
+
// Here, is isActive become true, opacity sprints to 0.
|
|
25
|
+
const labelOpacity = useDerivedValue(() => {
|
|
26
|
+
return withSpring(isActive.value ? 0 : 1);
|
|
27
|
+
}, [isActive]);
|
|
28
|
+
|
|
29
|
+
// Font Manager: Skia needs to load a font file to draw text.
|
|
30
|
+
// matchFont tries to find a system font that matches these specs.
|
|
31
|
+
const font = useMemo(() => matchFont({
|
|
32
|
+
fontFamily: 'Arial',
|
|
33
|
+
fontSize: 10,
|
|
34
|
+
fontWeight: 'bold'
|
|
35
|
+
}), []);
|
|
36
|
+
const labelText = useMemo(() => {
|
|
37
|
+
if (!originalData.length) return '';
|
|
38
|
+
const val = originalData[0]?.value || 0;
|
|
39
|
+
return new Intl.NumberFormat('pt-BR', {
|
|
40
|
+
style: 'currency',
|
|
41
|
+
currency: 'BRL',
|
|
42
|
+
notation: 'compact',
|
|
43
|
+
maximumFractionDigits: 1
|
|
44
|
+
}).format(val);
|
|
45
|
+
}, [originalData]);
|
|
46
|
+
|
|
47
|
+
// Geomatry Calculation: Positioning the label chip.
|
|
48
|
+
const chipGeometry = useMemo(() => {
|
|
49
|
+
if (!font || !labelText) return null;
|
|
50
|
+
const textWidth = font.getTextWidth(labelText);
|
|
51
|
+
const fontMetrics = font.getMetrics();
|
|
52
|
+
const textHeight = fontMetrics.descent - fontMetrics.ascent;
|
|
53
|
+
const hPadding = 8;
|
|
54
|
+
const vPadding = 4;
|
|
55
|
+
const chipHeight = textHeight + vPadding * 2;
|
|
56
|
+
const chipWidth = textWidth + hPadding * 2;
|
|
57
|
+
const chipRadius = 8;
|
|
58
|
+
const chipX = padding;
|
|
59
|
+
const chipY = baselineY - chipHeight / 2;
|
|
60
|
+
const textX = chipX + hPadding;
|
|
61
|
+
const textY = chipY + vPadding - fontMetrics.ascent;
|
|
62
|
+
return {
|
|
63
|
+
rect: {
|
|
64
|
+
x: chipX,
|
|
65
|
+
y: chipY,
|
|
66
|
+
width: chipWidth,
|
|
67
|
+
height: chipHeight,
|
|
68
|
+
r: chipRadius
|
|
69
|
+
},
|
|
70
|
+
textPos: {
|
|
71
|
+
x: textX,
|
|
72
|
+
y: textY
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}, [font, labelText, padding, baselineY]);
|
|
76
|
+
|
|
77
|
+
// Create simple horizontal line path
|
|
78
|
+
const path = useMemo(() => {
|
|
79
|
+
const p = Skia.Path.Make();
|
|
80
|
+
if (Number.isFinite(baselineY) && baselineY > 0) {
|
|
81
|
+
p.moveTo(padding, baselineY);
|
|
82
|
+
p.lineTo(width - padding, baselineY);
|
|
83
|
+
}
|
|
84
|
+
return p;
|
|
85
|
+
}, [width, padding, baselineY]);
|
|
86
|
+
if (!baselineY) return null;
|
|
87
|
+
return /*#__PURE__*/_jsxs(Group, {
|
|
88
|
+
children: [/*#__PURE__*/_jsx(Path, {
|
|
89
|
+
path: path,
|
|
90
|
+
color: color,
|
|
91
|
+
style: "stroke",
|
|
92
|
+
strokeWidth: 1,
|
|
93
|
+
children: /*#__PURE__*/_jsx(DashPathEffect, {
|
|
94
|
+
intervals: [5, 5]
|
|
95
|
+
})
|
|
96
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
97
|
+
cx: padding,
|
|
98
|
+
cy: baselineY,
|
|
99
|
+
r: 3,
|
|
100
|
+
color: color
|
|
101
|
+
}), showLabel && font && chipGeometry && /*#__PURE__*/_jsxs(Group, {
|
|
102
|
+
opacity: labelOpacity,
|
|
103
|
+
children: [/*#__PURE__*/_jsx(RoundedRect, {
|
|
104
|
+
x: chipGeometry.rect.x,
|
|
105
|
+
y: chipGeometry.rect.y,
|
|
106
|
+
width: chipGeometry.rect.width,
|
|
107
|
+
height: chipGeometry.rect.height,
|
|
108
|
+
r: chipGeometry.rect.r,
|
|
109
|
+
color: "#323546"
|
|
110
|
+
}), /*#__PURE__*/_jsx(SkiaText, {
|
|
111
|
+
font: font,
|
|
112
|
+
x: chipGeometry.textPos.x,
|
|
113
|
+
y: chipGeometry.textPos.y,
|
|
114
|
+
text: labelText,
|
|
115
|
+
color: "#FFFFFF"
|
|
116
|
+
})]
|
|
117
|
+
})]
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
export default ChartBaseline;
|
|
121
|
+
//# sourceMappingURL=ChartBaseline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDerivedValue","withSpring","useChart","useMemo","Circle","DashPathEffect","Group","matchFont","Path","RoundedRect","Skia","Text","SkiaText","jsx","_jsx","jsxs","_jsxs","ChartBaseline","color","showLabel","width","padding","baselineY","originalData","isActive","labelOpacity","value","font","fontFamily","fontSize","fontWeight","labelText","length","val","Intl","NumberFormat","style","currency","notation","maximumFractionDigits","format","chipGeometry","textWidth","getTextWidth","fontMetrics","getMetrics","textHeight","descent","ascent","hPadding","vPadding","chipHeight","chipWidth","chipRadius","chipX","chipY","textX","textY","rect","x","y","height","r","textPos","path","p","Make","Number","isFinite","moveTo","lineTo","children","strokeWidth","intervals","cx","cy","opacity","text"],"sourceRoot":"../../../src","sources":["components/ChartBaseline.tsx"],"mappings":";;AAAA,SAASA,eAAe,EAAEC,UAAU,QAAQ,yBAAyB;AACrE,SAASC,QAAQ,QAAQ,oBAAiB;AAC1C,SAASC,OAAO,QAAQ,OAAO;AAC/B,SACEC,MAAM,EACNC,cAAc,EACdC,KAAK,EACLC,SAAS,EACTC,IAAI,EACJC,WAAW,EACXC,IAAI,EACJC,IAAI,IAAIC,QAAQ,QACX,4BAA4B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC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A,CACG,CACR;EAAA,CACI,CAAC;AAEZ,CAAC;AAED,eAAeD,aAAa","ignoreList":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ChartContext, useChart } from "../ChartContext.js";
|
|
4
|
+
import { Canvas } from '@shopify/react-native-skia';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The wrapper for all Skia elements.
|
|
8
|
+
*/
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
const ChartCanvas = ({
|
|
11
|
+
children
|
|
12
|
+
}) => {
|
|
13
|
+
const ctx = useChart();
|
|
14
|
+
const {
|
|
15
|
+
width,
|
|
16
|
+
height
|
|
17
|
+
} = ctx;
|
|
18
|
+
const safeWidth = width || 1;
|
|
19
|
+
const safeHeight = height || 1;
|
|
20
|
+
return (
|
|
21
|
+
/*#__PURE__*/
|
|
22
|
+
// Skia 'Canvas' uses its own render three, separate from standard React Native views.
|
|
23
|
+
_jsx(Canvas, {
|
|
24
|
+
style: {
|
|
25
|
+
width: safeWidth,
|
|
26
|
+
height: safeHeight
|
|
27
|
+
},
|
|
28
|
+
children: /*#__PURE__*/_jsx(ChartContext.Provider, {
|
|
29
|
+
value: ctx,
|
|
30
|
+
children: children
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
export default ChartCanvas;
|
|
36
|
+
//# sourceMappingURL=ChartCanvas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ChartContext","useChart","Canvas","jsx","_jsx","ChartCanvas","children","ctx","width","height","safeWidth","safeHeight","style","Provider","value"],"sourceRoot":"../../../src","sources":["components/ChartCanvas.tsx"],"mappings":";;AACA,SAASA,YAAY,EAAEC,QAAQ,QAAQ,oBAAiB;AACxD,SAASC,MAAM,QAAQ,4BAA4B;;AAEnD;AACA;AACA;AAFA,SAAAC,GAAA,IAAAC,IAAA;AAGA,MAAMC,WAAwC,GAAGA,CAAC;EAAEC;AAAS,CAAC,KAAK;EACjE,MAAMC,GAAG,GAAGN,QAAQ,CAAC,CAAC;EACtB,MAAM;IAAEO,KAAK;IAAEC;EAAO,CAAC,GAAGF,GAAG;EAC7B,MAAMG,SAAS,GAAGF,KAAK,IAAI,CAAC;EAC5B,MAAMG,UAAU,GAAGF,MAAM,IAAI,CAAC;EAE9B;IAAA;IACE;IACAL,IAAA,CAACF,MAAM;MACLU,KAAK,EAAE;QACLJ,KAAK,EAAEE,SAAS;QAChBD,MAAM,EAAEE;MACV,CAAE;MAAAL,QAAA,eAGFF,IAAA,CAACJ,YAAY,CAACa,QAAQ;QAACC,KAAK,EAAEP,GAAI;QAAAD,QAAA,EAAEA;MAAQ,CAAwB;IAAC,CAC/D;EAAC;AAEb,CAAC;AAED,eAAeD,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useDerivedValue, withSpring } from 'react-native-reanimated';
|
|
4
|
+
import { useChart } from "../ChartContext.js";
|
|
5
|
+
import { BlurMask, Circle, Group, Line, LinearGradient, vec } from '@shopify/react-native-skia';
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
/**
|
|
8
|
+
* The Crosshair and Highlight Circle
|
|
9
|
+
*/
|
|
10
|
+
const ChartCursor = ({
|
|
11
|
+
crosshairColor = 'white',
|
|
12
|
+
circleColor = 'white'
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
currentX,
|
|
16
|
+
currentY,
|
|
17
|
+
isActive,
|
|
18
|
+
padding,
|
|
19
|
+
height,
|
|
20
|
+
gradientPositions
|
|
21
|
+
} = useChart();
|
|
22
|
+
|
|
23
|
+
// Calculate line endpoints responsively using Reanimated derived values
|
|
24
|
+
const lineP1 = useDerivedValue(() => vec(currentX.value, padding));
|
|
25
|
+
const lineP2 = useDerivedValue(() => vec(currentX.value, height - padding));
|
|
26
|
+
const opacity = useDerivedValue(() => withSpring(isActive.value ? 1 : 0));
|
|
27
|
+
const defaultColors = ['#00E396', '#00E396', '#EA3943', '#EA3943'];
|
|
28
|
+
const gradientColorsHalo = ['#00E396E6', '#00E39600', '#EA394300', '#EA394326'];
|
|
29
|
+
return /*#__PURE__*/_jsxs(Group, {
|
|
30
|
+
opacity: opacity,
|
|
31
|
+
children: [/*#__PURE__*/_jsx(Line, {
|
|
32
|
+
p1: lineP1,
|
|
33
|
+
p2: lineP2,
|
|
34
|
+
color: crosshairColor,
|
|
35
|
+
style: "stroke",
|
|
36
|
+
strokeWidth: 1,
|
|
37
|
+
children: /*#__PURE__*/_jsx(BlurMask, {
|
|
38
|
+
blur: 1,
|
|
39
|
+
style: "solid"
|
|
40
|
+
})
|
|
41
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
42
|
+
cx: currentX,
|
|
43
|
+
cy: currentY,
|
|
44
|
+
r: 12,
|
|
45
|
+
opacity: 0.3,
|
|
46
|
+
style: "fill",
|
|
47
|
+
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
48
|
+
start: vec(0, 0),
|
|
49
|
+
end: vec(0, height),
|
|
50
|
+
colors: gradientColorsHalo,
|
|
51
|
+
positions: gradientPositions
|
|
52
|
+
})
|
|
53
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
54
|
+
cx: currentX,
|
|
55
|
+
cy: currentY,
|
|
56
|
+
r: 6,
|
|
57
|
+
style: "fill",
|
|
58
|
+
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
59
|
+
start: vec(0, 0),
|
|
60
|
+
end: vec(0, height),
|
|
61
|
+
colors: defaultColors,
|
|
62
|
+
positions: gradientPositions
|
|
63
|
+
})
|
|
64
|
+
}), /*#__PURE__*/_jsx(Circle, {
|
|
65
|
+
cx: currentX,
|
|
66
|
+
cy: currentY,
|
|
67
|
+
r: 6,
|
|
68
|
+
color: circleColor,
|
|
69
|
+
style: "stroke",
|
|
70
|
+
strokeWidth: 2
|
|
71
|
+
})]
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
export default ChartCursor;
|
|
75
|
+
//# sourceMappingURL=ChartCursor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useDerivedValue","withSpring","useChart","BlurMask","Circle","Group","Line","LinearGradient","vec","jsx","_jsx","jsxs","_jsxs","ChartCursor","crosshairColor","circleColor","currentX","currentY","isActive","padding","height","gradientPositions","lineP1","value","lineP2","opacity","defaultColors","gradientColorsHalo","children","p1","p2","color","style","strokeWidth","blur","cx","cy","r","start","end","colors","positions"],"sourceRoot":"../../../src","sources":["components/ChartCursor.tsx"],"mappings":";;AAAA,SAASA,eAAe,EAAEC,UAAU,QAAQ,yBAAyB;AACrE,SAASC,QAAQ,QAAQ,oBAAiB;AAC1C,SACEC,QAAQ,EACRC,MAAM,EACNC,KAAK,EACLC,IAAI,EACJC,cAAc,EACdC,GAAG,QACE,4BAA4B;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAOpC;AACA;AACA;AACA,MAAMC,WAA6B,GAAGA,CAAC;EACrCC,cAAc,GAAG,OAAO;EACxBC,WAAW,GAAG;AAChB,CAAC,KAAK;EACJ,MAAM;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC,OAAO;IAAEC,MAAM;IAAEC;EAAkB,CAAC,GACxEnB,QAAQ,CAAC,CAAC;;EAEZ;EACA,MAAMoB,MAAM,GAAGtB,eAAe,CAAC,MAAMQ,GAAG,CAACQ,QAAQ,CAACO,KAAK,EAAEJ,OAAO,CAAC,CAAC;EAClE,MAAMK,MAAM,GAAGxB,eAAe,CAAC,MAAMQ,GAAG,CAACQ,QAAQ,CAACO,KAAK,EAAEH,MAAM,GAAGD,OAAO,CAAC,CAAC;EAE3E,MAAMM,OAAO,GAAGzB,eAAe,CAAC,MAAMC,UAAU,CAACiB,QAAQ,CAACK,KA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E;QACpBoB,MAAM,EAAEd,aAAc;QACtBe,SAAS,EAAEpB;MAAkB,CAC9B;IAAC,CACI,CAAC,eAETX,IAAA,CAACN,MAAM;MACL+B,EAAE,EAAEnB,QAAS;MACboB,EAAE,EAAEnB,QAAS;MACboB,CAAC,EAAE,CAAE;MACLN,KAAK,EAAEhB,WAAY;MACnBiB,KAAK,EAAC,QAAQ;MACdC,WAAW,EAAE;IAAE,CAChB,CAAC;EAAA,CACG,CAAC;AAEZ,CAAC;AAED,eAAepB,WAAW","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { LinearGradient, Path, vec } from '@shopify/react-native-skia';
|
|
4
|
+
import { useChart } from "../ChartContext.js";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
/**
|
|
7
|
+
* Draws the main trend line.
|
|
8
|
+
*/
|
|
9
|
+
const ChartLine = ({
|
|
10
|
+
strokeWidth = 3,
|
|
11
|
+
colors
|
|
12
|
+
}) => {
|
|
13
|
+
const {
|
|
14
|
+
path,
|
|
15
|
+
height,
|
|
16
|
+
gradientPositions
|
|
17
|
+
} = useChart();
|
|
18
|
+
const defaultColors = ['#00E396', '#00E396', '#EA3943', '#EA3943'];
|
|
19
|
+
return /*#__PURE__*/_jsx(Path, {
|
|
20
|
+
path: path,
|
|
21
|
+
style: "stroke" // 'stroke' means draw lines, 'fill' means fill shapes
|
|
22
|
+
,
|
|
23
|
+
strokeWidth: strokeWidth,
|
|
24
|
+
strokeJoin: "round",
|
|
25
|
+
strokeCap: "round",
|
|
26
|
+
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
27
|
+
start: vec(0, 0) // Gradient starts at top
|
|
28
|
+
,
|
|
29
|
+
end: vec(0, height) // Gradient ends at bottom
|
|
30
|
+
,
|
|
31
|
+
colors: colors || defaultColors,
|
|
32
|
+
positions: gradientPositions
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export default ChartLine;
|
|
37
|
+
//# sourceMappingURL=ChartLine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["LinearGradient","Path","vec","useChart","jsx","_jsx","ChartLine","strokeWidth","colors","path","height","gradientPositions","defaultColors","style","strokeJoin","strokeCap","children","start","end","positions"],"sourceRoot":"../../../src","sources":["components/ChartLine.tsx"],"mappings":";;AAAA,SAASA,cAAc,EAAEC,IAAI,EAAEC,GAAG,QAAQ,4BAA4B;AACtE,SAASC,QAAQ,QAAQ,oBAAiB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAO3C;AACA;AACA;AACA,MAAMC,SAA2B,GAAGA,CAAC;EAAEC,WAAW,GAAG,CAAC;EAAEC;AAAO,CAAC,KAAK;EACnE,MAAM;IAAEC,IAAI;IAAEC,MAAM;IAAEC;EAAkB,CAAC,GAAGR,QAAQ,CAAC,CAAC;EACtD,MAAMS,aAAa,GAAG,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;EAElE,oBACEP,IAAA,CAACJ,IAAI;IACHQ,IAAI,EAAEA,IAAK;IACXI,KAAK,EAAC,QAAQ,CAAC;IAAA;IACfN,WAAW,EAAEA,WAAY;IACzBO,UAAU,EAAC,OAAO;IAClBC,SAAS,EAAC,OAAO;IAAAC,QAAA,eAEjBX,IAAA,CAACL,cAAc;MACbiB,KAAK,EAAEf,GAAG,CAAC,CAAC,EAAE,CAAC,CAAE,CAAC;MAAA;MAClBgB,GAAG,EAAEhB,GAAG,CAAC,CAAC,EAAEQ,MAAM,CAAE,CAAC;MAAA;MACrBF,MAAM,EAAEA,MAAM,IAAII,aAAc;MAChCO,SAAS,EAAER;IAAkB,CAC9B;EAAC,CACE,CAAC;AAEX,CAAC;AAED,eAAeL,SAAS","ignoreList":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { StyleSheet } from 'react-native';
|
|
4
|
+
import { useChart } from "../ChartContext.js";
|
|
5
|
+
import Animated, { useAnimatedProps, useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';
|
|
6
|
+
import AnimatedTextInput from "./AnimatedTextInput.js";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const ChartTooltipDate = ({
|
|
9
|
+
style,
|
|
10
|
+
containerStyle,
|
|
11
|
+
format
|
|
12
|
+
}) => {
|
|
13
|
+
const {
|
|
14
|
+
currentX,
|
|
15
|
+
isActive,
|
|
16
|
+
currentTimestamp,
|
|
17
|
+
width,
|
|
18
|
+
padding
|
|
19
|
+
} = useChart();
|
|
20
|
+
|
|
21
|
+
// Shared value to track the dynamic width of the tooltip
|
|
22
|
+
const tooltipWidth = useSharedValue(0);
|
|
23
|
+
const containerAnimatedStyle = useAnimatedStyle(() => {
|
|
24
|
+
// 1. Calculate the ideal centered position
|
|
25
|
+
let translateX = currentX.value - tooltipWidth.value / 2;
|
|
26
|
+
|
|
27
|
+
// 2. Clamp logic (Boundary Protection)
|
|
28
|
+
// Left Boundary: Ensure tooltip doesn't go off-screen to the left (using padding to align with line chart path)
|
|
29
|
+
if (translateX < padding) {
|
|
30
|
+
translateX = padding;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Right Boundary: Ensure tooltip doesn't go off-screen to the right (using padding to align with line chart path)
|
|
34
|
+
if (translateX + tooltipWidth.value > width - padding) {
|
|
35
|
+
translateX = width - padding - tooltipWidth.value;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
opacity: withSpring(isActive.value ? 1 : 0),
|
|
39
|
+
transform: [
|
|
40
|
+
// Calculate dynamic centering (Position X - Half of Width)
|
|
41
|
+
{
|
|
42
|
+
translateX
|
|
43
|
+
}]
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const textProps = useAnimatedProps(() => {
|
|
47
|
+
if (format) return {
|
|
48
|
+
text: format(currentTimestamp.value)
|
|
49
|
+
};
|
|
50
|
+
const date = new Date(currentTimestamp.value);
|
|
51
|
+
const day = date.getDate().toString().padStart(2, '0');
|
|
52
|
+
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
53
|
+
const year = date.getFullYear();
|
|
54
|
+
return {
|
|
55
|
+
text: `${day}/${month}/${year}`
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
59
|
+
onLayout: event => tooltipWidth.value = event.nativeEvent.layout.width,
|
|
60
|
+
style: [styles.tooltipContainer, containerAnimatedStyle, containerStyle],
|
|
61
|
+
children: /*#__PURE__*/_jsx(AnimatedTextInput, {
|
|
62
|
+
underlineColorAndroid: "transparent",
|
|
63
|
+
editable: false,
|
|
64
|
+
defaultValue: "00/00/0000",
|
|
65
|
+
style: [styles.tooltipChipText, style],
|
|
66
|
+
animatedProps: textProps
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
const styles = StyleSheet.create({
|
|
71
|
+
tooltipContainer: {
|
|
72
|
+
position: 'absolute',
|
|
73
|
+
backgroundColor: '#323546',
|
|
74
|
+
paddingHorizontal: 8,
|
|
75
|
+
paddingVertical: 4,
|
|
76
|
+
borderRadius: 8,
|
|
77
|
+
alignItems: 'center',
|
|
78
|
+
justifyContent: 'center',
|
|
79
|
+
minWidth: 80,
|
|
80
|
+
shadowColor: '#000',
|
|
81
|
+
shadowOffset: {
|
|
82
|
+
width: 0,
|
|
83
|
+
height: 2
|
|
84
|
+
},
|
|
85
|
+
shadowOpacity: 0.25,
|
|
86
|
+
shadowRadius: 3.84,
|
|
87
|
+
elevation: 5,
|
|
88
|
+
zIndex: 20,
|
|
89
|
+
bottom: 10
|
|
90
|
+
},
|
|
91
|
+
tooltipChipText: {
|
|
92
|
+
color: '#858CA2',
|
|
93
|
+
fontWeight: '600',
|
|
94
|
+
fontSize: 11,
|
|
95
|
+
padding: 0,
|
|
96
|
+
textAlign: 'center'
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
export default ChartTooltipDate;
|
|
100
|
+
//# sourceMappingURL=ChartTooltipDate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StyleSheet","useChart","Animated","useAnimatedProps","useAnimatedStyle","useSharedValue","withSpring","AnimatedTextInput","jsx","_jsx","ChartTooltipDate","style","containerStyle","format","currentX","isActive","currentTimestamp","width","padding","tooltipWidth","containerAnimatedStyle","translateX","value","opacity","transform","textProps","text","date","Date","day","getDate","toString","padStart","month","getMonth","year","getFullYear","View","onLayout","event","nativeEvent","layout","styles","tooltipContainer","children","underlineColorAndroid","editable","defaultValue","tooltipChipText","animatedProps","create","position","backgroundColor","paddingHorizontal","paddingVertical","borderRadius","alignItems","justifyContent","minWidth","shadowColor","shadowOffset","height","shadowOpacity","shadowRadius","elevation","zIndex","bottom","color","fontWeight","fontSize","textAlign"],"sourceRoot":"../../../src","sources":["components/ChartTooltipDate.tsx"],"mappings":";;AAAA,SACEA,UAAU,QAIL,cAAc;AACrB,SAASC,QAAQ,QAAQ,oBAAiB;AAC1C,OAAOC,QAAQ,IACbC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAChC,OAAOC,iBAAiB,MAAM,wBAAqB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAQpD,MAAMC,gBAAkC,GAAGA,CAAC;EAC1CC,KAAK;EACLC,cAAc;EACdC;AACF,CAAC,KAAK;EACJ,MAAM;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC,gBAAgB;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGjB,QAAQ,CAAC,CAAC;;EAE3E;EACA,MAAMkB,YAAY,GAAGd,cAAc,CAAC,CAAC,CAAC;EAEtC,MAAMe,sBAAsB,GAAGhB,gBAAgB,CAAC,MAAM;IACpD;IACA,IAAIiB,UAAU,GAAGP,QAAQ,CAACQ,KAAK,GAAGH,YAAY,CAACG,KAAK,GAAG,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AAC+B,MAAM,CAACC,gBAAgB,EAAEvB,sBAAsB,EAAER,cAAc,CAAE;IAAAgC,QAAA,eAEzEnC,IAAA,CAACF,iBAAiB;MAChBsC,qBAAqB,EAAC,aAAa;MACnCC,QAAQ,EAAE,KAAM;MAChBC,YAAY,EAAC,YAAY;MACzBpC,KAAK,EAAE,CAAC+B,MAAM,CAACM,eAAe,EAAErC,KAAK,CAAE;MACvCsC,aAAa,EAAExB;IAAU,CAC1B;EAAC,CACW,CAAC;AAEpB,CAAC;AAED,MAAMiB,MAAM,GAAG1C,UAAU,CAACkD,MAAM,CAAC;EAC/BP,gBAAgB,EAAE;IAChBQ,QAAQ,EAAE,UAAU;IACpBC,eAAe,EAAE,SAAS;IAC1BC,iBAAiB,EAAE,CAAC;IACpBC,eAAe,EAAE,CAAC;IAClBC,YAAY,EAAE,CAAC;IACfC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE,QAAQ;IACxBC,QAAQ,EAAE,EAAE;IACZC,WAAW,EAAE,MAAM;IACnBC,YAAY,EAAE;MAAE3C,KAAK,EAAE,CAAC;MAAE4C,MAAM,EAAE;IAAE,CAAC;IACrCC,aAAa,EAAE,IAAI;IACnBC,YAAY,EAAE,IAAI;IAClBC,SAAS,EAAE,CAAC;IACZC,MAAM,EAAE,EAAE;IACVC,MAAM,EAAE;EACV,CAAC;EACDlB,eAAe,EAAE;IACfmB,KAAK,EAAE,SAAS;IAChBC,UAAU,EAAE,KAAK;IACjBC,QAAQ,EAAE,EAAE;IACZnD,OAAO,EAAE,CAAC;IACVoD,SAAS,EAAE;EACb;AACF,CAAC,CAAC;AAEF,eAAe5D,gBAAgB","ignoreList":[]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { StyleSheet } from 'react-native';
|
|
4
|
+
import { useChart } from "../ChartContext.js";
|
|
5
|
+
import Animated, { useAnimatedProps, useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';
|
|
6
|
+
import AnimatedTextInput from "./AnimatedTextInput.js";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const ChartTooltipPrice = ({
|
|
9
|
+
style,
|
|
10
|
+
containerStyle,
|
|
11
|
+
format
|
|
12
|
+
}) => {
|
|
13
|
+
const {
|
|
14
|
+
currentX,
|
|
15
|
+
isActive,
|
|
16
|
+
currentValue,
|
|
17
|
+
width,
|
|
18
|
+
padding
|
|
19
|
+
} = useChart();
|
|
20
|
+
|
|
21
|
+
// Track te dynamic width of tooltip
|
|
22
|
+
const tooltipWidth = useSharedValue(0);
|
|
23
|
+
|
|
24
|
+
// Moves the tooltip left/right with the cursor
|
|
25
|
+
const containerAnimatedStyle = useAnimatedStyle(() => {
|
|
26
|
+
// 1. Calculate the ideal centered position
|
|
27
|
+
let translateX = currentX.value - tooltipWidth.value / 2;
|
|
28
|
+
|
|
29
|
+
// 2. Clamp logic (Boundary Protection)
|
|
30
|
+
// Left Boundary: Ensure tooltip doesn't go off-screen to the left (using padding to align with line chart path)
|
|
31
|
+
if (translateX < padding) {
|
|
32
|
+
translateX = padding;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Right Boundary: Ensure tooltip doesn't go off-screen to the right (using padding to align with line chart path)
|
|
36
|
+
if (translateX + tooltipWidth.value > width - padding) {
|
|
37
|
+
translateX = width - padding - tooltipWidth.value;
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
opacity: withSpring(isActive.value ? 1 : 0),
|
|
41
|
+
transform: [
|
|
42
|
+
// Calculate dynamic centering (Position X - Half of Width)
|
|
43
|
+
{
|
|
44
|
+
translateX
|
|
45
|
+
}]
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Updates the text content directly on the Native UI Thread
|
|
50
|
+
// This is a special Reanimated feature for TextInput/Text inputs.
|
|
51
|
+
const textProps = useAnimatedProps(() => {
|
|
52
|
+
if (format) return {
|
|
53
|
+
text: format(currentValue.value)
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
text: `$ ${currentValue.value.toFixed(2)}`
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
60
|
+
onLayout: event => tooltipWidth.value = event.nativeEvent.layout.width,
|
|
61
|
+
style: [styles.tooltipContainer, containerStyle, containerAnimatedStyle],
|
|
62
|
+
children: /*#__PURE__*/_jsx(AnimatedTextInput, {
|
|
63
|
+
underlineColorAndroid: "transparent",
|
|
64
|
+
editable: false // Makes it look like a Text label, not an input
|
|
65
|
+
,
|
|
66
|
+
defaultValue: "",
|
|
67
|
+
animatedProps: textProps,
|
|
68
|
+
style: [styles.tooltipChipText, style]
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
const styles = StyleSheet.create({
|
|
73
|
+
tooltipContainer: {
|
|
74
|
+
position: 'absolute',
|
|
75
|
+
backgroundColor: '#323546',
|
|
76
|
+
paddingHorizontal: 8,
|
|
77
|
+
paddingVertical: 4,
|
|
78
|
+
borderRadius: 8,
|
|
79
|
+
alignItems: 'center',
|
|
80
|
+
justifyContent: 'center',
|
|
81
|
+
minWidth: 80,
|
|
82
|
+
shadowColor: '#000',
|
|
83
|
+
shadowOffset: {
|
|
84
|
+
width: 0,
|
|
85
|
+
height: 2
|
|
86
|
+
},
|
|
87
|
+
shadowOpacity: 0.25,
|
|
88
|
+
shadowRadius: 3.84,
|
|
89
|
+
elevation: 5,
|
|
90
|
+
zIndex: 20,
|
|
91
|
+
top: 10
|
|
92
|
+
},
|
|
93
|
+
tooltipChipText: {
|
|
94
|
+
color: '#FFFFFF',
|
|
95
|
+
fontWeight: 'bold',
|
|
96
|
+
fontSize: 12,
|
|
97
|
+
padding: 0,
|
|
98
|
+
textAlign: 'center'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
export default ChartTooltipPrice;
|
|
102
|
+
//# sourceMappingURL=ChartTooltipValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["StyleSheet","useChart","Animated","useAnimatedProps","useAnimatedStyle","useSharedValue","withSpring","AnimatedTextInput","jsx","_jsx","ChartTooltipPrice","style","containerStyle","format","currentX","isActive","currentValue","width","padding","tooltipWidth","containerAnimatedStyle","translateX","value","opacity","transform","textProps","text","toFixed","View","onLayout","event","nativeEvent","layout","styles","tooltipContainer","children","underlineColorAndroid","editable","defaultValue","animatedProps","tooltipChipText","create","position","backgroundColor","paddingHorizontal","paddingVertical","borderRadius","alignItems","justifyContent","minWidth","shadowColor","shadowOffset","height","shadowOpacity","shadowRadius","elevation","zIndex","top","color","fontWeight","fontSize","textAlign"],"sourceRoot":"../../../src","sources":["components/ChartTooltipValue.tsx"],"mappings":";;AAAA,SACEA,UAAU,QAIL,cAAc;AACrB,SAASC,QAAQ,QAAQ,oBAAiB;AAC1C,OAAOC,QAAQ,IACbC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,QACL,yBAAyB;AAChC,OAAOC,iBAAiB,MAAM,wBAAqB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAQpD,MAAMC,iBAAmC,GAAGA,CAAC;EAC3CC,KAAK;EACLC,cAAc;EACdC;AACF,CAAC,KAAK;EACJ,MAAM;IAAEC,QAAQ;IAAEC,QAAQ;IAAEC,YAAY;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAGjB,QAAQ,CAAC,CAAC;;EAEvE;EACA,MAAMkB,YAAY,GAAGd,cAAc,CAAC,CAAC,CAAC;;EAEtC;EACA,MAAMe,sBAAsB,GAAGhB,gBAAgB,CAAC,MAAM;IACpD;IACA,IAAIiB,UAAU,GAAGP,QAAQ,CAACQ,KAAK,GAAGH,YAAY,CAACG,KAAK,GAAG,CAAC;;IAExD;IACA;IACA,IAAID,UAAU,GAAGH,OAAO,EAAE;MACxBG,UAAU,GAAGH,OAAO;IACtB;;IAEA;IACA,IAAIG,UAAU,GAAGF,YAAY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AC;IAClBC,YAAY,EAAE,CAAC;IACfC,UAAU,EAAE,QAAQ;IACpBC,cAAc,EAAE,QAAQ;IACxBC,QAAQ,EAAE,EAAE;IACZC,WAAW,EAAE,MAAM;IACnBC,YAAY,EAAE;MAAElC,KAAK,EAAE,CAAC;MAAEmC,MAAM,EAAE;IAAE,CAAC;IACrCC,aAAa,EAAE,IAAI;IACnBC,YAAY,EAAE,IAAI;IAClBC,SAAS,EAAE,CAAC;IACZC,MAAM,EAAE,EAAE;IACVC,GAAG,EAAE;EACP,CAAC;EACDjB,eAAe,EAAE;IACfkB,KAAK,EAAE,SAAS;IAChBC,UAAU,EAAE,MAAM;IAClBC,QAAQ,EAAE,EAAE;IACZ1C,OAAO,EAAE,CAAC;IACV2C,SAAS,EAAE;EACb;AACF,CAAC,CAAC;AAEF,eAAenD,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import ChartProvider from "./ChartContext.js";
|
|
4
|
+
import ChartArea from "./components/ChartArea.js";
|
|
5
|
+
import ChartBaseline from "./components/ChartBaseline.js";
|
|
6
|
+
import ChartCanvas from "./components/ChartCanvas.js";
|
|
7
|
+
import ChartCursor from "./components/ChartCursor.js";
|
|
8
|
+
import ChartLine from "./components/ChartLine.js";
|
|
9
|
+
import ChartTooltipDate from "./components/ChartTooltipDate.js";
|
|
10
|
+
import ChartTooltipValue from "./components/ChartTooltipValue.js";
|
|
11
|
+
export const Chart = {
|
|
12
|
+
Root: ChartProvider,
|
|
13
|
+
Canvas: ChartCanvas,
|
|
14
|
+
Line: ChartLine,
|
|
15
|
+
Area: ChartArea,
|
|
16
|
+
Cursor: ChartCursor,
|
|
17
|
+
Baseline: ChartBaseline,
|
|
18
|
+
ToolTip: {
|
|
19
|
+
Value: ChartTooltipValue,
|
|
20
|
+
Date: ChartTooltipDate
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export * from "./interfaces.js";
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ChartProvider","ChartArea","ChartBaseline","ChartCanvas","ChartCursor","ChartLine","ChartTooltipDate","ChartTooltipValue","Chart","Root","Canvas","Line","Area","Cursor","Baseline","ToolTip","Value","Date"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,aAAa,MAAM,mBAAgB;AAC1C,OAAOC,SAAS,MAAM,2BAAwB;AAC9C,OAAOC,aAAa,MAAM,+BAA4B;AACtD,OAAOC,WAAW,MAAM,6BAA0B;AAClD,OAAOC,WAAW,MAAM,6BAA0B;AAClD,OAAOC,SAAS,MAAM,2BAAwB;AAC9C,OAAOC,gBAAgB,MAAM,kCAA+B;AAC5D,OAAOC,iBAAiB,MAAM,mCAAgC;AAE9D,OAAO,MAAMC,KAAK,GAAG;EACnBC,IAAI,EAAET,aAAa;EACnBU,MAAM,EAAEP,WAAW;EACnBQ,IAAI,EAAEN,SAAS;EACfO,IAAI,EAAEX,SAAS;EACfY,MAAM,EAAET,WAAW;EACnBU,QAAQ,EAAEZ,aAAa;EACvBa,OAAO,EAAE;IACPC,KAAK,EAAET,iBAAiB;IACxBU,IAAI,EAAEX;EACR;AACF,CAAC;AAED,cAAc,iBAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["interfaces.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// --- PURE MATH (CATMULL-ROM SPLINE) ---
|
|
4
|
+
/**
|
|
5
|
+
* This function is the heart of the smoothing logic.
|
|
6
|
+
* Instead of connecting points with straight lines (which would look jagged), we use a Spline.
|
|
7
|
+
* * How it works:
|
|
8
|
+
* To calculate the curve between point P1 and P2, we also look at neighbors P0 and P3.
|
|
9
|
+
* This gives us the correct "tangent" (slope) so the curve flows smoothly.
|
|
10
|
+
* * Parameters:
|
|
11
|
+
* @param p0 - The point before the current segment
|
|
12
|
+
* @param p1 - The start of the current segment
|
|
13
|
+
* @param p2 - The end of the current segment
|
|
14
|
+
* @param p3 - The point after the current segment
|
|
15
|
+
* @param t - The progress between p1 and p2 (0.0 to 1.0)
|
|
16
|
+
*/
|
|
17
|
+
export const solveCatmullRom = (p0, p1, p2, p3, t) => {
|
|
18
|
+
const t2 = t * t;
|
|
19
|
+
const t3 = t2 * t;
|
|
20
|
+
|
|
21
|
+
// Catmull-Rom Matrix Coefficients
|
|
22
|
+
const c0 = p1;
|
|
23
|
+
const c1 = 0.5 * (p2 - p0);
|
|
24
|
+
const c2 = 0.5 * (2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3);
|
|
25
|
+
const c3 = 0.5 * (-p0 + 3.0 * p1 - 3.0 * p2 + p3);
|
|
26
|
+
|
|
27
|
+
// Interpolated result
|
|
28
|
+
return c0 + c1 * t + c2 * t2 + c3 * t3;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["solveCatmullRom","p0","p1","p2","p3","t","t2","t3","c0","c1","c2","c3"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,eAAe,GAAGA,CAC7BC,EAAU,EACVC,EAAU,EACVC,EAAU,EACVC,EAAU,EACVC,CAAS,KACN;EACH,MAAMC,EAAE,GAAGD,CAAC,GAAGA,CAAC;EAChB,MAAME,EAAE,GAAGD,EAAE,GAAGD,CAAC;;EAEjB;EACA,MAAMG,EAAE,GAAGN,EAAE;EACb,MAAMO,EAAE,GAAG,GAAG,IAAIN,EAAE,GAAGF,EAAE,CAAC;EAC1B,MAAMS,EAAE,GAAG,GAAG,IAAI,GAAG,GAAGT,EAAE,GAAG,GAAG,GAAGC,EAAE,GAAG,GAAG,GAAGC,EAAE,GAAGC,EAAE,CAAC;EACtD,MAAMO,EAAE,GAAG,GAAG,IAAI,CAACV,EAAE,GAAG,GAAG,GAAGC,EAAE,GAAG,GAAG,GAAGC,EAAE,GAAGC,EAAE,CAAC;;EAEjD;EACA,OAAOI,EAAE,GAAGC,EAAE,GAAGJ,CAAC,GAAGK,EAAE,GAAGJ,EAAE,GAAGK,EAAE,GAAGJ,EAAE;AACxC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PropsWithChildren } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
4
|
+
import type { ChartContextValue, DataPoint } from './interfaces';
|
|
5
|
+
export declare const ChartContext: React.Context<ChartContextValue>;
|
|
6
|
+
export interface ChartRootPropsInterface extends PropsWithChildren {
|
|
7
|
+
data: DataPoint[];
|
|
8
|
+
width?: number;
|
|
9
|
+
height?: number;
|
|
10
|
+
padding?: number;
|
|
11
|
+
containerStyle?: StyleProp<ViewStyle>;
|
|
12
|
+
}
|
|
13
|
+
declare const ChartProvider: React.FC<ChartRootPropsInterface>;
|
|
14
|
+
export declare const useChart: () => ChartContextValue;
|
|
15
|
+
export default ChartProvider;
|
|
16
|
+
//# sourceMappingURL=ChartContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartContext.d.ts","sourceRoot":"","sources":["../../../src/ChartContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAA6C,MAAM,OAAO,CAAC;AAElE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAsCjE,eAAO,MAAM,YAAY,kCAAoD,CAAC;AAE9E,MAAM,WAAW,uBAAwB,SAAQ,iBAAiB;IAChE,IAAI,EAAE,SAAS,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACvC;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CA2OpD,CAAC;AAEF,eAAO,MAAM,QAAQ,yBAQpB,CAAC;AAWF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TextInputProps } from 'react-native';
|
|
2
|
+
import { type AnimatedProps } from 'react-native-reanimated';
|
|
3
|
+
interface AnimatedTextInputProps extends TextInputProps {
|
|
4
|
+
text?: string;
|
|
5
|
+
}
|
|
6
|
+
declare const AnimatedTextInput: React.ComponentClass<AnimatedProps<AnimatedTextInputProps>>;
|
|
7
|
+
export default AnimatedTextInput;
|
|
8
|
+
//# sourceMappingURL=AnimatedTextInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimatedTextInput.d.ts","sourceRoot":"","sources":["../../../../src/components/AnimatedTextInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAiB,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAUvE,UAAU,sBAAuB,SAAQ,cAAc;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAOD,QAAA,MAAM,iBAAiB,EACoB,KAAK,CAAC,cAAc,CAC3D,aAAa,CAAC,sBAAsB,CAAC,CACtC,CAAC;AAEJ,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChartArea.d.ts","sourceRoot":"","sources":["../../../../src/components/ChartArea.tsx"],"names":[],"mappings":"AAGA,MAAM,WAAW,MAAM;IACrB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,QAAA,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAe/B,CAAC;AAEF,eAAe,SAAS,CAAC"}
|