Skip to content

Commit

Permalink
feat: Issue 241 - added update method to support updating valueFontCo…
Browse files Browse the repository at this point in the history
…lor hex value dynamically
  • Loading branch information
deezone committed Nov 23, 2019
1 parent 7e7a3c8 commit 3e0841b
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions justgage.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,30 @@
obj, displayVal, color, max, min = null;
};

/**
* Update Gauge options
*
* @param {String} option The target option name
* @param {Number|String} val The value to be assigned to the option
*/
JustGage.prototype.update = function (option, val) {
var obj = this;

switch (option) {
case 'valueFontColor':
if (!isHexNumber(val)) {
console.log('* justgage: the updated valueFontColor value is not a valid hex value');
break;
}

obj.txtValue.attr({
'fill': val
});
break;
default:
console.log(`* justgage: "${option}" is not a supported update setting`);
}
};

/**
* Destroy the Gauge Object and unbind events
Expand Down Expand Up @@ -1201,6 +1225,17 @@
return (str.charAt(0) == "#") ? str.substring(1, 7) : str;
}

/**
* Validate if hex value
*
* @param val
* @returns {*|boolean}
*/
function isHexNumber(val) {
var regExp = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/;
return (typeof val === 'string' && regExp.test(val));
}

/** Human friendly number suffix - @robertsLando */
function humanFriendlyNumber(n, d) {
var d2, i, s, c;
Expand Down Expand Up @@ -1299,9 +1334,3 @@

return JustGage
}));






0 comments on commit 3e0841b

Please sign in to comment.