Best JavaScript code snippet using mountebank
arrowLine.js
Source:arrowLine.js
1//带ç®å¤´çæ线2(function(stName){ 3 /**4 * @param {object} åç
§jmElement çåæ°5 */6 function shapeType(option){ 7 option = jmUtils.extend(option||{}, {8 position :{x:300,y:50},9 width:100,10 height:6011 });12 this.start = option.start || option.position;13 this.end = option.end || {x: option.position.x + option.width, y: option.position.y + option.height};14 this.resizable = false;15 this.connectable = false;16 this.style = option.style || jmUtils.clone(option.editor.defaultStyle.line, true);17 //继æ¿jmElement18 jmUtils.extend(this, new jmDraw.jmElement());19 //è¡¥å
ä¸ä¸ªç®å¤´20 this.shape = option.graph.createShape('arraw', {style: this.style.arrow||option.editor.defaultStyle.line.arrow}); 21 //èµ·å§ä½ç½®å¯ææ¾å¾å½¢22 this.startDragShape = option.graph.createShape('rect', {width:8,height:8,style: this.style.dragShape||option.editor.defaultStyle.line.dragShape});23 this.endDragShape = option.graph.createShape('rect', {width:8,height:8,style: this.style.dragShape||option.editor.defaultStyle.line.dragShape}); 24 //é¼ æ è¿å
¥æ¾ç¤ºhoveræ ·å¼25 this.startDragShape.bind('mouseover', function(){26 this.style = jmUtils.extend(jmUtils.clone(this.parent.style.dragShape.hover),this.style);27 //this.cursor('crosshair');28 });29 this.startDragShape.bind('mouseleave', function(){30 this.style = jmUtils.extend(jmUtils.clone(this.parent.style.dragShape),this.style);31 });32 //é¼ æ è¿å
¥æ¾ç¤ºhoveræ ·å¼33 this.endDragShape.bind('mouseover', function(){34 this.style = jmUtils.extend(jmUtils.clone(this.parent.style.dragShape.hover),this.style);35 });36 this.endDragShape.bind('mouseleave', function(){37 this.style = jmUtils.extend(jmUtils.clone(this.parent.style.dragShape),this.style);38 });39 this.startDragShape.canMove(true).on('move', function(args){40 //å¦ææ¯å
ç´ çè¿æ¥å ï¼ååå
¶ä¸å¿41 if(this.parent.start.type == 'jmConnectPoint') {42 this.parent.start = jmUtils.clone(this.parent.start.getCenter(true, true));43 }44 this.parent.start.x += args.offsetX;45 this.parent.start.y += args.offsetY;46 this.parent.checkConnectPointsStatus();47 }).on('moveend', function(args){48 this.parent.checkConnectPointsStatus(true, function(start, end) {49 if(start) this.start = start;50 });//ç»ææ¾ç¤ºç¶æ 51 }).visible = false;; 52 this.endDragShape.canMove(true).on('move', function(args){53 //å¦ææ¯å
ç´ çè¿æ¥å ï¼ååå
¶ä¸å¿ 54 if(this.parent.end.type == 'jmConnectPoint') {55 this.parent.end = jmUtils.clone(this.parent.end.getCenter(true, true));56 }57 this.parent.end.x += args.offsetX;58 this.parent.end.y += args.offsetY;59 this.parent.checkConnectPointsStatus();60 }).on('moveend', function(args){61 this.parent.checkConnectPointsStatus(true, function(start, end) {62 if(end) this.end = end;63 });64 }).visible = false; 65 //åå§åèç¹66 this.init(option);67 //å 宽触æ§åºåï¼ä½¿å®æ´å®¹æéä¸68 this.style.touchPadding = 5;69 this.children.add(this.startDragShape);70 this.children.add(this.endDragShape);71 //éç½®å¾å½¢çæ72 this.initPoints = function() { 73 var loc = this.getLocation(); 74 //è·åäºç¹çæ¹ä½ï¼1=left,2=top,3=right,=bottom 75 function getDirection(s,e) {76 if(s.x == e.x) {77 return s.y > e.y?4:2;//åç´æ¹å78 }79 if(s.y == e.y) {80 return s.x > e.x?3:1;//æ°´å¹³æ¹å81 }82 if(s.x > e.x) {83 return s.y > e.y?3412:3214;//èµ·å§ç¹x,yé½å¤§äºç»æç¹å为左ä¸å³ä¸84 }85 else {86 return s.y > e.y?1432:1234;//èµ·å§ç¹Xå°äºç»æç¹ï¼Y大äºç»æç¹å为å³ä¸å³ä¸87 }88 }89 //计ç®ç¬¬ä¸ä¸ªé»è®¤ç¹ä½90 //æ ¹æ®ä¸åæ¹ä½è¿æ¥ç¹å移ä¸åçæ¹å91 function initFirstPoint(connectPoint, p, step) {92 var ret = {x: p.x, y: p.y};93 switch(connectPoint.pos) {94 //顶é¨,åä¸åéä¸ä¸ªstep95 case 'top': {96 ret.y -= step;97 break;98 }99 //å¨è¾¹,åå³ç§»ä¸ä¸ªstep100 case 'right': {101 ret.x += step;102 break;103 }104 //åºé¨,åä¸ç§»step105 case 'bottom': {106 ret.y += step;107 break;108 }109 //顶é¨,åä¸åéä¸ä¸ªstep110 case 'left': {111 ret.x -= step;112 break;113 }114 }115 return ret;116 }117 var maxFirstStep = 20;//æ¯ä¸ªè¿æ¥ç¹æä¸ä¸ªæ大é离é¿åº¦ï¼è®©çº¿æ¡ç¦»å¾å½¢ä¸å®è·ç¦»118 var start = this.start;119 var end = this.end;120 var firstStart,firstEnd;//å®ä¹äºä¸ªé度ç¹ï¼ç¦»è¿æ¥ç¹æè¿çç¹121 //å¦ææ¯å
ç´ çè¿æ¥å ï¼ååå
¶ä¸å¿122 if(start.type == 'jmConnectPoint') {123 start = jmUtils.clone(start.getCenter(true, true));124 firstStart = initFirstPoint(this.start, start, maxFirstStep);//计ç®è¿æ¥ç¹å¤ç§»ç第ä¸ä¸ªç¹125 }126 //å¦æä¸æ¯è¿æ¥çå¾å½¢è¿æ¥ç¹ï¼åä¸éè¦éç¹127 else {128 firstStart = start;129 }130 if(end.type == 'jmConnectPoint') {131 end = jmUtils.clone(end.getCenter(true, true));132 firstEnd = initFirstPoint(this.end, end, maxFirstStep);//计ç®è¿æ¥ç¹å¤ç§»ç第ä¸ä¸ªç¹133 }134 else {135 firstEnd = end;136 }137 var points = this.points = [start, firstStart];138 //å¤æäºç¹æå¨æ¹ä½139 var der = getDirection(start, end);140 //points.push({x: end.x, y: start.y});141 //å¦æèµ·å§ç¹è¿æ¥çæ¯å¾å½¢142 if(this.start.type == 'jmConnectPoint') {143 //å¦æç®å½ä¹æ¯å¾å½¢144 if(this.end.type == 'jmConnectPoint') {145 switch(der) {146 //ä»å·¦å¾å³çæ°´å¹³æ¹å147 case 1:{ 148 shape2ShapeLeft2Right.call(this, start, end, firstStart, firstEnd, maxFirstStep);149 break;150 }151 //ä»å³å¾å·¦çæ°´å¹³æ¹å152 case 3:{153 shape2ShapeRight2Left.call(this, start, end, firstStart, firstEnd, maxFirstStep);154 break;155 }156 //ä»ä¸å¾ä¸çåç´æ¹å157 case 2:{158 shape2ShapeTop2Bottom.call(this, start, end, firstStart, firstEnd, maxFirstStep);159 break;160 }161 //ä»ä¸å¾ä¸çåç´æ¹å162 case 4:{163 shape2ShapeBottom2Top.call(this, start, end, firstStart, firstEnd, maxFirstStep);164 break;165 }166 //å³ä¸å¾å·¦ä¸167 case 3412:{168 shape2ShapeRightBottom2LeftTop.call(this, start, end, firstStart, firstEnd, maxFirstStep);169 break;170 }171 //å³ä¸å¾å·¦ä¸172 case 3214:{173 var len = (firstEnd.x - firstStart.x)/2;174 points.push({x:firstStart.x + len,y:firstStart.y});175 points.push({x:firstEnd.x - len,y: firstEnd.y});176 break;177 }178 //å·¦ä¸å¾å³ä¸179 case 1432:{180 var len = (firstEnd.x - firstStart.x)/2;181 points.push({x:firstStart.x + len,y: firstStart.y});182 points.push({x:firstEnd.x - len,y: firstEnd.y});183 break;184 }185 //å·¦ä¸å³ä¸186 default:{187 var len = (firstEnd.x - firstStart.x)/2;188 points.push({x:firstStart.x + len,y: firstStart.y});189 points.push({x:firstEnd.x - len,y: firstEnd.y});190 break;191 }192 }193 }194 }195 else {196 switch(der) {197 //ä»å·¦å¾å³çæ°´å¹³æ¹å198 case 1:{199 200 var len = (firstEnd.x - firstStart.x)/3;201 points.push({x:firstStart.x + len, y: firstStart.y});202 points.push({x:firstEnd.x - len, y: firstStart.y});203 break;204 }205 //ä»å³å¾å·¦çæ°´å¹³æ¹å206 case 3:{207 var len = (firstStart.x - firstEnd.x)/3;208 points.push({x:firstStart.x - len, y: firstStart.y});209 points.push({x:firstEnd.x + len, y: firstStart.y});210 break;211 }212 //ä»ä¸å¾ä¸çåç´æ¹å213 case 2:{214 var len = (firstEnd.y - firstStart.y)/3;215 points.push({x:firstStart.x, y: firstStart.y + len});216 points.push({x:firstStart.x , y: firstEnd.y - len});217 break;218 }219 //ä»ä¸å¾ä¸çåç´æ¹å220 case 4:{221 var len = (firstStart.y - firstEnd.y)/3;222 points.push({x:firstStart.x, y: firstEnd.y + len});223 points.push({x:firstStart.x , y: firstStart.y - len});224 break;225 }226 //å³ä¸å¾å·¦ä¸227 case 3412:{228 var len = (firstStart.x - firstEnd.x)/2;229 points.push({x:firstStart.x - len,y: firstStart.y});230 points.push({x:firstStart.x - len,y: firstEnd.y});231 break;232 }233 //å³ä¸å¾å·¦ä¸234 case 3214:{235 var len = (firstEnd.x - firstStart.x)/2;236 points.push({x:firstStart.x + len,y:firstStart.y});237 points.push({x:firstEnd.x - len,y: firstEnd.y});238 break;239 }240 //å·¦ä¸å¾å³ä¸241 case 1432:{242 var len = (firstEnd.x - firstStart.x)/2;243 points.push({x:firstStart.x + len,y: firstStart.y});244 points.push({x:firstEnd.x - len,y: firstEnd.y});245 break;246 }247 //å·¦ä¸å³ä¸248 default:{249 var len = (firstEnd.x - firstStart.x)/2;250 points.push({x:firstStart.x + len,y: firstStart.y});251 points.push({x:firstEnd.x - len,y: firstEnd.y});252 break;253 }254 }255 }256 points.push(firstEnd, end);257 var bounds = this.getBounds(true);//强å¶éç®bounds,this.pointsæä¼å½åç»å¶çæ258 //çæç®å¤´åæ ç¹259 //ç®å¤´å å°äºå½ååæ§ä»¶ä¸ï¼æ以å®çåæ æ¯å¯¹åºä¸ºå½åæ§ä»¶å·¦ä¸è§ç260 var arrawP1 = jmUtils.clone(points[points.length-2]);261 var arrawP2 = jmUtils.clone(points[points.length-1]);262 jmUtils.offsetPoints([arrawP1,arrawP2], {x:-bounds.left, y:-bounds.top});263 this.shape.start = arrawP1; 264 this.shape.end = arrawP2;265 //计ç®çº¿æ¡ç¸å¯¹èµ·ç¹åç»æç¹266 var offstart = jmUtils.clone(start);267 var offend = jmUtils.clone(end);268 jmUtils.offsetPoints([offstart,offend], {x:-bounds.left-this.startDragShape.width/2, y:-bounds.top-this.endDragShape.height/2});269 this.startDragShape.position = offstart;270 this.endDragShape.position = offend;271 return points;272 }273 //å¾å½¢è¿å¾å½¢ä»å·¦åå³æ°´å¹³æ¹ä½274 function shape2ShapeLeft2Right(start, end, firstStart, firstEnd, maxFirstStep) { 275 //èµ·å§å¾å½¢çè¾¹çä¿¡æ¯276 var startShapeBound = this.start.parent.getBounds();277 var endShapeBound = this.end.parent.getBounds();278 //èµ·å§ç¹ä¸ºå¾å½¢ç左侧 279 if(this.start.pos == 'left') {280 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿281 switch(this.end.pos) {282 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸ï¼å¯¼çº¿éè¦ç»è¿èµ·å§å¾å½¢283 case 'left': {284 //å¦æäºå¾å¤ªè¿ï¼åç´è¿å³å¯285 if(end.x <= startShapeBound.right + maxFirstStep) {286 firstStart.x = start.x; 287 firstEnd = end; 288 }289 //ç»è¿å¾å½¢è¿ç»290 else {291 //å¦æç»æä½ç½®ç¦»èµ·å§å¾å½¢å¤ªè¿ï¼åéä¸ä½292 var foffx = end.x - startShapeBound.right;293 firstEnd.x = startShapeBound.right + foffx/2294 295 //ç»è¿åºé¨296 var p1 = {x:firstStart.x, y: startShapeBound.bottom + maxFirstStep};297 var p2 = {x: firstEnd.x, y: p1.y};298 this.points.push(p1,p2);299 }300 break;301 }302 //ç»æç¹å¨å¾å½¢ä¸æ¹303 case 'top': {304 //ç»è¿å¾å½¢è¿ç»305 var p1 = {x:firstStart.x, y: startShapeBound.top - maxFirstStep};306 p1.y = Math.min(p1.y, firstEnd.y);//åæé«çä¸ä¸ªç¹307 firstEnd.y = p1.y;308 this.points.push(p1);309 break;310 }311 //ç»æä½å¨å¾å½¢å³è¾¹312 case 'right': {313 314 //ç»è¿å¾å½¢è¿ç»315 var p1 = {x:firstStart.x, y: startShapeBound.top - maxFirstStep};316 p1.y = Math.min(p1.y, endShapeBound.top - maxFirstStep);317 var p2 = {x: firstEnd.x, y: p1.y};318 this.points.push(p1, p2);319 break;320 }321 //ç»æä½å¨å¾å½¢åºé¨322 //ä»èµ·å§å¾å½¢ä¸è¾¹ç»è¿323 case 'bottom': {324 //ç»è¿å¾å½¢è¿ç»325 var p1 = {x:firstStart.x, y: startShapeBound.bottom + maxFirstStep};326 p1.y = Math.max(p1.y, firstEnd.y);327 firstEnd.y = p1.y;328 this.points.push(p1);329 break;330 }331 }332 }333 //èµ·å§ä½å¨å¾å½¢ä¸è¾¹334 else if(this.start.pos == 'top') {335 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿336 switch(this.end.pos) {337 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸338 case 'left': {339 //å¦æç»æä½ç½®ç¦»èµ·å§å¾å½¢å¤ªè¿ï¼åéä¸ä½340 var foffx = end.x - startShapeBound.right;341 firstEnd.x = startShapeBound.right + foffx/2342 343 //ç»è¿åºé¨344 var p1 = {x:firstEnd.x, y: firstStart.y};345 this.points.push(p1);346 break;347 }348 //ç»æç¹å¨å¾å½¢ä¸æ¹349 case 'top': {350 //ç´è¿å移ç¹å³å¯351 firstStart.y = firstEnd.y = Math.min(firstStart.y, firstEnd.y);352 break;353 }354 //ç»æä½å¨å¾å½¢å³è¾¹355 case 'right': { 356 //ç»è¿å¾å½¢è¿ç»357 var p1 = {x:firstStart.x, y: startShapeBound.top - maxFirstStep};358 p1.y = Math.min(p1.y, endShapeBound.top - maxFirstStep);359 var p2 = {x: firstEnd.x, y: p1.y};360 this.points.push(p1, p2);361 break;362 }363 //ç»æä½å¨å¾å½¢åºé¨364 //ä»èµ·å§å¾å½¢ä¸è¾¹ç»è¿365 case 'bottom': { 366 //ç»è¿å¾å½¢è¿ç»367 var p1 = {x: firstStart.x/2 + firstEnd.x/2, y: firstStart.y};368 var p2 = {x: p1.x, y: firstEnd.y};369 //äºè
太è¿ï¼åç´è¿370 if(startShapeBound.right <= endShapeBound.left) {371 firstStart.y = p1.y = start.y;372 firstEnd.y = p2.y = end.y;373 }374 this.points.push(p1,p2);375 break;376 }377 }378 }379 //èµ·å§ä½å¨å¾å½¢å³è¾¹380 else if(this.start.pos == 'right') {381 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿382 switch(this.end.pos) {383 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸384 case 'left': {385 //ç´è¿386 firstStart.x = start.x;387 firstEnd.x = end.x;388 break;389 }390 //ç»æç¹å¨å¾å½¢ä¸æ¹391 case 'top': {392 //ä»ä¸çº¿ç»ä¸è¿393 firstStart.x = endShapeBound.left/2 + startShapeBound.right/2;394 var p1 = {x: firstStart.x, y: firstEnd.y};395 //å¦æè¿çº¿å¨èµ·å§å¾å½¢å
äºï¼åç´è¿396 if(firstStart.x <= startShapeBound.right) {397 firstStart.x = start.x;398 p1.y = firstEnd.y = end.y;399 }400 this.points.push(p1);401 break;402 }403 //ç»æä½å¨å¾å½¢å³è¾¹404 case 'right': { 405 //ä»ä¸çº¿ç»ä¸è¿406 firstStart.x = endShapeBound.left/2 + startShapeBound.right/2;407 var p1 = {x: firstStart.x, y: endShapeBound.top - maxFirstStep};408 var p2 = {x: firstEnd.x, y: p1.y};409 //å¦æè¿çº¿å¨èµ·å§å¾å½¢å
äºï¼åç´è¿410 if(firstStart.x <= startShapeBound.right) {411 firstStart.x = p1.x = start.x;412 firstEnd.x = p2.x = end.x; 413 p1.y = p2.y = end.y;414 }415 this.points.push(p1, p2);416 break;417 }418 //ç»æä½å¨å¾å½¢åºé¨419 //ä»èµ·å§å¾å½¢ä¸è¾¹ç»è¿420 case 'bottom': { 421 //ä»ä¸çº¿ç»ä¸è¿422 firstStart.x = endShapeBound.left/2 + startShapeBound.right/2;423 var p1 = {x: firstStart.x, y: firstEnd.y};424 //å¦æè¿çº¿å¨èµ·å§å¾å½¢å
äºï¼åç´è¿425 if(firstStart.x <= startShapeBound.right) {426 firstStart.x = p1.x = start.x;427 firstEnd.y = end.y; 428 }429 this.points.push(p1);430 break;431 }432 }433 }434 //èµ·å§ä½å¨å¾å½¢åº è¾¹435 else if(this.start.pos == 'bottom') {436 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿437 switch(this.end.pos) {438 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸439 case 'left': {440 //å离åºé¨åèµ°ä¸çº¿è¿æ¥441 var p1 = {x: endShapeBound.left/2 + startShapeBound.right/2, y: firstStart.y};442 if(p1.x <= startShapeBound.right) {443 firstStart.y = p1.y = start.y;444 firstEnd.x = p1.x = end.x;445 }446 firstEnd.x = p1.x;447 this.points.push(p1);448 break;449 }450 //ç»æç¹å¨å¾å½¢ä¸æ¹451 case 'top': { 452 var p1 = {x: endShapeBound.left/2 + startShapeBound.right/2, y: firstStart.y};453 //太è¿åä»åºé¨ç»è¿å»454 if(p1.x <= startShapeBound.right) {455 p1.y = firstStart.y = Math.max(firstStart.y, endShapeBound.y + maxFirstStep);456 p1.x = endShapeBound.right + maxFirstStep; 457 }458 var p2 = {x: p1.x, y: firstEnd.y}; 459 this.points.push(p1,p2);460 break;461 }462 //ç»æä½å¨å¾å½¢å³è¾¹463 case 'right': { 464 //ä»åºé¨ç»è¿å»465 firstStart.y = Math.max(firstStart.y, endShapeBound.y + maxFirstStep);466 var p1 = {x: firstEnd.x, y: firstStart.y}; 467 this.points.push(p1);468 break;469 }470 //ç»æä½å¨å¾å½¢åºé¨471 case 'bottom': { 472 firstStart.y = firstEnd.y;473 break;474 }475 }476 }477 }478 //å¾å½¢è¿å¾å½¢ä»å³å左水平æ¹ä½479 function shape2ShapeRight2Left(start, end, firstStart, firstEnd, maxFirstStep) { 480 //èµ·å§å¾å½¢çè¾¹çä¿¡æ¯481 var startShapeBound = this.start.parent.getBounds();482 var endShapeBound = this.end.parent.getBounds();483 //èµ·å§ç¹ä¸ºå¾å½¢ç左侧 484 if(this.start.pos == 'left') {485 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿486 switch(this.end.pos) {487 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸ï¼å¯¼çº¿éè¦ç»è¿èµ·å§å¾å½¢488 case 'left': {489 //ç»è¿æè¿çä¸ä¸ªé¡¶é¨æåºé¨490 firstStart.x = endShapeBound.right + maxFirstStep;491 var p1 = {x: firstStart.x, y: endShapeBound.top - maxFirstStep};492 //å¦æè¶
è¿äºèµ·å§ç¹ï¼åç´è¿å³å¯493 if(firstStart.x >= start.x) {494 p1.y = firstStart.y;495 firstStart.x = start.x;496 firstEnd.x = end.x;497 }498 var p2 = {x: firstEnd.x, y: p1.y};499 this.points.push(p1);500 break;501 }502 //ç»æç¹å¨å¾å½¢ä¸æ¹503 case 'top': {504 //ç»è¿å¾å½¢è¿ç»505 firstStart.x = endShapeBound.right + maxFirstStep;506 //å¦æç»è¿ç»æå¾å½¢çXä½è¶
è¿èµ·å§Xä½ï¼åéç¨èµ·å§Xä½507 if(firstStart.x >= start.x) {508 firstStart.x = start.x;509 }510 var p1 = {x:firstStart.x, y: firstEnd.y};511 512 this.points.push(p1);513 break;514 }515 //ç»æä½å¨å¾å½¢å³è¾¹516 case 'right': { 517 //è¿éå¥é½ä¸ç¨å¹²ï¼ç´è¿ 518 firstStart.x = firstEnd.x = start.x; 519 break;520 }521 //ç»æä½å¨å¾å½¢åºé¨522 //ä»èµ·å§å¾å½¢ä¸è¾¹ç»è¿523 case 'bottom': {524 //ç»è¿å¾å½¢è¿ç»525 firstStart.x = endShapeBound.right + maxFirstStep;526 //å¦æç»è¿ç»æå¾å½¢çXä½è¶
è¿èµ·å§Xä½ï¼åéç¨èµ·å§Xä½527 if(firstStart.x >= start.x) {528 firstStart.x = start.x;529 firstEnd.x = start.x;530 }531 var p1 = {x:firstStart.x, y: firstEnd.y};532 533 this.points.push(p1);534 break;535 }536 }537 }538 //èµ·å§ä½å¨å¾å½¢ä¸è¾¹539 else if(this.start.pos == 'top') {540 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿541 switch(this.end.pos) {542 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸543 case 'left': {544 firstStart.y = Math.min(firstStart.y, endShapeBound.right + maxFirstStep);545 //ç»è¿é¡¶é¨546 var p1 = {x:firstEnd.x, y: firstStart.y}; 547 //å¦æèµ·å§ä½å°äºç»æå¾å½¢å³ä¾§ï¼åç´è¿548 if(firstStart.x <= endShapeBound.right) {549 firstStart.y = start.y;550 firstEnd.x = start.x;551 p1 = start;552 } 553 554 this.points.push(p1);555 break;556 }557 //ç»æç¹å¨å¾å½¢ä¸æ¹558 case 'top': {559 //ç´è¿å移ç¹å³å¯560 firstStart.y = firstEnd.y = Math.min(firstStart.y, firstEnd.y);561 break;562 }563 //ç»æä½å¨å¾å½¢å³è¾¹564 case 'right': { 565 //ä»äºå¾ä¹é´ç空éè¿æ¥566 var p1 = {x: firstEnd.x, y: firstStart.y};567 //å¦æ转æå¤å¤ªé è¿èµ·å§å¾å½¢ï¼åç´è¿568 if(p1.x >= startShapeBound.left) {569 p1.y = firstStart.y = start.y;570 firstEnd.x = p1.x = start.x;571 }572 this.points.push(p1);573 break;574 }575 //ç»æä½å¨å¾å½¢åºé¨576 //ä»èµ·å§å¾å½¢ä¸è¾¹ç»è¿577 case 'bottom': { 578 //ä»äºå¾ä¹é´ç空éè¿æ¥579 var p1 = {x: endShapeBound.right + maxFirstStep, y: firstStart.y};580 this.points.push(p1);581 //å¦æ转æå¤å¤ªé è¿èµ·å§å¾å½¢ï¼åç´è¿582 if(p1.x >= startShapeBound.left) {583 p1.y = firstStart.y = start.y;584 firstEnd.x = p1.x = start.x;585 firstEnd.y = p1.y;586 587 }588 else {589 var p2 = {x: p1.x, y:firstEnd.y};590 this.points.push(p2);591 }592 break;593 }594 }595 }596 //èµ·å§ä½å¨å¾å½¢å³è¾¹597 else if(this.start.pos == 'right') {598 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿599 switch(this.end.pos) {600 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸601 case 'left': {602 //ç»è¿äºä¸ªå¾å½¢603 //ä»é¡¶é¨ç»è¿604 var p1 = {x: firstStart.x, y: Math.min(startShapeBound.top - maxFirstStep, endShapeBound.top - maxFirstStep)};605 var p2 = {x: firstEnd.x, y: p1.y};606 this.points.push(p1,p2);607 break;608 }609 //ç»æç¹å¨å¾å½¢ä¸æ¹610 case 'top': {611 //ç»è¿èµ·å§å¾å½¢ä¸æ¹612 var p1 = {x: firstStart.x, y: startShapeBound.top - maxFirstStep};613 p1.y = firstEnd.y = Math.min(p1.y, firstEnd.y);614 this.points.push(p1);615 break;616 }617 //ç»æä½å¨å¾å½¢å³è¾¹618 case 'right': { 619 var p1 = {x: firstStart.x, y: startShapeBound.top - maxFirstStep};620 var p2 = {x: firstEnd.x, y: p1.y};621 //å¦æç»çº¿å¨èµ·å§ç¹å·¦ä¾§å¤ªè¿ï¼åç´è¿622 if(p2.x >= startShapeBound.left) {623 p1.y = p2.y = firstStart.y;624 p2.x = firstEnd.x = p1.x;625 }626 this.points.push(p1, p2);627 break;628 }629 //ç»æä½å¨å¾å½¢åºé¨630 case 'bottom': { 631 //ç»è¿èµ·å§å¾å½¢ä¸æ¹632 var p1 = {x: firstStart.x, y: startShapeBound.bottom + maxFirstStep};633 p1.y = firstEnd.y = Math.max(p1.y, firstEnd.y);634 this.points.push(p1);635 break;636 }637 }638 }639 //èµ·å§ä½å¨å¾å½¢åº è¾¹640 else if(this.start.pos == 'bottom') {641 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿642 switch(this.end.pos) {643 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸644 case 'left': {645 //å离åºé¨646 firstStart.y = Math.max(firstStart.y, endShapeBound.bottom + maxFirstStep);647 var p1 = {x: firstEnd.x, y: firstStart.y};648 this.points.push(p1);649 break;650 }651 //ç»æç¹å¨å¾å½¢ä¸æ¹652 case 'top': { 653 //ä»äºå¾å½¢ä¸é´è¿å»ï¼å¦æ太è¿å°±å¾å¤ç» 654 var p1 = {x: startShapeBound.left/2 + endShapeBound.right/2, y: firstStart.y};655 //太è¿åä»åºé¨ç»è¿å»656 if(p1.x >= startShapeBound.left || p1.x <= endShapeBound.right) {657 p1.x = Math.max(startShapeBound.right + maxFirstStep, endShapeBound.right + maxFirstStep);658 firstEnd.y = Math.min(firstEnd.y, startShapeBound.top - maxFirstStep);659 }660 661 var p2 = {x: p1.x, y: firstEnd.y}; 662 this.points.push(p1,p2);663 break;664 }665 //ç»æä½å¨å¾å½¢å³è¾¹666 case 'right': { 667 //ä»ä¸é´è¿çº¿668 var p1 = {x: firstEnd.x, y: firstStart.y}; 669 //太è¿åç´è¿670 if(p1.x >= startShapeBound.left || p1.x <= endShapeBound.right) {671 p1.x = firstEnd.x = start.x;672 p1.y = firstStart.y= firstEnd.y = start.y;673 } 674 this.points.push(p1);675 break;676 }677 //ç»æä½å¨å¾å½¢åºé¨678 case 'bottom': { 679 firstStart.y = firstEnd.y = Math.max(firstStart.y, firstEnd.y);680 break;681 }682 }683 }684 }685 //å¾å½¢è¿å¾å½¢ä»ä¸åä¸åç´æ¹ä½686 function shape2ShapeTop2Bottom(start, end, firstStart, firstEnd, maxFirstStep) { 687 //èµ·å§å¾å½¢çè¾¹çä¿¡æ¯688 var startShapeBound = this.start.parent.getBounds();689 var endShapeBound = this.end.parent.getBounds();690 //èµ·å§ç¹ä¸ºå¾å½¢ç左侧 691 if(this.start.pos == 'left') {692 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿693 switch(this.end.pos) {694 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸695 case 'left': {696 //ä¸éè¦åä»»ä½äºä»¶ï¼ç´æ¥è¿æ¥å移ç¹697 firstStart.x = start.x;698 //ç»æç¹çå移ç¹ä¹å¾ç§»å°èµ·å§ç¹699 firstEnd.y = start.y;700 break;701 }702 //ç»æç¹å¨å¾å½¢ä¸æ¹703 case 'top': {704 var p1 = {x: firstStart.x, y: firstEnd.y};705 //å¦æä¸ä¸ç¦»å¤ªè¿ï¼åç´è¿706 if(firstEnd.y <= startShapeBound.bottom) {707 firstStart.x = p1.x = start.x;708 firstEnd.y = p1.y = start.y;709 }710 this.points.push(p1);711 break;712 }713 //ç»æä½å¨å¾å½¢å³è¾¹714 case 'right': { 715 //å¦æå¾å½¢è·ç¦»å¤è¿ï¼åä¹åç¸è¿716 if(startShapeBound.bottom <= endShapeBound.top - maxFirstStep) {717 var p1 = {x: firstStart.x, y: startShapeBound.bottom/2+endShapeBound.top/2};718 var p2 = {x: firstEnd.x, y: p1.y};719 this.points.push(p1, p2);720 }721 else {722 //ç´è¿723 firstEnd.x = firstStart.x = start.x;724 firstEnd.y = firstStart.y;725 } 726 break;727 }728 //ç»æä½å¨å¾å½¢åºé¨729 //ä»èµ·å§å¾å½¢ä¸è¾¹ç»è¿730 case 'bottom': {731 //å¦æèµ·å§ç¹ç¦»ç»æå¾å½¢é¡¶é¨å¤è·ç¦»ï¼åç»è¿ç»æå¾å½¢732 if(start.y <= endShapeBound.top - maxFirstStep) {733 firstStart.x = Math.min(firstStart.x, endShapeBound.left - maxFirstStep);734 var p1 = {x: firstStart.x, y: firstEnd.y};735 this.points.push(p1);736 }737 else {738 //ç´è¿739 firstStart.x = start.x;740 firstEnd.y = start.y;741 }742 break;743 }744 }745 }746 //èµ·å§ä½å¨å¾å½¢ä¸è¾¹747 else if(this.start.pos == 'top') {748 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿749 switch(this.end.pos) {750 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸751 case 'left': { 752 //ç»è¿é¡¶é¨753 var p1 = {x:startShapeBound.left - maxFirstStep, y: firstStart.y};754 //æ左侧åç»æç¹å移ä½åèµ·å§å¾å½¢å·¦ä¾§ æå·¦çå¼755 p1.x = firstEnd.x = Math.min(p1.x,firstEnd.x); 756 this.points.push(p1);757 break;758 }759 //ç»æç¹å¨å¾å½¢ä¸æ¹760 case 'top': {761 //太è¿åç´è¿762 if(endShapeBound.top <= startShapeBound.bottom + maxFirstStep) {763 firstStart.y = firse.y = start.y;764 }765 else {766 //ä»å·¦ä¾§ç»è¿èµ·å§å¾å½¢767 var p1 = {x: startShapeBound.x - maxFirstStep, y: firstStart.y};768 var p2 = {x: p1.x, y: firstEnd.y};769 this.points.push(p1,p2); 770 }771 break;772 }773 //ç»æä½å¨å¾å½¢å³è¾¹774 case 'right': { 775 var p1 = {x: Math.max(startShapeBound.right + maxFirstStep, firstEnd.x), y: firstStart.y}; 776 firstEnd.x = p1.x;777 this.points.push(p1);778 break;779 }780 //ç»æä½å¨å¾å½¢åºé¨781 case 'bottom': { 782 //ä»å³ä¾§ç»å°åºé¨783 var p1 = {x: Math.max(startShapeBound.right + maxFirstStep, endShapeBound.right + maxFirstStep), y: firstStart.y};784 var p2 = {x: p1.x, y: firstEnd.y};785 this.points.push(p1, p2);786 break;787 }788 }789 }790 //èµ·å§ä½å¨å¾å½¢å³è¾¹791 else if(this.start.pos == 'right') {792 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿793 switch(this.end.pos) {794 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸795 case 'left': {796 var p1 = {x: firstStart.x, y: endShapeBound.top - maxFirstStep}; 797 //太è¿ååä¸ä½èµ°ï¼å¦åè´´è¿ç»æå¾å½¢798 if(startShapeBound.bottom >= p1.y) {799 p1.y = end.y /2 + start.y/2;800 }801 var p2 = {x: firstEnd.x, y: p1.y};802 this.points.push(p1, p2);803 break;804 }805 //ç»æç¹å¨å¾å½¢ä¸æ¹806 case 'top': {807 //太è¿ç´è¿808 if(start.y >= firstEnd.y - maxFirstStep) {809 firstStart.x = start.x;810 firstEnd.y = start.y;811 }812 else {813 var p1 = {x: firstStart.x, y: firstEnd.y};814 this.points.push(p1);815 } 816 break;817 }818 //ç»æä½å¨å¾å½¢å³è¾¹819 case 'right': { 820 //å移ç¹ç´è¿ï¼å¥ä¹ä¸ç¨å821 break;822 }823 //ç»æä½å¨å¾å½¢åºé¨824 case 'bottom': { 825 //ç»è¿ç»æå¾å½¢å³ä¾§826 firstStart.x = Math.max(firstStart.x, startShapeBound.right + maxFirstStep);827 var p1 = {x: firstStart.x, y: firstEnd.y};828 this.points.push(p1);829 break;830 }831 }832 }833 //èµ·å§ä½å¨å¾å½¢åº è¾¹834 else if(this.start.pos == 'bottom') {835 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿836 switch(this.end.pos) {837 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸838 case 'left': {839 //ç»æå¾å½¢é¡¶é¨å移ä½ç½®è½¬æ840 firstStart.y = Math.max(firstStart.y, endShapeBound.top - maxFirstStep);841 var p1 = {x: firstEnd.x, y: firstStart.y};842 this.points.push(p1);843 break;844 }845 //ç»æç¹å¨å¾å½¢ä¸æ¹846 case 'top': { 847 //ç´è¿848 firstStart.y = start.y;849 firstEnd.y = end.y;850 break;851 }852 //ç»æä½å¨å¾å½¢å³è¾¹853 case 'right': { 854 //ç»æå¾å½¢é¡¶é¨å移ä½ç½®è½¬æ855 firstStart.y = Math.max(firstStart.y, endShapeBound.top - maxFirstStep);856 var p1 = {x: firstEnd.x, y: firstStart.y};857 this.points.push(p1);858 break;859 }860 //ç»æä½å¨å¾å½¢åºé¨861 case 'bottom': { 862 //å¦æä¸ä¸å¤ªè¿ï¼åç´è¿863 if(firstStart.y >= endShapeBound.top) {864 firstStart.y = firstEnd.y = start.y;865 }866 else {867 //ä»ç»æå¾å½¢å³ä¾§ç»è¿å»868 var p1 = {x: endShapeBound.right + maxFirstStep, y: firstStart.y};869 var p2 = {x: p1.x, y: firstEnd.y};870 this.points.push(p1, p2);871 }872 873 break;874 }875 }876 }877 }878 //å¾å½¢è¿å¾å½¢ä»ä¸åä¸åç´æ¹ä½879 function shape2ShapeBottom2Top(start, end, firstStart, firstEnd, maxFirstStep) { 880 //èµ·å§å¾å½¢çè¾¹çä¿¡æ¯881 var startShapeBound = this.start.parent.getBounds();882 var endShapeBound = this.end.parent.getBounds();883 //èµ·å§ç¹ä¸ºå¾å½¢ç左侧 884 if(this.start.pos == 'left') {885 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿886 switch(this.end.pos) {887 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸ï¼ä»å·¦ä¾§å移ä½è¿888 case 'left': {889 //å¥é½ä¸ç¨å890 break;891 }892 //ç»æç¹å¨å¾å½¢ä¸æ¹893 case 'top': {894 //左侧ç»ä¸895 var p1 = {x: endShapeBound.left - maxFirstStep, y: firstEnd.y};896 p1.x = firstStart.x = Math.min(p1.x, firstStart.x);897 //太è¿ç´è¿898 if(endShapeBound.bottom >= start.y) {899 p1.x = firstStart.x = firstEnd.x = start.x;900 p1.y = firstEnd.y = start.y;901 }902 this.points.push(p1);903 break;904 }905 //ç»æä½å¨å¾å½¢å³è¾¹906 case 'right': { 907 //ä¹åè¿908 var p1 = {x: firstStart.x, y: endShapeBound.bottom + maxFirstStep};909 910 //太è¿ï¼åç´è¿911 if(p1.y >= startShapeBound.top) {912 p1.x = firstStart.x = firstEnd.x = start.x; 913 p1.y = firstEnd.y = start.y;914 }915 else {916 var p2 = {x: firstEnd.x, y: p1.y};917 this.point.push(p1, p2); 918 } 919 break;920 }921 //ç»æä½å¨å¾å½¢åºé¨922 case 'bottom': {923 var p1 = {x:firstStart.x, y: firstEnd.y};924 if(p1.y >= startShapeBound.top) {925 p1.y = firstEnd.y = start.y;926 p1.x = firstStart.x = firstEnd.x = start.x;927 }928 this.points.push(p1);929 break;930 }931 }932 }933 //èµ·å§ä½å¨å¾å½¢ä¸è¾¹934 else if(this.start.pos == 'top') {935 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿936 switch(this.end.pos) {937 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸938 case 'left': {939 if(endShapeBound.bottom >= firstStart.y) {940 firstStart.y = firstEnd.y = start.y;941 firstEnd.x = start.x;942 }943 else {944 //离äºäºä¸ªå移éï¼åæ´é è¿ä¸é¢çå¾å½¢945 if(endShapeBound.bottom < firstStart.y - maxFirstStep) {946 firstStart.y = endShapeBound.bottom + maxFirstStep;947 }948 949 var p1 = {x: firstEnd.x, y: firstStart.y};950 this.points.push(p1);951 }952 break;953 }954 //ç»æç¹å¨å¾å½¢ä¸æ¹955 case 'top': {956 if(endShapeBound.bottom >= firstStart.y) {957 firstStart.y = firstEnd.y = start.y;958 firstEnd.x = start.x;959 }960 else {961 //离äºäºä¸ªå移éï¼åæ´é è¿ä¸é¢çå¾å½¢962 if(endShapeBound.bottom < firstStart.y - maxFirstStep) {963 firstStart.y = endShapeBound.bottom + maxFirstStep;964 }965 var p1 = {x: firstEnd.x, y: firstStart.y};966 var p2 = {x: p1.x, y: firstEnd.y};967 this.points.push(p1, p2);968 }969 break;970 }971 //ç»æä½å¨å¾å½¢å³è¾¹972 case 'right': { 973 if(endShapeBound.bottom >= firstStart.y) {974 firstStart.y = firstEnd.y = start.y;975 firstEnd.x = start.x;976 }977 else {978 //离äºäºä¸ªå移éï¼åæ´é è¿ä¸é¢çå¾å½¢979 if(endShapeBound.bottom < firstStart.y - maxFirstStep) {980 firstStart.y = endShapeBound.bottom + maxFirstStep;981 }982 var p1 = {x: firstEnd.x, y: firstStart.y};983 this.points.push(p1);984 }985 break;986 }987 //ç»æä½å¨å¾å½¢åºé¨988 case 'bottom': { 989 //ç´è¿990 firstStart.y = firstEnd.y = start.y;991 break;992 }993 }994 }995 //èµ·å§ä½å¨å¾å½¢å³è¾¹996 else if(this.start.pos == 'right') {997 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿998 switch(this.end.pos) {999 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸1000 case 'left': {1001 var p1 = {x: firstStart.x, y: endShapeBound.bottom + maxFirstStep};1002 //太è¿ï¼åèµ°ä¸çº¿1003 if(startShapeBound.top <= p1.y && startShapeBound.top > endShapeBound.bottom) {1004 p1.y = startShapeBound.top/2 + endShapeBound.bottom/2;1005 }1006 //æç¸äº¤åï¼åç´è¿1007 else if(startShapeBound.top < endShapeBound.bottom) {1008 firstEnd.y = start.y;1009 firstStart.x = firstEnd.x = start.x;1010 break;1011 }1012 1013 var p2 = {x: firstEnd.x, y: p1.y};1014 this.points.push(p1, p2); 1015 break;1016 }1017 //ç»æç¹å¨å¾å½¢ä¸æ¹1018 case 'top': {1019 //èµ°ç»æå¾å½¢å³ä¾§ä¸è¿1020 firstStart.x = Math.max(firstStart.x, endShapeBound.right + maxFirstStep);1021 var p1 = {x: firstStart.x, y: firstEnd.y};1022 this.points.push(p1);1023 break;1024 }1025 //ç»æä½å¨å¾å½¢å³è¾¹1026 case 'right': { 1027 break;1028 }1029 //ç»æä½å¨å¾å½¢åºé¨1030 case 'bottom': { 1031 //å¦æå移ç¹ç¦»èµ·å§å¾å½¢å¤ªè¿ï¼åå空éä¸ä½1032 if(firstEnd.y >= startShapeBound.top) {1033 firstEnd.y = startShapeBound.top/2 + endShapeBound.bottom/2;1034 }1035 var p1 = {x: firstStart.x, y: firstEnd.y};1036 this.points.push(p1);1037 break;1038 }1039 }1040 }1041 //èµ·å§ä½å¨å¾å½¢åºè¾¹1042 else if(this.start.pos == 'bottom') {1043 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿1044 switch(this.end.pos) {1045 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸1046 case 'left': {1047 //å离åºé¨ 1048 var p1 = {x: 0, y: firstStart.y};1049 p1.x = Math.min(firstEnd.x, startShapeBound.left - maxFirstStep);1050 this.points.push(p1);1051 break;1052 }1053 //ç»æç¹å¨å¾å½¢ä¸æ¹1054 case 'top': { 1055 var p1 = {x: 0, y: firstStart.y};1056 p1.x = Math.min(endShapeBound.left - maxFirstStep, startShapeBound.left - maxFirstStep);1057 var p2 = {x: p1.x, y: firstEnd.y};1058 this.points.push(p1, p2);1059 break;1060 }1061 //ç»æä½å¨å¾å½¢å³è¾¹1062 case 'right': { 1063 var p1 = {x: 0, y: firstStart.y};1064 p1.x = Math.min(firstEnd.x, startShapeBound.right + maxFirstStep);1065 this.points.push(p1);1066 break;1067 }1068 //ç»æä½å¨å¾å½¢åºé¨1069 case 'bottom': { 1070 //é太è¿ï¼åç´è¿1071 if(firstEnd.y >= startShapeBound.top) {1072 firstStart.y = firstEnd.y = start.y;1073 }1074 else {1075 var p1 = {x: startShapeBound.left - maxFirstStep, y: firstStart.y};1076 var p2 = {x: p1.x, y: firstEnd.y};1077 this.points.push(p1, p2);1078 } 1079 break;1080 }1081 }1082 }1083 }1084 //å¾å½¢è¿å¾å½¢ä»å³ä¸å¾å·¦ä¸1085 function shape2ShapeRightBottom2LeftTop(start, end, firstStart, firstEnd, maxFirstStep) { 1086 //èµ·å§å¾å½¢çè¾¹çä¿¡æ¯1087 var startShapeBound = this.start.parent.getBounds();1088 var endShapeBound = this.end.parent.getBounds();1089 //èµ·å§ç¹ä¸ºå¾å½¢ç左侧 1090 if(this.start.pos == 'left') {1091 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿1092 switch(this.end.pos) {1093 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸ï¼ä»å·¦ä¾§å移ä½è¿1094 case 'left': {1095 //ç´è¿ç»æå¾å½¢å·¦å移ç¹åç´çº¿1096 var p1 = {x: firstEnd.x, y: start.y};1097 this.points.push(p1);1098 break;1099 }1100 //ç»æç¹å¨å¾å½¢ä¸æ¹1101 case 'top': {1102 //å¦æèµ·å§ç¹å·¦å移ç¹å¨ç»æå¾å½¢å³ä¾§åå·¦ï¼åä»ç»æå¾å½¢å·¦ä¾§ç»è¿1103 //å¦åä»å³ä¾§ç»è¿1104 var p1 = {x: endShapeBound.right + maxFirstStep, y: firstEnd.y};1105 if(firstStart.x < p1.x) {1106 p1.x = endShapeBound.left - maxFirstStep;1107 if(firstStart.y <= endShapeBound.bottom) {1108 p1.x = firstEnd.x = start.x;1109 p1.y = firstEnd.y = start.y;1110 }1111 }1112 firstStart.x = p1.x;1113 this.points.push(p1);1114 break;1115 }1116 //ç»æä½å¨å¾å½¢å³è¾¹1117 case 'right': { 1118 //åªè¦ä¸æ¯å¤ªè¿ï¼å°±èµ°è´´è¿ç»æå¾å½¢å³ä¾§ï¼å¦åä¸çº¿ 1119 if(firstStart.x < firstEnd.x) {1120 firstStart.x = firstEnd.x / 2 + firstStart.x / 2;1121 firstEnd.x = firstStart.x;1122 }1123 else {1124 firstStart.x = firstEnd.x;1125 }1126 break;1127 }1128 //ç»æä½å¨å¾å½¢åºé¨1129 case 'bottom': {1130 firstStart.x = firstEnd.x;1131 firstEnd.y = Math.min(firstStart.y, firstEnd.y);1132 break;1133 }1134 }1135 }1136 //èµ·å§ä½å¨å¾å½¢ä¸è¾¹1137 else if(this.start.pos == 'top') {1138 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿1139 switch(this.end.pos) {1140 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸1141 case 'left': { 1142 //å¦æä¸ä¸å¤ªè¿ï¼åä»ç»æå¾å½¢é¡¶é¨ç»è¿1143 if(firstStart.y < endShapeBound.bottom) {1144 //å¦æ交Xï¼åç´è¿1145 if(firstStart.x <= endShapeBound.right) {1146 firstEnd.x = end.x;1147 firstStart.y = end.y;1148 }1149 //ä»é¡¶é¨ç»1150 else {1151 firstStart.y = Math.min(firstStart.y, endShapeBound.top - maxFirstStep);1152 var p1 = {x: firstEnd.x, y: firstStart.y};1153 this.points.push(p1);1154 }1155 }1156 else {1157 var p1 = {x: firstEnd.x, y: firstStart.y};1158 this.points.push(p1);1159 }1160 break;1161 }1162 //ç»æç¹å¨å¾å½¢ä¸æ¹1163 case 'top': {1164 //èµ·ç¹ä¸ç»æå¾å½¢X轴交X1165 if(firstStart.x <= endShapeBound.right) {1166 //èä¸Y轴交Xï¼åç´è¿1167 if(firstStart.y <= endShapeBound.bottom) {1168 firstEnd.y = firstStart.y = start.y;1169 firstEnd.x = start.x;1170 }1171 else {1172 var p1 = {x: endShapeBound.right + maxFirstStep, y: firstStart.y};1173 var p2 = {x: p1.x, y: firstEnd.y};1174 this.point.push(p1, p2);1175 }1176 }1177 else {1178 firstStart.y = firstEnd.y;1179 }1180 break;1181 }1182 //ç»æä½å¨å¾å½¢å³è¾¹1183 case 'right': { 1184 firstStart.y = Math.max(firstEnd.y, firstStart.y);1185 firstEnd.x = Math.min(firstEnd.x, firstStart.x);1186 break;1187 }1188 //ç»æä½å¨å¾å½¢åºé¨1189 case 'bottom': { 1190 firstStart.y = firstEnd.y = Math.max(firstEnd.y, firstStart.y);1191 break;1192 }1193 }1194 }1195 //èµ·å§ä½å¨å¾å½¢å³è¾¹ TODO::1196 else if(this.start.pos == 'right') {1197 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿1198 switch(this.end.pos) {1199 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸1200 case 'left': {1201 var p1 = {x: firstStart.x, y: endShapeBound.bottom + maxFirstStep};1202 //太è¿ï¼åèµ°ä¸çº¿1203 if(startShapeBound.top <= p1.y && startShapeBound.top > endShapeBound.bottom) {1204 p1.y = startShapeBound.top/2 + endShapeBound.bottom/2;1205 }1206 //æç¸äº¤åï¼åç´è¿1207 else if(startShapeBound.top < endShapeBound.bottom) {1208 firstEnd.y = start.y;1209 firstStart.x = firstEnd.x = start.x;1210 break;1211 }1212 1213 var p2 = {x: firstEnd.x, y: p1.y};1214 this.points.push(p1, p2); 1215 break;1216 }1217 //ç»æç¹å¨å¾å½¢ä¸æ¹1218 case 'top': {1219 //èµ°ç»æå¾å½¢å³ä¾§ä¸è¿1220 firstStart.x = Math.max(firstStart.x, endShapeBound.right + maxFirstStep);1221 var p1 = {x: firstStart.x, y: firstEnd.y};1222 this.points.push(p1);1223 break;1224 }1225 //ç»æä½å¨å¾å½¢å³è¾¹1226 case 'right': { 1227 break;1228 }1229 //ç»æä½å¨å¾å½¢åºé¨1230 case 'bottom': { 1231 //å¦æå移ç¹ç¦»èµ·å§å¾å½¢å¤ªè¿ï¼åå空éä¸ä½1232 if(firstEnd.y >= startShapeBound.top) {1233 firstEnd.y = startShapeBound.top/2 + endShapeBound.bottom/2;1234 }1235 var p1 = {x: firstStart.x, y: firstEnd.y};1236 this.points.push(p1);1237 break;1238 }1239 }1240 }1241 //èµ·å§ä½å¨å¾å½¢åºè¾¹1242 else if(this.start.pos == 'bottom') {1243 //ç¶åæ ¹æ®ç»æç¹çæ¹ä½æ¥è¿çº¿1244 switch(this.end.pos) {1245 //ç»æç¹ä¸ºå·¦ä¾§çæ
åµä¸1246 case 'left': {1247 //å离åºé¨ 1248 var p1 = {x: 0, y: firstStart.y};1249 p1.x = Math.min(firstEnd.x, startShapeBound.left - maxFirstStep);1250 this.points.push(p1);1251 break;1252 }1253 //ç»æç¹å¨å¾å½¢ä¸æ¹1254 case 'top': { 1255 var p1 = {x: 0, y: firstStart.y};1256 p1.x = Math.min(endShapeBound.left - maxFirstStep, startShapeBound.left - maxFirstStep);1257 var p2 = {x: p1.x, y: firstEnd.y};1258 this.points.push(p1, p2);1259 break;1260 }1261 //ç»æä½å¨å¾å½¢å³è¾¹1262 case 'right': { 1263 var p1 = {x: 0, y: firstStart.y};1264 p1.x = Math.min(firstEnd.x, startShapeBound.right + maxFirstStep);1265 this.points.push(p1);1266 break;1267 }1268 //ç»æä½å¨å¾å½¢åºé¨1269 case 'bottom': { 1270 //é太è¿ï¼åç´è¿1271 if(firstEnd.y >= startShapeBound.top) {1272 firstStart.y = firstEnd.y = start.y;1273 }1274 else {1275 var p1 = {x: startShapeBound.left - maxFirstStep, y: firstStart.y};1276 var p2 = {x: p1.x, y: firstEnd.y};1277 this.points.push(p1, p2);1278 } 1279 break;1280 }1281 }1282 }1283 }1284 /**1285 * éåæ§ä»¶ç§»å¨äºä»¶1286 */1287 this.offset = function(offx, offy, trans) {1288 1289 //å¦ææ¯å
ç´ çè¿æ¥ç¹ï¼ååå
¶ä¸å¿1290 if(this.start.type == 'jmConnectPoint') {1291 this.start = jmUtils.clone(this.start.getCenter(true, true));1292 }1293 if(this.end.type == 'jmConnectPoint') {1294 this.end = jmUtils.clone(this.end.getCenter(true, true));1295 }1296 this.start.x += offx;1297 this.start.y += offy,1298 this.end.x += offx;1299 this.end.y += offy;1300 //触åæ§ä»¶ç§»å¨äºä»¶ 1301 this.emit('move',{offsetX:offx,offsetY:offy,trans:trans});1302 }1303 //éä¸å½åå¾å½¢1304 this.on('select', function(selected){ 1305 this.startDragShape.visible = selected;1306 this.endDragShape.visible = selected; 1307 //å½éä¸æ¶ï¼å±çº§ç½®é¡¶ 1308 if(selected) {1309 this.lastZIndex = this.style.zIndex;1310 this.style.zIndex = 10000;1311 }1312 else {1313 this.style.zIndex = this.lastZIndex;1314 }1315 });1316 //é¼ æ è¿å
¥æ¶æ¾ç¤ºå¯ç§»å¨1317 this.bind('mouseover', function(){1318 this.cursor('move');1319 });1320 this.bind('mouseleave', function(){1321 this.cursor('default');1322 });1323 //å½å线æ¡ç§»å¨åï¼è§¦åå
¶å®å
ç´ æ¾ç¤ºç¶æ1324 this.on('move', function(e){1325 this.checkConnectPointsStatus(); 1326 });1327 this.on('moveend', function(e){1328 this.checkConnectPointsStatus(true, function(start, end) {1329 if(start) this.start = start;1330 if(end) this.end = end;1331 });1332 });1333 //æ£æ¥å½åè·è¿æ¥ç¹æ
åµï¼æ¾ç¤ºå¯è¿æç¦ç¹1334 //hide 强å¶æå®æ¯éæè¿æ¥ç¹1335 this.checkConnectPointsStatus = function(hide, callback) {1336 var minLen = 80;//æå®è§¦åé è¿çè·ç¦»1337 var self = this;1338 //è¿æ¥çº¿äºå¤´åä¸çè¿æ¥ç¹1339 var startPoint = null;1340 var endPoint = null;1341 this.editor.cells.each(function(i,cell) {1342 if(cell.type == 'baseFlow_polyarrow') return;1343 1344 var start = self.start;1345 var end = self.end;1346 //å¦ææ¯å
ç´ çè¿æ¥å ï¼ååå
¶ä¸å¿1347 if(start.type == 'jmConnectPoint') {1348 start = start.getCenter(true, true);1349 }1350 if(end.type == 'jmConnectPoint') {1351 end = end.getCenter(true, true);1352 }1353 var o = !hide && (cell.checkPoint(start, minLen) || cell.checkPoint(end, minLen));//èµ·ç¹æç»ç¹æ¯å¦è¿å
¥äºå¾å½¢1354 //å¦æä¸å¨å¾å½¢å
ï¼å计ç®å°å®æ¯ä¸ªè¿æ¥ç¹çè·ç¦»ï¼å¦æè¿ä¹è®¤ä¸ºå¯ä»¥åºç°è¿æ¥ç¹1355 if(cell.connectPoints) {1356 var loc = cell.getLocation();1357 for(var i = cell.connectPoints.length - 1;i >= 0;i--) {1358 var c = cell.connectPoints[i];1359 var center = c.getCenter(true, true);//è·åç»å¯¹ä¸å¿ä½ç½®1360 var r = jmUtils.getDistance(start, center);//计ç®èµ·ç¹è·ç¦»1361 if(r <= minLen) {1362 o = !hide;1363 //å¦æè¿å
¥è¿æ¥ç¹ï¼åé«äº®æ¾ç¤º1364 if(r < c.width*2) {1365 c.sideShape.visible = o;1366 startPoint = c;1367 }1368 else {1369 c.sideShape.visible = false;1370 }1371 }1372 r = jmUtils.getDistance(end, center);//计ç®ç¦»ç»æç¹è·ç¦»1373 if(r <= minLen) {1374 o = !hide;1375 //å¦æè¿å
¥è¿æ¥ç¹ï¼åé«äº®æ¾ç¤º1376 if(r < c.width*2) {1377 c.sideShape.visible = o;1378 endPoint = c;1379 }1380 else {1381 c.sideShape.visible = false;1382 }1383 }1384 } 1385 }1386 1387 cell.connectPointsVisible&&cell.connectPointsVisible(o);1388 });1389 callback && callback.call(this, startPoint, endPoint);1390 }1391 }1392 //å¾åç±»åå1393 shapeType.prototype.type = stName;1394 shapeType.ico = 'img/shapes/baseflow/polyarrow.png';1395 shapeType.nickName = 'å¨æè¿çº¿';1396 jmDraw.shapeTypes[stName] = shapeType; //ææªå°jmDrawä¸...
chronoDateManipulation.test.js
Source:chronoDateManipulation.test.js
1import test from 'tape'2import chrono from 'chrono-node'3import { add, subtract } from '../../helpers/chronoDateManipulation'4test('add increment to each unit of time', t => {5 // Test will compare difference against initial start date of6 // Feb 15, 2016 12:30:307 const result = chrono.parse('12:30:30pm-2pm', new Date('Feb 15, 2016 00:00:00'))8 const firstStart = result[0].start9 add(1, 'year', firstStart)10 add(1, 'month', firstStart)11 add(1, 'day', firstStart)12 add(1, 'hour', firstStart)13 add(15, 'minute', firstStart)14 add(15, 'second', firstStart)15 add(500, 'millisecond', firstStart)16 t.equals(firstStart.get('year'), 2017, 'Year incremented properly')17 t.equals(firstStart.get('month'), 3, 'Month incremented properly')18 t.equals(firstStart.get('day'), 16, 'Day incremented properly')19 t.equals(firstStart.get('hour'), 13, 'Hour incremented properly')20 t.equals(firstStart.get('minute'), 45, 'Minute incremented properly')21 t.equals(firstStart.get('second'), 45, 'Second incremented properly')22 t.equals(firstStart.get('millisecond'), 500, 'Millisecond incremented properly')23 t.end()24})25test('meridiem is updated correctly when adding', t => {26 // Test will compare difference against initial start date of27 // Feb 15, 2016 11:30:3028 const result = chrono.parse('11:30:30am-2pm', new Date('Feb 15, 2016 00:00:00'))29 const firstStart = result[0].start30 add(1, 'hour', firstStart)31 t.equals(firstStart.get('meridiem'), 1, 'Meridiem updated properly')32 t.end()33})34test('subtract amount to each unit of time', t => {35 // Test will compare difference against initial start date of36 // Feb 15, 2016 12:30:3037 const result = chrono.parse('12:30:30pm-2pm', new Date('Feb 15, 2016 00:00:00'))38 const firstStart = result[0].start39 subtract(1, 'year', firstStart)40 subtract(1, 'month', firstStart)41 subtract(1, 'day', firstStart)42 subtract(1, 'hour', firstStart)43 subtract(15, 'minute', firstStart)44 subtract(15, 'second', firstStart)45 subtract(500, 'millisecond', firstStart)46 t.equals(firstStart.get('year'), 2015, 'Year decremented properly')47 t.equals(firstStart.get('month'), 1, 'Month decremented properly')48 t.equals(firstStart.get('day'), 14, 'Day decremented properly')49 t.equals(firstStart.get('hour'), 11, 'Hour decremented properly')50 t.equals(firstStart.get('minute'), 15, 'Minute decremented properly')51 // Note: Since we are also subtracting 500 milliseconds, second will be 1452 // instead of 15.53 t.equals(firstStart.get('second'), 14, 'Second decremented properly')54 t.equals(firstStart.get('millisecond'), 500, 'Millisecond decremented properly')55 t.end()56})57test('meridiem is updated correctly when subtracting', t => {58 // Test will compare difference against initial start date of59 // Feb 15, 2016 12:30:3060 const result = chrono.parse('12:30:30pm-2pm', new Date('Feb 15, 2016 00:00:00'))61 const firstStart = result[0].start62 subtract(1, 'hour', firstStart)63 t.equals(firstStart.get('meridiem'), 0, 'Meridiem updated properly')64 t.end()...
index.ts
Source:index.ts
1import { Octokit } from '@octokit/core';2import chalk from 'chalk';3import { AsciiText, initialText, linkToPersonalToken } from './constant';4import {5 createLabel,6 createLabels,7 deleteLabel,8 deleteLabels,9} from './lib/callApi';10import { getConfirmation } from './lib/confirmToken';11import { getTargetLabel } from './lib/inputDeleteLabel';12import { getGitHubConfigs } from './lib/inputGitHubConfig';13import { getNewLabel } from './lib/inputNewLabel';14import { selectAction } from './lib/selectPrompts';15import { ConfigType } from './types';16const log = console.log;17let firstStart = true;18// set up configs to access GitHub repo19const setupConfigs = async () => {20 console.log(initialText);21 const resp = await getGitHubConfigs();22 const octokit = new Octokit({23 auth: `${resp.octokit}`,24 });25 return {26 octokit,27 owner: resp.owner,28 repo: resp.repo,29 };30};31// steps32// first call setupConfigs33let configs: ConfigType;34const main = async () => {35 const confirmation = await getConfirmation();36 if (!confirmation) {37 log(38 chalk.redBright(39 `Please go to ${linkToPersonalToken} and generate a personal token!`40 )41 );42 return;43 }44 if (firstStart) {45 log(AsciiText);46 configs = await setupConfigs();47 }48 let selectedIndex = await selectAction();49 while (selectedIndex == 99) {50 selectedIndex = await selectAction();51 }52 switch (selectedIndex) {53 case 0: {54 const newLabel = await getNewLabel();55 createLabel(configs, newLabel);56 firstStart = firstStart && false;57 break;58 }59 case 1: {60 // console.log('create labels');61 createLabels(configs);62 firstStart = firstStart && false;63 break;64 }65 case 2: {66 // console.log('delete a label');67 const targetLabel = await getTargetLabel();68 deleteLabel(configs, targetLabel);69 firstStart = firstStart && false;70 break;71 }72 case 3: {73 // console.log('delete all labels');74 deleteLabels(configs);75 firstStart = firstStart && false;76 break;77 }78 case 4: {79 console.log('exit');80 process.exit(0);81 // deleteLabels(octokit, userInfo);82 break;83 }84 default: {85 console.log('invalid input');86 break;87 }88 }89 main();90};...
Using AI Code Generation
1var mb = require('mountebank');2mb.start({3}, function () {4 console.log('mountebank started');5});6var mb = require('mountebank');7mb.start({8}, function () {9 console.log('mountebank started');10});11var mb = require('mountebank');12mb.start({13}, function () {14 console.log('mountebank started');15});16var mb = require('mountebank');17mb.start({18}, function () {19 console.log('mountebank started');20});21var mb = require('mountebank');22mb.start({23}, function () {24 console.log('mountebank started');25});26var mb = require('mountebank');27mb.start({28}, function () {29 console.log('
Using AI Code Generation
1var mb = require('mountebank');2mb.start({3}, function () {4});5var mb = require('mountebank');6mb.start({7}, function () {8});9var mb = require('mountebank');10mb.start({11}, function () {12});13var mb = require('mountebank');14mb.start({15}, function () {16});17var mb = require('mountebank');18mb.start({19}, function () {20});21var mb = require('mountebank');22mb.start({23}, function () {24});25var mb = require('mountebank');26mb.start({
Using AI Code Generation
1var mb = require('mountebank');2mb.start({3}, function (error) {4 if (error) {5 console.error(error);6 }7 else {8 console.log('mountebank started');9 }10});11var mb = require('mountebank');12mb.start({13}, function (error) {14 if (error) {15 console.error(error);16 }17 else {18 console.log('mountebank started');19 }20});21var mb = require('mountebank');22mb.start({23}, function (error) {24 if (error) {25 console.error(error);26 }27 else {28 console.log('mountebank started');29 }30});31var mb = require('mountebank');32mb.start({33}, function (error) {34 if (error) {35 console.error(error);36 }37 else {38 console.log('mountebank started');39 }40});41var mb = require('mountebank');42mb.start({43}, function (error) {44 if (error) {45 console.error(error);46 }47 else {48 console.log('mountebank started');49 }50});51var mb = require('mountebank');52mb.start({53}, function (error) {54 if (error) {55 console.error(error);56 }57 else {58 console.log('mountebank started');59 }60});61var mb = require('mountebank');62mb.start({
Using AI Code Generation
1var mb = require('mountebank');2mb.start({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto'}, function (error) {3 if (error) {4 console.log('Error starting mountebank: ', error);5 } else {6 console.log('Mountebank started on port 2525');7 }8});9var mb = require('mountebank');10mb.start({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto'}, function (error) {11 if (error) {12 console.log('Error starting mountebank: ', error);13 } else {14 console.log('Mountebank started on port 2525');15 }16});17var mb = require('mountebank');18mb.start({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto'}, function (error) {19 if (error) {20 console.log('Error starting mountebank: ', error);21 } else {22 console.log('Mountebank started on port 2525');23 }24});25var mb = require('mountebank');26mb.start({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto'}, function (error) {27 if (error) {28 console.log('Error starting mountebank: ', error);29 } else {30 console.log('Mountebank started on port 2525');31 }32});33var mb = require('mountebank');34mb.start({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto'}, function (error) {35 if (error) {36 console.log('Error starting mountebank: ', error);37 } else {38 console.log('Mountebank started on port 2525');39 }40});41var mb = require('mountebank');42mb.start({port: 2525, pidfile: 'mb
Using AI Code Generation
1const mb = require('mountebank');2mb.start({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' })3.then(() => mb.firstStart({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' }))4.then(() => mb.stop({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' }))5.catch(error => console.error(error));6Your name to display (optional):7Your name to display (optional):8const mb = require('mountebank');9mb.start({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' })10.then(() => mb.firstStart({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' }))11.then(() => mb.stop({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', protofile: 'mb.proto' }))12.catch(error => console.error(error));13Your name to display (optional):
Using AI Code Generation
1const mb = require('mountebank');2const mbHelper = require('mountebank-helper');3const firstStart = mbHelper.firstStart;4const port = 2525;5const options = {6};7firstStart(options)8.then(() => {9 console.log('mountebank started');10 const imposter = mbHelper.imposter;11 const imposterOptions = {12 {13 {14 equals: {15 }16 }17 {18 is: {19 headers: {20 },21 }22 }23 }24 };25 return imposter(imposterOptions);26})27.then(() => {28 console.log('imposter created');29})30.catch((err) => {31 console.log(err);32});33const mb = require('mountebank');34const mbHelper = require('mountebank-helper');35const firstStart = mbHelper.firstStart;36const port = 2525;37const options = {38};39firstStart(options)40.then(() => {41 console.log('mountebank started');42 const imposter = mbHelper.imposter;43 const imposterOptions = {44 {45 {46 equals: {47 }48 }49 {50 is: {51 headers: {52 },53 }54 }55 }56 };57 return imposter(imposterOptions);58})59.then(() => {60 console.log('imposter created');
Using AI Code Generation
1var mb = require('mountebank').create({port:2525});2mb.start().then(function () {3 console.log('mb started');4 mb.firstStart().then(function () {5 console.log('mb first start');6 });7});8var mb = require('mountebank').create({port:2525});9mb.start().then(function () {10 console.log('mb started');11 mb.firstStart().then(function () {12 console.log('mb first start');13 });14});15var mb = require('mountebank').create({port:2525});16mb.start().then(function () {17 console.log('mb started');18 mb.firstStart().then(function () {19 console.log('mb first start');20 });21});22var mb = require('mountebank').create({port:2525});23mb.start().then(function () {24 console.log('mb started');25 mb.firstStart().then(function () {26 console.log('mb first start');27 });28});29var mb = require('mountebank').create({port:2525});30mb.start().then(function () {31 console.log('mb started');32 mb.firstStart().then(function () {33 console.log('mb first start');34 });35});36var mb = require('mountebank').create({port:2525});37mb.start().then(function () {38 console.log('mb started');39 mb.firstStart().then(function () {40 console.log('mb first start');41 });42});43var mb = require('mountebank').create({port:2525});44mb.start().then(function () {45 console.log('mb started');46 mb.firstStart().then(function () {47 console.log('mb first start');48 });49});50var mb = require('mountebank').create({port:2525});51mb.start().then(function () {52 console.log('mb
Using AI Code Generation
1const mb = require('mountebank');2mb.start({3}).then(function () {4 console.log('Mountebank server started');5});6const mb = require('mountebank');7mb.start({8}).then(function () {9 console.log('Mountebank server started');10});11const mb = require('mountebank');12mb.start({13}).then(function () {14 console.log('Mountebank server started');15});16const mb = require('mountebank');17mb.start({
Using AI Code Generation
1var mb = require('mountebank-client');2var client = mb.create({host: 'localhost', port: 2525});3client.firstStart('test', 2525, {allowInjection: true}, function (error) {4 if (error) {5 console.log(error);6 }7 else {8 console.log('mountebank is running');9 }10});11var mb = require('mountebank-client');12var client = mb.create({host: 'localhost', port: 2525});13client.firstStart('test', 2525, {allowInjection: true}, function (error) {14 if (error) {15 console.log(error);16 }17 else {18 console.log('mountebank is running');19 }20});21var mb = require('mountebank-client');22var client = mb.create({host: 'localhost', port: 2525});23client.firstStart('test', 2525, {allowInjection: true}, function (error) {24 if (error) {25 console.log(error);26 }27 else {28 console.log('mountebank is running');29 }30});31var mb = require('mountebank-client');32var client = mb.create({host: 'localhost', port: 2525});33client.firstStart('test', 2525, {allowInjection:
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!