import React, { ComponentClass } from 'react'; import { StyleSheet, Animated, View, } from 'react-native'; import { AreaChart, ChartProps } from 'react-native-svg-charts'; import * as shape from 'd3-shape'; import { DefaultChartProps } from './types'; import styled from '../components/styled-components'; const AnimatedAreaChart = Animated.createAnimatedComponent( AreaChart as ComponentClass>, ); const DefaultAreaChart = (props: DefaultChartProps) => { const { width, style, data, backgroundColor, chartColor, children, handlePos, curve = shape.curveNatural, contentInset = { top: 10, bottom: 0 }, ...chartProps } = props; const pos = handlePos[1].interpolate({ inputRange: [0, 100], outputRange: [0, width], // extrapolate: 'clamp', }); const prevValue = handlePos[0].interpolate({ inputRange: [0, 100], outputRange: [0, -width], // extrapolate: 'clamp', }); const prevPos = handlePos[0].interpolate({ inputRange: [0, 100], outputRange: [0, width], // extrapolate: 'clamp', }); const diffValue = Animated.add(pos, prevValue); return ( {children} ); }; const DefaultStyledAreaChart = styled(DefaultAreaChart).attrs((props) => ({ chartColor: props.chartColor || (props.theme.rheostat?.themeColor) || 'palevioletred', backgroundColor: props.backgroundColor || (props.theme.rheostat?.grey) || '#d8d8d8', }))` height: 100px; `; export default DefaultStyledAreaChart;