1
YUI.add('graphics-vml', function (Y, NAME) {
3
var IMPLEMENTATION = "vml",
5
SPLITPATHPATTERN = /[a-z][^a-z]*/ig,
6
SPLITARGSPATTERN = /[\-]?[0-9]*[0-9|\.][0-9]*/g,
8
IS_NUM = Y_LANG.isNumber,
9
IS_ARRAY = Y_LANG.isArray,
11
Y_SELECTOR = Y.Selector,
12
DOCUMENT = Y.config.doc,
13
AttributeLite = Y.AttributeLite,
21
_getClassName = Y.ClassNameManager.getClassName;
23
function VMLDrawing() {}
26
* <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Drawing.html">`Drawing`</a> class.
27
* `VMLDrawing` is not intended to be used directly. Instead, use the <a href="Drawing.html">`Drawing`</a> class.
28
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
29
* capabilities, the <a href="Drawing.html">`Drawing`</a> class will point to the `VMLDrawing` class.
35
VMLDrawing.prototype = {
37
* Maps path to methods
39
* @property _pathSymbolToMethod
43
_pathSymbolToMethod: {
50
Q: "quadraticCurveTo",
51
q: "relativeQuadraticCurveTo",
57
* Value for rounding up to coordsize
59
* @property _coordSpaceMultiplier
63
_coordSpaceMultiplier: 100,
66
* Rounds dimensions and position values based on the coordinate space.
69
* @param {Number} The value for rounding
75
return Math.round(val * this._coordSpaceMultiplier);
79
* Concatanates the path.
82
* @param {String} val The value to add to the path string.
85
_addToPath: function(val)
87
this._path = this._path || "";
90
this._path += this._movePath;
91
this._movePath = null;
97
* Current x position of the drawing.
106
* Current y position of the drqwing.
108
* @property _currentY
115
* Draws a bezier curve.
118
* @param {Number} cp1x x-coordinate for the first control point.
119
* @param {Number} cp1y y-coordinate for the first control point.
120
* @param {Number} cp2x x-coordinate for the second control point.
121
* @param {Number} cp2y y-coordinate for the second control point.
122
* @param {Number} x x-coordinate for the end point.
123
* @param {Number} y y-coordinate for the end point.
126
curveTo: function() {
127
this._curveTo.apply(this, [Y.Array(arguments), false]);
132
* Draws a bezier curve.
134
* @method relativeCurveTo
135
* @param {Number} cp1x x-coordinate for the first control point.
136
* @param {Number} cp1y y-coordinate for the first control point.
137
* @param {Number} cp2x x-coordinate for the second control point.
138
* @param {Number} cp2y y-coordinate for the second control point.
139
* @param {Number} x x-coordinate for the end point.
140
* @param {Number} y y-coordinate for the end point.
143
relativeCurveTo: function() {
144
this._curveTo.apply(this, [Y.Array(arguments), true]);
149
* Implements curveTo methods.
152
* @param {Array} args The arguments to be used.
153
* @param {Boolean} relative Indicates whether or not to use relative coordinates.
156
_curveTo: function(args, relative) {
173
command = relative ? " v " : " c ",
174
relativeX = relative ? parseFloat(this._currentX) : 0,
175
relativeY = relative ? parseFloat(this._currentY) : 0;
176
len = args.length - 5;
178
for(i = 0; i < len; i = i + 6)
180
cp1x = parseFloat(args[i]);
181
cp1y = parseFloat(args[i + 1]);
182
cp2x = parseFloat(args[i + 2]);
183
cp2y = parseFloat(args[i + 3]);
184
x = parseFloat(args[i + 4]);
185
y = parseFloat(args[i + 5]);
202
cp1x = cp1x + relativeX;
203
cp1y = cp1y + relativeY;
204
cp2x = cp2x + relativeX;
205
cp2y = cp2y + relativeY;
208
right = Math.max(x, Math.max(cp1x, cp2x));
209
bottom = Math.max(y, Math.max(cp1y, cp2y));
210
left = Math.min(x, Math.min(cp1x, cp2x));
211
top = Math.min(y, Math.min(cp1y, cp2y));
212
w = Math.abs(right - left);
213
h = Math.abs(bottom - top);
214
pts = [[this._currentX, this._currentY] , [cp1x, cp1y], [cp2x, cp2y], [x, y]];
215
this._setCurveBoundingBox(pts, w, h);
219
this._addToPath(path);
223
* Draws a quadratic bezier curve.
225
* @method quadraticCurveTo
226
* @param {Number} cpx x-coordinate for the control point.
227
* @param {Number} cpy y-coordinate for the control point.
228
* @param {Number} x x-coordinate for the end point.
229
* @param {Number} y y-coordinate for the end point.
232
quadraticCurveTo: function() {
233
this._quadraticCurveTo.apply(this, [Y.Array(arguments), false]);
238
* Draws a quadratic bezier curve relative to the current position.
240
* @method relativeQuadraticCurveTo
241
* @param {Number} cpx x-coordinate for the control point.
242
* @param {Number} cpy y-coordinate for the control point.
243
* @param {Number} x x-coordinate for the end point.
244
* @param {Number} y y-coordinate for the end point.
247
relativeQuadraticCurveTo: function() {
248
this._quadraticCurveTo.apply(this, [Y.Array(arguments), true]);
253
* Implements quadraticCurveTo methods.
255
* @method _quadraticCurveTo
256
* @param {Array} args The arguments to be used.
257
* @param {Boolean} relative Indicates whether or not to use relative coordinates.
260
_quadraticCurveTo: function(args, relative) {
269
currentX = this._currentX,
270
currentY = this._currentY,
272
len = args.length - 3,
274
relativeX = relative ? parseFloat(this._currentX) : 0,
275
relativeY = relative ? parseFloat(this._currentY) : 0;
276
for(i = 0; i < len; i = i + 4)
278
cpx = parseFloat(args[i]) + relativeX;
279
cpy = parseFloat(args[i + 1]) + relativeY;
280
x = parseFloat(args[i + 2]) + relativeX;
281
y = parseFloat(args[i + 3]) + relativeY;
282
cp1x = currentX + 0.67*(cpx - currentX);
283
cp1y = currentY + 0.67*(cpy - currentY);
284
cp2x = cp1x + (x - currentX) * 0.34;
285
cp2y = cp1y + (y - currentY) * 0.34;
286
bezierArgs.push(cp1x);
287
bezierArgs.push(cp1y);
288
bezierArgs.push(cp2x);
289
bezierArgs.push(cp2y);
293
this._curveTo.apply(this, [bezierArgs, false]);
300
* @param {Number} x x-coordinate
301
* @param {Number} y y-coordinate
302
* @param {Number} w width
303
* @param {Number} h height
306
drawRect: function(x, y, w, h) {
308
this.lineTo(x + w, y);
309
this.lineTo(x + w, y + h);
310
this.lineTo(x, y + h);
318
* Draws a rectangle with rounded corners.
321
* @param {Number} x x-coordinate
322
* @param {Number} y y-coordinate
323
* @param {Number} w width
324
* @param {Number} h height
325
* @param {Number} ew width of the ellipse used to draw the rounded corners
326
* @param {Number} eh height of the ellipse used to draw the rounded corners
329
drawRoundRect: function(x, y, w, h, ew, eh) {
330
this.moveTo(x, y + eh);
331
this.lineTo(x, y + h - eh);
332
this.quadraticCurveTo(x, y + h, x + ew, y + h);
333
this.lineTo(x + w - ew, y + h);
334
this.quadraticCurveTo(x + w, y + h, x + w, y + h - eh);
335
this.lineTo(x + w, y + eh);
336
this.quadraticCurveTo(x + w, y, x + w - ew, y);
337
this.lineTo(x + ew, y);
338
this.quadraticCurveTo(x, y, x, y + eh);
343
* Draws a circle. Used internally by `CanvasCircle` class.
346
* @param {Number} x y-coordinate
347
* @param {Number} y x-coordinate
348
* @param {Number} r radius
352
drawCircle: function(x, y, radius) {
358
this._drawingComplete = false;
359
this._trackSize(x + circum, y + circum);
360
this.moveTo((x + circum), (y + radius));
363
this._round(x + radius) +
365
this._round(y + radius) +
367
this._round(radius) +
369
this._round(radius) +
381
* @method drawEllipse
382
* @param {Number} x x-coordinate
383
* @param {Number} y y-coordinate
384
* @param {Number} w width
385
* @param {Number} h height
389
drawEllipse: function(x, y, w, h) {
395
this._drawingComplete = false;
396
this._trackSize(x + w, y + h);
397
this.moveTo((x + w), (y + yRadius));
400
this._round(x + radius) +
402
this._round(x + radius) +
404
this._round(y + yRadius) +
406
this._round(radius) +
408
this._round(yRadius) +
420
* @method drawDiamond
421
* @param {Number} x y-coordinate
422
* @param {Number} y x-coordinate
423
* @param {Number} width width
424
* @param {Number} height height
428
drawDiamond: function(x, y, width, height)
430
var midWidth = width * 0.5,
431
midHeight = height * 0.5;
432
this.moveTo(x + midWidth, y);
433
this.lineTo(x + width, y + midHeight);
434
this.lineTo(x + midWidth, y + height);
435
this.lineTo(x, y + midHeight);
436
this.lineTo(x + midWidth, y);
444
* @param {Number} x x-coordinate of the wedge's center point
445
* @param {Number} y y-coordinate of the wedge's center point
446
* @param {Number} startAngle starting angle in degrees
447
* @param {Number} arc sweep of the wedge. Negative values draw clockwise.
448
* @param {Number} radius radius of wedge. If [optional] yRadius is defined, then radius is the x radius.
449
* @param {Number} yRadius [optional] y radius for wedge.
453
drawWedge: function(x, y, startAngle, arc, radius)
455
var diameter = radius * 2;
456
if(Math.abs(arc) > 360)
462
startAngle *= -65535;
464
startAngle = Math.round(startAngle);
465
arc = Math.round(arc);
473
this._round(radius) +
475
this._round(radius) +
481
this._trackSize(diameter, diameter);
486
* Draws a line segment from the current drawing position to the specified x and y coordinates.
489
* @param {Number} point1 x-coordinate for the end point.
490
* @param {Number} point2 y-coordinate for the end point.
495
this._lineTo.apply(this, [Y.Array(arguments), false]);
500
* Draws a line segment using the current line style from the current drawing position to the relative x and y coordinates.
502
* @method relativeLineTo
503
* @param {Number} point1 x-coordinate for the end point.
504
* @param {Number} point2 y-coordinate for the end point.
507
relativeLineTo: function()
509
this._lineTo.apply(this, [Y.Array(arguments), true]);
514
* Implements lineTo methods.
517
* @param {Array} args The arguments to be used.
518
* @param {Boolean} relative Indicates whether or not to use relative coordinates.
521
_lineTo: function(args, relative) {
522
var point1 = args[0],
527
path = relative ? " r " : " l ",
528
relativeX = relative ? parseFloat(this._currentX) : 0,
529
relativeY = relative ? parseFloat(this._currentY) : 0;
530
if (typeof point1 === "string" || typeof point1 === "number") {
531
len = args.length - 1;
532
for (i = 0; i < len; i = i + 2) {
533
x = parseFloat(args[i]);
534
y = parseFloat(args[i + 1]);
535
path += ' ' + this._round(x) + ', ' + this._round(y);
540
this._trackSize.apply(this, [x, y]);
546
for (i = 0; i < len; i = i + 1) {
547
x = parseFloat(args[i][0]);
548
y = parseFloat(args[i][1]);
549
path += ' ' + this._round(x) + ', ' + this._round(y);
554
this._trackSize.apply(this, [x, y]);
557
this._addToPath(path);
562
* Moves the current drawing position to specified x and y coordinates.
565
* @param {Number} x x-coordinate for the end point.
566
* @param {Number} y y-coordinate for the end point.
571
this._moveTo.apply(this, [Y.Array(arguments), false]);
576
* Moves the current drawing position relative to specified x and y coordinates.
578
* @method relativeMoveTo
579
* @param {Number} x x-coordinate for the end point.
580
* @param {Number} y y-coordinate for the end point.
583
relativeMoveTo: function()
585
this._moveTo.apply(this, [Y.Array(arguments), true]);
590
* Implements moveTo methods.
593
* @param {Array} args The arguments to be used.
594
* @param {Boolean} relative Indicates whether or not to use relative coordinates.
597
_moveTo: function(args, relative) {
598
var x = parseFloat(args[0]),
599
y = parseFloat(args[1]),
600
command = relative ? " t " : " m ",
601
relativeX = relative ? parseFloat(this._currentX) : 0,
602
relativeY = relative ? parseFloat(this._currentY) : 0;
603
this._movePath = command + this._round(x) + ", " + this._round(y);
606
this._trackSize(x, y);
617
_closePath: function()
619
var fill = this.get("fill"),
620
stroke = this.get("stroke"),
622
w = this.get("width"),
623
h = this.get("height"),
626
multiplier = this._coordSpaceMultiplier;
627
this._fillChangeHandler();
628
this._strokeChangeHandler();
631
if(fill && fill.color)
642
node.path = path + pathEnd;
644
if(!isNaN(w) && !isNaN(h))
646
node.coordOrigin = this._left + ", " + this._top;
647
node.coordSize = (w * multiplier) + ", " + (h * multiplier);
648
node.style.position = "absolute";
649
node.style.width = w + "px";
650
node.style.height = h + "px";
653
this._movePath = null;
654
this._updateTransform();
658
* Completes a drawing operation.
670
* Ends a fill and stroke
675
closePath: function()
677
this._addToPath(" x e");
696
this._movePath = null;
701
* Returns the points on a curve
703
* @method getBezierData
704
* @param Array points Array containing the begin, end and control points of a curve.
705
* @param Number t The value for incrementing the next set of points.
709
getBezierData: function(points, t) {
710
var n = points.length,
715
for (i = 0; i < n; ++i){
716
tmp[i] = [points[i][0], points[i][1]]; // save input
719
for (j = 1; j < n; ++j) {
720
for (i = 0; i < n - j; ++i) {
721
tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];
722
tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];
725
return [ tmp[0][0], tmp[0][1] ];
729
* Calculates the bounding box for a curve
731
* @method _setCurveBoundingBox
732
* @param Array pts Array containing points for start, end and control points of a curve.
733
* @param Number w Width used to calculate the number of points to describe the curve.
734
* @param Number h Height used to calculate the number of points to describe the curve.
737
_setCurveBoundingBox: function(pts, w, h)
740
left = this._currentX,
742
top = this._currentY,
744
len = Math.round(Math.sqrt((w * w) + (h * h))),
747
for(i = 0; i < len; ++i)
749
xy = this.getBezierData(pts, t * i);
750
left = isNaN(left) ? xy[0] : Math.min(xy[0], left);
751
right = isNaN(right) ? xy[0] : Math.max(xy[0], right);
752
top = isNaN(top) ? xy[1] : Math.min(xy[1], top);
753
bottom = isNaN(bottom) ? xy[1] : Math.max(xy[1], bottom);
755
left = Math.round(left * 10)/10;
756
right = Math.round(right * 10)/10;
757
top = Math.round(top * 10)/10;
758
bottom = Math.round(bottom * 10)/10;
759
this._trackSize(right, bottom);
760
this._trackSize(left, top);
764
* Updates the size of the graphics object
767
* @param {Number} w width
768
* @param {Number} h height
771
_trackSize: function(w, h) {
772
if (w > this._right) {
783
if (h > this._bottom)
787
this._width = this._right - this._left;
788
this._height = this._bottom - this._top;
803
Y.VMLDrawing = VMLDrawing;
805
* <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Shape.html">`Shape`</a> class.
806
* `VMLShape` is not intended to be used directly. Instead, use the <a href="Shape.html">`Shape`</a> class.
807
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
808
* capabilities, the <a href="Shape.html">`Shape`</a> class will point to the `VMLShape` class.
813
* @param {Object} cfg (optional) Attribute configs
815
VMLShape = function()
817
this._transforms = [];
818
this.matrix = new Y.Matrix();
819
this._normalizedMatrix = new Y.Matrix();
820
VMLShape.superclass.constructor.apply(this, arguments);
823
VMLShape.NAME = "shape";
825
Y.extend(VMLShape, Y.GraphicBase, Y.mix({
827
* Indicates the type of shape
836
* Init method, invoked during construction.
837
* Calls `initializer` method.
844
this.initializer.apply(this, arguments);
848
* Initializes the shape
851
* @method _initialize
853
initializer: function(cfg)
856
graphic = cfg.graphic,
857
data = this.get("data");
861
this._setGraphic(graphic);
865
host._parsePathData(data);
867
this._updateHandler();
871
* Set the Graphic instance for the shape.
873
* @method _setGraphic
874
* @param {Graphic | Node | HTMLElement | String} render This param is used to determine the graphic instance. If it is a
875
* `Graphic` instance, it will be assigned to the `graphic` attribute. Otherwise, a new Graphic instance will be created
876
* and rendered into the dom element that the render represents.
879
_setGraphic: function(render)
882
if(render instanceof Y.VMLGraphic)
884
this._graphic = render;
888
graphic = new Y.VMLGraphic({
891
graphic._appendShape(this);
892
this._graphic = graphic;
893
this._appendStrokeAndFill();
898
* Appends fill and stroke nodes to the shape.
900
* @method _appendStrokeAndFill
903
_appendStrokeAndFill: function()
907
this.node.appendChild(this._strokeNode);
911
this.node.appendChild(this._fillNode);
916
* Creates the dom node for the shape.
919
* @return HTMLElement
922
createNode: function()
925
concat = this._camelCaseConcat,
928
w = this.get("width"),
929
h = this.get("height"),
934
visibility = this.get("visible") ? "visible" : "hidden",
946
type = this._type === "path" ? "shape" : this._type;
947
classString = _getClassName(SHAPE) +
949
_getClassName(concat(IMPLEMENTATION, SHAPE)) +
951
_getClassName(name) +
953
_getClassName(concat(IMPLEMENTATION, name)) +
957
stroke = this._getStrokeProps();
958
fill = this._getFillProps();
962
' xmlns="urn:schemas-microsft.com:vml" id="' +
966
'" style="behavior:url(#default#VML);display:inline-block;position:absolute;left:' +
978
if(stroke && stroke.weight && stroke.weight > 0)
980
endcap = stroke.endcap;
981
opacity = parseFloat(stroke.opacity);
982
joinstyle = stroke.joinstyle;
983
miterlimit = stroke.miterlimit;
984
dashstyle = stroke.dashstyle;
985
nodestring += ' stroked="t" strokecolor="' + stroke.color + '" strokeWeight="' + stroke.weight + 'px"';
987
strokestring = '<stroke class="vmlstroke"' +
988
' xmlns="urn:schemas-microsft.com:vml"' +
990
' style="behavior:url(#default#VML);display:inline-block;"' +
991
' opacity="' + opacity + '"';
994
strokestring += ' endcap="' + endcap + '"';
998
strokestring += ' joinstyle="' + joinstyle + '"';
1002
strokestring += ' miterlimit="' + miterlimit + '"';
1006
strokestring += ' dashstyle="' + dashstyle + '"';
1008
strokestring += '></stroke>';
1009
this._strokeNode = DOCUMENT.createElement(strokestring);
1010
nodestring += ' stroked="t"';
1014
nodestring += ' stroked="f"';
1020
fillstring = fill.node;
1021
this._fillNode = DOCUMENT.createElement(fillstring);
1025
nodestring += ' fillcolor="' + fill.color + '"';
1027
nodestring += ' filled="' + fill.filled + '"';
1032
nodestring += '</' + type + '>';
1034
node = DOCUMENT.createElement(nodestring);
1037
this._strokeFlag = false;
1038
this._fillFlag = false;
1042
* Add a class name to each node.
1045
* @param {String} className the class name to add to the node's class attribute
1047
addClass: function(className)
1049
var node = this.node;
1050
Y_DOM.addClass(node, className);
1054
* Removes a class name from each node.
1056
* @method removeClass
1057
* @param {String} className the class name to remove from the node's class attribute
1059
removeClass: function(className)
1061
var node = this.node;
1062
Y_DOM.removeClass(node, className);
1066
* Gets the current position of the node in page coordinates.
1069
* @return Array The XY position of the shape.
1073
var graphic = this._graphic,
1074
parentXY = graphic.getXY(),
1077
return [parentXY[0] + x, parentXY[1] + y];
1081
* Set the position of the shape in page coordinates, regardless of how the node is positioned.
1084
* @param {Array} Contains x & y values for new position (coordinates are page-based)
1089
var graphic = this._graphic,
1090
parentXY = graphic.getXY();
1091
this.set("x", xy[0] - parentXY[0]);
1092
this.set("y", xy[1] - parentXY[1]);
1096
* Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
1099
* @param {VMLShape | HTMLElement} needle The possible node or descendent
1100
* @return Boolean Whether or not this shape is the needle or its ancestor.
1102
contains: function(needle)
1104
var node = needle instanceof Y.Node ? needle._node : needle;
1105
return node === this.node;
1109
* Compares nodes to determine if they match.
1110
* Node instances can be compared to each other and/or HTMLElements.
1112
* @param {HTMLElement | Node} refNode The reference node to compare to the node.
1113
* @return {Boolean} True if the nodes match, false if they do not.
1115
compareTo: function(refNode) {
1116
var node = this.node;
1117
return node === refNode;
1121
* Test if the supplied node matches the supplied selector.
1124
* @param {String} selector The CSS selector to test against.
1125
* @return Boolean Wheter or not the shape matches the selector.
1127
test: function(selector)
1129
return Y_SELECTOR.test(this.node, selector);
1133
* Calculates and returns properties for setting an initial stroke.
1135
* @method _getStrokeProps
1140
_getStrokeProps: function()
1143
stroke = this.get("stroke"),
1152
if(stroke && stroke.weight && stroke.weight > 0)
1155
linecap = stroke.linecap || "flat";
1156
linejoin = stroke.linejoin || "round";
1157
if(linecap !== "round" && linecap !== "square")
1161
strokeOpacity = parseFloat(stroke.opacity);
1162
dashstyle = stroke.dashstyle || "none";
1163
stroke.color = stroke.color || "#000000";
1164
stroke.weight = stroke.weight || 1;
1165
stroke.opacity = IS_NUM(strokeOpacity) ? strokeOpacity : 1;
1166
props.stroked = true;
1167
props.color = stroke.color;
1168
props.weight = stroke.weight;
1169
props.endcap = linecap;
1170
props.opacity = stroke.opacity;
1171
if(IS_ARRAY(dashstyle))
1174
len = dashstyle.length;
1175
for(i = 0; i < len; ++i)
1178
dash[i] = val / stroke.weight;
1181
if(linejoin === "round" || linejoin === "bevel")
1183
props.joinstyle = linejoin;
1187
linejoin = parseInt(linejoin, 10);
1188
if(IS_NUM(linejoin))
1190
props.miterlimit = Math.max(linejoin, 1);
1191
props.joinstyle = "miter";
1194
props.dashstyle = dash;
1200
* Adds a stroke to the shape node.
1202
* @method _strokeChangeHandler
1205
_strokeChangeHandler: function()
1207
if(!this._strokeFlag)
1211
var node = this.node,
1212
stroke = this.get("stroke"),
1221
if(stroke && stroke.weight && stroke.weight > 0)
1223
linecap = stroke.linecap || "flat";
1224
linejoin = stroke.linejoin || "round";
1225
if(linecap !== "round" && linecap !== "square")
1229
strokeOpacity = parseFloat(stroke.opacity);
1230
dashstyle = stroke.dashstyle || "none";
1231
stroke.color = stroke.color || "#000000";
1232
stroke.weight = stroke.weight || 1;
1233
stroke.opacity = IS_NUM(strokeOpacity) ? strokeOpacity : 1;
1234
node.stroked = true;
1235
node.strokeColor = stroke.color;
1236
node.strokeWeight = stroke.weight + "px";
1237
if(!this._strokeNode)
1239
this._strokeNode = this._createGraphicNode("stroke");
1240
node.appendChild(this._strokeNode);
1242
this._strokeNode.endcap = linecap;
1243
this._strokeNode.opacity = stroke.opacity;
1244
if(IS_ARRAY(dashstyle))
1247
len = dashstyle.length;
1248
for(i = 0; i < len; ++i)
1251
dash[i] = val / stroke.weight;
1254
if(linejoin === "round" || linejoin === "bevel")
1256
this._strokeNode.joinstyle = linejoin;
1260
linejoin = parseInt(linejoin, 10);
1261
if(IS_NUM(linejoin))
1263
this._strokeNode.miterlimit = Math.max(linejoin, 1);
1264
this._strokeNode.joinstyle = "miter";
1267
this._strokeNode.dashstyle = dash;
1268
this._strokeNode.on = true;
1272
if(this._strokeNode)
1274
this._strokeNode.on = false;
1276
node.stroked = false;
1278
this._strokeFlag = false;
1282
* Calculates and returns properties for setting an initial fill.
1284
* @method _getFillProps
1289
_getFillProps: function()
1291
var fill = this.get("fill"),
1302
if(fill.type === "radial" || fill.type === "linear")
1304
fillOpacity = parseFloat(fill.opacity);
1305
fillOpacity = IS_NUM(fillOpacity) ? fillOpacity : 1;
1307
gradient = this._getGradientFill(fill);
1308
fillstring = '<fill xmlns="urn:schemas-microsft.com:vml"' +
1309
' class="vmlfill" style="behavior:url(#default#VML);display:inline-block;"' +
1310
' opacity="' + fillOpacity + '"';
1313
if(gradient.hasOwnProperty(i))
1315
fillstring += ' ' + i + '="' + gradient[i] + '"';
1318
fillstring += ' />';
1319
props.node = fillstring;
1323
fillOpacity = parseFloat(fill.opacity);
1325
props.color = fill.color;
1326
if(IS_NUM(fillOpacity))
1328
fillOpacity = Math.max(Math.min(fillOpacity, 1), 0);
1329
props.opacity = fillOpacity;
1332
props.node = '<fill xmlns="urn:schemas-microsft.com:vml"' +
1333
' class="vmlfill" style="behavior:url(#default#VML);display:inline-block;"' +
1334
' type="solid" opacity="' + fillOpacity + '"/>';
1338
props.filled = filled;
1344
* Adds a fill to the shape node.
1346
* @method _fillChangeHandler
1349
_fillChangeHandler: function()
1355
var node = this.node,
1356
fill = this.get("fill"),
1364
if(fill.type === "radial" || fill.type === "linear")
1367
gradient = this._getGradientFill(fill);
1372
if(gradient.hasOwnProperty(i))
1376
this._fillNode.colors.value = gradient[i];
1380
this._fillNode[i] = gradient[i];
1387
fillstring = '<fill xmlns="urn:schemas-microsft.com:vml"' +
1388
' class="vmlfill"' +
1389
' style="behavior:url(#default#VML);display:inline-block;"';
1392
if(gradient.hasOwnProperty(i))
1394
fillstring += ' ' + i + '="' + gradient[i] + '"';
1397
fillstring += ' />';
1398
this._fillNode = DOCUMENT.createElement(fillstring);
1399
node.appendChild(this._fillNode);
1404
node.fillcolor = fill.color;
1405
fillOpacity = parseFloat(fill.opacity);
1407
if(IS_NUM(fillOpacity) && fillOpacity < 1)
1409
fill.opacity = fillOpacity;
1412
if(this._fillNode.getAttribute("type") !== "solid")
1414
this._fillNode.type = "solid";
1416
this._fillNode.opacity = fillOpacity;
1420
fillstring = '<fill xmlns="urn:schemas-microsft.com:vml"' +
1421
' class="vmlfill"' +
1422
' style="behavior:url(#default#VML);display:inline-block;"' +
1424
' opacity="' + fillOpacity + '"' +
1426
this._fillNode = DOCUMENT.createElement(fillstring);
1427
node.appendChild(this._fillNode);
1430
else if(this._fillNode)
1432
this._fillNode.opacity = 1;
1433
this._fillNode.type = "solid";
1437
node.filled = filled;
1438
this._fillFlag = false;
1441
//not used. remove next release.
1442
_updateFillNode: function(node)
1446
this._fillNode = this._createGraphicNode("fill");
1447
node.appendChild(this._fillNode);
1452
* Calculates and returns an object containing gradient properties for a fill node.
1454
* @method _getGradientFill
1455
* @param {Object} fill Object containing fill properties.
1459
_getGradientFill: function(fill)
1461
var gradientProps = {},
1465
w = this.get("width"),
1466
h = this.get("height"),
1482
rotation = fill.rotation || 0;
1483
if(type === "linear")
1487
rotation = Math.abs(rotation - 270);
1489
else if(rotation < 360)
1491
rotation = 270 + (360 - rotation);
1497
gradientProps.type = "gradient";//"gradientunscaled";
1498
gradientProps.angle = rotation;
1500
else if(type === "radial")
1502
gradientBoxWidth = w * (r * 2);
1503
gradientBoxHeight = h * (r * 2);
1504
fx = r * 2 * (fx - 0.5);
1505
fy = r * 2 * (fy - 0.5);
1508
gradientProps.focussize = (gradientBoxWidth/w)/10 + "% " + (gradientBoxHeight/h)/10 + "%";
1509
gradientProps.alignshape = false;
1510
gradientProps.type = "gradientradial";
1511
gradientProps.focus = "100%";
1512
gradientProps.focusposition = Math.round(fx * 100) + "% " + Math.round(fy * 100) + "%";
1514
for(i = 0;i < len; ++i) {
1517
opacity = stop.opacity;
1518
opacity = isNumber(opacity) ? opacity : 1;
1519
pct = stop.offset || i/(len-1);
1521
pct = Math.round(100 * pct) + "%";
1522
oi = i > 0 ? i + 1 : "";
1523
gradientProps["opacity" + oi] = opacity + "";
1524
colorstring += ", " + pct + " " + color;
1526
if(parseFloat(pct) < 100)
1528
colorstring += ", 100% " + color;
1530
gradientProps.colors = colorstring.substr(2);
1531
return gradientProps;
1535
* Adds a transform to the shape.
1537
* @method _addTransform
1538
* @param {String} type The transform being applied.
1539
* @param {Array} args The arguments for the transform.
1542
_addTransform: function(type, args)
1544
args = Y.Array(args);
1545
this._transform = Y_LANG.trim(this._transform + " " + type + "(" + args.join(", ") + ")");
1547
this._transforms.push(args);
1548
if(this.initialized)
1550
this._updateTransform();
1555
* Applies all transforms.
1557
* @method _updateTransform
1560
_updateTransform: function()
1562
var node = this.node,
1570
matrix = this.matrix,
1571
normalizedMatrix = this._normalizedMatrix,
1572
isPathShape = this instanceof Y.VMLPath,
1574
len = this._transforms.length;
1575
if(this._transforms && this._transforms.length > 0)
1577
transformOrigin = this.get("transformOrigin");
1581
normalizedMatrix.translate(this._left, this._top);
1583
//vml skew matrix transformOrigin ranges from -0.5 to 0.5.
1584
//subtract 0.5 from values
1585
tx = transformOrigin[0] - 0.5;
1586
ty = transformOrigin[1] - 0.5;
1588
//ensure the values are within the appropriate range to avoid errors
1589
tx = Math.max(-0.5, Math.min(0.5, tx));
1590
ty = Math.max(-0.5, Math.min(0.5, ty));
1591
for(i = 0; i < len; ++i)
1593
key = this._transforms[i].shift();
1596
normalizedMatrix[key].apply(normalizedMatrix, this._transforms[i]);
1597
matrix[key].apply(matrix, this._transforms[i]);
1602
normalizedMatrix.translate(-this._left, -this._top);
1604
transform = normalizedMatrix.a + "," +
1605
normalizedMatrix.c + "," +
1606
normalizedMatrix.b + "," +
1607
normalizedMatrix.d + "," +
1611
this._graphic.addToRedrawQueue(this);
1616
this._skew = DOCUMENT.createElement(
1617
'<skew class="vmlskew"' +
1618
' xmlns="urn:schemas-microsft.com:vml"' +
1620
' style="behavior:url(#default#VML);display:inline-block;"' +
1623
this.node.appendChild(this._skew);
1625
this._skew.matrix = transform;
1626
this._skew.on = true;
1627
//this._skew.offset = this._getSkewOffsetValue(normalizedMatrix.dx) + "px, " + this._getSkewOffsetValue(normalizedMatrix.dy) + "px";
1628
this._skew.origin = tx + ", " + ty;
1630
if(this._type !== "path")
1632
this._transforms = [];
1634
//add the translate to the x and y coordinates
1635
node.style.left = (x + this._getSkewOffsetValue(normalizedMatrix.dx)) + "px";
1636
node.style.top = (y + this._getSkewOffsetValue(normalizedMatrix.dy)) + "px";
1640
* Normalizes the skew offset values between -32767 and 32767.
1642
* @method _getSkewOffsetValue
1643
* @param {Number} val The value to normalize
1647
_getSkewOffsetValue: function(val)
1649
var sign = Y.MatrixUtil.sign(val),
1650
absVal = Math.abs(val);
1651
val = Math.min(absVal, 32767) * sign;
1656
* Storage for translateX
1658
* @property _translateX
1665
* Storage for translateY
1667
* @property _translateY
1674
* Storage for the transform attribute.
1676
* @property _transform
1683
* Specifies a 2d translation.
1686
* @param {Number} x The value to translate on the x-axis.
1687
* @param {Number} y The value to translate on the y-axis.
1689
translate: function(x, y)
1691
this._translateX += x;
1692
this._translateY += y;
1693
this._addTransform("translate", arguments);
1697
* Translates the shape along the x-axis. When translating x and y coordinates,
1698
* use the `translate` method.
1700
* @method translateX
1701
* @param {Number} x The value to translate.
1703
translateX: function(x)
1705
this._translateX += x;
1706
this._addTransform("translateX", arguments);
1710
* Performs a translate on the y-coordinate. When translating x and y coordinates,
1711
* use the `translate` method.
1713
* @method translateY
1714
* @param {Number} y The value to translate.
1716
translateY: function(y)
1718
this._translateY += y;
1719
this._addTransform("translateY", arguments);
1723
* Skews the shape around the x-axis and y-axis.
1726
* @param {Number} x The value to skew on the x-axis.
1727
* @param {Number} y The value to skew on the y-axis.
1731
this._addTransform("skew", arguments);
1735
* Skews the shape around the x-axis.
1738
* @param {Number} x x-coordinate
1742
this._addTransform("skewX", arguments);
1746
* Skews the shape around the y-axis.
1749
* @param {Number} y y-coordinate
1753
this._addTransform("skewY", arguments);
1757
* Rotates the shape clockwise around it transformOrigin.
1760
* @param {Number} deg The degree of the rotation.
1764
this._addTransform("rotate", arguments);
1768
* Specifies a 2d scaling operation.
1771
* @param {Number} val
1775
this._addTransform("scale", arguments);
1779
* Overrides default `on` method. Checks to see if its a dom interaction event. If so,
1780
* return an event attached to the `node` element. If not, return the normal functionality.
1783
* @param {String} type event type
1784
* @param {Object} callback function
1787
on: function(type, fn)
1789
if(Y.Node.DOM_EVENTS[type])
1791
return Y.on(type, fn, "#" + this.get("id"));
1793
return Y.on.apply(this, arguments);
1807
* Updates `Shape` based on attribute changes.
1809
* @method _updateHandler
1812
_updateHandler: function()
1816
host._fillChangeHandler();
1817
host._strokeChangeHandler();
1818
node.style.width = this.get("width") + "px";
1819
node.style.height = this.get("height") + "px";
1821
host._updateTransform();
1825
* Creates a graphic node
1827
* @method _createGraphicNode
1828
* @param {String} type node type to create
1829
* @return HTMLElement
1832
_createGraphicNode: function(type)
1834
type = type || this._type;
1835
return DOCUMENT.createElement(
1837
' xmlns="urn:schemas-microsft.com:vml"' +
1838
' style="behavior:url(#default#VML);display:inline-block;"' +
1839
' class="vml' + type + '"' +
1845
* Value function for fill attribute
1848
* @method _getDefaultFill
1851
_getDefaultFill: function() {
1864
* Value function for stroke attribute
1867
* @method _getDefaultStroke
1870
_getDefaultStroke: function()
1881
* Sets the value of an attribute.
1884
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
1885
* be passed in to set multiple attributes at once.
1886
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
1892
AttributeLite.prototype.set.apply(host, arguments);
1893
if(host.initialized)
1895
host._updateHandler();
1900
* Returns the bounds for a shape.
1902
* Calculates the a new bounding box from the original corner coordinates (base on size and position) and the transform matrix.
1903
* The calculated bounding box is used by the graphic instance to calculate its viewBox.
1908
getBounds: function()
1910
var isPathShape = this instanceof Y.VMLPath,
1911
w = this.get("width"),
1912
h = this.get("height"),
1919
w = this._right - this._left;
1920
h = this._bottom - this._top;
1922
return this._getContentRect(w, h, x, y);
1926
* Calculates the bounding box for the shape.
1928
* @method _getContentRect
1929
* @param {Number} w width of the shape
1930
* @param {Number} h height of the shape
1931
* @param {Number} x x-coordinate of the shape
1932
* @param {Number} y y-coordinate of the shape
1935
_getContentRect: function(w, h, x, y)
1937
var transformOrigin = this.get("transformOrigin"),
1938
transformX = transformOrigin[0] * w,
1939
transformY = transformOrigin[1] * h,
1940
transforms = this.matrix.getTransformArray(this.get("transform")),
1941
matrix = new Y.Matrix(),
1943
len = transforms.length,
1947
isPathShape = this instanceof Y.VMLPath;
1950
matrix.translate(this._left, this._top);
1952
transformX = !isNaN(transformX) ? transformX : 0;
1953
transformY = !isNaN(transformY) ? transformY : 0;
1954
matrix.translate(transformX, transformY);
1955
for(i = 0; i < len; i = i + 1)
1957
transform = transforms[i];
1958
key = transform.shift();
1961
matrix[key].apply(matrix, transform);
1964
matrix.translate(-transformX, -transformY);
1967
matrix.translate(-this._left, -this._top);
1969
contentRect = matrix.getContentRect(w, h, x, y);
1974
* Places the shape above all other shapes.
1980
var graphic = this.get("graphic");
1983
graphic._toFront(this);
1988
* Places the shape underneath all other shapes.
1994
var graphic = this.get("graphic");
1997
graphic._toBack(this);
2002
* Parses path data string and call mapped methods.
2004
* @method _parsePathData
2005
* @param {String} val The path data
2008
_parsePathData: function(val)
2013
commandArray = Y.Lang.trim(val.match(SPLITPATHPATTERN)),
2017
symbolToMethod = this._pathSymbolToMethod;
2021
len = commandArray.length || 0;
2022
for(i = 0; i < len; i = i + 1)
2024
str = commandArray[i];
2025
methodSymbol = str.substr(0, 1);
2026
args = str.substr(1).match(SPLITARGSPATTERN);
2027
method = symbolToMethod[methodSymbol];
2032
this[method].apply(this, args);
2036
this[method].apply(this);
2051
var graphic = this.get("graphic");
2054
graphic.removeShape(this);
2063
* Implementation for shape destruction
2068
_destroy: function()
2074
this.node.removeChild(this._fillNode);
2075
this._fillNode = null;
2077
if(this._strokeNode)
2079
this.node.removeChild(this._strokeNode);
2080
this._strokeNode = null;
2082
Y.Event.purgeElement(this.node, true);
2083
if(this.node.parentNode)
2085
this.node.parentNode.removeChild(this.node);
2090
}, Y.VMLDrawing.prototype));
2094
* An array of x, y values which indicates the transformOrigin in which to rotate the shape. Valid values range between 0 and 1 representing a
2095
* fraction of the shape's corresponding bounding box dimension. The default value is [0.5, 0.5].
2097
* @config transformOrigin
2108
* <p>A string containing, in order, transform operations applied to the shape instance. The `transform` string can contain the following values:
2111
* <dt>rotate</dt><dd>Rotates the shape clockwise around it transformOrigin.</dd>
2112
* <dt>translate</dt><dd>Specifies a 2d translation.</dd>
2113
* <dt>skew</dt><dd>Skews the shape around the x-axis and y-axis.</dd>
2114
* <dt>scale</dt><dd>Specifies a 2d scaling operation.</dd>
2115
* <dt>translateX</dt><dd>Translates the shape along the x-axis.</dd>
2116
* <dt>translateY</dt><dd>Translates the shape along the y-axis.</dd>
2117
* <dt>skewX</dt><dd>Skews the shape around the x-axis.</dd>
2118
* <dt>skewY</dt><dd>Skews the shape around the y-axis.</dd>
2119
* <dt>matrix</dt><dd>Specifies a 2D transformation matrix comprised of the specified six values.</dd>
2122
* <p>Applying transforms through the transform attribute will reset the transform matrix and apply a new transform. The shape class also contains
2123
* corresponding methods for each transform that will apply the transform to the current matrix. The below code illustrates how you might use the
2124
* `transform` attribute to instantiate a recangle with a rotation of 45 degrees.</p>
2125
var myRect = new Y.Rect({
2129
transform: "rotate(45)"
2131
* <p>The code below would apply `translate` and `rotate` to an existing shape.</p>
2133
myRect.set("transform", "translate(40, 50) rotate(45)");
2138
setter: function(val)
2144
this._normalizedMatrix.init();
2145
this._transforms = this.matrix.getTransformArray(val);
2146
len = this._transforms.length;
2147
for(i = 0;i < len; ++i)
2149
transform = this._transforms[i];
2151
this._transform = val;
2157
return this._transform;
2162
* Indicates the x position of shape.
2172
* Indicates the y position of shape.
2182
* Unique id for class instance.
2193
setter: function(val)
2195
var node = this.node;
2198
node.setAttribute("id", val);
2221
* Indicates whether the shape is visible.
2229
setter: function(val){
2230
var node = this.node,
2231
visibility = val ? "visible" : "hidden";
2234
node.style.visibility = visibility;
2241
* Contains information about the fill of the shape.
2243
* <dt>color</dt><dd>The color of the fill.</dd>
2244
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the fill. The default value is 1.</dd>
2245
* <dt>type</dt><dd>Type of fill.
2247
* <dt>solid</dt><dd>Solid single color fill. (default)</dd>
2248
* <dt>linear</dt><dd>Linear gradient fill.</dd>
2249
* <dt>radial</dt><dd>Radial gradient fill.</dd>
2253
* <p>If a `linear` or `radial` is specified as the fill type. The following additional property is used:
2255
* <dt>stops</dt><dd>An array of objects containing the following properties:
2257
* <dt>color</dt><dd>The color of the stop.</dd>
2258
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stop. The default value is 1.
2259
* Note: No effect for IE 6 - 8</dd>
2260
* <dt>offset</dt><dd>Number between 0 and 1 indicating where the color stop is positioned.</dd>
2263
* <p>Linear gradients also have the following property:</p>
2264
* <dt>rotation</dt><dd>Linear gradients flow left to right by default. The rotation property allows you to change the
2265
* flow by rotation. (e.g. A rotation of 180 would make the gradient pain from right to left.)</dd>
2266
* <p>Radial gradients have the following additional properties:</p>
2267
* <dt>r</dt><dd>Radius of the gradient circle.</dd>
2268
* <dt>fx</dt><dd>Focal point x-coordinate of the gradient.</dd>
2269
* <dt>fy</dt><dd>Focal point y-coordinate of the gradient.</dd>
2271
* <p>The corresponding `SVGShape` class implements the following additional properties.</p>
2274
* <p>The x-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
2275
* <p><strong>Note: </strong>Currently, this property is not implemented for corresponding `CanvasShape` and
2276
* `VMLShape` classes which are used on Android or IE 6 - 8.</p>
2279
* <p>The y-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
2280
* <p><strong>Note: </strong>Currently, this property is not implemented for corresponding `CanvasShape` and `VMLShape`
2281
* classes which are used on Android or IE 6 - 8.</p>
2284
* <p>These properties are not currently implemented in `CanvasShape` or `VMLShape`.</p>
2290
valueFn: "_getDefaultFill",
2292
setter: function(val)
2296
tmpl = this.get("fill") || this._getDefaultFill();
2300
//ensure, fill type is solid if color is explicitly passed.
2301
if(val.hasOwnProperty("color"))
2307
if(val.hasOwnProperty(i))
2314
if(fill && fill.color)
2316
if(fill.color === undefined || fill.color === "none")
2322
if(fill.color.toLowerCase().indexOf("rgba") > -1)
2324
fill.opacity = Y.Color._getAlpha(fill.color);
2325
fill.color = Y.Color.toHex(fill.color);
2329
this._fillFlag = true;
2335
* Contains information about the stroke of the shape.
2337
* <dt>color</dt><dd>The color of the stroke.</dd>
2338
* <dt>weight</dt><dd>Number that indicates the width of the stroke.</dd>
2339
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stroke. The default value is 1.</dd>
2340
* <dt>dashstyle</dt>Indicates whether to draw a dashed stroke. When set to "none", a solid stroke is drawn. When set
2341
* to an array, the first index indicates the length of the dash. The second index indicates the length of gap.
2342
* <dt>linecap</dt><dd>Specifies the linecap for the stroke. The following values can be specified:
2344
* <dt>butt (default)</dt><dd>Specifies a butt linecap.</dd>
2345
* <dt>square</dt><dd>Specifies a sqare linecap.</dd>
2346
* <dt>round</dt><dd>Specifies a round linecap.</dd>
2349
* <dt>linejoin</dt><dd>Specifies a linejoin for the stroke. The following values can be specified:
2351
* <dt>round (default)</dt><dd>Specifies that the linejoin will be round.</dd>
2352
* <dt>bevel</dt><dd>Specifies a bevel for the linejoin.</dd>
2353
* <dt>miter limit</dt><dd>An integer specifying the miter limit of a miter linejoin. If you want to specify a linejoin
2354
* of miter, you simply specify the limit as opposed to having separate miter and miter limit values.</dd>
2363
valueFn: "_getDefaultStroke",
2365
setter: function(val)
2370
tmpl = this.get("stroke") || this._getDefaultStroke();
2373
if(val.hasOwnProperty("weight"))
2375
wt = parseInt(val.weight, 10);
2383
if(val.hasOwnProperty(i))
2389
if(tmpl.color && tmpl.color.toLowerCase().indexOf("rgba") > -1)
2391
tmpl.opacity = Y.Color._getAlpha(tmpl.color);
2392
tmpl.color = Y.Color.toHex(tmpl.color);
2395
this._strokeFlag = true;
2400
//Not used. Remove in future.
2405
// Only implemented in SVG
2406
// Determines whether the instance will receive mouse events.
2408
// @config pointerEvents
2412
value: "visiblePainted"
2416
* Dom node for the shape.
2432
* Represents an SVG Path string. This will be parsed and added to shape's API to represent the SVG data across all
2433
* implementations. Note that when using VML or SVG implementations, part of this content will be added to the DOM using
2434
* respective VML/SVG attributes. If your content comes from an untrusted source, you will need to ensure that no
2435
* malicious code is included in that content.
2441
setter: function(val)
2443
if(this.get("node"))
2445
this._parsePathData(val);
2452
* Reference to the container Graphic.
2462
return this._graphic;
2466
Y.VMLShape = VMLShape;
2468
* <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Path.html">`Path`</a> class.
2469
* `VMLPath` is not intended to be used directly. Instead, use the <a href="Path.html">`Path`</a> class.
2470
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
2471
* capabilities, the <a href="Path.html">`Path`</a> class will point to the `VMLPath` class.
2477
VMLPath = function()
2479
VMLPath.superclass.constructor.apply(this, arguments);
2482
VMLPath.NAME = "path";
2483
Y.extend(VMLPath, Y.VMLShape);
2484
VMLPath.ATTRS = Y.merge(Y.VMLShape.ATTRS, {
2486
* Indicates the width of the shape
2494
var val = Math.max(this._right - this._left, 0);
2500
* Indicates the height of the shape
2508
return Math.max(this._bottom - this._top, 0);
2513
* Indicates the path used for the node.
2528
Y.VMLPath = VMLPath;
2530
* <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Rect.html">`Rect`</a> class.
2531
* `VMLRect` is not intended to be used directly. Instead, use the <a href="Rect.html">`Rect`</a> class.
2532
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
2533
* capabilities, the <a href="Rect.html">`Rect`</a> class will point to the `VMLRect` class.
2539
VMLRect = function()
2541
VMLRect.superclass.constructor.apply(this, arguments);
2543
VMLRect.NAME = "rect";
2544
Y.extend(VMLRect, Y.VMLShape, {
2546
* Indicates the type of shape
2554
VMLRect.ATTRS = Y.VMLShape.ATTRS;
2555
Y.VMLRect = VMLRect;
2557
* <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Ellipse.html">`Ellipse`</a> class.
2558
* `VMLEllipse` is not intended to be used directly. Instead, use the <a href="Ellipse.html">`Ellipse`</a> class.
2559
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
2560
* capabilities, the <a href="Ellipse.html">`Ellipse`</a> class will point to the `VMLEllipse` class.
2566
VMLEllipse = function()
2568
VMLEllipse.superclass.constructor.apply(this, arguments);
2571
VMLEllipse.NAME = "ellipse";
2573
Y.extend(VMLEllipse, Y.VMLShape, {
2575
* Indicates the type of shape
2583
VMLEllipse.ATTRS = Y.merge(Y.VMLShape.ATTRS, {
2585
* Horizontal radius for the ellipse.
2595
var val = this.get("width");
2596
val = Math.round((val/2) * 100)/100;
2600
setter: function(val)
2603
this.set("width", w);
2609
* Vertical radius for the ellipse.
2620
var val = this.get("height");
2621
val = Math.round((val/2) * 100)/100;
2625
setter: function(val)
2628
this.set("height", h);
2633
Y.VMLEllipse = VMLEllipse;
2635
* <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Circle.html">`Circle`</a> class.
2636
* `VMLCircle` is not intended to be used directly. Instead, use the <a href="Circle.html">`Circle`</a> class.
2637
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
2638
* capabilities, the <a href="Circle.html">`Circle`</a> class will point to the `VMLCircle` class.
2644
VMLCircle = function()
2646
VMLCircle.superclass.constructor.apply(this, arguments);
2649
VMLCircle.NAME = "circle";
2651
Y.extend(VMLCircle, VMLShape, {
2653
* Indicates the type of shape
2662
VMLCircle.ATTRS = Y.merge(VMLShape.ATTRS, {
2664
* Radius for the circle.
2676
* Indicates the width of the shape
2682
setter: function(val)
2684
this.set("radius", val/2);
2690
var radius = this.get("radius"),
2691
val = radius && radius > 0 ? radius * 2 : 0;
2697
* Indicates the height of the shape
2703
setter: function(val)
2705
this.set("radius", val/2);
2711
var radius = this.get("radius"),
2712
val = radius && radius > 0 ? radius * 2 : 0;
2717
Y.VMLCircle = VMLCircle;
2722
* @class VMLPieSlice
2725
VMLPieSlice = function()
2727
VMLPieSlice.superclass.constructor.apply(this, arguments);
2729
VMLPieSlice.NAME = "vmlPieSlice";
2730
Y.extend(VMLPieSlice, Y.VMLShape, Y.mix({
2732
* Indicates the type of shape
2741
* Change event listener
2744
* @method _updateHandler
2748
var x = this.get("cx"),
2750
startAngle = this.get("startAngle"),
2751
arc = this.get("arc"),
2752
radius = this.get("radius");
2754
this.drawWedge(x, y, startAngle, arc, radius);
2757
}, Y.VMLDrawing.prototype));
2758
VMLPieSlice.ATTRS = Y.mix({
2767
* Starting angle in relation to a circle in which to begin the pie slice drawing.
2769
* @config startAngle
2787
* Radius of the circle in which the pie slice is drawn
2795
}, Y.VMLShape.ATTRS);
2796
Y.VMLPieSlice = VMLPieSlice;
2798
* <a href="http://www.w3.org/TR/NOTE-VML">VML</a> implementation of the <a href="Graphic.html">`Graphic`</a> class.
2799
* `VMLGraphic` is not intended to be used directly. Instead, use the <a href="Graphic.html">`Graphic`</a> class.
2800
* If the browser lacks <a href="http://www.w3.org/TR/SVG/">SVG</a> and <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a>
2801
* capabilities, the <a href="Graphic.html">`Graphic`</a> class will point to the `VMLGraphic` class.
2807
VMLGraphic = function() {
2808
VMLGraphic.superclass.constructor.apply(this, arguments);
2811
VMLGraphic.NAME = "vmlGraphic";
2813
VMLGraphic.ATTRS = {
2815
* Whether or not to render the `Graphic` automatically after to a specified parent node after init. This can be a Node
2816
* instance or a CSS selector string.
2819
* @type Node | String
2824
* Unique id for class instance.
2835
setter: function(val)
2837
var node = this._node;
2840
node.setAttribute("id", val);
2847
* Key value pairs in which a shape instance is associated with its id.
2858
return this._shapes;
2863
* Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
2865
* @config contentBounds
2873
return this._contentBounds;
2878
* The html element that represents to coordinate system of the Graphic instance.
2893
* Indicates the width of the `Graphic`.
2899
setter: function(val)
2903
this._node.style.width = val + "px";
2910
* Indicates the height of the `Graphic`.
2916
setter: function(val)
2920
this._node.style.height = val + "px";
2927
* Determines the sizing of the Graphic.
2930
* <dt>sizeContentToGraphic</dt><dd>The Graphic's width and height attributes are, either explicitly set through the
2931
* <code>width</code> and <code>height</code> attributes or are determined by the dimensions of the parent element. The
2932
* content contained in the Graphic will be sized to fit with in the Graphic instance's dimensions. When using this
2933
* setting, the <code>preserveAspectRatio</code> attribute will determine how the contents are sized.</dd>
2934
* <dt>sizeGraphicToContent</dt><dd>(Also accepts a value of true) The Graphic's width and height are determined by the
2935
* size and positioning of the content.</dd>
2936
* <dt>false</dt><dd>The Graphic's width and height attributes are, either explicitly set through the <code>width</code>
2937
* and <code>height</code> attributes or are determined by the dimensions of the parent element. The contents of the
2938
* Graphic instance are not affected by this setting.</dd>
2943
* @type Boolean | String
2951
* Determines how content is sized when <code>autoSize</code> is set to <code>sizeContentToGraphic</code>.
2954
* <dt>none<dt><dd>Do not force uniform scaling. Scale the graphic content of the given element non-uniformly if necessary
2955
* such that the element's bounding box exactly matches the viewport rectangle.</dd>
2956
* <dt>xMinYMin</dt><dd>Force uniform scaling position along the top left of the Graphic's node.</dd>
2957
* <dt>xMidYMin</dt><dd>Force uniform scaling horizontally centered and positioned at the top of the Graphic's node.<dd>
2958
* <dt>xMaxYMin</dt><dd>Force uniform scaling positioned horizontally from the right and vertically from the top.</dd>
2959
* <dt>xMinYMid</dt>Force uniform scaling positioned horizontally from the left and vertically centered.</dd>
2960
* <dt>xMidYMid (the default)</dt><dd>Force uniform scaling with the content centered.</dd>
2961
* <dt>xMaxYMid</dt><dd>Force uniform scaling positioned horizontally from the right and vertically centered.</dd>
2962
* <dt>xMinYMax</dt><dd>Force uniform scaling positioned horizontally from the left and vertically from the bottom.</dd>
2963
* <dt>xMidYMax</dt><dd>Force uniform scaling horizontally centered and position vertically from the bottom.</dd>
2964
* <dt>xMaxYMax</dt><dd>Force uniform scaling positioned horizontally from the right and vertically from the bottom.</dd>
2967
* @config preserveAspectRatio
2971
preserveAspectRatio: {
2976
* The contentBounds will resize to greater values but not values. (for performance)
2977
* When resizing the contentBounds down is desirable, set the resizeDown value to true.
2979
* @config resizeDown
2987
* Indicates the x-coordinate for the instance.
2998
setter: function(val)
3003
this._node.style.left = val + "px";
3010
* Indicates the y-coordinate for the instance.
3021
setter: function(val)
3026
this._node.style.top = val + "px";
3033
* Indicates whether or not the instance will automatically redraw after a change is made to a shape.
3034
* This property will get set to false when batching operations.
3048
setter: function(val)
3050
this._toggleVisible(val);
3056
Y.extend(VMLGraphic, Y.GraphicBase, {
3058
* Sets the value of an attribute.
3061
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
3062
* be passed in to set multiple attributes at once.
3063
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
3069
attr = arguments[0],
3073
preserveAspectRatio: true,
3077
forceRedraw = false;
3078
AttributeLite.prototype.set.apply(host, arguments);
3079
if(host._state.autoDraw === true && Y.Object.size(this._shapes) > 0)
3081
if(Y_LANG.isString && redrawAttrs[attr])
3085
else if(Y_LANG.isObject(attr))
3087
for(key in redrawAttrs)
3089
if(redrawAttrs.hasOwnProperty(key) && attr[key])
3104
* Storage for `x` attribute.
3113
* Storage for `y` attribute.
3122
* Gets the current position of the graphic instance in page coordinates.
3125
* @return Array The XY position of the shape.
3129
var node = this.parentNode,
3135
xy = Y.DOM.getXY(node);
3141
xy = Y.DOM._getOffset(this._node);
3147
* Initializes the class.
3149
* @method initializer
3152
initializer: function() {
3153
var render = this.get("render"),
3154
visibility = this.get("visible") ? "visible" : "hidden";
3156
this._contentBounds = {
3162
this._node = this._createGraphic();
3163
this._node.style.left = this.get("x") + "px";
3164
this._node.style.top = this.get("y") + "px";
3165
this._node.style.visibility = visibility;
3166
this._node.setAttribute("id", this.get("id"));
3169
this.render(render);
3174
* Adds the graphics node to the dom.
3177
* @param {HTMLElement} parentNode node in which to render the graphics node into.
3179
render: function(render) {
3180
var parentNode = render || DOCUMENT.body,
3184
if(render instanceof Y.Node)
3186
parentNode = render._node;
3188
else if(Y.Lang.isString(render))
3190
parentNode = Y.Selector.query(render, DOCUMENT.body, true);
3192
w = this.get("width") || parseInt(Y.DOM.getComputedStyle(parentNode, "width"), 10);
3193
h = this.get("height") || parseInt(Y.DOM.getComputedStyle(parentNode, "height"), 10);
3194
parentNode.appendChild(node);
3195
this.parentNode = parentNode;
3196
this.set("width", w);
3197
this.set("height", h);
3202
* Removes all nodes.
3208
this.removeAllShapes();
3211
this._removeChildren(this._node);
3212
if(this._node.parentNode)
3214
this._node.parentNode.removeChild(this._node);
3221
* Generates a shape instance by type.
3224
* @param {Object} cfg attributes for the shape
3227
addShape: function(cfg)
3230
if(!this.get("visible"))
3232
cfg.visible = false;
3234
var ShapeClass = this._getShapeClass(cfg.type),
3235
shape = new ShapeClass(cfg);
3236
this._appendShape(shape);
3237
shape._appendStrokeAndFill();
3242
* Adds a shape instance to the graphic instance.
3244
* @method _appendShape
3245
* @param {Shape} shape The shape instance to be added to the graphic.
3248
_appendShape: function(shape)
3250
var node = shape.node,
3251
parentNode = this._frag || this._node;
3252
if(this.get("autoDraw") || this.get("autoSize") === "sizeContentToGraphic")
3254
parentNode.appendChild(node);
3258
this._getDocFrag().appendChild(node);
3263
* Removes a shape instance from from the graphic instance.
3265
* @method removeShape
3266
* @param {Shape|String} shape The instance or id of the shape to be removed.
3268
removeShape: function(shape)
3270
if(!(shape instanceof VMLShape))
3272
if(Y_LANG.isString(shape))
3274
shape = this._shapes[shape];
3277
if(shape && (shape instanceof VMLShape))
3280
this._shapes[shape.get("id")] = null;
3281
delete this._shapes[shape.get("id")];
3283
if(this.get("autoDraw"))
3290
* Removes all shape instances from the dom.
3292
* @method removeAllShapes
3294
removeAllShapes: function()
3296
var shapes = this._shapes,
3300
if(shapes.hasOwnProperty(i))
3302
shapes[i].destroy();
3309
* Removes all child nodes.
3311
* @method _removeChildren
3315
_removeChildren: function(node)
3317
if(node.hasChildNodes())
3320
while(node.firstChild)
3322
child = node.firstChild;
3323
this._removeChildren(child);
3324
node.removeChild(child);
3330
* Clears the graphics object.
3335
this.removeAllShapes();
3336
this._removeChildren(this._node);
3340
* Toggles visibility
3342
* @method _toggleVisible
3343
* @param {Boolean} val indicates visibilitye
3346
_toggleVisible: function(val)
3349
shapes = this._shapes,
3350
visibility = val ? "visible" : "hidden";
3355
if(shapes.hasOwnProperty(i))
3357
shapes[i].set("visible", val);
3363
this._node.style.visibility = visibility;
3367
this._node.style.visibility = visibility;
3372
* Sets the size of the graphics object.
3375
* @param w {Number} width to set for the instance.
3376
* @param h {Number} height to set for the instance.
3378
setSize: function(w, h) {
3381
this._node.style.width = w + 'px';
3382
this._node.style.height = h + 'px';
3386
* Sets the positon of the graphics object.
3388
* @method setPosition
3389
* @param {Number} x x-coordinate for the object.
3390
* @param {Number} y y-coordinate for the object.
3392
setPosition: function(x, y)
3396
this._node.style.left = x + "px";
3397
this._node.style.top = y + "px";
3401
* Creates a group element
3403
* @method _createGraphic
3406
_createGraphic: function() {
3407
var group = DOCUMENT.createElement(
3408
'<group xmlns="urn:schemas-microsft.com:vml"' +
3409
' style="behavior:url(#default#VML);padding:0px 0px 0px 0px;display:block;position:absolute;top:0px;left:0px;zoom:1;"' +
3416
* Creates a graphic node
3418
* @method _createGraphicNode
3419
* @param {String} type node type to create
3420
* @param {String} pe specified pointer-events value
3421
* @return HTMLElement
3424
_createGraphicNode: function(type)
3426
return DOCUMENT.createElement(
3429
' xmlns="urn:schemas-microsft.com:vml"' +
3430
' style="behavior:url(#default#VML);display:inline-block;zoom:1;"' +
3437
* Returns a shape based on the id of its dom node.
3439
* @method getShapeById
3440
* @param {String} id Dom id of the shape's node attribute.
3443
getShapeById: function(id)
3445
return this._shapes[id];
3449
* Returns a shape class. Used by `addShape`.
3451
* @method _getShapeClass
3452
* @param {Shape | String} val Indicates which shape class.
3456
_getShapeClass: function(val)
3458
var shape = this._shapeClass[val];
3467
* Look up for shape classes. Used by `addShape` to retrieve a class for instantiation.
3469
* @property _shapeClass
3474
circle: Y.VMLCircle,
3477
ellipse: Y.VMLEllipse,
3478
pieslice: Y.VMLPieSlice
3482
* Allows for creating multiple shapes in order to batch appending and redraw operations.
3485
* @param {Function} method Method to execute.
3487
batch: function(method)
3489
var autoDraw = this.get("autoDraw");
3490
this.set("autoDraw", false);
3492
this.set("autoDraw", autoDraw);
3496
* Returns a document fragment to for attaching shapes.
3498
* @method _getDocFrag
3499
* @return DocumentFragment
3502
_getDocFrag: function()
3506
this._frag = DOCUMENT.createDocumentFragment();
3512
* Adds a shape to the redraw queue and calculates the contentBounds.
3514
* @method addToRedrawQueue
3515
* @param shape {VMLShape}
3518
addToRedrawQueue: function(shape)
3522
this._shapes[shape.get("id")] = shape;
3523
if(!this.get("resizeDown"))
3525
shapeBox = shape.getBounds();
3526
box = this._contentBounds;
3527
box.left = box.left < shapeBox.left ? box.left : shapeBox.left;
3528
box.top = box.top < shapeBox.top ? box.top : shapeBox.top;
3529
box.right = box.right > shapeBox.right ? box.right : shapeBox.right;
3530
box.bottom = box.bottom > shapeBox.bottom ? box.bottom : shapeBox.bottom;
3531
box.width = box.right - box.left;
3532
box.height = box.bottom - box.top;
3533
this._contentBounds = box;
3535
if(this.get("autoDraw"))
3542
* Redraws all shapes.
3549
var autoSize = this.get("autoSize"),
3550
preserveAspectRatio,
3551
node = this.parentNode,
3552
nodeWidth = parseFloat(Y.DOM.getComputedStyle(node, "width")),
3553
nodeHeight = parseFloat(Y.DOM.getComputedStyle(node, "height")),
3556
box = this.get("resizeDown") ? this._getUpdatedContentBounds() : this._contentBounds,
3560
bottom = box.bottom,
3561
contentWidth = right - left,
3562
contentHeight = bottom - top,
3568
visible = this.get("visible");
3569
this._node.style.visibility = "hidden";
3572
if(autoSize === "sizeContentToGraphic")
3574
preserveAspectRatio = this.get("preserveAspectRatio");
3575
if(preserveAspectRatio === "none" || contentWidth/contentHeight === nodeWidth/nodeHeight)
3577
xCoordOrigin = left;
3579
xCoordSize = contentWidth;
3580
yCoordSize = contentHeight;
3584
if(contentWidth * nodeHeight/contentHeight > nodeWidth)
3586
aspectRatio = nodeHeight/nodeWidth;
3587
xCoordSize = contentWidth;
3588
yCoordSize = contentWidth * aspectRatio;
3589
scaledHeight = (nodeWidth * (contentHeight/contentWidth)) * (yCoordSize/nodeHeight);
3590
yCoordOrigin = this._calculateCoordOrigin(preserveAspectRatio.slice(5).toLowerCase(), scaledHeight, yCoordSize);
3591
yCoordOrigin = top + yCoordOrigin;
3592
xCoordOrigin = left;
3596
aspectRatio = nodeWidth/nodeHeight;
3597
xCoordSize = contentHeight * aspectRatio;
3598
yCoordSize = contentHeight;
3599
scaledWidth = (nodeHeight * (contentWidth/contentHeight)) * (xCoordSize/nodeWidth);
3600
xCoordOrigin = this._calculateCoordOrigin(preserveAspectRatio.slice(1, 4).toLowerCase(), scaledWidth, xCoordSize);
3601
xCoordOrigin = xCoordOrigin + left;
3605
this._node.style.width = nodeWidth + "px";
3606
this._node.style.height = nodeHeight + "px";
3607
this._node.coordOrigin = xCoordOrigin + ", " + yCoordOrigin;
3611
xCoordSize = contentWidth;
3612
yCoordSize = contentHeight;
3613
this._node.style.width = contentWidth + "px";
3614
this._node.style.height = contentHeight + "px";
3615
this._state.width = contentWidth;
3616
this._state.height = contentHeight;
3619
this._node.coordSize = xCoordSize + ", " + yCoordSize;
3623
this._node.style.width = nodeWidth + "px";
3624
this._node.style.height = nodeHeight + "px";
3625
this._node.coordSize = nodeWidth + ", " + nodeHeight;
3629
this._node.appendChild(this._frag);
3634
this._node.style.visibility = "visible";
3639
* Determines the value for either an x or y coordinate to be used for the <code>coordOrigin</code> of the Graphic.
3641
* @method _calculateCoordOrigin
3642
* @param {String} position The position for placement. Possible values are min, mid and max.
3643
* @param {Number} size The total scaled size of the content.
3644
* @param {Number} coordsSize The coordsSize for the Graphic.
3648
_calculateCoordOrigin: function(position, size, coordsSize)
3657
coord = (size - coordsSize)/2;
3660
coord = (size - coordsSize);
3667
* Recalculates and returns the `contentBounds` for the `Graphic` instance.
3669
* @method _getUpdatedContentBounds
3673
_getUpdatedContentBounds: function()
3678
queue = this._shapes,
3682
if(queue.hasOwnProperty(i))
3685
bounds = shape.getBounds();
3686
box.left = Y_LANG.isNumber(box.left) ? Math.min(box.left, bounds.left) : bounds.left;
3687
box.top = Y_LANG.isNumber(box.top) ? Math.min(box.top, bounds.top) : bounds.top;
3688
box.right = Y_LANG.isNumber(box.right) ? Math.max(box.right, bounds.right) : bounds.right;
3689
box.bottom = Y_LANG.isNumber(box.bottom) ? Math.max(box.bottom, bounds.bottom) : bounds.bottom;
3692
box.left = Y_LANG.isNumber(box.left) ? box.left : 0;
3693
box.top = Y_LANG.isNumber(box.top) ? box.top : 0;
3694
box.right = Y_LANG.isNumber(box.right) ? box.right : 0;
3695
box.bottom = Y_LANG.isNumber(box.bottom) ? box.bottom : 0;
3696
this._contentBounds = box;
3701
* Inserts shape on the top of the tree.
3704
* @param {VMLShape} Shape to add.
3707
_toFront: function(shape)
3709
var contentNode = this._node;
3710
if(shape instanceof Y.VMLShape)
3712
shape = shape.get("node");
3714
if(contentNode && shape)
3716
contentNode.appendChild(shape);
3721
* Inserts shape as the first child of the content node.
3724
* @param {VMLShape} Shape to add.
3727
_toBack: function(shape)
3729
var contentNode = this._node,
3731
if(shape instanceof Y.VMLShape)
3733
shape = shape.get("node");
3735
if(contentNode && shape)
3737
targetNode = contentNode.firstChild;
3740
contentNode.insertBefore(shape, targetNode);
3744
contentNode.appendChild(shape);
3749
Y.VMLGraphic = VMLGraphic;
3753
}, '@VERSION@', {"requires": ["graphics"]});