【发布时间】:2018-02-08 01:00:54
【问题描述】:
我目前正在构建一个平台,用于映射一些需要在地图中的节点之间画线的数据。现在,我已经创建了这些行
(Picture 1 (fill: none))。此外,我打算在我已经完成的行中添加一个点击侦听器。不幸的是,该路径似乎有一个填充区域,该区域也侦听事件并与其他路径重叠,这使得无法单击其下方的路径 (Picture 2 default fill attr)。我试图设置fill: none(如第一张图片所示),但似乎只删除了颜色,而不是填充区域。
这是我添加行的代码:
function createPath(company) {
//Create Paths Line
var linePathGenerator = d3.line()
.x(function(d) {
return d.x;
})
.y(function(d) {
return d.y;
})
.curve(d3.curveMonotoneX);
// Add Path to the Line Layer
var svgPath = layerArc.append("path")
.attr("stroke", companyConfig[company].color)
.attr("stroke-width", "1.5px")
.attr("fill", "none")
.style("opacity", 0.6);
var d = linePathGenerator(adjency[company])
var line = svgPath.attr("d", d)
// Click Listener
line
.on('click', function() {
if (!d3.select(this).classed("active")) {
layerArc.selectAll('path')
.attr("stroke-width", "1.5px")
.style("opacity", 0.6);
d3.select(this)
.attr("stroke-width", 3)
.style("opacity", 1)
.attr("class", "active")
d3.selectAll(".nodes svg circle")
.style("stroke", 'none')
var circles = d3.selectAll(".nodes svg")
circles = circles.filter(function(d) {
return d.value.company == company
})
circles.select('circle').style("stroke", 'white')
.style("stroke-width", 2)
} else {
layerArc.selectAll('path')
.attr("stroke-width", "1.5px")
.style("opacity", 0.6)
.attr("class", "deactive")
d3.selectAll(".nodes svg circle")
.style("stroke", 'none')
}
})
var totalLength = svgPath.node().getTotalLength();
svgPath
.attr("stroke-dasharray", totalLength + " " + totalLength)
.attr("stroke-dashoffset", totalLength)
.transition()
.duration(4000)
.ease(d3.easeLinear)
.attr("stroke-dashoffset", 0)
}
有人知道如何完全去除填充物吗?或关于我如何以相同方式绘制线条但没有路径的任何其他建议?
【问题讨论】:
-
Stack sn-p 仅用于运行代码,我相应地编辑了您的问题。
-
谢谢@Gerardo Furtado,这是我的第一篇文章
标签: javascript google-maps d3.js svg gis