Skip to content

Commit 3188f34

Browse files
committed
feat: add yRange
1 parent a795dd5 commit 3188f34

File tree

5 files changed

+13
-10
lines changed

5 files changed

+13
-10
lines changed

Example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ PODS:
302302
- React
303303
- RNReactNativeHapticFeedback (1.10.0):
304304
- React
305-
- RNReanimated (2.0.0-alpha.6):
305+
- RNReanimated (2.0.0-alpha.7):
306306
- DoubleConversion
307307
- FBLazyVector
308308
- FBReactNativeSpec
@@ -510,7 +510,7 @@ SPEC CHECKSUMS:
510510
ReactCommon: a0a1edbebcac5e91338371b72ffc66aa822792ce
511511
RNGestureHandler: b6b359bb800ae399a9c8b27032bdbf7c18f08a08
512512
RNReactNativeHapticFeedback: 22c5ecf474428766c6b148f96f2ff6155cd7225e
513-
RNReanimated: 6bd3347e383cee6eb879a1a7d6c748934a015a05
513+
RNReanimated: c40c29429b22a1564e505b789132cfcef456c6bd
514514
RNSVG: ce9d996113475209013317e48b05c21ee988d42e
515515
Yoga: 7740b94929bbacbddda59bf115b5317e9a161598
516516
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react-native": "0.63.2",
2020
"react-native-gesture-handler": "^1.7.0",
2121
"react-native-haptic-feedback": "^1.10.0",
22-
"react-native-reanimated": "^2.0.0-alpha.6",
22+
"react-native-reanimated": "^2.0.0-alpha.7",
2323
"react-native-redash": "^14.2.4",
2424
"react-native-shadow-stack": "^0.0.5",
2525
"react-native-svg": "^12.1.0",

Example/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5560,10 +5560,10 @@ react-native-haptic-feedback@^1.10.0:
55605560
resolved "https://registry.yarnpkg.com/react-native-haptic-feedback/-/react-native-haptic-feedback-1.10.0.tgz#869d2e7179a17226becf43173c6f6495038524a0"
55615561
integrity sha512-2aEXYTLrQq2N3phaGJ23V0x6qsIz4j1vhTck9A7geTfW7J54mOfk1Pr4Y1WEMMKptFA9p78kZHBb31IIE+g37w==
55625562

5563-
react-native-reanimated@^2.0.0-alpha.6:
5564-
version "2.0.0-alpha.6"
5565-
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.0.0-alpha.6.tgz#d3b55127e8202a12b9073c97086dfe85283c9e08"
5566-
integrity sha512-VlclQ4dlHM7e8F8HBgwqUQTfCNK3k+h13aL/9k/JMqx4CrUAWe2RYdsRWxurV3YrK0RYdjpM4AvmxqGvJKWuWA==
5563+
react-native-reanimated@^2.0.0-alpha.7:
5564+
version "2.0.0-alpha.7"
5565+
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.0.0-alpha.7.tgz#20b9852df6aeab9fc0efb938527bf47ae954370a"
5566+
integrity sha512-dAOkt087c3uSm9oTe8cDIKHbZ+D6X951OG/SWzGAOWaR9GH/JW5N++YjmxQX2IK1vFlYNCMfBnxjTuWT6QHfmQ==
55675567
dependencies:
55685568
"@babel/plugin-transform-object-assign" "^7.10.4"
55695569
fbjs "^1.0.0"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ It's important to have it as a separated component because under this component
105105
- The `complex` strategy uses approach explained [here](https://medium.com/@francoisromain/smooth-a-svg-path-with-cubic-bezier-curves-e37b49d46c74) using cubic splines. It's parametrized by `smoothingFactor`.
106106
- The `simple` strategy is a bit simplified `complex` strategy using quadratic splines. It's parametrized by `smoothingFactor`.
107107
- `smoothingFactor`. Is a value from `0` to `1` defining how smooth a presentation should be. `0` means no smoothing, and it's the default. `smoothingFactor` has an impact if `smoothingStrategy` is `simple` or `complex`.
108+
- `yRange`. 2-elements array with numbers describing minY and maxY in this order. When not applied, charts are automatically adjusted vertically. However, when data are monotonical, they might present incorrectly without bounding due to numerical issues.
108109

109110
### `ChartPath`
110111
This component is used for showing the path itself.

src/charts/linear/ChartPath.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,18 @@ function combineConfigs(a, b) {
5555
return r;
5656
}
5757

58-
const parse = data => {
58+
const parse = (data, yRange) => {
5959
const { greatestY, smallestY } = findYExtremes(data);
60+
const minY = yRange ? yRange[0] : smallestY.y;
61+
const maxY = yRange ? yRange[1] : greatestY.y;
6062
const smallestX = data[0];
6163
const greatestX = data[data.length - 1];
6264
return [
6365
data.map(({ x, y }) => ({
6466
originalX: x,
6567
originalY: y,
6668
x: (x - smallestX.x) / (greatestX.x - smallestX.x),
67-
y: 1 - (y - smallestY.y) / (greatestY.y - smallestY.y),
69+
y: 1 - (y - minY) / (maxY - minY),
6870
})),
6971
{
7072
greatestX,
@@ -202,7 +204,7 @@ export default function ChartPathProvider({
202204
if (!data || !data.points || data.points.length === 0) {
203205
return;
204206
}
205-
const [parsedData] = parse(data.points);
207+
const [parsedData] = parse(data.points, data.yRange);
206208
const [parsedoriginalData, newExtremes] = parse(
207209
data.nativePoints || data.points
208210
);

0 commit comments

Comments
 (0)