Skip to content

Commit b60a6f2

Browse files
committed
adding a way to set the 0 position of the knob, fixing issue aterrien#26
1 parent b83cec8 commit b60a6f2

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Behaviors :
3737
* max : max value || default=100.
3838
* stopper : stop at 0 & 100 on keydown/mousewheel || default=true.
3939
* readOnly : disable input and events.
40+
* angleOffset: change the 0 position of the knob (in degree), || default=0.
4041

4142
UI :
4243
* cursor : display mode "cursor" | default=gauge.

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@
126126
data-min="-100"
127127
data-cgColor="#A9EFFD"
128128
data-displayPrevious=true
129+
data-angleOffset="90"
129130
</pre>
130-
<input class="knob"data-width="200" data-min="-100" data-displayPrevious=true value="44">
131+
<input class="knob"data-width="200" data-min="-100" data-angleOffset="90" data-displayPrevious=true value="44">
131132
</div>
132133
<div style="clear:both"></div>
133134
<div style="float:left;width:300px;height:320px;padding:20px">

js/jquery.knob.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $(function () {
1919

2020
var v = null
2121
,ctx = c[0].getContext("2d")
22-
,PI2 = 2*Math.PI
22+
,PI2 = 2 * Math.PI
2323
,mx ,my ,x ,y
2424
,self = this;
2525

@@ -55,7 +55,7 @@ $(function () {
5555
this.draw = function (nv) {
5656

5757
var a = this.angle(nv) // Angle
58-
,sa = 1.5 * Math.PI // Previous start angle
58+
,sa = 1.5 * Math.PI + opt.angleOffset // Previous start angle
5959
,sat = sa // Start angle
6060
,ea = sa + this.angle(v) // Previous end angle
6161
,eat = sat + a // End angle
@@ -242,6 +242,7 @@ $(function () {
242242
,'tickWidth' : $this.data('tickWidth') || 0.02
243243
,'tickColorizeValues' : $this.data('tickColorizeValues') || true
244244
,'skin' : $this.data('skin') || 'default'
245+
,'angleOffset': degreeToRadians($this.data('angleoffset'))
245246

246247
// Hooks
247248
,'draw' :
@@ -418,4 +419,8 @@ $(function () {
418419
}
419420
).parent();
420421
};
422+
423+
function degreeToRadians (angle) {
424+
return $.isNumeric(angle) ? angle * Math.PI / 180 : 0;
425+
}
421426
});

0 commit comments

Comments
 (0)