11import React from 'react' ;
22import { View , Text } from 'react-native' ;
33import PropTypes from 'prop-types' ;
4- import { getStyles } from './rules' ;
4+ import { getStyles , getColorPointIndicator } from './rules' ;
55
6- const Speedometer = ( { value, totalValue, size, outerColor, innerColor, internalColor, style, innerCircleStyle, outerCircleStyle, halfCircleStyle, showText, text, textStyle, showLabels, labelStyle, showPercent, percentStyle, percentSize } ) => {
6+ const Speedometer = ( { value, totalValue, size, outerColor, innerColor, internalColor, style, innerCircleStyle, outerCircleStyle, halfCircleStyle, showText, text, textStyle, showLabels, labelStyle, showPercent, percentStyle, percentSize, showIndicator , indicatorColor } ) => {
77 const styles = getStyles ( size , percentSize ) ;
88 const degreesValue = ( value > totalValue ) ? totalValue : value ;
99 const percentValue = parseInt ( String ( ( value * 100 ) / totalValue ) . split ( '.' ) [ 0 ] ) ;
@@ -13,6 +13,10 @@ const Speedometer = ({ value, totalValue, size, outerColor, innerColor, internal
1313 transform : [ { translateX : size / 4 } , { rotate : `${ degrees } deg` } , { translateX : ( size / 4 * - 1 ) } ] ,
1414 } ;
1515
16+ const degressStyleIndicator = {
17+ transform : [ { translateX : ( 2 + size ) / 4 } , { rotate : `${ ( ( 180 / 100 ) * degreesValue ) } deg` } , { translateX : ( ( 2 + size ) / 4 * - 1 ) } ] ,
18+ } ;
19+
1620 const percentElement = ( showPercent ) ? (
1721 < Text style = { [ { backgroundColor : innerColor } , percentStyle ] } numberOfLines = { 1 } > { percentValue } %</ Text >
1822 ) : null ;
@@ -28,6 +32,12 @@ const Speedometer = ({ value, totalValue, size, outerColor, innerColor, internal
2832 </ View >
2933 ) : null ;
3034
35+ const indicadorElement = ( ( ! showText ) && ( ! showPercent ) && ( showIndicator ) && ( totalValue ) ) ? (
36+ < View style = { [ degressStyleIndicator , styles . indicator , { width : 2 + size / 2 , backgroundColor : indicatorColor } ] } >
37+ < View style = { [ styles . pointIndicator , { backgroundColor : getColorPointIndicator ( indicatorColor ) } ] } />
38+ </ View >
39+ ) : null ;
40+
3141 return (
3242 < View style = { style } >
3343 < View style = { [ styles . outerCircle , { backgroundColor : outerColor } , outerCircleStyle ] } >
@@ -37,6 +47,7 @@ const Speedometer = ({ value, totalValue, size, outerColor, innerColor, internal
3747 { textElement }
3848 </ View >
3949 </ View >
50+ { indicadorElement }
4051 { labelsElement }
4152 </ View >
4253 ) ;
@@ -64,6 +75,8 @@ Speedometer.propTypes = {
6475 outerCircleStyle : PropTypes . object ,
6576 halfCircleStyle : PropTypes . object ,
6677 percentSize : PropTypes . number ,
78+ showIndicator : PropTypes . bool ,
79+ indicatorColor : PropTypes . string ,
6780} ;
6881
6982Speedometer . defaultProps = {
@@ -80,6 +93,8 @@ Speedometer.defaultProps = {
8093 showPercent : false ,
8194 percentStyle : { } ,
8295 percentSize : 0.5 ,
96+ showIndicator : false ,
97+ indicatorColor : 'grey'
8398} ;
8499
85100export default Speedometer ;
0 commit comments