bpmn-io / diagram-js

A toolbox for displaying and modifying diagrams on the web.
MIT License
1.69k stars 419 forks source link

docs: Update Canvas.js #859

Closed joeskeen closed 7 months ago

joeskeen commented 7 months ago

I was trying to use canvas.zoom('fit-viewport') but wanted it centered. Looking at the code, it appears that the second parameter can be true in this case to have it automatically center (rather than providing a point). Updating the documentation to reflect this.

nikku commented 7 months ago

Thanks for the contribution. I believe center is an optional argument, and if not provided zooming (fit-viewport) will be done focused on the center.

I wonder if it makes sense to have a dedicated type definition for the fit-viewport case, as center = false yields won't center there, but will center for zoom(0.3, false).

joeskeen commented 7 months ago

Interesting. If I understand your last comment, it is expected to center the diagram if the second parameter is not provided? When I tried 'fit-viewport' without a second parameter, my diagram was always ending up at the far left.

nikku commented 7 months ago

If I understand your last comment, it is expected to center the diagram if the second parameter is not provided?

Yes. At best we always center. I don't see a reason why fit-viewbox should not center the diagram (but push it to the coordinate origin).

nikku commented 7 months ago

As indicated I'd love to have a dedicated override for the 'fit-viewport' case. https://github.com/bpmn-io/diagram-js/pull/859#issuecomment-1945517219.