Skip to content

Commit

Permalink
add external rendering function for displayed value
Browse files Browse the repository at this point in the history
  • Loading branch information
tristan-c committed Nov 23, 2012
1 parent a5f8a9a commit ef3a0f7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions justgage.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ JustGage = function(config) {
// number of decimal places for our human friendly number to contain
humanFriendlyDecimal : (config.humanFriendlyDecimal) ? config.humanFriendlyDecimal : 0,

// textRenderer: func
// function applied before rendering text
textRenderer : (config.textRenderer) ? config.textRenderer : null,

// gaugeWidthScale : float
// width of the gauge element
gaugeWidthScale : (config.gaugeWidthScale) ? config.gaugeWidthScale : 1.0,
Expand Down Expand Up @@ -414,8 +418,12 @@ JustGage = function(config) {
this.txtTitle.id = this.config.id+"-txttitle";

// value
if( this.config.humanFriendly ) this.originalValue = humanFriendlyNumber( this.originalValue, this.config.humanFriendlyDecimal );
this.txtValue = this.canvas.text(this.params.valueX, this.params.valueY, this.originalValue + this.config.symbol);
if(this.config.textRenderer)
this.originalValue = this.config.textRenderer(this.originalValue);
else if( this.config.humanFriendly )
this.originalValue = humanFriendlyNumber( this.originalValue, this.config.humanFriendlyDecimal ) + this.config.symbol;

this.txtValue = this.canvas.text(this.params.valueX, this.params.valueY, this.originalValue);
this.txtValue. attr({
"font-size":this.params.valueFontSize,
"font-weight":"bold",
Expand Down Expand Up @@ -493,8 +501,13 @@ JustGage.prototype.refresh = function(val) {
if (val < this.config.min) {val = this.config.min;}

var color = getColorForPercentage((val - this.config.min) / (this.config.max - this.config.min), this.config.levelColors, this.config.levelColorsGradient);
if( this.config.humanFriendly ) displayVal = humanFriendlyNumber( displayVal, this.config.humanFriendlyDecimal );
this.canvas.getById(this.config.id+"-txtvalue").attr({"text":displayVal + this.config.symbol});

if(this.config.textRenderer)
displayVal = this.config.textRenderer(displayVal);
else if( this.config.humanFriendly )
displayVal = humanFriendlyNumber( displayVal, this.config.humanFriendlyDecimal ) + this.config.symbol;

this.canvas.getById(this.config.id+"-txtvalue").attr({"text":displayVal});
this.canvas.getById(this.config.id+"-level").animate({pki: [val, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut], "fill":color}, this.config.refreshAnimationTime, this.config.refreshAnimationType);
this.config.value = val;
originalVal = null;
Expand Down

0 comments on commit ef3a0f7

Please sign in to comment.