dash14 / v-network-graph

An interactive network graph visualization component for Vue 3
https://dash14.github.io/v-network-graph/
MIT License
480 stars 44 forks source link

Make the graph fit to the edges of the canvas? #135

Closed linkurzweg closed 7 months ago

linkurzweg commented 8 months ago

Thanks again for this great library! I have a question regarding the initial zoom of the network graph. Is it somehow possible to make the graph fit right to the edges of its parent container (v-ng-canvas/v-ng-container). I have autoPanAndZoomOnLoad: 'fit-content' set in the view config. But as you can see there is a lot of of space around the graph which makes it difficult to integrate into my app styling-wise. Maybe there is something else I need to set? This is my view config:

vNG.defineConfigs({
      view: {
        scalingObjects: true,
        autoPanAndZoomOnLoad: 'fit-content',
        panEnabled: false,
        zoomEnabled: false,
      },
     ...
    })

image

dash14 commented 8 months ago

Hi @linkurzweg, Thanks for your question!

When configs.view.scalingObjects is set to true, the size of the nodes in the SVG coordinates is dynamically changed according to the zoom level to ensure that the size on the display does not change. Even if fitting the node at a certain point in time, the size of the node changes with the new zoom level, making it difficult to exactly fit the edge of the parent container, so the current behavior is to provide a certain margin.

Your comments have made me consider this again. I have some ideas and would like to try them out. Please wait a few more days.

linkurzweg commented 8 months ago

Hello @dash14! Thank you very much for considering! I'll be waiting :)

dash14 commented 8 months ago

Hi @linkurzweg! Thank you for your patience! Released v0.9.11 with support for the ability to fit to the edge of the display area. For compatibility reasons, the distance from the edge of the display area can now be specified. Please add the following configuration and try it out.

vNG.defineConfigs({
  view: {
    scalingObjects: true,
    autoPanAndZoomOnLoad: 'fit-content',
    fitContentMargin: 0,  // <-- add
    panEnabled: false,
    zoomEnabled: false,
  },
 ...
})

Best Regards.

dash14 commented 8 months ago

I found a case where it did not work and it is being fixed.... Please wait a little longer.

linkurzweg commented 8 months ago

@dash14 thank you very much for taking care of this so quickly and sorry for the late reply. Work is quite stressful at the moment and the project using the network graph has been pushed back a bit because of other deadlines. So, I'll wait :)

dash14 commented 8 months ago

@linkurzweg thank you for your reply and waiting. The fix is complete and v0.9.13 has been released! I think fit-content will work in most cases, but if you have problems, please contact again. Hope your project goes well!

linkurzweg commented 7 months ago

@dash14 Thank you so much! Just tested it and it looks like it works perfectly for me :)