作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
以下代码用于显示 javascript 树形图的文本标签。
nodeEnter.append("svg:text")
.attr("x", function(d) { return d._children ? -8 : -48; }) /*the position of the text (left to right)*/
.attr("y", 3) /*the position of the text (Up and Down)*/
.text(function(d) { return d.name; });
这里使用了 svg,它没有自动换行功能。我该如何更改这个普通段落
以便我可以使用 css 将其自动换行。如何制作此常规文本而不是 svg 文本?
最佳答案
这是使用 D3 自动换行文本的示例代码:
var nodes = [
{title: "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut"}
]
var w = 960, h = 800;
var svg = d3.select("body").append("svg")
.attr("width", w)
.attr("height", h);
var vSeparation = 13, textX=200, textY=100, maxLength=20
var textHolder = svg.selectAll("text")
.data(nodes)
.enter().append("text")
.attr("x",textX)
.attr("y",textY)
.attr("text-anchor", "middle")
.each(function (d) {
var lines = wordwrap(d.title, maxLength)
for (var i = 0; i < lines.length; i++) {
d3.select(this).append("tspan").attr("dy",vSeparation).attr("x",textX).text(lines[i])
}
});
function wordwrap(text, max) {
var regex = new RegExp(".{0,"+max+"}(?:\\s|$)","g");
var lines = []
var line
while ((line = regex.exec(text))!="") {
lines.push(line);
}
return lines
}
关于javascript - 将 SVG 文本更改为 css 自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12677878/
在 Vaadin 7.0,显示时JavaBean Table 中的数据与 BeanContainer ,用新数据刷新表的正确方法是什么? 最佳答案 该表通过监听器监视表项的属性。如果您通过表的 Ite
首先,我使用的是带有 Axis2 1.6.2 的 eclipse,我正在 tomcat 6 上部署我创建的 Web 服务。Web 服务是在 eclipse 中通过自上而下的方法创建的。 我被要求使对我
我已将 Rails 3.1.1 应用程序升级到 Rails 3.1.3,现在,对于每个请求,它仅响应错误数量的参数(3 for 1)。不幸的是,它没有说明错误在哪里,并且应用程序跟踪为空。我认为存在一
我是一名优秀的程序员,十分优秀!