Skip to content

Commit f889693

Browse files
author
Ben Quirk
committed
added support for linear gradient on foreground to span the amount visible
1 parent 755309e commit f889693

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

js/jquery.knob.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@
114114
displayInput: this.$.data('displayinput') == null || this.$.data('displayinput'),
115115
displayPrevious: this.$.data('displayprevious'),
116116
fgColor: this.$.data('fgcolor') || '#87CEEB',
117+
fgGradientStart: this.$.data('fggradientstart') || this.$.data('fgcolor') || '#87CEEB',
118+
fgGradientEnd: this.$.data('fggradientend') || this.$.data('fgcolor') || '#87CEEB',
117119
inputColor: this.$.data('inputcolor'),
118120
font: this.$.data('font') || 'Arial',
119121
fontWeight: this.$.data('font-weight') || 'bold',
@@ -779,9 +781,19 @@
779781
c.stroke();
780782
r = this.cv == this.v;
781783
}
784+
var perc = (isNaN(this.v) ? 100 : this.v) / 100;
785+
var gwidth = perc === 100 ? this.w : (this.w * perc);
786+
var grad = c.createLinearGradient(0, this.h, gwidth, this.h);
787+
grad.addColorStop(0, this.o.fgGradientStart);
788+
grad.addColorStop(1, this.o.fgGradientEnd);
782789

783790
c.beginPath();
784-
c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
791+
792+
if (this.o.fgGradientStart === this.o.fgGradientEnd)
793+
c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
794+
else
795+
c.strokeStyle = grad;
796+
785797
c.arc(this.xy, this.xy, this.radius, a.s, a.e, a.d);
786798
c.stroke();
787799
};

0 commit comments

Comments
 (0)