diff --git a/App.js b/App.js index c9b2746..ad12142 100644 --- a/App.js +++ b/App.js @@ -1,6 +1,6 @@ import React from 'react'; -import {View, Text} from 'react-native'; -import {BarChart, LineChart, PieChart} from './src'; +import { View, Text } from 'react-native'; +import { BarChart, LineChart, PieChart } from './src'; const App = () => { // const lineData = [ @@ -19,14 +19,14 @@ const App = () => { // ]; const data = [ - {value: 15, label: 'Jan'}, - {value: 40, label: 'Feb'}, - {value: 10, label: 'Mar'}, - {value: 30, label: 'Apr'}, + { value: 15, label: 'Jan' }, + { value: 40, label: 'Feb', showDataPoint: true, dataPointShape: 'rectangular', dataPointHeight: 12, dataPointWidth: 12, }, + { value: 10, label: 'Mar', showDataPoint: true, dataPointShape: 'rectangular', dataPointHeight: 20, dataPointWidth: 20, }, + { value: 30, label: 'Apr', showDataPoint: true }, ]; return ( - + { alignItems: 'center', }}> - + {/* { const maxValue = props.maxValue || maxItem; - const horizSections = [{value: 0}]; + const horizSections = [{ value: 0 }]; const stepHeight = props.stepHeight || containerHeight / noOfSections; const stepValue = props.stepValue || maxValue / noOfSections; const initialSpacing = @@ -260,7 +267,7 @@ export const LineChart = (props: propTypes) => { // console.log('data', data); horizSections.pop(); for (let i = 0; i <= noOfSections; i++) { - horizSections.push({value: maxValue - stepValue * i}); + horizSections.push({ value: maxValue - stepValue * i }); } useEffect(() => { @@ -373,8 +380,8 @@ export const LineChart = (props: propTypes) => { p2Array.push([ initialSpacing - dataPointsWidth2 / 2 + spacing * i, containerHeight + - 10 - - (data2[i].value * containerHeight) / maxValue, + 10 - + (data2[i].value * containerHeight) / maxValue, ]); } } @@ -472,9 +479,9 @@ export const LineChart = (props: propTypes) => { justifyContent: 'center', // alignSelf: 'center' }, - rotateLabel && {transform: [{rotate: '60deg'}]}, + rotateLabel && { transform: [{ rotate: '60deg' }] }, ]}> - + {label || ''} @@ -502,9 +509,9 @@ export const LineChart = (props: propTypes) => { left: initialSpacing + spacing * index - spacing / 2, opacity: appearingOpacity, }, - rotateLabel && {transform: [{rotate: '60deg'}]}, + rotateLabel && { transform: [{ rotate: '60deg' }] }, ]}> - + {label || ''} @@ -594,8 +601,8 @@ export const LineChart = (props: propTypes) => { {showFractionalValues ? sectionItems.value || '' : sectionItems.value - ? sectionItems.value.toString().split('.')[0] - : ''} + ? sectionItems.value.toString().split('.')[0] + : ''} )} @@ -614,7 +621,7 @@ export const LineChart = (props: propTypes) => { ) : hideRules ? null : ( @@ -646,6 +653,86 @@ export const LineChart = (props: propTypes) => { ); }; + const renderSpecificDataPoints = (dataForRender) => { + return dataForRender.map((item: itemType, index: number) => { + if (item.showDataPoint) { + if (item.dataPointShape === 'rectangular') { + return ( + + + {item.dataPointText && ( + + {item.dataPointText} + + )} + + ); + } + else { + return ( + + + {item.dataPointText && ( + + {item.dataPointText} + + )} + + ) + } + } + return null; + }) + } + const renderDataPoints = ( dataForRender, dataPointsShape, @@ -785,7 +872,7 @@ export const LineChart = (props: propTypes) => { strokeWidth={currentLineThickness || thickness} /> )} - {!hideDataPoints1 && + {!hideDataPoints1 ? renderDataPoints( data, dataPointsShape1, @@ -795,8 +882,11 @@ export const LineChart = (props: propTypes) => { dataPointsRadius1, textColor1, textFontSize1, - )} - {!hideDataPoints2 && + ) + : + renderSpecificDataPoints(data) + } + {!hideDataPoints2 ? renderDataPoints( data2, dataPointsShape2, @@ -806,7 +896,10 @@ export const LineChart = (props: propTypes) => { dataPointsRadius2, textColor2, textFontSize2, - )} + ) + : + renderSpecificDataPoints(data2) + } ); @@ -868,7 +961,7 @@ export const LineChart = (props: propTypes) => { strokeWidth={currentLineThickness || thickness} /> )} - {!hideDataPoints1 && + {!hideDataPoints1 ? renderDataPoints( data, dataPointsShape1, @@ -878,8 +971,9 @@ export const LineChart = (props: propTypes) => { dataPointsRadius1, textColor1, textFontSize1, - )} - {!hideDataPoints2 && + ) : + renderSpecificDataPoints(data)} + {!hideDataPoints2 ? renderDataPoints( data2, dataPointsShape2, @@ -889,14 +983,15 @@ export const LineChart = (props: propTypes) => { dataPointsRadius2, textColor2, textFontSize2, - )} + ) : + renderSpecificDataPoints(data2)} ); }; return ( - + {props.hideAxesAndRules !== true && renderHorizSections()} {/* {sectionsOverlay()} */} { {isAnimated ? renderAnimatedLine( - points, - animatedWidth, - thickness1, - color1, - fillPoints, - startFillColor1, - endFillColor1, - startOpacity1, - endOpacity1, - ) + points, + animatedWidth, + thickness1, + color1, + fillPoints, + startFillColor1, + endFillColor1, + startOpacity1, + endOpacity1, + ) : renderLine( - points, - thickness1, - color1, - fillPoints, - startFillColor1, - endFillColor1, - startOpacity1, - endOpacity1, - )} + points, + thickness1, + color1, + fillPoints, + startFillColor1, + endFillColor1, + startOpacity1, + endOpacity1, + )} {points2 ? isAnimated ? renderAnimatedLine( - points2, - animatedWidth2, - thickness2, - color2, - fillPoints2, - startFillColor2, - endFillColor2, - startOpacity2, - endOpacity2, - ) + points2, + animatedWidth2, + thickness2, + color2, + fillPoints2, + startFillColor2, + endFillColor2, + startOpacity2, + endOpacity2, + ) : renderLine( - points2, - thickness2, - color2, - fillPoints2, - startFillColor2, - endFillColor2, - startOpacity2, - endOpacity2, - ) + points2, + thickness2, + color2, + fillPoints2, + startFillColor2, + endFillColor2, + startOpacity2, + endOpacity2, + ) : null} {data.map((item: itemType, index: number) => { // console.log('item', item)