diff --git a/README.md b/README.md index f1849f7..4e3633a 100755 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Behaviors : * angleArc : arc size in degrees | default=360. * stopper : stop at min & max on keydown/mousewheel | default=true. * readOnly : disable input and events | default=false. +* rotation : direction of progression | default=clockwise. UI : * cursor : display mode "cursor", cursor size could be changed passing a numeric value to the option, default width is used when passing boolean value "true" | default=gauge. @@ -131,4 +132,4 @@ Supported browser Tested on Chrome, Safari, Firefox, IE>=8.0 (IE8.0 with excanvas). - \ No newline at end of file + diff --git a/index.html b/index.html index 1e17ef4..3dffa5e 100755 --- a/index.html +++ b/index.html @@ -24,33 +24,25 @@ // "tron" case if(this.$.data('skin') == 'tron') { - var a = this.angle(this.cv) // Angle - , sa = this.startAngle // Previous start angle - , sat = this.startAngle // Start angle - , ea // Previous end angle - , eat = sat + a // End angle + this.cursorExt = 0.3; + + var a = this.arc(this.cv) // Arc + , pa // Previous arc , r = 1; this.g.lineWidth = this.lineWidth; - this.o.cursor - && (sat = eat - 0.3) - && (eat = eat + 0.3); - if (this.o.displayPrevious) { - ea = this.startAngle + this.angle(this.v); - this.o.cursor - && (sa = ea - 0.3) - && (ea = ea + 0.3); + pa = this.arc(this.v); this.g.beginPath(); this.g.strokeStyle = this.pColor; - this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sa, ea, false); + this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, pa.s, pa.e, pa.d); this.g.stroke(); } this.g.beginPath(); this.g.strokeStyle = r ? this.o.fgColor : this.fgColor ; - this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, sat, eat, false); + this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, a.s, a.e, a.d); this.g.stroke(); this.g.lineWidth = 2; @@ -156,8 +148,9 @@
× 5-digit values, step 1000
diff --git a/js/jquery.knob.js b/js/jquery.knob.js index a2fb82a..c3f097a 100755 --- a/js/jquery.knob.js +++ b/js/jquery.knob.js @@ -110,6 +110,7 @@ fontWeight: this.$.data('font-weight') || 'bold', inline : false, step : this.$.data('step') || 1, + rotation: this.$.data('rotation'), // Hooks draw : null, // function () {} @@ -120,6 +121,7 @@ ); // finalize options + this.o.flip = this.o.rotation === 'anticlockwise' || this.o.rotation === 'acw'; if(!this.o.inputColor) { this.o.inputColor = this.o.fgColor; } @@ -526,6 +528,10 @@ , - (y - this.y - this.w2) ) - this.angleOffset; + if (this.o.flip) { + a = this.angleArc - a - this.PI2; + } + if(this.angleArc != this.PI2 && (a < 0) && (a > -0.5)) { // if isset angleArc option, set to min if .5 under min a = 0; @@ -705,45 +711,54 @@ return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min); }; + this.arc = function (v) { + var sa, ea; + v = this.angle(v); + if (this.o.flip) { + sa = this.endAngle + 0.00001; + ea = sa - v - 0.00001; + } else { + sa = this.startAngle - 0.00001; + ea = sa + v + 0.00001; + } + this.o.cursor + && (sa = ea - this.cursorExt) + && (ea = ea + this.cursorExt); + return { + s: sa, + e: ea, + d: this.o.flip && !this.o.cursor + }; + }; + this.draw = function () { var c = this.g, // context - a = this.angle(this.cv) // Angle - , sat = this.startAngle // Start angle - , eat = sat + a // End angle - , sa, ea // Previous angles + a = this.arc(this.cv) // Arc + , pa // Previous arc , r = 1; c.lineWidth = this.lineWidth; c.lineCap = this.lineCap; - this.o.cursor - && (sat = eat - this.cursorExt) - && (eat = eat + this.cursorExt); - c.beginPath(); c.strokeStyle = this.o.bgColor; c.arc(this.xy, this.xy, this.radius, this.endAngle - 0.00001, this.startAngle + 0.00001, true); c.stroke(); if (this.o.displayPrevious) { - ea = this.startAngle + this.angle(this.v); - sa = this.startAngle; - this.o.cursor - && (sa = ea - this.cursorExt) - && (ea = ea + this.cursorExt); - + pa = this.arc(this.v); c.beginPath(); c.strokeStyle = this.pColor; - c.arc(this.xy, this.xy, this.radius, sa - 0.00001, ea + 0.00001, false); + c.arc(this.xy, this.xy, this.radius, pa.s, pa.e, pa.d); c.stroke(); r = (this.cv == this.v); } c.beginPath(); c.strokeStyle = r ? this.o.fgColor : this.fgColor ; - c.arc(this.xy, this.xy, this.radius, sat - 0.00001, eat + 0.00001, false); + c.arc(this.xy, this.xy, this.radius, a.s, a.e, a.d); c.stroke(); }; @@ -763,4 +778,4 @@ ).parent(); }; -})(jQuery); \ No newline at end of file +})(jQuery);