SVG gradient as polylines stroke background with absolute position

大兔子大兔子 提交于 2020-01-02 21:00:34

问题


Is there the ability to set absolute position of the gradient background applied to polyline?

For example when I set gradient:

<filter id="black-glow">
    <feColorMatrix type="matrix" values=
       "0 0 0 0   0        
        0 0 0 0   0
        0 0 0 0   0
        0 0 0 1   0" />
    <feGaussianBlur stdDeviation="3" result="coloredBlur" />
    <feMerge>
      <feMergeNode in="coloredBlur" />
      <feMergeNode in="SourceGraphic" />
    </feMerge>
</filter>

to polyline's stroke:

<polyline points="50,350 ... 350,239" style="fill:none;" stroke="url(#grad1)" stroke-width="3" stroke-linecap="round" />

(polyline have max/min position points)

Result is ok:

But, when polyline is flat:

Green colour is much higher. Since this is coloured chart, I need to achieve constantly looking background, independently of the way polyline is draw.


回答1:


If you want the gradient to be applied in userspace then that's possible by expressing the gradient like this:

<linearGradient id="grad1" gradientUnits="userSpaceOnUse" x1="0"
                y1="350" x2="0" y2="220">

See fiddle.

The values in x1, y1, x2 and y2 will then be relative to the current userspace coordinate system, so if you use percentages they will be relative to the closest viewport, not to the boundingbox of the shape that uses the gradient. See the svg specification for the details.



来源:https://stackoverflow.com/questions/29750227/svg-gradient-as-polylines-stroke-background-with-absolute-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!