Skip to content

Commit bf461a9

Browse files
committed
add readme and scrollable props plus fixes
1 parent e900be4 commit bf461a9

File tree

7 files changed

+67
-10
lines changed

7 files changed

+67
-10
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# react-native-slide-charts
2+
3+
[![Version](https://img.shields.io/npm/v/react-native-slide-charts.svg)](https://www.npmjs.com/package/react-native-slide-charts)
4+
[![NPM](https://img.shields.io/npm/dm/react-native-slide-charts.svg)](https://www.npmjs.com/package/react-native-slide-charts)
5+
6+
`react-native-slide-charts` uses [`react-native-svg`](https://github.com/react-native-community/react-native-svg), [`d3`](https://github.com/d3/d3), and [`react-native-gesture-handler`](https://github.com/software-mansion/react-native-gesture-handler) to create interactive charts.
7+
8+
## [Check out the demo in expo](https://snack.expo.io/@nhannah/react-native-slide-charts)
9+
10+
## Features
11+
12+
### Bar Chart
13+
14+
### Area Chart
15+
16+
TODO: Gifs
17+
18+
---
19+
20+
## Installation
21+
22+
---
23+
24+
```console
25+
$ npm install react-native-slide-charts --save
26+
```
27+
28+
or
29+
30+
```console
31+
$ yarn add react-native-slide-charts
32+
```
33+
34+
### Peer Dependencies
35+
36+
`react-native-slide-charts` depends on three peer dependencies with native modules that must be installed alongside it. Follow the installation instructions for both iOS and Android for all three packages.
37+
38+
| Package | Minimum Version | Maximum Version |
39+
| ----------------------------------------------------------------------------------------------------- | --------------- | --------------- |
40+
| [`react-native-svg`](https://github.com/react-native-community/react-native-svg) | 7.0.0 | 9.x |
41+
| [`react-native-gesture-handler`](https://github.com/software-mansion/react-native-gesture-handler) | 1.1.0 | 1.x |
42+
| [`react-native-haptic-feedback`](https://github.com/milk-and-cookies-io/react-native-haptic-feedback) | 1.8.0 | 1.x |
43+
44+
#### NOTICE:
45+
46+
Make sure the version of the native module packages chosen works with the `react-native` version of the project. Manually linking the projects may be required depending on the version and platform.
47+
48+
---
49+
50+
## Usage
51+
52+
---

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-slide-charts",
33
"version": "0.0.6",
4-
"description": "React Native slide charts uses d3 and react-native-gesture-handler to create interactive charts.",
4+
"description": "React Native Slide Charts uses react-native-svg, d3, and react-native-gesture-handler to create interactive charts.",
55
"homepage": "https://github.com/connectedcars/react-native-slide-charts",
66
"repository": {
77
"type": "git",

src/lib/SlideAreaChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class SlideAreaChart extends Component<SlideAreaChartComponentProps, State> {
356356
}
357357

358358
renderTouchable() {
359-
const { onPress, axisWidth, shouldCancelWhenOutside, paddingLeft, paddingRight } = this.props
359+
const { onPress, axisWidth, shouldCancelWhenOutside, paddingLeft, paddingRight, scrollable } = this.props
360360
const { x } = this.state
361361

362362
/**
@@ -394,7 +394,7 @@ class SlideAreaChart extends Component<SlideAreaChartComponentProps, State> {
394394
shouldCancelWhenOutside={shouldCancelWhenOutside}
395395
minPointers={0}
396396
activeOffsetX={[-3, 3]}
397-
failOffsetY={[-6, 6]}
397+
failOffsetY={scrollable ? [-6, 6] : undefined}
398398
onGestureEvent={Animated.event([{ nativeEvent: { x } }], { useNativeDriver: true })}
399399

400400
/**

src/lib/SlideBarChart.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class SlideBarChart extends Component<SlideBarChartComponentProps, State> {
356356
}
357357

358358
renderTouchable() {
359-
const { onPress, axisWidth, shouldCancelWhenOutside, paddingLeft, paddingRight } = this.props
359+
const { onPress, axisWidth, shouldCancelWhenOutside, paddingLeft, paddingRight, scrollable } = this.props
360360
const { x } = this.state
361361

362362
/**
@@ -390,7 +390,7 @@ class SlideBarChart extends Component<SlideBarChartComponentProps, State> {
390390
shouldCancelWhenOutside={shouldCancelWhenOutside}
391391
minPointers={0}
392392
activeOffsetX={[-3, 3]}
393-
failOffsetY={[-6, 6]}
393+
failOffsetY={scrollable ? [-6, 6] : undefined}
394394
onGestureEvent={Animated.event([{ nativeEvent: { x } }], { useNativeDriver: true })}
395395

396396
/**

src/lib/components/chartComponents/axis/XAxis.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class XAxis extends Component<XAxisComponentProps> {
6666
axisLabelAlignment, scaleY, yRange, labelTopPadding, axisLabelStyle, height, labelBottomOffset,
6767
axisLabel, data, width, scaleX, axisMarkerLabels, axisWidth, paddingLeft, paddingRight
6868
} = this.props
69-
const stopX = data.length > 0 ? scaleX(data[data.length - 1].x) : width - paddingRight
69+
const stopX = data.length > 1 ? scaleX(data[data.length - 1].x) : width - paddingRight
7070

7171
// Align label at start, end, or center of graph
7272
const labelAnchor = axisLabelAlignment === XAxisLabelAlignment.right ? 'end' :

src/lib/components/toolTip/ToolTip.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ class ToolTip extends Component<ToolTipComponentProps, State> {
5050
) => {
5151
this.realPercentage = realPercentage
5252
this.toolTipPosition = { x, y, cursorMarkerHeight, standoff }
53-
const { borderRadius } = this.props
53+
const { borderRadius, lockTriangleCenter } = this.props
5454
const width = this.props.width ?? this.state.width
55-
const labelPosition = x - (width / 10) - borderRadius - ((width - (width / 5) - (2 * borderRadius)) * realPercentage)
55+
const labelPosition = lockTriangleCenter ?
56+
x - (width / 2) :
57+
x - (width / 10) - borderRadius - ((width - (width / 5) - (2 * borderRadius)) * realPercentage)
5658
if (this.toolTip.current != null) {
5759
this.toolTip.current.setNativeProps({
5860
top: y - cursorMarkerHeight / 2 - (this.state.height + width / 5) - standoff,
@@ -71,9 +73,11 @@ class ToolTip extends Component<ToolTipComponentProps, State> {
7173

7274
// Set toolTip X position only
7375
setNativeToolTipPositionPropX = (x: number, realPercentage: number) => {
74-
const { borderRadius } = this.props
76+
const { borderRadius, lockTriangleCenter } = this.props
7577
const width = this.props.width ?? this.state.width
76-
const labelPosition = x - (width / 10) - borderRadius - ((width - (width / 5) - (2 * borderRadius)) * realPercentage)
78+
const labelPosition = lockTriangleCenter ?
79+
x - (width / 2) :
80+
x - (width / 10) - borderRadius - ((width - (width / 5) - (2 * borderRadius)) * realPercentage)
7781
if (this.toolTip.current != null) {
7882
this.toolTip.current.setNativeProps({ left: labelPosition })
7983
}

src/lib/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type SharedChartComponentProps = {
2525
showIndicatorCallback?: (opacity: number) => void
2626
onPress?: () => void
2727
style?: StyleProp<ViewStyle>
28+
scrollable?: boolean
2829
}
2930

3031
type SharedChartProps = SharedChartComponentProps & {

0 commit comments

Comments
 (0)