vis-network icon indicating copy to clipboard operation
vis-network copied to clipboard

New option: minZoom

Open inmylo opened this issue 5 years ago • 2 comments

Feature request:

Please add a new option minZoom to limit minimal zoom level. Currently, probably, there no limit to zoom out and even large graph can be "resized" until it's ~1px big, which makes no sense. I would like to set the limit so the labels are always readable.

I've tried one workaround from the internet, but it's buggy. So a native solution would be great.

inmylo avatar Mar 25 '20 10:03 inmylo

@Thomaash , as existing pull request was not approved and closed - any chance to implement the feature in some other way?

inmylo avatar Oct 11 '21 12:10 inmylo

I was able to do with a workaround, pls follow if it helps (took me a while lol)

let lastPosition = null;
const max_zoom = 2;
const min_zoom = 0.5;
    network.on("zoom", function (params) {
      if (params.scale < min_zoom|| params.scale > max_zoom) { // adjust this value according to your requirement
        network.moveTo({
          position: lastPosition, // use the last position before zoom limit
          scale: params.scale > max_zoom ? max_zoom : min_zoom // this scale prevents zooming out beyond the desired limit
        });
      } else {
        // store the current position as the last position before zoom limit
        lastPosition = network.getViewPosition();
      }
    });
    // on pan, store the current position
    network.on("dragEnd", function () {
      lastPosition = network.getViewPosition();
    });

codergautam avatar Jul 27 '23 17:07 codergautam