diff --git a/ChartsSpace/EdgeEditor.js b/ChartsSpace/EdgeEditor.js index e402404ec..649ec2538 100644 --- a/ChartsSpace/EdgeEditor.js +++ b/ChartsSpace/EdgeEditor.js @@ -414,6 +414,16 @@ function newEdgeEditor () { y: pointB4.y + edgeSize } + pointA1 = canvas.chartSpace.viewport.fitIntoViewport(pointA1) + pointA2 = canvas.chartSpace.viewport.fitIntoViewport(pointA2) + pointA3 = canvas.chartSpace.viewport.fitIntoViewport(pointA3) + pointA4 = canvas.chartSpace.viewport.fitIntoViewport(pointA4) + + pointB1 = canvas.chartSpace.viewport.fitIntoViewport(pointB1) + pointB2 = canvas.chartSpace.viewport.fitIntoViewport(pointB2) + pointB3 = canvas.chartSpace.viewport.fitIntoViewport(pointB3) + pointB4 = canvas.chartSpace.viewport.fitIntoViewport(pointB4) + browserCanvasContext.setLineDash([0, 0]) browserCanvasContext.beginPath() diff --git a/ChartsSpace/ViewPort.js b/ChartsSpace/ViewPort.js index d2bced074..2a054191c 100644 --- a/ChartsSpace/ViewPort.js +++ b/ChartsSpace/ViewPort.js @@ -36,6 +36,7 @@ function newViewport () { isThisPointVisible: isThisPointVisible, isThisPointInViewport: isThisPointInViewport, fitIntoVisibleArea: fitIntoVisibleArea, + fitIntoViewport: fitIntoViewport, displace: displace, physics: physics, raiseEvents: raiseEvents, @@ -221,25 +222,40 @@ function newViewport () { } function fitIntoVisibleArea (point) { - /* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */ - - if (point.x > thisObject.visibleArea.bottomRight.x + 1) { - point.x = thisObject.visibleArea.bottomRight.x + 1 + let pointCopy = { + x: point.x, + y: point.y } - if (point.x < thisObject.visibleArea.topLeft.x - 1) { - point.x = thisObject.visibleArea.topLeft.x - 1 + /* Here we check the boundaries of the resulting points, so they dont go out of the visible area. */ + if (pointCopy.x > thisObject.visibleArea.bottomRight.x + 1) { + pointCopy.x = thisObject.visibleArea.bottomRight.x + 1 } - if (point.y > thisObject.visibleArea.bottomRight.y + 1) { - point.y = thisObject.visibleArea.bottomRight.y + 1 + if (pointCopy.x < thisObject.visibleArea.topLeft.x - 1) { + pointCopy.x = thisObject.visibleArea.topLeft.x - 1 } - if (point.y < thisObject.visibleArea.topLeft.y - 1) { - point.y = thisObject.visibleArea.topLeft.y - 1 + if (pointCopy.y > thisObject.visibleArea.bottomRight.y + 1) { + pointCopy.y = thisObject.visibleArea.bottomRight.y + 1 } - return point + if (pointCopy.y < thisObject.visibleArea.topLeft.y - 1) { + pointCopy.y = thisObject.visibleArea.topLeft.y - 1 + } + + return pointCopy + } + + function fitIntoViewport (point) { + let pointCopy = { + x: point.x, + y: point.y + } + if (pointCopy.y > COCKPIT_SPACE_POSITION) { + pointCopy.y = COCKPIT_SPACE_POSITION + } + return pointCopy } function displace (displaceVector, recalculate) { @@ -320,7 +336,7 @@ function newViewport () { } function isThisPointInViewport (point) { - if (point.y > browserCanvas.height - COCKPIT_SPACE_POSITION) { + if (point.y > COCKPIT_SPACE_POSITION) { return false } else { return true