Skip to content

Commit

Permalink
add a build step, add comments, rename component.json to bower.json, …
Browse files Browse the repository at this point in the history
…bump to version 0.2.1
  • Loading branch information
gregberge committed Apr 29, 2013
1 parent e781b0d commit 3e61244
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# npm
node_modules/
21 changes: 21 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = function (grunt) {
'use strict';

grunt.initConfig({
uglify: {
'default': {
options: {
preserveComments: 'some',
sourceMap: 'circular-progress.min.map'
},
files: {
'circular-progress.min.js': 'circular-progress.js'
}
}
}
});

grunt.loadNpmTasks('grunt-contrib-uglify');

grunt.registerTask('default', ['uglify']);
};
14 changes: 14 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "circular-progress",
"description": "A JavaScript circular progress widget, dependency-free and configurable.",
"author": "Bergé Greg <[email protected]>",
"version": "0.2.1",
"main": "circular-progress.js",
"ignore": [
".gitignore",
".jshintrc",
"Gruntfile.js",
"package.json",
"test"
],
}
25 changes: 16 additions & 9 deletions circular-progress.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*! circular-progress - v0.2.1 - https://github.com/neoziro/circular-progress */

(function () {
var autoscale, extendCtx, ctxProperties, CircularProgress;

ctxProperties = ['fillStyle', 'font', 'globalAlpha', 'globalCompositeOperation',
// List of 2D context properties
var ctxProperties = ['fillStyle', 'font', 'globalAlpha', 'globalCompositeOperation',
'lineCap', 'lineDashOffset', 'lineJoin', 'lineWidth',
'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX',
'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseLine'];

// autoscale function from https://github.com/component/autoscale-canvas
autoscale = function (canvas) {
// Autoscale function from https://github.com/component/autoscale-canvas
var autoscale = function (canvas) {
var ctx = canvas.getContext('2d'),
ratio = window.devicePixelRatio || 1;

Expand All @@ -22,15 +24,17 @@
return canvas;
};

extendCtx = function (ctx, options) {
// Utility function to extend a 2D context with some options
var extendCtx = function (ctx, options) {
for (var i in options) {
if (ctxProperties.indexOf(i) === -1) continue;

ctx[i] = options[i];
}
};

CircularProgress = this.CircularProgress = function (options) {
// Main CircularProgress object exposes on global context
var CircularProgress = this.CircularProgress = function (options) {
var ctx, i, property;

options = options || {};
Expand All @@ -51,12 +55,14 @@
if (options.radius) this.radius(options.radius);
};

// Update with a new `percent` value and redraw the canvas
CircularProgress.prototype.update = function (value) {
this._percent = value;
this.draw();
return this;
};

// Specify a new `radius` for the circle
CircularProgress.prototype.radius = function (value) {
var size = value * 2;
this.el.width = size;
Expand All @@ -65,6 +71,7 @@
return this;
};

// Draw the canvas
CircularProgress.prototype.draw = function () {
var tw, text, fontSize,
options = this.options,
Expand All @@ -79,7 +86,7 @@

ctx.clearRect(0, 0, size, size);

// initial circle
// Initial circle
if (options.initial) {
extendCtx(ctx, options);
extendCtx(ctx, options.initial);
Expand All @@ -89,14 +96,14 @@
ctx.stroke();
}

// progress circle
// Progress circle
extendCtx(ctx, options);

ctx.beginPath();
ctx.arc(x, y, half - ctx.lineWidth, 0, angle, false);
ctx.stroke();

// text
// Text
if (options.text) {
extendCtx(ctx, options);
extendCtx(ctx, options.text);
Expand Down
3 changes: 3 additions & 0 deletions circular-progress.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions circular-progress.min.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions component.json

This file was deleted.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "circular-progress",
"description": "A JavaScript circular progress widget, dependency-free and configurable.",
"author": "Bergé Greg <[email protected]>",
"version": "0.2.1",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-uglify": "~0.2.0"
}
}

0 comments on commit 3e61244

Please sign in to comment.