| 1 |
define(["exports", "dojo/_base/lang", "../util/oo", "../stencil/Text"], |
| 2 |
function(exports, lang, oo, Text){ |
| 3 |
|
| 4 |
exports.Label = oo.declare( |
| 5 |
Text, |
| 6 |
function(options){ |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
this.master = options.stencil; |
| 11 |
this.labelPosition = options.labelPosition || "BR"; |
| 12 |
if(lang.isFunction(this.labelPosition)){ |
| 13 |
this.setLabel = this.setLabelCustom; |
| 14 |
} |
| 15 |
this.setLabel(options.text || ""); |
| 16 |
this.connect(this.master, "onTransform", this, "setLabel"); |
| 17 |
this.connect(this.master, "destroy", this, "destroy"); |
| 18 |
|
| 19 |
if(this.style.labelSameColor){ |
| 20 |
this.connect(this.master, "attr", this, "beforeAttr"); |
| 21 |
} |
| 22 |
},{ |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
_align:"start", |
| 31 |
drawingType:"label", |
| 32 |
|
| 33 |
setLabelCustom: function(text){ |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
var d = lang.hitch(this.master, this.labelPosition)(); |
| 38 |
this.setData({ |
| 39 |
x:d.x, |
| 40 |
y:d.y, |
| 41 |
width:d.w || this.style.text.minWidth, |
| 42 |
height:d.h || this._lineHeight |
| 43 |
}); |
| 44 |
|
| 45 |
|
| 46 |
if(text && !text.split){ text = this.getText(); } |
| 47 |
|
| 48 |
this.render(this.typesetter(text)); |
| 49 |
}, |
| 50 |
|
| 51 |
setLabel: function(text){ |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
var x, y, box = this.master.getBounds(); |
| 58 |
|
| 59 |
if(/B/.test(this.labelPosition)){ |
| 60 |
y = box.y2 - this._lineHeight; |
| 61 |
}else{ |
| 62 |
y = box.y1; |
| 63 |
} |
| 64 |
|
| 65 |
if(/R/.test(this.labelPosition)){ |
| 66 |
x = box.x2; |
| 67 |
}else{ |
| 68 |
y = box.y1; |
| 69 |
this._align = "end"; |
| 70 |
} |
| 71 |
|
| 72 |
if(!this.labelWidth || (text && text.split && text != this.getText())){ |
| 73 |
this.setData({ |
| 74 |
x:x, |
| 75 |
y:y, |
| 76 |
height:this._lineHeight, |
| 77 |
width:this.style.text.minWidth |
| 78 |
}); |
| 79 |
|
| 80 |
this.labelWidth = this.style.text.minWidth; |
| 81 |
this.render(this.typesetter(text)); |
| 82 |
|
| 83 |
}else{ |
| 84 |
|
| 85 |
this.setData({ |
| 86 |
x:x, |
| 87 |
y:y, |
| 88 |
height:this.data.height, |
| 89 |
width:this.data.width |
| 90 |
}); |
| 91 |
|
| 92 |
this.render(); |
| 93 |
} |
| 94 |
|
| 95 |
}, |
| 96 |
beforeAttr: function(key, value){ |
| 97 |
if(value!==undefined){ |
| 98 |
|
| 99 |
var k = key; key = {}; key[k] = value; |
| 100 |
} |
| 101 |
delete key.x; |
| 102 |
delete key.y; |
| 103 |
delete key.width; |
| 104 |
delete key.height; |
| 105 |
this.attr(key); |
| 106 |
|
| 107 |
!this.created && this.render(); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
); |
| 112 |
}); |