Giter Club home page Giter Club logo

circle-progress-bar's Introduction

English · 中文

Introduction

circle-progress-bar.js is a plugin that uses canvas to draw a circular progress bar and does not rely on any library. The effect is as follows:

Usage

Basic usage

git clone this repository, and then reference 'index.js' in the lib folder in your html.

<style>
#my-canvas {
/* Use css to control the width and height of canvas elements to solve the distortion problem of canvas itself */
width: 20px;
}
</style>
<canvas id="my-canvas" > 
</canvas>
<script src="./circle-progress-bar.js">
</script>
<script>
	var myCanvas = document.querySelector('#my-canvas');
	var c1 = new CircleProgressBar({
		canvasDom: myCanvas
	});
</script>

CommonJS usage

⚠️Tips: ---- Please note that the npm package name is mini-circle-progress-bar not circle-progress-bar!!

npm i mini-circle-progress-bar

ES Module:

import Bar from 'mini-circle-progress-bar'
var c1 = new Bar({
	canvasDom: myCanvas
});

CommonJS :

var Bar = require 'mini-circle-progress-bar'
var c1 = new Bar({
	canvasDom: myCanvas
});

Parameter configuration

{
	canvasDom: CanvasDomNeedToSet, // Required canvas dom
	// The following values are default values
	r: 30, // inner circle radius
	lineWidth: 5, // border width
	lineColor: '#3385ff', // border progress bar color
	lineBgColor: '#eeeeee', // border background color
	angle: Math.PI * 0.5, // The Angle to be rotated
	startAngle: -Math.PI * 0.5, // Start Angle
	duration: 1000, // Transition time, unit :ms
	text: ", // Text in a circle
	showPercent: true, // Whether to display the percentage 
	value
	textFontSize: 12, // Text size (px)
	textColor: '#3385ff', // Text color
	animationMode: 'linear' // 'linear' || 'accelerate' || 
	'decelerate' AnimationMode: 'Linear' // ||   
	'accelerate' || 'decelerate
}

Compatibility

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔ 10+ ✔

FAQ

  • The direction of operation of this plug-in is clockwise, counterclockwise is not supported for the time being;

  • It is strongly not recommended to set the lineWitdh value to odd! Because the odd line width will appear blank in the canvas (because the remaining 0.5px width of the line color will fade)

  • When showPercent is true and text: 'Example text' exists, 'example text' will not appear, only the percentage text will appear.

  • How to solve the canvas distortion problem?
    The distortion problem is the existing problem of canvas itself. Using css to reduce the width and height of canvas can be done. For example, set parameters: r: 50, lineWidth: 10, then the width of canvas will be 50*2+10*2 === 120, then css set '#my-canvas {width: 60px; } 'is reduced to 60px.

  • Can I set multiple lines of text?
    No, you can only set single lines of text.

  • How to solve the problem of text wrapping?
    This plug-in does not support text wrapping. Excessive text will cause the display of the canvas to be abnormal. Solution: Set the parameter 'showPercent: false', then the user writes the text element and uses positioning to adjust the display to the center of the ring.

  • How to adapt to mobile terminals?
    You can get the width of the canvas you want when the page is loaded, and then render the progress bar.

circle-progress-bar's People

Contributors

aswind7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.