Question

Although autozoom is on, nodes keep moving out of view. Automatic zoom to keep all nodes in view does not happen.

My console shows this:

interaction: Object
  panning: Object
  resizing: Object
  selection: Object
  zooming: Object
    autoZoom: true
    autoZoomDuration: 500
    autoZoomSize: 0.9
    doubleClickZoom: 1.5
    fingers: true
    sensitivity: 1
    wheel: true

I create nodes with this function

        function graphDoubleClick(event){
            $("#nodemenu").css("display", "none");
            $("#linkmenu").css("display", "none");

            if (event.clickNode && event.shiftKey){//test the click was on a node
                    chart.addData({
                        nodes:[{
                            "id":"n"+nextId,
                            "type":"unknown",
                            "x":event.chartX, 
                            "y":event.chartY,
                            "loaded":true,
                            "style":{"label":"newNode"}
                            }], 
                        links:[{
                            "id":"ll"+nextId,
                             from:event.clickNode.id, 
                             to:"n"+nextId,
                             "style":{"label":"unknown"}
                             }]
                    });
                    nextId += 1;
            }
            else if  (!event.clickNode && !event.clickLink && event.shiftKey){
                    chart.addData({
                        nodes:[{
                            "id":"n"+nextId, 
                            "loaded":true, 
                            "type":"unknown",
                            "x":event.chartX, 
                            "y":event.chartY,
                            "style":{"label":"newNode"}
                            }]
                    });
                    nextId += 1;
            };

        } 

What could cause this behaviour?

Was it helpful?

Solution

Default doubleClick action is zoom in and it internally disables auto zoom.

Add event.preventDefault() at the end of graphDoubleClick and you should be fine.

Or disable zoom on double click by setting settings.interaction.zooming.doubleClickZoom = 0.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top