GoalModelEditor/FrontEnd/public/js/projectEdit/graph.js
/**
 * Re-centre/Re-scale
 * Function for resetting zoom and recentring the graph
 *  This is necessary when "Export" is pressed to help export the graph to the
 *    right resolution. to properly locate the canvas view for the export
 *    function, we actually need to centre the view such that:
 *      x = x coord of leftmost symbol; and
 *      y = y coord of topmost symbol
 */
Re-centre/Re-scale
Function for resetting zoom and recentring the graph
This is necessary when "Export" is pressed to help export the graph to the
right resolution. to properly locate the canvas view for the export
function, we actually need to centre the view such that:
x = x coord of leftmost symbol; and
y = y coord of topmost symbol
Re - centre / Re - scale Function for resetting zoom and recentring the graph This is necessary when " Export " is pressed to help export the graph to the right resolution . to properly locate the canvas view for the export function we actually need to centre the view such that : x = x coord of leftmost symbol ; and y = y coord of topmost symbol
function recentreView() {
    var vertices = graph.getChildVertices();
    if (vertices.length == 0) {
        graph.view.setTranslate(0, 0);
        graph.view.setScale(1);
        return;
    }
    var leftmost = vertices[0].geometry.x;
    var upmost = vertices[0].geometry.y;
    for (var i = 0; i < vertices.length; i++) {
        var curr = vertices[i].geometry;
        if (curr.x < leftmost) {
            leftmost = curr.x;
        }
        if (curr.y < upmost) {
            upmost = curr.y;
        }
    }
    graph.view.setTranslate(-leftmost, -upmost);
    graph.view.setScale(1);
}
function recentreView ( ) { var vertices = graph . getChildVertices ( ) ; if ( vertices . length == 0 ) { graph . view . setTranslate ( 0 , 0 ) ; graph . view . setScale ( 1 ) ; return ; } var leftmost = vertices [ 0 ] . geometry . x ; var upmost = vertices [ 0 ] . geometry . y ; for ( var i = 0 ; i < vertices . length ; i ++ ) { var curr = vertices [ i ] . geometry ; if ( curr . x < leftmost ) { leftmost = curr . x ; } if ( curr . y < upmost ) { upmost = curr . y ; } } graph . view . setTranslate ( - leftmost , - upmost ) ; graph . view . setScale ( 1 ) ; }
Re-centre/Re-scale
 Function for resetting zoom and recentring the graph
  This is necessary when "Export" is pressed to help export the graph to the
    right resolution.
Re - centre / Re - scale Function for resetting zoom and recentring the graph This is necessary when " Export " is pressed to help export the graph to the right resolution .
// get the list of all cells in the graph // if no vertices, then just centre to (0,0) // if there are vertices, then find the leftmost x coord and upmost y coord // recentres the view to its starting position (x=0, y=0) // resets the zoom to the original level