Skip to content

added support for linear gradient on foreground to span the amount vi… #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion js/jquery.knob.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
displayInput: this.$.data('displayinput') == null || this.$.data('displayinput'),
displayPrevious: this.$.data('displayprevious'),
fgColor: this.$.data('fgcolor') || '#87CEEB',
fgGradientStart: this.$.data('fggradientstart') || this.$.data('fgcolor') || '#87CEEB',
fgGradientEnd: this.$.data('fggradientend') || this.$.data('fgcolor') || '#87CEEB',
inputColor: this.$.data('inputcolor'),
font: this.$.data('font') || 'Arial',
fontWeight: this.$.data('font-weight') || 'bold',
Expand Down Expand Up @@ -779,9 +781,19 @@
c.stroke();
r = this.cv == this.v;
}
var perc = (isNaN(this.v) ? 100 : this.v) / 100;
var gwidth = perc === 100 ? this.w : (this.w * perc);
var grad = c.createLinearGradient(0, this.h, gwidth, this.h);
grad.addColorStop(0, this.o.fgGradientStart);
grad.addColorStop(1, this.o.fgGradientEnd);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that gwidth formula will be better like that (in case of negative this.o.min) :
var gwidth = (((this.cv - this.o.min) * this.w) / (this.o.max - this.o.min));

Using this.cv allows to change color dynamically.

The result is cool but why use gradients instead of changing the fgcolor of the entire circle while changing value ? with new props fgColorMin, fgColorMax for example ?


c.beginPath();
c.strokeStyle = r ? this.o.fgColor : this.fgColor ;

if (this.o.fgGradientStart === this.o.fgGradientEnd)
c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
else
c.strokeStyle = grad;

c.arc(this.xy, this.xy, this.radius, a.s, a.e, a.d);
c.stroke();
};
Expand Down