在 D3 地图中向 SVG 元素添加边框和边框半径
adding a border and border radius to an svg element in D3 Maps
function buildMap(target, data, path, type) {
var svg = d3.select(target);
svg
.selectAll('path')
.data(data).enter()
.append('g').attr('class', function(d) {
var name = sanitize(d.properties.name);
// if(name != 'territories'){
return name + '-group';
// }
})
.append('path')
.attr('d', path)
.attr("style", function() {
if(this.parentNode.parentNode.className.animVal == 'territories-group' && type == 'full'){
//console.log(this.parentNode.parentNode.className.animVal == 'territories-group');
return "outline: thick solid #FFFFFF;";
}
})
.attr('class', function(d) {
if (d.properties.hasOwnProperty('selected') && d.properties.selected) {
return 'highlighted';
}
})
.attr('transform', function(d) {
if (type == 'none') {
return '';
}
var transform = getTransform(d, type);
return transform;
});
}
我正在绘制美国和美国领土的地图。我需要在每个美国领土周围建立一个圆形边界,但我没有运气。它可以在路径或<g>
标记周围。现在,我只有一个轮廓,它勾勒出路径并且是矩形的。我也尝试将轮廓更改为圆形,但也没有找到正确的方法。我尝试附加一个新的矩形、圆形等,但 x 和 y 坐标都是一样的。我找不到使它们动态或相对于子元素的方法。
地图的当前树
<svg>
<a>
<g>
<path>
我真的不知道 d3,但设置路径的笔触和笔触宽度属性应该会为其添加边框。 所以你有
.attr("style", function() {
if(this.parentNode.parentNode.className.animVal == 'territories-group' && type == 'full'){
return "outline: thick solid #FFFFFF;";
}
})
块,尝试如下操作:
.attr('stroke','#FFFFFF')
.attr('stroke-width', 3)
.attr('fill','none')
所以整个函数看起来像这样:
function buildMap(target, data, path, type) {
var svg = d3.select(target);
svg
.selectAll('path')
.data(data).enter()
.append('g').attr('class', function(d) {
var name = sanitize(d.properties.name);
// if(name != 'territories'){
return name + '-group';
// }
})
.append('path')
.attr('d', path)
.attr('stroke','#FFFFFF')
.attr('stroke-width', 3)
.attr('fill','none')
.attr('class', function(d) {
if (d.properties.hasOwnProperty('selected') && d.properties.selected) {
return 'highlighted';
}
})
.attr('transform', function(d) {
if (type == 'none') {
return '';
}
var transform = getTransform(d, type);
return transform;
});
}
让我知道这是否对您有帮助。
相关文章:
- 在mouseover上添加边框,在mouseout上删除边框
- 如何在 javascript 中添加和删除图像上的边框
- Video.js在视频上添加黑色边框
- 在覆盖和关闭按钮或链接中为img添加边框
- 如何添加添加边框的无限制点击
- 动画添加边框(先增大然后缩小)
- 如何在高图表中为标题添加边框
- 在 JavaScript 中编辑 blob 图像(调整大小并添加边框)
- 为什么我动态添加的边框不会显示在 IE8 中
- 使用Javascript为输入字段添加边框样式颜色(提交时没有值),该字段已经在css中带有!important标签的边
- 如何在跳转到页面时向行添加边框
- 使用 jquery 将鼠标悬停在地图区域时添加边框
- 如何将边框添加到 jQuery 按钮
- 谷歌地图为自定义标记添加了矩形边框
- Javascript将数组添加到带有边框的表中
- 优化jQuery动态添加插入边框效果
- 引导表将边框添加到'内容可编辑'改变后上课
- Onmouseover在JavaScript中添加边框
- 在 D3 地图中向 SVG 元素添加边框和边框半径
- 使用Jquery添加边框