| 1 |
define(["dojo", "dojo/fx/easing", "../util/oo", "../annotations/BoxShadow", |
| 2 |
"../annotations/Angle", "../annotations/Label", "../defaults"], |
| 3 |
function(dojo, easing, oo, BoxShadow, Angle, Label, defaults){ |
| 4 |
|
| 5 |
|
| 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 |
|
| 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 |
var Base = oo.declare( |
| 143 |
function(options){ |
| 144 |
|
| 145 |
|
| 146 |
dojo.mixin(this, options); |
| 147 |
this.style = options.style || defaults.copy(); |
| 148 |
if(options.stencil){ |
| 149 |
this.stencil = options.stencil; |
| 150 |
this.util = options.stencil.util; |
| 151 |
this.mouse = options.stencil.mouse; |
| 152 |
this.container = options.stencil.container; |
| 153 |
this.style = options.stencil.style; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
var lineTypes = /Line|Vector|Axes|Arrow/; |
| 159 |
var textTypes = /Text/; |
| 160 |
|
| 161 |
this.shortType = this.util.abbr(this.type); |
| 162 |
this.isText = textTypes.test(this.type); |
| 163 |
this.isLine = lineTypes.test(this.type); |
| 164 |
|
| 165 |
this.renderHit = this.style.renderHitLayer; |
| 166 |
if(!this.renderHit && this.style.renderHitLines && this.isLine){ |
| 167 |
this.renderHit = true; |
| 168 |
} |
| 169 |
if(!this.renderHit && this.style.useSelectedStyle){ |
| 170 |
this.useSelectedStyle = true; |
| 171 |
this.selCopy = dojo.clone(this.style.selected); |
| 172 |
for(var nm in this.style.norm){ |
| 173 |
if(this.style.selected[nm]===undefined){ |
| 174 |
this.style.selected[nm] = this.style.norm[nm]; |
| 175 |
} |
| 176 |
} |
| 177 |
this.textSelected = dojo.clone(this.style.text); |
| 178 |
this.textSelected.color = this.style.selected.fill; |
| 179 |
|
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
this.angleSnap = this.style.angleSnap || 1; |
| 184 |
|
| 185 |
this.marginZero = options.marginZero || this.style.anchors.marginZero; |
| 186 |
this.id = options.id || this.util.uid(this.type); |
| 187 |
this._cons = []; |
| 188 |
|
| 189 |
if(!this.annotation && !this.subShape){ |
| 190 |
this.util.attr(this.container, "id", this.id); |
| 191 |
} |
| 192 |
|
| 193 |
this.connect(this, "onBeforeRender", "preventNegativePos"); |
| 194 |
|
| 195 |
this._offX = this.mouse.origin.x; |
| 196 |
this._offY = this.mouse.origin.y; |
| 197 |
|
| 198 |
if(this.isText){ |
| 199 |
this.align = options.align || this.align; |
| 200 |
this.valign = options.valign || this.valign; |
| 201 |
if(options.data && options.data.makeFit){ |
| 202 |
var textObj = this.makeFit(options.data.text, options.data.width); |
| 203 |
this.textSize = this.style.text.size = textObj.size; |
| 204 |
this._lineHeight = textObj.box.h; |
| 205 |
}else{ |
| 206 |
this.textSize = parseInt(this.style.text.size, 10); |
| 207 |
this._lineHeight = this.textSize * 1.4; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
this.deleteEmptyCreate = options.deleteEmptyCreate!==undefined ? options.deleteEmptyCreate : this.style.text.deleteEmptyCreate; |
| 216 |
this.deleteEmptyModify = options.deleteEmptyModify!==undefined ? options.deleteEmptyModify : this.style.text.deleteEmptyModify; |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
this.attr(options.data); |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
if(this.noBaseRender){ |
| 228 |
|
| 229 |
return; |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
if(options.points){ |
| 234 |
|
| 235 |
if(options.data && options.data.closePath===false){ |
| 236 |
this.closePath = false; |
| 237 |
} |
| 238 |
this.setPoints(options.points); |
| 239 |
this.connect(this, "render", this, "onRender", true); |
| 240 |
this.baseRender && this.enabled && this.render(); |
| 241 |
options.label && this.setLabel(options.label); |
| 242 |
options.shadow && this.addShadow(options.shadow); |
| 243 |
|
| 244 |
}else if(options.data){ |
| 245 |
|
| 246 |
options.data.width = options.data.width ? options.data.width : this.style.text.minWidth; |
| 247 |
options.data.height = options.data.height ? options.data.height : this._lineHeight; |
| 248 |
this.setData(options.data); |
| 249 |
this.connect(this, "render", this, "onRender", true); |
| 250 |
this.baseRender && this.enabled && this.render(options.data.text); |
| 251 |
this.baseRender && options.label && this.setLabel(options.label); |
| 252 |
this.baseRender && options.shadow && this.addShadow(options.shadow); |
| 253 |
|
| 254 |
}else if(this.draws){ |
| 255 |
|
| 256 |
this.points = []; |
| 257 |
this.data = {}; |
| 258 |
this.connectMouse(); |
| 259 |
this._postRenderCon = dojo.connect(this, "render", this, "_onPostRender"); |
| 260 |
} |
| 261 |
if(this.showAngle){ |
| 262 |
this.angleLabel = new Angle({stencil:this}); |
| 263 |
} |
| 264 |
|
| 265 |
if(!this.enabled){ |
| 266 |
this.disable(); |
| 267 |
this.moveToBack(); |
| 268 |
|
| 269 |
this.render(options.data.text); |
| 270 |
} |
| 271 |
|
| 272 |
}, |
| 273 |
{ |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
type:"dojox.drawing.stencil", |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
minimumSize:10, |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
enabled:true, |
| 294 |
|
| 295 |
|
| 296 |
drawingType:"stencil", |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
setData: function(data){ |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
this.data = data; |
| 306 |
this.points = this.dataToPoints(); |
| 307 |
}, |
| 308 |
|
| 309 |
setPoints: function(points){ |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
this.points = points; |
| 315 |
|
| 316 |
if(this.pointsToData){ |
| 317 |
this.data = this.pointsToData(); |
| 318 |
} |
| 319 |
}, |
| 320 |
|
| 321 |
onDelete: function( stencil){ |
| 322 |
|
| 323 |
|
| 324 |
console.info("onDelete", this.id); |
| 325 |
}, |
| 326 |
|
| 327 |
onBeforeRender: function( stencil){ |
| 328 |
|
| 329 |
|
| 330 |
}, |
| 331 |
|
| 332 |
onModify: function(stencil){ |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
}, |
| 338 |
|
| 339 |
onChangeData: function( stencil){ |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
}, |
| 344 |
|
| 345 |
onChangeText: function(value){ |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
}, |
| 350 |
|
| 351 |
onRender: function( stencil){ |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
this._postRenderCon = dojo.connect(this, "render", this, "_onPostRender"); |
| 368 |
this.created = true; |
| 369 |
this.disconnectMouse(); |
| 370 |
|
| 371 |
|
| 372 |
if(this.shape){ |
| 373 |
this.shape.superClass = this; |
| 374 |
}else{ |
| 375 |
this.container.superClass = this; |
| 376 |
} |
| 377 |
this._setNodeAtts(this); |
| 378 |
|
| 379 |
}, |
| 380 |
|
| 381 |
onChangeStyle: function(stencil){ |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
this._isBeingModified = true; |
| 386 |
if(!this.enabled){ |
| 387 |
this.style.current = this.style.disabled; |
| 388 |
this.style.currentText = this.style.textDisabled; |
| 389 |
this.style.currentHit = this.style.hitNorm; |
| 390 |
|
| 391 |
}else{ |
| 392 |
this.style.current = this.style.norm; |
| 393 |
this.style.currentHit = this.style.hitNorm; |
| 394 |
this.style.currentText = this.style.text; |
| 395 |
} |
| 396 |
|
| 397 |
if(this.selected){ |
| 398 |
if(this.useSelectedStyle){ |
| 399 |
this.style.current = this.style.selected; |
| 400 |
this.style.currentText = this.textSelected; |
| 401 |
} |
| 402 |
this.style.currentHit = this.style.hitSelected; |
| 403 |
|
| 404 |
}else if(this.highlighted){ |
| 405 |
|
| 406 |
this.style.currentHit = this.style.hitHighlighted; |
| 407 |
|
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
this.render(); |
| 413 |
}, |
| 414 |
|
| 415 |
animate: function(options, create){ |
| 416 |
console.warn("ANIMATE..........................") |
| 417 |
var d = options.d || options.duration || 1000; |
| 418 |
var ms = options.ms || 20; |
| 419 |
var ease = options.ease || easing.linear; |
| 420 |
var steps = options.steps; |
| 421 |
var ts = new Date().getTime(); |
| 422 |
var w = 100; |
| 423 |
var cnt = 0; |
| 424 |
var isArray = true; |
| 425 |
var sp, ep; |
| 426 |
|
| 427 |
if(dojo.isArray(options.start)){ |
| 428 |
sp = options.start; |
| 429 |
ep = options.end; |
| 430 |
|
| 431 |
}else if(dojo.isObject(options.start)){ |
| 432 |
sp = options.start; |
| 433 |
ep = options.end; |
| 434 |
isArray = false; |
| 435 |
}else{ |
| 436 |
|
| 437 |
console.warn("No data provided to animate") |
| 438 |
} |
| 439 |
|
| 440 |
var v = setInterval(dojo.hitch(this, function(){ |
| 441 |
var t = new Date().getTime() - ts; |
| 442 |
var p = ease(1-t/d); |
| 443 |
if(t > d || cnt++ > 100){ |
| 444 |
clearInterval(v); |
| 445 |
return; |
| 446 |
} |
| 447 |
|
| 448 |
if(isArray){ |
| 449 |
var pnts = []; |
| 450 |
dojo.forEach(sp, function(pt, i){ |
| 451 |
|
| 452 |
var o = { |
| 453 |
x: (ep[i].x-sp[i].x)*p + sp[i].x, |
| 454 |
y: (ep[i].y-sp[i].y)*p + sp[i].y |
| 455 |
}; |
| 456 |
pnts.push(o); |
| 457 |
}); |
| 458 |
this.setPoints(pnts); |
| 459 |
this.render(); |
| 460 |
|
| 461 |
}else{ |
| 462 |
|
| 463 |
var o = {}; |
| 464 |
for(var nm in sp){ |
| 465 |
o[nm] = (ep[nm] - sp[nm]) * p + sp[nm]; |
| 466 |
} |
| 467 |
|
| 468 |
this.attr(o); |
| 469 |
|
| 470 |
} |
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
}), ms); |
| 479 |
}, |
| 480 |
|
| 481 |
attr: function( key, value){ |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
var n = this.enabled?this.style.norm:this.style.disabled; |
| 496 |
var t = this.enabled?this.style.text:this.style.textDisabled; |
| 497 |
var ts = this.textSelected || {}, |
| 498 |
o, |
| 499 |
nm, |
| 500 |
width, |
| 501 |
styleWas = dojo.toJson(n), |
| 502 |
textWas = dojo.toJson(t); |
| 503 |
|
| 504 |
var coords = { |
| 505 |
x:true, |
| 506 |
y:true, |
| 507 |
r:true, |
| 508 |
height:true, |
| 509 |
width:true, |
| 510 |
radius:true, |
| 511 |
angle:true |
| 512 |
}; |
| 513 |
var propChange = false; |
| 514 |
if(typeof(key)!="object"){ |
| 515 |
o = {}; |
| 516 |
o[key] = value; |
| 517 |
}else{ |
| 518 |
|
| 519 |
o = dojo.clone(key); |
| 520 |
} |
| 521 |
|
| 522 |
if(o.width){ |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
width = o.width; |
| 527 |
delete o.width; |
| 528 |
} |
| 529 |
|
| 530 |
for(nm in o){ |
| 531 |
if(nm in n){ n[nm] = o[nm]; } |
| 532 |
if(nm in t){ t[nm] = o[nm]; } |
| 533 |
if(nm in ts){ ts[nm] = o[nm]; } |
| 534 |
|
| 535 |
if(nm in coords){ |
| 536 |
coords[nm] = o[nm]; |
| 537 |
propChange = true; |
| 538 |
if(nm == "radius" && o.angle===undefined){ |
| 539 |
o.angle = coords.angle = this.getAngle(); |
| 540 |
}else if(nm == "angle" && o.radius===undefined){ |
| 541 |
o.radius = coords.radius = this.getRadius(); |
| 542 |
} |
| 543 |
|
| 544 |
} |
| 545 |
if(nm == "text"){ |
| 546 |
this.setText(o.text); |
| 547 |
} |
| 548 |
if(nm == "label"){ |
| 549 |
this.setLabel(o.label); |
| 550 |
} |
| 551 |
} |
| 552 |
if(o.borderWidth!==undefined){ |
| 553 |
n.width = o.borderWidth; |
| 554 |
} |
| 555 |
|
| 556 |
if(this.useSelectedStyle){ |
| 557 |
|
| 558 |
|
| 559 |
for(nm in this.style.norm){ |
| 560 |
if(this.selCopy[nm]===undefined){ |
| 561 |
this.style.selected[nm] = this.style.norm[nm]; |
| 562 |
} |
| 563 |
} |
| 564 |
this.textSelected.color = this.style.selected.color; |
| 565 |
|
| 566 |
} |
| 567 |
|
| 568 |
if(!this.created){ |
| 569 |
return; |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
if(o.x!==undefined || o.y!==undefined){ |
| 574 |
var box = this.getBounds(true); |
| 575 |
var mx = { dx:0, dy:0 }; |
| 576 |
for(nm in o){ |
| 577 |
if(nm=="x" || nm =="y" || nm =="r"){ |
| 578 |
mx["d"+nm] = o[nm] - box[nm]; |
| 579 |
} |
| 580 |
} |
| 581 |
this.transformPoints(mx); |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
var p = this.points; |
| 586 |
if(o.angle!==undefined){ |
| 587 |
this.dataToPoints({ |
| 588 |
x:this.data.x1, |
| 589 |
y:this.data.y1, |
| 590 |
angle:o.angle, |
| 591 |
radius:o.radius |
| 592 |
}); |
| 593 |
|
| 594 |
} else if(width!==undefined){ |
| 595 |
p[1].x = p[2].x = p[0].x + width; |
| 596 |
this.pointsToData(p); |
| 597 |
} |
| 598 |
|
| 599 |
if(o.height!==undefined && o.angle===undefined){ |
| 600 |
console.log("Doing P2D-2"); |
| 601 |
p[2].y = p[3].y = p[0].y + o.height; |
| 602 |
this.pointsToData(p); |
| 603 |
} |
| 604 |
|
| 605 |
if(o.r!==undefined){ |
| 606 |
this.data.r = Math.max(0, o.r); |
| 607 |
} |
| 608 |
|
| 609 |
|
| 610 |
if(propChange || textWas!=dojo.toJson(t) || styleWas != dojo.toJson(n)){ |
| 611 |
|
| 612 |
|
| 613 |
this.onChangeStyle(this); |
| 614 |
} |
| 615 |
o.width = width; |
| 616 |
|
| 617 |
if(o.cosphi!=undefined){ |
| 618 |
!this.data? this.data = {cosphi:o.cosphi} : this.data.cosphi = o.cosphi; |
| 619 |
this.style.zAxis = o.cosphi!=0 ? true : false; |
| 620 |
} |
| 621 |
}, |
| 622 |
|
| 623 |
exporter: function(){ |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
var type = this.type.substring(this.type.lastIndexOf(".")+1).charAt(0).toLowerCase() |
| 628 |
+ this.type.substring(this.type.lastIndexOf(".")+2); |
| 629 |
var o = dojo.clone(this.style.norm); |
| 630 |
o.borderWidth = o.width; |
| 631 |
delete o.width; |
| 632 |
if(type=="path"){ |
| 633 |
o.points = this.points; |
| 634 |
}else{ |
| 635 |
o = dojo.mixin(o, this.data); |
| 636 |
} |
| 637 |
o.type = type; |
| 638 |
if(this.isText){ |
| 639 |
o.text = this.getText(); |
| 640 |
o = dojo.mixin(o, this.style.text); |
| 641 |
delete o.minWidth; |
| 642 |
delete o.deleteEmptyCreate; |
| 643 |
delete o.deleteEmptyModify; |
| 644 |
} |
| 645 |
var lbl = this.getLabel(); |
| 646 |
if(lbl){ |
| 647 |
o.label = lbl; |
| 648 |
} |
| 649 |
return o; |
| 650 |
}, |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
disable: function(){ |
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
this.enabled = false; |
| 662 |
this.renderHit = false; |
| 663 |
this.onChangeStyle(this); |
| 664 |
}, |
| 665 |
|
| 666 |
enable: function(){ |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
this.enabled = true; |
| 672 |
this.renderHit = true; |
| 673 |
this.onChangeStyle(this); |
| 674 |
}, |
| 675 |
|
| 676 |
select: function(){ |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
this.selected = true; |
| 685 |
this.onChangeStyle(this); |
| 686 |
}, |
| 687 |
|
| 688 |
deselect: function(useDelay){ |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
if(useDelay){ |
| 702 |
setTimeout(dojo.hitch(this, function(){ |
| 703 |
this.selected = false; |
| 704 |
this.onChangeStyle(this); |
| 705 |
}),200); |
| 706 |
}else{ |
| 707 |
this.selected = false; |
| 708 |
this.onChangeStyle(this); |
| 709 |
} |
| 710 |
}, |
| 711 |
_toggleSelected: function(){ |
| 712 |
if(!this.selected){ return; } |
| 713 |
this.deselect(); |
| 714 |
setTimeout(dojo.hitch(this, "select"), 0); |
| 715 |
}, |
| 716 |
|
| 717 |
highlight: function(){ |
| 718 |
|
| 719 |
|
| 720 |
this.highlighted = true; |
| 721 |
this.onChangeStyle(this); |
| 722 |
}, |
| 723 |
|
| 724 |
unhighlight: function(){ |
| 725 |
|
| 726 |
|
| 727 |
this.highlighted = false; |
| 728 |
this.onChangeStyle(this); |
| 729 |
}, |
| 730 |
|
| 731 |
moveToFront: function(){ |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
this.container && this.container.moveToFront(); |
| 736 |
}, |
| 737 |
|
| 738 |
moveToBack: function(){ |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
this.container && this.container.moveToBack(); |
| 743 |
}, |
| 744 |
|
| 745 |
onTransformBegin: function(anchor){ |
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
this._isBeingModified = true; |
| 751 |
}, |
| 752 |
|
| 753 |
onTransformEnd: function(anchor){ |
| 754 |
|
| 755 |
|
| 756 |
this._isBeingModified = false; |
| 757 |
this.onModify(this); |
| 758 |
}, |
| 759 |
|
| 760 |
onTransform: function(anchor){ |
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
if(!this._isBeingModified){ |
| 765 |
this.onTransformBegin(); |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
this.setPoints(this.points); |
| 770 |
this.render(); |
| 771 |
}, |
| 772 |
|
| 773 |
transformPoints: function(mx){ |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
if(!mx.dx && !mx.dy){ |
| 782 |
|
| 783 |
return; |
| 784 |
} |
| 785 |
var backup = dojo.clone(this.points), abort = false; |
| 786 |
dojo.forEach(this.points, function(o){ |
| 787 |
o.x += mx.dx; |
| 788 |
o.y += mx.dy; |
| 789 |
if(o.x<this.marginZero || o.y<this.marginZero){ |
| 790 |
abort = true; |
| 791 |
} |
| 792 |
}); |
| 793 |
if(abort){ |
| 794 |
this.points = backup; |
| 795 |
console.error("Attempt to set object '"+this.id+"' to less than zero."); |
| 796 |
return; |
| 797 |
} |
| 798 |
this.onTransform(); |
| 799 |
this.onTransformEnd(); |
| 800 |
}, |
| 801 |
|
| 802 |
applyTransform: function(mx){ |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
this.transformPoints(mx); |
| 808 |
}, |
| 809 |
|
| 810 |
setTransform: function(mx){ |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
this.attr({ |
| 816 |
x:mx.dx, |
| 817 |
y:mx.dy |
| 818 |
}); |
| 819 |
}, |
| 820 |
|
| 821 |
getTransform: function(){ |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
return this.selected ? this.container.getParent().getTransform() : {dx:0, dy:0}; |
| 826 |
}, |
| 827 |
|
| 828 |
addShadow: function(args){ |
| 829 |
args = args===true ? {} : args; |
| 830 |
args.stencil = this; |
| 831 |
this.shadow = new BoxShadow(args); |
| 832 |
}, |
| 833 |
|
| 834 |
removeShadow: function(){ |
| 835 |
this.shadow.destroy(); |
| 836 |
}, |
| 837 |
|
| 838 |
setLabel: function(text){ |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
if(!this._label){ |
| 847 |
this._label = new Label.Label({ |
| 848 |
text:text, |
| 849 |
util:this.util, |
| 850 |
mouse:this.mouse, |
| 851 |
stencil:this, |
| 852 |
annotation:true, |
| 853 |
container:this.container, |
| 854 |
labelPosition:this.labelPosition |
| 855 |
}); |
| 856 |
}else if(text!=undefined){ |
| 857 |
this._label.setLabel(text); |
| 858 |
} |
| 859 |
}, |
| 860 |
|
| 861 |
getLabel: function(){ |
| 862 |
|
| 863 |
|
| 864 |
if(this._label){ |
| 865 |
return this._label.getText(); |
| 866 |
} |
| 867 |
return null; |
| 868 |
}, |
| 869 |
|
| 870 |
getAngle: function(){ |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
var d = this.pointsToData(); |
| 876 |
var obj = { |
| 877 |
start:{ |
| 878 |
x:d.x1, |
| 879 |
y:d.y1 |
| 880 |
}, |
| 881 |
x:d.x2, |
| 882 |
y:d.y2 |
| 883 |
}; |
| 884 |
var angle = this.util.angle(obj, this.angleSnap); |
| 885 |
|
| 886 |
angle<0 ? angle = 360 + angle : angle; |
| 887 |
return angle; |
| 888 |
}, |
| 889 |
getRadius: function(){ |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
var box = this.getBounds(true); |
| 896 |
var line = {start:{x:box.x1, y:box.y1}, x:box.x2, y:box.y2}; |
| 897 |
return this.util.length(line); |
| 898 |
}, |
| 899 |
getBounds: function(absolute){ |
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
var p = this.points, x1, y1, x2, y2; |
| 914 |
if(p.length==2){ |
| 915 |
if(absolute){ |
| 916 |
x1 = p[0].x; |
| 917 |
y1 = p[0].y; |
| 918 |
x2 = p[1].x; |
| 919 |
y2 = p[1].y |
| 920 |
}else{ |
| 921 |
x1 = p[0].x < p[1].x ? p[0].x : p[1].x; |
| 922 |
y1 = p[0].y < p[1].y ? p[0].y : p[1].y; |
| 923 |
x2 = p[0].x < p[1].x ? p[1].x : p[0].x; |
| 924 |
y2 = p[0].y < p[1].y ? p[1].y : p[0].y; |
| 925 |
} |
| 926 |
return { |
| 927 |
x1:x1, |
| 928 |
y1:y1, |
| 929 |
x2:x2, |
| 930 |
y2:y2, |
| 931 |
x:x1, |
| 932 |
y:y1, |
| 933 |
w:x2-x1, |
| 934 |
h:y2-y1 |
| 935 |
}; |
| 936 |
}else{ |
| 937 |
return { |
| 938 |
x1:p[0].x, |
| 939 |
y1:p[0].y, |
| 940 |
x2:p[2].x, |
| 941 |
y2:p[2].y, |
| 942 |
x:p[0].x, |
| 943 |
y:p[0].y, |
| 944 |
w:p[2].x - p[0].x, |
| 945 |
h:p[2].y - p[0].y |
| 946 |
}; |
| 947 |
} |
| 948 |
}, |
| 949 |
|
| 950 |
|
| 951 |
preventNegativePos: function(){ |
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
if(this._isBeingModified){ return; } |
| 958 |
|
| 959 |
if(!this.points || !this.points.length){ return; } |
| 960 |
|
| 961 |
if(this.type=="dojox.drawing.tools.custom.Axes"){ |
| 962 |
|
| 963 |
var minY = this.marginZero, minX = this.marginZero; |
| 964 |
dojo.forEach(this.points, function(p){ minY = Math.min(p.y, minY); }); |
| 965 |
dojo.forEach(this.points, function(p){ minX = Math.min(p.x, minX); }); |
| 966 |
|
| 967 |
if(minY<this.marginZero){ |
| 968 |
dojo.forEach(this.points, function(p, i){ |
| 969 |
p.y = p.y + (this.marginZero-minY) |
| 970 |
}, this); |
| 971 |
} |
| 972 |
if(minX<this.marginZero){ |
| 973 |
dojo.forEach(this.points, function(p){ |
| 974 |
p.x += (this.marginZero-minX) |
| 975 |
}, this); |
| 976 |
} |
| 977 |
|
| 978 |
}else{ |
| 979 |
|
| 980 |
dojo.forEach(this.points, function(p){ |
| 981 |
p.x = p.x < 0 ? this.marginZero : p.x; |
| 982 |
p.y = p.y < 0 ? this.marginZero : p.y; |
| 983 |
}); |
| 984 |
} |
| 985 |
this.setPoints(this.points); |
| 986 |
}, |
| 987 |
|
| 988 |
_onPostRender: function(data){ |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
if(this._isBeingModified){ |
| 999 |
this.onModify(this); |
| 1000 |
this._isBeingModified = false; |
| 1001 |
}else if(!this.created){ |
| 1002 |
|
| 1003 |
|
| 1004 |
} |
| 1005 |
|
| 1006 |
if(!this.editMode && !this.selected && this._prevData && dojo.toJson(this._prevData) != dojo.toJson(this.data)){ |
| 1007 |
|
| 1008 |
this.onChangeData(this); |
| 1009 |
this._prevData = dojo.clone(this.data); |
| 1010 |
|
| 1011 |
}else if(!this._prevData && (!this.isText || this.getText())){ |
| 1012 |
|
| 1013 |
this._prevData = dojo.clone(this.data); |
| 1014 |
|
| 1015 |
} |
| 1016 |
|
| 1017 |
}, |
| 1018 |
|
| 1019 |
_setNodeAtts: function(shape){ |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
var att = this.enabled && (!this.annotation || this.drawingType=="label") ? this.drawingType : ""; |
| 1031 |
this.util.attr(shape, "drawingType", att); |
| 1032 |
}, |
| 1033 |
|
| 1034 |
|
| 1035 |
destroy: function(){ |
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
if(this.destroyed){ return; } |
| 1045 |
if(this.data || this.points && this.points.length){ |
| 1046 |
this.onDelete(this); |
| 1047 |
} |
| 1048 |
|
| 1049 |
this.disconnectMouse(); |
| 1050 |
this.disconnect(this._cons); |
| 1051 |
dojo.disconnect(this._postRenderCon); |
| 1052 |
this.remove(this.shape, this.hit); |
| 1053 |
this.destroyed = true; |
| 1054 |
}, |
| 1055 |
|
| 1056 |
remove: function(){ |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
var a = arguments; |
| 1065 |
if(!a.length){ |
| 1066 |
if(!this.shape){ return; } |
| 1067 |
a = [this.shape]; |
| 1068 |
} |
| 1069 |
for(var i=0;i<a.length;i++){ |
| 1070 |
if(a[i]){ |
| 1071 |
a[i].removeShape(); |
| 1072 |
} |
| 1073 |
} |
| 1074 |
}, |
| 1075 |
|
| 1076 |
connectMult: function(){ |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
if(arguments.length>1){ |
| 1083 |
|
| 1084 |
this._cons.push(this.connect.apply(this, arguments)); |
| 1085 |
}else if(dojo.isArray(arguments[0][0])){ |
| 1086 |
|
| 1087 |
dojo.forEach(arguments[0], function(ar){ |
| 1088 |
this._cons.push(this.connect.apply(this, ar)); |
| 1089 |
}, this); |
| 1090 |
}else{ |
| 1091 |
|
| 1092 |
this._cons.push(this.connect.apply(this, arguments[0])); |
| 1093 |
} |
| 1094 |
|
| 1095 |
}, |
| 1096 |
|
| 1097 |
|
| 1098 |
connect: function(o, e, s, m, once){ |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
var c; |
| 1109 |
if(typeof(o)!="object"){ |
| 1110 |
if(s){ |
| 1111 |
|
| 1112 |
m = s; s = e; e=o; o = this; |
| 1113 |
}else{ |
| 1114 |
|
| 1115 |
m = e; e = o; o = s = this; |
| 1116 |
} |
| 1117 |
}else if(!m){ |
| 1118 |
|
| 1119 |
m = s; s = this; |
| 1120 |
}else if(once){ |
| 1121 |
|
| 1122 |
c = dojo.connect(o, e, function(evt){ |
| 1123 |
dojo.hitch(s, m)(evt); |
| 1124 |
dojo.disconnect(c); |
| 1125 |
}); |
| 1126 |
this._cons.push(c); |
| 1127 |
return c; |
| 1128 |
}else{ |
| 1129 |
|
| 1130 |
} |
| 1131 |
c = dojo.connect(o, e, s, m); |
| 1132 |
this._cons.push(c); |
| 1133 |
return c; |
| 1134 |
}, |
| 1135 |
|
| 1136 |
disconnect: function(handles){ |
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
if(!handles){ return } |
| 1141 |
if(!dojo.isArray(handles)){ handles=[handles]; } |
| 1142 |
dojo.forEach(handles, dojo.disconnect, dojo); |
| 1143 |
}, |
| 1144 |
|
| 1145 |
connectMouse: function(){ |
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
this._mouseHandle = this.mouse.register(this); |
| 1150 |
}, |
| 1151 |
disconnectMouse: function(){ |
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
this.mouse.unregister(this._mouseHandle); |
| 1156 |
}, |
| 1157 |
|
| 1158 |
|
| 1159 |
render: function(){ |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
}, |
| 1164 |
|
| 1165 |
dataToPoints: function(data){ |
| 1166 |
|
| 1167 |
|
| 1168 |
}, |
| 1169 |
pointsToData: function(points){ |
| 1170 |
|
| 1171 |
|
| 1172 |
}, |
| 1173 |
onDown: function(obj){ |
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
this._downOnCanvas = true; |
| 1182 |
dojo.disconnect(this._postRenderCon); |
| 1183 |
this._postRenderCon = null; |
| 1184 |
}, |
| 1185 |
onMove: function(obj){ |
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
}, |
| 1191 |
onDrag: function(obj){ |
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
}, |
| 1196 |
onUp: function(obj){ |
| 1197 |
|
| 1198 |
|
| 1199 |
} |
| 1200 |
} |
| 1201 |
); |
| 1202 |
dojo.setObject("dojox.drawing.stencil._Base", Base); |
| 1203 |
return Base; |
| 1204 |
}); |