简体   繁体   English

如何在绝对线宽的SVG中绘制多边形?

[英]How to draw a polygon in SVG with absolute line width?

My application generates a set of graph points to be drawn in SVG. 我的应用程序生成一组要在SVG中绘制的图形点。 The point values are always in the range of 0-1000 horizontally and vertically. 点值始终在水平和垂直方向上为0-1000。 The size of the rectangle where the drawing takes place might change. 绘图发生的矩形的大小可能会改变。

here is the SVG element to draw the graph on a 200 X 85 rect: 这是在200 X 85 rect上绘制图形的SVG元素:

<svg width="200" height="85" viewBox="0 0 1000 1000" preserveAspectRatio="none">
    <polyline  stroke="#e69800"
               stroke-width="2px"
               fill="none"
               points="0,1000 100,900 200,800
                       300,700 400,600 500,500
                       600 400 700,300 800,200900,100 1000,0"/>
</svg>

Setting viewBox="0 0 1000 1000" makes the graph shrink to the proper size, the problem is that this also shrinks the width of the line in the same proportion, so the line is not visible any more. 设置viewBox="0 0 1000 1000"会使图形缩小到合适的大小,问题是这也会以相同的比例缩小线条的宽度,因此该线条不再可见。

SVG seems to ignore the "px" in the attribute stroke-width="2px" . SVG似乎忽略属性stroke-width="2px"的“px stroke-width="2px"

Is there a way to specify the width of the line (stroke-width) in absolute pixel size? 有没有办法用绝对像素大小指定线宽(笔画宽度)?

You can use the attribute vector-effect="non-scaling-stroke" to prevent the line from scaling with the rest. 您可以使用属性vector-effect="non-scaling-stroke"来防止线条与其余线条一起缩放。

Ref: http://www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke 参考: http//www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke

The resulting visual effect of this modification is that stroke width is not dependant on the transformations of the element (including non-uniform scaling and shear transformations) and zoom level 这种修改产生的视觉效果是笔划宽度不依赖于元素的变换(包括非均匀缩放和剪切变换)和缩放级别

It seems that SVG1.1 doesn't support non-scaling stroke though, so the final result might depend on the rendering engine. 看来SVG1.1不支持非缩放笔划,因此最终结果可能取决于渲染引擎。

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

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