| 1 |
define(["dojo/_base/lang", "dojo/_base/array", "dojo/_base/sniff", "dojo/_base/declare", |
| 2 |
"dojo/_base/connect", "dojo/dom-geometry", "./Invisible", |
| 3 |
"../scaler/common", "../scaler/linear","../scaler/log", "./common", "dojox/gfx", "dojox/lang/utils", "dojox/lang/functional"], |
| 4 |
function(lang, arr, has, declare, connect, domGeom, Invisible, scommon, |
| 5 |
lin, log, acommon, g, du, df){ |
| 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 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
var centerAnchorLimit = 45; |
| 100 |
|
| 101 |
return declare("dojox.charting.axis2d.Log", Invisible, { |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
defaultParams: { |
| 136 |
vertical: false, |
| 137 |
fixUpper: "none", |
| 138 |
fixLower: "none", |
| 139 |
natural: false, |
| 140 |
leftBottom: true, |
| 141 |
includeZero: false, |
| 142 |
fixed: true, |
| 143 |
majorLabels: true, |
| 144 |
minorTicks: true, |
| 145 |
minorLabels: true, |
| 146 |
microTicks: false, |
| 147 |
rotation: 0, |
| 148 |
htmlLabels: true, |
| 149 |
enableCache: false, |
| 150 |
dropLabels: true, |
| 151 |
labelSizeChange: false, |
| 152 |
log: 10 |
| 153 |
}, |
| 154 |
optionalParams: { |
| 155 |
min: 0, |
| 156 |
max: 1, |
| 157 |
from: 0, |
| 158 |
to: 1, |
| 159 |
majorTickStep: 4, |
| 160 |
minorTickStep: 2, |
| 161 |
microTickStep: 1, |
| 162 |
labels: [], |
| 163 |
|
| 164 |
|
| 165 |
labelFunc: null, |
| 166 |
maxLabelSize: 0, |
| 167 |
maxLabelCharCount: 0, |
| 168 |
trailingSymbol: null, |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
stroke: {}, |
| 175 |
majorTick: {}, |
| 176 |
minorTick: {}, |
| 177 |
microTick: {}, |
| 178 |
tick: {}, |
| 179 |
font: "", |
| 180 |
fontColor: "", |
| 181 |
title: "", |
| 182 |
titleGap: 0, |
| 183 |
titleFont: "", |
| 184 |
titleFontColor: "", |
| 185 |
titleOrientation: "" |
| 186 |
}, |
| 187 |
|
| 188 |
constructor: function(chart, kwArgs){ |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
this.opt = lang.clone(this.defaultParams); |
| 196 |
du.updateWithObject(this.opt, kwArgs); |
| 197 |
du.updateWithPattern(this.opt, kwArgs, this.optionalParams); |
| 198 |
if(this.opt.enableCache){ |
| 199 |
this._textFreePool = []; |
| 200 |
this._lineFreePool = []; |
| 201 |
this._textUsePool = []; |
| 202 |
this._lineUsePool = []; |
| 203 |
} |
| 204 |
this._invalidMaxLabelSize = true; |
| 205 |
if(this.opt.log > 1){ |
| 206 |
this.scalerType = log; |
| 207 |
this.scalerType.setBase(this.opt.log); |
| 208 |
}else{ |
| 209 |
this.scalerType = lin; |
| 210 |
} |
| 211 |
}, |
| 212 |
setWindow: function(scale, offset){ |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
if(scale != this.scale){ |
| 222 |
|
| 223 |
this._invalidMaxLabelSize = true; |
| 224 |
} |
| 225 |
return this.inherited(arguments); |
| 226 |
}, |
| 227 |
|
| 228 |
_groupLabelWidth: function(labels, font, wcLimit){ |
| 229 |
if(!labels.length){ |
| 230 |
return 0; |
| 231 |
} |
| 232 |
if(labels.length > 50){ |
| 233 |
|
| 234 |
labels.length = 50; |
| 235 |
} |
| 236 |
if(lang.isObject(labels[0])){ |
| 237 |
labels = df.map(labels, function(label){ return label.text; }); |
| 238 |
} |
| 239 |
if(wcLimit){ |
| 240 |
labels = df.map(labels, function(label){ |
| 241 |
return lang.trim(label).length == 0 ? "" : label.substring(0, wcLimit) + this.trailingSymbol; |
| 242 |
}, this); |
| 243 |
} |
| 244 |
var s = labels.join("<br>"); |
| 245 |
return g._base._getTextBox(s, {font: font}).w || 0; |
| 246 |
}, |
| 247 |
|
| 248 |
_getMaxLabelSize: function(min, max, span, rotation, font, size){ |
| 249 |
if(this._maxLabelSize == null && arguments.length == 6){ |
| 250 |
var o = this.opt; |
| 251 |
|
| 252 |
this.scaler.minMinorStep = this._prevMinMinorStep = 0; |
| 253 |
var ob = lang.clone(o); |
| 254 |
delete ob.to; |
| 255 |
delete ob.from; |
| 256 |
|
| 257 |
|
| 258 |
var sb = this.scalerType.buildScaler(min, max, span, ob, o.to - o.from); |
| 259 |
sb.minMinorStep = 0; |
| 260 |
this._majorStart = sb.major.start; |
| 261 |
|
| 262 |
|
| 263 |
var tb = this.scalerType.buildTicks(sb, o); |
| 264 |
|
| 265 |
if(size && tb){ |
| 266 |
var majLabelW = 0, minLabelW = 0; |
| 267 |
|
| 268 |
var tickLabelFunc = function(tick){ |
| 269 |
if(tick.label){ |
| 270 |
this.push(tick.label); |
| 271 |
} |
| 272 |
}; |
| 273 |
var labels = []; |
| 274 |
if(this.opt.majorLabels){ |
| 275 |
arr.forEach(tb.major, tickLabelFunc, labels); |
| 276 |
majLabelW = this._groupLabelWidth(labels, font, ob.maxLabelCharCount); |
| 277 |
if(ob.maxLabelSize){ |
| 278 |
majLabelW = Math.min(ob.maxLabelSize, majLabelW); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
labels = []; |
| 283 |
if(this.opt.dropLabels && this.opt.minorLabels){ |
| 284 |
arr.forEach(tb.minor, tickLabelFunc, labels); |
| 285 |
minLabelW = this._groupLabelWidth(labels, font, ob.maxLabelCharCount); |
| 286 |
if(ob.maxLabelSize){ |
| 287 |
minLabelW = Math.min(ob.maxLabelSize, minLabelW); |
| 288 |
} |
| 289 |
} |
| 290 |
this._maxLabelSize = { |
| 291 |
majLabelW: majLabelW, minLabelW: minLabelW, |
| 292 |
majLabelH: size, minLabelH: size |
| 293 |
}; |
| 294 |
}else{ |
| 295 |
this._maxLabelSize = null; |
| 296 |
} |
| 297 |
} |
| 298 |
return this._maxLabelSize; |
| 299 |
}, |
| 300 |
|
| 301 |
calculate: function(min, max, span){ |
| 302 |
this.inherited(arguments, [min, max, span, this.scalerType]); |
| 303 |
|
| 304 |
this.scaler.minMinorStep = this._prevMinMinorStep; |
| 305 |
|
| 306 |
|
| 307 |
if((this._invalidMaxLabelSize || span != this._oldSpan) && (min != Infinity && max != -Infinity)){ |
| 308 |
this._invalidMaxLabelSize = false; |
| 309 |
if(this.opt.labelSizeChange){ |
| 310 |
this._maxLabelSize = null; |
| 311 |
} |
| 312 |
this._oldSpan = span; |
| 313 |
var o = this.opt; |
| 314 |
var ta = this.chart.theme.axis, rotation = o.rotation % 360, |
| 315 |
labelGap = this.chart.theme.axis.tick.labelGap, |
| 316 |
|
| 317 |
font = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font), |
| 318 |
size = font ? g.normalizedLength(g.splitFontString(font).size) : 0, |
| 319 |
|
| 320 |
labelW = this._getMaxLabelSize(min, max, span, rotation, font, size); |
| 321 |
if(typeof labelGap != "number"){ |
| 322 |
labelGap = 4; |
| 323 |
} |
| 324 |
if(labelW && o.dropLabels){ |
| 325 |
var cosr = Math.abs(Math.cos(rotation * Math.PI / 180)), |
| 326 |
sinr = Math.abs(Math.sin(rotation * Math.PI / 180)); |
| 327 |
var majLabelW, minLabelW; |
| 328 |
if(rotation < 0){ |
| 329 |
rotation += 360; |
| 330 |
} |
| 331 |
switch(rotation){ |
| 332 |
case 0: |
| 333 |
case 180: |
| 334 |
|
| 335 |
if(this.vertical){ |
| 336 |
majLabelW = minLabelW = size; |
| 337 |
}else{ |
| 338 |
majLabelW = labelW.majLabelW; |
| 339 |
minLabelW = labelW.minLabelW; |
| 340 |
} |
| 341 |
break; |
| 342 |
case 90: |
| 343 |
case 270: |
| 344 |
|
| 345 |
if(this.vertical){ |
| 346 |
majLabelW = labelW.majLabelW; |
| 347 |
minLabelW = labelW.minLabelW; |
| 348 |
}else{ |
| 349 |
majLabelW = minLabelW = size; |
| 350 |
} |
| 351 |
break; |
| 352 |
default: |
| 353 |
|
| 354 |
|
| 355 |
majLabelW = this.vertical ? Math.min(labelW.majLabelW, size / cosr) : Math.min(labelW.majLabelW, size / sinr); |
| 356 |
|
| 357 |
var gap1 = Math.sqrt(labelW.minLabelW * labelW.minLabelW + size * size), |
| 358 |
gap2 = this.vertical ? size * cosr + labelW.minLabelW * sinr : labelW.minLabelW * cosr + size * sinr; |
| 359 |
minLabelW = Math.min(gap1, gap2); |
| 360 |
break; |
| 361 |
} |
| 362 |
|
| 363 |
this.scaler.minMinorStep = this._prevMinMinorStep = Math.max(majLabelW, minLabelW) + labelGap; |
| 364 |
var canMinorLabel = this.scaler.minMinorStep <= this.scaler.minor.tick * this.scaler.bounds.scale; |
| 365 |
if(!canMinorLabel){ |
| 366 |
|
| 367 |
|
| 368 |
this._skipInterval = Math.floor((majLabelW + labelGap) / (this.scaler.major.tick * this.scaler.bounds.scale)); |
| 369 |
}else{ |
| 370 |
|
| 371 |
this._skipInterval = 0; |
| 372 |
} |
| 373 |
}else{ |
| 374 |
|
| 375 |
this._skipInterval = 0; |
| 376 |
} |
| 377 |
} |
| 378 |
|
| 379 |
this.ticks = this.scalerType.buildTicks(this.scaler, this.opt); |
| 380 |
return this; |
| 381 |
}, |
| 382 |
|
| 383 |
getOffsets: function(){ |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
var s = this.scaler, offsets = { l: 0, r: 0, t: 0, b: 0 }; |
| 390 |
if(!s){ |
| 391 |
return offsets; |
| 392 |
} |
| 393 |
var o = this.opt, a, b, c, d, |
| 394 |
gl = scommon.getNumericLabel, |
| 395 |
offset = 0, ma = s.major, mi = s.minor, |
| 396 |
ta = this.chart.theme.axis, |
| 397 |
labelGap = this.chart.theme.axis.tick.labelGap, |
| 398 |
|
| 399 |
taTitleFont = o.titleFont || (ta.title && ta.title.font), |
| 400 |
taTitleGap = (o.titleGap==0) ? 0 : o.titleGap || (ta.title && ta.title.gap), |
| 401 |
taMajorTick = this.chart.theme.getTick("major", o), |
| 402 |
taMinorTick = this.chart.theme.getTick("minor", o), |
| 403 |
tsize = taTitleFont ? g.normalizedLength(g.splitFontString(taTitleFont).size) : 0, |
| 404 |
rotation = o.rotation % 360, leftBottom = o.leftBottom, |
| 405 |
cosr = Math.abs(Math.cos(rotation * Math.PI / 180)), |
| 406 |
sinr = Math.abs(Math.sin(rotation * Math.PI / 180)); |
| 407 |
this.trailingSymbol = (o.trailingSymbol === undefined || o.trailingSymbol === null) ? |
| 408 |
this.trailingSymbol : o.trailingSymbol; |
| 409 |
if(typeof labelGap != "number"){ |
| 410 |
labelGap = 4; |
| 411 |
} |
| 412 |
if(rotation < 0){ |
| 413 |
rotation += 360; |
| 414 |
} |
| 415 |
var maxLabelSize = this._getMaxLabelSize(); |
| 416 |
if(maxLabelSize){ |
| 417 |
var side; |
| 418 |
var labelWidth = Math.ceil(Math.max(maxLabelSize.majLabelW, maxLabelSize.minLabelW)) + 1, |
| 419 |
size = Math.ceil(Math.max(maxLabelSize.majLabelH, maxLabelSize.minLabelH)) + 1; |
| 420 |
if(this.vertical){ |
| 421 |
side = leftBottom ? "l" : "r"; |
| 422 |
switch(rotation){ |
| 423 |
case 0: |
| 424 |
case 180: |
| 425 |
offsets[side] = labelWidth; |
| 426 |
offsets.t = offsets.b = size / 2; |
| 427 |
break; |
| 428 |
case 90: |
| 429 |
case 270: |
| 430 |
offsets[side] = size; |
| 431 |
offsets.t = offsets.b = labelWidth / 2; |
| 432 |
break; |
| 433 |
default: |
| 434 |
if(rotation <= centerAnchorLimit || (180 < rotation && rotation <= (180 + centerAnchorLimit))){ |
| 435 |
offsets[side] = size * sinr / 2 + labelWidth * cosr; |
| 436 |
offsets[leftBottom ? "t" : "b"] = size * cosr / 2 + labelWidth * sinr; |
| 437 |
offsets[leftBottom ? "b" : "t"] = size * cosr / 2; |
| 438 |
}else if(rotation > (360 - centerAnchorLimit) || (180 > rotation && rotation > (180 - centerAnchorLimit))){ |
| 439 |
offsets[side] = size * sinr / 2 + labelWidth * cosr; |
| 440 |
offsets[leftBottom ? "b" : "t"] = size * cosr / 2 + labelWidth * sinr; |
| 441 |
offsets[leftBottom ? "t" : "b"] = size * cosr / 2; |
| 442 |
}else if(rotation < 90 || (180 < rotation && rotation < 270)){ |
| 443 |
offsets[side] = size * sinr + labelWidth * cosr; |
| 444 |
offsets[leftBottom ? "t" : "b"] = size * cosr + labelWidth * sinr; |
| 445 |
}else{ |
| 446 |
offsets[side] = size * sinr + labelWidth * cosr; |
| 447 |
offsets[leftBottom ? "b" : "t"] = size * cosr + labelWidth * sinr; |
| 448 |
} |
| 449 |
break; |
| 450 |
} |
| 451 |
offsets[side] += labelGap + Math.max(taMajorTick.length, taMinorTick.length) + (o.title ? (tsize + taTitleGap) : 0); |
| 452 |
}else{ |
| 453 |
side = leftBottom ? "b" : "t"; |
| 454 |
switch(rotation){ |
| 455 |
case 0: |
| 456 |
case 180: |
| 457 |
offsets[side] = size; |
| 458 |
offsets.l = offsets.r = labelWidth / 2; |
| 459 |
break; |
| 460 |
case 90: |
| 461 |
case 270: |
| 462 |
offsets[side] = labelWidth; |
| 463 |
offsets.l = offsets.r = size / 2; |
| 464 |
break; |
| 465 |
default: |
| 466 |
if((90 - centerAnchorLimit) <= rotation && rotation <= 90 || (270 - centerAnchorLimit) <= rotation && rotation <= 270){ |
| 467 |
offsets[side] = size * cosr / 2 + labelWidth * sinr; |
| 468 |
offsets[leftBottom ? "r" : "l"] = size * sinr / 2 + labelWidth * cosr; |
| 469 |
offsets[leftBottom ? "l" : "r"] = size * sinr / 2; |
| 470 |
}else if(90 <= rotation && rotation <= (90 + centerAnchorLimit) || 270 <= rotation && rotation <= (270 + centerAnchorLimit)){ |
| 471 |
offsets[side] = size * cosr / 2 + labelWidth * sinr; |
| 472 |
offsets[leftBottom ? "l" : "r"] = size * sinr / 2 + labelWidth * cosr; |
| 473 |
offsets[leftBottom ? "r" : "l"] = size * sinr / 2; |
| 474 |
}else if(rotation < centerAnchorLimit || (180 < rotation && rotation < (180 + centerAnchorLimit))){ |
| 475 |
offsets[side] = size * cosr + labelWidth * sinr; |
| 476 |
offsets[leftBottom ? "r" : "l"] = size * sinr + labelWidth * cosr; |
| 477 |
}else{ |
| 478 |
offsets[side] = size * cosr + labelWidth * sinr; |
| 479 |
offsets[leftBottom ? "l" : "r"] = size * sinr + labelWidth * cosr; |
| 480 |
} |
| 481 |
break; |
| 482 |
} |
| 483 |
offsets[side] += labelGap + Math.max(taMajorTick.length, taMinorTick.length) + (o.title ? (tsize + taTitleGap) : 0); |
| 484 |
} |
| 485 |
} |
| 486 |
return offsets; |
| 487 |
}, |
| 488 |
cleanGroup: function(creator){ |
| 489 |
if(this.opt.enableCache && this.group){ |
| 490 |
this._lineFreePool = this._lineFreePool.concat(this._lineUsePool); |
| 491 |
this._lineUsePool = []; |
| 492 |
this._textFreePool = this._textFreePool.concat(this._textUsePool); |
| 493 |
this._textUsePool = []; |
| 494 |
} |
| 495 |
this.inherited(arguments); |
| 496 |
}, |
| 497 |
createText: function(labelType, creator, x, y, align, textContent, font, fontColor, labelWidth){ |
| 498 |
if(!this.opt.enableCache || labelType=="html"){ |
| 499 |
return acommon.createText[labelType]( |
| 500 |
this.chart, |
| 501 |
creator, |
| 502 |
x, |
| 503 |
y, |
| 504 |
align, |
| 505 |
textContent, |
| 506 |
font, |
| 507 |
fontColor, |
| 508 |
labelWidth |
| 509 |
); |
| 510 |
} |
| 511 |
var text; |
| 512 |
if (this._textFreePool.length > 0){ |
| 513 |
text = this._textFreePool.pop(); |
| 514 |
text.setShape({x: x, y: y, text: textContent, align: align}); |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
creator.add(text); |
| 519 |
}else{ |
| 520 |
text = acommon.createText[labelType]( |
| 521 |
this.chart, |
| 522 |
creator, |
| 523 |
x, |
| 524 |
y, |
| 525 |
align, |
| 526 |
textContent, |
| 527 |
font, |
| 528 |
fontColor |
| 529 |
); |
| 530 |
} |
| 531 |
this._textUsePool.push(text); |
| 532 |
return text; |
| 533 |
}, |
| 534 |
createLine: function(creator, params){ |
| 535 |
var line; |
| 536 |
if(this.opt.enableCache && this._lineFreePool.length > 0){ |
| 537 |
line = this._lineFreePool.pop(); |
| 538 |
line.setShape(params); |
| 539 |
|
| 540 |
creator.add(line); |
| 541 |
}else{ |
| 542 |
line = creator.createLine(params); |
| 543 |
} |
| 544 |
if(this.opt.enableCache){ |
| 545 |
this._lineUsePool.push(line); |
| 546 |
} |
| 547 |
return line; |
| 548 |
}, |
| 549 |
render: function(dim, offsets){ |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
if(!this.dirty || !this.scaler){ |
| 559 |
return this; |
| 560 |
} |
| 561 |
|
| 562 |
var o = this.opt, ta = this.chart.theme.axis, leftBottom = o.leftBottom, rotation = o.rotation % 360, |
| 563 |
start, stop, titlePos, titleRotation=0, titleOffset, axisVector, tickVector, anchorOffset, labelOffset, labelAlign, |
| 564 |
labelGap = this.chart.theme.axis.tick.labelGap, |
| 565 |
|
| 566 |
taFont = o.font || (ta.majorTick && ta.majorTick.font) || (ta.tick && ta.tick.font), |
| 567 |
taTitleFont = o.titleFont || (ta.title && ta.title.font), |
| 568 |
|
| 569 |
taFontColor = o.fontColor || (ta.majorTick && ta.majorTick.fontColor) || (ta.tick && ta.tick.fontColor) || "black", |
| 570 |
taTitleFontColor = o.titleFontColor || (ta.title && ta.title.fontColor) || "black", |
| 571 |
taTitleGap = (o.titleGap==0) ? 0 : o.titleGap || (ta.title && ta.title.gap) || 15, |
| 572 |
taTitleOrientation = o.titleOrientation || (ta.title && ta.title.orientation) || "axis", |
| 573 |
taMajorTick = this.chart.theme.getTick("major", o), |
| 574 |
taMinorTick = this.chart.theme.getTick("minor", o), |
| 575 |
taMicroTick = this.chart.theme.getTick("micro", o), |
| 576 |
|
| 577 |
tickSize = Math.max(taMajorTick.length, taMinorTick.length, taMicroTick.length), |
| 578 |
taStroke = "stroke" in o ? o.stroke : ta.stroke, |
| 579 |
size = taFont ? g.normalizedLength(g.splitFontString(taFont).size) : 0, |
| 580 |
cosr = Math.abs(Math.cos(rotation * Math.PI / 180)), |
| 581 |
sinr = Math.abs(Math.sin(rotation * Math.PI / 180)), |
| 582 |
tsize = taTitleFont ? g.normalizedLength(g.splitFontString(taTitleFont).size) : 0; |
| 583 |
if(typeof labelGap != "number"){ |
| 584 |
labelGap = 4; |
| 585 |
} |
| 586 |
if(rotation < 0){ |
| 587 |
rotation += 360; |
| 588 |
} |
| 589 |
var cachedLabelW = this._getMaxLabelSize(); |
| 590 |
cachedLabelW = cachedLabelW && cachedLabelW.majLabelW; |
| 591 |
if(this.vertical){ |
| 592 |
start = {y: dim.height - offsets.b}; |
| 593 |
stop = {y: offsets.t}; |
| 594 |
titlePos = {y: (dim.height - offsets.b + offsets.t)/2}; |
| 595 |
titleOffset = size * sinr + (cachedLabelW || 0) * cosr + labelGap + Math.max(taMajorTick.length, taMinorTick.length) + tsize + taTitleGap; |
| 596 |
axisVector = {x: 0, y: -1}; |
| 597 |
labelOffset = {x: 0, y: 0}; |
| 598 |
tickVector = {x: 1, y: 0}; |
| 599 |
anchorOffset = {x: labelGap, y: 0}; |
| 600 |
switch(rotation){ |
| 601 |
case 0: |
| 602 |
labelAlign = "end"; |
| 603 |
labelOffset.y = size * 0.4; |
| 604 |
break; |
| 605 |
case 90: |
| 606 |
labelAlign = "middle"; |
| 607 |
labelOffset.x = -size; |
| 608 |
break; |
| 609 |
case 180: |
| 610 |
labelAlign = "start"; |
| 611 |
labelOffset.y = -size * 0.4; |
| 612 |
break; |
| 613 |
case 270: |
| 614 |
labelAlign = "middle"; |
| 615 |
break; |
| 616 |
default: |
| 617 |
if(rotation < centerAnchorLimit){ |
| 618 |
labelAlign = "end"; |
| 619 |
labelOffset.y = size * 0.4; |
| 620 |
}else if(rotation < 90){ |
| 621 |
labelAlign = "end"; |
| 622 |
labelOffset.y = size * 0.4; |
| 623 |
}else if(rotation < (180 - centerAnchorLimit)){ |
| 624 |
labelAlign = "start"; |
| 625 |
}else if(rotation < (180 + centerAnchorLimit)){ |
| 626 |
labelAlign = "start"; |
| 627 |
labelOffset.y = -size * 0.4; |
| 628 |
}else if(rotation < 270){ |
| 629 |
labelAlign = "start"; |
| 630 |
labelOffset.x = leftBottom ? 0 : size * 0.4; |
| 631 |
}else if(rotation < (360 - centerAnchorLimit)){ |
| 632 |
labelAlign = "end"; |
| 633 |
labelOffset.x = leftBottom ? 0 : size * 0.4; |
| 634 |
}else{ |
| 635 |
labelAlign = "end"; |
| 636 |
labelOffset.y = size * 0.4; |
| 637 |
} |
| 638 |
} |
| 639 |
if(leftBottom){ |
| 640 |
start.x = stop.x = offsets.l; |
| 641 |
titleRotation = (taTitleOrientation && taTitleOrientation == "away") ? 90 : 270; |
| 642 |
titlePos.x = offsets.l - titleOffset + (titleRotation == 270 ? tsize : 0); |
| 643 |
tickVector.x = -1; |
| 644 |
anchorOffset.x = -anchorOffset.x; |
| 645 |
}else{ |
| 646 |
start.x = stop.x = dim.width - offsets.r; |
| 647 |
titleRotation = (taTitleOrientation && taTitleOrientation == "axis") ? 90 : 270; |
| 648 |
titlePos.x = dim.width - offsets.r + titleOffset - (titleRotation == 270 ? 0 : tsize); |
| 649 |
switch(labelAlign){ |
| 650 |
case "start": |
| 651 |
labelAlign = "end"; |
| 652 |
break; |
| 653 |
case "end": |
| 654 |
labelAlign = "start"; |
| 655 |
break; |
| 656 |
case "middle": |
| 657 |
labelOffset.x += size; |
| 658 |
break; |
| 659 |
} |
| 660 |
} |
| 661 |
}else{ |
| 662 |
start = {x: offsets.l}; |
| 663 |
stop = {x: dim.width - offsets.r}; |
| 664 |
titlePos = {x: (dim.width - offsets.r + offsets.l)/2}; |
| 665 |
titleOffset = size * cosr + (cachedLabelW || 0) * sinr + labelGap + Math.max(taMajorTick.length, taMinorTick.length) + tsize + taTitleGap; |
| 666 |
axisVector = {x: 1, y: 0}; |
| 667 |
labelOffset = {x: 0, y: 0}; |
| 668 |
tickVector = {x: 0, y: 1}; |
| 669 |
anchorOffset = {x: 0, y: labelGap}; |
| 670 |
switch(rotation){ |
| 671 |
case 0: |
| 672 |
labelAlign = "middle"; |
| 673 |
labelOffset.y = size; |
| 674 |
break; |
| 675 |
case 90: |
| 676 |
labelAlign = "start"; |
| 677 |
labelOffset.x = -size * 0.4; |
| 678 |
break; |
| 679 |
case 180: |
| 680 |
labelAlign = "middle"; |
| 681 |
break; |
| 682 |
case 270: |
| 683 |
labelAlign = "end"; |
| 684 |
labelOffset.x = size * 0.4; |
| 685 |
break; |
| 686 |
default: |
| 687 |
if(rotation < (90 - centerAnchorLimit)){ |
| 688 |
labelAlign = "start"; |
| 689 |
labelOffset.y = leftBottom ? size : 0; |
| 690 |
}else if(rotation < (90 + centerAnchorLimit)){ |
| 691 |
labelAlign = "start"; |
| 692 |
labelOffset.x = -size * 0.4; |
| 693 |
}else if(rotation < 180){ |
| 694 |
labelAlign = "start"; |
| 695 |
labelOffset.y = leftBottom ? 0 : -size; |
| 696 |
}else if(rotation < (270 - centerAnchorLimit)){ |
| 697 |
labelAlign = "end"; |
| 698 |
labelOffset.y = leftBottom ? 0 : -size; |
| 699 |
}else if(rotation < (270 + centerAnchorLimit)){ |
| 700 |
labelAlign = "end"; |
| 701 |
labelOffset.y = leftBottom ? size * 0.4 : 0; |
| 702 |
}else{ |
| 703 |
labelAlign = "end"; |
| 704 |
labelOffset.y = leftBottom ? size : 0; |
| 705 |
} |
| 706 |
} |
| 707 |
if(leftBottom){ |
| 708 |
start.y = stop.y = dim.height - offsets.b; |
| 709 |
titleRotation = (taTitleOrientation && taTitleOrientation == "axis") ? 180 : 0; |
| 710 |
titlePos.y = dim.height - offsets.b + titleOffset - (titleRotation ? tsize : 0); |
| 711 |
}else{ |
| 712 |
start.y = stop.y = offsets.t; |
| 713 |
titleRotation = (taTitleOrientation && taTitleOrientation == "away") ? 180 : 0; |
| 714 |
titlePos.y = offsets.t - titleOffset + (titleRotation ? 0 : tsize); |
| 715 |
tickVector.y = -1; |
| 716 |
anchorOffset.y = -anchorOffset.y; |
| 717 |
switch(labelAlign){ |
| 718 |
case "start": |
| 719 |
labelAlign = "end"; |
| 720 |
break; |
| 721 |
case "end": |
| 722 |
labelAlign = "start"; |
| 723 |
break; |
| 724 |
case "middle": |
| 725 |
labelOffset.y -= size; |
| 726 |
break; |
| 727 |
} |
| 728 |
} |
| 729 |
} |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
this.cleanGroup(); |
| 734 |
|
| 735 |
var s = this.group, |
| 736 |
c = this.scaler, |
| 737 |
t = this.ticks, |
| 738 |
f = this.scalerType.getTransformerFromModel(this.scaler), |
| 739 |
|
| 740 |
|
| 741 |
labelType = (!o.title || !titleRotation) && !rotation && this.opt.htmlLabels && !has("ie") && !has("opera") ? "html" : "gfx", |
| 742 |
dx = tickVector.x * taMajorTick.length, |
| 743 |
dy = tickVector.y * taMajorTick.length, |
| 744 |
skip = this._skipInterval; |
| 745 |
|
| 746 |
s.createLine({ |
| 747 |
x1: start.x, |
| 748 |
y1: start.y, |
| 749 |
x2: stop.x, |
| 750 |
y2: stop.y |
| 751 |
}).setStroke(taStroke); |
| 752 |
|
| 753 |
|
| 754 |
if(o.title){ |
| 755 |
var axisTitle = acommon.createText[labelType]( |
| 756 |
this.chart, |
| 757 |
s, |
| 758 |
titlePos.x, |
| 759 |
titlePos.y, |
| 760 |
"middle", |
| 761 |
o.title, |
| 762 |
taTitleFont, |
| 763 |
taTitleFontColor |
| 764 |
); |
| 765 |
if(labelType == "html"){ |
| 766 |
this.htmlElements.push(axisTitle); |
| 767 |
}else{ |
| 768 |
|
| 769 |
|
| 770 |
axisTitle.setTransform(g.matrix.rotategAt(titleRotation, titlePos.x, titlePos.y)); |
| 771 |
} |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
if(t == null){ |
| 776 |
this.dirty = false; |
| 777 |
return this; |
| 778 |
} |
| 779 |
|
| 780 |
var canLabel = this.opt.majorLabels; |
| 781 |
arr.forEach(t.major, function(tick, i){ |
| 782 |
var offset = f(tick.value), elem, |
| 783 |
x = start.x + axisVector.x * offset, |
| 784 |
y = start.y + axisVector.y * offset; |
| 785 |
this.createLine(s, { |
| 786 |
x1: x, y1: y, |
| 787 |
x2: x + dx, |
| 788 |
y2: y + dy |
| 789 |
}).setStroke(taMajorTick); |
| 790 |
if(tick.label && (!skip || (i - (1 + skip)) % (1 + skip) == 0)){ |
| 791 |
var label = o.maxLabelCharCount ? this.getTextWithLimitCharCount(tick.label, taFont, o.maxLabelCharCount) : { |
| 792 |
text: tick.label, |
| 793 |
truncated: false |
| 794 |
}; |
| 795 |
label = o.maxLabelSize ? this.getTextWithLimitLength(label.text, taFont, o.maxLabelSize, label.truncated) : label; |
| 796 |
elem = this.createText(labelType, |
| 797 |
s, |
| 798 |
x + dx + anchorOffset.x + (rotation ? 0 : labelOffset.x), |
| 799 |
y + dy + anchorOffset.y + (rotation ? 0 : labelOffset.y), |
| 800 |
labelAlign, |
| 801 |
label.text, |
| 802 |
taFont, |
| 803 |
taFontColor |
| 804 |
|
| 805 |
); |
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
if(this.chart.truncateBidi && label.truncated){ |
| 812 |
this.chart.truncateBidi(elem, tick.label, labelType); |
| 813 |
} |
| 814 |
label.truncated && this.labelTooltip(elem, this.chart, tick.label, label.text, taFont, labelType); |
| 815 |
if(labelType == "html"){ |
| 816 |
this.htmlElements.push(elem); |
| 817 |
}else if(rotation){ |
| 818 |
elem.setTransform([ |
| 819 |
{dx: labelOffset.x, dy: labelOffset.y}, |
| 820 |
g.matrix.rotategAt( |
| 821 |
rotation, |
| 822 |
x + dx + anchorOffset.x, |
| 823 |
y + dy + anchorOffset.y |
| 824 |
) |
| 825 |
]); |
| 826 |
} |
| 827 |
} |
| 828 |
}, this); |
| 829 |
|
| 830 |
dx = tickVector.x * taMinorTick.length; |
| 831 |
dy = tickVector.y * taMinorTick.length; |
| 832 |
canLabel = this.opt.minorLabels && !skip && this.opt.log === 10 && t.minor.length; |
| 833 |
if(canLabel){ |
| 834 |
|
| 835 |
var minorTickMinSize = 1, logBase = Math.log(10); |
| 836 |
arr.forEach(t.minor, function(tick, i){ |
| 837 |
var logValue = Math.log(tick.value) / logBase, |
| 838 |
logFloor = Math.floor(logValue), logCeil = Math.ceil(logValue); |
| 839 |
minorTickMinSize = Math.min(minorTickMinSize, logValue - logFloor, logCeil - logValue); |
| 840 |
if(i){ |
| 841 |
minorTickMinSize = Math.min(minorTickMinSize, |
| 842 |
logValue - Math.log(t.minor[i - 1].value) / logBase); |
| 843 |
} |
| 844 |
}); |
| 845 |
canLabel = c.minMinorStep <= minorTickMinSize * c.bounds.scale; |
| 846 |
} |
| 847 |
arr.forEach(t.minor, function(tick){ |
| 848 |
var offset = f(tick.value), elem, |
| 849 |
x = start.x + axisVector.x * offset, |
| 850 |
y = start.y + axisVector.y * offset; |
| 851 |
this.createLine(s, { |
| 852 |
x1: x, y1: y, |
| 853 |
x2: x + dx, |
| 854 |
y2: y + dy |
| 855 |
}).setStroke(taMinorTick); |
| 856 |
if(canLabel && tick.label){ |
| 857 |
var label = o.maxLabelCharCount ? this.getTextWithLimitCharCount(tick.label, taFont, o.maxLabelCharCount) : { |
| 858 |
text: tick.label, |
| 859 |
truncated: false |
| 860 |
}; |
| 861 |
label = o.maxLabelSize ? this.getTextWithLimitLength(label.text, taFont, o.maxLabelSize, label.truncated) : label; |
| 862 |
elem = this.createText(labelType, |
| 863 |
s, |
| 864 |
x + dx + anchorOffset.x + (rotation ? 0 : labelOffset.x), |
| 865 |
y + dy + anchorOffset.y + (rotation ? 0 : labelOffset.y), |
| 866 |
labelAlign, |
| 867 |
label.text, |
| 868 |
taFont, |
| 869 |
taFontColor |
| 870 |
|
| 871 |
); |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
if(this.chart.getTextDir && label.truncated){ |
| 878 |
this.chart.truncateBidi(elem, tick.label, labelType); |
| 879 |
} |
| 880 |
label.truncated && this.labelTooltip(elem, this.chart, tick.label, label.text, taFont, labelType); |
| 881 |
if(labelType == "html"){ |
| 882 |
this.htmlElements.push(elem); |
| 883 |
}else if(rotation){ |
| 884 |
elem.setTransform([ |
| 885 |
{dx: labelOffset.x, dy: labelOffset.y}, |
| 886 |
g.matrix.rotategAt( |
| 887 |
rotation, |
| 888 |
x + dx + anchorOffset.x, |
| 889 |
y + dy + anchorOffset.y |
| 890 |
) |
| 891 |
]); |
| 892 |
} |
| 893 |
} |
| 894 |
}, this); |
| 895 |
|
| 896 |
dx = tickVector.x * taMicroTick.length; |
| 897 |
dy = tickVector.y * taMicroTick.length; |
| 898 |
arr.forEach(t.micro, function(tick){ |
| 899 |
var offset = f(tick.value), elem, |
| 900 |
x = start.x + axisVector.x * offset, |
| 901 |
y = start.y + axisVector.y * offset; |
| 902 |
this.createLine(s, { |
| 903 |
x1: x, y1: y, |
| 904 |
x2: x + dx, |
| 905 |
y2: y + dy |
| 906 |
}).setStroke(taMicroTick); |
| 907 |
}, this); |
| 908 |
|
| 909 |
this.dirty = false; |
| 910 |
return this; |
| 911 |
}, |
| 912 |
labelTooltip: function(elem, chart, label, truncatedLabel, font, elemType){ |
| 913 |
var modules = ["dijit/Tooltip"]; |
| 914 |
var aroundRect = {type: "rect"}, position = ["above", "below"], |
| 915 |
fontWidth = g._base._getTextBox(truncatedLabel, {font: font}).w || 0, |
| 916 |
fontHeight = font ? g.normalizedLength(g.splitFontString(font).size) : 0; |
| 917 |
if(elemType == "html"){ |
| 918 |
lang.mixin(aroundRect, domGeom.position(elem.firstChild, true)); |
| 919 |
aroundRect.width = Math.ceil(fontWidth); |
| 920 |
aroundRect.height = Math.ceil(fontHeight); |
| 921 |
this._events.push({ |
| 922 |
shape: dojo, |
| 923 |
handle: connect.connect(elem.firstChild, "onmouseover", this, function(e){ |
| 924 |
require(modules, function(Tooltip){ |
| 925 |
Tooltip.show(label, aroundRect, position); |
| 926 |
}); |
| 927 |
}) |
| 928 |
}); |
| 929 |
this._events.push({ |
| 930 |
shape: dojo, |
| 931 |
handle: connect.connect(elem.firstChild, "onmouseout", this, function(e){ |
| 932 |
require(modules, function(Tooltip){ |
| 933 |
Tooltip.hide(aroundRect); |
| 934 |
}); |
| 935 |
}) |
| 936 |
}); |
| 937 |
}else{ |
| 938 |
var shp = elem.getShape(), |
| 939 |
lt = chart.getCoords(); |
| 940 |
aroundRect = lang.mixin(aroundRect, { |
| 941 |
x: shp.x - fontWidth / 2, |
| 942 |
y: shp.y |
| 943 |
}); |
| 944 |
aroundRect.x += lt.x; |
| 945 |
aroundRect.y += lt.y; |
| 946 |
aroundRect.x = Math.round(aroundRect.x); |
| 947 |
aroundRect.y = Math.round(aroundRect.y); |
| 948 |
aroundRect.width = Math.ceil(fontWidth); |
| 949 |
aroundRect.height = Math.ceil(fontHeight); |
| 950 |
this._events.push({ |
| 951 |
shape: elem, |
| 952 |
handle: elem.connect("onmouseenter", this, function(e){ |
| 953 |
require(modules, function(Tooltip){ |
| 954 |
Tooltip.show(label, aroundRect, position); |
| 955 |
}); |
| 956 |
}) |
| 957 |
}); |
| 958 |
this._events.push({ |
| 959 |
shape: elem, |
| 960 |
handle: elem.connect("onmouseleave", this, function(e){ |
| 961 |
require(modules, function(Tooltip){ |
| 962 |
Tooltip.hide(aroundRect); |
| 963 |
}); |
| 964 |
}) |
| 965 |
}); |
| 966 |
} |
| 967 |
}, |
| 968 |
isNullValue: function(value){ |
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
return value <= 0; |
| 977 |
}, |
| 978 |
naturalBaseline: 1 |
| 979 |
}); |
| 980 |
}); |