Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scriptex/react-svg-donuts

SVG donut component for React
https://github.com/scriptex/react-svg-donuts

donut-chart react-component svg-donuts

Last synced: 9 days ago
JSON representation

SVG donut component for React

Awesome Lists containing this project

README

        

[![Travis CI](https://travis-ci.com/scriptex/react-svg-donuts.svg?branch=master)](https://travis-ci.com/scriptex/react-svg-donuts)
[![Github Build](https://github.com/scriptex/react-svg-donuts/workflows/Build/badge.svg)](https://github.com/scriptex/react-svg-donuts/actions?query=workflow%3ABuild)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/34d3d75710534dc6a38c3584a1dcd068)](https://www.codacy.com/gh/scriptex/react-svg-donuts/dashboard?utm_source=github.com&utm_medium=referral&utm_content=scriptex/react-svg-donuts&utm_campaign=Badge_Grade)
[![Codebeat Badge](https://codebeat.co/badges/d765a4c8-2c0e-44f2-89c3-fa364fdc14e6)](https://codebeat.co/projects/github-com-scriptex-react-svg-donuts-master)
[![CodeFactor Badge](https://www.codefactor.io/repository/github/scriptex/react-svg-donuts/badge)](https://www.codefactor.io/repository/github/scriptex/react-svg-donuts)
[![DeepScan grade](https://deepscan.io/api/teams/3574/projects/5257/branches/40799/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=3574&pid=5257&bid=40799)
[![Analytics](https://ga-beacon-361907.ew.r.appspot.com/UA-83446952-1/github.com/scriptex/react-svg-donuts/README.md?pixel)](https://github.com/scriptex/react-svg-donuts/)

# React SVG Donuts

> A React component for simple (and complex) SVG donuts.

**The current version depends on the Hooks API introduced with React 16.8. If you need legacy React support, please use a 1.x.x version.**

## Visitor stats

![GitHub stars](https://img.shields.io/github/stars/scriptex/react-svg-donuts?style=social)
![GitHub forks](https://img.shields.io/github/forks/scriptex/react-svg-donuts?style=social)
![GitHub watchers](https://img.shields.io/github/watchers/scriptex/react-svg-donuts?style=social)
![GitHub followers](https://img.shields.io/github/followers/scriptex?style=social)

## Code stats

![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/scriptex/react-svg-donuts)
![GitHub repo size](https://img.shields.io/github/repo-size/scriptex/react-svg-donuts?style=plastic)
![GitHub language count](https://img.shields.io/github/languages/count/scriptex/react-svg-donuts?style=plastic)
![GitHub top language](https://img.shields.io/github/languages/top/scriptex/react-svg-donuts?style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/scriptex/react-svg-donuts?style=plastic)

## Demo

TL;DR [here is the demo](https://react-svg-donuts.atanas.info/)

## Dependencies

1. NodeJS
2. NPM / Yarn
3. React and ReactDOM
4. A ReactJS application

## Usage

First install the package

```sh
$ npm i react-svg-donuts

# or

$ yarn add react-svg-donuts
```

Then

```javascript
import React from 'react';

import { Donut, ComplexDonut } from 'react-svg-donuts';

// The donut will be half filled
const progress = 50;

// The value will be wrapped inside a tag.
const renderProgress = progress => {progress}%;

const MyComponent = () => (
<>
, document.getElementById('demo')

>
);
```

## Props

### Donut props

| Prop | Type | Required | Default | Description |
| ---------- | ---------- | -------- | ----------------------------------------- | ----------------------------------------------------------------------- |
| `prefix` | `string` | false | 'donut' | String used as a prefix for the CSS class names |
| `progress` | `number` | false | 0 | A number between 0 and 100 |
| `onRender` | `Function` | false | (progress) => {progress} | Function which runs after the Donut is rendered and returns a ReactNode |

### Complex donut props

| Prop | Type | Required | Default | Description |
| ----------- | ----------------------------------- | -------- | ------- | ------------------------------------------- |
| size | number | false | 160 | The width and height of the donut |
| parts | { color: string; value: number; }[] | false | [] | The donut parts |
| radius | number | false | 60 | The radius of the element |
| className | string | false | '' | Custom CSS class name for the Donut |
| thickness | number | false | 30 | Stroke width of the element |
| textProps | SVGProps for SVGTextElement | false | {} | Additional props for the element |
| startAngle | number | false | -90 | Number between -360 and 360 |
| circleProps | SVGProps for SVGCircleElement | false | {} | Additional props for the element |

## CSS

There is a predefined stylesheet which can be used as is.
If you want it, just import it:

```css
@import 'react-svg-donuts/src/index.css';
```

or

```javascript
import 'react-svg-donuts/src/index.css';
```

## LICENSE

MIT

---


Connect with me:






 



 



 



 



 



 



 



 



 



 



 



---


Support and sponsor my work: