Comments (7)
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.
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.
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.
Could you provide a JSFiddle starting from this https://jsfiddle.net/chrvadala/f67qyfsd/?
Thanks
from react-svg-pan-zoom.
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.
Is this fixed by #167 and can be closed?
from react-svg-pan-zoom.
I think yes
from react-svg-pan-zoom.
Related Issues (20)
- Can we load a SVG from a remote http Url and Pan/Zoom it in this control? Any example will be helpful. HOT 1
- How can I disable the pan on hover? HOT 1
- ReactSVGPanZoom onclick get svg polygon or rect name HOT 1
- "Unable to preventDefault inside passive event listener invocation." on console HOT 3
- Autosizer example outdated / not working HOT 1
- Set Toolbar Background and Toolbar Icon Color via props
- Members required for customized toolbar are not exported HOT 4
- SvgLoaderSelectElement properties doesn't override SVG default CSS
- Responsive Display with ReactSVGPanZoom HOT 2
- Is there support to react 15 HOT 2
- Improving scrolling performance with passive listeners? HOT 1
- No touch event handlers provided when tool="auto" is selected HOT 1
- [react-svg-pan-zoom] Review doc with absolute url
- there is a warning at the start of rendering "Prop `id` did not match"
- Execute pan event for a certain amount of pixels by clicking a UI button
- Change line thickness in the grid
- Unable to Handle input field in svg
- scaleFactorMin scaleFactorMax not working
- Lazy loading or progressive loading of complex svg
- onmouseover event doesn't fire on SVG path HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-svg-pan-zoom.