AnalogArcIndicator.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.AnalogArcIndicator']){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource['dojox.widget.gauge.AnalogArcIndicator'] = true;
  8. dojo.provide('dojox.widget.gauge.AnalogArcIndicator');
  9. dojo.require('dojox.widget.AnalogGauge');
  10. dojo.experimental("dojox.widget.gauge.AnalogArcIndicator");
  11. dojo.declare("dojox.widget.gauge.AnalogArcIndicator",[dojox.widget.gauge.AnalogLineIndicator],{
  12. _createArc: function(val){
  13. // Creating the Arc Path string manually. This is instead of creating new dojox.gfx.Path object
  14. // each time since we really just need the Path string (to use with setShape) and we don't want to
  15. // have to redo the connects, etc.
  16. if(this.shapes[0]){
  17. var a = this._gauge._getRadians(this._gauge._getAngle(val));
  18. var cosa = Math.cos(a);
  19. var sina = Math.sin(a);
  20. var sa = this._gauge._getRadians(this._gauge.startAngle);
  21. var cossa = Math.cos(sa);
  22. var sinsa = Math.sin(sa);
  23. var off = this.offset + this.width;
  24. var p = ['M'];
  25. p.push(this._gauge.cx+this.offset*sinsa);
  26. p.push(this._gauge.cy-this.offset*cossa);
  27. p.push('A', this.offset, this.offset, 0, ((a-sa)>Math.PI)?1:0, 1);
  28. p.push(this._gauge.cx+this.offset*sina);
  29. p.push(this._gauge.cy-this.offset*cosa);
  30. p.push('L');
  31. p.push(this._gauge.cx+off*sina);
  32. p.push(this._gauge.cy-off*cosa);
  33. p.push('A', off, off, 0, ((a-sa)>Math.PI)?1:0, 0);
  34. p.push(this._gauge.cx+off*sinsa);
  35. p.push(this._gauge.cy-off*cossa);
  36. this.shapes[0].setShape(p.join(' '));
  37. this.currentValue = val;
  38. }
  39. },
  40. draw: function(/*Boolean?*/ dontAnimate){
  41. // summary:
  42. // Override of dojox.widget._Indicator.draw
  43. var v = this.value;
  44. if(v < this._gauge.min){v = this._gauge.min;}
  45. if(v > this._gauge.max){v = this._gauge.max;}
  46. if(this.shapes){
  47. if(dontAnimate){
  48. this._createArc(v);
  49. }else{
  50. var anim = new dojo.Animation({curve: [this.currentValue, v], duration: this.duration, easing: this.easing});
  51. dojo.connect(anim, "onAnimate", dojo.hitch(this, this._createArc));
  52. anim.play();
  53. }
  54. }else{
  55. var stroke = {color: this.color, width: 1};
  56. if(this.color.type){
  57. stroke.color = this.color.colors[0].color;
  58. }
  59. this.shapes = [this._gauge.surface.createPath()
  60. .setStroke(stroke).setFill(this.color)];
  61. this._createArc(v);
  62. if(this.hover){
  63. this.shapes[0].getEventSource().setAttribute('hover',this.hover);
  64. }
  65. if(this.onDragMove && !this.noChange){
  66. this._gauge.connect(this.shapes[0].getEventSource(), 'onmousedown', this._gauge.handleMouseDown);
  67. this.shapes[0].getEventSource().style.cursor = 'pointer';
  68. }
  69. }
  70. }
  71. });
  72. }