jgraph / mxgraph

mxGraph is a fully client side JavaScript diagramming library
Other
6.82k stars 2.06k forks source link

Support both "FIT" and "FILL" for aspect-ratio fixed image resize #490

Closed nbelyh closed 4 years ago

nbelyh commented 4 years ago

Is your feature request related to a problem? Please describe. Many applications allow you to do two style of image resize when keeping aspect - "fit in box" and "fill box". This is illustrated by the picture below (there are more options, but these two are basic)

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio

FIT (this is supported now) FIT

FILL (this is not supported yet) FILL

Describe the solution you'd like It would be nice in addition to have "imageAspect" have "imageFill" style (versus the current "fit"), or something like this. Basically as style for this could be great.

This needs to go to the basic renderer, I think. For the SVG for example, now it sets "preserveAspectRatio" to "none" or empty (which is equivalaent of "xMidYMid meet", in case this style "fill" it should be "xMidYMid slice". https://github.com/jgraph/mxgraph/blob/693c67a81ed33e0fcffc761c242e9eaafcaeb95a/javascript/src/js/util/mxSvgCanvas2D.js#L1070-L1073

For other renderers (?) this should not be hard to implement either, as it's just switching min scale to max scale basically.