plugins/connectors/joint.connectors.jumpover.js
function createJumps(line, intersections, jumpSize) {
        return intersections.reduce(function(resultLines, point, idx) {
            // skipping points that were merged with the previous line
            // to make bigger arc over multiple lines that are close to each other
            if (point.skip === true) {
                return resultLines;
            }

            // always grab the last line from buffer and modify it
            var lastLine = resultLines.pop() || line;

            // calculate start and end of jump by moving by a given size of jump
            var jumpStart = g.point(point).move(lastLine.start, -(jumpSize));
            var jumpEnd = g.point(point).move(lastLine.start, +(jumpSize));

            // now try to look at the next intersection point
            var nextPoint = intersections[idx + 1];
            if (nextPoint != null) {
                var distance = jumpEnd.distance(nextPoint);
                if (distance <= jumpSize) {
                    // next point is close enough, move the jump end by this
                    // difference and mark the next point to be skipped
                    jumpEnd = nextPoint.move(lastLine.start, distance);
                    nextPoint.skip = true;
                }
            } else {
                // this block is inside of `else` as an optimization so the distance is
                // not calculated when we know there are no other intersection points
                var endDistance = jumpStart.distance(lastLine.end);
                // if the end is too close to possible jump, draw remaining line instead of a jump
                if (endDistance < jumpSize * 2 + CLOSE_PROXIMITY_PADDING) {
                    resultLines.push(lastLine);
                    return resultLines;
                }
            }

            var startDistance = jumpEnd.distance(lastLine.start);
            if (startDistance < jumpSize * 2 + CLOSE_PROXIMITY_PADDING) {
                // if the start of line is too close to jump, draw that line instead of a jump
                resultLines.push(lastLine);
                return resultLines;
            }

            // finally create a jump line
            var jumpLine = g.line(jumpStart, jumpEnd);
            // it's just simple line but with a `isJump` property
            jumpLine.isJump = true;

            resultLines.push(
                g.line(lastLine.start, jumpStart),
                jumpLine,
                g.line(jumpEnd, lastLine.end)
            );
            return resultLines;
        }, []);
    }
function createJumps(line, intersections, jumpSize) {
        return intersections.reduce(function(resultLines, point, idx) {
            // skipping points that were merged with the previous line
            // to make bigger arc over multiple lines that are close to each other
            if (point.skip === true) {
                return resultLines;
            }

            // always grab the last line from buffer and modify it
            var lastLine = resultLines.pop() || line;

            // calculate start and end of jump by moving by a given size of jump
            var jumpStart = g.point(point).move(lastLine.start, -(jumpSize));
            var jumpEnd = g.point(point).move(lastLine.start, +(jumpSize));

            // now try to look at the next intersection point
            var nextPoint = intersections[idx + 1];
            if (nextPoint != null) {
                var distance = jumpEnd.distance(nextPoint);
                if (distance <= jumpSize) {
                    // next point is close enough, move the jump end by this
                    // difference and mark the next point to be skipped
                    jumpEnd = nextPoint.move(lastLine.start, distance);
                    nextPoint.skip = true;
                }
            } else {
                // this block is inside of `else` as an optimization so the distance is
                // not calculated when we know there are no other intersection points
                var endDistance = jumpStart.distance(lastLine.end);
                // if the end is too close to possible jump, draw remaining line instead of a jump
                if (endDistance < jumpSize * 2 + CLOSE_PROXIMITY_PADDING) {
                    resultLines.push(lastLine);
                    return resultLines;
                }
            }

            var startDistance = jumpEnd.distance(lastLine.start);
            if (startDistance < jumpSize * 2 + CLOSE_PROXIMITY_PADDING) {
                // if the start of line is too close to jump, draw that line instead of a jump
                resultLines.push(lastLine);
                return resultLines;
            }

            // finally create a jump line
            var jumpLine = g.line(jumpStart, jumpEnd);
            // it's just simple line but with a `isJump` property
            jumpLine.isJump = true;

            resultLines.push(
                g.line(lastLine.start, jumpStart),
                jumpLine,
                g.line(jumpEnd, lastLine.end)
            );
            return resultLines;
        }, []);
    }
function createJumps ( line , intersections , jumpSize ) { return intersections . reduce ( function ( resultLines , point , idx ) { // skipping points that were merged with the previous line // to make bigger arc over multiple lines that are close to each other if ( point . skip === true ) { return resultLines ; } // always grab the last line from buffer and modify it var lastLine = resultLines . pop ( ) || line ; // calculate start and end of jump by moving by a given size of jump var jumpStart = g . point ( point ) . move ( lastLine . start , - ( jumpSize ) ) ; var jumpEnd = g . point ( point ) . move ( lastLine . start , + ( jumpSize ) ) ; // now try to look at the next intersection point var nextPoint = intersections [ idx + 1 ] ; if ( nextPoint != null ) { var distance = jumpEnd . distance ( nextPoint ) ; if ( distance <= jumpSize ) { // next point is close enough, move the jump end by this // difference and mark the next point to be skipped jumpEnd = nextPoint . move ( lastLine . start , distance ) ; nextPoint . skip = true ; } } else { // this block is inside of `else` as an optimization so the distance is // not calculated when we know there are no other intersection points var endDistance = jumpStart . distance ( lastLine . end ) ; // if the end is too close to possible jump, draw remaining line instead of a jump if ( endDistance < jumpSize * 2 + CLOSE_PROXIMITY_PADDING ) { resultLines . push ( lastLine ) ; return resultLines ; } } var startDistance = jumpEnd . distance ( lastLine . start ) ; if ( startDistance < jumpSize * 2 + CLOSE_PROXIMITY_PADDING ) { // if the start of line is too close to jump, draw that line instead of a jump resultLines . push ( lastLine ) ; return resultLines ; } // finally create a jump line var jumpLine = g . line ( jumpStart , jumpEnd ) ; // it's just simple line but with a `isJump` property jumpLine . isJump = true ; resultLines . push ( g . line ( lastLine . start , jumpStart ) , jumpLine , g . line ( jumpEnd , lastLine . end ) ) ; return resultLines ; } , [ ] ) ; }
Split input line into multiple based on intersection points.
@param {g.line} line input line to split
@param {g.point[]} intersections poinst where to split the line
@param {number} jumpSize the size of jump arc (length empty spot on a line)
@return {g.line[]} list of lines being split
Split input line into multiple based on intersection points .