_Gauge.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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._Gauge"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.widget.gauge._Gauge"] = true;
  8. dojo.provide("dojox.widget.gauge._Gauge");
  9. dojo.require("dijit._Widget");
  10. dojo.require("dijit._Templated");
  11. dojo.require("dijit._Container");
  12. dojo.require("dijit._Contained");
  13. dojo.require("dijit.Tooltip");
  14. dojo.require("dojo.fx.easing");
  15. dojo.require("dojox.gfx");
  16. dojo.experimental("dojox.widget.gauge._Gauge");
  17. dojo.declare("dojox.widget.gauge._Gauge",[dijit._Widget, dijit._Templated, dijit._Container],{
  18. // summary:
  19. // a gauge built using the dojox.gfx package.
  20. //
  21. // description:
  22. // using dojo.gfx (and thus either SVG or VML based on what is supported), this widget
  23. // builds a gauge component, used to display numerical data in a familiar format
  24. //
  25. // usage:
  26. // this widget is not to be used alone. it is meant to be subclassed, such as
  27. // dojox.widget.BarGauge or dojox.widget.AnalogGauge
  28. // width: Number
  29. // the width of the gauge (default is 300)
  30. width: 0,
  31. // height: Number
  32. // the height of the gauge (default is 200)
  33. height: 0,
  34. // background: Object
  35. // the color of the background. This must be an object of one of two forms:
  36. // {'color': 'color-name'}
  37. // OR
  38. // (for a gradient:)
  39. // {'type': 'linear', 'x1': 0, 'x2': 0, 'y1': 0, 'y2': 200, 'colors': [{offset: 0, color:'#C0C0C0'}, {offset: 1, color: '#E0E0E0'}] }
  40. background: null,
  41. // min: Number
  42. // minimum value displayed by gauge (default is lowest range value)
  43. min: 0,
  44. // max: Number
  45. // maximum value displayed by gauge (default is largest range value)
  46. max: 0,
  47. // image: String
  48. // background image for gauge (default is no image)
  49. image: null,
  50. // useRangeStyles: Number
  51. // indicates whether to use given css classes (dojoxGaugeRangeXX)
  52. // to determine the color (and other style attributes?) of the ranges
  53. // this value should be the number of dojoxGaugeRange classes that are
  54. // defined, starting at dojoxGaugeRange1 (0 indicates falling to default
  55. // hardcoded colors)
  56. useRangeStyles: 0,
  57. // useTooltip: Boolean
  58. // indicates whether tooltips should be displayed for ranges, indicators, etc.
  59. useTooltip: true,
  60. // majorTicks: Object
  61. // An object representing the tick marks that should be added to the gauge. Major tick marks have a text label
  62. // indicating the value. The object can have the following attributes (required are marked with a *):
  63. // offset: the distance from the 'center' of the gauge. Used differently for Analog vs. Bar
  64. // width: The width of the mark
  65. // length: The length of the mark
  66. // interval: The interval the ticks should be added on
  67. // color: The color of the mark and text
  68. // font: an object with any/all of the following parameters:
  69. // {family: "Helvetica", style: "italic", variant: 'small-caps', weight: 'bold', size: "18pt"}
  70. majorTicks: null,
  71. // minorTicks: Object
  72. // An object of the same format as majorTicks, indicating where the minor (label-less) marks should be placed
  73. // The font parameter is ignored if provided since minor tick marks have no text label.
  74. minorTicks: null,
  75. // _defaultIndicator: Objection
  76. // Should be overridden by any extending classes and used to indicate what the 'default' indicator is.
  77. // This object is used as the indicator when creating tick marks or when an anonmyous object is passed into
  78. // addIndicator.
  79. _defaultIndicator: null,
  80. // defaultColors: Array
  81. // Set of default colors to color ranges with.
  82. defaultColors: [[0x00,0x54,0xAA,1],
  83. [0x44,0x77,0xBB,1],
  84. [0x66,0x99,0xCC,1],
  85. [0x99,0xBB,0xEE,1],
  86. [0x99,0xCC,0xFF,1],
  87. [0xCC,0xEE,0xFF,1],
  88. [0xDD,0xEE,0xFF,1]],
  89. // min: Number
  90. // The minimum value of the gauge. Normally not set explicitly, as it will be determined by
  91. // the ranges that are added.
  92. min: null,
  93. // max: Number
  94. // The maximum value of the gauge. Normally not set explicitly, as it will be determined by
  95. // the ranges that are added.
  96. max: null,
  97. // surface: Object
  98. // The SVG/VML surface that the shapes are drawn on. Can be accessed/used by indicators to draw themselves
  99. surface: null,
  100. // hideValues: Boolean
  101. // indicates whether the text boxes showing the value of the indicator (as text
  102. // content) should be hidden or shown. Default is not hidden, aka shown.
  103. hideValues: false,
  104. // internal data
  105. gaugeContent: undefined,
  106. templateString: dojo.cache("dojox.widget.gauge", "_Gauge.html", "<div>\n\t<div class=\"dojoxGaugeContent\" dojoAttachPoint=\"gaugeContent\"></div>\n\t<div dojoAttachPoint=\"containerNode\"></div>\n\t<div dojoAttachPoint=\"mouseNode\"></div>\n</div>\n"),
  107. _backgroundDefault: {color: '#E0E0E0'},
  108. _rangeData: null,
  109. _indicatorData: null,
  110. _drag: null,
  111. _img: null,
  112. _overOverlay: false,
  113. _lastHover: '',
  114. startup: function(){
  115. // handle settings from HTML by making sure all the options are
  116. // converted correctly to numbers and that we calculate defaults
  117. // for cx, cy and radius
  118. if(this.image === null){
  119. this.image={};
  120. }
  121. this.connect(this.gaugeContent, 'onmousemove', this.handleMouseMove);
  122. this.connect(this.gaugeContent, 'onmouseover', this.handleMouseOver);
  123. this.connect(this.gaugeContent, 'onmouseout', this.handleMouseOut);
  124. this.connect(this.gaugeContent, 'onmouseup', this.handleMouseUp);
  125. if(!dojo.isArray(this.ranges)){ this.ranges = []; }
  126. if(!dojo.isArray(this.indicators)){ this.indicators = []; }
  127. var ranges = [], indicators = [];
  128. var i;
  129. if(this.hasChildren()){
  130. var children = this.getChildren();
  131. for(i=0; i<children.length; i++){
  132. if(/dojox\.widget\..*Indicator/.test(children[i].declaredClass)){
  133. indicators.push(children[i]);
  134. //this.addIndicator(children[i]);
  135. continue;
  136. }
  137. switch(children[i].declaredClass){
  138. case "dojox.widget.gauge.Range":
  139. ranges.push(children[i]);
  140. break;
  141. }
  142. }
  143. this.ranges = this.ranges.concat(ranges);
  144. this.indicators = this.indicators.concat(indicators);
  145. }
  146. if(!this.background){ this.background = this._backgroundDefault; }
  147. this.background = this.background.color || this.background;
  148. if(!this.surface){ this.createSurface(); }
  149. this.addRanges(this.ranges);
  150. if(this.minorTicks && this.minorTicks.interval){
  151. this.setMinorTicks(this.minorTicks);
  152. }
  153. if(this.majorTicks && this.majorTicks.interval){
  154. this.setMajorTicks(this.majorTicks);
  155. }
  156. for(i=0; i<this.indicators.length; i++){
  157. this.addIndicator(this.indicators[i]);
  158. }
  159. },
  160. _setTicks: function(/*Object*/ oldTicks, /*Object*/ newTicks, /*Boolean*/ label){
  161. // summary:
  162. // internal method used to clear existing tick marks, then add new ones
  163. var i;
  164. if(oldTicks && dojo.isArray(oldTicks._ticks)){
  165. for(i=0; i<oldTicks._ticks.length; i++){
  166. this.removeIndicator(oldTicks._ticks[i]);
  167. }
  168. }
  169. var t = {length: newTicks.length,
  170. offset: newTicks.offset,
  171. noChange: true};
  172. if(newTicks.color){ t.color = newTicks.color; }
  173. if(newTicks.font){ t.font = newTicks.font; }
  174. newTicks._ticks = [];
  175. for(i=this.min; i<=this.max; i+=newTicks.interval){
  176. t.value = i;
  177. if(label){t.label = ''+i;}
  178. newTicks._ticks.push(this.addIndicator(t));
  179. }
  180. return newTicks;
  181. },
  182. setMinorTicks: function(/*Object*/ ticks){
  183. // summary:
  184. // Creates and draws the minor tick marks based on the passed object (expecting the same format
  185. // as the minorTicks object documented above)
  186. this.minorTicks = this._setTicks(this.minorTicks, ticks, false);
  187. },
  188. setMajorTicks: function(/*Object*/ ticks){
  189. // summary:
  190. // Creates and draws the major tick marks based on the passed object (expecting the same format
  191. // as the majorTicks object documented above)
  192. this.majorTicks = this._setTicks(this.majorTicks, ticks, true);
  193. },
  194. postCreate: function(){
  195. if(this.hideValues){
  196. dojo.style(this.containerNode, "display", "none");
  197. }
  198. dojo.style(this.mouseNode, 'width', '0');
  199. dojo.style(this.mouseNode, 'height', '0');
  200. dojo.style(this.mouseNode, 'position', 'absolute');
  201. dojo.style(this.mouseNode, 'z-index', '100');
  202. if(this.useTooltip){
  203. dijit.showTooltip('test',this.mouseNode, !this.isLeftToRight());
  204. dijit.hideTooltip(this.mouseNode);
  205. }
  206. },
  207. createSurface: function(){
  208. // summary:
  209. // internal method used by the gauge to create the graphics surface area
  210. this.gaugeContent.style.width = this.width + 'px';
  211. this.gaugeContent.style.height = this.height + 'px';
  212. this.surface = dojox.gfx.createSurface(this.gaugeContent, this.width, this.height);
  213. this._background = this.surface.createRect({x: 0, y: 0, width: this.width, height: this.height });
  214. this._background.setFill(this.background);
  215. if(this.image.url){
  216. this._img = this.surface.createImage({width: this.image.width || this.width, height: this.image.height || this.height, src: this.image.url});
  217. if(this.image.overlay){
  218. this._img.getEventSource().setAttribute('overlay',true);
  219. }
  220. if(this.image.x || this.image.y){
  221. this._img.setTransform({dx: this.image.x || 0, dy: this.image.y || 0});
  222. }
  223. }
  224. },
  225. setBackground: function(background){
  226. // summary:
  227. // This method is used to set the background of the gauge after it is created.
  228. // description:
  229. // Sets the background using the given object. Must be the same 'type' of object
  230. // as the original background argument.
  231. // background:
  232. // An object in one of the two forms:
  233. // {'color': 'color-name'}
  234. // OR
  235. // (for a gradient:)
  236. // {'type': 'linear', 'colors': [{offset: 0, color:'#C0C0C0'}, {offset: 1, color: '#E0E0E0'}] }
  237. // If background is null or undefined, this will set the fill to this._backgroundDefault
  238. if(!background){ background = this._backgroundDefault; }
  239. this.background = background.color || background;
  240. this._background.setFill(this.background);
  241. },
  242. addRange: function(/*Object*/range){
  243. // summary:
  244. // This method is used to add a range to the gauge.
  245. // description:
  246. // Creates a range (colored area on the background of the gauge)
  247. // based on the given arguments.
  248. // range:
  249. // A range is either a dojox.widget.gauge.Range object, or a object
  250. // with similar parameters (low, high, hover, etc.).
  251. this.addRanges([range]);
  252. },
  253. addRanges: function(/*Array*/ranges){
  254. // summary:
  255. // This method is used to add ranges to the gauge.
  256. // description:
  257. // Creates a range (colored area on the background of the gauge)
  258. // based on the given arguments.
  259. // range:
  260. // A range is either a dojox.widget.gauge.Range object, or a object
  261. // with similar parameters (low, high, hover, etc.).
  262. if(!this._rangeData){
  263. this._rangeData = [];
  264. }
  265. var range;
  266. for(var i=0; i<ranges.length; i++){
  267. range = ranges[i];
  268. if((this.min === null) || (range.low < this.min)){this.min = range.low;}
  269. if((this.max === null) || (range.high > this.max)){this.max = range.high;}
  270. if(!range.color){
  271. var colorIndex = this._rangeData.length % this.defaultColors.length;
  272. if(dojox.gfx.svg && this.useRangeStyles > 0){
  273. colorIndex = (this._rangeData.length % this.useRangeStyles)+1;
  274. range.color = {style: "dojoxGaugeRange"+colorIndex};
  275. }else{
  276. colorIndex = this._rangeData.length % this.defaultColors.length;
  277. range.color = this.defaultColors[colorIndex];
  278. }
  279. }
  280. this._rangeData[this._rangeData.length] = range;
  281. }
  282. this.draw();
  283. },
  284. addIndicator: function(/*Object*/indicator){
  285. // summary:
  286. // This method is used to add an indicator to the bar graph.
  287. // description:
  288. // This method adds an indicator, such as a tick mark or needle,
  289. // to the bar graph.
  290. // indicator:
  291. // A dojox.widget.gauge._Indicator or an object with similar parameters
  292. // (value, color, offset, etc.).
  293. indicator._gauge = this;
  294. if(!indicator.declaredClass){// !== 'dojox.widget.gauge.Indicator'){
  295. // We were passed a plain object, need to make an indicator out of it.
  296. indicator = new this._defaultIndicator(indicator);
  297. }
  298. if(!indicator.hideValue){
  299. this.containerNode.appendChild(indicator.domNode);
  300. }
  301. if(!this._indicatorData){this._indicatorData = [];}
  302. this._indicatorData[this._indicatorData.length] = indicator;
  303. indicator.draw();
  304. return indicator;
  305. },
  306. removeIndicator: function(/*Object*/indicator){
  307. // summary:
  308. // Removes the given indicator from the gauge by calling it's remove function
  309. // and removing it from the local cache.
  310. for(var i=0; i<this._indicatorData.length; i++){
  311. if(this._indicatorData[i] === indicator){
  312. this._indicatorData.splice(i, 1);
  313. indicator.remove();
  314. break;
  315. }
  316. }
  317. },
  318. moveIndicatorToFront: function(/*Object*/indicator){
  319. // summary:
  320. // This function is used to move an indicator the the front (top)
  321. // of the gauge
  322. // indicator:
  323. // A dojox.widget.gauge._Indicator or an object with similar parameters
  324. // (value, color, offset, etc.).
  325. if(indicator.shapes){
  326. for(var i=0; i<indicator.shapes.length; i++){
  327. indicator.shapes[i].moveToFront();
  328. }
  329. }
  330. },
  331. drawText: function(/*String*/txt, /*Number*/x, /*Number*/y, /*String?*/align, /*String?*/vAlign, /*String?*/color, /*Object?*/font){
  332. // summary:
  333. // This function is used draw text onto the gauge. The text object
  334. // is also returned by the function so that may be removed later
  335. // by calling removeText
  336. // txt: String
  337. // The text to be drawn
  338. // x: Number
  339. // The x coordinate at which to place the text
  340. // y: Number
  341. // The y coordinate at which to place the text
  342. // align?: String
  343. // Indicates how to align the text
  344. // Valid value is 'right', otherwise text is left-aligned
  345. // vAlign?: String
  346. // Indicates how to align the text vertically.
  347. // Valid value is 'top', otherwise text is bottom-aligned
  348. // color?: String
  349. // Indicates the color of the text
  350. // font?: Object
  351. // A font object, generally of the following format:
  352. // {family: "Helvetica", style: "italic", variant: 'small-caps', weight: 'bold', size: "18pt"}
  353. var t = this.surface.createText({x: x, y: y, text: txt, align: align});
  354. t.setFill(color);
  355. t.setFont(font);
  356. return t;
  357. },
  358. removeText:function(/*String*/t){
  359. // summary:
  360. // Removes a text element from the gauge.
  361. // t: String
  362. // The text to remove.
  363. this.surface.rawNode.removeChild(t);
  364. },
  365. updateTooltip: function(/*String*/txt, /*Event*/ e){
  366. // summary:
  367. // Updates the tooltip for the gauge to display the given text.
  368. // txt: String
  369. // The text to put in the tooltip.
  370. if(this._lastHover != txt){
  371. if(txt !== ''){
  372. dijit.hideTooltip(this.mouseNode);
  373. dijit.showTooltip(txt,this.mouseNode, !this.isLeftToRight());
  374. }else{
  375. dijit.hideTooltip(this.mouseNode);
  376. }
  377. this._lastHover = txt;
  378. }
  379. },
  380. handleMouseOver: function(/*Object*/event){
  381. // summary:
  382. // This is an internal handler used by the gauge to support
  383. // hover text
  384. // event: Object
  385. // The event object
  386. var hover = event.target.getAttribute('hover');
  387. if(event.target.getAttribute('overlay')){
  388. this._overOverlay = true;
  389. var r = this.getRangeUnderMouse(event);
  390. if(r && r.hover){
  391. hover = r.hover;
  392. }
  393. }
  394. if(this.useTooltip && !this._drag){
  395. if(hover){
  396. this.updateTooltip(hover, event);
  397. }else{
  398. this.updateTooltip('', event);
  399. }
  400. }
  401. },
  402. handleMouseOut: function(/*Object*/event){
  403. // summary:
  404. // This is an internal handler used by the gauge to support
  405. // hover text
  406. // event: Object
  407. // The event object
  408. if(event.target.getAttribute('overlay')){
  409. this._overOverlay = false;
  410. }
  411. if(this.useTooltip && this.mouseNode){
  412. dijit.hideTooltip(this.mouseNode);
  413. }
  414. },
  415. handleMouseDown: function(/*Object*/event){
  416. // summary:
  417. // This is an internal handler used by the gauge to support using
  418. // the mouse to drag an indicator to modify it's value
  419. // event: Object
  420. // The event object
  421. // find the indicator being dragged
  422. for(var i=0; i<this._indicatorData.length; i++){
  423. var shapes = this._indicatorData[i].shapes;
  424. for(var s=0; s<shapes.length; s++){
  425. if(shapes[s].getEventSource() == event.target){
  426. this._drag = this._indicatorData[i];
  427. s = shapes.length;
  428. i = this._indicatorData.length;
  429. }
  430. }
  431. }
  432. dojo.stopEvent(event);
  433. },
  434. handleMouseUp: function(/*Object*/event){
  435. // summary:
  436. // This is an internal handler used by the gauge to support using
  437. // the mouse to drag an indicator to modify it's value
  438. // event: Object
  439. // The event object
  440. this._drag = null;
  441. dojo.stopEvent(event);
  442. },
  443. handleMouseMove: function(/*Object*/event){
  444. // summary:
  445. // This is an internal handler used by the gauge to support using
  446. // the mouse to drag an indicator to modify it's value
  447. // event: Object
  448. // The event object
  449. if(event){
  450. dojo.style(this.mouseNode, 'left', event.pageX+1+'px');
  451. dojo.style(this.mouseNode, 'top', event.pageY+1+'px');
  452. }
  453. if(this._drag){
  454. this._dragIndicator(this, event);
  455. }else{
  456. if(this.useTooltip && this._overOverlay){
  457. var r = this.getRangeUnderMouse(event);
  458. if(r && r.hover){
  459. this.updateTooltip(r.hover, event);
  460. }else{
  461. this.updateTooltip('', event);
  462. }
  463. }
  464. }
  465. }
  466. });
  467. dojo.declare("dojox.widget.gauge.Range",[dijit._Widget, dijit._Contained],{
  468. // summary:
  469. // a range to be used in a _Gauge
  470. //
  471. // description:
  472. // a range widget, which has given properties. drawn by a _Gauge.
  473. //
  474. // usage:
  475. // <script type="text/javascript">
  476. // dojo.require("dojox.widget.AnalogGauge");
  477. // dojo.require("dijit.util.parser");
  478. // </script>
  479. // ...
  480. // <div dojoType="dojox.widget.AnalogGauge"
  481. // id="testGauge"
  482. // width="300"
  483. // height="200"
  484. // cx=150
  485. // cy=175
  486. // radius=125
  487. // image="gaugeOverlay.png"
  488. // imageOverlay="false"
  489. // imageWidth="280"
  490. // imageHeight="155"
  491. // imageX="12"
  492. // imageY="38">
  493. // <div dojoType="dojox.widget.gauge.Range"
  494. // low=5
  495. // high=10
  496. // hover="5 - 10"
  497. // ></div>
  498. // <div dojoType="dojox.widget.gauge.Range"
  499. // low=10
  500. // high=20
  501. // hover="10 - 20"
  502. // ></div>
  503. // </div>
  504. // low: Number
  505. // the low value of the range
  506. low: 0,
  507. // high: Numbe
  508. // the high value of the range
  509. high: 0,
  510. // hover: String
  511. // the text to put in the tooltip for the gauge
  512. hover: '',
  513. // color: Object
  514. // the color of the range. This must be an object of one of two forms:
  515. // {'color': 'color-name'}
  516. // OR
  517. // (for a gradient:)
  518. // {'type': 'linear', 'colors': [{offset: 0, color:'#C0C0C0'}, {offset: 1, color: '#E0E0E0'}] }
  519. color: null,
  520. // size: Number
  521. // for a circular gauge (such as an AnalogGauge), this dictates the size of the arc
  522. size: 0,
  523. startup: function(){
  524. this.color = this.color.color || this.color;
  525. }
  526. });
  527. dojo.declare("dojox.widget.gauge._Indicator",[dijit._Widget, dijit._Contained, dijit._Templated],{
  528. // summary:
  529. // a indicator to be used in a gauge
  530. //
  531. // description:
  532. // an indicator widget, which has given properties. drawn by a gauge.
  533. //
  534. // usage:
  535. // <script type="text/javascript">
  536. // dojo.require("dojox.widget.AnalogGauge");
  537. // dojo.require("dijit.util.parser");
  538. // </script>
  539. // ...
  540. // <div dojoType="dojox.widget.AnalogGauge"
  541. // id="testGauge"
  542. // width="300"
  543. // height="200"
  544. // cx=150
  545. // cy=175
  546. // radius=125
  547. // image="gaugeOverlay.png"
  548. // imageOverlay="false"
  549. // imageWidth="280"
  550. // imageHeight="155"
  551. // imageX="12"
  552. // imageY="38">
  553. // <div dojoType="dojox.widget.gauge.Indicator"
  554. // value=17
  555. // type="arrow"
  556. // length=135
  557. // width=3
  558. // hover="Value: 17"
  559. // onDragMove="handleDragMove">
  560. // </div>
  561. // </div>
  562. // value: Number
  563. // The value (on the gauge) that this indicator should be placed at
  564. value: 0,
  565. // type: String
  566. // The type of indicator to draw. Varies by gauge type. Some examples include
  567. // "line", "arrow", and "bar"
  568. type: '',
  569. // color: String
  570. // The color of the indicator.
  571. color: 'black',
  572. // label: String
  573. // The text label for the indicator.
  574. label: '',
  575. // font: Object
  576. // Generally in a format similar to:
  577. // {family: "Helvetica", weight: "bold", style: "italic", size: "18pt", rotated: true}
  578. font: {family: "sans-serif", size: "12px"},
  579. // length: Number
  580. // The length of the indicator. In the above example, the radius of the AnalogGauge
  581. // is 125, but the length of the indicator is 135, meaning it would project beyond
  582. // the edge of the AnalogGauge
  583. length: 0,
  584. // width: Number
  585. // The width of the indicator.
  586. width: 0,
  587. // offset: Number
  588. // The offset of the indicator
  589. offset: 0,
  590. // hover: String
  591. // The string to put in the tooltip when this indicator is hovered over.
  592. hover: '',
  593. // front: boolean
  594. // Keep this indicator at the front
  595. front: false,
  596. // onDragMove: String
  597. // The function to call when this indicator is moved by dragging.
  598. //onDragMove: '',
  599. // easing: String|Object
  600. // indicates the easing function to be used when animating the of an indicator.
  601. easing: dojo._defaultEasing,
  602. // duration: Number
  603. // indicates how long an animation of the indicator should take
  604. duration: 1000,
  605. // hideValues: Boolean
  606. // indicates whether the text boxes showing the value of the indicator (as text
  607. // content) should be hidden or shown. Default is not hidden, aka shown.
  608. hideValue: false,
  609. // noChange: Boolean
  610. // indicates whether the indicator's value can be changed. Useful for
  611. // a static target indicator. Default is false (that the value can be changed).
  612. noChange: false,
  613. _gauge: null,
  614. // title: String
  615. // The title of the indicator, to be displayed next to it's input box for the text-representation.
  616. title: "",
  617. templateString: dojo.cache("dojox.widget.gauge", "_Indicator.html", "<div class=\"dojoxGaugeIndicatorDiv\">\n\t<label class=\"dojoxGaugeIndicatorLabel\" for=\"${title}\">${title}:</label>\n\t<input class=\"dojoxGaugeIndicatorInput\" name=\"${title}\" size=\"5\" value=\"${value}\" dojoAttachPoint=\"valueNode\" dojoAttachEvent=\"onchange:_update\"></input>\n</div>\n"),
  618. startup: function(){
  619. if(this.onDragMove){
  620. this.onDragMove = dojo.hitch(this.onDragMove);
  621. }
  622. },
  623. postCreate: function(){
  624. if(this.title === ""){
  625. dojo.style(this.domNode, "display", "none");
  626. }
  627. if(dojo.isString(this.easing)){
  628. this.easing = dojo.getObject(this.easing);
  629. }
  630. },
  631. _update: function(event){
  632. // summary:
  633. // A private function, handling the updating of the gauge
  634. var value = this.valueNode.value;
  635. if(value === ''){
  636. this.value = null;
  637. }else{
  638. this.value = Number(value);
  639. this.hover = this.title+': '+value;
  640. }
  641. if(this._gauge){
  642. this.draw();
  643. this.valueNode.value = this.value;
  644. if((this.title == 'Target' || this.front) && this._gauge.moveIndicator){
  645. // if re-drawing value, make sure target is still on top
  646. this._gauge.moveIndicatorToFront(this);
  647. }
  648. }
  649. },
  650. update: function(value){
  651. // summary:
  652. // Updates the value of the indicator, including moving/re-drawing at it's new location and
  653. // updating the text box
  654. if(!this.noChange){
  655. this.valueNode.value = value;
  656. this._update();
  657. }
  658. },
  659. onDragMove: function(){
  660. // summary:
  661. // Handles updating the text box and the hover text while dragging an indicator
  662. this.value = Math.floor(this.value);
  663. this.valueNode.value = this.value;
  664. this.hover = this.title+': '+this.value;
  665. },
  666. draw: function(/* Boolean? */ dontAnimate){
  667. // summary:
  668. // Performs the initial drawing of the indicator.
  669. // dontAnimate:
  670. // Indicates if the drawing should not be animated (rather than teh default, to animate)
  671. },
  672. remove: function(){
  673. // summary:
  674. // Removes the indicator's shapes from the gauge surface.
  675. for(var i=0; i<this.shapes.length; i++){
  676. this._gauge.surface.remove(this.shapes[i]);
  677. }
  678. if(this.text){
  679. this._gauge.surface.remove(this.text);
  680. }
  681. }
  682. });
  683. }