| 1 |
define(["dojox/main", "dojo/_base/declare", "dojo/_base/lang", "dojo/dom-style", "dojo/_base/array", "dojo/sniff", |
| 2 |
"dojo/dom","dojo/dom-construct", |
| 3 |
"dojox/gfx", "dojox/gfx/_gfxBidiSupport", "../axis2d/common", "dojox/string/BidiEngine", |
| 4 |
"dojox/lang/functional","dojo/dom-attr","./_bidiutils"], |
| 5 |
function(dojox, declare, lang, domStyle, arr, has, dom, domConstruct, g, gBidi, da, BidiEngine, df, domAttr,utils){ |
| 6 |
|
| 7 |
|
| 8 |
var bidiEngine = new BidiEngine(); |
| 9 |
var dc = lang.getObject("charting", true, dojox); |
| 10 |
function validateTextDir(textDir){ |
| 11 |
return /^(ltr|rtl|auto)$/.test(textDir) ? textDir : null; |
| 12 |
}; |
| 13 |
|
| 14 |
return declare(null, { |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
textDir:"", |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
dir: "", |
| 36 |
isMirrored: false, |
| 37 |
|
| 38 |
getTextDir: function(text){ |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
var textDir = this.textDir == "auto" ? bidiEngine.checkContextual(text) : this.textDir; |
| 51 |
|
| 52 |
if(!textDir){ |
| 53 |
textDir = domStyle.get(this.node, "direction"); |
| 54 |
} |
| 55 |
return textDir; |
| 56 |
}, |
| 57 |
|
| 58 |
postscript: function(node,args){ |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
var textDir = args ? (args["textDir"] ? validateTextDir(args["textDir"]) : "") : ""; |
| 68 |
|
| 69 |
textDir = textDir ? textDir : domStyle.get(this.node, "direction"); |
| 70 |
this.textDir = textDir; |
| 71 |
|
| 72 |
this.surface.textDir = textDir; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
this.htmlElementsRegistry = []; |
| 77 |
this.truncatedLabelsRegistry = []; |
| 78 |
|
| 79 |
var chartDir = "ltr"; |
| 80 |
if(domAttr.has(node, "direction")){ |
| 81 |
chartDir = domAttr.get(node, "direction"); |
| 82 |
} |
| 83 |
this.setDir(args ? (args.dir ? args.dir: chartDir) : chartDir); |
| 84 |
|
| 85 |
}, |
| 86 |
|
| 87 |
setTextDir: function(newTextDir, obj){ |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
if(newTextDir == this.textDir){ |
| 97 |
return this; |
| 98 |
} |
| 99 |
if(validateTextDir(newTextDir) != null){ |
| 100 |
this.textDir = newTextDir; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
this.surface.setTextDir(newTextDir); |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
if(this.truncatedLabelsRegistry && newTextDir == "auto"){ |
| 114 |
arr.forEach(this.truncatedLabelsRegistry, function(elem){ |
| 115 |
var tDir = this.getTextDir(elem["label"]); |
| 116 |
if(elem["element"].textDir != tDir){ |
| 117 |
elem["element"].setShape({textDir: tDir}); |
| 118 |
} |
| 119 |
}, this); |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
var axesKeyArr = df.keys(this.axes); |
| 126 |
if(axesKeyArr.length > 0){ |
| 127 |
|
| 128 |
arr.forEach(axesKeyArr, function(key, index, arr){ |
| 129 |
|
| 130 |
var axis = this.axes[key]; |
| 131 |
|
| 132 |
if(axis.htmlElements[0]){ |
| 133 |
axis.dirty = true; |
| 134 |
axis.render(this.dim, this.offsets); |
| 135 |
} |
| 136 |
},this); |
| 137 |
|
| 138 |
|
| 139 |
if(this.title){ |
| 140 |
this._renderTitle(this.dim, this.offsets); |
| 141 |
} |
| 142 |
}else{ |
| 143 |
|
| 144 |
arr.forEach(this.htmlElementsRegistry, function(elem, index, arr){ |
| 145 |
var tDir = newTextDir == "auto" ? this.getTextDir(elem[4]) : newTextDir; |
| 146 |
if(elem[0].children[0] && elem[0].children[0].dir != tDir){ |
| 147 |
domConstruct.destroy(elem[0].children[0]); |
| 148 |
elem[0].children[0] = da.createText["html"] |
| 149 |
(this, this.surface, elem[1], elem[2], elem[3], elem[4], elem[5], elem[6]).children[0]; |
| 150 |
} |
| 151 |
},this); |
| 152 |
} |
| 153 |
} |
| 154 |
return this; |
| 155 |
}, |
| 156 |
|
| 157 |
setDir : function(dir){ |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
if(dir == "rtl" || dir == "ltr"){ |
| 166 |
if(this.dir != dir){ |
| 167 |
this.isMirrored = true; |
| 168 |
this.dirty = true; |
| 169 |
} |
| 170 |
this.dir = dir; |
| 171 |
} |
| 172 |
return this; |
| 173 |
}, |
| 174 |
|
| 175 |
isRightToLeft: function(){ |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
return this.dir == "rtl"; |
| 182 |
}, |
| 183 |
|
| 184 |
applyMirroring: function(plot, dim, offsets){ |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
utils.reverseMatrix(plot, dim, offsets, this.dir == "rtl"); |
| 189 |
|
| 190 |
domStyle.set(this.node, "direction", "ltr"); |
| 191 |
return this; |
| 192 |
}, |
| 193 |
|
| 194 |
formatTruncatedLabel: function(element, label, labelType){ |
| 195 |
this.truncateBidi(element, label, labelType); |
| 196 |
}, |
| 197 |
|
| 198 |
truncateBidi: function(elem, label, labelType){ |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
if(labelType == "gfx"){ |
| 220 |
|
| 221 |
this.truncatedLabelsRegistry.push({element: elem, label: label}); |
| 222 |
if(this.textDir == "auto"){ |
| 223 |
elem.setShape({textDir: this.getTextDir(label)}); |
| 224 |
} |
| 225 |
} |
| 226 |
if(labelType == "html" && this.textDir == "auto"){ |
| 227 |
elem.children[0].dir = this.getTextDir(label); |
| 228 |
} |
| 229 |
}, |
| 230 |
|
| 231 |
render: function(){ |
| 232 |
this.inherited(arguments); |
| 233 |
this.isMirrored = false; |
| 234 |
return this; |
| 235 |
}, |
| 236 |
|
| 237 |
_resetLeftBottom: function(axis){ |
| 238 |
if(axis.vertical && this.isMirrored){ |
| 239 |
axis.opt.leftBottom = !axis.opt.leftBottom; |
| 240 |
} |
| 241 |
} |
| 242 |
}); |
| 243 |
}); |
| 244 |
|