BarIndicator.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource['dojox.widget.gauge.BarIndicator']){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource['dojox.widget.gauge.BarIndicator'] = true;
  8. dojo.provide('dojox.widget.gauge.BarIndicator');
  9. dojo.require('dojox.widget.BarGauge');
  10. dojo.experimental("dojox.widget.gauge.BarIndicator");
  11. dojo.declare("dojox.widget.gauge.BarIndicator",[dojox.widget.gauge.BarLineIndicator],{
  12. _getShapes: function(){
  13. // summary:
  14. // Override of dojox.widget.BarLineIndicator._getShapes
  15. if(!this._gauge){
  16. return null;
  17. }
  18. var v = this.value;
  19. if(v < this._gauge.min){v = this._gauge.min;}
  20. if(v > this._gauge.max){v = this._gauge.max;}
  21. var pos = this._gauge._getPosition(v);
  22. if(pos == this.dataX){pos = this.dataX+1;}
  23. var y = this._gauge.dataY + Math.floor((this._gauge.dataHeight - this.width)/2) + this.offset;
  24. var shapes = [];
  25. shapes[0] = this._gauge.surface.createRect({x:this._gauge.dataX, y:y, width:pos - this._gauge.dataX, height:this.width});
  26. shapes[0].setStroke({color: this.color});
  27. shapes[0].setFill(this.color);
  28. shapes[1] = this._gauge.surface.createLine({ x1:this._gauge.dataX, y1:y, x2:pos, y2:y });
  29. shapes[1].setStroke({color: this.highlight});
  30. if(this.highlight2){
  31. y--;
  32. shapes[2] = this._gauge.surface.createLine({ x1:this._gauge.dataX, y1:y, x2:pos, y2:y });
  33. shapes[2].setStroke({color: this.highlight2});
  34. }
  35. return shapes;
  36. },
  37. _createShapes: function(val){
  38. // summary:
  39. // Creates a shallow copy of the current shapes while adjusting for the new value
  40. for(var i in this.shapes){
  41. i = this.shapes[i];
  42. var newShape = {};
  43. for(var j in i){
  44. newShape[j] = i[j];
  45. }
  46. if(i.shape.type == "line"){
  47. newShape.shape.x2 = val+newShape.shape.x1;
  48. }else if(i.shape.type == "rect"){
  49. newShape.width = val;
  50. }
  51. i.setShape(newShape);
  52. }
  53. },
  54. _move: function(/*Boolean?*/ dontAnimate){
  55. // summary:
  56. // Override of dojox.widget.BarLineIndicator._move to resize the bar (rather than moving it)
  57. var changed = false;
  58. var c;
  59. var v = this.value ;
  60. if(v < this.min){v = this.min;}
  61. if(v > this.max){v = this.max;}
  62. c = this._gauge._getPosition(this.currentValue);
  63. this.currentValue = v;
  64. v = this._gauge._getPosition(v)-this._gauge.dataX;
  65. if(dontAnimate){
  66. this._createShapes(v);
  67. }else{
  68. if(c!=v){
  69. var anim = new dojo.Animation({curve: [c, v], duration: this.duration, easing: this.easing});
  70. dojo.connect(anim, "onAnimate", dojo.hitch(this, this._createShapes));
  71. anim.play();
  72. }
  73. }
  74. }
  75. });
  76. }