clone

a browser-first diagram editor with live svg previews, local drafts and encrypted, accountless sharing

main
diagramzip / renderers / browser-run / frames / diagramsnet / vendor / assets / shapes / mxNetworks.js
mxNetworks.js 3.3K
1/**2 * Copyright (c) 2006-2015, JGraph Holdings Ltd3 */45//**********************************************************************************************************************************************************6//Bus7//**********************************************************************************************************************************************************8/**9* Extends mxShape.10*/11function mxShapeNetworksBus(bounds, fill, stroke, strokewidth)12{13 mxShape.call(this);14 this.bounds = bounds;15 this.fill = fill;16 this.stroke = stroke;17 this.strokewidth = (strokewidth != null) ? strokewidth : 1;18};1920/**21* Extends mxShape.22*/23mxUtils.extend(mxShapeNetworksBus, mxShape);2425mxShapeNetworksBus.prototype.cst = {26 SHAPE_BUS : 'mxgraph.networks.bus'27};2829/**30* Function: paintVertexShape31* 32* Paints the vertex shape.33*/34mxShapeNetworksBus.prototype.paintVertexShape = function(c, x, y, w, h)35{36 c.translate(x, y);37 this.background(c, x, y, w, h);38 c.setShadow(false);39 this.foreground(c, x, y, w, h);40};4142mxShapeNetworksBus.prototype.background = function(c, x, y, w, h)43{44 c.begin();45 c.moveTo(8, h * 0.5 + 10);46 c.arcTo(12, 12, 0, 0, 1, 8, h * 0.5 - 10);47 c.lineTo(w - 8, h * 0.5 - 10);48 c.arcTo(12, 12, 0, 0, 1, w - 8, h * 0.5 + 10);49 c.close();50 c.fillAndStroke();51};5253mxShapeNetworksBus.prototype.foreground = function(c, x, y, w, h)54{55 c.setFillColor('#ffffff');56 c.begin();57 c.moveTo(w - 8, h * 0.5 - 10);58 c.arcTo(12, 12, 0, 0, 1, w - 8, h * 0.5 + 10);59 c.arcTo(12, 12, 0, 0, 1, w - 8, h * 0.5 - 10);60 c.fillAndStroke();61};6263mxCellRenderer.registerShape(mxShapeNetworksBus.prototype.cst.SHAPE_BUS, mxShapeNetworksBus);6465//**********************************************************************************************************************************************************66//Comm Link67//**********************************************************************************************************************************************************68function mxShapeNetworksCommLinkEdge()69{70 mxArrow.call(this);71};7273mxUtils.extend(mxShapeNetworksCommLinkEdge, mxArrow);7475mxShapeNetworksCommLinkEdge.prototype.paintEdgeShape = function(c, pts)76{77 // Base vector (between end points)78 var p0 = pts[0];79 var pe = pts[pts.length - 1];80 81 var dx = pe.x - p0.x;82 var dy = pe.y - p0.y;83 84 p0.x = p0.x + dx * 0.05;85 p0.y = p0.y + dy * 0.05;86 pe.x = pe.x - dx * 0.05;87 pe.y = pe.y - dy * 0.05;88 dx = pe.x - p0.x;89 dy = pe.y - p0.y;90 91 var dist = Math.sqrt(dx * dx + dy * dy);92 var nx = dx / dist;93 var ny = dy / dist;94 var midX = p0.x + dx * 0.5; 95 var midY = p0.y + dy * 0.5;96 97 var p1x = midX + nx * dist / 3 * 0.1 - ny / 3 * dist * 0.1;98 var p1y = midY + ny * dist / 3 * 0.1 + nx / 3 * dist * 0.1;99 var p2x = midX + nx * dist * 0.1 + ny * dist * 0.1;100 var p2y = midY + ny * dist * 0.1 - nx * dist * 0.1;101102 var p3x = midX - nx * dist / 3 * 0.1 + ny / 3 * dist * 0.1;103 var p3y = midY - ny * dist / 3 * 0.1 - nx / 3 * dist * 0.1;104 var p4x = midX - nx * dist * 0.1 - ny * dist * 0.1;105 var p4y = midY - ny * dist * 0.1 + nx * dist * 0.1;106107 c.begin();108 c.moveTo(p0.x, p0.y);109 c.lineTo(p2x, p2y);110 c.lineTo(p1x, p1y);111 c.lineTo(pe.x, pe.y);112 c.lineTo(p4x, p4y);113 c.lineTo(p3x, p3y);114 c.close();115 c.fillAndStroke();116};117118//Registers the comm link edge119mxCellRenderer.registerShape('mxgraph.networks.comm_link_edge', mxShapeNetworksCommLinkEdge);