mirror of
https://github.com/status-im/react-native-gifted-charts.git
synced 2025-02-23 17:18:24 +00:00
added the prop customDataPoint to render a custom component as the data points
This commit is contained in:
parent
ad2a132666
commit
62835a4010
30
App.js
30
App.js
@ -51,7 +51,7 @@ const App = () => {
|
|||||||
height={300}
|
height={300}
|
||||||
maxValue={360}
|
maxValue={360}
|
||||||
showLine
|
showLine
|
||||||
initialSpacing={20}
|
initialSpacing={30}
|
||||||
// showVerticalLines
|
// showVerticalLines
|
||||||
lineConfig={{
|
lineConfig={{
|
||||||
// isAnimated: true,
|
// isAnimated: true,
|
||||||
@ -135,12 +135,26 @@ const App = () => {
|
|||||||
data={data}
|
data={data}
|
||||||
// data2={lineData1}
|
// data2={lineData1}
|
||||||
areaChart
|
areaChart
|
||||||
initialSpacing={10}
|
initialSpacing={20}
|
||||||
|
customDataPoint={() => {
|
||||||
|
return (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
height: 10,
|
||||||
|
width: 10,
|
||||||
|
backgroundColor: 'red',
|
||||||
|
borderWidth: 2,
|
||||||
|
borderColor: 'blue',
|
||||||
|
borderRadius: 5,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}}
|
||||||
onPress={(item, index) => {
|
onPress={(item, index) => {
|
||||||
console.log('index-->', index);
|
console.log('index-->', index);
|
||||||
setData(data => {
|
setData(data => {
|
||||||
item.dataPointColor = 'green';
|
item.dataPointColor = 'green';
|
||||||
item.dataPointRadius = 6;
|
// item.dataPointRadius = 5;
|
||||||
item.dataPointText = item.value;
|
item.dataPointText = item.value;
|
||||||
// item.dataPointShape = 'rectangular';
|
// item.dataPointShape = 'rectangular';
|
||||||
// item.dataPointWidth = 10;
|
// item.dataPointWidth = 10;
|
||||||
@ -160,9 +174,9 @@ const App = () => {
|
|||||||
textFontSize={18}
|
textFontSize={18}
|
||||||
textColor={'green'}
|
textColor={'green'}
|
||||||
stripWidth={1}
|
stripWidth={1}
|
||||||
stripHeight={200}
|
|
||||||
// stripHeight={200}
|
// stripHeight={200}
|
||||||
stripOpacity={0.4}
|
// stripHeight={200}
|
||||||
|
stripOpacity={1}
|
||||||
curved
|
curved
|
||||||
isAnimated
|
isAnimated
|
||||||
animationDuration={2000}
|
animationDuration={2000}
|
||||||
@ -172,9 +186,9 @@ const App = () => {
|
|||||||
color={'rgb(78, 0, 142)'}
|
color={'rgb(78, 0, 142)'}
|
||||||
yAxisColor={'rgb(78, 0, 142)'}
|
yAxisColor={'rgb(78, 0, 142)'}
|
||||||
xAxisColor={'rgb(78, 0, 142)'}
|
xAxisColor={'rgb(78, 0, 142)'}
|
||||||
dataPointsColor={'rgb(78, 0, 142)'}
|
// dataPointsColor={'yellow'}
|
||||||
dataPointsWidth={8}
|
dataPointsWidth={22}
|
||||||
dataPointsHeight={8}
|
dataPointsHeight={22}
|
||||||
xAxisThickness={3}
|
xAxisThickness={3}
|
||||||
yAxisThickness={3}
|
yAxisThickness={3}
|
||||||
dataPointsRadius={4}
|
dataPointsRadius={4}
|
||||||
|
@ -174,6 +174,7 @@ type referenceConfigType = {
|
|||||||
| textFontSize | number | Font size of the dataPointText | \_ |
|
| textFontSize | number | Font size of the dataPointText | \_ |
|
||||||
| textShiftX | number | To shift the dataPointText text horizontally | 0 |
|
| textShiftX | number | To shift the dataPointText text horizontally | 0 |
|
||||||
| textShiftY | number | To shift the dataPointText text vertically | 0 |
|
| textShiftY | number | To shift the dataPointText text vertically | 0 |
|
||||||
|
| customDataPoint | Function | A callback function to render a custom component as the data points | \_ |
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "react-native-gifted-charts",
|
"name": "react-native-gifted-charts",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"description": "The most complete library for Bar, Line, Area, Pie and Donut charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
"description": "The most complete library for Bar, Line, Area, Pie and Donut charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
||||||
"main": "src/index.tsx",
|
"main": "src/index.tsx",
|
||||||
"files": [
|
"files": [
|
||||||
|
@ -138,6 +138,7 @@ type propTypes = {
|
|||||||
dataPointsRadius3?: number;
|
dataPointsRadius3?: number;
|
||||||
dataPointsColor3?: string;
|
dataPointsColor3?: string;
|
||||||
dataPointsShape3?: string;
|
dataPointsShape3?: string;
|
||||||
|
customDataPoint?: Function;
|
||||||
|
|
||||||
startFillColor?: string;
|
startFillColor?: string;
|
||||||
endFillColor?: string;
|
endFillColor?: string;
|
||||||
@ -1182,24 +1183,18 @@ export const LineChart = (props: propTypes) => {
|
|||||||
)}
|
)}
|
||||||
{index === selectedIndex && showStripOnPress ? (
|
{index === selectedIndex && showStripOnPress ? (
|
||||||
<Rect
|
<Rect
|
||||||
x={
|
x={initialSpacing + (spacing * index - dataPointsWidth / 2)}
|
||||||
initialSpacing / 2 +
|
|
||||||
(spacing * index - stripWidth) +
|
|
||||||
stripWidth / 2 +
|
|
||||||
1
|
|
||||||
}
|
|
||||||
y={
|
y={
|
||||||
stripHeight
|
stripHeight
|
||||||
? containerHeight - stripHeight + 8
|
? containerHeight - stripHeight + 8
|
||||||
: containerHeight -
|
: containerHeight -
|
||||||
dataPointsHeight / 2 +
|
dataPointsHeight / 2 +
|
||||||
15 -
|
20 -
|
||||||
(item.value * containerHeight) / maxValue
|
(item.value * containerHeight) / maxValue
|
||||||
}
|
}
|
||||||
width={stripWidth}
|
width={stripWidth}
|
||||||
height={
|
height={
|
||||||
stripHeight ||
|
stripHeight || containerHeight - dataPointsHeight / 2 + 20
|
||||||
containerHeight - dataPointsHeight / 2 + 10 - 0
|
|
||||||
}
|
}
|
||||||
opacity={stripOpacity}
|
opacity={stripOpacity}
|
||||||
fill={stripColor}
|
fill={stripColor}
|
||||||
@ -1207,8 +1202,25 @@ export const LineChart = (props: propTypes) => {
|
|||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
) : null}
|
) : null}
|
||||||
|
{props.customDataPoint ? (
|
||||||
|
<View
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
height: dataPointsHeight,
|
||||||
|
width: dataPointsWidth,
|
||||||
|
// backgroundColor: 'orange',
|
||||||
|
top:
|
||||||
|
containerHeight - (item.value * containerHeight) / maxValue,
|
||||||
|
left: initialSpacing - dataPointsWidth + spacing * index,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
}}>
|
||||||
|
{props.customDataPoint()}
|
||||||
|
</View>
|
||||||
|
) : null}
|
||||||
{dataPointsShape === 'rectangular' ? (
|
{dataPointsShape === 'rectangular' ? (
|
||||||
<Fragment key={index}>
|
<Fragment key={index}>
|
||||||
|
{props.customDataPoint ? null : (
|
||||||
<Rect
|
<Rect
|
||||||
x={initialSpacing - dataPointsWidth + spacing * index}
|
x={initialSpacing - dataPointsWidth + spacing * index}
|
||||||
y={
|
y={
|
||||||
@ -1227,6 +1239,7 @@ export const LineChart = (props: propTypes) => {
|
|||||||
: dataPointsColor
|
: dataPointsColor
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
{text ? (
|
{text ? (
|
||||||
!showTextOnPress || index === selectedIndex ? (
|
!showTextOnPress || index === selectedIndex ? (
|
||||||
<CanvasText
|
<CanvasText
|
||||||
@ -1255,6 +1268,7 @@ export const LineChart = (props: propTypes) => {
|
|||||||
</Fragment>
|
</Fragment>
|
||||||
) : (
|
) : (
|
||||||
<Fragment key={index}>
|
<Fragment key={index}>
|
||||||
|
{props.customDataPoint ? null : (
|
||||||
<Circle
|
<Circle
|
||||||
cx={initialSpacing - dataPointsWidth / 2 + spacing * index}
|
cx={initialSpacing - dataPointsWidth / 2 + spacing * index}
|
||||||
cy={
|
cy={
|
||||||
@ -1271,6 +1285,7 @@ export const LineChart = (props: propTypes) => {
|
|||||||
: dataPointsColor
|
: dataPointsColor
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
{text ? (
|
{text ? (
|
||||||
!showTextOnPress || index === selectedIndex ? (
|
!showTextOnPress || index === selectedIndex ? (
|
||||||
<CanvasText
|
<CanvasText
|
||||||
|
Loading…
x
Reference in New Issue
Block a user