vis-network
vis-network copied to clipboard
New option: minZoom
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.
@Thomaash , as existing pull request was not approved and closed - any chance to implement the feature in some other way?
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();
});