?? vml.js
字號:
var p = [" r"]; var n = segment.args; var l = n.length; for(var i = 0; i < l; ++i){ p.push(" 0 "); p.push(n[i].toFixed()); } this.lastControl = {}; return p; }, _curveToA: function(segment){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 6){ p.push(" c"); this._addArgs(p, n, i, i + 6); } this.lastControl = {x: n[l - 4], y: n[l - 3], type: "C"}; return p; }, _curveToR: function(segment, last){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 6){ p.push(" v"); this._addArgs(p, n, i, i + 6); this.lastControl = {x: last.x + n[i + 2], y: last.y + n[i + 3]}; last.x += n[i + 4]; last.y += n[i + 5]; } this.lastControl.type = "C"; return p; }, _smoothCurveToA: function(segment, last){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 4){ p.push(" c"); if(this.lastControl.type == "C"){ this._addArgs(p, [ 2 * last.x - this.lastControl.x, 2 * last.y - this.lastControl.y ]); }else{ this._addArgs(p, [last.x, last.y]); } this._addArgs(p, n, i, i + 4); } this.lastControl = {x: n[l - 4], y: n[l - 3], type: "C"}; return p; }, _smoothCurveToR: function(segment, last){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 4){ p.push(" v"); if(this.lastControl.type == "C"){ this._addArgs(p, [ last.x - this.lastControl.x, last.y - this.lastControl.y ]); }else{ this._addArgs(p, [0, 0]); } this._addArgs(p, n, i, i + 4); this.lastControl = {x: last.x + n[i], y: last.y + n[i + 1]}; last.x += n[i + 2]; last.y += n[i + 3]; } this.lastControl.type = "C"; return p; }, _qCurveToA: function(segment){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 4){ p.push(" qb"); this._addArgs(p, n, i, i + 4); } this.lastControl = {x: n[l - 4], y: n[l - 3], type: "Q"}; return p; }, _qCurveToR: function(segment, last){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 4){ p.push(" qb"); this._addArgsAdjusted(p, last, n, i, i + 4); this.lastControl = {x: last.x + n[i], y: last.y + n[i + 1]}; last.x += n[i + 2]; last.y += n[i + 3]; } this.lastControl.type = "Q"; return p; }, _qSmoothCurveToA: function(segment, last){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 2){ p.push(" qb"); if(this.lastControl.type == "Q"){ this._addArgs(p, [ this.lastControl.x = 2 * last.x - this.lastControl.x, this.lastControl.y = 2 * last.y - this.lastControl.y ]); }else{ this._addArgs(p, [ this.lastControl.x = last.x, this.lastControl.y = last.y ]); } this._addArgs(p, n, i, i + 2); } this.lastControl.type = "Q"; return p; }, _qSmoothCurveToR: function(segment, last){ var p = []; var n = segment.args; var l = n.length; for(var i = 0; i < l; i += 2){ p.push(" qb"); if(this.lastControl.type == "Q"){ this._addArgs(p, [ this.lastControl.x = 2 * last.x - this.lastControl.x, this.lastControl.y = 2 * last.y - this.lastControl.y ]); }else{ this._addArgs(p, [ this.lastControl.x = last.x, this.lastControl.y = last.y ]); } this._addArgsAdjusted(p, last, n, i, i + 2); } this.lastControl.type = "Q"; return p; }, _PI4: Math.PI / 4, _curvePI4: dojo.gfx.path._calcArc(Math.PI / 8), _calcArcTo: function(path, last, rx, ry, xRotg, large, cw, x, y){ var m = dojo.gfx.matrix; // calculate parameters var xRot = -dojo.math.degToRad(xRotg); var rx2 = rx * rx; var ry2 = ry * ry; var pa = m.multiplyPoint( m.rotate(-xRot), {x: (last.x - x) / 2, y: (last.y - y) / 2} ); var pax2 = pa.x * pa.x; var pay2 = pa.y * pa.y; var c1 = Math.sqrt((rx2 * ry2 - rx2 * pay2 - ry2 * pax2) / (rx2 * pay2 + ry2 * pax2)); var ca = { x: c1 * rx * pa.y / ry, y: -c1 * ry * pa.x / rx }; if(large == cw){ ca = {x: -ca.x, y: -ca.y}; } // our center var c = m.multiplyPoint( [ m.translate( (last.x + x) / 2, (last.y + y) / 2 ), m.rotate(xRot) ], ca ); // start of our arc var startAngle = Math.atan2(c.y - last.y, last.x - c.x) - xRot; var endAngle = Math.atan2(c.y - y, x - c.x) - xRot; // size of our arc in radians var theta = cw ? startAngle - endAngle : endAngle - startAngle; if(theta < 0){ theta += this._2PI; }else if(theta > this._2PI){ theta = this._2PI; } // calculate our elliptic transformation var elliptic_transform = m.normalize([ m.translate(c.x, c.y), m.rotate(xRot), m.scale(rx, ry) ]); // draw curve chunks var alpha = this._PI4 / 2; var curve = this._curvePI4; var step = cw ? -alpha : alpha; for(var angle = theta; angle > 0; angle -= this._PI4){ if(angle < this._PI4){ alpha = angle / 2; curve = dojo.gfx.path._calcArc(alpha); step = cw ? -alpha : alpha; } var c1, c2, e; var M = m.normalize([elliptic_transform, m.rotate(startAngle + step)]); if(cw){ c1 = m.multiplyPoint(M, curve.c2); c2 = m.multiplyPoint(M, curve.c1); e = m.multiplyPoint(M, curve.s ); }else{ c1 = m.multiplyPoint(M, curve.c1); c2 = m.multiplyPoint(M, curve.c2); e = m.multiplyPoint(M, curve.e ); } // draw the curve path.push(" c"); this._addArgs(path, [c1.x, c1.y, c2.x, c2.y, e.x, e.y]); startAngle += 2 * step; } }, _arcTo: function(segment, last){ var p = []; var n = segment.args; var l = n.length; var relative = segment.action == "a"; for(var i = 0; i < l; i += 7){ var x1 = n[i + 5]; var y1 = n[i + 6]; if(relative){ x1 += last.x; y1 += last.y; } this._calcArcTo( p, last, n[i], n[i + 1], n[i + 2], n[i + 3] ? 1 : 0, n[i + 4] ? 1 : 0, x1, y1 ); last = {x: x1, y: y1}; } this.lastControl = {}; return p; }, _closePath: function(){ this.lastControl = {}; return ["x"]; }});dojo.gfx.Path.nodeType = "shape";dojo.gfx._creators = { // summary: VML shape creators createPath: function(path){ // summary: creates an SVG path shape // path: Object: a path object (see dojo.gfx.defaultPath) return this.createObject(dojo.gfx.Path, path, true); // dojo.gfx.Path }, createRect: function(rect){ // summary: creates an VML rectangle shape // rect: Object: a path object (see dojo.gfx.defaultRect) return this.createObject(dojo.gfx.Rect, rect); // dojo.gfx.Rect }, createCircle: function(circle){ // summary: creates an VML circle shape // circle: Object: a circle object (see dojo.gfx.defaultCircle) return this.createObject(dojo.gfx.Circle, circle); // dojo.gfx.Circle }, createEllipse: function(ellipse){ // summary: creates an VML ellipse shape // ellipse: Object: an ellipse object (see dojo.gfx.defaultEllipse) return this.createObject(dojo.gfx.Ellipse, ellipse); // dojo.gfx.Ellipse }, createLine: function(line){ // summary: creates an VML line shape // line: Object: a line object (see dojo.gfx.defaultLine) return this.createObject(dojo.gfx.Line, line, true); // dojo.gfx.Line }, createPolyline: function(points){ // summary: creates an VML polyline/polygon shape // points: Object: a points object (see dojo.gfx.defaultPolyline) // or an Array of points return this.createObject(dojo.gfx.Polyline, points, true); // dojo.gfx.Polyline }, createImage: function(image){ // summary: creates an VML image shape // image: Object: an image object (see dojo.gfx.defaultImage) if(!this.rawNode) return null; var shape = new dojo.gfx.Image(); var node = document.createElement('div'); node.style.position = "relative"; node.style.width = this.rawNode.style.width; node.style.height = this.rawNode.style.height; node.style.filter = "progid:DXImageTransform.Microsoft.Matrix(M11=1, M12=0, M21=0, M22=1, Dx=0, Dy=0)"; var img = document.createElement('img'); node.appendChild(img); shape.setRawNode(node); this.rawNode.appendChild(node); shape.setShape(image); this.add(shape); return shape; // dojo.gfx.Image }, createGroup: function(){ // summary: creates an VML group shape return this.createObject(dojo.gfx.Group, null, true); // dojo.gfx.Group }, createObject: function(shapeType, rawShape, overrideSize) { // summary: creates an instance of the passed shapeType class // shapeType: Function: a class constructor to create an instance of // rawShape: Object: properties to be passed in to the classes "setShape" method if(!this.rawNode) return null; var shape = new shapeType(); var node = document.createElement('v:' + shapeType.nodeType); shape.setRawNode(node); this.rawNode.appendChild(node); if(overrideSize) this._overrideSize(node); shape.setShape(rawShape); this.add(shape); return shape; // dojo.gfx.Shape }, _overrideSize: function(node){ node.style.width = this.rawNode.style.width; node.style.height = this.rawNode.style.height; node.coordsize = parseFloat(node.style.width) + " " + parseFloat(node.style.height); }};dojo.lang.extend(dojo.gfx.Group, dojo.gfx._creators);dojo.lang.extend(dojo.gfx.Surface, dojo.gfx._creators);delete dojo.gfx._creators;dojo.gfx.attachNode = function(node){ // summary: creates a shape from a Node // node: Node: an VML node if(!node) return null; var s = null; switch(node.tagName.toLowerCase()){ case dojo.gfx.Rect.nodeType: s = new dojo.gfx.Rect(); break; case dojo.gfx.Ellipse.nodeType: s = (node.style.width == node.style.height) ? new dojo.gfx.Circle() : new dojo.gfx.Ellipse(); break; case dojo.gfx.Path.nodeType: switch(node.getAttribute("dojoGfxType")){ case "line": s = new dojo.gfx.Line(); break; case "polyline": s = new dojo.gfx.Polyline(); break; case "path": s = new dojo.gfx.Path(); break; } break; case dojo.gfx.Image.nodeType: s = new dojo.gfx.Image(); break; default: dojo.debug("FATAL ERROR! tagName = " + node.tagName); } s.attach(node); return s; // dojo.gfx.Shape};dojo.lang.extend(dojo.gfx.Surface, { // summary: a surface object to be used for drawings (VML) setDimensions: function(width, height){ // summary: sets the width and height of the rawNode // width: String: width of surface, e.g., "100px" // height: String: height of surface, e.g., "100px" if(!this.rawNode) return this; this.rawNode.style.width = width; this.rawNode.style.height = height; this.rawNode.coordsize = width + " " + height; return this; // self }, getDimensions: function(){ // summary: returns an object with properties "width" and "height" return this.rawNode ? { width: this.rawNode.style.width, height: this.rawNode.style.height } : null; // Object }, // group control add: function(shape){ // summary: adds a shape to a group/surface // shape: dojo.gfx.Shape: an VMLshape object var oldParent = shape.getParent(); if(this != oldParent){ this.rawNode.appendChild(shape.rawNode); if(oldParent){ oldParent.remove(shape, true); } shape._setParent(this, null); } return this; // self }, remove: function(shape, silently){ // summary: remove a shape from a group/surface // shape: dojo.gfx.Shape: an VML shape object // silently: Boolean?: if true, regenerate a picture if(this == shape.getParent()){ if(this.rawNode == shape.rawNode.parentNode){ this.rawNode.removeChild(shape.rawNode); } shape._setParent(null, null); } return this; // self }});dojo.gfx.createSurface = function(parentNode, width, height){ // summary: creates a surface (VML) // parentNode: Node: a parent node // width: String: width of surface, e.g., "100px" // height: String: height of surface, e.g., "100px" var s = new dojo.gfx.Surface(); s.rawNode = document.createElement("v:group"); s.rawNode.style.width = width ? width : "100%"; s.rawNode.style.height = height ? height : "100%"; s.rawNode.coordsize = (width && height) ? (parseFloat(width) + " " + parseFloat(height)) : "100% 100%"; s.rawNode.coordorigin = "0 0"; dojo.byId(parentNode).appendChild(s.rawNode); return s; // dojo.gfx.Surface};dojo.gfx.attachSurface = function(node){ // summary: creates a surface from a Node // node: Node: an VML node var s = new dojo.gfx.Surface(); s.rawNode = node; return s; // dojo.gfx.Surface};
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -