javascript - 圆形对象内的图像导致像素化 d3 js

标签 javascript jquery css d3.js

看来我已经正确地按照这些步骤用外部图像填充了一个圆圈。我尝试了很多不同的图像链接,但仍然无法解决这个像素化问题。感谢您的帮助,这是我的 fiddle 的链接:

http://jsfiddle.net/SdN2F/7/

代码问题片段:

var photoCircle = d3.select('svg')
                .append("circle")
                .attr("cx", width-160)
                .attr("cy", height-140)
                .attr("r", radius-35)
                .style("fill", "url(#photo)");

var image = d3.select('svg')
                .append("pattern")
                .attr("id", "photo")
                .attr("x", 0)
                .attr("y", 0)
                .attr("width", width-160)
                .attr("height", height-140)    
                .append("image")
                .attr("x", 0)
                .attr("y", 0)
                .attr("width", width-160)
                .attr("height", height-140)
                .attr("xlink:href", "http://static-1.nexusmods.com/15/mods/110/images/50622-1-1391287636.jpeg");

最佳答案

您需要设置patternpatternUnits 属性。

var image = d3.select('svg').append('defs')
                .append("pattern")
                .attr("id", "photo")
                .attr("patternUnits","userSpaceOnUse")
                .attr("x", 0)
                .attr("y", 0)
                .attr("width", 2*radius)
                .attr("height", 2*radius)

.append("image")
                 .attr("x", 0)
                .attr("y", 0)
                .attr("width", 2*radius)
                .attr("height", 2*radius)
                .attr("xlink:href", "http://static-1.nexusmods.com/15/mods/110/images/50622-1-1391287636.jpeg");

jsFiddle:http://jsfiddle.net/chrisJamesC/SdN2F/11/

关于javascript - 圆形对象内的图像导致像素化 d3 js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24131767/

相关文章:

html - 将 HTML 表格设置为看起来像电子表格(如 Google 文档)

javascript - 在 Canvas 中显示坐标 - JavaScript

javascript - 我可以在 Alfresco 拖放上传中选择内容类型吗?

javascript - 避免在移动设备上按下按钮时的长按行为

jquery - 如何使用 jquery 更改输入字段的值?

css - 使用 CSS flexbox 重新排序整个页面

javascript - 如何在不丢失文本格式的情况下替换内容可编辑 div 中部分文本的文本格式

javascript - 计算 HTML 表格中的百分比 - jQuery

javascript - 在 MapMyindia map 上显示多个标记

css - 小图像,但是在 Firebug 中看到一个 "imaginary box"阻止我使用链接?