autoZoom in zoomcharts (netchart 1.6.0) does not prevent nodes moving out of view

StackOverflow https://stackoverflow.com/questions/22982971

  •  01-07-2023
  •  | 
  •  

Pregunta

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?

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top