From 0ae83de6a4b9bdd81a78417456edf7ed44868e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Wed, 24 Apr 2013 18:25:48 +0200 Subject: [PATCH] first version --- README.md | 36 ++++++++++++++++++++++++++++++++++++ circular-progress.js | 33 +++++++++++++++++++++++++++++++++ component.json | 6 ++++++ 3 files changed, 75 insertions(+) create mode 100644 circular-progress.js create mode 100644 component.json diff --git a/README.md b/README.md index e69de29..adb981c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,36 @@ +# Circular progress + +A JavaScript circular progress bar widget, dependency-free and configurable. + +## Example + +```javascript +var progressBar = new CircularProgress({ + width: 200, + height: 200, + radius: 70, + strokeStyle: '#000', + lineCap: 'round', + lineWidth: '4.0' +}); + +document.body.appendChild(progressBar.canvas); + +progressBar.progress(0.4); +``` + +## Usage + +### new CircularProgress( options ) + +Options must contains : + +* `width` +* `height` +* `radius` + +Other attributes are attached to the canvas 2D context. + +### progress( value ) + +Notify the progress, and draw the canvas, `value` is a float between 0 and 1. \ No newline at end of file diff --git a/circular-progress.js b/circular-progress.js new file mode 100644 index 0000000..a685ae9 --- /dev/null +++ b/circular-progress.js @@ -0,0 +1,33 @@ +(function () { + var circ = Math.PI * 2, + quart = Math.PI / 2; + + this.CircularProgress = function (options) { + if (! options.width || ! options.height || ! options.radius) { + return ; + } + + this.canvas = document.createElement('canvas'); + this.canvas.width = options.width; + this.canvas.height = options.height; + + this.radius = options.radius; + + delete options.width; + delete options.height; + delete options.radius; + + this.ctx = this.canvas.getContext('2d'); + for (var i in options) { + console.log(i); + this.ctx[i] = options[i]; + } + }; + + this.CircularProgress.prototype.progress = function (value) { + this.ctx.beginPath(); + this.ctx.arc(this.canvas.width / 2, this.canvas.height / 2, this.radius, -(quart), ((circ) * value) - quart, false); + this.ctx.stroke(); + }; + +}).call(this); \ No newline at end of file diff --git a/component.json b/component.json new file mode 100644 index 0000000..2c84a23 --- /dev/null +++ b/component.json @@ -0,0 +1,6 @@ +{ + "name": "circular-progress", + "description": "A JavaScript circular progress bar widget, dependency-free and configurable.", + "version": "0.1.0", + "main": "circular-progress.js" +} \ No newline at end of file