Skip to content

Commit 3ef03bd

Browse files
committed
Version 1.1.2
- line cap - gradient angle - gradient direction - gradient stop point custom position
1 parent 842b0f3 commit 3ef03bd

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ You should specify options like in usage example above.
4343
| startAngle | Initial angle (for `0` value) <br> Default: `-Math.PI` |
4444
| reverse | Reverse animation and arc draw<br> Default: `false` |
4545
| thickness | Width of the arc. By default it's automatically calculated as 1/14 of `size` but you may set your own number <br> Default: `"auto"` |
46-
| fill | The arc fill config. You may specify next: <br>- `{ gradient: ["red", "green", "blue"] }` <br>- `{ color: "#ff1e41" }` <br>- `{ image: "http://i.imgur.com/pT0i89v.png" }`<br>- `{ image: imageInstance }`<br>- `{ color: "lime", image: "http://i.imgur.com/pT0i89v.png" }` <br> Default: `{ gradient: ["#3aeabb", "#fdd250"] }` |
46+
| lineCap | Arc line cap (`"butt"`, `"round"` or `"square"`)) <br> Default: `"butt"`
47+
| fill | The arc fill config. You may specify next: <br>- `{ color: "#ff1e41" }` <br>- `{ color: 'rgba(255, 255, 255, .3)' }` <br>- `{ gradient: ["red", "green", "blue"] }` <br>- `{ gradient: [["red", .2], ["green", .3], ["blue", .8]] }` <br>- `{ gradient: ["red", "orange"], gradientAngle: Math.PI / 4 }` <br>- `{ gradient: ["red", "orange"], gradientDirection: [x0, y0, x1, y1] }` <br>- `{ image: "http://i.imgur.com/pT0i89v.png" }`<br>- `{ image: imageInstance }`<br>- `{ color: "lime", image: "http://i.imgur.com/pT0i89v.png" }` <br> Default: `{ gradient: ["#3aeabb", "#fdd250"] }` |
4748
| emptyFill | Color of the "empty" arc. Only a color fill supported by now <br> Default: `"rgba(0, 0, 0, .1)"` |
4849
| animation | Animation config. See [jQuery animations](http://api.jquery.com/animate/). <br> You may also set it to `false` <br> Default: `{ duration: 1200, ease: "circleProgressEase" }` <br> `"circleProgressEase"` *is just a ease-in-out-cubic easing* |
4950
| 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` <br> Default: `0.0`

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-circle-progress",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"authors": [
55
"Rostyslav Bryzgunov <[email protected]>"
66
],

dist/circle-progress.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ jquery-circle-progress - jQuery Plugin to draw animated circular progress bars
33
44
URL: http://kottenator.github.io/jquery-circle-progress/
55
Author: Rostyslav Bryzgunov <[email protected]>
6-
Version: 1.1.1
6+
Version: 1.1.2
77
License: MIT
88
*/
99
(function($) {
@@ -43,8 +43,8 @@ License: MIT
4343
* - { color: '#3aeabb' }
4444
* - { color: 'rgba(255, 255, 255, .3)' }
4545
* - linear gradient (left to right):
46-
* - { gradient: ['#3aeabb', '#fdd250'] }
47-
* - { gradient: ['red', 'green', 'blue'] }
46+
* - { gradient: ['#3aeabb', '#fdd250'], gradientAngle: Math.PI / 4 }
47+
* - { gradient: ['red', 'green', 'blue'], gradientDirection: [x0, y0, x1, y1] }
4848
* - image:
4949
* - { image: 'http://i.imgur.com/pT0i89v.png' }
5050
* - { image: imageObject }
@@ -82,6 +82,13 @@ License: MIT
8282
*/
8383
reverse: false,
8484

85+
/**
86+
* Arc line cap ('butt' (default), 'round' and 'square')
87+
* Read more: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D.lineCap
88+
* @type {string}
89+
*/
90+
lineCap: 'butt',
91+
8592
//-------------------------------------- protected properties and methods --------------------------------------
8693
/**
8794
* @protected
@@ -171,12 +178,32 @@ License: MIT
171178

172179
if (fill.gradient) {
173180
var gr = fill.gradient;
181+
174182
if (gr.length == 1) {
175183
this.arcFill = gr[0];
176184
} else if (gr.length > 1) {
177-
var lg = ctx.createLinearGradient(0, 0, size, 0);
178-
for (var i = 0; i < gr.length; i++)
179-
lg.addColorStop(i / (gr.length - 1), gr[i]);
185+
var ga = fill.gradientAngle || 0, // gradient direction angle; 0 by default
186+
gd = fill.gradientDirection || [
187+
size / 2 * (1 - Math.cos(ga)), // x0
188+
size / 2 * (1 + Math.sin(ga)), // y0
189+
size / 2 * (1 + Math.cos(ga)), // x1
190+
size / 2 * (1 - Math.sin(ga)) // y1
191+
];
192+
193+
var lg = ctx.createLinearGradient.apply(ctx, gd);
194+
195+
for (var i = 0; i < gr.length; i++) {
196+
var color = gr[i],
197+
pos = i / (gr.length - 1);
198+
199+
if ($.isArray(color)) {
200+
pos = color[1];
201+
color = color[0];
202+
}
203+
204+
lg.addColorStop(pos, color);
205+
}
206+
180207
this.arcFill = lg;
181208
}
182209
}
@@ -221,8 +248,8 @@ License: MIT
221248
drawFrame: function(v) {
222249
this.lastFrameValue = v;
223250
this.ctx.clearRect(0, 0, this.size, this.size);
224-
this.drawArc(v);
225251
this.drawEmptyArc(v);
252+
this.drawArc(v);
226253
},
227254

228255
/**
@@ -245,6 +272,7 @@ License: MIT
245272
}
246273

247274
ctx.lineWidth = t;
275+
ctx.lineCap = this.lineCap;
248276
ctx.strokeStyle = this.arcFill;
249277
ctx.stroke();
250278
ctx.restore();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-circle-progress",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"author": "Rostyslav Bryzgunov <[email protected]>",
55
"description": "Plugin to draw animated circular progress bars",
66
"license": "MIT",

0 commit comments

Comments
 (0)