BarLineIndicator.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. define("dojox/gauges/BarLineIndicator", ["dojo/_base/declare","dojo/_base/fx","dojo/_base/connect","dojo/_base/lang", "dojox/gfx", "./_Indicator"],
  2. function(declare, fx, connect, lang, gfx, Indicator) {
  3. /*=====
  4. Indicator = dojox.gauges._Indicator;
  5. =====*/
  6. return declare("dojox.gauges.BarLineIndicator",[Indicator],{
  7. // summary:
  8. // An indicator for the BarGauge that draws a segment a line corresponding to the indicator value.
  9. width: 1,
  10. _getShapes: function(/*dojox.gfx.Group*/ group){
  11. // summary:
  12. // Private function for generating the shapes for this indicator. An indicator that behaves the
  13. // same might override this one and simply replace the shapes (such as BarIndicator).
  14. if(!this._gauge){
  15. return null;
  16. }
  17. var v = this.value;
  18. if(v < this._gauge.min){v = this._gauge.min;}
  19. if(v > this._gauge.max){v = this._gauge.max;}
  20. var pos = this._gauge._getPosition(v);
  21. var shapes = [];
  22. if(this.width > 1){
  23. shapes[0] = group.createRect({
  24. x:0,
  25. y:this._gauge.dataY + this.offset,
  26. width:this.width,
  27. height:this.length
  28. });
  29. shapes[0].setStroke({color: this.color});
  30. shapes[0].setFill(this.color);
  31. shapes[0].setTransform(gfx.matrix.translate(pos,0));
  32. }else{
  33. shapes[0] = group.createLine({
  34. x1:0,
  35. y1:this._gauge.dataY + this.offset,
  36. x2:0,
  37. y2:this._gauge.dataY + this.offset + this.length
  38. });
  39. shapes[0].setStroke({color: this.color});
  40. shapes[0].setTransform(gfx.matrix.translate(pos,0));
  41. }
  42. return shapes;
  43. },
  44. draw: function(/*dojox.gfx.Group*/group, /*Boolean?*/ dontAnimate){
  45. // summary:
  46. // Override of dojox.gauges._Indicator.draw
  47. // dontAnimate: Boolean
  48. // Indicates if the drawing should not be animated (vs. the default of doing an animation)
  49. var i;
  50. if (this.shape){
  51. this._move(dontAnimate);
  52. }else{
  53. if (this.shape){
  54. this.shape.parent.remove(this.shape);
  55. this.shape = null;
  56. }
  57. if (this.text){
  58. this.text.parent.remove(this.text);
  59. this.text = null;
  60. }
  61. this.color = this.color || '#000000';
  62. this.length = this.length || this._gauge.dataHeight;
  63. this.width = this.width || 3;
  64. this.offset = this.offset || 0;
  65. this.highlight = this.highlight || '#4D4D4D';
  66. this.highlight2 = this.highlight2 || '#A3A3A3';
  67. var shapes = this._getShapes(group, this._gauge, this);
  68. if (shapes.length > 1){
  69. this.shape = group.createGroup();
  70. for (var s = 0; s < shapes.length; s++){
  71. this.shape.add(shapes[s]);
  72. }
  73. } else this.shape = shapes[0];
  74. if (this.label){
  75. var v = this.value;
  76. if (v < this._gauge.min){
  77. v = this._gauge.min;
  78. }
  79. if (v > this._gauge.max){
  80. v = this._gauge.max;
  81. }
  82. var pos = this._gauge._getPosition(v);
  83. if (this.direction == 'inside'){
  84. var font = this.font ? this.font : gfx.defaultFont;
  85. var fz = font.size;
  86. var th = gfx.normalizedLength(fz);
  87. this.text = this._gauge.drawText(group, '' + this.label, pos, this._gauge.dataY + this.offset + this.length + 5 + th, 'middle', this.color, this.font);
  88. } else this.text = this._gauge.drawText(group, '' + this.label, pos, this._gauge.dataY + this.offset - 5, 'middle', this.color, this.font);
  89. }
  90. this.shape.connect("onmouseover", this, this.handleMouseOver);
  91. this.shape.connect("onmouseout", this, this.handleMouseOut);
  92. this.shape.connect("onmousedown", this, this.handleMouseDown);
  93. this.shape.connect("touchstart", this, this.handleTouchStart);
  94. this.currentValue = this.value;
  95. }
  96. },
  97. _move: function(/*Boolean?*/ dontAnimate){
  98. // summary:
  99. // Moves this indicator (since it's already been drawn once)
  100. // dontAnimate: Boolean
  101. // Indicates if the drawing should not be animated (vs. the default of doing an animation)
  102. var v = this.value ;
  103. if(v < this._gauge.min){v = this._gauge.min;}
  104. if(v > this._gauge.max){v = this._gauge.max;}
  105. var c = this._gauge._getPosition(this.currentValue);
  106. this.currentValue = v;
  107. v = this._gauge._getPosition(v);
  108. if(dontAnimate || (c==v)){
  109. this.shape.setTransform(gfx.matrix.translate(v,0));
  110. }else{
  111. var anim = new fx.Animation({curve: [c, v], duration: this.duration, easing: this.easing});
  112. connect.connect(anim, "onAnimate", lang.hitch(this, function(jump){
  113. if (this.shape)
  114. this.shape.setTransform(gfx.matrix.translate(jump,0));
  115. }));
  116. anim.play();
  117. }
  118. }
  119. });
  120. });