BarIndicator.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. define("dojox/gauges/BarIndicator", ["dojo/_base/declare","dojo/_base/fx","dojo/_base/connect","dojo/_base/lang","./BarLineIndicator"],
  2. function(declare, fx, connect, lang, BarLineIndicator) {
  3. /*=====
  4. BarLineIndicator = dojox.gauges.BarLineIndicator;
  5. =====*/
  6. return declare("dojox.gauges.BarIndicator",[BarLineIndicator],{
  7. // summary:
  8. // An indicator for the BarGauge that draws a bar corresponding to the indicator value.
  9. _getShapes: function(group){
  10. // summary:
  11. // Override of dojox.gauges.BarLineIndicator._getShapes
  12. if(!this._gauge){
  13. return null;
  14. }
  15. var v = this.value;
  16. if(v < this._gauge.min){v = this._gauge.min;}
  17. if(v > this._gauge.max){v = this._gauge.max;}
  18. var pos = this._gauge._getPosition(v);
  19. if(pos == this.dataX){pos = this.dataX+1;}
  20. var y = this._gauge.dataY + Math.floor((this._gauge.dataHeight - this.width)/2) + this.offset;
  21. var shapes = [];
  22. shapes[0] = group.createRect({x:this._gauge.dataX, y:y, width:pos - this._gauge.dataX, height:this.width});
  23. shapes[0].setStroke({color: this.color});
  24. shapes[0].setFill(this.color);
  25. shapes[1] = group.createLine({ x1:this._gauge.dataX, y1:y, x2:pos, y2:y });
  26. shapes[1].setStroke({color: this.highlight});
  27. if(this.highlight2){
  28. y--;
  29. shapes[2] = group.createLine({ x1:this._gauge.dataX, y1:y, x2:pos, y2:y });
  30. shapes[2].setStroke({color: this.highlight2});
  31. }
  32. return shapes;
  33. },
  34. _createShapes: function(val){
  35. // summary:
  36. // Creates a shallow copy of the current shapes while adjusting for the new value
  37. for(var i in this.shape.children){
  38. i = this.shape.children[i];
  39. var newShape = {};
  40. for(var j in i){
  41. newShape[j] = i[j];
  42. }
  43. if(i.shape.type == "line"){
  44. newShape.shape.x2 = val+newShape.shape.x1;
  45. }else if(i.shape.type == "rect"){
  46. newShape.width = val;
  47. }
  48. i.setShape(newShape);
  49. }
  50. },
  51. _move: function(/*Boolean?*/ dontAnimate){
  52. // summary:
  53. // Override of dojox.gauges.BarLineIndicator._move to resize the bar (rather than moving it)
  54. var c;
  55. var v = this.value ;
  56. if(v < this.min){v = this.min;}
  57. if(v > this.max){v = this.max;}
  58. c = this._gauge._getPosition(this.currentValue);
  59. this.currentValue = v;
  60. v = this._gauge._getPosition(v)-this._gauge.dataX;
  61. if(dontAnimate){
  62. this._createShapes(v);
  63. }else{
  64. if(c!=v){
  65. var anim = new fx.Animation({curve: [c, v], duration: this.duration, easing: this.easing});
  66. connect.connect(anim, "onAnimate", lang.hitch(this, this._createShapes));
  67. anim.play();
  68. }
  69. }
  70. }
  71. });
  72. });