mirror of
https://github.com/status-im/react-native-gifted-charts.git
synced 2025-02-23 09:08:13 +00:00
Merge pull request #215 from Abhinandan-Kushwaha/abhi
fixed label position issue with pointers in Line/Area charts
This commit is contained in:
commit
09474b1497
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-gifted-charts",
|
"name": "react-native-gifted-charts",
|
||||||
"version": "1.2.30",
|
"version": "1.2.31",
|
||||||
"description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
||||||
"main": "src/index.tsx",
|
"main": "src/index.tsx",
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -371,6 +371,7 @@ type Pointer = {
|
|||||||
|
|
||||||
export const LineChart = (props: propTypes) => {
|
export const LineChart = (props: propTypes) => {
|
||||||
const scrollRef = useRef();
|
const scrollRef = useRef();
|
||||||
|
const [scrollX, setScrollX] = useState(0);
|
||||||
const [pointerIndex, setPointerIndex] = useState(-1);
|
const [pointerIndex, setPointerIndex] = useState(-1);
|
||||||
const [pointerX, setPointerX] = useState(0);
|
const [pointerX, setPointerX] = useState(0);
|
||||||
const [pointerY, setPointerY] = useState(0);
|
const [pointerY, setPointerY] = useState(0);
|
||||||
@ -2557,6 +2558,11 @@ export const LineChart = (props: propTypes) => {
|
|||||||
if (autoAdjustPointerLabelPosition) {
|
if (autoAdjustPointerLabelPosition) {
|
||||||
if (pointerX < pointerLabelWidth / 2) {
|
if (pointerX < pointerLabelWidth / 2) {
|
||||||
left = 7;
|
left = 7;
|
||||||
|
} else if (
|
||||||
|
activatePointersOnLongPress &&
|
||||||
|
pointerX - scrollX < pointerLabelWidth / 2 - 10
|
||||||
|
) {
|
||||||
|
left = 7;
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
!activatePointersOnLongPress &&
|
!activatePointersOnLongPress &&
|
||||||
@ -2568,7 +2574,10 @@ export const LineChart = (props: propTypes) => {
|
|||||||
left = -pointerLabelWidth - 4;
|
left = -pointerLabelWidth - 4;
|
||||||
} else if (
|
} else if (
|
||||||
activatePointersOnLongPress &&
|
activatePointersOnLongPress &&
|
||||||
pointerX > totalWidth - yAxisLabelWidth - pointerLabelWidth / 2
|
pointerX - scrollX >
|
||||||
|
(props.width + 10 ||
|
||||||
|
Dimensions.get('window').width - yAxisLabelWidth - 15) -
|
||||||
|
pointerLabelWidth / 2
|
||||||
) {
|
) {
|
||||||
left = -pointerLabelWidth - 4;
|
left = -pointerLabelWidth - 4;
|
||||||
} else {
|
} else {
|
||||||
@ -3293,6 +3302,15 @@ export const LineChart = (props: propTypes) => {
|
|||||||
scrollRef.current.scrollToEnd({animated: scrollAnimation});
|
scrollRef.current.scrollToEnd({animated: scrollAnimation});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onScroll={ev => {
|
||||||
|
if (
|
||||||
|
pointerConfig &&
|
||||||
|
pointerConfig.activatePointersOnLongPress &&
|
||||||
|
pointerConfig.autoAdjustPointerLabelPosition
|
||||||
|
) {
|
||||||
|
setScrollX(ev.nativeEvent.contentOffset.x);
|
||||||
|
}
|
||||||
|
}}
|
||||||
showsHorizontalScrollIndicator={showScrollIndicator}
|
showsHorizontalScrollIndicator={showScrollIndicator}
|
||||||
indicatorStyle={props.indicatorColor}
|
indicatorStyle={props.indicatorColor}
|
||||||
style={[
|
style={[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user