Skip to content

Commit

Permalink
Merge pull request Mikhus#179 from TamarLahav/feature/customize
Browse files Browse the repository at this point in the history
Feature/customize
  • Loading branch information
Mikhus authored Apr 9, 2020
2 parents e17c14a + 55be188 commit 9add91f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/GenericOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ const GenericOptions = {
{ from: 60, to: 80, color: '#ccc' },
{ from: 80, to: 100, color: '#999' }],
highlightsWidth: 15,
highlightsLineCap: 'butt',

// progress bar
barWidth: 20, // percents
Expand Down
12 changes: 11 additions & 1 deletion lib/RadialGauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function drawRadialHighlights(context, options) {
);
context.strokeStyle = hlt.color;
context.lineWidth = hlWidth;
context.lineCap = options.highlightsLineCap;
context.stroke();
context.closePath();

Expand Down Expand Up @@ -460,6 +461,15 @@ function drawRadialTitle(context, options) {
context.restore();
}

const validMember = /{([_a-zA-Z]+[_a-zA-Z0-9]*)}/g
function formatContext(options, format) {
// "{value} % {Title}"

return format.replace(validMember, function (match, member){
const value = options[member];
return (typeof value !== 'undefined') ? value : match;
})
}
/* istanbul ignore next: private, not testable */
/**
* Draws units name on the gauge
Expand All @@ -475,7 +485,7 @@ function drawRadialUnits(context, options) {
context.font = drawings.font(options, 'Units', context.max / 200);
context.fillStyle = options.colorUnits;
context.textAlign = 'center';
context.fillText(options.units, 0, context.max / 3.25, context.max * 0.8);
context.fillText(formatContext(options, options.units), 0, context.max / 3.25, context.max * 0.8);
context.restore();
}

Expand Down

0 comments on commit 9add91f

Please sign in to comment.