summaryrefslogtreecommitdiff
path: root/js/dojo-1.7.2/dojox/gauges/TextIndicator.js
blob: 8f4fcb644695a280541aff2f2f7c4fd79a6ed6df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//>>built
define("dojox/gauges/TextIndicator", ["dojo/_base/declare","./_Indicator"],
  function(declare, Indicator) { 

/*=====
	Indicator = dojox.gauges._Indicator;
=====*/

return declare("dojox.gauges.TextIndicator", [Indicator], {
	// summary:
	//		A gauge indicator the simply draws its value as text.
	
	
	// x: Number
	// 		The x coordinate of the indicator
	x: 0,
	
	// y: Number
	// 		The y coordinate of the indicator
	y: 0,
	
	// align: String
	// 		The horizontal alignment of the text, the value can be 'middle' (the default), 'left' or 'right'
	align: 'middle',
	
	// fixedPrecision: Boolean
	// 		Indicates that the number is displayed in fixed precision or not (precision is defined by the 'precision' property (default is true).
	fixedPrecision: true,
	
	// precision: Number
	//		The number of tailing digits to display the value of the indicator when the 'fixedPrecision' property is set to true (default is 0).
	precision: 0,
	
	draw: function(group, /*Boolean?*/ dontAnimate){
		// summary: 
		//		Override of dojox.gauges._Indicator.draw
		var v = this.value;
		
		if (v < this._gauge.min) {
			v = this._gauge.min;
		}
		if (v > this._gauge.max) {
			v = this._gauge.max;
		}
		var txt;
		var NumberUtils = this._gauge ? this._gauge._getNumberModule() : null;
		if (NumberUtils) {
			txt = this.fixedPrecision ? NumberUtils.format(v, {
				places: this.precision
			}) : NumberUtils.format(v);
		} else {
			txt = this.fixedPrecision ? v.toFixed(this.precision) : v.toString();
		}
		
		var x = this.x ? this.x : 0;
		var y = this.y ? this.y : 0;
		var align = this.align ? this.align : "middle";
		if(!this.shape){
			this.shape = group.createText({
				x: x,
				y: y,
				text: txt,
				align: align
			});
		}else{
			this.shape.setShape({
				x: x,
				y: y,
				text: txt,
				align: align
			});
		}
		this.shape.setFill(this.color);
		if (this.font) this.shape.setFont(this.font);
		
	}
	
});
});