js 그래 픽 개발 라 이브 러 리 -- mxgraph -- contexticons - 서 스 펜 션 아이콘. html

js 그래 픽 개발 라 이브 러 리 -- mxgraph -- contexticons - 서 스 펜 션 아이콘. html
 
 
<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml>
	<head>
	<meta http-equiv=Content-Type content="text/html;charset=utf-8">
	<title>       for mxGraph</title>

	<!--         src        ,   basepath   src    -->
	<script type="text/javascript">
		mxBasePath = '../src';
	</script>

	<!--         -->
	<script type="text/javascript" src="../src/js/mxClient.js"></script>
	<!--      -->
	<script type="text/javascript">
		// Defines a subclass for mxVertexHandler that adds a set of clickable icons to every selected vertex.
		//        ,                。              。
		function mxVertexToolHandler(state) {
			mxVertexHandler.apply(this, arguments);
		};

		mxVertexToolHandler.prototype = new mxVertexHandler();
		mxVertexToolHandler.prototype.constructor = mxVertexToolHandler;
		
		mxVertexToolHandler.prototype.domNode = null;
		//   
		mxVertexToolHandler.prototype.init = function()
		{
			mxVertexHandler.prototype.init.apply(this, arguments);

			//     div      ,          IE          。
			this.domNode = document.createElement('div');
			this.domNode.style.position = 'absolute';
			this.domNode.style.whiteSpace = 'nowrap';
			var md = (mxClient.IS_TOUCH) ? 'touchstart' : 'mousedown';

			//     
			var img = mxUtils.createImage('images/delete2.png');
			img.style.cursor = 'pointer';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					// Disables dragging the image
					mxEvent.consume(evt);
				})
			);
			mxEvent.addListener(img, 'click',
				mxUtils.bind(this, function(evt)
				{
					this.graph.removeCells([this.state.cell]);
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);

			//     
			var img = mxUtils.createImage('images/fit_to_size.png');
			img.style.cursor = 'se-resize';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					this.start(mxEvent.getClientX(evt), mxEvent.getClientY(evt), 7);
					this.graph.isMouseDown = true;
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);

			//     
			var img = mxUtils.createImage('images/connector.gif');
			img.style.cursor = 'move';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					this.graph.graphHandler.start(this.state.cell,
						mxEvent.getClientX(evt), mxEvent.getClientY(evt));
					this.graph.graphHandler.cellWasClicked = true;
					this.graph.isMouseDown = true;
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);

			//     
			var img = mxUtils.createImage('images/check.png');
			img.style.cursor = 'pointer';
			img.style.width = '16px';
			img.style.height = '16px';
			mxEvent.addListener(img, md,
				mxUtils.bind(this, function(evt)
				{
					var pt = mxUtils.convertPoint(this.graph.container,
							mxEvent.getClientX(evt), mxEvent.getClientY(evt));
					this.graph.connectionHandler.start(this.state, pt.x, pt.y);
					this.graph.isMouseDown = true;
					mxEvent.consume(evt);
				})
			);
			this.domNode.appendChild(img);
			//        
			this.graph.container.appendChild(this.domNode);
			this.redrawTools();
		};
		//  
		mxVertexToolHandler.prototype.redraw = function()
		{
			mxVertexHandler.prototype.redraw.apply(this);
			this.redrawTools();
		};
		//    
		mxVertexToolHandler.prototype.redrawTools = function()
		{
			if (this.state != null && this.domNode != null)
			{
				var dy = (mxClient.IS_VML && document.compatMode == 'CSS1Compat') ? 20 : 4;
				this.domNode.style.left = (this.state.x + this.state.width - 56) + 'px';
				this.domNode.style.top = (this.state.y + this.state.height + dy) + 'px';
			}
		};
		//    
		mxVertexToolHandler.prototype.destroy = function(sender, me)
		{
			mxVertexHandler.prototype.destroy.apply(this, arguments);

			if (this.domNode != null)
			{
				this.domNode.parentNode.removeChild(this.domNode);
				this.domNode = null;
			}
		};
		
		//          
		function main(container) {
			//        
			if (!mxClient.isBrowserSupported()) {
				mxUtils.error('Browser is not supported!', 200, false);
			} else {
				//         
				var graph = new mxGraph(container);
				graph.setConnectable(true);
				graph.connectionHandler.createTarget = true;

				graph.createHandler = function(state) {
					if (state != null && 
							this.model.isVertex(state.cell)) {
						return new mxVertexToolHandler(state);
					}

					return mxGraph.prototype.createHandler.apply(this, arguments);
				};

				//              
				//graph.setResizeContainer(true);
				
				//      
				//new mxRubberband(graph);
				
				//            
				var parent = graph.getDefaultParent();
								
				
				//       
				graph.getModel().beginUpdate();
				try {
					//        
					var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
					var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
					var e1 = graph.insertEdge(parent, null, '', v1, v2);
				}
				finally
				{
					//     
					graph.getModel().endUpdate();
				}
			}
		};
	</script>
</head>

<!--           -->
<body onload="main(document.getElementById('graphContainer'))">

	<!--                 -->
	<div id="graphContainer"
		style="overflow:hidden;width:321px;height:241px;background:url('editors/images/grid.gif');cursor:default;">
	</div>
</body>
</html>

 
 
 
 

좋은 웹페이지 즐겨찾기