1.1.5 • Published 4 years ago

react-segmented-round-display v1.1.5

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

react-segmented-round-display

Version NPM STARS

react-segmented-round-display provides a simple ARC component, drawn with SVG, it can have one or more segments and its easy configurable.

Example

Features

  • One segment
  • Multiple segments
  • Fill animation
  • Control of fill animation duration
  • Animated tag with value
  • Custom value formater
  • Configurable colors
  • Configurable ARC radius and total size in degrees
  • Configurable space between arc segments
  • [React Native version](https://github.com/ricardovcorrea/react-native-segmented-round-display "React Native version")

Installation

yarn add react-segmented-round-display

or

npm install react-segmented-round-display --save

Usage

Here's a simple example. To render output like this:

Usage example

import React from 'react';
import SegmentedRoundDisplay from 'react-segmented-round-display';

function App() {

  const examples = [
    {
      displayValue: true,
      formatValue: (value) => `R$ ${value.toFixed(2)}`,
      segments: [
        {
          total: 80,
          filled: 40
        }
      ]
    },
    {
      displayValue: true,
      formatValue: (value) => `R$ ${value.toFixed(2)}`,
      segments: [
        {
          total: 80,
          filled: 80
        },
        {
          total: 30,
          filled: 15
        }
      ]
    },
    {
      displayValue: true,
      formatValue: (value) => `R$ ${value.toFixed(2)}`,
      segments: [
        {
          total: 80,
          filled: 80
        },
        {
          total: 30,
          filled: 30
        },
        {
          total: 100,
          filled: 40
        }
      ]
    }
  ]
  return (
    <div>
      {examples.map((example, i) => (<SegmentedRoundDisplay style={{ marginLeft: 30 }} key={i} {...example} />))}
    </div>
  );
}

export default App;

Common props

NameTypeDefaultDescription
segmentsArray of { total: int, filled: int }[]segments to be rendered
filledArcWidthint7thickness of filled arc
emptyArcWidthint7thickness of empty arc
arcSpacingint7space between segments
totalArcSizeint280total arc size in degrees
radiusint150radius of the arc
emptyArcColorstring#ADB1CCcolor of empty arc
filledArcColorstring#5ECCAAcolor of filled arc
incompleteArcColorstring#23318Ccolor of incomplete arc
animatedbooltrueenable/disable segments fill animation
animationDurationint1000duration of fill animation in MS
displayValueboolfalseenable/disable the value display
formatValuefunction{}function to formar the value
valueBoxColorstring#23318Ccolor of box that holds the value if displayValue = true
valueFontColorstring#FFFFFFcolor of text of value if displayValue = true
stylesStyles object{}styles to be applied to container

Run example

git clone https://github.com/ricardovcorrea/react-segmented-round-display.git
cd react-segmented-round-display/example
yarn
yarn start

Contributors

Ricardo Vaz Corrêa

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago