| 1 |
define(["../main", "dojo/_base/lang", "dojo/_base/array","dojo/_base/declare", "dojo/dom-style", |
| 2 |
"dojo/dom", "dojo/dom-geometry", "dojo/dom-construct","dojo/_base/Color", "dojo/sniff", |
| 3 |
"./Element", "./SimpleTheme", "./Series", "./axis2d/common", "./plot2d/common", "dojox/gfx/shape", |
| 4 |
"dojox/gfx", "dojo/has!dojo-bidi?./bidi/Chart", "dojox/lang/functional", "dojox/lang/functional/fold", "dojox/lang/functional/reversed"], |
| 5 |
function(dojox, lang, arr, declare, domStyle, |
| 6 |
dom, domGeom, domConstruct, Color, has, |
| 7 |
Element, SimpleTheme, Series, common, plot2dCommon, shape, |
| 8 |
g, BidiChart, func){ |
| 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 |
var dc = lang.getObject("charting", true, dojox), |
| 47 |
defaultMargins = {l: 10, t: 10, r: 10, b: 10}; |
| 48 |
|
| 49 |
function clear (item) { |
| 50 |
return item.clear(); |
| 51 |
} |
| 52 |
|
| 53 |
function destroy (item) { |
| 54 |
return item.destroy(); |
| 55 |
} |
| 56 |
|
| 57 |
function makeClean (item) { |
| 58 |
item.dirty = false; |
| 59 |
return false; |
| 60 |
} |
| 61 |
|
| 62 |
function makeDirty (item) { |
| 63 |
item.dirty = true; |
| 64 |
return true; |
| 65 |
} |
| 66 |
|
| 67 |
function getName (item) { |
| 68 |
return item.name; |
| 69 |
} |
| 70 |
|
| 71 |
var Chart = declare(has("dojo-bidi")? "dojox.charting.NonBidiChart" : "dojox.charting.Chart", null, { |
| 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 |
|
| 100 |
|
| 101 |
|
| 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 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
constructor: function(node, kwArgs){ |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
if(!kwArgs){ kwArgs = {}; } |
| 180 |
this.margins = kwArgs.margins || defaultMargins; |
| 181 |
this._customMargins = !!kwArgs.margins; |
| 182 |
this.stroke = kwArgs.stroke; |
| 183 |
this.fill = kwArgs.fill; |
| 184 |
this.delayInMs = kwArgs.delayInMs || 200; |
| 185 |
this.title = kwArgs.title; |
| 186 |
this.titleGap = kwArgs.titleGap; |
| 187 |
this.titlePos = kwArgs.titlePos; |
| 188 |
this.titleFont = kwArgs.titleFont; |
| 189 |
this.titleFontColor = kwArgs.titleFontColor; |
| 190 |
this.titleAlign = kwArgs.titleAlign; |
| 191 |
|
| 192 |
this.chartTitle = null; |
| 193 |
this.htmlLabels = true; |
| 194 |
if("htmlLabels" in kwArgs){ |
| 195 |
this.htmlLabels = kwArgs.htmlLabels; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
this.theme = null; |
| 200 |
this.axes = {}; |
| 201 |
this.stack = []; |
| 202 |
this.plots = {}; |
| 203 |
this.series = []; |
| 204 |
this.runs = {}; |
| 205 |
this.dirty = true; |
| 206 |
|
| 207 |
|
| 208 |
this.node = dom.byId(node); |
| 209 |
var box = domGeom.getMarginBox(node); |
| 210 |
this.surface = g.createSurface(this.node, box.w || 400, box.h || 300); |
| 211 |
if(this.surface.declaredClass.indexOf("vml") == -1){ |
| 212 |
|
| 213 |
this._nativeClip = true; |
| 214 |
} |
| 215 |
}, |
| 216 |
destroy: function(){ |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
arr.forEach(this.series, destroy); |
| 221 |
arr.forEach(this.stack, destroy); |
| 222 |
func.forIn(this.axes, destroy); |
| 223 |
this.surface.destroy(); |
| 224 |
if(this.chartTitle && this.chartTitle.tagName){ |
| 225 |
|
| 226 |
domConstruct.destroy(this.chartTitle); |
| 227 |
} |
| 228 |
}, |
| 229 |
getCoords: function(){ |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
var node = this.node; |
| 236 |
var s = domStyle.getComputedStyle(node), coords = domGeom.getMarginBox(node, s); |
| 237 |
var abs = domGeom.position(node, true); |
| 238 |
coords.x = abs.x; |
| 239 |
coords.y = abs.y; |
| 240 |
return coords; |
| 241 |
}, |
| 242 |
setTheme: function(theme){ |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
this.theme = theme.clone(); |
| 250 |
if(!this._customMargins){ |
| 251 |
this.margins = this.theme.chart.margins || defaultMargins; |
| 252 |
} |
| 253 |
this.dirty = true; |
| 254 |
return this; |
| 255 |
}, |
| 256 |
addAxis: function(name, kwArgs){ |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
var axis, axisType = kwArgs && kwArgs.type || "Default"; |
| 266 |
if(typeof axisType == "string"){ |
| 267 |
if(!dc.axis2d || !dc.axis2d[axisType]){ |
| 268 |
throw Error("Can't find axis: " + axisType + " - Check " + "require() dependencies."); |
| 269 |
} |
| 270 |
axis = new dc.axis2d[axisType](this, kwArgs); |
| 271 |
}else{ |
| 272 |
axis = new axisType(this, kwArgs); |
| 273 |
} |
| 274 |
axis.name = name; |
| 275 |
axis.dirty = true; |
| 276 |
if(name in this.axes){ |
| 277 |
this.axes[name].destroy(); |
| 278 |
} |
| 279 |
this.axes[name] = axis; |
| 280 |
this.dirty = true; |
| 281 |
return this; |
| 282 |
}, |
| 283 |
getAxis: function(name){ |
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
return this.axes[name]; |
| 291 |
}, |
| 292 |
removeAxis: function(name){ |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
if(name in this.axes){ |
| 300 |
|
| 301 |
this.axes[name].destroy(); |
| 302 |
delete this.axes[name]; |
| 303 |
|
| 304 |
this.dirty = true; |
| 305 |
} |
| 306 |
return this; |
| 307 |
}, |
| 308 |
addPlot: function(name, kwArgs){ |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
var plot, plotType = kwArgs && kwArgs.type || "Default"; |
| 321 |
if(typeof plotType == "string"){ |
| 322 |
if(!dc.plot2d || !dc.plot2d[plotType]){ |
| 323 |
throw Error("Can't find plot: " + plotType + " - didn't you forget to dojo" + ".require() it?"); |
| 324 |
} |
| 325 |
plot = new dc.plot2d[plotType](this, kwArgs); |
| 326 |
}else{ |
| 327 |
plot = new plotType(this, kwArgs); |
| 328 |
} |
| 329 |
plot.name = name; |
| 330 |
plot.dirty = true; |
| 331 |
if(name in this.plots){ |
| 332 |
this.stack[this.plots[name]].destroy(); |
| 333 |
this.stack[this.plots[name]] = plot; |
| 334 |
}else{ |
| 335 |
this.plots[name] = this.stack.length; |
| 336 |
this.stack.push(plot); |
| 337 |
} |
| 338 |
this.dirty = true; |
| 339 |
return this; |
| 340 |
}, |
| 341 |
getPlot: function(name){ |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
return this.stack[this.plots[name]]; |
| 349 |
}, |
| 350 |
removePlot: function(name){ |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
if(name in this.plots){ |
| 358 |
|
| 359 |
var index = this.plots[name]; |
| 360 |
delete this.plots[name]; |
| 361 |
|
| 362 |
this.stack[index].destroy(); |
| 363 |
|
| 364 |
this.stack.splice(index, 1); |
| 365 |
|
| 366 |
func.forIn(this.plots, function(idx, name, plots){ |
| 367 |
if(idx > index){ |
| 368 |
plots[name] = idx - 1; |
| 369 |
} |
| 370 |
}); |
| 371 |
|
| 372 |
var ns = arr.filter(this.series, function(run){ return run.plot != name; }); |
| 373 |
if(ns.length < this.series.length){ |
| 374 |
|
| 375 |
arr.forEach(this.series, function(run){ |
| 376 |
if(run.plot == name){ |
| 377 |
run.destroy(); |
| 378 |
} |
| 379 |
}); |
| 380 |
|
| 381 |
this.runs = {}; |
| 382 |
arr.forEach(ns, function(run, index){ |
| 383 |
this.runs[run.plot] = index; |
| 384 |
}, this); |
| 385 |
this.series = ns; |
| 386 |
} |
| 387 |
|
| 388 |
this.dirty = true; |
| 389 |
} |
| 390 |
return this; |
| 391 |
}, |
| 392 |
getPlotOrder: function(){ |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
return func.map(this.stack, getName); |
| 398 |
}, |
| 399 |
setPlotOrder: function(newOrder){ |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
var names = {}, |
| 408 |
order = func.filter(newOrder, function(name){ |
| 409 |
if(!(name in this.plots) || (name in names)){ |
| 410 |
return false; |
| 411 |
} |
| 412 |
names[name] = 1; |
| 413 |
return true; |
| 414 |
}, this); |
| 415 |
if(order.length < this.stack.length){ |
| 416 |
func.forEach(this.stack, function(plot){ |
| 417 |
var name = plot.name; |
| 418 |
if(!(name in names)){ |
| 419 |
order.push(name); |
| 420 |
} |
| 421 |
}); |
| 422 |
} |
| 423 |
var newStack = func.map(order, function(name){ |
| 424 |
return this.stack[this.plots[name]]; |
| 425 |
}, this); |
| 426 |
func.forEach(newStack, function(plot, i){ |
| 427 |
this.plots[plot.name] = i; |
| 428 |
}, this); |
| 429 |
this.stack = newStack; |
| 430 |
this.dirty = true; |
| 431 |
return this; |
| 432 |
}, |
| 433 |
movePlotToFront: function(name){ |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
if(name in this.plots){ |
| 441 |
var index = this.plots[name]; |
| 442 |
if(index){ |
| 443 |
var newOrder = this.getPlotOrder(); |
| 444 |
newOrder.splice(index, 1); |
| 445 |
newOrder.unshift(name); |
| 446 |
return this.setPlotOrder(newOrder); |
| 447 |
} |
| 448 |
} |
| 449 |
return this; |
| 450 |
}, |
| 451 |
movePlotToBack: function(name){ |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
if(name in this.plots){ |
| 459 |
var index = this.plots[name]; |
| 460 |
if(index < this.stack.length - 1){ |
| 461 |
var newOrder = this.getPlotOrder(); |
| 462 |
newOrder.splice(index, 1); |
| 463 |
newOrder.push(name); |
| 464 |
return this.setPlotOrder(newOrder); |
| 465 |
} |
| 466 |
} |
| 467 |
return this; |
| 468 |
}, |
| 469 |
addSeries: function(name, data, kwArgs){ |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
var run = new Series(this, data, kwArgs); |
| 485 |
run.name = name; |
| 486 |
if(name in this.runs){ |
| 487 |
this.series[this.runs[name]].destroy(); |
| 488 |
this.series[this.runs[name]] = run; |
| 489 |
}else{ |
| 490 |
this.runs[name] = this.series.length; |
| 491 |
this.series.push(run); |
| 492 |
} |
| 493 |
this.dirty = true; |
| 494 |
|
| 495 |
if(!("ymin" in run) && "min" in run){ run.ymin = run.min; } |
| 496 |
if(!("ymax" in run) && "max" in run){ run.ymax = run.max; } |
| 497 |
return this; |
| 498 |
}, |
| 499 |
getSeries: function(name){ |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
return this.series[this.runs[name]]; |
| 507 |
}, |
| 508 |
removeSeries: function(name){ |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
if(name in this.runs){ |
| 516 |
|
| 517 |
var index = this.runs[name]; |
| 518 |
delete this.runs[name]; |
| 519 |
|
| 520 |
this.series[index].destroy(); |
| 521 |
|
| 522 |
this.series.splice(index, 1); |
| 523 |
|
| 524 |
func.forIn(this.runs, function(idx, name, runs){ |
| 525 |
if(idx > index){ |
| 526 |
runs[name] = idx - 1; |
| 527 |
} |
| 528 |
}); |
| 529 |
this.dirty = true; |
| 530 |
} |
| 531 |
return this; |
| 532 |
}, |
| 533 |
updateSeries: function(name, data, offsets){ |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
if(name in this.runs){ |
| 550 |
var run = this.series[this.runs[name]]; |
| 551 |
run.update(data); |
| 552 |
if(offsets){ |
| 553 |
this.dirty = true; |
| 554 |
}else{ |
| 555 |
this._invalidateDependentPlots(run.plot, false); |
| 556 |
this._invalidateDependentPlots(run.plot, true); |
| 557 |
} |
| 558 |
} |
| 559 |
return this; |
| 560 |
}, |
| 561 |
getSeriesOrder: function(plotName){ |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
return func.map(func.filter(this.series, function(run){ |
| 569 |
return run.plot == plotName; |
| 570 |
}), getName); |
| 571 |
}, |
| 572 |
setSeriesOrder: function(newOrder){ |
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
var plotName, names = {}, |
| 582 |
order = func.filter(newOrder, function(name){ |
| 583 |
if(!(name in this.runs) || (name in names)){ |
| 584 |
return false; |
| 585 |
} |
| 586 |
var run = this.series[this.runs[name]]; |
| 587 |
if(plotName){ |
| 588 |
if(run.plot != plotName){ |
| 589 |
return false; |
| 590 |
} |
| 591 |
}else{ |
| 592 |
plotName = run.plot; |
| 593 |
} |
| 594 |
names[name] = 1; |
| 595 |
return true; |
| 596 |
}, this); |
| 597 |
func.forEach(this.series, function(run){ |
| 598 |
var name = run.name; |
| 599 |
if(!(name in names) && run.plot == plotName){ |
| 600 |
order.push(name); |
| 601 |
} |
| 602 |
}); |
| 603 |
var newSeries = func.map(order, function(name){ |
| 604 |
return this.series[this.runs[name]]; |
| 605 |
}, this); |
| 606 |
this.series = newSeries.concat(func.filter(this.series, function(run){ |
| 607 |
return run.plot != plotName; |
| 608 |
})); |
| 609 |
func.forEach(this.series, function(run, i){ |
| 610 |
this.runs[run.name] = i; |
| 611 |
}, this); |
| 612 |
this.dirty = true; |
| 613 |
return this; |
| 614 |
}, |
| 615 |
moveSeriesToFront: function(name){ |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
if(name in this.runs){ |
| 623 |
var index = this.runs[name], |
| 624 |
newOrder = this.getSeriesOrder(this.series[index].plot); |
| 625 |
if(name != newOrder[0]){ |
| 626 |
newOrder.splice(index, 1); |
| 627 |
newOrder.unshift(name); |
| 628 |
return this.setSeriesOrder(newOrder); |
| 629 |
} |
| 630 |
} |
| 631 |
return this; |
| 632 |
}, |
| 633 |
moveSeriesToBack: function(name){ |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
if(name in this.runs){ |
| 641 |
var index = this.runs[name], |
| 642 |
newOrder = this.getSeriesOrder(this.series[index].plot); |
| 643 |
if(name != newOrder[newOrder.length - 1]){ |
| 644 |
newOrder.splice(index, 1); |
| 645 |
newOrder.push(name); |
| 646 |
return this.setSeriesOrder(newOrder); |
| 647 |
} |
| 648 |
} |
| 649 |
return this; |
| 650 |
}, |
| 651 |
resize: function(width, height){ |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
switch(arguments.length){ |
| 665 |
|
| 666 |
case 1: |
| 667 |
|
| 668 |
domGeom.setMarginBox(this.node, width); |
| 669 |
break; |
| 670 |
case 2: |
| 671 |
|
| 672 |
domGeom.setMarginBox(this.node, {w: width, h: height}); |
| 673 |
break; |
| 674 |
} |
| 675 |
|
| 676 |
var box = domGeom.getMarginBox(this.node); |
| 677 |
var d = this.surface.getDimensions(); |
| 678 |
if(d.width != box.w || d.height != box.h){ |
| 679 |
|
| 680 |
this.surface.setDimensions(box.w, box.h); |
| 681 |
this.dirty = true; |
| 682 |
return this.render(); |
| 683 |
}else{ |
| 684 |
return this; |
| 685 |
} |
| 686 |
}, |
| 687 |
getGeometry: function(){ |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
var ret = {}; |
| 694 |
func.forIn(this.axes, function(axis){ |
| 695 |
if(axis.initialized()){ |
| 696 |
ret[axis.name] = { |
| 697 |
name: axis.name, |
| 698 |
vertical: axis.vertical, |
| 699 |
scaler: axis.scaler, |
| 700 |
ticks: axis.ticks |
| 701 |
}; |
| 702 |
} |
| 703 |
}); |
| 704 |
return ret; |
| 705 |
}, |
| 706 |
setAxisWindow: function(name, scale, offset, zoom){ |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
var axis = this.axes[name]; |
| 721 |
if(axis){ |
| 722 |
axis.setWindow(scale, offset); |
| 723 |
arr.forEach(this.stack,function(plot){ |
| 724 |
if(plot.hAxis == name || plot.vAxis == name){ |
| 725 |
plot.zoom = zoom; |
| 726 |
} |
| 727 |
}); |
| 728 |
} |
| 729 |
return this; |
| 730 |
}, |
| 731 |
setWindow: function(sx, sy, dx, dy, zoom){ |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
if(!("plotArea" in this)){ |
| 748 |
this.calculateGeometry(); |
| 749 |
} |
| 750 |
func.forIn(this.axes, function(axis){ |
| 751 |
var scale, offset, bounds = axis.getScaler().bounds, |
| 752 |
s = bounds.span / (bounds.upper - bounds.lower); |
| 753 |
if(axis.vertical){ |
| 754 |
scale = sy; |
| 755 |
offset = dy / s / scale; |
| 756 |
}else{ |
| 757 |
scale = sx; |
| 758 |
offset = dx / s / scale; |
| 759 |
} |
| 760 |
axis.setWindow(scale, offset); |
| 761 |
}); |
| 762 |
arr.forEach(this.stack, function(plot){ plot.zoom = zoom; }); |
| 763 |
return this; |
| 764 |
}, |
| 765 |
zoomIn: function(name, range, delayed){ |
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
var axis = this.axes[name]; |
| 774 |
if(axis){ |
| 775 |
var scale, offset, bounds = axis.getScaler().bounds; |
| 776 |
var lower = Math.min(range[0],range[1]); |
| 777 |
var upper = Math.max(range[0],range[1]); |
| 778 |
lower = range[0] < bounds.lower ? bounds.lower : lower; |
| 779 |
upper = range[1] > bounds.upper ? bounds.upper : upper; |
| 780 |
scale = (bounds.upper - bounds.lower) / (upper - lower); |
| 781 |
offset = lower - bounds.lower; |
| 782 |
this.setAxisWindow(name, scale, offset); |
| 783 |
if(delayed){ |
| 784 |
this.delayedRender(); |
| 785 |
}else{ |
| 786 |
this.render(); |
| 787 |
} |
| 788 |
} |
| 789 |
}, |
| 790 |
calculateGeometry: function(){ |
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
if(this.dirty){ |
| 797 |
return this.fullGeometry(); |
| 798 |
} |
| 799 |
|
| 800 |
|
| 801 |
var dirty = arr.filter(this.stack, function(plot){ |
| 802 |
return plot.dirty || |
| 803 |
(plot.hAxis && this.axes[plot.hAxis].dirty) || |
| 804 |
(plot.vAxis && this.axes[plot.vAxis].dirty); |
| 805 |
}, this); |
| 806 |
calculateAxes(dirty, this.plotArea); |
| 807 |
|
| 808 |
return this; |
| 809 |
}, |
| 810 |
fullGeometry: function(){ |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
this._makeDirty(); |
| 818 |
|
| 819 |
|
| 820 |
arr.forEach(this.stack, clear); |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
if(!this.theme){ |
| 826 |
this.setTheme(new SimpleTheme()); |
| 827 |
} |
| 828 |
|
| 829 |
|
| 830 |
arr.forEach(this.series, function(run){ |
| 831 |
if(!(run.plot in this.plots)){ |
| 832 |
|
| 833 |
if(!dc.plot2d || !dc.plot2d.Default){ |
| 834 |
throw Error("Can't find plot: Default - didn't you forget to dojo" + ".require() it?"); |
| 835 |
} |
| 836 |
var plot = new dc.plot2d.Default(this, {}); |
| 837 |
plot.name = run.plot; |
| 838 |
this.plots[run.plot] = this.stack.length; |
| 839 |
this.stack.push(plot); |
| 840 |
} |
| 841 |
this.stack[this.plots[run.plot]].addSeries(run); |
| 842 |
}, this); |
| 843 |
|
| 844 |
arr.forEach(this.stack, function(plot){ |
| 845 |
if(plot.assignAxes){ |
| 846 |
plot.assignAxes(this.axes); |
| 847 |
} |
| 848 |
}, this); |
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
var dim = this.dim = this.surface.getDimensions(); |
| 854 |
dim.width = g.normalizedLength(dim.width); |
| 855 |
dim.height = g.normalizedLength(dim.height); |
| 856 |
func.forIn(this.axes, clear); |
| 857 |
calculateAxes(this.stack, dim); |
| 858 |
|
| 859 |
|
| 860 |
var offsets = this.offsets = {l: 0, r: 0, t: 0, b: 0}; |
| 861 |
|
| 862 |
var self = this; |
| 863 |
func.forIn(this.axes, function(axis){ |
| 864 |
if(has("dojo-bidi")){ |
| 865 |
self._resetLeftBottom(axis); |
| 866 |
} |
| 867 |
func.forIn(axis.getOffsets(), function(o, i){ offsets[i] = Math.max(o, offsets[i]); }); |
| 868 |
}); |
| 869 |
|
| 870 |
|
| 871 |
if(this.title){ |
| 872 |
this.titleGap = (this.titleGap==0) ? 0 : this.titleGap || this.theme.chart.titleGap || 20; |
| 873 |
this.titlePos = this.titlePos || this.theme.chart.titlePos || "top"; |
| 874 |
this.titleFont = this.titleFont || this.theme.chart.titleFont; |
| 875 |
this.titleFontColor = this.titleFontColor || this.theme.chart.titleFontColor || "black"; |
| 876 |
this.titleAlign = this.titleAlign || this.theme && this.theme.chart && this.theme.chart.titleAlign || "middle"; |
| 877 |
var tsize = g.normalizedLength(g.splitFontString(this.titleFont).size); |
| 878 |
offsets[this.titlePos == "top" ? "t" : "b"] += (tsize + this.titleGap); |
| 879 |
} |
| 880 |
|
| 881 |
func.forIn(this.margins, function(o, i){ offsets[i] += o; }); |
| 882 |
|
| 883 |
|
| 884 |
this.plotArea = { |
| 885 |
width: dim.width - offsets.l - offsets.r, |
| 886 |
height: dim.height - offsets.t - offsets.b |
| 887 |
}; |
| 888 |
func.forIn(this.axes, clear); |
| 889 |
calculateAxes(this.stack, this.plotArea); |
| 890 |
|
| 891 |
return this; |
| 892 |
}, |
| 893 |
render: function(){ |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
if(this._delayedRenderHandle){ |
| 903 |
clearTimeout(this._delayedRenderHandle); |
| 904 |
this._delayedRenderHandle = null; |
| 905 |
} |
| 906 |
|
| 907 |
if(this.theme){ |
| 908 |
this.theme.clear(); |
| 909 |
} |
| 910 |
|
| 911 |
if(this.dirty){ |
| 912 |
return this.fullRender(); |
| 913 |
} |
| 914 |
|
| 915 |
this.calculateGeometry(); |
| 916 |
|
| 917 |
|
| 918 |
func.forEachRev(this.stack, function(plot){ plot.render(this.dim, this.offsets); }, this); |
| 919 |
|
| 920 |
|
| 921 |
func.forIn(this.axes, function(axis){ axis.render(this.dim, this.offsets); }, this); |
| 922 |
|
| 923 |
this._makeClean(); |
| 924 |
|
| 925 |
return this; |
| 926 |
}, |
| 927 |
fullRender: function(){ |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
this.fullGeometry(); |
| 936 |
var offsets = this.offsets, dim = this.dim; |
| 937 |
var w = Math.max(0, dim.width - offsets.l - offsets.r), |
| 938 |
h = Math.max(0, dim.height - offsets.t - offsets.b); |
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
arr.forEach(this.series, plot2dCommon.purgeGroup); |
| 946 |
func.forIn(this.axes, plot2dCommon.purgeGroup); |
| 947 |
arr.forEach(this.stack, plot2dCommon.purgeGroup); |
| 948 |
var children = this.surface.children; |
| 949 |
|
| 950 |
if(shape.dispose){ |
| 951 |
for(var i = 0; i < children.length;++i){ |
| 952 |
shape.dispose(children[i]); |
| 953 |
} |
| 954 |
} |
| 955 |
if(this.chartTitle && this.chartTitle.tagName){ |
| 956 |
|
| 957 |
domConstruct.destroy(this.chartTitle); |
| 958 |
} |
| 959 |
this.surface.clear(); |
| 960 |
this.chartTitle = null; |
| 961 |
|
| 962 |
this._renderChartBackground(dim, offsets); |
| 963 |
if(this._nativeClip){ |
| 964 |
this._renderPlotBackground(dim, offsets, w, h); |
| 965 |
}else{ |
| 966 |
|
| 967 |
this._renderPlotBackground(dim, offsets, w, h); |
| 968 |
} |
| 969 |
|
| 970 |
|
| 971 |
func.foldr(this.stack, function(z, plot){ return plot.render(dim, offsets), 0; }, 0); |
| 972 |
|
| 973 |
if(!this._nativeClip){ |
| 974 |
|
| 975 |
this._renderChartBackground(dim, offsets); |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
if(this.title){ |
| 980 |
this._renderTitle(dim, offsets); |
| 981 |
} |
| 982 |
|
| 983 |
|
| 984 |
func.forIn(this.axes, function(axis){ axis.render(dim, offsets); }); |
| 985 |
|
| 986 |
this._makeClean(); |
| 987 |
|
| 988 |
return this; |
| 989 |
}, |
| 990 |
_renderTitle: function(dim, offsets){ |
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
var forceHtmlLabels = (g.renderer == "canvas") && this.htmlLabels, |
| 998 |
labelType = forceHtmlLabels || !has("ie") && !has("opera") && this.htmlLabels ? "html" : "gfx", |
| 999 |
tsize = g.normalizedLength(g.splitFontString(this.titleFont).size), |
| 1000 |
tBox = g._base._getTextBox(this.title,{ font: this.titleFont }); |
| 1001 |
|
| 1002 |
var titleAlign = this.titleAlign; |
| 1003 |
var isRtl = has("dojo-bidi") && this.isRightToLeft(); |
| 1004 |
var posX = dim.width/2; |
| 1005 |
if(titleAlign === "edge"){ |
| 1006 |
titleAlign = "left"; |
| 1007 |
if(isRtl){ |
| 1008 |
posX = dim.width - (offsets.r + tBox.w); |
| 1009 |
}else { |
| 1010 |
posX = offsets.l; |
| 1011 |
} |
| 1012 |
}else if(titleAlign != "middle"){ |
| 1013 |
if(isRtl){ |
| 1014 |
|
| 1015 |
titleAlign = titleAlign === "left" ? "right" : "left"; |
| 1016 |
} |
| 1017 |
if(titleAlign === "left"){ |
| 1018 |
posX = this.margins.l; |
| 1019 |
}else if(titleAlign === "right"){ |
| 1020 |
titleAlign = "left"; |
| 1021 |
posX = dim.width - (this.margins.l + tBox.w); |
| 1022 |
} |
| 1023 |
} |
| 1024 |
this.chartTitle = common.createText[labelType]( |
| 1025 |
this, |
| 1026 |
this.surface, |
| 1027 |
posX, |
| 1028 |
this.titlePos=="top" ? tsize + this.margins.t : dim.height - this.margins.b, |
| 1029 |
titleAlign, |
| 1030 |
this.title, |
| 1031 |
this.titleFont, |
| 1032 |
this.titleFontColor |
| 1033 |
); |
| 1034 |
}, |
| 1035 |
_renderChartBackground: function(dim, offsets){ |
| 1036 |
var t = this.theme, rect; |
| 1037 |
|
| 1038 |
var fill = this.fill !== undefined ? this.fill : (t.chart && t.chart.fill); |
| 1039 |
var stroke = this.stroke !== undefined ? this.stroke : (t.chart && t.chart.stroke); |
| 1040 |
|
| 1041 |
|
| 1042 |
if(fill == "inherit"){ |
| 1043 |
|
| 1044 |
var node = this.node; |
| 1045 |
fill = new Color(domStyle.get(node, "backgroundColor")); |
| 1046 |
while(fill.a==0 && node!=document.documentElement){ |
| 1047 |
fill = new Color(domStyle.get(node, "backgroundColor")); |
| 1048 |
node = node.parentNode; |
| 1049 |
} |
| 1050 |
} |
| 1051 |
|
| 1052 |
if(fill){ |
| 1053 |
if(this._nativeClip){ |
| 1054 |
fill = Element.prototype._shapeFill(Element.prototype._plotFill(fill, dim), |
| 1055 |
{ x:0, y: 0, width: dim.width + 1, height: dim.height + 1 }); |
| 1056 |
this.surface.createRect({ width: dim.width + 1, height: dim.height + 1 }).setFill(fill); |
| 1057 |
}else{ |
| 1058 |
|
| 1059 |
fill = Element.prototype._plotFill(fill, dim, offsets); |
| 1060 |
if(offsets.l){ |
| 1061 |
rect = { |
| 1062 |
x: 0, |
| 1063 |
y: 0, |
| 1064 |
width: offsets.l, |
| 1065 |
height: dim.height + 1 |
| 1066 |
}; |
| 1067 |
this.surface.createRect(rect).setFill(Element.prototype._shapeFill(fill, rect)); |
| 1068 |
} |
| 1069 |
if(offsets.r){ |
| 1070 |
rect = { |
| 1071 |
x: dim.width - offsets.r, |
| 1072 |
y: 0, |
| 1073 |
width: offsets.r + 1, |
| 1074 |
height: dim.height + 2 |
| 1075 |
}; |
| 1076 |
this.surface.createRect(rect).setFill(Element.prototype._shapeFill(fill, rect)); |
| 1077 |
} |
| 1078 |
if(offsets.t){ |
| 1079 |
rect = { |
| 1080 |
x: 0, |
| 1081 |
y: 0, |
| 1082 |
width: dim.width + 1, |
| 1083 |
height: offsets.t |
| 1084 |
}; |
| 1085 |
this.surface.createRect(rect).setFill(Element.prototype._shapeFill(fill, rect)); |
| 1086 |
} |
| 1087 |
if(offsets.b){ |
| 1088 |
rect = { |
| 1089 |
x: 0, |
| 1090 |
y: dim.height - offsets.b, |
| 1091 |
width: dim.width + 1, |
| 1092 |
height: offsets.b + 2 |
| 1093 |
}; |
| 1094 |
this.surface.createRect(rect).setFill(Element.prototype._shapeFill(fill, rect)); |
| 1095 |
} |
| 1096 |
} |
| 1097 |
} |
| 1098 |
if(stroke){ |
| 1099 |
this.surface.createRect({ |
| 1100 |
width: dim.width - 1, |
| 1101 |
height: dim.height - 1 |
| 1102 |
}).setStroke(stroke); |
| 1103 |
} |
| 1104 |
}, |
| 1105 |
_renderPlotBackground: function(dim, offsets, w, h){ |
| 1106 |
var t = this.theme; |
| 1107 |
|
| 1108 |
|
| 1109 |
var fill = t.plotarea && t.plotarea.fill; |
| 1110 |
var stroke = t.plotarea && t.plotarea.stroke; |
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
var rect = { |
| 1115 |
x: offsets.l - 1, y: offsets.t - 1, |
| 1116 |
width: w + 2, |
| 1117 |
height: h + 2 |
| 1118 |
}; |
| 1119 |
if(fill){ |
| 1120 |
fill = Element.prototype._shapeFill(Element.prototype._plotFill(fill, dim, offsets), rect); |
| 1121 |
this.surface.createRect(rect).setFill(fill); |
| 1122 |
} |
| 1123 |
if(stroke){ |
| 1124 |
this.surface.createRect({ |
| 1125 |
x: offsets.l, y: offsets.t, |
| 1126 |
width: w + 1, |
| 1127 |
height: h + 1 |
| 1128 |
}).setStroke(stroke); |
| 1129 |
} |
| 1130 |
}, |
| 1131 |
delayedRender: function(){ |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
if(!this._delayedRenderHandle){ |
| 1139 |
this._delayedRenderHandle = setTimeout( |
| 1140 |
lang.hitch(this, function(){ |
| 1141 |
this.render(); |
| 1142 |
}), |
| 1143 |
this.delayInMs |
| 1144 |
); |
| 1145 |
} |
| 1146 |
|
| 1147 |
return this; |
| 1148 |
}, |
| 1149 |
connectToPlot: function(name, object, method){ |
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
return name in this.plots ? this.stack[this.plots[name]].connect(object, method) : null; |
| 1161 |
}, |
| 1162 |
fireEvent: function(seriesName, eventName, index){ |
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
if(seriesName in this.runs){ |
| 1174 |
var plotName = this.series[this.runs[seriesName]].plot; |
| 1175 |
if(plotName in this.plots){ |
| 1176 |
var plot = this.stack[this.plots[plotName]]; |
| 1177 |
if(plot){ |
| 1178 |
plot.fireEvent(seriesName, eventName, index); |
| 1179 |
} |
| 1180 |
} |
| 1181 |
} |
| 1182 |
return this; |
| 1183 |
}, |
| 1184 |
_makeClean: function(){ |
| 1185 |
|
| 1186 |
arr.forEach(this.axes, makeClean); |
| 1187 |
arr.forEach(this.stack, makeClean); |
| 1188 |
arr.forEach(this.series, makeClean); |
| 1189 |
this.dirty = false; |
| 1190 |
}, |
| 1191 |
_makeDirty: function(){ |
| 1192 |
|
| 1193 |
arr.forEach(this.axes, makeDirty); |
| 1194 |
arr.forEach(this.stack, makeDirty); |
| 1195 |
arr.forEach(this.series, makeDirty); |
| 1196 |
this.dirty = true; |
| 1197 |
}, |
| 1198 |
_invalidateDependentPlots: function(plotName, verticalAxis){ |
| 1199 |
if(plotName in this.plots){ |
| 1200 |
var plot = this.stack[this.plots[plotName]], axis, |
| 1201 |
axisName = verticalAxis ? "vAxis" : "hAxis"; |
| 1202 |
if(plot[axisName]){ |
| 1203 |
axis = this.axes[plot[axisName]]; |
| 1204 |
if(axis && axis.dependOnData()){ |
| 1205 |
axis.dirty = true; |
| 1206 |
|
| 1207 |
arr.forEach(this.stack, function(p){ |
| 1208 |
if(p[axisName] && p[axisName] == plot[axisName]){ |
| 1209 |
p.dirty = true; |
| 1210 |
} |
| 1211 |
}); |
| 1212 |
} |
| 1213 |
}else{ |
| 1214 |
plot.dirty = true; |
| 1215 |
} |
| 1216 |
} |
| 1217 |
}, |
| 1218 |
setDir : function(dir){ |
| 1219 |
return this; |
| 1220 |
}, |
| 1221 |
_resetLeftBottom: function(axis){ |
| 1222 |
}, |
| 1223 |
formatTruncatedLabel: function(element, label, labelType){ |
| 1224 |
} |
| 1225 |
}); |
| 1226 |
|
| 1227 |
function hSection(stats){ |
| 1228 |
return {min: stats.hmin, max: stats.hmax}; |
| 1229 |
} |
| 1230 |
|
| 1231 |
function vSection(stats){ |
| 1232 |
return {min: stats.vmin, max: stats.vmax}; |
| 1233 |
} |
| 1234 |
|
| 1235 |
function hReplace(stats, h){ |
| 1236 |
stats.hmin = h.min; |
| 1237 |
stats.hmax = h.max; |
| 1238 |
} |
| 1239 |
|
| 1240 |
function vReplace(stats, v){ |
| 1241 |
stats.vmin = v.min; |
| 1242 |
stats.vmax = v.max; |
| 1243 |
} |
| 1244 |
|
| 1245 |
function combineStats(target, source){ |
| 1246 |
if(target && source){ |
| 1247 |
target.min = Math.min(target.min, source.min); |
| 1248 |
target.max = Math.max(target.max, source.max); |
| 1249 |
} |
| 1250 |
return target || source; |
| 1251 |
} |
| 1252 |
|
| 1253 |
function calculateAxes(stack, plotArea){ |
| 1254 |
var plots = {}, axes = {}; |
| 1255 |
arr.forEach(stack, function(plot){ |
| 1256 |
var stats = plots[plot.name] = plot.getSeriesStats(); |
| 1257 |
if(plot.hAxis){ |
| 1258 |
axes[plot.hAxis] = combineStats(axes[plot.hAxis], hSection(stats)); |
| 1259 |
} |
| 1260 |
if(plot.vAxis){ |
| 1261 |
axes[plot.vAxis] = combineStats(axes[plot.vAxis], vSection(stats)); |
| 1262 |
} |
| 1263 |
}); |
| 1264 |
arr.forEach(stack, function(plot){ |
| 1265 |
var stats = plots[plot.name]; |
| 1266 |
if(plot.hAxis){ |
| 1267 |
hReplace(stats, axes[plot.hAxis]); |
| 1268 |
} |
| 1269 |
if(plot.vAxis){ |
| 1270 |
vReplace(stats, axes[plot.vAxis]); |
| 1271 |
} |
| 1272 |
plot.initializeScalers(plotArea, stats); |
| 1273 |
}); |
| 1274 |
} |
| 1275 |
|
| 1276 |
return has("dojo-bidi")? declare("dojox.charting.Chart", [Chart, BidiChart]) : Chart; |
| 1277 |
}); |