Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ <h1>jQuery Knob</h1>
<input class="knob" data-min="-15000" data-displayPrevious=true data-max="15000" data-step="1000" value="-11000">
</div>
<div style="clear:both"></div>
<div class="demo" >
<p>&#215; knob</p>
<pre>
data-displayknob="true"
data-knobcolor="#5bbce4"
data-knobradius="1.4"
</pre>
<input class="knob" data-displayknob="true" data-knobcolor="#5bbce4" data-knobradius="0.7" value="35">
</div>
<div style="clear:both"></div>
<div style="text-align: center">
<p style="font-size: 20px">&#215; Overloaded 'draw' method</p>
</div>
Expand Down
21 changes: 19 additions & 2 deletions js/jquery.knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@
height : this.$.data('height') || 200,
displayInput : this.$.data('displayinput') == null || this.$.data('displayinput'),
displayPrevious : this.$.data('displayprevious'),
displayKnob: this.$.data('displayknob') || false,
fgColor : this.$.data('fgcolor') || '#87CEEB',
inputColor: this.$.data('inputcolor'),
font: this.$.data('font') || 'Arial',
fontWeight: this.$.data('font-weight') || 'bold',
inline : false,
step : this.$.data('step') || 1,
rotation: this.$.data('rotation'),
knobColor: this.$.data('knobcolor'),
knobRadius: this.$.data('knobradius') || 0.7,

// Hooks
draw : null, // function () {}
Expand All @@ -134,6 +137,10 @@
this.o.inputColor = this.o.fgColor;
}

if(!this.o.knobColor) {
this.o.knobColor = this.o.fgColor;
}

// routing value
if(this.$.is('fieldset')) {

Expand Down Expand Up @@ -669,7 +676,7 @@
this.xy = this.w2 * this.scale;
this.lineWidth = this.xy * this.o.thickness;
this.lineCap = this.o.lineCap;
this.radius = this.xy - this.lineWidth / 2;
this.radius = this.xy - this.lineWidth / 2 - this.o.knobRadius * this.lineWidth / 2;

this.o.angleOffset
&& (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
Expand Down Expand Up @@ -697,7 +704,7 @@
,'height' : ((this.w / 3) >> 0) + 'px'
,'position' : 'absolute'
,'vertical-align' : 'middle'
,'margin-top' : ((this.w / 3) >> 0) + 'px'
,'margin-top' : (this.w / 3 >> 0) + 'px'
,'margin-left' : '-' + ((this.w * 3 / 4 + 2) >> 0) + 'px'
,'border' : 0
,'background' : 'none'
Expand Down Expand Up @@ -768,6 +775,16 @@
c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
c.arc(this.xy, this.xy, this.radius, a.s, a.e, a.d);
c.stroke();

if(this.o.displayKnob) {
var dx = Math.sin(a.e - a.s) * this.radius;
var dy = - Math.cos(a.e - a.s) * this.radius;

c.beginPath();
c.arc(this.xy + dx, this.xy + dy, this.o.knobRadius * this.lineWidth, 0, 2 * Math.PI, false);
c.fillStyle = this.o.knobColor;
c.fill();
}
};

this.cancel = function () {
Expand Down