Debian Codegraph @

dojox/drawing/annotations/Label.js

raw symbols SCIP
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(/*Object*/options){
7 // options: Object
8 // One key value: the stencil that called this.
9
10 this.master = options.stencil;
11 this.labelPosition = options.labelPosition || "BR"; // TL, TR, BR, BL, or function
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 // summary:
24 // An annotation called internally to label an Stencil.
25 // description:
26 // Annotation is positioned with dojox.drawing.util.positioning.label
27 // That method should be overwritten for custom placement. Or,
28 // add a 'setLabelCustom' method to the Stencil and it will be used.
29
30 _align:"start",
31 drawingType:"label",
32
33 setLabelCustom: function(/* ? String */text){
34 // summary:
35 // Attaches to custom positioning within a Stencil
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 // is an event, not text, so keep the old label:
46 if(text && !text.split){ text = this.getText(); }
47
48 this.render(this.typesetter(text));
49 },
50
51 setLabel: function(/* String */text){
52 // summary:
53 // Sets the text of the label. Not called directly. Should
54 // be called within Stencil. See stencil._Base
55
56 // onTransform will pass an object here
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 // make it an object
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 // FIXME: this.created should already be set, shouldn't it?
107 !this.created && this.render();
108 }
109 }
110
111 );
112 });