d3.js layout.force 可以用来(重新)定位非 svg 元素,如 div 吗?
如果 divposition: absolute;
可能left
并且top
可以用作 svg 元素中使用的x1
andy1
属性的等价物?
目标是在支持 IE8 的情况下对图像和菜单项产生一些强制效果。我知道 svg 节点可以是图像,但因为我需要支持 IE8,所以这不是一个选项。
如果不可能,是否将svgweb与 d3.js 一起用于此目的?
谢谢!
**更新**
D3好帅!!我开始掌握它的窍门,并且肯定可以在像 div 之类的常规 html 元素上使用“原力d3.layout.force()
”,因为本质上为您可以使用的每个“tick”(或框架)提供 x 和 y 坐标,但是你想。
IE:
force.nodes(data)
.on("tick", tick)
.start();
function tick() {
div.style("left", function(d) {return d.x+"px"})
.style("top", function(d) {return d.y+"px"});
}
工作得很好!
拖动.call(force.drag);
确实会给您带来问题(如预期的那样)。
萤火虫:
(container.ownerSVGElement || container).createSVGPoint is not a function
d3_svg_mousePoint()d3.js (line 3718)
container = div#nav
e = mousemove clientX=607, clientY=200
mouse()d3.js (line 3711)
container = div#nav
d3_behavior_dragPoint()d3.js (line 4481)
d3_behavior_dragDispatch()d3.js (line 4453)
type = "drag"
d3_behavior_dragMove()d3.js (line 4491)
l()d3.js (line 1871)
e = mousemove clientX=607, clientY=200
[Break On This Error]
var point = (container.ownerSVGElement || container).createSVGPoint();
不过应该是可以修复的。