0.5.1 ā€¢ Published 3 years ago

@hoker/react-native-cool-speedometer v0.5.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Cool Speedometer šŸ˜Ž

If you are tired of all those boring speedometers for react native, have a look at this one. This is different. This is cool.

Cool speedometer

Cool speedometer

āœ… Flexible

āœ… Made out of SVG

āœ… Animated

āœ… More customization than you'll use

āœ… Cool šŸ˜Ž

Install it for free:

npm i react-native-cool-speedometer

Usage

Default speedometer

<Speedometer
  value={128}
  fontFamily='squada-one'
/>

Note you'll need to configure the font by your own.

Playing with angle

Half speedometer

<Speedometer
  value={54}
  max={80}
  angle={160}
  backgroundAngle={180}
  indicatorStyle={{
    bottom: 25,
    fontSize: 60,
    color: '#555'
  }}
  fontFamily='squada-one'
  indicatorSuffix='k/h'
/>

Rotated

Changing rotation, step, the looking of the needle, and adding an optional "danger zone": Rotated speedometer

<Speedometer
  primaryArcWidth={10}
  secondaryArcWidth={4}
  value={5}
  step={1}
  max={11}
  noIndicator
  rotation={-90}
  dangerZone
  needle={{
    baseOffset: 40,
    circleRadius: 30
  }}
/>

Circular progress

Circular progress

<Speedometer
  primaryArcWidth={40}
  value={40}
  max={100}
  lineCap="round"
  noNeedle
  noLineMarks
  noNumberMarks
  angle={360}
  accentColor="orange"
  noBackground
  duration={500}
  indicatorCentered
  indicatorStyle={{
    color: 'orange'
  }}
  indicatorSuffix='%'
/>

More options

Make it as ugly as you want:

Ugly speedometer

<Speedometer
  value={73}
  max={100}
  step={5}
  angle={300}
  backgroundColor='aquamarine'
  backgroundOpacity={1}
  noProgress
  noNumberMarks
  needle={{
    color: 'tomato',
    circleColor: 'transparent',
    baseWidth: 20,
    baseOffset: 0
  }}
  marks={{
    lineCap: 'round',
    lineColor: 'tomato'
  }}
  indicatorStyle={{
    color: 'tomato'
  }}
/>

Properties

PropDefaultTypeDescription
size250numberSize of the speedometer. Note that if you change this value you will probably need to adjust the font size of the indicator and the marks.
primaryArcWidth5numberWidth of the progress bar
secondaryArcWidthprimaryArcWidth - 1numberWidth of the secondary arc. Will use the progress bar width as reference by default.
accentColor'#00e0ff'stringAccent color. Used by default for the progress bar, and the circle of the needle.
primaryArcColoraccentColorstringColor of the primary path.
secondaryArcColor'black'stringColor of the secondary path.
secondaryArcOpacity0.3numberOpacity of the secondary path.
styleobjectStyle applied to the speedometer
rotationnumberBy default, the rotation is computed with the given angle. If you want to change the rotation (like this example) have in mind that "0" is at the top of the circle.
lineCap'butt'stringLine terminations, can be butt, line, or square.
angle250numberAngle of the speedometer in degrees
value0numberActual speed
max180numberMax velocity
noIndicatorbooleanWhether to hide the indicator
backgroundColor'#000000'stringColor of the background
backgroundOpacity0.5numberOpacity of the background
step10numberTimes the max speed will be divided in to show the marks
indicatorStyle{}objectStyle applied to the indicator
noNeedlebooleanWhether to hide the needle
indicatorCenteredbooleanWhether to vertically align the indicator
noLineMarksbooleanWhether to hide the line marks
dangerZonebooleanWhether to show the red line at the right
dangerZoneAngle60numberAngle to show the danger zone (from the right)
noProgressbooleanWhether to hide the progress bar
needle{}objectNeedle options
marks{}objectMarks options
noNumberMarksbooleanWhether to hide the numbers next to the line marks
noBackgroundbooleanWhether to hide the background circle
backgroundAngle360numberAngle of the circle path used for the background. It is usually better to let this by default.
fontFamily'helvetica'stringFont to use in the indicator and the marks. You need to configure in your project the font you want to use.
indicatorSuffixstringText to append to the indicator, for example 'k/h' or '%'.
indicatorSuffixStyle{}objectStyle applied to the suffix of the indicator. (You can reduce its font size to make it more cool).
calcSizeByAnglefalsebooleanCalculate the component view by angle, usable when in case when component is square and the height calculated by backgroundAngle
calcSizeByAngleIndicatorHeightnumber0When calcSizeByAngle is used with bottom indicator, the indicator height must be added to total height

Needle Options

PropDefaultTypeDescription
baseWidth6numberWidth of the base of the needle
baseOffset18numberDistance from the center of the circle
color'white'stringColor of ne needle
circleRadius15numberRadius of the circle behind the needle
circleColoraccentColorstringColor fo the circle behind the needle

Marks Options

PropDefaultTypeDescription
lineCap'butt'stringLine terminations, can be butt, line, or square.
lineColor'white'stringColor of the lines
lineOpacity1numberOpacity of the lines
numbersRadius17stringChange this to place the numbers closer or farther of the center.
numbersFontSize19stringFont size of the number marks
roundNumbersfalsebooleanRound the numbers in case of decimal value.