简体   繁体   English

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

[英]Problem in displaying nodes through PREFUSE library for Java?

I am developing a graphical view of data using PREFUSE library. 我正在使用PREFUSE库开发数据的图形视图。

I have 3 kinds of nodes in my graph: 我的图中有3种节点:

  1. APPLICATION 应用
  2. DATABASE 数据库
  3. INTERFACE 接口

Below are some excerpts from my .xml file containing graph 以下是我的包含图表的.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>

I want to show the above 3 diff. 我想显示以上3个差异。 kinds of nodes with 3 diff. 3个差异的各种节点。 kinds of shapes as follows: 各种形状如下:

  1. APPLICATION by Rectangle 矩形应用
  2. DATABASE by custom shape (shape of a cylinder, usually used to denote a database) 通过自定义形状(圆柱形状,通常用于表示数据库)的DATABASE
  3. INTERFACE by circle 圈出界面

I have first read the .xml file in a 我首先阅读了

Graph g 图g

Q1. 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. Q2。 How to specify my custom shape and how to set a renderer that can render the custom shape developed by me? 如何指定我的自定义形状以及如何设置可以渲染我开发的自定义形状的渲染器?

The paradigm for assigning different shapes to nodes is with a DataShapeAction 用于为节点分配不同形状的范例是使用DataShapeAction

Eg 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, ie 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). 这会根据“参议院”数据字段中的值将不同的形状分配给数据点,即,参议员是一种形状,议员是另一种形状(以某种顺序排列(API中对此有多种控件,请参见Constants.ORDINAL)一个例子)。

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. 因此,换句话说,您可能会使用“类型”数据字段来指示节点属于哪种节点,然后使用DataShapeAction分配不同的形状。

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. 我会尝试给您一个更好的答案,但是我想最直接的方法是编写自己的noderenderer子类,该子类能够绘制所需的形状,然后扩展DataShapeAction来处理一些问题。新数据类型的标志。 More on that later, though, hopefully. 希望以后能有更多的信息。

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子类ShapeRenderer ShapeRenderer distinguishes between shapes using id number ( int ). ShapeRenderer使用ID号( int )区分形状。 These ints are in structure Constants for all the standard shapes - like bcr wrote, for example Constants.SHAPE_RECTANGLE . 这些int在结构上是所有标准形状的Constants -如bcr所写,例如Constants.SHAPE_RECTANGLE

Internally prefuse calls ShapeRenderer's protected Shape getRawShape(VisualItem item) function. 内部预熔调用ShapeRenderer protected Shape getRawShape(VisualItem item)函数。 In turn, this function calls other internals from ShapeRenderer in order to get the shape to draw. 反过来,此函数从ShapeRenderer调用其他内部ShapeRenderer以获取要绘制的形状。 For example: 例如:

  • to get the shape id, getRawShape calls int stype = item.getShape() ( set by shape action DataShapeAction ) 要获取形状ID, getRawShape调用int stype = item.getShape()由形状动作DataShapeAction设置
  • then, hawing the shape id at hand, there is switch statement selecting proper shape to draw 然后,拥有手头的形状ID,有switch语句选择要绘制的适当形状

     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 . 为了绘制其他形状(自定义形状),可以将ShapeRenderer子类ShapeRenderer并提供自己的形状实现以绘制和覆盖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. 如果您将形状ID识别为自己的形状ID,则返回形状,否则在getRawShape的实现中调用super(item)以调用标准形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM