Stroke on rect in D3 blurry

会有一股神秘感。 提交于 2020-05-23 08:41:07

问题


I am trying to draw a rectangle with a dashed strong in SVG using D3 but when I do the top and bottom dashed lines are blurry. Here is my code:

var width = 400,
        height = 400;

var svg = d3.select('body')
        .append('svg')
            .attr('width', width)
            .attr('height', height)
        .append('g')
            .attr('transform', 'translate('+height/2+','+width/2+')');

svg.append('rect')
    .attr('width', '185')
    .attr('height', '45')
    .attr('x', -height/2+185/2)
    .attr('y', -width/2+10)
    .attr('fill', 'rgba(0,0,0,0)')
    .attr('stroke', '#2378ae')
    .attr('stroke-dasharray', '10,5')
    .attr('stroke-linecap', 'butt')
    .attr('stroke-width', '3')

http://jsfiddle.net/sigscotty/9H9PX/

Here is what it looks like in the browser:

enter image description here

Any way to get the top and bottom crisp looking like the sides?


回答1:


shape-rendering is probably what you want. shape-rendering="crispEdges" should do it for your case. Alternatively you could adjust the y and height attributes so that the top and bottom positions are + 0.5.



来源:https://stackoverflow.com/questions/21101225/stroke-on-rect-in-d3-blurry

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