123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- if(!dojo._hasResource["dojox.charting.plot2d.Grid"]){
- dojo._hasResource["dojox.charting.plot2d.Grid"] = true;
- dojo.provide("dojox.charting.plot2d.Grid");
- dojo.require("dojox.charting.Element");
- dojo.require("dojox.charting.plot2d.common");
- dojo.require("dojox.lang.functional");
- dojo.require("dojox.lang.utils");
- (function(){
- var du = dojox.lang.utils, dc = dojox.charting.plot2d.common;
- dojo.declare("dojox.charting.plot2d.Grid", dojox.charting.Element, {
-
-
-
- defaultParams: {
- hAxis: "x",
- vAxis: "y",
- hMajorLines: true,
- hMinorLines: false,
- vMajorLines: true,
- vMinorLines: false,
- hStripes: "none",
- vStripes: "none",
- animate: null
- },
- optionalParams: {},
- constructor: function(chart, kwArgs){
-
-
-
-
-
-
- this.opt = dojo.clone(this.defaultParams);
- du.updateWithObject(this.opt, kwArgs);
- this.hAxis = this.opt.hAxis;
- this.vAxis = this.opt.vAxis;
- this.dirty = true;
- this.animate = this.opt.animate;
- this.zoom = null,
- this.zoomQueue = [];
- this.lastWindow = {vscale: 1, hscale: 1, xoffset: 0, yoffset: 0};
- },
- clear: function(){
-
-
-
-
- this._hAxis = null;
- this._vAxis = null;
- this.dirty = true;
- return this;
- },
- setAxis: function(axis){
-
-
-
-
- if(axis){
- this[axis.vertical ? "_vAxis" : "_hAxis"] = axis;
- }
- return this;
- },
- addSeries: function(run){
-
-
-
-
- return this;
- },
- getSeriesStats: function(){
-
-
-
-
- return dojo.delegate(dc.defaultStats);
- },
- initializeScalers: function(){
-
-
- return this;
- },
- isDirty: function(){
-
-
-
-
- return this.dirty || this._hAxis && this._hAxis.dirty || this._vAxis && this._vAxis.dirty;
- },
- performZoom: function(dim, offsets){
-
-
-
-
-
-
-
-
-
- var vs = this._vAxis.scale || 1,
- hs = this._hAxis.scale || 1,
- vOffset = dim.height - offsets.b,
- hBounds = this._hAxis.getScaler().bounds,
- xOffset = (hBounds.from - hBounds.lower) * hBounds.scale,
- vBounds = this._vAxis.getScaler().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 = dojox.gfx.fx.animateTransform(dojo.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));
- dojo.mixin(this.lastWindow, {vscale: vs, hscale: hs, xoffset: xOffset, yoffset: yOffset});
-
-
- this.zoomQueue.push(anim);
-
- dojo.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;
- },
- getRequiredColors: function(){
-
-
-
-
- return 0;
- },
- render: function(dim, offsets){
-
-
-
-
-
-
-
-
- if(this.zoom){
- return this.performZoom(dim, offsets);
- }
- this.dirty = this.isDirty();
- if(!this.dirty){ return this; }
- this.cleanGroup();
- var s = this.group, ta = this.chart.theme.axis;
-
- try{
- var vScaler = this._vAxis.getScaler(),
- vt = vScaler.scaler.getTransformerFromModel(vScaler),
- ticks = this._vAxis.getTicks();
- if(this.opt.hMinorLines){
- dojo.forEach(ticks.minor, function(tick){
- var y = dim.height - offsets.b - vt(tick.value);
- var hMinorLine = s.createLine({
- x1: offsets.l,
- y1: y,
- x2: dim.width - offsets.r,
- y2: y
- }).setStroke(ta.minorTick);
- if(this.animate){
- this._animateGrid(hMinorLine, "h", offsets.l, offsets.r + offsets.l - dim.width);
- }
- }, this);
- }
- if(this.opt.hMajorLines){
- dojo.forEach(ticks.major, function(tick){
- var y = dim.height - offsets.b - vt(tick.value);
- var hMajorLine = s.createLine({
- x1: offsets.l,
- y1: y,
- x2: dim.width - offsets.r,
- y2: y
- }).setStroke(ta.majorTick);
- if(this.animate){
- this._animateGrid(hMajorLine, "h", offsets.l, offsets.r + offsets.l - dim.width);
- }
- }, this);
- }
- }catch(e){
-
- }
-
- try{
- var hScaler = this._hAxis.getScaler(),
- ht = hScaler.scaler.getTransformerFromModel(hScaler),
- ticks = this._hAxis.getTicks();
- if(ticks && this.opt.vMinorLines){
- dojo.forEach(ticks.minor, function(tick){
- var x = offsets.l + ht(tick.value);
- var vMinorLine = s.createLine({
- x1: x,
- y1: offsets.t,
- x2: x,
- y2: dim.height - offsets.b
- }).setStroke(ta.minorTick);
- if(this.animate){
- this._animateGrid(vMinorLine, "v", dim.height - offsets.b, dim.height - offsets.b - offsets.t);
- }
- }, this);
- }
- if(ticks && this.opt.vMajorLines){
- dojo.forEach(ticks.major, function(tick){
- var x = offsets.l + ht(tick.value);
- var vMajorLine = s.createLine({
- x1: x,
- y1: offsets.t,
- x2: x,
- y2: dim.height - offsets.b
- }).setStroke(ta.majorTick);
- if(this.animate){
- this._animateGrid(vMajorLine, "v", dim.height - offsets.b, dim.height - offsets.b - offsets.t);
- }
- }, this);
- }
- }catch(e){
-
- }
- this.dirty = false;
- return this;
- },
- _animateGrid: function(shape, type, offset, size){
- var transStart = type == "h" ? [offset, 0] : [0, offset];
- var scaleStart = type == "h" ? [1/size, 1] : [1, 1/size];
- dojox.gfx.fx.animateTransform(dojo.delegate({
- shape: shape,
- duration: 1200,
- transform: [
- {name: "translate", start: transStart, end: [0, 0]},
- {name: "scale", start: scaleStart, end: [1, 1]},
- {name: "original"}
- ]
- }, this.animate)).play();
- }
- });
- })();
- }
|