| 1 |
define(["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/connect", "dojo/has", |
| 2 |
"./Base", "../scaler/primitive", "dojox/gfx", "dojox/gfx/fx", "dojox/lang/utils"], |
| 3 |
function(lang, declare, hub, has, Base, primitive, gfx, fx, du){ |
| 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 |
var alwaysFalse = function(){ return false; } |
| 57 |
|
| 58 |
return declare("dojox.charting.plot2d.CartesianBase", Base, { |
| 59 |
baseParams: { |
| 60 |
hAxis: "x", |
| 61 |
vAxis: "y", |
| 62 |
labels: false, |
| 63 |
labelOffset: 10, |
| 64 |
fixed: true, |
| 65 |
precision: 1, |
| 66 |
labelStyle: "inside", |
| 67 |
htmlLabels: true, |
| 68 |
omitLabels: true, |
| 69 |
labelFunc: null |
| 70 |
}, |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
constructor: function(chart, kwArgs){ |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
this.axes = ["hAxis", "vAxis"]; |
| 82 |
this.zoom = null; |
| 83 |
this.zoomQueue = []; |
| 84 |
this.lastWindow = {vscale: 1, hscale: 1, xoffset: 0, yoffset: 0}; |
| 85 |
this.hAxis = (kwArgs && kwArgs.hAxis) || "x"; |
| 86 |
this.vAxis = (kwArgs && kwArgs.vAxis) || "y"; |
| 87 |
this.series = []; |
| 88 |
this.opt = lang.clone(this.baseParams); |
| 89 |
du.updateWithObject(this.opt, kwArgs); |
| 90 |
}, |
| 91 |
clear: function(){ |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
this.inherited(arguments); |
| 97 |
this._hAxis = null; |
| 98 |
this._vAxis = null; |
| 99 |
return this; |
| 100 |
}, |
| 101 |
cleanGroup: function(creator, noClip){ |
| 102 |
this.inherited(arguments); |
| 103 |
if(!noClip && this.chart._nativeClip){ |
| 104 |
var offsets = this.chart.offsets, dim = this.chart.dim; |
| 105 |
var w = Math.max(0, dim.width - offsets.l - offsets.r), |
| 106 |
h = Math.max(0, dim.height - offsets.t - offsets.b); |
| 107 |
this.group.setClip({ x: offsets.l, y: offsets.t, width: w, height: h }); |
| 108 |
if(!this._clippedGroup){ |
| 109 |
this._clippedGroup = this.group.createGroup(); |
| 110 |
} |
| 111 |
} |
| 112 |
}, |
| 113 |
purgeGroup: function(){ |
| 114 |
this.inherited(arguments); |
| 115 |
this._clippedGroup = null; |
| 116 |
}, |
| 117 |
getGroup: function(){ |
| 118 |
return this._clippedGroup || this.group; |
| 119 |
}, |
| 120 |
setAxis: function(axis){ |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
if(axis){ |
| 128 |
this[axis.vertical ? "_vAxis" : "_hAxis"] = axis; |
| 129 |
} |
| 130 |
return this; |
| 131 |
}, |
| 132 |
toPage: function(coord){ |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
var ah = this._hAxis, av = this._vAxis, |
| 143 |
sh = ah.getScaler(), sv = av.getScaler(), |
| 144 |
th = sh.scaler.getTransformerFromModel(sh), |
| 145 |
tv = sv.scaler.getTransformerFromModel(sv), |
| 146 |
c = this.chart.getCoords(), |
| 147 |
o = this.chart.offsets, dim = this.chart.dim; |
| 148 |
var t = function(coord){ |
| 149 |
var r = {}; |
| 150 |
r.x = th(coord[ah.name]) + c.x + o.l; |
| 151 |
r.y = c.y + dim.height - o.b - tv(coord[av.name]); |
| 152 |
return r; |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
return coord?t(coord):t; |
| 157 |
}, |
| 158 |
toData: function(coord){ |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
var ah = this._hAxis, av = this._vAxis, |
| 169 |
sh = ah.getScaler(), sv = av.getScaler(), |
| 170 |
th = sh.scaler.getTransformerFromPlot(sh), |
| 171 |
tv = sv.scaler.getTransformerFromPlot(sv), |
| 172 |
c = this.chart.getCoords(), |
| 173 |
o = this.chart.offsets, dim = this.chart.dim; |
| 174 |
var t = function(coord){ |
| 175 |
var r = {}; |
| 176 |
r[ah.name] = th(coord.x - c.x - o.l); |
| 177 |
r[av.name] = tv(c.y + dim.height - coord.y - o.b); |
| 178 |
return r; |
| 179 |
}; |
| 180 |
|
| 181 |
|
| 182 |
return coord?t(coord):t; |
| 183 |
}, |
| 184 |
isDirty: function(){ |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
return this.dirty || this._hAxis && this._hAxis.dirty || this._vAxis && this._vAxis.dirty; |
| 190 |
}, |
| 191 |
createLabel: function(group, value, bbox, theme){ |
| 192 |
if(this.opt.labels){ |
| 193 |
var x, y, label = this.opt.labelFunc?this.opt.labelFunc.apply(this, [value, this.opt.fixed, this.opt.precision]): |
| 194 |
this._getLabel(isNaN(value.y)?value:value.y); |
| 195 |
if(this.opt.labelStyle == "inside"){ |
| 196 |
var lbox = gfx._base._getTextBox(label, { font: theme.series.font } ); |
| 197 |
x = bbox.x + bbox.width / 2; |
| 198 |
y = bbox.y + bbox.height / 2 + lbox.h / 4; |
| 199 |
if(lbox.w > bbox.width || lbox.h > bbox.height){ |
| 200 |
return; |
| 201 |
} |
| 202 |
|
| 203 |
}else{ |
| 204 |
x = bbox.x + bbox.width / 2; |
| 205 |
y = bbox.y - this.opt.labelOffset; |
| 206 |
} |
| 207 |
this.renderLabel(group, x, y, label, theme, this.opt.labelStyle == "inside"); |
| 208 |
} |
| 209 |
}, |
| 210 |
performZoom: function(dim, offsets){ |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
var vs = this._vAxis.scale || 1, |
| 222 |
hs = this._hAxis.scale || 1, |
| 223 |
vOffset = dim.height - offsets.b, |
| 224 |
hBounds = this._hScaler.bounds, |
| 225 |
xOffset = (hBounds.from - hBounds.lower) * hBounds.scale, |
| 226 |
vBounds = this._vScaler.bounds, |
| 227 |
yOffset = (vBounds.from - vBounds.lower) * vBounds.scale, |
| 228 |
|
| 229 |
rVScale = vs / this.lastWindow.vscale, |
| 230 |
rHScale = hs / this.lastWindow.hscale, |
| 231 |
rXOffset = (this.lastWindow.xoffset - xOffset)/ |
| 232 |
((this.lastWindow.hscale == 1)? hs : this.lastWindow.hscale), |
| 233 |
rYOffset = (yOffset - this.lastWindow.yoffset)/ |
| 234 |
((this.lastWindow.vscale == 1)? vs : this.lastWindow.vscale), |
| 235 |
|
| 236 |
shape = this.getGroup(), |
| 237 |
anim = fx.animateTransform(lang.delegate({ |
| 238 |
shape: shape, |
| 239 |
duration: 1200, |
| 240 |
transform:[ |
| 241 |
{name:"translate", start:[0, 0], end: [offsets.l * (1 - rHScale), vOffset * (1 - rVScale)]}, |
| 242 |
{name:"scale", start:[1, 1], end: [rHScale, rVScale]}, |
| 243 |
{name:"original"}, |
| 244 |
{name:"translate", start: [0, 0], end: [rXOffset, rYOffset]} |
| 245 |
]}, this.zoom)); |
| 246 |
|
| 247 |
lang.mixin(this.lastWindow, {vscale: vs, hscale: hs, xoffset: xOffset, yoffset: yOffset}); |
| 248 |
|
| 249 |
|
| 250 |
this.zoomQueue.push(anim); |
| 251 |
|
| 252 |
hub.connect(anim, "onEnd", this, function(){ |
| 253 |
this.zoom = null; |
| 254 |
this.zoomQueue.shift(); |
| 255 |
if(this.zoomQueue.length > 0){ |
| 256 |
this.zoomQueue[0].play(); |
| 257 |
} |
| 258 |
}); |
| 259 |
if(this.zoomQueue.length == 1){ |
| 260 |
this.zoomQueue[0].play(); |
| 261 |
} |
| 262 |
return this; |
| 263 |
}, |
| 264 |
initializeScalers: function(dim, stats){ |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
if(this._hAxis){ |
| 274 |
if(!this._hAxis.initialized()){ |
| 275 |
this._hAxis.calculate(stats.hmin, stats.hmax, dim.width); |
| 276 |
} |
| 277 |
this._hScaler = this._hAxis.getScaler(); |
| 278 |
}else{ |
| 279 |
this._hScaler = primitive.buildScaler(stats.hmin, stats.hmax, dim.width); |
| 280 |
} |
| 281 |
if(this._vAxis){ |
| 282 |
if(!this._vAxis.initialized()){ |
| 283 |
this._vAxis.calculate(stats.vmin, stats.vmax, dim.height); |
| 284 |
} |
| 285 |
this._vScaler = this._vAxis.getScaler(); |
| 286 |
}else{ |
| 287 |
this._vScaler = primitive.buildScaler(stats.vmin, stats.vmax, dim.height); |
| 288 |
} |
| 289 |
return this; |
| 290 |
}, |
| 291 |
isNullValue: function(value){ |
| 292 |
if(value === null || typeof value == "undefined"){ |
| 293 |
return true; |
| 294 |
} |
| 295 |
var h = this._hAxis ? this._hAxis.isNullValue : alwaysFalse, |
| 296 |
v = this._vAxis ? this._vAxis.isNullValue : alwaysFalse; |
| 297 |
if(typeof value == "number"){ |
| 298 |
return h(1) || v(value); |
| 299 |
} |
| 300 |
return h(isNaN(value.x) ? 1 : value.x) || value.y === null || v(value.y); |
| 301 |
} |
| 302 |
}); |
| 303 |
}); |