旋转SVG文本围绕一个圆圈,然后围绕自己使用d3
Rotate SVG text around a circle then around itself using d3
我有一个可视化的标签放置的位置,通过围绕圆圈的中心旋转。然而,这意味着圆圈左侧的所有标签都是上下颠倒的。是否有可能旋转左手边的标签周围,在这个旋转发生后?
可视化是基于来自d3js.org的zoomable
日冕
相关代码为:
function computeTextRotation(d) {
var angle=(d.x +d.dx/2)*180/Math.PI - 90;
return angle;
}
var texts = svg.selectAll("text")
.data(partitioned_data)
.enter().append("text")
.filter(filter_min_arc_size_text)
.attr("transform", function(d) {return "rotate(" + computeTextRotation(d) + ")"})
.attr("x", function(d) { return radius / 3 * d.depth; })
.attr("dx", "6") // margin
.attr("dy", ".35em") // vertical-align
.text(function(d,i) {return d.name})
我尝试了下面的代码,因为我知道这是可能的,如果你知道文本的x
和y
坐标,但它不会让我通过d.x
和d.y
作为坐标。
var texts = svg.selectAll("text")
.data(partitioned_data)
.enter().append("text")
.filter(filter_min_arc_size_text)
.attr("transform", function(d) {
if (computeTextRotation(d)>90&&computeTextRotation(d)<270) {
return "rotate(" + computeTextRotation(d) + ") rotate(d.x,d.y,180)";
} else {
return "rotate(" + computeTextRotation(d) + ")";
}})
.attr("x", function(d) { return radius / 3 * d.depth; })
.attr("dx", "6") // margin
.attr("dy", ".35em") // vertical-align
.text(function(d,i) {return d.name})
我不是100%确定你的意思,当你说"它不会让我传递d.x和d.y作为坐标",但它看起来像你试图传递变量名称作为字符串,而不是变量值。在下面的代码中,我改变了你的。attr("transform")来传递d.x和d.y的值。
var texts = svg.selectAll("text")
.data(partitioned_data)
.enter()
.append("text")
.filter(filter_min_arc_size_text)
.attr("transform", function(d) {
if (computeTextRotation(d)>90&&computeTextRotation(d)<270) {
return "rotate(" + computeTextRotation(d) +
") rotate(" + d.x + "," + d.y + ",180)";
} else {
return "rotate(" + computeTextRotation(d) + ")";
}
})
.attr("x", function(d) { return radius / 3 * d.depth; })
.attr("dx", "6") // margin
.attr("dy", ".35em") // vertical-align
.text(function(d,i) {return d.name})
相关文章:
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- Javascript运行php文件,然后下载文件
- 如何将屏幕分辨率乘以 80%,然后在代码中使用
- 弹出窗口出现,然后退出
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 将值输入到对象,然后该对象推送到数组
- 如何临时暂停浏览器渲染,然后恢复整个页面
- JS:检查URL中的参数,然后迭代一个参数为var的函数
- 按我自己的类克隆另一个元素的内容和顺序
- 如何配置分析以将数据发送到我自己的服务器
- 滚动然后捕捉到顶部而不是取消捕捉
- AngularJS加载JSON数据,然后从中解析/加载HTML
- 节点 - MySQL 查询,需要几分钟时间,在几分钟后重复自己,然后完成原始查询
- PHP脚本重新运行自己,直到进程完成.然后每周重新启动
- I'我试着只点击4次,然后就不起作用了,尽管我不确定自己做错了什么
- Javascript -是否有可能在函数定义后调用它自己,然后在作用域的其他地方作为函数被引用?
- 旋转SVG文本围绕一个圆圈,然后围绕自己使用d3
- CORS标头未设置-我可以请求一个图像url,然后将其发送回自己吗
- 按钮更新它自己的OnClientClick,然后执行它