123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- define("dojox/charting/plot2d/Base", ["dojo/_base/lang", "dojo/_base/declare", "dojo/_base/connect",
- "../Element", "./_PlotEvents", "dojo/_base/array",
- "../scaler/primitive", "./common", "dojox/gfx/fx"],
- function(lang, declare, hub, Element, PlotEvents, arr, primitive, common, fx){
- return declare("dojox.charting.plot2d.Base", [Element, PlotEvents], {
- constructor: function(chart, kwArgs){
-
-
-
-
-
-
- this.zoom = null,
- this.zoomQueue = [];
- this.lastWindow = {vscale: 1, hscale: 1, xoffset: 0, yoffset: 0};
- },
- clear: function(){
-
-
-
-
- this.series = [];
- this._hAxis = null;
- this._vAxis = null;
- this.dirty = true;
- return this;
- },
- setAxis: function(axis){
-
-
-
-
-
-
- if(axis){
- this[axis.vertical ? "_vAxis" : "_hAxis"] = axis;
- }
- return this;
- },
- toPage: function(coord){
-
-
-
-
-
-
-
-
-
- var ah = this._hAxis, av = this._vAxis,
- sh = ah.getScaler(), sv = av.getScaler(),
- th = sh.scaler.getTransformerFromModel(sh),
- tv = sv.scaler.getTransformerFromModel(sv),
- c = this.chart.getCoords(),
- o = this.chart.offsets, dim = this.chart.dim;
- var t = function(coord){
- var r = {};
- r.x = th(coord[ah.name]) + c.x + o.l;
- r.y = c.y + dim.height - o.b - tv(coord[av.name]);
- return r;
- };
-
-
- return coord?t(coord):t;
- },
- toData: function(coord){
-
-
-
-
-
-
-
-
-
- var ah = this._hAxis, av = this._vAxis,
- sh = ah.getScaler(), sv = av.getScaler(),
- th = sh.scaler.getTransformerFromPlot(sh),
- tv = sv.scaler.getTransformerFromPlot(sv),
- c = this.chart.getCoords(),
- o = this.chart.offsets, dim = this.chart.dim;
- var t = function(coord){
- var r = {};
- r[ah.name] = th(coord.x - c.x - o.l);
- r[av.name] = tv(c.y + dim.height - coord.y - o.b);
- return r;
- };
-
-
- return coord?t(coord):t;
- },
- addSeries: function(run){
-
-
-
-
-
-
- this.series.push(run);
- return this;
- },
- getSeriesStats: function(){
-
-
-
-
- return common.collectSimpleStats(this.series);
- },
- calculateAxes: function(dim){
-
-
-
-
-
-
- this.initializeScalers(dim, this.getSeriesStats());
- return this;
- },
- isDirty: function(){
-
-
-
-
- return this.dirty || this._hAxis && this._hAxis.dirty || this._vAxis && this._vAxis.dirty;
- },
- isDataDirty: function(){
-
-
-
-
- return arr.some(this.series, function(item){ return item.dirty; });
- },
- performZoom: function(dim, offsets){
-
-
-
-
-
-
-
-
-
- var vs = this._vAxis.scale || 1,
- hs = this._hAxis.scale || 1,
- vOffset = dim.height - offsets.b,
- hBounds = this._hScaler.bounds,
- xOffset = (hBounds.from - hBounds.lower) * hBounds.scale,
- vBounds = this._vScaler.bounds,
- yOffset = (vBounds.from - vBounds.lower) * vBounds.scale,
-
- rVScale = vs / this.lastWindow.vscale,
- rHScale = hs / this.lastWindow.hscale,
- rXOffset = (this.lastWindow.xoffset - xOffset)/
- ((this.lastWindow.hscale == 1)? hs : this.lastWindow.hscale),
- rYOffset = (yOffset - this.lastWindow.yoffset)/
- ((this.lastWindow.vscale == 1)? vs : this.lastWindow.vscale),
- shape = this.group,
- anim = fx.animateTransform(lang.delegate({
- shape: shape,
- duration: 1200,
- transform:[
- {name:"translate", start:[0, 0], end: [offsets.l * (1 - rHScale), vOffset * (1 - rVScale)]},
- {name:"scale", start:[1, 1], end: [rHScale, rVScale]},
- {name:"original"},
- {name:"translate", start: [0, 0], end: [rXOffset, rYOffset]}
- ]}, this.zoom));
- lang.mixin(this.lastWindow, {vscale: vs, hscale: hs, xoffset: xOffset, yoffset: yOffset});
-
-
- this.zoomQueue.push(anim);
-
- hub.connect(anim, "onEnd", this, function(){
- this.zoom = null;
- this.zoomQueue.shift();
- if(this.zoomQueue.length > 0){
- this.zoomQueue[0].play();
- }
- });
- if(this.zoomQueue.length == 1){
- this.zoomQueue[0].play();
- }
- return this;
- },
- render: function(dim, offsets){
-
-
-
-
-
-
-
-
- return this;
- },
- getRequiredColors: function(){
-
-
-
-
- return this.series.length;
- },
- initializeScalers: function(dim, stats){
-
-
-
-
-
-
-
-
- if(this._hAxis){
- if(!this._hAxis.initialized()){
- this._hAxis.calculate(stats.hmin, stats.hmax, dim.width);
- }
- this._hScaler = this._hAxis.getScaler();
- }else{
- this._hScaler = primitive.buildScaler(stats.hmin, stats.hmax, dim.width);
- }
- if(this._vAxis){
- if(!this._vAxis.initialized()){
- this._vAxis.calculate(stats.vmin, stats.vmax, dim.height);
- }
- this._vScaler = this._vAxis.getScaler();
- }else{
- this._vScaler = primitive.buildScaler(stats.vmin, stats.vmax, dim.height);
- }
- return this;
- }
- });
- });
|