在我的项目中,我从路径创建线条。 由于我使用了较大的笔画宽度,因此它非常粗糙:
我已经做了一些搜索,但我找到的唯一解决方法是stroke-linejoin: round;
,如下图所示:
虽然这样要好得多,但我还不满意。
有没有办法获得真正平滑的线条? 或者说有更圆润的linejoin方式吗?
y
坐标的插值,d3.svg.line的想法来实现线平滑,这个想法来自于E.Meeks。E. Meeks在这里解释了他的方法。
d3.json("./world-110m.json", function(data){
console.log(data)
var geojson = topojson.feature(data, data.objects.countries);
var newJson = newgeoson(geojson);
console.log(JSON.stringify(newJson))
d3.select("body").append("svg").attr("id","world")
.selectAll("path")
.data(newJson)
.enter()
.append("path")
.style("stroke-width", 1)
.style("stroke", "black")
.style("fill-opacity", .5)
.attr("d", d3.svg.line()
.x(function(d){ return d[0] })
.y(function(d){ return d[1] }).interpolate("cardinal"))
.style("fill", "#7fc97f");
})
console.log(JSON.stringify(d))
并检查数据。通用解决方案已完成,你的代码可以轻松实现。 - Hugolpz