GithubHelp home page GithubHelp logo

kottenator / jquery-circle-progress Goto Github PK

View Code? Open in Web Editor NEW
1.1K 51.0 316.0 131 KB

jQuery Plugin to draw animated circular progress bars

Home Page: http://kottenator.github.io/jquery-circle-progress/

License: MIT License

JavaScript 96.43% HTML 3.57%
jquery jquery-plugin javascript animation circle

jquery-circle-progress's Introduction

jquery-circle-progress

Build status Bower version NPM version

jQuery Plugin to draw animated circular progress bars like this:

Check out more examples! Or maybe the crazy one?

Install

Make your choice:

Usage

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="jquery-circle-progress/dist/circle-progress.js"></script>

<div id="circle"></div>

<script>
  $('#circle').circleProgress({
    value: 0.75,
    size: 80,
    fill: {
      gradient: ["red", "orange"]
    }
  });
</script>

If you use AMD or CommonJS with some JS bundler - see the UMD section below.

Options

Specify options like in example above.

Option Description
value This is the only required option. It should be from 0.0 to 1.0
Default: 0
size Size of the circle / canvas in pixels
Default: 100
startAngle Initial angle (for 0 value)
Default: -Math.PI
reverse Reverse animation and arc draw
Default: false
thickness Width of the arc. By default it's automatically calculated as 1/14 of size but you may set your own number
Default: "auto"
lineCap Arc line cap: "butt", "round" or "square" - read more
Default: "butt"
fill The arc fill config. You may specify next:
- "#ff1e41"
- { color: "#ff1e41" }
- { color: 'rgba(255, 255, 255, .3)' }
- { gradient: ["red", "green", "blue"] }
- { gradient: [["red", .2], ["green", .3], ["blue", .8]] }
- { gradient: [ ... ], gradientAngle: Math.PI / 4 }
- { gradient: [ ... ], gradientDirection: [x0, y0, x1, y1] }
- { image: "http://i.imgur.com/pT0i89v.png" }
- { image: imageInstance }
- { color: "lime", image: "http://i.imgur.com/pT0i89v.png" }
Default: { gradient: ["#3aeabb", "#fdd250"] }
emptyFill Color of the "empty" arc. Only a color fill supported by now
Default: "rgba(0, 0, 0, .1)"
animation Animation config. See jQuery animations.
You may also set it to false
Default: { duration: 1200, easing: "circleProgressEasing" }
"circleProgressEasing" is just a ease-in-out-cubic easing
animationStartValue Default animation starts at 0.0 and ends at specified value. Let's call this direct animation. If you want to make reversed animation then you should set animationStartValue to 1.0. Also you may specify any other value from 0.0 to 1.0
Default: 0.0
insertMode Canvas insertion mode: append or prepend it into the parent element?
Default: "prepend"

From version 1.1.3 you can specify any config option as HTML data- attribute.

It will work only on init, i.e. after the widget is inited you may update its properties only via .circleProgress({/*...*/}) method. data- attributes will be ignored.

Also, object options like "fill" or "animation" should be valid JSON (and don't forget about HTML-escaping):

<div
  class="circle"
  data-value="0.9"
  data-size="60"
  data-thickness="20"
  data-animation-start-value="1.0"
  data-fill="{
    &quot;color&quot;: &quot;rgba(0, 0, 0, .3)&quot;,
    &quot;image&quot;: &quot;http://i.imgur.com/pT0i89v.png&quot;
  }"
  data-reverse="true"
></div>

Events

Event Description Handler
circle-inited Triggered on init or re-init. function(event):
- event - jQuery event
circle-animation-start Triggered once the animation is started. function(event):
- event - jQuery event
circle-animation-progress Triggered on each animation tick. function(event, animationProgress, stepValue):
- event - jQuery event
- animationProgress - from 0.0 to 1.0
- stepValue - current step value: from 0.0 to value
circle-animation-end Triggered once the animation is finished. function(event):
- event - jQuery event

Browsers support

The library uses <canvas> which is supported by all modern browsers (including mobile browsers) and Internet Explorer 9+ (Can I Use).

I haven't implemented any fallback / polyfill for unsupported browsers yet (i.e. for Internet Explorer 8 and older / misc browsers).

UMD

I use UMD template for jQuery plugin which combines three things:

  • works fine with browser globals
  • works fine with AMD
  • works fine with CommonJS

Browser globals

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="jquery-circle-progress/dist/circle-progress.js"></script>
<script>
  $('#circle').circleProgress({
    value: 0.75,
  });
</script>

AMD

Assuming that you have jquery, jquery-circle-progress and requirejs in libs/ directory:

<script src="libs/requirejs/require.js"></script>
<script>
  requirejs.config({
    paths: {
      'jquery': 'libs/jquery/dist/jquery', // 'jquery' path is required - 'jquery-circle-progress' requires it
      'jquery-circle-progress': 'libs/jquery-circle-progress/dist/circle-progress' // and this one is for your convenience
    }
  });
  requirejs(['jquery', 'jquery-circle-progress'], function($) {
    $('#circle').circleProgress({
      value: 0.75
    });
  });
</script>

You can configure RequireJS as you wish, just make 'jquery' dependency reachable.

CommonJS

// script.js
require('jquery-circle-progress');
var $ = require('jquery');
$('#circle').circleProgress({
  value: 0.75
});
some-js-bundler < script.js > script.bundle.js
<script src="script.bundle.js"></script>

You can use any JS bundler (Webpack, Browserify, etc) - no specific configuration required.

API

Get/set value

Get it:

$('.circle').circleProgress({ value: 0.5 });
var value = $('.circle').circleProgress('value'); // 0.5

It will return the first item's value (by first I mean when $('.circle').length >= 1). It works only if the widget is already inited. Raises an error otherwise.

Set it:

$('.circle').circleProgress('value', 0.75); // set value to 0.75 & animate the change

It will update all selected items value and animate the change. It doesn't redraw the widget - it updates the value & animates the changes. For example, it may be an AJAX loading indicator, which shows the loading progress.

Get <canvas>

$('.circle').circleProgress({ value: 0.5 });
var canvas = $('.circle').circleProgress('widget');

It will return the first item's <canvas> (by first I mean when $('.circle').length >= 1). It works only if the widget is already inited. Raises an error otherwise.

Get CircleProgress instance

var instance = $('#circle').data('circle-progress');

Redraw existing circle

$('#circle').circleProgress({ value: 0.5, fill: { color: 'orange' }});
$('#circle').circleProgress('redraw'); // use current configuration and redraw
$('#circle').circleProgress(); // alias for 'redraw'
$('#circle').circleProgress({ size: 150 }); // set new size and redraw

It works only if the widget is already inited. Raises an error otherwise.

Change default options

$.circleProgress.defaults.size = 50;

FAQ

How to start the animation only when the circle appears in browser's view (on scrolling)?
Here is my proposed solution.
How to make the size flexible?
E.g. for responsive design, you can do it in the following way.
What if I need it to run in IE8?
There is no full-feature support for IE8 (actually, I didn't imlpement IE8 support at all). But you may follow my recommendations.
How to stop the animation?
Here is what you can do.
Can I handle "click" event?
It's not in the "core" but you can use my example of mouse/touch events handling.
May I customize the shape somehow?
It's a bit "tricky" but possible. Here is my little collection.

Development

Install

git clone [email protected]:kottenator/jquery-circle-progress.git
npm install

Modify

You need to update dist/circle-progress.min.js after any change to dist/circle-progress.js:

npm run build-min

If you're using one of JetBrains IDEs - you can configure a File Watcher. It's also possible to use some CLI tool like Watchman.

Test

npm test

SauceLabs:

export SAUCE_USERNAME=...
export SAUCE_ACCESS_KEY=...
export BUILD_NUMBER=...
npm test -- karma-saucelabs.conf.js

Build docs

The API docs are not complete yet but you can build them:

npm run build-docs

They will be generated in docs/api/.

Release new version

  • finalize the code

  • update the version in package.json, bower.json and dist/circle-progress.js docstring

  • update min dist: npm run build-min

  • update docs/index.html - link to the latest dist version (which doesn't exist yet)

  • push the changes to master branch

  • release on Bower: just create a Git tag (e.g.): git tag v1.2.3 && git push --tags

  • release on GitHub - add release notes to the Git tag

  • release on NPM: npm publish, but be aware:

    Once a package is published with a given name and version, that specific name and version combination can never be used again - NPM docs

jquery-circle-progress's People

Contributors

andreiglingeanu avatar dougt avatar kottenator avatar majestic2k avatar mattmezza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-circle-progress's Issues

Value Format

Hi,
I feel bad putting this as an issue seems as its more of a question.
Is there anyway of changing the values required from 0.0 to just round numbers from 1 to 100?

Thanks for this library,

Problem with the progress

I tried to use the following code for the progress. But when the value is 100%, it only shows 00. But the circles is complete. What might be the problem?

$('.second.circle').circleProgress({
    value: 0.75
}).on('circle-animation-progress', function(event, progress, stepValue) {
    $(this).find('strong').html(parseInt(100 * stepValue) + '%');
});

Circle with multiple colors

Hi kottenator,

Your library looks solid and light weight. I'm thinking of using it in our project. Does it support stacked progress (not concentric circles like in another example)? For instance, can it show:,
30% - no college
20% - undergrads
10% - grads
40% - no data

So, this needs 4 different colors and %ages are configurable.

Progress chart segments

Hi, I really like your library. I was wondering if there was a way to split up the chart into segments, similarly to the way it is done in this picture.
screenshot_2015-07-30-15-14-20

Thanks

help

this plugin has a problem when i try to use the property of animationStartValue for the first time.
The first time , i use this plugin , and i set a value to the animationStartValue property , it doesn't work

Labels and gradient customization

Hi, just have a couple of quick questions. I've been struggling to implement the following customizations.

  • How do you change the gradient such that the second color is the end color of the circle? (ie. there would be a hard transition between the end and start color instead of fading back into the start color)
  • How do I add a label/image to the end value of the progress bar?

I've added the image below for illustration.

screen shot 2015-09-17 at 3 44 34 pm

Any help would be much appreciated!

Duration doesn't seem to have an affect?

Thanks for creating this, its very cool, just a question about duration and how I am using it:

function createCircle(circleID){
$(circleID).circleProgress({
value: 1,
size: 25,
animate:{
duration:[ 2000],
},
fill: {
gradient: ["blue"]
}
});
}
Regardless of what number I put for duration, the speed of the circle being drawn always seems to be the same. Am I doing something wrong? Perhaps I should put duration:["slow"] or something like that?
Steve
Edit: Huge mistake, turns out the proper syntax is animation: {
duration: 5000
},

duplicated events callback when using the same circle in multiple times

drawAnimated: function(v) {
    var self = this,
        el = this.el;
        el.unbind(); //  <------- just add this to fix the this bug. :)

    el.trigger('circle-animation-start');

    $(this.canvas)
        .stop(true, true)
        .css({ animationProgress: 0 })
        .animate({ animationProgress: 1 }, $.extend({}, this.animation, {
            step: function(animationProgress) {
                var stepValue = self.animationStartValue * (1 - animationProgress) + v * animationProgress;
                self.drawFrame(stepValue);
                el.trigger('circle-animation-progress', [animationProgress, stepValue]);
            },
            complete: function() {
                el.trigger('circle-animation-end');
            }
        }));
},

data-attributes support

It will be useful to support some data-attributes for initialisation

<div class="circle" data-value="0.75"></div>

Drawing circle at the start of the arc

I would like to do something like this using your plugin, basically just to draw circle of certain radius at the start of the arc.
untitled-1
Is it possible with your plugin? I've browsed source code, but I'm unsure where to put this kind of stuff, my guess is that I add extra method like drawStartCircle in drawArc function and extra property for startCircleRadius in the prototype. Would do you think?

Custom element as cap

I need the "cap" of the progress bar to be a textual representation of the value. Basically, on every circle-animation-progress event, I need to get the cap position, move the number to that position, and update the value. Is this possible currently?

Possible to redraw from previous value?

Very good job with the library! Fits a little project of mine totally perfect.

I have two questions:

  1. Lets say i've initiated the circle and it ends up on value 0.75.
    Now I click a button and then want to redraw the same circle from value 0.75 (and not start over from 0 again). Is this possible?
  2. At the same time I want to redraw the color in the circle - preferable some way so its not a hard cut, but so it fades over to the new color. Is this possible?

Cheers!

Safari support

Hi there,
first of all thank you for the great plugin.

This issue is related to Safari. The arc is not well painted (colors and shape - it has not rounded lines). I'm posting here some pics...
screen shot 2015-01-13 at 6 56 13 pm

screen shot 2015-01-13 at 6 55 59 pm

screen shot 2015-01-13 at 6 53 13 pm

This does not occur using Chrome, where the canvas is rendered perfectly.
screen shot 2015-01-13 at 6 59 28 pm

The application is developed using Polymer. Might it be a compatibility problem?

Circle color attribute + IE8 support.

It would be nice to have circle color attribute. Now it is somehow grey color, which seems to have some opacity. It would be nice to be able to definie your own color. For example I would like to have light red color of the whole circle and the progress will have dark red color. Now everything has to be in grey (due to page background).

Another thing is IE8 support. It would be nice to somehow have IE8 support.
it is still heavily used on WIN XP.

Draw the progress bar around a circular image

Hey.

I am using Twitter Bootstrap 3.2 which offers a class that turns an image into a circular view. Its not cropped or anything - but it just is styled to look like its actually round.

For my app, I'd like to draw a progress bar around such image. To be specific: I am uploading an image, and I want to show the image preview and have the progress bar surround it. This way I dont need to make extra space for a usual progress bar and can keep the content displayed minimal.

Is that possible with this plugin?

Kind regards, Ingwie

No foreground color

Hi,

I know you added a foreground color that is a grey with some opacity, can I remove it somehow? Just want to show the loading circle animation, not the holder.

Start circle, where previous ended

Hi, this is not a bug report, but a question, hoping you could help me :-)

I'd like to have 3 circles next to each other, the first animating to position x, the second to pos y and the third to position z. It would be very nice if circle 2 could start at that position, where circle one ended. How do I have to calculate that? ...sorry, my Math is really baaaaaad :-(

$('#circle_01').circleProgress({ value: 0.104 });
$('#circle_02').circleProgress({ value: 0.32, startAngle: ???[end position of circle one] });
$('#circle_02').circleProgress({ value: 0.516, startAngle: ???[end position of circle two] });

Thanks so much!

angular js binding problem

Thanks for your great plugin before. I just used it with angularjs and requirejs, it worked fine if I added static value inside data-value attribute. But, when I added my controller scope variable, for example :

myController.js
...

fidi.Quota = 0.8

...

In the html directive,
<div id="fidiTargetQuota" data-value="{{fidi.Quota}}"> ... </div>

The progress bar did not show up. But, the sources showed that the data-value already binded with value 0.8.

Thanks! Sorry for my bad English.... :)

Stop function

Hi,

Thank you for your plugin, it is the nicest and easiest I have found. I may have missed something but is there any way to stop the timer at the value it is ?
When I do
var A = $("#myElement").circleProgress({...})

I have tried

  • A.stop() => Does nothing
  • A.circleProgress('stop') => Redraw the circle

Baptiste

Can't get the value change to animate

Hello, this is a fantastic plugin that you've made and is exactly what I've been looking for ๐Ÿ‘

The only problem is that for some reason I can't get it to animate when I update the value. The whole thing just disappears entirely.

I'm trying to use it as a download meter to show the user the total percentage of the number of files they are downloading.

This has been what i've been trying to use and every time I update it with the new value the whole thing just vanishes

iDifference = Math.round(iFilesTotal - iFilesNeeded);
progress = (iDifference / iFilesTotal).toFixed(2);
$( "#circle" ).circleProgress( 'value', progress );

I've had to resort to what you mentioned in an earlier issue topic and this is my current set-up where I can successfully update the percentage value of the circle but it doesn't animate to the updated value :(
(I've cut the code down that I have to make it easier to read but the gist of it is when a file has finished being downloaded it does the maths and then fires of the UpdateCircle function)

iDifference = Math.round(iFilesTotal - iFilesNeeded);
progress = (iDifference / iFilesTotal).toFixed(2);

UpdateCircle();

var circle = $('#circle').circleProgress();
    function UpdateCircle() {
    circle.circleProgress({
    animationStartValue: circle.data('circle-progress').value,
        value: progress
    });
};

I've probably done something wrong somewhere and it's probably a total noob error but I would greatly appreciate your help :)

Progress starts when circles are visible on web page.

Hi, is there a way for the circles to start the progress when they're viewed.

As in you scroll down to the section they're in. You view them, then they start to spin. Appose to them just spinning as soon as the web pages loads.

Thanks

real Progress

Hi,

i've got an uploader and i want to display the progress, so i'm updating the progressCircle every percent change.

If i simply update the value it starts from the beginning every time i update, so i set animationStartValue before, like that:

        $('#circle').circleProgress({ animationStartValue:  progress});
        $('#circle').circleProgress({ value:  newProgress});

but is that really the way to go?
Because if i do so, and the value changes fast there is no animation...

regards and thank you for your work!

celevra

ps.: can you tell me the color codes from the blue circle (the third) in the readme?

Animation Start event doesn't seem to be working

I could be doing something wrong here, but I'm trying to use the first even in the docs, the circle-animation-start one, and it doesn't appear to be working

Essentially what I'm trying to do is find the dimensions of the canvas object and set the position of my counter to be in the center of the circle. I could do it through the CSS but I want it to be set regardless of the size I choose. Any ideas?

Hook into multiple progress callbacks

Hey,

I'm trying to hook into multiple 'circle-animation-progress' instances, as per below. I can't seem to get anywhere with the circle-animation-progress, as it always will update my percentage value for both.

    var percentage = '';
    var circle = [];
    $(".circle-stat .circle").each(function(i, val) {
        percentage = $('.percentage_value', val).val() * 100;
        console.log(percentage);
        circle[i] = $(val).circleProgress({
            lineCap: 'round',
            fill: { gradient: ['#71d4fc', '#05a1e0'] }
        }).on('circle-animation-progress', function(event, progress) {
            circle[i].find('p.percentage').html(parseInt(percentage * progress) + '<i>%</i>');
        });
    });

My markup is the following,

Is this a bug or a scope issue? Any ideas really appreciated.

-- Simon

How to show percentage progress?

I am using something like this:
$('#progress_container').circleProgress({
value: 0.2,
startAngle: -Math.PI/2,
fill : {
color: '#FBC70D'
},
thickness: '2'
}).on('circle-animation-progress', function(event, progress) {
$(this).find('strong').html(parseInt(100 * progress) + '%');
});

But the percentage doesn't show up, only the circle. Am I missing anything? Do I need to set up any html as well? Please response ASAP.

Request for the ability to animate to a new value

I love the library, but I really want to be able to change the current position of the progress bar via an ajax method. Is there any way to do this without redrawing the whole bar from zero, and without needing to cache the previous position it used outside of the widget itself?

lazyload or waypoint kind of waiting time

how can i animate circle while scrolling down to page ? my page is quite long and this plugin come just above the footer, but it animate, when page loads and when scroll down, can not see the circle progress effect ?

Color of inner circle

Hello,

Thanks for the awesome plugin.

Is there a way to change the inner circle color as attached image, which is currently transparent. I tried giving canvas a css background with border-radius but it looks bad on the edges.

Thanks

screen shot 2014-12-26 at 10 31 58

Show 100% in Value Progress

I'm not sure if this is the right place to post this but here goes anyway.

I'm not a javascripter and have no tech knowledge.

Question 1:
I'm trying to get the Value progress to show 100%

If I add "value: 1.0" - the value displayed is ".00"
If I add "value: 100" - the value displayed is "00.00"

How do I get a displayed value of "100" ?

Question 2:
The value in the front end shows a dot before the number - can this be removed

Example:
If I add "value: 0.50" - the value displayed is ".50"

Question 3:
Is it possible to group settings instead of having to create settings for each circle - I have 4, the only setting that changes is the value - 25, 50, 75, 100

Any help is much appreciated.

Issue with progress

Hey,

Great plug-in.

Just an issue with the progress...it always goes to 100% rather than the value specified. Not sure if this is the intended functionality, but I'd expect progress to stop at the value specified. In this case 75%

$('.second.circle').circleProgress({
value: 0.75
}).on('circle-animation-progress', function(event, progress) {
$(this).find('strong').html(parseInt(100 * progress) + '%');
});

Thanks!

Iphone doesn't show

Iphone can't show me the canvas. What it might be? Or what am i doing wrong

Feature request

Hi,

Can you please make a example where value is updated every second from json (either via ajax or .getjson) ?

Thanks n advance

Value

Hello,

Is any chance to change a value? I need value from 0 to 50 not 0.0 to 1.0.

How to actually set a new value without resetting the circle?

So I've been looking through several circle progress plugins and I find yours is nice, elegant and animated.

Problem is I don't know how to update the value without resetting the circle.

Let me explain:
I have a 5 step client side process, at first the progress is at 0%... when the first step is finished, the circle should animate to 20% (0.2), when the second step is finished, it should animate to 40% (0.4) WITHOUT going back to 0 and then to 40, and so on.

Without this functionality your progress plugin is kind of useless =(

Hope I'm missing something.
Thank you!

Text in center of progress bar

How would you go about making the text in the center of the progress bar to stay at the center of the progress bar on a responsive website?

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.