diff --git a/App.js b/App.js index b59393f..70cc1b8 100644 --- a/App.js +++ b/App.js @@ -946,39 +946,86 @@ const App = () => { {value: 0.7, label: '6'}, ]; - const [myData, setMyData] = useState([]); - - useEffect(() => { - setTimeout(() => setMyData(barDatas), 500); - }, []); + const llData = [ + {value: 70}, + {value: 36}, + {value: 50}, + {value: 40}, + {value: 18}, + {value: 38}, + ]; + const llData2 = [ + {value: 50}, + {value: 10}, + {value: 45}, + {value: 30}, + {value: 45}, + {value: 18}, + ]; return ( { + return ( + + {2018} + {items[0].value} + {2019} + {items[1].value} + + ); + }, + }} /> + {/* ; }; ``` @@ -311,6 +312,12 @@ The above properties can be understood with this labelled diagram- **Note** If you are using the `pointerConfig` prop, the scroll will be disabled automatically. This is because, it's difficult to achive both scrolling line and scrolling pointer simultaneously. So if you want to retain the scroll behaviour even after passing the `pointerConfig` prop, then set the property `activatePointersOnLongPress` to true inside the pointerConfig object. This will make the pointers visible only after long press. So, before the long press, user can can scroll the line. Once long pressed, scrolling will be disabled until the release of the long press. The duration after which a press event will be considered as long press can be controlled using the `activatePointersDelay` property inside the pointerConfig object. The default value of activatePointersDelay is 150. +The strokeDashArray property lets us render a dashed/dotted strip along the pointer. + +#### pointerLabelComponent + +pointerLabelComponent is a function that returns the component to be rendered as a Label. It takes a single parameter - an array of items. So, if there are multiple data arrays, the parameter items will have the data item corresponding to each data array. + ### onPress and strip related props diff --git a/package.json b/package.json index eb8abb3..54b71c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-gifted-charts", - "version": "1.2.8", + "version": "1.2.9", "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", "files": [ diff --git a/src/LineChart/index.tsx b/src/LineChart/index.tsx index 67b49db..8aa1fc0 100644 --- a/src/LineChart/index.tsx +++ b/src/LineChart/index.tsx @@ -22,6 +22,7 @@ import Svg, { Circle, Rect, Text as CanvasText, + Line, } from 'react-native-svg'; import {svgPath, bezierCommand} from '../utils'; import Rule from '../Components/lineSvg'; @@ -347,6 +348,7 @@ type Pointer = { hidePointer3?: boolean; hidePointer4?: boolean; hidePointer5?: boolean; + strokeDashArray?: Array; }; export const LineChart = (props: propTypes) => { @@ -2399,24 +2401,77 @@ export const LineChart = (props: propTypes) => { }} /> )} + + ); + }; + + const renderStripAndLabel = () => { + let pointerItemLocal, pointerYLocal; + + pointerItemLocal = [pointerItem]; + let arr = [pointerY]; + if (pointerY2 !== 0) { + arr.push(pointerY2); + pointerItemLocal.push(pointerItem2); + } + if (pointerY3 !== 0) { + arr.push(pointerY3); + pointerItemLocal.push(pointerItem3); + } + if (pointerY4 !== 0) { + arr.push(pointerY4); + pointerItemLocal.push(pointerItem4); + } + if (pointerY5 !== 0) { + arr.push(pointerY5); + pointerItemLocal.push(pointerItem5); + } + pointerYLocal = Math.min(...arr); + + return ( + {showPointerStrip && ( + }}> + + + + )} {pointerLabelComponent && ( @@ -2783,7 +2838,6 @@ export const LineChart = (props: propTypes) => { endOpacity, strokeDashArray, )} - {pointerX ? renderPointer(lineNumber) : null} ); }; @@ -2985,7 +3039,6 @@ export const LineChart = (props: propTypes) => { endOpacity, strokeDashArray, )} - {pointerX ? renderPointer(lineNumber) : null} ); }; @@ -3220,6 +3273,24 @@ export const LineChart = (props: propTypes) => { strokeDashArray5, ) : null} + {pointerX ? ( + + {renderPointer(1)} + {points2 ? renderPointer(2) : null} + {points3 ? renderPointer(3) : null} + {points4 ? renderPointer(4) : null} + {points5 ? renderPointer(5) : null} + {renderStripAndLabel()} + + ) : null} {data.map((item: itemType, index: number) => { // console.log('item', item) return (