gpt4 book ai didi

javascript - 使用 View 框时如何阻止路径在 D3 中模糊/消失?

转载 作者:数据小太阳 更新时间:2023-10-29 06:15:43 24 4
gpt4 key购买 nike

我正在使用 D3 库创建一些图表。它们被放置在一个 View 框中(参见下面“输出”下的片段)。

View 框允许响应式缩放。

但是在某些分辨率下,线条要么消失,要么模糊/变粗。我认为这与它在这些分辨率下像素不完美有关,但我可能是错的。

没有添加额外的样式,除了

shape-rendering: crispEdges;

JS

this.y = d3.scale.linear()
.rangeRound([this.height, 0]);

this.yAxis = d3.svg.axis()
.scale(this.y)
.tickSize(this.width)
.tickValues([0, 25, 50, 75, 100])
.tickFormat(function(d) {
return parseInt(d, 10) + "%";
})
.orient("right");

this.y.domain([0, 100]);


// Y Axis elements
var gy = this.svg.append("g").attr("class", "y axis").call(this.yAxis);

// Add minor class to all the things
gy.selectAll("g").classed("minor", true);

// Move the text over to the left
gy.selectAll("text").attr("x", 0).attr("dy", -4);

输出

<svg class="bargraph" viewBox="0 0 250 250" preserveAspectRatio="xMidYMid" width="100%" height="100%">
<g class="x axis">...</g>
<g class="y axis">
<g class="tick minor" transform="translate(0,150)">
..repeat..
</g>
...content...
</svg>

绘制的输出

错误 - 注释行 75% 和 50%

Bad

好 - 像 cucumber 一样脆!

enter image description here

最佳答案

使用 vector-effect="non-scaling-stroke"这样笔划宽度就不会缩放。这样当您缩小时它就不会折叠。

关于javascript - 使用 View 框时如何阻止路径在 D3 中模糊/消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33951229/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com