通过 Java 的 PREFUSE 库显示节点时出现问题?
我正在使用 PREFUSE 库开发数据的图形视图。
我的图中有 3 种节点:
- 应用程序
- 数据库
- 接口
下面是我的 .xml 文件中的一些摘录,其中包含
<node id="AP-1">
<data key="name">Application1</data>
<data key="type">APPLICATION</data>
</node>
<node id="DB-1">
<data key="name">Database1</data>
<data key="type">DATABASE</data>
</node>
<node id="IT-1">
<data key="name">Interface1</data>
<data key="type">INTERFACE</data>
</node>
我想显示上述 3 个差异的图。具有 3 个差异的节点类型。各种形状如下:
- 应用程序按矩形
- 数据库按自定义形状(圆柱体的形状,通常用于表示数据库)
- 界面按圆形
我首先读取了
图形 g
Q1 中的 .xml 文件。现在我如何区分数据组中的这 3 种节点。我想我应该写谓词。我已经阅读了 prefuse 的整个谓词和表达式手册,但无法编写谓词来区分它们。那么它的谓词是什么?
Q2。如何指定我的自定义形状以及如何设置可以渲染我开发的自定义形状的渲染器?
I am developing a graphical view of data using PREFUSE library.
I have 3 kinds of nodes in my graph:
- APPLICATION
- DATABASE
- INTERFACE
Below are some excerpts from my .xml file containing graph
<node id="AP-1">
<data key="name">Application1</data>
<data key="type">APPLICATION</data>
</node>
<node id="DB-1">
<data key="name">Database1</data>
<data key="type">DATABASE</data>
</node>
<node id="IT-1">
<data key="name">Interface1</data>
<data key="type">INTERFACE</data>
</node>
I want to show the above 3 diff. kinds of nodes with 3 diff. kinds of shapes as follows:
- APPLICATION by Rectangle
- DATABASE by custom shape (shape of a cylinder, usually used to denote a database)
- INTERFACE by circle
I have first read the .xml file in a
Graph g
Q1. Now how can I distinguish these 3 kinds of nodes in a datagroup. I think I should write predicates. I have read the whole predicates and expressions manuals for prefuse but couldn't write a predicate to distinguish them. So what will be the predicate for that?
Q2. How to specify my custom shape and how to set a renderer that can render the custom shape developed by me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为节点分配不同形状的范例是使用 DataShapeAction
,例如在“国会”演示中(这同样适用于作为表的节点):
这根据“参议院”数据字段中的值向数据点分配不同的形状,即参议员是一种形状,国会议员是另一种形状,按某种顺序(API 中对此有各种控件,请参阅 Constants.ORDINAL 获取示例)。
因此,换句话说,您可能会使用“类型”数据字段来指示该节点是什么类型的节点,然后使用 DataShapeAction 来分配不同的形状。
定义新的形状当然是可能的,但需要更多的修改。我会尝试给你一个更好的答案,但我猜最直接的方法是编写你自己的 NodeRenderer 子类,它能够绘制你想要的形状,然后也许扩展 DataShapeAction 来处理一些新数据类型的标志。不过,希望稍后会详细介绍。
The paradigm for assigning different shapes to nodes is with a DataShapeAction
E.g. in the "Congress" demo (the same applies to Nodes as Tables):
This assigns different shapes to data points based on the value in the "Senate" data field, i.e. senators are one shape, and congressmen are another shape, in some order (there are various controls for this in the API, see Constants.ORDINAL for an example).
So, in other words, you would probably use your "type" data field to indicate what kind of node the node was, and then use a DataShapeAction to assign different shapes.
Defining a new shape is certainly possible, but will require some more tinkering. I'll try to get back to you with a better answer, but I'm guessing the most straightforward way would be to write your own subclass of the noderenderer that was capable of drawing your desired shape, and then perhaps extending DataShapeAction to handle some flag for your new data type. More on that later, though, hopefully.
您不需要谓词来分配形状。事实上,为了绘制自定义形状,您必须对形状绘制渲染器
ShapeRenderer
进行子类化。 ShapeRenderer 使用 ID 号 (int
) 来区分形状。这些整数位于所有标准形状的
Constants
结构中 - 就像 bcr 所写的那样,例如Constants.SHAPE_RECTANGLE
。prefuse 在内部调用 ShapeRenderer 的
protected Shape getRawShape(VisualItem item)
函数。反过来,该函数从ShapeRenderer
调用其他内部函数以获得要绘制的形状。例如:getRawShape
调用int stype = item.getShape()
(由形状操作DataShapeAction
设置< /em>)然后,掌握手边的形状 ID,使用
switch
语句选择要绘制的正确形状为了绘制一些其他形状(自定义形状),您需要子类
ShapeRenderer
并提供您自己的形状实现来绘制和覆盖getRawShape
。如果您将形状 ID 识别为您自己的形状,则返回您的形状,否则您在
getRawShape
的实现中调用 super(item) 来调用标准形状。You don't need predicates to assign shapes. In fact, in order to draw custom shapes you have to subclass the shape drawing renderer
ShapeRenderer
. ShapeRenderer distinguishes between shapes using id number (int
).These ints are in structure
Constants
for all the standard shapes - like bcr wrote, for exampleConstants.SHAPE_RECTANGLE
.Internally prefuse calls ShapeRenderer's
protected Shape getRawShape(VisualItem item)
function. In turn, this function calls other internals fromShapeRenderer
in order to get the shape to draw. For example:getRawShape
callsint stype = item.getShape()
(set by shape actionDataShapeAction
)then, hawing the shape id at hand, there is
switch
statement selecting proper shape to drawIn order to draw some other shapes (custom ones) you subclass
ShapeRenderer
and provide your own implementation of shape to draw and overridegetRawShape
.If you recognize the shape id as your own you return your shape otherwise you call super(item) in your implementation of
getRawShape
in order to call the standard one.