source: Dev/trunk/src/client/dojox/dgauges/RectangularScale.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

  • Property svn:executable set to *
File size: 4.5 KB
Line 
1define(["dojo/_base/declare", "dojox/gfx", "./ScaleBase"], function(declare, gfx, ScaleBase){
2        return declare("dojox.dgauges.RectangularScale", ScaleBase, {
3                // summary:
4                //              The rectangular scale. A scaler must be set to use this class.
5
6                // paddingLeft: Number
7                //              The left padding.
8                paddingLeft: 15,
9                // paddingTop: Number
10                //              The top padding.
11                paddingTop: 12,
12                // paddingRight: Number
13                //              The right padding.
14                paddingRight: 15,
15                // paddingBottom: Number
16                //              The bottom padding.
17                paddingBottom: 0,
18                _contentBox: null,             
19                constructor: function(){
20                        this.labelPosition = "leading";
21                        this.addInvalidatingProperties(["paddingTop", "paddingLeft", "paddingRight", "paddingBottom"]);
22                },
23               
24                positionForValue: function(value){
25                        // summary:
26                        //              Transforms a value into a position using the associated scaler.
27                        // value:
28                        //              The value to transform.
29                        // returns: Number
30                        //              A position in pixels.
31                        var relativePos = 0;
32                        var position;
33                        var spos = 0;
34                        var length = 0;
35                        if(this._contentBox){
36                                if(this._gauge.orientation == "horizontal"){
37                                        spos = this._contentBox.x;
38                                        length = this._contentBox.w;
39                                }else{
40                                        spos = this._contentBox.y;
41                                        length = this._contentBox.h;
42                                }
43                        }
44                        relativePos = this.scaler.positionForValue(value);
45                        position = spos + (relativePos * length);
46                        return position;
47                },
48               
49                valueForPosition: function(pos){
50                        // summary:
51                        //              Transforms a position in pixels into a value using the associated scaler.
52                        // pos:
53                        //              The position to transform.
54                        // returns: Number
55                        //              The value represented by pos.
56                        var value = this.scaler.minimum;
57                        var position = NaN;
58                        var spos = 0;
59                        var epos = 0;
60                       
61                        if(this._gauge.orientation == "horizontal"){
62                                position = pos.x;
63                                spos = this._contentBox.x;
64                                epos = this._contentBox.x + this._contentBox.w;
65                        }else{
66                                position = pos.y;
67                                spos = this._contentBox.y;
68                                epos = this._contentBox.y + this._contentBox.h;
69                        }
70                       
71                        if(position <= spos){
72                                value = this.scaler.minimum;
73                        }else if(position >= epos){
74                                value = this.scaler.maximum;
75                        }else {
76                                value = this.scaler.valueForPosition((position - spos)/(epos - spos));
77                        }
78                        return value;
79                       
80                },
81               
82                refreshRendering: function(){
83                        this.inherited(arguments);
84                        if(!this._gfxGroup || !this.scaler)
85                                return;
86                       
87                        this._ticksGroup.clear();
88                       
89                        // variables for ticks rendering
90                        var middleBox = this._gauge._layoutInfos.middle;
91                       
92                        this._contentBox = {};
93                       
94                        this._contentBox.x = middleBox.x + this.paddingLeft;
95                        this._contentBox.y = middleBox.y + this.paddingTop;
96                        this._contentBox.w = middleBox.w - (this.paddingLeft + this.paddingRight);
97                        this._contentBox.h = middleBox.h - (this.paddingBottom + this.paddingTop);
98                        var renderer;
99                       
100                        // variables for tick labels
101                        var labelText;
102                        var font = this._getFont();
103                       
104                        // Layout ticks
105                        var allTicks = this.scaler.computeTicks();
106                       
107                        for(var i = 0; i < allTicks.length; i++){
108                                var tickItem = allTicks[i];
109                                renderer = this.tickShapeFunc(this._ticksGroup, this, tickItem);
110                               
111                                if(renderer){
112                                        var a = this.positionForValue(tickItem.value);
113                                        var tickSize = this._gauge._computeBoundingBox(renderer).width;
114                                       
115                                        var x1 = 0, y1 = 0, angle = 0;
116                                        if(this._gauge.orientation == "horizontal"){
117                                                x1 = a;
118                                                y1 = this._contentBox.y;
119                                                angle = 90;
120                                        }else{
121                                                x1 = this._contentBox.x;
122                                                y1 = a;
123                                        }
124                                       
125                                        renderer.setTransform([{
126                                                dx: x1,
127                                                dy: y1
128                                        }, gfx.matrix.rotateg(angle)]);
129                                }
130                               
131                                labelText = this.tickLabelFunc(tickItem);
132                               
133                                if(labelText){
134                                        var tbox = gfx._base._getTextBox(labelText, {
135                                                font: gfx.makeFontString(gfx.makeParameters(gfx.defaultFont, font))
136                                        });
137                                        var tw = tbox.w;
138                                        var th = tbox.h;
139                                        var al = "start";
140                                        var xt = x1;
141                                        var yt = y1;
142                                       
143                                        if(this._gauge.orientation == "horizontal"){
144                                                xt = x1;
145                                                if(this.labelPosition == "trailing"){
146                                                        yt = y1 + tickSize + this.labelGap + th;
147                                                }else{
148                                                        yt = y1 - this.labelGap;
149                                                }
150                                                al = "middle";
151                                        }else{
152                                                if(this.labelPosition == "trailing"){
153                                                        xt = x1 + tickSize + this.labelGap;
154                                                }else{
155                                                        xt = x1 - this.labelGap - tw;
156                                                }
157                                                yt = y1 + th / 2;
158                                        }
159                                       
160                                        var t = this._ticksGroup.createText({
161                                                x: xt,
162                                                y: yt,
163                                                text: labelText,
164                                                align: al
165                                        });
166                                        t.setFill(font.color ? font.color : "black");
167                                        t.setFont(font);
168                                }
169                        }
170                       
171                        for(var key in this._indicatorsIndex){
172                                this._indicatorsRenderers[key] = this._indicatorsIndex[key].invalidateRendering();
173                        }
174                }
175        })
176});
Note: See TracBrowser for help on using the repository browser.