Code Monkey home page Code Monkey logo

Comments (7)

otake avatar otake commented on May 12, 2024 1

I also needed this feature. I wrote some "hacky" code using this.Viewer.fitSelection(). Its not pretty but it gets the job done. Run this after the component is mounted (you need a reference to the Viewer).

// Find the inner container that wraps all the diagram components
let innerContainer = this.Viewer.ViewerDOM.querySelector('g > g');
let bbox = innerContainer.getBBox();

// only resize if it runs outside the main viewport
if (bbox.height > this.height || bbox.width > this.width || bbox.x < 0 || bbox.y < 0) {
    // give it some padding on the left and top
    const padding = 20;
    const topPadding = (this.height / 2) - (bbox.height / 2);
    let pointX = bbox.x - padding;
    let pointY = bbox.y - topPadding;
    let width = bbox.width + (padding * 2);
    let height = bbox.height + topPadding + padding;

    this.Viewer.fitSelection(pointX, pointY, width, height);
} else {
    this.Viewer.fitToViewer();
}

from react-svg-pan-zoom.

otake avatar otake commented on May 12, 2024 1

https://jsfiddle.net/f67qyfsd/10/

I moved the <rect> x property over to 500 because my situation was more about the elements inside the SVG being cut off and not the SVG tag itself. In other cases your default fitToViewer() seems to work well.

from react-svg-pan-zoom.

chrvadala avatar chrvadala commented on May 12, 2024

Hi, at this moment the fit function arrange the image to obtain all image inside the viewer.
What you are asking is a good feature that I will introduce as soon as possible.

Thank you for your feedback

from react-svg-pan-zoom.

chrvadala avatar chrvadala commented on May 12, 2024

Could you provide a JSFiddle starting from this https://jsfiddle.net/chrvadala/f67qyfsd/?
Thanks

from react-svg-pan-zoom.

wolasss avatar wolasss commented on May 12, 2024

Bump. It would be super nice to have a way to fit an image to the viewer, working just like object-fit: cover or background-size: cover.

from react-svg-pan-zoom.

krnlde avatar krnlde commented on May 12, 2024

Is this fixed by #167 and can be closed?

from react-svg-pan-zoom.

wolasss avatar wolasss commented on May 12, 2024

I think yes

from react-svg-pan-zoom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.