⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 svg.js

📁 js基本操作
💻 JS
📖 第 1 页 / 共 2 页
字号:
		if(rawNode){			shape = dojo.lang.shallowCopy(this.shape, true);			for(var i in shape) {				shape[i] = rawNode.getAttribute(i);			}		}		return shape;	// dojo.gfx.Shape	},	attach: function(rawNode){		// summary: reconstructs all shape parameters from a Node.		// rawNode: Node: an SVG node		if(rawNode) {			this.rawNode = rawNode;			this.fillStyle = this.attachFill(rawNode);			this.strokeStyle = this.attachStroke(rawNode);			this.matrix = this.attachTransform(rawNode);			this.shape = this.attachShape(rawNode);		}	}});dojo.declare("dojo.gfx.Group", dojo.gfx.Shape, {	// summary: a group shape (SVG), which can be used 	//	to logically group shapes (e.g, to propagate matricies)	setRawNode: function(rawNode){		// summary: sets a raw SVG node to be used by this shape		// rawNode: Node: an SVG node		this.rawNode = rawNode;	}});dojo.gfx.Group.nodeType = "g";dojo.declare("dojo.gfx.Rect", dojo.gfx.shape.Rect, {	// summary: a rectangle shape (SVG)	attachShape: function(rawNode){		// summary: builds a rectangle shape from a Node.		// rawNode: Node: an SVG node		var shape = null;		if(rawNode){			shape = dojo.gfx.Rect.superclass.attachShape.apply(this, arguments);			shape.r = Math.min(rawNode.getAttribute("rx"), rawNode.getAttribute("ry"));		}		return shape;	// dojo.gfx.shape.Rect	},	setShape: function(newShape){		// summary: sets a rectangle shape object (SVG)		// newShape: Object: a rectangle shape object		this.shape = dojo.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		for(var i in this.shape){			if(i != "type" && i != "r"){ this.rawNode.setAttribute(i, this.shape[i]); }		}		this.rawNode.setAttribute("rx", this.shape.r);		this.rawNode.setAttribute("ry", this.shape.r);		return this;	// self	}});dojo.gfx.Rect.nodeType = "rect";dojo.gfx.Ellipse = dojo.gfx.shape.Ellipse;dojo.gfx.Ellipse.nodeType = "ellipse";dojo.gfx.Circle = dojo.gfx.shape.Circle;dojo.gfx.Circle.nodeType = "circle";dojo.gfx.Line = dojo.gfx.shape.Line;dojo.gfx.Line.nodeType = "line";dojo.declare("dojo.gfx.Polyline", dojo.gfx.shape.Polyline, {	// summary: a polyline/polygon shape (SVG)		setShape: function(points){		// summary: sets a polyline/polygon shape object (SVG)		// points: Object: a polyline/polygon shape object		if(points && points instanceof Array){			// branch			// points: Array: an array of points			this.shape = dojo.gfx.makeParameters(this.shape, { points: points });			if(closed && this.shape.points.length){ 				this.shape.points.push(this.shape.points[0]);			}		}else{			this.shape = dojo.gfx.makeParameters(this.shape, points);		}		this.box = null;		var attr = [];		var p = this.shape.points;		for(var i = 0; i < p.length; ++i){			attr.push(p[i].x.toFixed(8));			attr.push(p[i].y.toFixed(8));		}		this.rawNode.setAttribute("points", attr.join(" "));		return this;	// self	}});dojo.gfx.Polyline.nodeType = "polyline";dojo.declare("dojo.gfx.Image", dojo.gfx.shape.Image, {	// summary: an image (SVG)	setShape: function(newShape){		// summary: sets an image shape object (SVG)		// newShape: Object: an image shape object		this.shape = dojo.gfx.makeParameters(this.shape, newShape);		this.bbox = null;		var rawNode = this.rawNode;		for(var i in this.shape){			if(i != "type" && i != "src"){ rawNode.setAttribute(i, this.shape[i]); }		}		rawNode.setAttributeNS(dojo.svg.xmlns.xlink, "href", this.shape.src);		return this;	// self	},	setStroke: function(){		// summary: ignore setting a stroke style		return this;	// self	},	setFill: function(){		// summary: ignore setting a fill style		return this;	// self	},	attachStroke: function(rawNode){		// summary: ignore attaching a stroke style		return null;	},	attachFill: function(rawNode){		// summary: ignore attaching a fill style		return null;	}});dojo.gfx.Image.nodeType = "image";dojo.declare("dojo.gfx.Path", dojo.gfx.path.Path, {	// summary: a path shape (SVG)	_updateWithSegment: function(segment){		// summary: updates the bounding box of path with new segment		// segment: Object: a segment		dojo.gfx.Path.superclass._updateWithSegment.apply(this, arguments);		if(typeof(this.shape.path) == "string"){			this.rawNode.setAttribute("d", this.shape.path);		}	},	setShape: function(newShape){		// summary: forms a path using a shape (SVG)		// newShape: Object: an SVG path string or a path object (see dojo.gfx.defaultPath)		dojo.gfx.Path.superclass.setShape.apply(this, arguments);		this.rawNode.setAttribute("d", this.shape.path);		return this;	// self	}});dojo.gfx.Path.nodeType = "path";dojo.gfx._creators = {	// summary: SVG 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);	// dojo.gfx.Path	},	createRect: function(rect){		// summary: creates an SVG 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 SVG 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 SVG 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 SVG line shape		// line: Object: a line object (see dojo.gfx.defaultLine)		return this.createObject(dojo.gfx.Line, line);	// dojo.gfx.Line	},	createPolyline: function(points){		// summary: creates an SVG polyline/polygon shape		// points: Object: a points object (see dojo.gfx.defaultPolyline)		//	or an Array of points		return this.createObject(dojo.gfx.Polyline, points);	// dojo.gfx.Polyline	},	createImage: function(image){		// summary: creates an SVG image shape		// image: Object: an image object (see dojo.gfx.defaultImage)		return this.createObject(dojo.gfx.Image, image);	// dojo.gfx.Image	},	createGroup: function(){		// summary: creates an SVG group shape		return this.createObject(dojo.gfx.Group);	// dojo.gfx.Group	},	createObject: function(shapeType, rawShape){		// 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.createElementNS(dojo.svg.xmlns.svg, shapeType.nodeType); 		shape.setRawNode(node);		this.rawNode.appendChild(node);		shape.setShape(rawShape);		this.add(shape);		return shape;	// dojo.gfx.Shape	},	// group control	add: function(shape){		// summary: adds a shape to a group/surface		// shape: dojo.gfx.Shape: an SVG shape object		var oldParent = shape.getParent();		if(oldParent){			oldParent.remove(shape, true);		}		shape._setParent(this, null);		this.rawNode.appendChild(shape.rawNode);		return this;	// self	},	remove: function(shape, silently){		// summary: remove a shape from a group/surface		// shape: dojo.gfx.Shape: an SVG shape object		// silently: Boolean?: if true, regenerate a picture		if(this.rawNode == shape.rawNode.parentNode){			this.rawNode.removeChild(shape.rawNode);		}		shape._setParent(null, null);		return this;	// self	}};dojo.gfx.attachNode = function(node){	// summary: creates a shape from a Node	// node: Node: an SVG 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 = new dojo.gfx.Ellipse();			break;		case dojo.gfx.Polyline.nodeType:			s = new dojo.gfx.Polyline();			break;		case dojo.gfx.Path.nodeType:			s = new dojo.gfx.Path();			break;		case dojo.gfx.Circle.nodeType:			s = new dojo.gfx.Circle();			break;		case dojo.gfx.Line.nodeType:			s = new dojo.gfx.Line();			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 (SVG)	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.setAttribute("width",  width);		this.rawNode.setAttribute("height", height);		return this;	// self	},	getDimensions: function(){		// summary: returns an object with properties "width" and "height"		return this.rawNode ? {width: this.rawNode.getAttribute("width"), height: this.rawNode.getAttribute("height")} : null; // Object	}});dojo.gfx.createSurface = function(parentNode, width, height){	// summary: creates a surface (SVG)	// 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.createElementNS(dojo.svg.xmlns.svg, "svg");	s.rawNode.setAttribute("width",  width);	s.rawNode.setAttribute("height", height);	var defs = new dojo.gfx.svg.Defines();	var node = document.createElementNS(dojo.svg.xmlns.svg, dojo.gfx.svg.Defines.nodeType); 	defs.setRawNode(node);	s.rawNode.appendChild(node);		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 SVG node	var s = new dojo.gfx.Surface();	s.rawNode = node;	return s;	// dojo.gfx.Surface};dojo.lang.extend(dojo.gfx.Group, dojo.gfx._creators);dojo.lang.extend(dojo.gfx.Surface, dojo.gfx._creators);delete dojo.gfx._creators;// Gradient and patterndojo.gfx.svg.Defines = function(){	this.rawNode = null;};dojo.lang.extend(dojo.gfx.svg.Defines, {	setRawNode: function(rawNode){		this.rawNode = rawNode;	}});dojo.gfx.svg.Defines.nodeType = "defs";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -