| 1 |
define(["dojo/_base/lang", "dojo/_base/window", "dojo/dom-geometry", "dojox/gfx", "dojo/has"], |
| 2 |
function(lang, win, domGeom, g, has){ |
| 3 |
|
| 4 |
var common = lang.getObject("dojox.charting.axis2d.common", true); |
| 5 |
|
| 6 |
var clearNode = function(s){ |
| 7 |
s.marginLeft = "0px"; |
| 8 |
s.marginTop = "0px"; |
| 9 |
s.marginRight = "0px"; |
| 10 |
s.marginBottom = "0px"; |
| 11 |
s.paddingLeft = "0px"; |
| 12 |
s.paddingTop = "0px"; |
| 13 |
s.paddingRight = "0px"; |
| 14 |
s.paddingBottom = "0px"; |
| 15 |
s.borderLeftWidth = "0px"; |
| 16 |
s.borderTopWidth = "0px"; |
| 17 |
s.borderRightWidth = "0px"; |
| 18 |
s.borderBottomWidth = "0px"; |
| 19 |
}; |
| 20 |
|
| 21 |
var getBoxWidth = function(n){ |
| 22 |
|
| 23 |
if(n["getBoundingClientRect"]){ |
| 24 |
var bcr = n.getBoundingClientRect(); |
| 25 |
return bcr.width || (bcr.right - bcr.left); |
| 26 |
}else{ |
| 27 |
return domGeom.getMarginBox(n).w; |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
return lang.mixin(common, { |
| 32 |
|
| 33 |
|
| 34 |
createText: { |
| 35 |
gfx: function(chart, creator, x, y, align, text, font, fontColor){ |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
return creator.createText({ |
| 57 |
x: x, y: y, text: text, align: align |
| 58 |
}).setFont(font).setFill(fontColor); |
| 59 |
}, |
| 60 |
html: function(chart, creator, x, y, align, text, font, fontColor, labelWidth){ |
| 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 |
var p = win.doc.createElement("div"), s = p.style, boxWidth; |
| 86 |
|
| 87 |
if(chart.getTextDir){ |
| 88 |
p.dir = chart.getTextDir(text); |
| 89 |
} |
| 90 |
clearNode(s); |
| 91 |
s.font = font; |
| 92 |
p.innerHTML = String(text).replace(/\s/g, " "); |
| 93 |
s.color = fontColor; |
| 94 |
|
| 95 |
s.position = "absolute"; |
| 96 |
s.left = "-10000px"; |
| 97 |
win.body().appendChild(p); |
| 98 |
var size = g.normalizedLength(g.splitFontString(font).size); |
| 99 |
|
| 100 |
|
| 101 |
if(!labelWidth){ |
| 102 |
boxWidth = getBoxWidth(p); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
if(p.dir == "rtl"){ |
| 107 |
x += labelWidth ? labelWidth : boxWidth; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
win.body().removeChild(p); |
| 112 |
|
| 113 |
s.position = "relative"; |
| 114 |
if(labelWidth){ |
| 115 |
s.width = labelWidth + "px"; |
| 116 |
|
| 117 |
switch(align){ |
| 118 |
case "middle": |
| 119 |
s.textAlign = "center"; |
| 120 |
s.left = (x - labelWidth / 2) + "px"; |
| 121 |
break; |
| 122 |
case "end": |
| 123 |
s.textAlign = "right"; |
| 124 |
s.left = (x - labelWidth) + "px"; |
| 125 |
break; |
| 126 |
default: |
| 127 |
s.left = x + "px"; |
| 128 |
s.textAlign = "left"; |
| 129 |
break; |
| 130 |
} |
| 131 |
}else{ |
| 132 |
switch(align){ |
| 133 |
case "middle": |
| 134 |
s.left = Math.floor(x - boxWidth / 2) + "px"; |
| 135 |
|
| 136 |
break; |
| 137 |
case "end": |
| 138 |
s.left = Math.floor(x - boxWidth) + "px"; |
| 139 |
|
| 140 |
break; |
| 141 |
|
| 142 |
default: |
| 143 |
s.left = Math.floor(x) + "px"; |
| 144 |
break; |
| 145 |
} |
| 146 |
} |
| 147 |
s.top = Math.floor(y - size) + "px"; |
| 148 |
s.whiteSpace = "nowrap"; |
| 149 |
|
| 150 |
var wrap = win.doc.createElement("div"), w = wrap.style; |
| 151 |
clearNode(w); |
| 152 |
w.width = "0px"; |
| 153 |
w.height = "0px"; |
| 154 |
|
| 155 |
wrap.appendChild(p); |
| 156 |
chart.node.insertBefore(wrap, chart.node.firstChild); |
| 157 |
if(has("dojo-bidi")){ |
| 158 |
chart.htmlElementsRegistry.push([wrap, x, y, align, text, font, fontColor]); |
| 159 |
} |
| 160 |
return wrap; |
| 161 |
} |
| 162 |
} |
| 163 |
}); |
| 164 |
}); |