How to zoom into a GraphStream View?

In GraphStream visualizations Graphs can be dense. The enableAutoLayout method gives a global visualization of the Graph and so zooming is needed. How to zoom into a GraphStream View?

Graph go=...;
Viewer viewer = new Viewer(go, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
viewer.enableAutoLayout();
View view = viewer.addDefaultView(false); 
swingNode.setContent((JComponent) view);

I tried to find a way to zoom to the mouse cursor using the mouse wheel and stumbled across this thread, hoping to find an answer. I figured out how to zoom to the mouse eventually with GraphStream:

The zoom-factor for each mouse wheel rotation in my case is 1.25 (or 0.8 when zooming out). The code calculates the new center of the graph based on the original center of the graph, the clicked point in the graph, the zoom and eventually the ratio of Px to Gu which can be retrieved from the camera.

final Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
viewer.enableAutoLayout();
final View view = viewer.addDefaultView(false);
view.getCamera().setViewPercent(1);
((Component) view).addMouseWheelListener(new MouseWheelListener() {
    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {
        e.consume();
        int i = e.getWheelRotation();
        double factor = Math.pow(1.25, i);
        Camera cam = view.getCamera();
        double zoom = cam.getViewPercent() * factor;
        Point2 pxCenter  = cam.transformGuToPx(cam.getViewCenter().x, cam.getViewCenter().y, 0);
        Point3 guClicked = cam.transformPxToGu(e.getX(), e.getY());
        double newRatioPx2Gu = cam.getMetrics().ratioPx2Gu/factor;
        double x = guClicked.x + (pxCenter.x - e.getX())/newRatioPx2Gu;
        double y = guClicked.y - (pxCenter.y - e.getY())/newRatioPx2Gu;
        cam.setViewCenter(x, y, 0);
        cam.setViewPercent(zoom);
    }
});

In GraphStream visualizations Graphs can be dense. The enableAutoLayout method gives a global visualization of the Graph and so zooming is needed. How to  In this lesson you will learn how to zoom in your graph. It will help you improving visibility of values in your graph. The most important in charting is visibility. In this lesson you will learn how to zoom in your graph. The easiest way is to zoom in the Sheet. To do it go to right corner of screen and click + button. It makes whole Sheet bigger.

Here a simple code to show you how you can zoom a graph:

public class zoomGraph{

   public zoomGraph(){
   }
   //the methode that will zoom the graph
   public static void zoomGraphMouseWheelMoved(MouseWheelEvent mwe, ViewPanel view_panel){
        if (Event.ALT_MASK != 0) {            
            if (mwe.getWheelRotation() > 0) {
                double new_view_percent = view_panel.getCamera().getViewPercent() + 0.05;
                view_panel.getCamera().setViewPercent(new_view_percent);               
            } else if (mwe.getWheelRotation() < 0) {
                double current_view_percent = view_panel.getCamera().getViewPercent();
                if(current_view_percent > 0.05){
                    view_panel.getCamera().setViewPercent(current_view_percent - 0.05);                
                }
            }
        }                     
    }

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        frame.setLayout(new GridLayout());
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);        
        frame.setBounds(0, 0, 700, 500);
        frame.setPreferredSize(new Dimension(700, 500));


        //Components
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout());
        frame.add(panel);

        //create a simple graph
        Graph graph = new SingleGraph("tuto_zoom", false, true);
        graph.addNode("node_1");
        graph.addNode("node_2");
        graph.addEdge("edge_1_2", "node_1","node_2");

        //show the graph in the panel
        Viewer viewer = new Viewer(graph, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
        viewer.enableAutoLayout();
        ViewPanel view_panel = viewer.addDefaultView(false); 
        Rectangle rec = panel.getBounds();
        view_panel.setBounds(0, 0, rec.width, rec.height);
        view_panel.setPreferredSize(new Dimension(rec.width, rec.height));
        panel.add(view_panel);


        //add a mouse wheel listener to the ViewPanel for zooming the graph
        view_panel.addMouseWheelListener(new MouseWheelListener() {
            @Override
            public void mouseWheelMoved(MouseWheelEvent mwe) {
                zoomGraph.zoomGraphMouseWheelMoved(mwe, view_panel);
            }
        });


        frame.setVisible(true);
    }

}

How to display a graph. There are several ways to display a graph. The most easy one is to use the Graph.display() method. This is in  Zoom In and Zoom Out: After the graph is drawn, these commands allow you to zoom in on a portion of the graph or to zoom out from the graph. They work very much like a zoom lens on a camera. Press [ZOOM][2] to zoom in or press [ZOOM][3] to zoom out. Then use the. keys to move the cursor to the spot on the screen from which you want to zoom in

From the official documentation at http://graphstream-project.org/doc/Tutorials/Graph-Visualisation:

You can also zoom in or out using:

view.getCamera().setViewPercent(0.5);

This will zoom of 200% on the view center.

It can zoom on the graph, pan in any direction and rotate along two axes. (not in the camera view) or "on what element is the mouse cursor actually ?". I figured out how to zoom to the mouse eventually with GraphStream: The zoom-factor for each mouse wheel rotation in my case is 1.25 (or 0.8 when zooming out). The code calculates the new center of the graph based on the original center of the graph, the clicked point in the graph, the zoom and eventually the ratio of Px to Gu which can be retrieved from the camera.

The default viewer of GraphStream is only able to handle colors and sizes of You specify the style sheet of a graph by putting a ui.stylesheet attribute on the graph. text-visibility : The zoom values at which the labels should be shown,  The Zoom mobile app on iPad supports active speaker or gallery view. Gallery view allows you to see up to 9 participants at once. To switch from active speaker view, tap Switch to Gallery View in the upper-left corner of the Zoom window. If you do not see the controls, tap your screen to get them to appear. This will switch into gallery view.

Then in our code, at any time, we can add or change the attribute ui.class on individual nodes to As you can see, the colors are interpolated. or x and y attributes, using graph units, your nodes can change size when you change the zoom). Zoom is the leader in modern enterprise video communications, with an easy, reliable cloud platform for video and audio conferencing, chat, and webinars across mobile, desktop, and room systems. Zoom Rooms is the original software-based conference room solution used around the world in board, conference, huddle, and training rooms, as well as executive offices and classrooms.

In GraphStream visualizations Graphs can be dense. The enableAutoLayout method gives a global visualization of the Graph and so zooming is needed. How to  To zoom in a slide, you can use keyboard shortcuts. Zoom in or out. On your computer, open a document in Google Docs or a spreadsheet in Google Sheets. In the toolbar, click 100%. Choose how big you want your text or enter a number from 50 to 200. In Google Docs, to make the document as wide as the browser window, click Fit. Change your view

Comments
  • More here.
  • This only changes the scale to the center. My question was about zooming to any point of the View, not only the center.
  • as per the same docmentation page, you can first change the center of the view to any point and then do the zooming view.getCamera().setViewCenter(2, 3, 4);