简体   繁体   English

内联SVG在“角度材质”对话框中无法正确缩放

[英]Inline SVG won't scale correctly in Angular Material dialog

I've been trying to implement an SVG document markup editor inside an Angular material dialog, where the screen is split between the actual SVG element (on the left) and art controls (on the right). 我一直在尝试在Angular材质对话框中实现SVG文档标记编辑器,在该屏幕中,实际的SVG元素(左侧)和art控件(右侧)之间被分割。

The problem is that the SVG must maintain its own aspect ratio instead of stretching to fill the space. 问题在于SVG必须保持其自身的纵横比,而不是拉伸以填充空间。 Ideally it would also be centered in the screen. 理想情况下,它也应位于屏幕中央。

Here's an sketch of what the ideal outcome would be: 以下是理想结果的示意图:

*-------------------*--------------------------*
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |         Art              |
|      SVG          |       Options            |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
*-------------------*--------------------------*

And here is what is happening: 这是正在发生的事情:

*-------------------*--------------------------*
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |         Art              |
|      SVG          |       Options            |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
|                   |                          |
*-------------------*--------------------------*
|                   |
|    Overflow       |
|                   |
*-------------------*

Here's the code for the dialog: 这是对话框的代码:

<md-dialog>
    <md-dialog-content flex layout="row">
        <div class="pdf-wrap" flex layout="column" layout-align="center center">
            <svg-wrapper></svg-wrapper>
        </div>
        <md-divider></md-divider>
        <div class="md-padding" layout="column">
            <art-options></art-options>
        </div>
    </md-dialog-content>
</md-dialog>

The only extra stylings present are: 存在的唯一额外样式是:

pdf-wrap {
    padding: 10px;
}
svg-wrapper {
    width: 100%;
}

The rest is handled by default Angular-Material css rules. 其余部分由默认的Angular-Material css规则处理。

Some overview: svg-wrapper is the directive that fetches the document that the user will sketch on. 一些概述:svg-wrapper是用于提取用户将在其上进行素描的文档的指令。 It compiles that svg onto the page. 它将svg编译到页面上。 Adding preserveAspectRatio has no effect, no matter the options selected. 无论选择什么选项,添加preserveAspectRatio均无效。

If anyone has a better understanding of what's going on, I'd appreciate some explanation of what's happening, and more importantly how to fix it. 如果有人对正在发生的事情有更好的了解,我希望对正在发生的事情进行一些解释,更重要的是如何解决它。

Edit: updated with Plunkr. 编辑:用Plunkr更新。 If you stretch the code section at different widths, you'll see that some of the pdf is shown in full view, but all is shown in constrained view (which is the desired behavior) 如果以不同的宽度拉伸代码部分,则会看到部分pdf以全视图显示,但全部以受限视图显示(这是所需的行为)

https://plnkr.co/edit/Or10mAmBrlDsqcKAS6BZ?p=info https://plnkr.co/edit/Or10mAmBrlDsqcKAS6BZ?p=info

Just add flex layout="column" to the svg-wrapper - Plunker 只需将flex layout="column"添加到svg-wrapper - Plunker

Markup 标记

<md-dialog>
  <md-dialog-content flex layout="row">
    <div class="pdf-wrap" flex layout="column" layout-align="center center"  style="background:yellow">
      <svg-wrapper flex layout="column"></svg-wrapper>
    </div>
    <div class="md-padding" layout="column" style="background:red">
      <h2>Some art options here</h2>
    </div>
  </md-dialog-content>
</md-dialog>

As a suggestion, adding flex to the Art Options would be good too - Plunker 作为建议,在art选项中添加flex也将很好-Plunker

I ended up solving this issue programatically. 我最终以编程方式解决了这个问题。 I followed camden_kid's suggestion of adding flex layout="column" to svg-wrapper . 我遵循了camden_kid的建议,在svg-wrapper中添加了flex layout="column" Then, in the directive, I added to the style of the SVG the following: 然后,在指令中,我将以下内容添加到SVG的样式中:

width: auto
height: element[0].clientHeight
margin: auto

Setting the height equal to the clientHeight doesn't allow for vertical stretching unless you keep an eye on it programmatically, but it solves every other problem. 设置高度等于clientHeight不允许垂直拉伸,除非您以编程方式关注它,但这解决了所有其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM