AnalogArcIndicator.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. define("dojox/gauges/AnalogArcIndicator", ["dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","dojo/_base/fx","./AnalogIndicatorBase"],
  2. function(declare, lang, connect, fx, AnalogIndicatorBase) {
  3. /*=====
  4. AnalogIndicatorBase = dojox.gauges.AnalogIndicatorBase;
  5. =====*/
  6. return declare("dojox.gauges.AnalogArcIndicator",[AnalogIndicatorBase],{
  7. // summary:
  8. // An indicator for the AnalogGauge that draws a segment of arc.
  9. // The segment of arc starts at the start angle of the gauge and ends at the
  10. // angle that corresponds to the value of the indicator.
  11. _createArc: function(val){
  12. // Creating the Arc Path string manually. This is instead of creating new dojox.gfx.Path object
  13. // each time since we really just need the Path string (to use with setShape) and we don't want to
  14. // have to redo the connects, etc.
  15. if(this.shape){
  16. var startAngle = this._gauge._mod360(this._gauge.startAngle);
  17. var a = this._gauge._getRadians(this._gauge._getAngle(val));
  18. var sa = this._gauge._getRadians(startAngle);
  19. if (this._gauge.orientation == 'cclockwise'){
  20. var tmp = a;
  21. a = sa;
  22. sa = tmp;
  23. }
  24. var arange;
  25. var big = 0;
  26. if (sa<=a)
  27. arange = a-sa;
  28. else
  29. arange = 2*Math.PI+a-sa;
  30. if(arange>Math.PI){big=1;}
  31. var cosa = Math.cos(a);
  32. var sina = Math.sin(a);
  33. var cossa = Math.cos(sa);
  34. var sinsa = Math.sin(sa);
  35. var off = this.offset + this.width;
  36. var p = ['M'];
  37. p.push(this._gauge.cx+this.offset*sinsa);
  38. p.push(this._gauge.cy-this.offset*cossa);
  39. p.push('A', this.offset, this.offset, 0, big, 1);
  40. p.push(this._gauge.cx+this.offset*sina);
  41. p.push(this._gauge.cy-this.offset*cosa);
  42. p.push('L');
  43. p.push(this._gauge.cx+off*sina);
  44. p.push(this._gauge.cy-off*cosa);
  45. p.push('A', off, off, 0, big, 0);
  46. p.push(this._gauge.cx+off*sinsa);
  47. p.push(this._gauge.cy-off*cossa);
  48. p.push('z');
  49. this.shape.setShape(p.join(' '));
  50. this.currentValue = val;
  51. }
  52. },
  53. draw: function(group, /*Boolean?*/ dontAnimate){
  54. // summary:
  55. // Override of dojox.gauges._Indicator.draw
  56. var v = this.value;
  57. if(v < this._gauge.min){v = this._gauge.min;}
  58. if(v > this._gauge.max){v = this._gauge.max;}
  59. if(this.shape){
  60. if(dontAnimate){
  61. this._createArc(v);
  62. }else{
  63. var anim = new fx.Animation({curve: [this.currentValue, v], duration: this.duration, easing: this.easing});
  64. connect.connect(anim, "onAnimate", lang.hitch(this, this._createArc));
  65. anim.play();
  66. }
  67. }else{
  68. var color = this.color ? this.color : 'black';
  69. var strokeColor = this.strokeColor ? this.strokeColor : color;
  70. var stroke = {color: strokeColor, width: 1};
  71. if(this.color.type && !this.strokeColor){
  72. stroke.color = this.color.colors[0].color;
  73. }
  74. this.shape = group.createPath().setStroke(stroke).setFill(color);
  75. this._createArc(v);
  76. this.shape.connect("onmouseover", this, this.handleMouseOver);
  77. this.shape.connect("onmouseout", this, this.handleMouseOut);
  78. this.shape.connect("onmousedown", this, this.handleMouseDown);
  79. this.shape.connect("touchstart", this, this.handleTouchStart);
  80. }
  81. }
  82. });
  83. });