[483] | 1 | define(["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/Color", "dojo/_base/sniff", "dojo/_base/window", |
---|
| 2 | "dojo/_base/array","dojo/dom", "dojo/dom-construct","dojo/dom-geometry"], |
---|
| 3 | function(kernel, lang, Color, has, win, arr, dom, domConstruct, domGeom){ |
---|
| 4 | // module: |
---|
| 5 | // dojox/gfx |
---|
| 6 | // summary: |
---|
| 7 | // This module contains common core Graphics API used by different graphics renderers. |
---|
| 8 | |
---|
| 9 | var g = lang.getObject("dojox.gfx", true), |
---|
| 10 | b = g._base = {}; |
---|
| 11 | |
---|
| 12 | // candidates for dojox.style (work on VML and SVG nodes) |
---|
| 13 | g._hasClass = function(/*DomNode*/node, /*String*/classStr){ |
---|
| 14 | // summary: |
---|
| 15 | // Returns whether or not the specified classes are a portion of the |
---|
| 16 | // class list currently applied to the node. |
---|
| 17 | |
---|
| 18 | // return (new RegExp('(^|\\s+)'+classStr+'(\\s+|$)')).test(node.className) // Boolean |
---|
| 19 | var cls = node.getAttribute("className"); |
---|
| 20 | return cls && (" " + cls + " ").indexOf(" " + classStr + " ") >= 0; // Boolean |
---|
| 21 | }; |
---|
| 22 | g._addClass = function(/*DomNode*/node, /*String*/classStr){ |
---|
| 23 | // summary: |
---|
| 24 | // Adds the specified classes to the end of the class list on the |
---|
| 25 | // passed node. |
---|
| 26 | var cls = node.getAttribute("className") || ""; |
---|
| 27 | if(!cls || (" " + cls + " ").indexOf(" " + classStr + " ") < 0){ |
---|
| 28 | node.setAttribute("className", cls + (cls ? " " : "") + classStr); |
---|
| 29 | } |
---|
| 30 | }; |
---|
| 31 | g._removeClass = function(/*DomNode*/node, /*String*/classStr){ |
---|
| 32 | // summary: |
---|
| 33 | // Removes classes from node. |
---|
| 34 | var cls = node.getAttribute("className"); |
---|
| 35 | if(cls){ |
---|
| 36 | node.setAttribute( |
---|
| 37 | "className", |
---|
| 38 | cls.replace(new RegExp('(^|\\s+)' + classStr + '(\\s+|$)'), "$1$2") |
---|
| 39 | ); |
---|
| 40 | } |
---|
| 41 | }; |
---|
| 42 | |
---|
| 43 | // candidate for dojox.html.metrics (dynamic font resize handler is not implemented here) |
---|
| 44 | |
---|
| 45 | // derived from Morris John's emResized measurer |
---|
| 46 | b._getFontMeasurements = function(){ |
---|
| 47 | // summary: |
---|
| 48 | // Returns an object that has pixel equivilents of standard font |
---|
| 49 | // size values. |
---|
| 50 | var heights = { |
---|
| 51 | '1em': 0, '1ex': 0, '100%': 0, '12pt': 0, '16px': 0, 'xx-small': 0, |
---|
| 52 | 'x-small': 0, 'small': 0, 'medium': 0, 'large': 0, 'x-large': 0, |
---|
| 53 | 'xx-large': 0 |
---|
| 54 | }; |
---|
| 55 | var p; |
---|
| 56 | |
---|
| 57 | if(has("ie")){ |
---|
| 58 | // we do a font-size fix if and only if one isn't applied already. |
---|
| 59 | // NOTE: If someone set the fontSize on the HTML Element, this will kill it. |
---|
| 60 | win.doc.documentElement.style.fontSize="100%"; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | // set up the measuring node. |
---|
| 64 | var div = domConstruct.create("div", {style: { |
---|
| 65 | position: "absolute", |
---|
| 66 | left: "0", |
---|
| 67 | top: "-100px", |
---|
| 68 | width: "30px", |
---|
| 69 | height: "1000em", |
---|
| 70 | borderWidth: "0", |
---|
| 71 | margin: "0", |
---|
| 72 | padding: "0", |
---|
| 73 | outline: "none", |
---|
| 74 | lineHeight: "1", |
---|
| 75 | overflow: "hidden" |
---|
| 76 | }}, win.body()); |
---|
| 77 | |
---|
| 78 | // do the measurements. |
---|
| 79 | for(p in heights){ |
---|
| 80 | div.style.fontSize = p; |
---|
| 81 | heights[p] = Math.round(div.offsetHeight * 12/16) * 16/12 / 1000; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | win.body().removeChild(div); |
---|
| 85 | return heights; //object |
---|
| 86 | }; |
---|
| 87 | |
---|
| 88 | var fontMeasurements = null; |
---|
| 89 | |
---|
| 90 | b._getCachedFontMeasurements = function(recalculate){ |
---|
| 91 | if(recalculate || !fontMeasurements){ |
---|
| 92 | fontMeasurements = b._getFontMeasurements(); |
---|
| 93 | } |
---|
| 94 | return fontMeasurements; |
---|
| 95 | }; |
---|
| 96 | |
---|
| 97 | // candidate for dojox.html.metrics |
---|
| 98 | |
---|
| 99 | var measuringNode = null, empty = {}; |
---|
| 100 | b._getTextBox = function( /*String*/ text, |
---|
| 101 | /*Object*/ style, |
---|
| 102 | /*String?*/ className){ |
---|
| 103 | var m, s, al = arguments.length; |
---|
| 104 | var i, box; |
---|
| 105 | if(!measuringNode){ |
---|
| 106 | measuringNode = domConstruct.create("div", {style: { |
---|
| 107 | position: "absolute", |
---|
| 108 | top: "-10000px", |
---|
| 109 | left: "0", |
---|
| 110 | visibility: "hidden" |
---|
| 111 | }}, win.body()); |
---|
| 112 | } |
---|
| 113 | m = measuringNode; |
---|
| 114 | // reset styles |
---|
| 115 | m.className = ""; |
---|
| 116 | s = m.style; |
---|
| 117 | s.borderWidth = "0"; |
---|
| 118 | s.margin = "0"; |
---|
| 119 | s.padding = "0"; |
---|
| 120 | s.outline = "0"; |
---|
| 121 | // set new style |
---|
| 122 | if(al > 1 && style){ |
---|
| 123 | for(i in style){ |
---|
| 124 | if(i in empty){ continue; } |
---|
| 125 | s[i] = style[i]; |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | // set classes |
---|
| 129 | if(al > 2 && className){ |
---|
| 130 | m.className = className; |
---|
| 131 | } |
---|
| 132 | // take a measure |
---|
| 133 | m.innerHTML = text; |
---|
| 134 | |
---|
| 135 | if(m.getBoundingClientRect){ |
---|
| 136 | var bcr = m.getBoundingClientRect(); |
---|
| 137 | box = {l: bcr.left, t: bcr.top, w: bcr.width || (bcr.right - bcr.left), h: bcr.height || (bcr.bottom - bcr.top)}; |
---|
| 138 | }else{ |
---|
| 139 | box = domGeom.getMarginBox(m); |
---|
| 140 | } |
---|
| 141 | m.innerHTML = ""; |
---|
| 142 | return box; |
---|
| 143 | }; |
---|
| 144 | |
---|
| 145 | b._computeTextLocation = function(/*g.defaultTextShape*/textShape, /*Number*/width, /*Number*/height, /*Boolean*/fixHeight) { |
---|
| 146 | var loc = {}, align = textShape.align; |
---|
| 147 | switch (align) { |
---|
| 148 | case 'end': |
---|
| 149 | loc.x = textShape.x - width; |
---|
| 150 | break; |
---|
| 151 | case 'middle': |
---|
| 152 | loc.x = textShape.x - width / 2; |
---|
| 153 | break; |
---|
| 154 | default: |
---|
| 155 | loc.x = textShape.x; |
---|
| 156 | break; |
---|
| 157 | } |
---|
| 158 | var c = fixHeight ? 0.75 : 1; |
---|
| 159 | loc.y = textShape.y - height*c; // **rough** approximation of the ascent... |
---|
| 160 | return loc; |
---|
| 161 | }; |
---|
| 162 | b._computeTextBoundingBox = function(/*shape.Text*/s){ |
---|
| 163 | // summary: |
---|
| 164 | // Compute the bbox of the given shape.Text instance. Note that this method returns an |
---|
| 165 | // approximation of the bbox, and should be used when the underlying renderer cannot provide precise metrics. |
---|
| 166 | if(!g._base._isRendered(s)){ |
---|
| 167 | return {x:0, y:0, width:0, height:0}; |
---|
| 168 | } |
---|
| 169 | var loc, textShape = s.getShape(), |
---|
| 170 | font = s.getFont() || g.defaultFont, |
---|
| 171 | w = s.getTextWidth(), |
---|
| 172 | h = g.normalizedLength(font.size); |
---|
| 173 | loc = b._computeTextLocation(textShape, w, h, true); |
---|
| 174 | return { |
---|
| 175 | x: loc.x, |
---|
| 176 | y: loc.y, |
---|
| 177 | width: w, |
---|
| 178 | height: h |
---|
| 179 | }; |
---|
| 180 | }; |
---|
| 181 | b._isRendered = function(/*Shape*/s){ |
---|
| 182 | var p = s.parent; |
---|
| 183 | while(p && p.getParent){ |
---|
| 184 | p = p.parent; |
---|
| 185 | } |
---|
| 186 | return p !== null; |
---|
| 187 | }; |
---|
| 188 | |
---|
| 189 | // candidate for dojo.dom |
---|
| 190 | |
---|
| 191 | var uniqueId = 0; |
---|
| 192 | b._getUniqueId = function(){ |
---|
| 193 | // summary: |
---|
| 194 | // returns a unique string for use with any DOM element |
---|
| 195 | var id; |
---|
| 196 | do{ |
---|
| 197 | id = kernel._scopeName + "xUnique" + (++uniqueId); |
---|
| 198 | }while(dom.byId(id)); |
---|
| 199 | return id; |
---|
| 200 | }; |
---|
| 201 | |
---|
| 202 | // IE10 |
---|
| 203 | |
---|
| 204 | b._fixMsTouchAction = function(/*dojox/gfx/shape.Surface*/surface){ |
---|
| 205 | var r = surface.rawNode; |
---|
| 206 | if (typeof r.style.msTouchAction != 'undefined') |
---|
| 207 | r.style.msTouchAction = "none"; |
---|
| 208 | }; |
---|
| 209 | |
---|
| 210 | /*===== |
---|
| 211 | g.Stroke = { |
---|
| 212 | // summary: |
---|
| 213 | // A stroke defines stylistic properties that are used when drawing a path. |
---|
| 214 | |
---|
| 215 | // color: String |
---|
| 216 | // The color of the stroke, default value 'black'. |
---|
| 217 | color: "black", |
---|
| 218 | |
---|
| 219 | // style: String |
---|
| 220 | // The style of the stroke, one of 'solid', ... . Default value 'solid'. |
---|
| 221 | style: "solid", |
---|
| 222 | |
---|
| 223 | // width: Number |
---|
| 224 | // The width of a stroke, default value 1. |
---|
| 225 | width: 1, |
---|
| 226 | |
---|
| 227 | // cap: String |
---|
| 228 | // The endcap style of the path. One of 'butt', 'round', ... . Default value 'butt'. |
---|
| 229 | cap: "butt", |
---|
| 230 | |
---|
| 231 | // join: Number |
---|
| 232 | // The join style to use when combining path segments. Default value 4. |
---|
| 233 | join: 4 |
---|
| 234 | }; |
---|
| 235 | |
---|
| 236 | g.Fill = { |
---|
| 237 | // summary: |
---|
| 238 | // Defines how to fill a shape. Four types of fills can be used: solid, linear gradient, radial gradient and pattern. |
---|
| 239 | // See dojox/gfx.LinearGradient, dojox/gfx.RadialGradient and dojox/gfx.Pattern respectively for more information about the properties supported by each type. |
---|
| 240 | |
---|
| 241 | // type: String? |
---|
| 242 | // The type of fill. One of 'linear', 'radial', 'pattern' or undefined. If not specified, a solid fill is assumed. |
---|
| 243 | type:"", |
---|
| 244 | |
---|
| 245 | // color: String|dojo/Color? |
---|
| 246 | // The color of a solid fill type. |
---|
| 247 | color:null, |
---|
| 248 | |
---|
| 249 | }; |
---|
| 250 | |
---|
| 251 | g.LinearGradient = { |
---|
| 252 | // summary: |
---|
| 253 | // An object defining the default stylistic properties used for Linear Gradient fills. |
---|
| 254 | // Linear gradients are drawn along a virtual line, which results in appearance of a rotated pattern in a given direction/orientation. |
---|
| 255 | |
---|
| 256 | // type: String |
---|
| 257 | // Specifies this object is a Linear Gradient, value 'linear' |
---|
| 258 | type: "linear", |
---|
| 259 | |
---|
| 260 | // x1: Number |
---|
| 261 | // The X coordinate of the start of the virtual line along which the gradient is drawn, default value 0. |
---|
| 262 | x1: 0, |
---|
| 263 | |
---|
| 264 | // y1: Number |
---|
| 265 | // The Y coordinate of the start of the virtual line along which the gradient is drawn, default value 0. |
---|
| 266 | y1: 0, |
---|
| 267 | |
---|
| 268 | // x2: Number |
---|
| 269 | // The X coordinate of the end of the virtual line along which the gradient is drawn, default value 100. |
---|
| 270 | x2: 100, |
---|
| 271 | |
---|
| 272 | // y2: Number |
---|
| 273 | // The Y coordinate of the end of the virtual line along which the gradient is drawn, default value 100. |
---|
| 274 | y2: 100, |
---|
| 275 | |
---|
| 276 | // colors: Array |
---|
| 277 | // An array of colors at given offsets (from the start of the line). The start of the line is |
---|
| 278 | // defined at offest 0 with the end of the line at offset 1. |
---|
| 279 | // Default value, [{ offset: 0, color: 'black'},{offset: 1, color: 'white'}], is a gradient from black to white. |
---|
| 280 | colors: [] |
---|
| 281 | }; |
---|
| 282 | |
---|
| 283 | g.RadialGradient = { |
---|
| 284 | // summary: |
---|
| 285 | // Specifies the properties for RadialGradients using in fills patterns. |
---|
| 286 | |
---|
| 287 | // type: String |
---|
| 288 | // Specifies this is a RadialGradient, value 'radial' |
---|
| 289 | type: "radial", |
---|
| 290 | |
---|
| 291 | // cx: Number |
---|
| 292 | // The X coordinate of the center of the radial gradient, default value 0. |
---|
| 293 | cx: 0, |
---|
| 294 | |
---|
| 295 | // cy: Number |
---|
| 296 | // The Y coordinate of the center of the radial gradient, default value 0. |
---|
| 297 | cy: 0, |
---|
| 298 | |
---|
| 299 | // r: Number |
---|
| 300 | // The radius to the end of the radial gradient, default value 100. |
---|
| 301 | r: 100, |
---|
| 302 | |
---|
| 303 | // colors: Array |
---|
| 304 | // An array of colors at given offsets (from the center of the radial gradient). |
---|
| 305 | // The center is defined at offest 0 with the outer edge of the gradient at offset 1. |
---|
| 306 | // Default value, [{ offset: 0, color: 'black'},{offset: 1, color: 'white'}], is a gradient from black to white. |
---|
| 307 | colors: [] |
---|
| 308 | }; |
---|
| 309 | |
---|
| 310 | g.Pattern = { |
---|
| 311 | // summary: |
---|
| 312 | // An object specifying the default properties for a Pattern using in fill operations. |
---|
| 313 | |
---|
| 314 | // type: String |
---|
| 315 | // Specifies this object is a Pattern, value 'pattern'. |
---|
| 316 | type: "pattern", |
---|
| 317 | |
---|
| 318 | // x: Number |
---|
| 319 | // The X coordinate of the position of the pattern, default value is 0. |
---|
| 320 | x: 0, |
---|
| 321 | |
---|
| 322 | // y: Number |
---|
| 323 | // The Y coordinate of the position of the pattern, default value is 0. |
---|
| 324 | y: 0, |
---|
| 325 | |
---|
| 326 | // width: Number |
---|
| 327 | // The width of the pattern image, default value is 0. |
---|
| 328 | width: 0, |
---|
| 329 | |
---|
| 330 | // height: Number |
---|
| 331 | // The height of the pattern image, default value is 0. |
---|
| 332 | height: 0, |
---|
| 333 | |
---|
| 334 | // src: String |
---|
| 335 | // A url specifying the image to use for the pattern. |
---|
| 336 | src: "" |
---|
| 337 | }; |
---|
| 338 | |
---|
| 339 | g.Text = { |
---|
| 340 | // summary: |
---|
| 341 | // A keyword argument object defining both the text to be rendered in a VectorText shape, |
---|
| 342 | // and specifying position, alignment, and fitting. |
---|
| 343 | // text: String |
---|
| 344 | // The text to be rendered. |
---|
| 345 | // x: Number? |
---|
| 346 | // The left coordinate for the text's bounding box. |
---|
| 347 | // y: Number? |
---|
| 348 | // The top coordinate for the text's bounding box. |
---|
| 349 | // width: Number? |
---|
| 350 | // The width of the text's bounding box. |
---|
| 351 | // height: Number? |
---|
| 352 | // The height of the text's bounding box. |
---|
| 353 | // align: String? |
---|
| 354 | // The alignment of the text, as defined in SVG. Can be "start", "end" or "middle". |
---|
| 355 | // fitting: Number? |
---|
| 356 | // How the text is to be fitted to the bounding box. Can be 0 (no fitting), 1 (fitting based on |
---|
| 357 | // passed width of the bounding box and the size of the font), or 2 (fit text to the bounding box, |
---|
| 358 | // and ignore any size parameters). |
---|
| 359 | // leading: Number? |
---|
| 360 | // The leading to be used between lines in the text. |
---|
| 361 | // decoration: String? |
---|
| 362 | // Any text decoration to be used. |
---|
| 363 | }; |
---|
| 364 | |
---|
| 365 | g.Font = { |
---|
| 366 | // summary: |
---|
| 367 | // An object specifying the properties for a Font used in text operations. |
---|
| 368 | |
---|
| 369 | // type: String |
---|
| 370 | // Specifies this object is a Font, value 'font'. |
---|
| 371 | type: "font", |
---|
| 372 | |
---|
| 373 | // style: String |
---|
| 374 | // The font style, one of 'normal', 'bold', default value 'normal'. |
---|
| 375 | style: "normal", |
---|
| 376 | |
---|
| 377 | // variant: String |
---|
| 378 | // The font variant, one of 'normal', ... , default value 'normal'. |
---|
| 379 | variant: "normal", |
---|
| 380 | |
---|
| 381 | // weight: String |
---|
| 382 | // The font weight, one of 'normal', ..., default value 'normal'. |
---|
| 383 | weight: "normal", |
---|
| 384 | |
---|
| 385 | // size: String |
---|
| 386 | // The font size (including units), default value '10pt'. |
---|
| 387 | size: "10pt", |
---|
| 388 | |
---|
| 389 | // family: String |
---|
| 390 | // The font family, one of 'serif', 'sanserif', ..., default value 'serif'. |
---|
| 391 | family: "serif" |
---|
| 392 | }; |
---|
| 393 | |
---|
| 394 | =====*/ |
---|
| 395 | |
---|
| 396 | lang.mixin(g, { |
---|
| 397 | // summary: |
---|
| 398 | // defines constants, prototypes, and utility functions for the core Graphics API |
---|
| 399 | |
---|
| 400 | // default shapes, which are used to fill in missing parameters |
---|
| 401 | defaultPath: { |
---|
| 402 | // summary: |
---|
| 403 | // Defines the default Path prototype object. |
---|
| 404 | |
---|
| 405 | // type: String |
---|
| 406 | // Specifies this object is a Path, default value 'path'. |
---|
| 407 | type: "path", |
---|
| 408 | |
---|
| 409 | // path: String |
---|
| 410 | // The path commands. See W32C SVG 1.0 specification. |
---|
| 411 | // Defaults to empty string value. |
---|
| 412 | path: "" |
---|
| 413 | }, |
---|
| 414 | defaultPolyline: { |
---|
| 415 | // summary: |
---|
| 416 | // Defines the default PolyLine prototype. |
---|
| 417 | |
---|
| 418 | // type: String |
---|
| 419 | // Specifies this object is a PolyLine, default value 'polyline'. |
---|
| 420 | type: "polyline", |
---|
| 421 | |
---|
| 422 | // points: Array |
---|
| 423 | // An array of point objects [{x:0,y:0},...] defining the default polyline's line segments. Value is an empty array []. |
---|
| 424 | points: [] |
---|
| 425 | }, |
---|
| 426 | defaultRect: { |
---|
| 427 | // summary: |
---|
| 428 | // Defines the default Rect prototype. |
---|
| 429 | |
---|
| 430 | // type: String |
---|
| 431 | // Specifies this default object is a type of Rect. Value is 'rect' |
---|
| 432 | type: "rect", |
---|
| 433 | |
---|
| 434 | // x: Number |
---|
| 435 | // The X coordinate of the default rectangles position, value 0. |
---|
| 436 | x: 0, |
---|
| 437 | |
---|
| 438 | // y: Number |
---|
| 439 | // The Y coordinate of the default rectangle's position, value 0. |
---|
| 440 | y: 0, |
---|
| 441 | |
---|
| 442 | // width: Number |
---|
| 443 | // The width of the default rectangle, value 100. |
---|
| 444 | width: 100, |
---|
| 445 | |
---|
| 446 | // height: Number |
---|
| 447 | // The height of the default rectangle, value 100. |
---|
| 448 | height: 100, |
---|
| 449 | |
---|
| 450 | // r: Number |
---|
| 451 | // The corner radius for the default rectangle, value 0. |
---|
| 452 | r: 0 |
---|
| 453 | }, |
---|
| 454 | defaultEllipse: { |
---|
| 455 | // summary: |
---|
| 456 | // Defines the default Ellipse prototype. |
---|
| 457 | |
---|
| 458 | // type: String |
---|
| 459 | // Specifies that this object is a type of Ellipse, value is 'ellipse' |
---|
| 460 | type: "ellipse", |
---|
| 461 | |
---|
| 462 | // cx: Number |
---|
| 463 | // The X coordinate of the center of the ellipse, default value 0. |
---|
| 464 | cx: 0, |
---|
| 465 | |
---|
| 466 | // cy: Number |
---|
| 467 | // The Y coordinate of the center of the ellipse, default value 0. |
---|
| 468 | cy: 0, |
---|
| 469 | |
---|
| 470 | // rx: Number |
---|
| 471 | // The radius of the ellipse in the X direction, default value 200. |
---|
| 472 | rx: 200, |
---|
| 473 | |
---|
| 474 | // ry: Number |
---|
| 475 | // The radius of the ellipse in the Y direction, default value 200. |
---|
| 476 | ry: 100 |
---|
| 477 | }, |
---|
| 478 | defaultCircle: { |
---|
| 479 | // summary: |
---|
| 480 | // An object defining the default Circle prototype. |
---|
| 481 | |
---|
| 482 | // type: String |
---|
| 483 | // Specifies this object is a circle, value 'circle' |
---|
| 484 | type: "circle", |
---|
| 485 | |
---|
| 486 | // cx: Number |
---|
| 487 | // The X coordinate of the center of the circle, default value 0. |
---|
| 488 | cx: 0, |
---|
| 489 | // cy: Number |
---|
| 490 | // The Y coordinate of the center of the circle, default value 0. |
---|
| 491 | cy: 0, |
---|
| 492 | |
---|
| 493 | // r: Number |
---|
| 494 | // The radius, default value 100. |
---|
| 495 | r: 100 |
---|
| 496 | }, |
---|
| 497 | defaultLine: { |
---|
| 498 | // summary: |
---|
| 499 | // An object defining the default Line prototype. |
---|
| 500 | |
---|
| 501 | // type: String |
---|
| 502 | // Specifies this is a Line, value 'line' |
---|
| 503 | type: "line", |
---|
| 504 | |
---|
| 505 | // x1: Number |
---|
| 506 | // The X coordinate of the start of the line, default value 0. |
---|
| 507 | x1: 0, |
---|
| 508 | |
---|
| 509 | // y1: Number |
---|
| 510 | // The Y coordinate of the start of the line, default value 0. |
---|
| 511 | y1: 0, |
---|
| 512 | |
---|
| 513 | // x2: Number |
---|
| 514 | // The X coordinate of the end of the line, default value 100. |
---|
| 515 | x2: 100, |
---|
| 516 | |
---|
| 517 | // y2: Number |
---|
| 518 | // The Y coordinate of the end of the line, default value 100. |
---|
| 519 | y2: 100 |
---|
| 520 | }, |
---|
| 521 | defaultImage: { |
---|
| 522 | // summary: |
---|
| 523 | // Defines the default Image prototype. |
---|
| 524 | |
---|
| 525 | // type: String |
---|
| 526 | // Specifies this object is an image, value 'image'. |
---|
| 527 | type: "image", |
---|
| 528 | |
---|
| 529 | // x: Number |
---|
| 530 | // The X coordinate of the image's position, default value 0. |
---|
| 531 | x: 0, |
---|
| 532 | |
---|
| 533 | // y: Number |
---|
| 534 | // The Y coordinate of the image's position, default value 0. |
---|
| 535 | y: 0, |
---|
| 536 | |
---|
| 537 | // width: Number |
---|
| 538 | // The width of the image, default value 0. |
---|
| 539 | width: 0, |
---|
| 540 | |
---|
| 541 | // height: Number |
---|
| 542 | // The height of the image, default value 0. |
---|
| 543 | height: 0, |
---|
| 544 | |
---|
| 545 | // src: String |
---|
| 546 | // The src url of the image, defaults to empty string. |
---|
| 547 | src: "" |
---|
| 548 | }, |
---|
| 549 | defaultText: { |
---|
| 550 | // summary: |
---|
| 551 | // Defines the default Text prototype. |
---|
| 552 | |
---|
| 553 | // type: String |
---|
| 554 | // Specifies this is a Text shape, value 'text'. |
---|
| 555 | type: "text", |
---|
| 556 | |
---|
| 557 | // x: Number |
---|
| 558 | // The X coordinate of the text position, default value 0. |
---|
| 559 | x: 0, |
---|
| 560 | |
---|
| 561 | // y: Number |
---|
| 562 | // The Y coordinate of the text position, default value 0. |
---|
| 563 | y: 0, |
---|
| 564 | |
---|
| 565 | // text: String |
---|
| 566 | // The text to be displayed, default value empty string. |
---|
| 567 | text: "", |
---|
| 568 | |
---|
| 569 | // align: String |
---|
| 570 | // The horizontal text alignment, one of 'start', 'end', 'center'. Default value 'start'. |
---|
| 571 | align: "start", |
---|
| 572 | |
---|
| 573 | // decoration: String |
---|
| 574 | // The text decoration , one of 'none', ... . Default value 'none'. |
---|
| 575 | decoration: "none", |
---|
| 576 | |
---|
| 577 | // rotated: Boolean |
---|
| 578 | // Whether the text is rotated, boolean default value false. |
---|
| 579 | rotated: false, |
---|
| 580 | |
---|
| 581 | // kerning: Boolean |
---|
| 582 | // Whether kerning is used on the text, boolean default value true. |
---|
| 583 | kerning: true |
---|
| 584 | }, |
---|
| 585 | defaultTextPath: { |
---|
| 586 | // summary: |
---|
| 587 | // Defines the default TextPath prototype. |
---|
| 588 | |
---|
| 589 | // type: String |
---|
| 590 | // Specifies this is a TextPath, value 'textpath'. |
---|
| 591 | type: "textpath", |
---|
| 592 | |
---|
| 593 | // text: String |
---|
| 594 | // The text to be displayed, default value empty string. |
---|
| 595 | text: "", |
---|
| 596 | |
---|
| 597 | // align: String |
---|
| 598 | // The horizontal text alignment, one of 'start', 'end', 'center'. Default value 'start'. |
---|
| 599 | align: "start", |
---|
| 600 | |
---|
| 601 | // decoration: String |
---|
| 602 | // The text decoration , one of 'none', ... . Default value 'none'. |
---|
| 603 | decoration: "none", |
---|
| 604 | |
---|
| 605 | // rotated: Boolean |
---|
| 606 | // Whether the text is rotated, boolean default value false. |
---|
| 607 | rotated: false, |
---|
| 608 | |
---|
| 609 | // kerning: Boolean |
---|
| 610 | // Whether kerning is used on the text, boolean default value true. |
---|
| 611 | kerning: true |
---|
| 612 | }, |
---|
| 613 | |
---|
| 614 | // default stylistic attributes |
---|
| 615 | defaultStroke: { |
---|
| 616 | // summary: |
---|
| 617 | // A stroke defines stylistic properties that are used when drawing a path. |
---|
| 618 | // This object defines the default Stroke prototype. |
---|
| 619 | // type: String |
---|
| 620 | // Specifies this object is a type of Stroke, value 'stroke'. |
---|
| 621 | type: "stroke", |
---|
| 622 | |
---|
| 623 | // color: String |
---|
| 624 | // The color of the stroke, default value 'black'. |
---|
| 625 | color: "black", |
---|
| 626 | |
---|
| 627 | // style: String |
---|
| 628 | // The style of the stroke, one of 'solid', ... . Default value 'solid'. |
---|
| 629 | style: "solid", |
---|
| 630 | |
---|
| 631 | // width: Number |
---|
| 632 | // The width of a stroke, default value 1. |
---|
| 633 | width: 1, |
---|
| 634 | |
---|
| 635 | // cap: String |
---|
| 636 | // The endcap style of the path. One of 'butt', 'round', ... . Default value 'butt'. |
---|
| 637 | cap: "butt", |
---|
| 638 | |
---|
| 639 | // join: Number |
---|
| 640 | // The join style to use when combining path segments. Default value 4. |
---|
| 641 | join: 4 |
---|
| 642 | }, |
---|
| 643 | defaultLinearGradient: { |
---|
| 644 | // summary: |
---|
| 645 | // An object defining the default stylistic properties used for Linear Gradient fills. |
---|
| 646 | // Linear gradients are drawn along a virtual line, which results in appearance of a rotated pattern in a given direction/orientation. |
---|
| 647 | |
---|
| 648 | // type: String |
---|
| 649 | // Specifies this object is a Linear Gradient, value 'linear' |
---|
| 650 | type: "linear", |
---|
| 651 | |
---|
| 652 | // x1: Number |
---|
| 653 | // The X coordinate of the start of the virtual line along which the gradient is drawn, default value 0. |
---|
| 654 | x1: 0, |
---|
| 655 | |
---|
| 656 | // y1: Number |
---|
| 657 | // The Y coordinate of the start of the virtual line along which the gradient is drawn, default value 0. |
---|
| 658 | y1: 0, |
---|
| 659 | |
---|
| 660 | // x2: Number |
---|
| 661 | // The X coordinate of the end of the virtual line along which the gradient is drawn, default value 100. |
---|
| 662 | x2: 100, |
---|
| 663 | |
---|
| 664 | // y2: Number |
---|
| 665 | // The Y coordinate of the end of the virtual line along which the gradient is drawn, default value 100. |
---|
| 666 | y2: 100, |
---|
| 667 | |
---|
| 668 | // colors: Array |
---|
| 669 | // An array of colors at given offsets (from the start of the line). The start of the line is |
---|
| 670 | // defined at offest 0 with the end of the line at offset 1. |
---|
| 671 | // Default value, [{ offset: 0, color: 'black'},{offset: 1, color: 'white'}], is a gradient from black to white. |
---|
| 672 | colors: [ |
---|
| 673 | { offset: 0, color: "black" }, { offset: 1, color: "white" } |
---|
| 674 | ] |
---|
| 675 | }, |
---|
| 676 | defaultRadialGradient: { |
---|
| 677 | // summary: |
---|
| 678 | // An object specifying the default properties for RadialGradients using in fills patterns. |
---|
| 679 | |
---|
| 680 | // type: String |
---|
| 681 | // Specifies this is a RadialGradient, value 'radial' |
---|
| 682 | type: "radial", |
---|
| 683 | |
---|
| 684 | // cx: Number |
---|
| 685 | // The X coordinate of the center of the radial gradient, default value 0. |
---|
| 686 | cx: 0, |
---|
| 687 | |
---|
| 688 | // cy: Number |
---|
| 689 | // The Y coordinate of the center of the radial gradient, default value 0. |
---|
| 690 | cy: 0, |
---|
| 691 | |
---|
| 692 | // r: Number |
---|
| 693 | // The radius to the end of the radial gradient, default value 100. |
---|
| 694 | r: 100, |
---|
| 695 | |
---|
| 696 | // colors: Array |
---|
| 697 | // An array of colors at given offsets (from the center of the radial gradient). |
---|
| 698 | // The center is defined at offest 0 with the outer edge of the gradient at offset 1. |
---|
| 699 | // Default value, [{ offset: 0, color: 'black'},{offset: 1, color: 'white'}], is a gradient from black to white. |
---|
| 700 | colors: [ |
---|
| 701 | { offset: 0, color: "black" }, { offset: 1, color: "white" } |
---|
| 702 | ] |
---|
| 703 | }, |
---|
| 704 | defaultPattern: { |
---|
| 705 | // summary: |
---|
| 706 | // An object specifying the default properties for a Pattern using in fill operations. |
---|
| 707 | |
---|
| 708 | // type: String |
---|
| 709 | // Specifies this object is a Pattern, value 'pattern'. |
---|
| 710 | type: "pattern", |
---|
| 711 | |
---|
| 712 | // x: Number |
---|
| 713 | // The X coordinate of the position of the pattern, default value is 0. |
---|
| 714 | x: 0, |
---|
| 715 | |
---|
| 716 | // y: Number |
---|
| 717 | // The Y coordinate of the position of the pattern, default value is 0. |
---|
| 718 | y: 0, |
---|
| 719 | |
---|
| 720 | // width: Number |
---|
| 721 | // The width of the pattern image, default value is 0. |
---|
| 722 | width: 0, |
---|
| 723 | |
---|
| 724 | // height: Number |
---|
| 725 | // The height of the pattern image, default value is 0. |
---|
| 726 | height: 0, |
---|
| 727 | |
---|
| 728 | // src: String |
---|
| 729 | // A url specifying the image to use for the pattern. |
---|
| 730 | src: "" |
---|
| 731 | }, |
---|
| 732 | defaultFont: { |
---|
| 733 | // summary: |
---|
| 734 | // An object specifying the default properties for a Font used in text operations. |
---|
| 735 | |
---|
| 736 | // type: String |
---|
| 737 | // Specifies this object is a Font, value 'font'. |
---|
| 738 | type: "font", |
---|
| 739 | |
---|
| 740 | // style: String |
---|
| 741 | // The font style, one of 'normal', 'bold', default value 'normal'. |
---|
| 742 | style: "normal", |
---|
| 743 | |
---|
| 744 | // variant: String |
---|
| 745 | // The font variant, one of 'normal', ... , default value 'normal'. |
---|
| 746 | variant: "normal", |
---|
| 747 | |
---|
| 748 | // weight: String |
---|
| 749 | // The font weight, one of 'normal', ..., default value 'normal'. |
---|
| 750 | weight: "normal", |
---|
| 751 | |
---|
| 752 | // size: String |
---|
| 753 | // The font size (including units), default value '10pt'. |
---|
| 754 | size: "10pt", |
---|
| 755 | |
---|
| 756 | // family: String |
---|
| 757 | // The font family, one of 'serif', 'sanserif', ..., default value 'serif'. |
---|
| 758 | family: "serif" |
---|
| 759 | }, |
---|
| 760 | |
---|
| 761 | getDefault: (function(){ |
---|
| 762 | // summary: |
---|
| 763 | // Returns a function used to access default memoized prototype objects (see them defined above). |
---|
| 764 | var typeCtorCache = {}; |
---|
| 765 | // a memoized delegate() |
---|
| 766 | return function(/*String*/ type){ |
---|
| 767 | var t = typeCtorCache[type]; |
---|
| 768 | if(t){ |
---|
| 769 | return new t(); |
---|
| 770 | } |
---|
| 771 | t = typeCtorCache[type] = new Function(); |
---|
| 772 | t.prototype = g[ "default" + type ]; |
---|
| 773 | return new t(); |
---|
| 774 | } |
---|
| 775 | })(), |
---|
| 776 | |
---|
| 777 | normalizeColor: function(/*dojo/Color|Array|string|Object*/ color){ |
---|
| 778 | // summary: |
---|
| 779 | // converts any legal color representation to normalized |
---|
| 780 | // dojo/Color object |
---|
| 781 | // color: |
---|
| 782 | // A color representation. |
---|
| 783 | return (color instanceof Color) ? color : new Color(color); // dojo/Color |
---|
| 784 | }, |
---|
| 785 | normalizeParameters: function(existed, update){ |
---|
| 786 | // summary: |
---|
| 787 | // updates an existing object with properties from an 'update' |
---|
| 788 | // object |
---|
| 789 | // existed: Object |
---|
| 790 | // the target object to be updated |
---|
| 791 | // update: Object |
---|
| 792 | // the 'update' object, whose properties will be used to update |
---|
| 793 | // the existed object |
---|
| 794 | var x; |
---|
| 795 | if(update){ |
---|
| 796 | var empty = {}; |
---|
| 797 | for(x in existed){ |
---|
| 798 | if(x in update && !(x in empty)){ |
---|
| 799 | existed[x] = update[x]; |
---|
| 800 | } |
---|
| 801 | } |
---|
| 802 | } |
---|
| 803 | return existed; // Object |
---|
| 804 | }, |
---|
| 805 | makeParameters: function(defaults, update){ |
---|
| 806 | // summary: |
---|
| 807 | // copies the original object, and all copied properties from the |
---|
| 808 | // 'update' object |
---|
| 809 | // defaults: Object |
---|
| 810 | // the object to be cloned before updating |
---|
| 811 | // update: Object |
---|
| 812 | // the object, which properties are to be cloned during updating |
---|
| 813 | // returns: Object |
---|
| 814 | // new object with new and default properties |
---|
| 815 | var i = null; |
---|
| 816 | if(!update){ |
---|
| 817 | // return dojo.clone(defaults); |
---|
| 818 | return lang.delegate(defaults); |
---|
| 819 | } |
---|
| 820 | var result = {}; |
---|
| 821 | for(i in defaults){ |
---|
| 822 | if(!(i in result)){ |
---|
| 823 | result[i] = lang.clone((i in update) ? update[i] : defaults[i]); |
---|
| 824 | } |
---|
| 825 | } |
---|
| 826 | return result; // Object |
---|
| 827 | }, |
---|
| 828 | formatNumber: function(x, addSpace){ |
---|
| 829 | // summary: |
---|
| 830 | // converts a number to a string using a fixed notation |
---|
| 831 | // x: Number |
---|
| 832 | // number to be converted |
---|
| 833 | // addSpace: Boolean |
---|
| 834 | // whether to add a space before a positive number |
---|
| 835 | // returns: String |
---|
| 836 | // the formatted value |
---|
| 837 | var val = x.toString(); |
---|
| 838 | if(val.indexOf("e") >= 0){ |
---|
| 839 | val = x.toFixed(4); |
---|
| 840 | }else{ |
---|
| 841 | var point = val.indexOf("."); |
---|
| 842 | if(point >= 0 && val.length - point > 5){ |
---|
| 843 | val = x.toFixed(4); |
---|
| 844 | } |
---|
| 845 | } |
---|
| 846 | if(x < 0){ |
---|
| 847 | return val; // String |
---|
| 848 | } |
---|
| 849 | return addSpace ? " " + val : val; // String |
---|
| 850 | }, |
---|
| 851 | // font operations |
---|
| 852 | makeFontString: function(font){ |
---|
| 853 | // summary: |
---|
| 854 | // converts a font object to a CSS font string |
---|
| 855 | // font: Object |
---|
| 856 | // font object (see dojox/gfx.defaultFont) |
---|
| 857 | return font.style + " " + font.variant + " " + font.weight + " " + font.size + " " + font.family; // Object |
---|
| 858 | }, |
---|
| 859 | splitFontString: function(str){ |
---|
| 860 | // summary: |
---|
| 861 | // converts a CSS font string to a font object |
---|
| 862 | // description: |
---|
| 863 | // Converts a CSS font string to a gfx font object. The CSS font |
---|
| 864 | // string components should follow the W3C specified order |
---|
| 865 | // (see http://www.w3.org/TR/CSS2/fonts.html#font-shorthand): |
---|
| 866 | // style, variant, weight, size, optional line height (will be |
---|
| 867 | // ignored), and family. Note that the Font.size attribute is limited to numeric CSS length. |
---|
| 868 | // str: String |
---|
| 869 | // a CSS font string. |
---|
| 870 | // returns: Object |
---|
| 871 | // object in dojox/gfx.defaultFont format |
---|
| 872 | var font = g.getDefault("Font"); |
---|
| 873 | var t = str.split(/\s+/); |
---|
| 874 | do{ |
---|
| 875 | if(t.length < 5){ break; } |
---|
| 876 | font.style = t[0]; |
---|
| 877 | font.variant = t[1]; |
---|
| 878 | font.weight = t[2]; |
---|
| 879 | var i = t[3].indexOf("/"); |
---|
| 880 | font.size = i < 0 ? t[3] : t[3].substring(0, i); |
---|
| 881 | var j = 4; |
---|
| 882 | if(i < 0){ |
---|
| 883 | if(t[4] == "/"){ |
---|
| 884 | j = 6; |
---|
| 885 | }else if(t[4].charAt(0) == "/"){ |
---|
| 886 | j = 5; |
---|
| 887 | } |
---|
| 888 | } |
---|
| 889 | if(j < t.length){ |
---|
| 890 | font.family = t.slice(j).join(" "); |
---|
| 891 | } |
---|
| 892 | }while(false); |
---|
| 893 | return font; // Object |
---|
| 894 | }, |
---|
| 895 | // length operations |
---|
| 896 | |
---|
| 897 | // cm_in_pt: Number |
---|
| 898 | // points per centimeter (constant) |
---|
| 899 | cm_in_pt: 72 / 2.54, |
---|
| 900 | |
---|
| 901 | // mm_in_pt: Number |
---|
| 902 | // points per millimeter (constant) |
---|
| 903 | mm_in_pt: 7.2 / 2.54, |
---|
| 904 | |
---|
| 905 | px_in_pt: function(){ |
---|
| 906 | // summary: |
---|
| 907 | // returns the current number of pixels per point. |
---|
| 908 | return g._base._getCachedFontMeasurements()["12pt"] / 12; // Number |
---|
| 909 | }, |
---|
| 910 | |
---|
| 911 | pt2px: function(len){ |
---|
| 912 | // summary: |
---|
| 913 | // converts points to pixels |
---|
| 914 | // len: Number |
---|
| 915 | // a value in points |
---|
| 916 | return len * g.px_in_pt(); // Number |
---|
| 917 | }, |
---|
| 918 | |
---|
| 919 | px2pt: function(len){ |
---|
| 920 | // summary: |
---|
| 921 | // converts pixels to points |
---|
| 922 | // len: Number |
---|
| 923 | // a value in pixels |
---|
| 924 | return len / g.px_in_pt(); // Number |
---|
| 925 | }, |
---|
| 926 | |
---|
| 927 | normalizedLength: function(len) { |
---|
| 928 | // summary: |
---|
| 929 | // converts any length value to pixels |
---|
| 930 | // len: String |
---|
| 931 | // a length, e.g., '12pc' |
---|
| 932 | // returns: Number |
---|
| 933 | // pixels |
---|
| 934 | if(len.length === 0){ return 0; } |
---|
| 935 | if(len.length > 2){ |
---|
| 936 | var px_in_pt = g.px_in_pt(); |
---|
| 937 | var val = parseFloat(len); |
---|
| 938 | switch(len.slice(-2)){ |
---|
| 939 | case "px": return val; |
---|
| 940 | case "pt": return val * px_in_pt; |
---|
| 941 | case "in": return val * 72 * px_in_pt; |
---|
| 942 | case "pc": return val * 12 * px_in_pt; |
---|
| 943 | case "mm": return val * g.mm_in_pt * px_in_pt; |
---|
| 944 | case "cm": return val * g.cm_in_pt * px_in_pt; |
---|
| 945 | } |
---|
| 946 | } |
---|
| 947 | return parseFloat(len); // Number |
---|
| 948 | }, |
---|
| 949 | |
---|
| 950 | // pathVmlRegExp: RegExp |
---|
| 951 | // a constant regular expression used to split a SVG/VML path into primitive components |
---|
| 952 | // tags: |
---|
| 953 | // private |
---|
| 954 | pathVmlRegExp: /([A-Za-z]+)|(\d+(\.\d+)?)|(\.\d+)|(-\d+(\.\d+)?)|(-\.\d+)/g, |
---|
| 955 | |
---|
| 956 | // pathVmlRegExp: RegExp |
---|
| 957 | // a constant regular expression used to split a SVG/VML path into primitive components |
---|
| 958 | // tags: |
---|
| 959 | // private |
---|
| 960 | pathSvgRegExp: /([A-Za-z])|(\d+(\.\d+)?)|(\.\d+)|(-\d+(\.\d+)?)|(-\.\d+)/g, |
---|
| 961 | |
---|
| 962 | equalSources: function(a, b){ |
---|
| 963 | // summary: |
---|
| 964 | // compares event sources, returns true if they are equal |
---|
| 965 | // a: Object |
---|
| 966 | // first event source |
---|
| 967 | // b: Object |
---|
| 968 | // event source to compare against a |
---|
| 969 | // returns: Boolean |
---|
| 970 | // true, if objects are truthy and the same |
---|
| 971 | return a && b && a === b; |
---|
| 972 | }, |
---|
| 973 | |
---|
| 974 | switchTo: function(/*String|Object*/ renderer){ |
---|
| 975 | // summary: |
---|
| 976 | // switch the graphics implementation to the specified renderer. |
---|
| 977 | // renderer: |
---|
| 978 | // Either the string name of a renderer (eg. 'canvas', 'svg, ...) or the renderer |
---|
| 979 | // object to switch to. |
---|
| 980 | var ns = typeof renderer == "string" ? g[renderer] : renderer; |
---|
| 981 | if(ns){ |
---|
| 982 | // If more options are added, update the docblock at the end of shape.js! |
---|
| 983 | arr.forEach(["Group", "Rect", "Ellipse", "Circle", "Line", |
---|
| 984 | "Polyline", "Image", "Text", "Path", "TextPath", |
---|
| 985 | "Surface", "createSurface", "fixTarget"], function(name){ |
---|
| 986 | g[name] = ns[name]; |
---|
| 987 | }); |
---|
| 988 | if(typeof renderer == "string"){ |
---|
| 989 | g.renderer = renderer; |
---|
| 990 | }else{ |
---|
| 991 | arr.some(["svg","vml","canvas","canvasWithEvents","silverlight"], function(r){ |
---|
| 992 | return (g.renderer = g[r] && g[r].Surface === g.Surface ? r : null); |
---|
| 993 | }); |
---|
| 994 | } |
---|
| 995 | } |
---|
| 996 | } |
---|
| 997 | }); |
---|
| 998 | |
---|
| 999 | /*===== |
---|
| 1000 | g.createSurface = function(parentNode, width, height){ |
---|
| 1001 | // summary: |
---|
| 1002 | // creates a surface |
---|
| 1003 | // parentNode: Node |
---|
| 1004 | // a parent node |
---|
| 1005 | // width: String|Number |
---|
| 1006 | // width of surface, e.g., "100px" or 100 |
---|
| 1007 | // height: String|Number |
---|
| 1008 | // height of surface, e.g., "100px" or 100 |
---|
| 1009 | // returns: dojox/gfx.Surface |
---|
| 1010 | // newly created surface |
---|
| 1011 | }; |
---|
| 1012 | g.fixTarget = function(){ |
---|
| 1013 | // tags: |
---|
| 1014 | // private |
---|
| 1015 | }; |
---|
| 1016 | =====*/ |
---|
| 1017 | |
---|
| 1018 | return g; // defaults object api |
---|
| 1019 | }); |
---|