标记D3中的网络节点(Labeling network nodes in D3)
我需要在D3之外的节点上绘制标签(名称)。 这是我的代码:
<script src="//d3js.org/d3.v3.min.js"></script> <script> var width = window.innerWidth, height = 400; var color = d3.scale.category20(); var force = d3.layout.force() .charge(-120) .linkDistance(40) .size([width, height]); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .call(d3.behavior.zoom().on("zoom", redraw)) .append('g'); function redraw() { svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")");} var drag = force.stop().drag() .on("dragstart", function(d) { d3.event.sourceEvent.stopPropagation(); }); d3.json("/static/net.json", function(error, graph) { if (error) throw error; force .nodes(graph.nodes) .links(graph.links) .start(); var link = svg.selectAll(".link") .data(graph.links) .enter().append("line") .attr("class", "link") .style("stroke-width", function(d) { return Math.sqrt(d.value); }); var node = svg.selectAll(".node") .data(graph.nodes) .enter().append("circle") .attr("class", "node") .attr("r", function(d) { return d.degree; }) .style("fill", function(d) { return color(d.group); }) .call(force.drag); node.append("title") .text(function(d) { return d.name; }) force.on("tick", function() { link.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }); node.attr("cx", function(d) { return d.x; }) .attr("cy", function(d) { return d.y; }); }); }); </script>
出于某种原因,只有当我将鼠标悬停在节点上而不是始终被绘制时,才会出现标签。
当我更换:
node.append("title") .text(function(d) { return d.name; })
有:
node.append("text") .attr("dx", 12) .attr("dy", ".35em") .text(function(d) { return d.name });
即使悬停,也不会出现任何标签。
我的代码中是否有一些明显的东西?
I need to draw labels (names) besides nodes with D3. Here's my code:
<script src="//d3js.org/d3.v3.min.js"></script> <script> var width = window.innerWidth, height = 400; var color = d3.scale.category20(); var force = d3.layout.force() .charge(-120) .linkDistance(40) .size([width, height]); var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height) .call(d3.behavior.zoom().on("zoom", redraw)) .append('g'); function redraw() { svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")");} var drag = force.stop().drag() .on("dragstart", function(d) { d3.event.sourceEvent.stopPropagation(); }); d3.json("/static/net.json", function(error, graph) { if (error) throw error; force .nodes(graph.nodes) .links(graph.links) .start(); var link = svg.selectAll(".link") .data(graph.links) .enter().append("line") .attr("class", "link") .style("stroke-width", function(d) { return Math.sqrt(d.value); }); var node = svg.selectAll(".node") .data(graph.nodes) .enter().append("circle") .attr("class", "node") .attr("r", function(d) { return d.degree; }) .style("fill", function(d) { return color(d.group); }) .call(force.drag); node.append("title") .text(function(d) { return d.name; }) force.on("tick", function() { link.attr("x1", function(d) { return d.source.x; }) .attr("y1", function(d) { return d.source.y; }) .attr("x2", function(d) { return d.target.x; }) .attr("y2", function(d) { return d.target.y; }); node.attr("cx", function(d) { return d.x; }) .attr("cy", function(d) { return d.y; }); }); }); </script>
For some reason, labels only appear if I hover over nodes with the mouse, instead of always being drawn.
When I replace:
node.append("title") .text(function(d) { return d.name; })
with:
node.append("text") .attr("dx", 12) .attr("dy", ".35em") .text(function(d) { return d.name });
No label appear at all, even when hovering.
Is there something obvious I am missing in this code?
原文:https://stackoverflow.com/questions/35440823
最满意答案
我使用Visual Studio作为编译器,并使用emacs作为编辑器。
只需安装Visual Studio C ++ 2010 Express Edition。 然后,我所做的就是编写一个nmake Makefile并从Visual Studio命令提示符调用nmake(可从“程序”菜单访问)。 这适用于较小的项目。
有关更多详细信息,请参阅http://msdn.microsoft.com/en-us/library/f35ctcxw.aspx 。
对于大型项目,您可以在Visual Studio中创建解决方案,并使用emacs作为编辑器。 您也可以从命令提示符调用msbuild来构建解决方案。
此外,visual studio命令提示符只是调用vcvars.bat(或类似的东西)来设置必要的环境。 我猜你可能可以修改emacs shell来指向在启动时运行此bat文件的cmd实例?
I use Visual Studio as a compiler with emacs as an editor.
Just install Visual Studio C++ 2010 Express Edition. Then what I do is write an nmake Makefile and invoke nmake from the Visual Studio Command Prompt (accessible from the Programs menu). This works fine for smaller projects.
See http://msdn.microsoft.com/en-us/library/f35ctcxw.aspx for more details.
For larger projects you can create a solution in Visual Studio and just use emacs as an editor. You can also invoke msbuild from the command prompt to build the solution.
Also, the visual studio command prompt just invokes vcvars.bat (or something like it) to set up the necessary environment. I guess you might be able to modify the emacs shell to point to an instance of cmd that has run this bat file on startup?
相关问答
更多-
您需要在计算机设置的环境变量中设置HOME (如果我没有记错的话),或者将init文件放到默认目录(只需启动Emacs,然后按Cx Cf ~/查看实际目录)。 据我_emacs ,在Windows上,init文件可以被称为_emacs ... You need to set HOME in environment variables in Computer settings (if I remember correctly), or put init file to default directory (j ...
-
我使用aspell在Windows上使用emacs进行拼写检查。 看看我的.emacs文件,我可以看到这些配置变量。 (custom-set-variables '(ispell-dictionary "british") '(ispell-program-name "H:\\bin\\aspell\\bin\\aspell.exe")) 我使用安装向导安装了aspell。 MS-$ ispell-buffer flyspell-mode等都可以正常工作。 I use aspell for ...
-
Windows中的Emacs(Emacs in Windows)[2022-10-30]
我使用EmacsW32 ,它的效果很好。 编辑:我现在使用常规的GNU Emacs 24,见下文。 有关详细信息,请参阅其EmacsWiki页面 。 对我来说,最大的优点是: 它有一个版本的emacsclient启动Emacs服务器,如果没有服务器正在运行(打开所有的文件在同一个Emacs窗口) 它包括几个有用的包,如Nxml 它有一个Windows安装程序,或者你可以从源代码构建它 关于XEmacs,根据Steve Yegge的这篇文章 : 总而言之,我认为XEmacs的市场份额要低得多,性能更差,更多的 ... -
使用Emacs作为IDE(Using Emacs as an IDE)[2022-03-21]
你必须具体说明你的意思是“其余的”。 除了对象检查员(我知道的),emacs很容易做到以上所有: 编辑(明显) 编译器 - 只需运行Mx compile并输入你的编译命令。 从那里,你可以只是Mx compile并使用默认值。 Emacs将捕获C / C ++编译器错误(最好使用GCC),并帮助您导航到带有警告或错误的行。 调试 - 类似地,当你想调试时,键入Mx gdb ,它将创建一个具有特殊绑定的gdb缓冲区 文档查找 - emacs具有出色的CScope绑定用于代码导航。 对于其他文档:Emacs还有 ... -
Emacs通过Putty(Emacs Through Putty)[2021-09-07]
使用Cx o, other-window 。 请参阅http://www.gnu.org/software/emacs/manual/html_node/emacs/Other-Window.html 。 Use C-x o, other-window. See http://www.gnu.org/software/emacs/manual/html_node/emacs/Other-Window.html. -
我使用Visual Studio作为编译器,并使用emacs作为编辑器。 只需安装Visual Studio C ++ 2010 Express Edition。 然后,我所做的就是编写一个nmake Makefile并从Visual Studio命令提示符调用nmake(可从“程序”菜单访问)。 这适用于较小的项目。 有关更多详细信息,请参阅http://msdn.microsoft.com/en-us/library/f35ctcxw.aspx 。 对于大型项目,您可以在Visual Studio中创建 ...
-
Windows上的emacs中的gdb(gdb within emacs on Windows)[2022-07-24]
可能会调整您的系统路径,将其指向您安装gdb的位置。 probably adjust your system path to point it where you have gdb installed. -
对于后人来说,让Emacs从.emacs.d文件夹中读取数据的.emacs.d是首先手动删除.emacs.d文件夹中的所有.emacs文件(对于我来说,rlrner / AppData / Roaming)。 这将迫使Emacs在rlrner / AppData / Roaming / .emacs.d中寻找init.el,就像在OS X中一样。 这里的文档: https : //www.emacswiki.org/emacs/DotEmacsDotD For posterity, the way to h ...
-
(shell-command "ver" t) ;; outputs version in current buffer (shell-command "ver" t) ;; outputs version in current buffer
-
从w32-pass-lwindow-to-system的文档: 请注意,左侧“Windows”键与其他键的某些组合由Windows在低级别捕获,因此在Emacs中绑定它们将不起作用。 例如,
-r总是弹出Windows运行对话框, - 弹出“系统属性”对话框等。但是,请参阅`w32-phantom-key-code'的文档字符串。 从w32-phantom-key-code的文档: 用于生成“幻像”按键的虚拟键码。 值是0到255之间的数字。生成幻像按键是为 ...