Prefuse:向 GraphView 演示添加边权重
我正在使用 prefuse 可视化工具包,工具包中的 GraphView 演示非常出色,提供了各种控件来可视化数据。
我能够为我的数据集生成 GraphML 并使用 GraphView 对其进行可视化,我希望拥有的另一件事是使用权重或颜色编码来标记边缘,以展示两个节点之间的强度。
任何有关相同的意见都非常感谢..谢谢..
I am using the prefuse visualization toolkit, The GraphView Demo in the toolkit is amazing providing a variety of controls to visualize the data.
I am able to generate GraphML for my dataset and visualize it using GraphView, One additional thing that i would love to have is to label the edges with weights or color coding to demonstrate the strength between two nodes.
Any input about the same are greatly appreciated..Thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
免责声明:我没有使用过该 API,只是检查了文档:) 看来该 API 有一个 EdgeRenderer 接口,您应该实现该接口来实现所需的行为。
参考:http://prefuse.org/doc/manual/introduction/example/ , http://prefuse.org/doc/api/prefuse/render/DefaultRendererFactory.html
更新:首先更正:事实上 EdgeRenderer 不是一个 iterface,而是一个类。我做了一个简单的演示来说明如何实现自定义边缘渲染。
功能
将标签添加到包含节点标签首字母缩写的边缘
方法
我做了一个快速但肮脏的解决方案,即复制 LabelRenderer 并进行修改以处理边缘。
代码
我将该类命名为
MyEdgeRenderer
:使用原始
EdgeRenderer
绘制边缘线(有关渲染器的实际操作,请参阅下面的render()
):修改
getText()
以从节点获取缩写:修改
getAlignedPoint()
以将标签定位在边缘的一半位置:修改
render()
(I) 首先画线并(II) 使用黑色:为了测试,我修改了 Prefuse 网站上找到的示例 (http://prefuse.org/doc/manual/introduction/example/Example.java):
这只是一个演示,用于说明自定义渲染。实际上,您可能会从图形模型中检索标签文本和颜色,即:
EdgeItem.getString()、getTextColor()
。我猜这两个属性都可能来自 GraphML 数据。示例代码还显示了如何为节点设置颜色,它也可能适用于边缘(尽管我还没有尝试过):Disclaimer: I haven't worked with the API just checked the documentation:) It seems that the API has an EdgeRenderer interface that you should implement to achieve the desired behaviour.
Ref: http://prefuse.org/doc/manual/introduction/example/, http://prefuse.org/doc/api/prefuse/render/DefaultRendererFactory.html
Update: First a correction: in fact EdgeRenderer is not an iterface but a class. I've made a simple demo to illustrate how to implement custom edge rendering.
Feature
Add label to edges containing the initials of the node labels
Method
I made a quick and dirty solution, that is copied LabelRenderer and modified in order to handle edges.
Code
I named the class as
MyEdgeRenderer
:use the original
EdgeRenderer
to draw edge lines (seerender()
below for the renderer in action):modify
getText()
to get the initials from nodes:modified
getAlignedPoint()
to position the label half way on the edge:modify
render()
to (I) first draw the line and (II) use black color:For testing I modified the sample found on the Prefuse website (http://prefuse.org/doc/manual/introduction/example/Example.java):
This is just a demo to illustrate custom rendering. In real you would probably retrieve label text and color from the graph model, ie:
EdgeItem.getString(), getTextColor()
. I guess both attribute could come from the GraphML data. Also the example code shows how to set colors for nodes, it might be adapted for edges as well (though I haven't tried):