| 1 | define(["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, scalerType){ |
| 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 | // scalerType: Object |
| 162 | // An optional scaler type object. |
| 163 | // returns: dojox/charting/axis2d/Invisible |
| 164 | // The reference to the axis for functional chaining. |
| 165 | if(this.initialized()){ |
| 166 | return this; |
| 167 | } |
| 168 | var o = this.opt; |
| 169 | // we used to have a 4th function parameter to reach labels but |
| 170 | // nobody was calling it with 4 parameters. |
| 171 | this.labels = o.labels; |
| 172 | this.scaler = (scalerType || lin).buildScaler(min, max, span, o); |
| 173 | // store the absolute major tick start, this will be useful when dropping a label every n labels |
| 174 | // TODO: if o.lower then it does not work |
| 175 | var tsb = this.scaler.bounds; |
| 176 | if("scale" in this){ |
| 177 | // calculate new range |
| 178 | o.from = tsb.lower + this.offset; |
| 179 | o.to = (tsb.upper - tsb.lower) / this.scale + o.from; |
| 180 | // make sure that bounds are correct |
| 181 | if( !isFinite(o.from) || |
| 182 | isNaN(o.from) || |
| 183 | !isFinite(o.to) || |
| 184 | isNaN(o.to) || |
| 185 | o.to - o.from >= tsb.upper - tsb.lower |
| 186 | ){ |
| 187 | // any error --- remove from/to bounds |
| 188 | delete o.from; |
| 189 | delete o.to; |
| 190 | delete this.scale; |
| 191 | delete this.offset; |
| 192 | }else{ |
| 193 | // shift the window, if we are out of bounds |
| 194 | if(o.from < tsb.lower){ |
| 195 | o.to += tsb.lower - o.from; |
| 196 | o.from = tsb.lower; |
| 197 | }else if(o.to > tsb.upper){ |
| 198 | o.from += tsb.upper - o.to; |
| 199 | o.to = tsb.upper; |
| 200 | } |
| 201 | // update the offset |
| 202 | this.offset = o.from - tsb.lower; |
| 203 | } |
| 204 | // re-calculate the scaler |
| 205 | this.scaler = (scalerType || lin).buildScaler(min, max, span, o); |
| 206 | tsb = this.scaler.bounds; |
| 207 | // cleanup |
| 208 | if(this.scale == 1 && this.offset == 0){ |
| 209 | delete this.scale; |
| 210 | delete this.offset; |
| 211 | } |
| 212 | } |
| 213 | return this; // dojox/charting/axis2d/Invisible |
| 214 | }, |
| 215 | getScaler: function(){ |
| 216 | // summary: |
| 217 | // Get the pre-calculated scaler object. |
| 218 | return this.scaler; // Object |
| 219 | }, |
| 220 | getTicks: function(){ |
| 221 | // summary: |
| 222 | // Get the pre-calculated ticks object. |
| 223 | return this.ticks; // Object |
| 224 | } |
| 225 | }); |
| 226 | }); |