通过 Java 的 PREFUSE 库显示节点时出现问题?

发布于 2024-08-21 22:07:37 字数 922 浏览 7 评论 0原文

我正在使用 PREFUSE 库开发数据的图形视图。

我的图中有 3 种节点:

  1. 应用程序
  2. 数据库
  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 个差异的节点类型。各种形状如下:

  1. 应用程序按矩形
  2. 数据库按自定义形状(圆柱体的形状,通常用于表示数据库)
  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:

  1. APPLICATION
  2. DATABASE
  3. 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:

  1. APPLICATION by Rectangle
  2. DATABASE by custom shape (shape of a cylinder, usually used to denote a database)
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下客 2024-08-28 22:07:37

为节点分配不同形状的范例是使用 DataShapeAction

,例如在“国会”演示中(这同样适用于作为表的节点):

int[] shapes = new int[]
            { Constants.SHAPE_RECTANGLE, Constants.SHAPE_DIAMOND };
DataShapeAction shape = new DataShapeAction(group, "Senate", shapes);

这根据“参议院”数据字段中的值向数据点分配不同的形状,即参议员是一种形状,国会议员是另一种形状,按某种顺序(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):

int[] shapes = new int[]
            { Constants.SHAPE_RECTANGLE, Constants.SHAPE_DIAMOND };
DataShapeAction shape = new DataShapeAction(group, "Senate", shapes);

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.

七分※倦醒 2024-08-28 22:07:37

您不需要谓词来分配形状。事实上,为了绘制自定义形状,您必须对形状绘制渲染器 ShapeRenderer 进行子类化。 ShapeRenderer 使用 ID 号 (int) 来区分形状。
这些整数位于所有标准形状的 Constants 结构中 - 就像 bcr 所写的那样,例如 Constants.SHAPE_RECTANGLE

prefuse 在内部调用 ShapeRenderer 的 protected Shape getRawShape(VisualItem item) 函数。反过来,该函数从 ShapeRenderer 调用其他内部函数以获得要绘制的形状。例如:

  • 要获取形状 ID,getRawShape 调用 int stype = item.getShape()由形状操作 DataShapeAction 设置< /em>)
  • 然后,掌握手边的形状 ID,使用 switch 语句选择要绘制的正确形状

    开关 ( stype )  
    {  
    case Constants.SHAPE_NONE:  
        返回空值;  
    case Constants.SHAPE_RECTANGLE:  
        返回矩形(x,y,宽度,宽度);  
    case Constants.SHAPE_ELLIPSE:  
        返回椭圆(x,y,宽度,宽度);  
    case Constants.SHAPE_TRIANGLE_UP:  
        返回triangle_up((float)x,(float)y,(float)width);  
    ...  
    

为了绘制一些其他形状(自定义形状),您需要子类 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 example Constants.SHAPE_RECTANGLE.

Internally prefuse calls ShapeRenderer's protected Shape getRawShape(VisualItem item) function. In turn, this function calls other internals from ShapeRenderer in order to get the shape to draw. For example:

  • to get the shape id, getRawShape calls int stype = item.getShape() (set by shape action DataShapeAction)
  • then, hawing the shape id at hand, there is switch statement selecting proper shape to draw

    switch ( stype )  
    {  
    case Constants.SHAPE_NONE:  
        return null;  
    case Constants.SHAPE_RECTANGLE:  
        return rectangle(x, y, width, width);  
    case Constants.SHAPE_ELLIPSE:  
        return ellipse(x, y, width, width);  
    case Constants.SHAPE_TRIANGLE_UP:  
        return triangle_up((float)x, (float)y, (float)width);  
    ...  
    

In order to draw some other shapes (custom ones) you subclass ShapeRenderer and provide your own implementation of shape to draw and override getRawShape.
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文