Navigation Menu

Skip to content

Commit

Permalink
adding a way to set the 0 position of the knob, fixing issue aterrien#26
Browse files Browse the repository at this point in the history
  • Loading branch information
eskimoblood committed May 27, 2012
1 parent b83cec8 commit b60a6f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -37,6 +37,7 @@ Behaviors :
* max : max value || default=100.
* stopper : stop at 0 & 100 on keydown/mousewheel || default=true.
* readOnly : disable input and events.
* angleOffset: change the 0 position of the knob (in degree), || default=0.

UI :
* cursor : display mode "cursor" | default=gauge.
Expand Down
3 changes: 2 additions & 1 deletion index.html
Expand Up @@ -126,8 +126,9 @@
data-min="-100"
data-cgColor="#A9EFFD"
data-displayPrevious=true
data-angleOffset="90"
</pre>
<input class="knob"data-width="200" data-min="-100" data-displayPrevious=true value="44">
<input class="knob"data-width="200" data-min="-100" data-angleOffset="90" data-displayPrevious=true value="44">
</div>
<div style="clear:both"></div>
<div style="float:left;width:300px;height:320px;padding:20px">
Expand Down
9 changes: 7 additions & 2 deletions js/jquery.knob.js
Expand Up @@ -19,7 +19,7 @@ $(function () {

var v = null
,ctx = c[0].getContext("2d")
,PI2 = 2*Math.PI
,PI2 = 2 * Math.PI
,mx ,my ,x ,y
,self = this;

Expand Down Expand Up @@ -55,7 +55,7 @@ $(function () {
this.draw = function (nv) {

var a = this.angle(nv) // Angle
,sa = 1.5 * Math.PI // Previous start angle
,sa = 1.5 * Math.PI + opt.angleOffset // Previous start angle
,sat = sa // Start angle
,ea = sa + this.angle(v) // Previous end angle
,eat = sat + a // End angle
Expand Down Expand Up @@ -242,6 +242,7 @@ $(function () {
,'tickWidth' : $this.data('tickWidth') || 0.02
,'tickColorizeValues' : $this.data('tickColorizeValues') || true
,'skin' : $this.data('skin') || 'default'
,'angleOffset': degreeToRadians($this.data('angleoffset'))

// Hooks
,'draw' :
Expand Down Expand Up @@ -418,4 +419,8 @@ $(function () {
}
).parent();
};

function degreeToRadians (angle) {
return $.isNumeric(angle) ? angle * Math.PI / 180 : 0;
}
});

0 comments on commit b60a6f2

Please sign in to comment.