x
and y
in the second argument of zoom
refer to screen coordinates. They do not refer to diagram coordinates. The documentation is not clear about this. We’ll look into this and maybe add the possibility to specify diagram coordinates when using zoom
.
In the meantime you can use this function from diagram-js-minimap that solves the same problem:
function setViewboxCenteredAroundPoint(point, canvas) {
// get cached viewbox to preserve zoom
var cachedViewbox = canvas.viewbox(),
cachedViewboxWidth = cachedViewbox.width,
cachedViewboxHeight = cachedViewbox.height;
canvas.viewbox({
x: point.x - cachedViewboxWidth / 2,
y: point.y - cachedViewboxHeight / 2,
width: cachedViewboxWidth,
height: cachedViewboxHeight
});
}
Please open a separate thread for this question.