How to use firstStart method in mountebank

Best JavaScript code snippet using mountebank

arrowLine.js

Source:arrowLine.js Github

copy

Full Screen

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下...

Full Screen

Full Screen

chronoDateManipulation.test.js

Source:chronoDateManipulation.test.js Github

copy

Full Screen

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()...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

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};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

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('

Full Screen

Using AI Code Generation

copy

Full Screen

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({

Full Screen

Using AI Code Generation

copy

Full Screen

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({

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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):

Full Screen

Using AI Code Generation

copy

Full Screen

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');

Full Screen

Using AI Code Generation

copy

Full Screen

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

Full Screen

Using AI Code Generation

copy

Full Screen

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({

Full Screen

Using AI Code Generation

copy

Full Screen

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:

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run mountebank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful