source: [view]
if(this.initialized()){
return this;
}
var o = this.opt;
this.labels = "labels" in o ? o.labels : labels;
this.scaler = lin.buildScaler(min, max, span, o);
var tsb = this.scaler.bounds;
if("scale" in this){
// calculate new range
o.from = tsb.lower + this.offset;
o.to = (tsb.upper - tsb.lower) / this.scale + o.from;
// make sure that bounds are correct
if( !isFinite(o.from) ||
isNaN(o.from) ||
!isFinite(o.to) ||
isNaN(o.to) ||
o.to - o.from >= tsb.upper - tsb.lower
){
// any error --- remove from/to bounds
delete o.from;
delete o.to;
delete this.scale;
delete this.offset;
}else{
// shift the window, if we are out of bounds
if(o.from < tsb.lower){
o.to += tsb.lower - o.from;
o.from = tsb.lower;
}else if(o.to > tsb.upper){
o.from += tsb.upper - o.to;
o.to = tsb.upper;
}
// update the offset
this.offset = o.from - tsb.lower;
}
// re-calculate the scaler
this.scaler = lin.buildScaler(min, max, span, o);
tsb = this.scaler.bounds;
// cleanup
if(this.scale == 1 && this.offset == 0){
delete this.scale;
delete this.offset;
}
}
var ta = this.chart.theme.axis, labelWidth = 0, rotation = o.rotation % 360,
// TODO: we use one font --- of major tick, we need to use major and minor fonts
taFont = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font),
size = taFont ? g.normalizedLength(g.splitFontString(taFont).size) : 0,
cosr = Math.abs(Math.cos(rotation * Math.PI / 180)),
sinr = Math.abs(Math.sin(rotation * Math.PI / 180));
if(rotation < 0){
rotation += 360;
}
if(size){
if(this.vertical ? rotation != 0 && rotation != 180 : rotation != 90 && rotation != 270){
// we need width of all labels
if(this.labels){
labelWidth = this._groupLabelWidth(this.labels, taFont, o.maxLabelCharCount);
}else{
var labelLength = Math.ceil(
Math.log(
Math.max(
Math.abs(tsb.from),
Math.abs(tsb.to)
)
) / Math.LN10
),
t = [];
if(tsb.from < 0 || tsb.to < 0){
t.push("-");
}
t.push(dojo.string.rep("9", labelLength));
var precision = Math.floor(
Math.log( tsb.to - tsb.from ) / Math.LN10
);
if(precision > 0){
t.push(".");
t.push(dojo.string.rep("9", precision));
}
labelWidth = dojox.gfx._base._getTextBox(
t.join(""),
{ font: taFont }
).w;
}
labelWidth = o.maxLabelSize ? Math.min(o.maxLabelSize, labelWidth) : labelWidth;
}else{
labelWidth = size;
}
switch(rotation){
case 0:
case 90:
case 180:
case 270:
// trivial cases: use labelWidth
break;
default:
// rotated labels
var gap1 = Math.sqrt(labelWidth * labelWidth + size * size), // short labels
gap2 = this.vertical ? size * cosr + labelWidth * sinr : labelWidth * cosr + size * sinr; // slanted labels
labelWidth = Math.min(gap1, gap2);
break;
}
}
this.scaler.minMinorStep = labelWidth + labelGap;
this.ticks = lin.buildTicks(this.scaler, o);
return this; // dojox.charting.axis2d.Default