Skip to content
Discussion options

You must be logged in to vote

One option might be to move the visible part of the canvas with Viewport.transformBy:

Option 1
import { Viewport } from 'js-draw';
import { Mat33, Vec2 } from '@js-draw/math';

// Enable autoresize (if not already enabled).
editor.dispatch(editor.image.setAutoresizeEnabled(true));

// Zooms the editor content such that its width matches the editor width
// (or height matches the editor height).
const zoomToContent = () => {
	const svgRect = editor.getImportExportRect();
	const currentVisibleRect = editor.viewport.visibleRect;

	// Calculate how much we need to zoom in or out
	const xScale = svgRect.width / currentVisibleRect.width;
	const yScale = svgRect.height / currentVisibleRect.height;

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@awmasakityan
Comment options

@awmasakityan
Comment options

Answer selected by awmasakityan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants