Skip to content

Commit

Permalink
Merge pull request #275 from doofusdavid/master
Browse files Browse the repository at this point in the history
add displayRemaining property
  • Loading branch information
robertsLando authored Aug 6, 2019
2 parents 350a7db + b55706c commit b4fd547
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions justgage.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ JustGage = function(config) {

// pointerOptions : object
// define pointer look
pointerOptions: kvLookup('pointerOptions', config, dataset, {})
pointerOptions: kvLookup('pointerOptions', config, dataset, {}),

// displayRemaining: boolean
// replace display number with the number remaining to reach max
displayRemaining: kvLookup('displayRemaining', config, dataset, false)
};

// variables
Expand Down Expand Up @@ -710,7 +714,9 @@ JustGage = function(config) {
obj.originalValue = humanFriendlyNumber(obj.originalValue, obj.config.humanFriendlyDecimal) + obj.config.symbol;
} else if (obj.config.formatNumber) {
obj.originalValue = formatNumber(obj.originalValue) + obj.config.symbol;
} else {
} else if(obj.config.displayRemaining) {
obj.originalValue = ((obj.config.max - obj.originalValue) * 1).toFixed(obj.config.decimals) + obj.config.symbol;
} else {
obj.originalValue = (obj.originalValue * 1).toFixed(obj.config.decimals) + obj.config.symbol;
}

Expand All @@ -727,7 +733,9 @@ JustGage = function(config) {
obj.txtValue.attr("text", humanFriendlyNumber(Math.floor(currentValue), obj.config.humanFriendlyDecimal) + obj.config.symbol);
} else if (obj.config.formatNumber) {
obj.txtValue.attr("text", formatNumber(Math.floor(currentValue)) + obj.config.symbol);
} else {
} else if (obj.config.displayRemaining) {
obj.txtValue.attr("text", ((obj.config.max - currentValue) * 1).toFixed(obj.config.decimals) + obj.config.symbol);
}else {
obj.txtValue.attr("text", (currentValue * 1).toFixed(obj.config.decimals) + obj.config.symbol);
}
setDy(obj.txtValue, obj.params.valueFontSize, obj.params.valueY);
Expand Down Expand Up @@ -882,10 +890,12 @@ JustGage.prototype.refresh = function(val, max, min, label) {
displayVal = humanFriendlyNumber(displayVal, obj.config.humanFriendlyDecimal) + obj.config.symbol;
} else if (obj.config.formatNumber) {
displayVal = formatNumber((displayVal * 1).toFixed(obj.config.decimals)) + obj.config.symbol;
} else if (obj.config.displayRemaining) {
displayVal = ((obj.config.max - displayVal) * 1).toFixed(obj.config.decimals) + obj.config.symbol;
} else {
displayVal = (displayVal * 1).toFixed(obj.config.decimals) + obj.config.symbol;
displayVal = (displayVal * 1).toFixed(obj.config.decimals) + obj.config.symbol;
}
obj.originalValue = displayVal;
obj.originalValue = displayVal;
obj.config.value = val * 1;

if (!obj.config.counter) {
Expand Down

0 comments on commit b4fd547

Please sign in to comment.