Socket
Book a DemoInstallSign in
Socket

react-svg-donuts

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-svg-donuts

A ReactJS component for simple SVG donut graphs.

latest
Source
npmnpm
Version
3.0.0
Version published
Weekly downloads
74
-30.84%
Maintainers
1
Weekly downloads
 
Created
Source

Travis CI Github Build Codacy Badge Codebeat Badge CodeFactor Badge DeepScan grade Analytics

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 GitHub forks GitHub watchers GitHub followers

Code stats

GitHub code size in bytes GitHub repo size GitHub language count GitHub top language GitHub last commit

Demo

TL;DR here is the demo

Dependencies

  • NodeJS
  • NPM / Yarn
  • React and ReactDOM
  • A ReactJS application

Usage

First install the package

$ npm i react-svg-donuts

# or

$ yarn add react-svg-donuts

Then

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 <strong> tag.
const renderProgress = progress => <strong>{progress}%</strong>;

const MyComponent = () => (
	<>
		<Donut progress={progress} onRender={renderProgress} />, document.getElementById('demo')
		<ComplexDonut
			size={200}
			parts={[
				{
					color: '#FF8A80',
					value: 230
				},
				{
					color: '#FF80AB',
					value: 308
				},
				{
					color: '#B9F6CA',
					value: 520
				},
				{
					color: '#B388FF',
					value: 130
				},
				{
					color: '#8C9EFF',
					value: 200
				}
			]}
			radius={80}
			thickness={40}
			startAngle={-90}
		/>
	</>
);

Props

Donut props

PropTypeRequiredDefaultDescription
prefixstringfalse'donut'String used as a prefix for the CSS class names
progressnumberfalse0A number between 0 and 100
onRenderFunctionfalse(progress) => {progress}Function which runs after the Donut is rendered and returns a ReactNode

Complex donut props

PropTypeRequiredDefaultDescription
sizenumberfalse160The width and height of the donut
parts{ color: string; value: number; }[]false[]The donut parts
radiusnumberfalse60The radius of the element
classNamestringfalse''Custom CSS class name for the Donut
thicknessnumberfalse30Stroke width of the element
textPropsSVGProps for SVGTextElementfalse{}Additional props for the element
startAnglenumberfalse-90Number between -360 and 360
circlePropsSVGProps for SVGCircleElementfalse{}Additional props for the element

CSS

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

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

or

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

LICENSE

MIT

Connect with me:

Support and sponsor my work:

Keywords

Chart

FAQs

Package last updated on 08 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts