- Author:
- David Nickerson <nickerso@users.sourceforge.net>
- Date:
- 2009-07-16 02:00:03+12:00
- Desc:
- the starting point for the HH tutorial example
- Permanent Source URI:
- https://models.fieldml.org/workspace/a1/rawfile/f6a8f90307388eb4b040ee3566b84d88b59247f7/dojo-presentation/js/dojo/dojox/charting/plot2d/Grid.js
dojo.provide("dojox.charting.plot2d.Grid");
dojo.require("dojox.charting.Element");
dojo.require("dojox.charting.plot2d.common");
dojo.require("dojox.lang.functional");
(function(){
var du = dojox.lang.utils;
dojo.declare("dojox.charting.plot2d.Grid", dojox.charting.Element, {
defaultParams: {
hAxis: "x", // use a horizontal axis named "x"
vAxis: "y", // use a vertical axis named "y"
hMajorLines: true, // draw horizontal major lines
hMinorLines: false, // draw horizontal minor lines
vMajorLines: true, // draw vertical major lines
vMinorLines: false, // draw vertical minor lines
hStripes: "none", // TBD
vStripes: "none" // TBD
},
optionalParams: {}, // no optional parameters
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;
},
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){
// nothing
return this;
},
calculateAxes: function(dim){
// nothing
return this;
},
isDirty: function(){
return this.dirty || this._hAxis && this._hAxis.dirty || this._vAxis && this._vAxis.dirty;
},
getRequiredColors: function(){
return 0;
},
render: function(dim, offsets){
// draw horizontal stripes and lines
this.dirty = this.isDirty();
if(!this.dirty){ return this; }
this.cleanGroup();
var s = this.group, ta = this.chart.theme.axis, ticks = this._vAxis.getTicks(),
hScaler = this._hAxis.getScaler(), vScaler = this._vAxis.getScaler(),
ht = hScaler.scaler.getTransformerFromModel(hScaler),
vt = vScaler.scaler.getTransformerFromModel(vScaler);
if(this.opt.hMinorLines){
dojo.forEach(ticks.minor, function(tick){
var y = dim.height - offsets.b - vt(tick.value);
s.createLine({
x1: offsets.l,
y1: y,
x2: dim.width - offsets.r,
y2: y
}).setStroke(ta.minorTick);
});
}
if(this.opt.hMajorLines){
dojo.forEach(ticks.major, function(tick){
var y = dim.height - offsets.b - vt(tick.value);
s.createLine({
x1: offsets.l,
y1: y,
x2: dim.width - offsets.r,
y2: y
}).setStroke(ta.majorTick);
});
}
// draw vertical stripes and lines
ticks = this._hAxis.getTicks();
if(this.opt.vMinorLines){
dojo.forEach(ticks.minor, function(tick){
var x = offsets.l + ht(tick.value);
s.createLine({
x1: x,
y1: offsets.t,
x2: x,
y2: dim.height - offsets.b
}).setStroke(ta.minorTick);
});
}
if(this.opt.vMajorLines){
dojo.forEach(ticks.major, function(tick){
var x = offsets.l + ht(tick.value);
s.createLine({
x1: x,
y1: offsets.t,
x2: x,
y2: dim.height - offsets.b
}).setStroke(ta.majorTick);
});
}
this.dirty = false;
return this;
}
});
})();