TextIndicator.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. define("dojox/gauges/TextIndicator", ["dojo/_base/declare","./_Indicator"],
  2. function(declare, Indicator) {
  3. /*=====
  4. Indicator = dojox.gauges._Indicator;
  5. =====*/
  6. return declare("dojox.gauges.TextIndicator", [Indicator], {
  7. // summary:
  8. // A gauge indicator the simply draws its value as text.
  9. // x: Number
  10. // The x coordinate of the indicator
  11. x: 0,
  12. // y: Number
  13. // The y coordinate of the indicator
  14. y: 0,
  15. // align: String
  16. // The horizontal alignment of the text, the value can be 'middle' (the default), 'left' or 'right'
  17. align: 'middle',
  18. // fixedPrecision: Boolean
  19. // Indicates that the number is displayed in fixed precision or not (precision is defined by the 'precision' property (default is true).
  20. fixedPrecision: true,
  21. // precision: Number
  22. // The number of tailing digits to display the value of the indicator when the 'fixedPrecision' property is set to true (default is 0).
  23. precision: 0,
  24. draw: function(group, /*Boolean?*/ dontAnimate){
  25. // summary:
  26. // Override of dojox.gauges._Indicator.draw
  27. var v = this.value;
  28. if (v < this._gauge.min) {
  29. v = this._gauge.min;
  30. }
  31. if (v > this._gauge.max) {
  32. v = this._gauge.max;
  33. }
  34. var txt;
  35. var NumberUtils = this._gauge ? this._gauge._getNumberModule() : null;
  36. if (NumberUtils) {
  37. txt = this.fixedPrecision ? NumberUtils.format(v, {
  38. places: this.precision
  39. }) : NumberUtils.format(v);
  40. } else {
  41. txt = this.fixedPrecision ? v.toFixed(this.precision) : v.toString();
  42. }
  43. var x = this.x ? this.x : 0;
  44. var y = this.y ? this.y : 0;
  45. var align = this.align ? this.align : "middle";
  46. if(!this.shape){
  47. this.shape = group.createText({
  48. x: x,
  49. y: y,
  50. text: txt,
  51. align: align
  52. });
  53. }else{
  54. this.shape.setShape({
  55. x: x,
  56. y: y,
  57. text: txt,
  58. align: align
  59. });
  60. }
  61. this.shape.setFill(this.color);
  62. if (this.font) this.shape.setFont(this.font);
  63. }
  64. });
  65. });