1
2
3
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
//>>built
define("dojox/charting/axis2d/common", ["dojo/_base/lang", "dojo/_base/html", "dojo/_base/window", "dojo/dom-geometry", "dojox/gfx"],
function(lang, html, win, domGeom, g){
var common = lang.getObject("dojox.charting.axis2d.common", true);
var clearNode = function(s){
s.marginLeft = "0px";
s.marginTop = "0px";
s.marginRight = "0px";
s.marginBottom = "0px";
s.paddingLeft = "0px";
s.paddingTop = "0px";
s.paddingRight = "0px";
s.paddingBottom = "0px";
s.borderLeftWidth = "0px";
s.borderTopWidth = "0px";
s.borderRightWidth = "0px";
s.borderBottomWidth = "0px";
};
var getBoxWidth = function(n){
// marginBox is incredibly slow, so avoid it if we can
if(n["getBoundingClientRect"]){
var bcr = n.getBoundingClientRect();
return bcr.width || (bcr.right - bcr.left);
}else{
return domGeom.getMarginBox(n).w;
}
};
return lang.mixin(common, {
// summary:
// Common methods to be used by any axis. This is considered "static".
createText: {
gfx: function(chart, creator, x, y, align, text, font, fontColor){
// summary:
// Use dojox.gfx to create any text.
// chart: dojox.charting.Chart
// The chart to create the text into.
// creator: dojox.gfx.Surface
// The graphics surface to use for creating the text.
// x: Number
// Where to create the text along the x axis (CSS left).
// y: Number
// Where to create the text along the y axis (CSS top).
// align: String
// How to align the text. Can be "left", "right", "center".
// text: String
// The text to render.
// font: String
// The font definition, a la CSS "font".
// fontColor: String|dojo.Color
// The color of the resultant text.
// returns: dojox.gfx.Text
// The resultant GFX object.
return creator.createText({
x: x, y: y, text: text, align: align
}).setFont(font).setFill(fontColor); // dojox.gfx.Text
},
html: function(chart, creator, x, y, align, text, font, fontColor, labelWidth){
// summary:
// Use the HTML DOM to create any text.
// chart: dojox.charting.Chart
// The chart to create the text into.
// creator: dojox.gfx.Surface
// The graphics surface to use for creating the text.
// x: Number
// Where to create the text along the x axis (CSS left).
// y: Number
// Where to create the text along the y axis (CSS top).
// align: String
// How to align the text. Can be "left", "right", "center".
// text: String
// The text to render.
// font: String
// The font definition, a la CSS "font".
// fontColor: String|dojo.Color
// The color of the resultant text.
// labelWidth: Number?
// The maximum width of the resultant DOM node.
// returns: DOMNode
// The resultant DOMNode (a "div" element).
// setup the text node
var p = win.doc.createElement("div"), s = p.style, boxWidth;
// bidi support, if this function exists the module was loaded
if(chart.getTextDir){
p.dir = chart.getTextDir(text);
}
clearNode(s);
s.font = font;
p.innerHTML = String(text).replace(/\s/g, " ");
s.color = fontColor;
// measure the size
s.position = "absolute";
s.left = "-10000px";
win.body().appendChild(p);
var size = g.normalizedLength(g.splitFontString(font).size);
// do we need to calculate the label width?
if(!labelWidth){
boxWidth = getBoxWidth(p);
}
// when the textDir is rtl, but the UI ltr needs
// to recalculate the starting point
if(p.dir == "rtl"){
x += labelWidth ? labelWidth : boxWidth;
}
// new settings for the text node
win.body().removeChild(p);
s.position = "relative";
if(labelWidth){
s.width = labelWidth + "px";
// s.border = "1px dotted grey";
switch(align){
case "middle":
s.textAlign = "center";
s.left = (x - labelWidth / 2) + "px";
break;
case "end":
s.textAlign = "right";
s.left = (x - labelWidth) + "px";
break;
default:
s.left = x + "px";
s.textAlign = "left";
break;
}
}else{
switch(align){
case "middle":
s.left = Math.floor(x - boxWidth / 2) + "px";
// s.left = Math.floor(x - p.offsetWidth / 2) + "px";
break;
case "end":
s.left = Math.floor(x - boxWidth) + "px";
// s.left = Math.floor(x - p.offsetWidth) + "px";
break;
//case "start":
default:
s.left = Math.floor(x) + "px";
break;
}
}
s.top = Math.floor(y - size) + "px";
s.whiteSpace = "nowrap"; // hack for WebKit
// setup the wrapper node
var wrap = win.doc.createElement("div"), w = wrap.style;
clearNode(w);
w.width = "0px";
w.height = "0px";
// insert nodes
wrap.appendChild(p)
chart.node.insertBefore(wrap, chart.node.firstChild);
return wrap; // DOMNode
}
}
});
});
|