source: Dev/trunk/src/client/dojox/charting/axis2d/Invisible.js @ 483

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

Added Dojo 1.9.3 release.

File size: 8.0 KB
Line 
1define(["dojo/_base/lang", "dojo/_base/declare", "./Base", "../scaler/linear",
2        "dojox/lang/utils"],
3        function(lang, declare, Base, lin, du){
4
5/*=====
6        var __InvisibleAxisCtorArgs = {
7                // summary:
8                //              Optional arguments used in the definition of an invisible axis.
9                // vertical: Boolean?
10                //              A flag that says whether an axis is vertical (i.e. y axis) or horizontal. Default is false (horizontal).
11                // fixUpper: String?
12                //              Align the greatest value on the axis with the specified tick level. Options are "major", "minor", "micro", or "none".  Defaults to "none".
13                // fixLower: String?
14                //              Align the smallest value on the axis with the specified tick level. Options are "major", "minor", "micro", or "none".  Defaults to "none".
15                // natural: Boolean?
16                //              Ensure tick marks are made on "natural" numbers. Defaults to false.
17                // leftBottom: Boolean?
18                //              The position of a vertical axis; if true, will be placed against the left-bottom corner of the chart.  Defaults to true.
19                // includeZero: Boolean?
20                //              Include 0 on the axis rendering.  Default is false.
21                // fixed: Boolean?
22                //              Force all axis labels to be fixed numbers.  Default is true.
23                // min: Number?
24                //              The smallest value on an axis. Default is 0.
25                // max: Number?
26                //              The largest value on an axis. Default is 1.
27                // from: Number?
28                //              Force the chart to render data visible from this value. Default is 0.
29                // to: Number?
30                //              Force the chart to render data visible to this value. Default is 1.
31                // majorTickStep: Number?
32                //              The amount to skip before a major tick is drawn. When not set the major ticks step is computed from
33                //              the data range.
34                // minorTickStep: Number?
35                //              The amount to skip before a minor tick is drawn. When not set the minor ticks step is computed from
36                //              the data range.
37                // microTickStep: Number?
38                //              The amount to skip before a micro tick is drawn. When not set the micro ticks step is computed from
39        };
40=====*/
41
42        return declare("dojox.charting.axis2d.Invisible", Base, {
43                // summary:
44                //              A axis object used in dojox.charting.  You can use that axis if you want the axis to be invisible.
45                //              See dojox.charting.Chart.addAxis for details.
46                //
47                // defaultParams: Object
48                //              The default parameters used to define any axis.
49                // optionalParams: Object
50                //              Any optional parameters needed to define an axis.
51
52                /*
53                // TODO: the documentation tools need these to be pre-defined in order to pick them up
54                //      correctly, but the code here is partially predicated on whether or not the properties
55                //      actually exist.  For now, we will leave these undocumented but in the code for later. -- TRT
56
57                // opt: Object
58                //              The actual options used to define this axis, created at initialization.
59                // scaler: Object
60                //              The calculated helper object to tell charts how to draw an axis and any data.
61                // ticks: Object
62                //              The calculated tick object that helps a chart draw the scaling on an axis.
63                // dirty: Boolean
64                //              The state of the axis (whether it needs to be redrawn or not)
65                // scale: Number
66                //              The current scale of the axis.
67                // offset: Number
68                //              The current offset of the axis.
69
70                opt: null,
71                scaler: null,
72                ticks: null,
73                dirty: true,
74                scale: 1,
75                offset: 0,
76                */
77                defaultParams: {
78                        vertical:    false,             // true for vertical axis
79                        fixUpper:    "none",    // align the upper on ticks: "major", "minor", "micro", "none"
80                        fixLower:    "none",    // align the lower on ticks: "major", "minor", "micro", "none"
81                        natural:     false,             // all tick marks should be made on natural numbers
82                        leftBottom:  true,              // position of the axis, used with "vertical"
83                        includeZero: false,             // 0 should be included
84                        fixed:       true               // all labels are fixed numbers
85                },
86                optionalParams: {
87                        min:                    0,      // minimal value on this axis
88                        max:                    1,      // maximal value on this axis
89                        from:                   0,      // visible from this value
90                        to:                             1,      // visible to this value
91                        majorTickStep:  4,      // major tick step
92                        minorTickStep:  2,      // minor tick step
93                        microTickStep:  1       // micro tick step
94                },
95
96                constructor: function(chart, kwArgs){
97                        // summary:
98                        //              The constructor for an invisible axis.
99                        // chart: dojox/charting/Chart
100                        //              The chart the axis belongs to.
101                        // kwArgs: __InvisibleAxisCtorArgs?
102                        //              Any optional keyword arguments to be used to define this axis.
103                        this.opt = lang.clone(this.defaultParams);
104            du.updateWithObject(this.opt, kwArgs);
105                        du.updateWithPattern(this.opt, kwArgs, this.optionalParams);
106                },
107                dependOnData: function(){
108                        // summary:
109                        //              Find out whether or not the axis options depend on the data in the axis.
110                        return !("min" in this.opt) || !("max" in this.opt);    //      Boolean
111                },
112                clear: function(){
113                        // summary:
114                        //              Clear out all calculated properties on this axis;
115                        // returns: dojox/charting/axis2d/Invisible
116                        //              The reference to the axis for functional chaining.
117                        delete this.scaler;
118                        delete this.ticks;
119                        this.dirty = true;
120                        return this;    //      dojox/charting/axis2d/Invisible
121                },
122                initialized: function(){
123                        // summary:
124                        //              Finds out if this axis has been initialized or not.
125                        // returns: Boolean
126                        //              Whether a scaler has been calculated and if the axis is not dirty.
127                        return "scaler" in this && !(this.dirty && this.dependOnData());
128                },
129                setWindow: function(scale, offset){
130                        // summary:
131                        //              Set the drawing "window" for the axis.
132                        // scale: Number
133                        //              The new scale for the axis.
134                        // offset: Number
135                        //              The new offset for the axis.
136                        // returns: dojox/charting/axis2d/Invisible
137                        //              The reference to the axis for functional chaining.
138                        this.scale  = scale;
139                        this.offset = offset;
140                        return this.clear();    //      dojox/charting/axis2d/Invisible
141                },
142                getWindowScale: function(){
143                        // summary:
144                        //              Get the current windowing scale of the axis.
145                        return "scale" in this ? this.scale : 1;        //      Number
146                },
147                getWindowOffset: function(){
148                        // summary:
149                        //              Get the current windowing offset for the axis.
150                        return "offset" in this ? this.offset : 0;      //      Number
151                },
152                calculate: function(min, max, span){
153                        // summary:
154                        //              Perform all calculations needed to render this axis.
155                        // min: Number
156                        //              The smallest value represented on this axis.
157                        // max: Number
158                        //              The largest value represented on this axis.
159                        // span: Number
160                        //              The span in pixels over which axis calculations are made.
161                        // returns: dojox/charting/axis2d/Invisible
162                        //              The reference to the axis for functional chaining.
163                        if(this.initialized()){
164                                return this;
165                        }
166                        var o = this.opt;
167                        // we used to have a 4th function parameter to reach labels but
168                        // nobody was calling it with 4 parameters.
169                        this.labels = o.labels;
170                        this.scaler = lin.buildScaler(min, max, span, o);
171                        // store the absolute major tick start, this will be useful when dropping a label every n labels
172                        // TODO: if o.lower then it does not work
173                        var tsb = this.scaler.bounds;
174                        if("scale" in this){
175                                // calculate new range
176                                o.from = tsb.lower + this.offset;
177                                o.to   = (tsb.upper - tsb.lower) / this.scale + o.from;
178                                // make sure that bounds are correct
179                                if( !isFinite(o.from) ||
180                                        isNaN(o.from) ||
181                                        !isFinite(o.to) ||
182                                        isNaN(o.to) ||
183                                        o.to - o.from >= tsb.upper - tsb.lower
184                                ){
185                                        // any error --- remove from/to bounds
186                                        delete o.from;
187                                        delete o.to;
188                                        delete this.scale;
189                                        delete this.offset;
190                                }else{
191                                        // shift the window, if we are out of bounds
192                                        if(o.from < tsb.lower){
193                                                o.to += tsb.lower - o.from;
194                                                o.from = tsb.lower;
195                                        }else if(o.to > tsb.upper){
196                                                o.from += tsb.upper - o.to;
197                                                o.to = tsb.upper;
198                                        }
199                                        // update the offset
200                                        this.offset = o.from - tsb.lower;
201                                }
202                                // re-calculate the scaler
203                                this.scaler = lin.buildScaler(min, max, span, o);
204                                tsb = this.scaler.bounds;
205                                // cleanup
206                                if(this.scale == 1 && this.offset == 0){
207                                        delete this.scale;
208                                        delete this.offset;
209                                }
210                        }
211                        return this;    //      dojox/charting/axis2d/Invisible
212                },
213                getScaler: function(){
214                        // summary:
215                        //              Get the pre-calculated scaler object.
216                        return this.scaler;     //      Object
217                },
218                getTicks: function(){
219                        // summary:
220                        //              Get the pre-calculated ticks object.
221                        return this.ticks;      //      Object
222                }
223        });
224});
Note: See TracBrowser for help on using the repository browser.