Need graph prefix graphs such as arrows

I did my homework and searched for both google for the sample and the topic that was answered earlier in stackoverflow. But nothing was found.

My problem is regular edges that don't have a look like arrows.

Here is what I do to hope that there are arrows forward from target to target:

  LabelRenderer nameLabel = new LabelRenderer ("name");
         nameLabel.setRoundedCorner (8, 8);
         DefaultRendererFactory rendererFactory = new DefaultRendererFactory (nameLabel);
         EdgeRenderer edgeRenderer;
     edgeRenderer = new EdgeRenderer (prefuse.Constants.EDGE_TYPE_LINE, prefuse.Constants.EDGE_ARROW_FORWARD);
         rendererFactory.setDefaultEdgeRenderer (edgeRenderer);
         vis.setRendererFactory (rendererFactory);


Here is what I see about the color of the ribs, hoping that they should not be transparent:

  int [] palette = new int [] {ColorLib.rgb (255, 180, 180), ColorLib.rgb (190, 190, 255)};

         DataColorAction fill = new DataColorAction ("socialnet.nodes", "gender", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);

         ColorAction text = new ColorAction ("socialnet.nodes", VisualItem.TEXTCOLOR, ColorLib.gray (0));


         ColorAction edges = new ColorAction ("socialnet.edges", VisualItem.STROKECOLOR, ColorLib.gray (200));
         ColorAction arrow = new ColorAction ("socialnet.edges", VisualItem.FILLCOLOR, ColorLib.gray (200));

         ActionList color = new ActionList ();
         color.add (fill);
         color.add (text);
         color.add (edges);
         colour.add (arrow);
         vis.putAction ("color", color);

So I wonder where I am going wrong? Why don't my edges look like arrows?

Thanks for any idea.

For more details, I want to insert all the code:

  / *
  * To change this template, choose Tools |  Templates
  * and open the template in the editor.
  * /

 package prefusedeneme;

 import javax.swing.JFrame;

 import prefuse.data. *;
 import prefuse.data.io. *;
 import prefuse.Display;
 import prefuse.Visualization;
 import prefuse.render. *;
 import prefuse.util. *;
 import prefuse.action.assignment. *;
 import prefuse.Constants;
 import prefuse.visual. *;
 import prefuse.action. *;
 import prefuse.activity. *;
 import prefuse.action.layout.graph. *;
 import prefuse.controls. *;
 import prefuse.data.expression.Predicate;
 import prefuse.data.expression.parser.ExpressionParser;

 public class SocialNetworkVis {

     public static void main (String argv []) {

         // 1. Load the data

         Graph graph = null;
         / * graph will contain the core data * /
         try {
             graph = new GraphMLReader (). readGraph ("socialnet.xml");

         / * load the data from an XML file * /
         } catch (DataIOException e) {
             e.printStackTrace ();
             System.err.println ("Error loading graph. Exiting ...");
             System.exit (1);
         }

         // 2. prepare the visualization

         Visualization vis = new Visualization ();
         / * vis is the main object that will run the visualization * /
         vis.add ("socialnet", graph);
         / * add our data to the visualization * /

         // 3. setup the renderers and the render factory

         // labels for name
         LabelRenderer nameLabel = new LabelRenderer ("name");
         nameLabel.setRoundedCorner (8, 8);
         / * nameLabel decribes how to draw the data elements labeled as "name" * /

         // create the render factory
         DefaultRendererFactory rendererFactory = new DefaultRendererFactory (nameLabel);
         EdgeRenderer edgeRenderer;
     edgeRenderer = new EdgeRenderer (prefuse.Constants.EDGE_TYPE_LINE, prefuse.Constants.EDGE_ARROW_FORWARD);
         rendererFactory.setDefaultEdgeRenderer (edgeRenderer);
         vis.setRendererFactory (rendererFactory);


         // 4. process the actions

         // color palette for nominal data type
         int [] palette = new int [] {ColorLib.rgb (255, 180, 180), ColorLib.rgb (190, 190, 255)};
         / * ColorLib.rgb converts the color values ​​to integers * /


         // map data to colors in the palette
         DataColorAction fill = new DataColorAction ("socialnet.nodes", "gender", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
         / * fill describes what color to draw the graph based on a portion of the data * /

         // node text
         ColorAction text = new ColorAction ("socialnet.nodes", VisualItem.TEXTCOLOR, ColorLib.gray (0));
         / * text describes what color to draw the text * /

         // edge
         ColorAction edges = new ColorAction ("socialnet.edges", VisualItem.STROKECOLOR, ColorLib.gray (200));
         ColorAction arrow = new ColorAction ("socialnet.edges", VisualItem.FILLCOLOR, ColorLib.gray (200));
         / * edge describes what color to draw the edges * /

         // combine the color assignments into an action list
         ActionList color = new ActionList ();
         color.add (fill);
         color.add (text);
         color.add (edges);
         colour.add (arrow);
         vis.putAction ("color", color);
         / * add the color actions to the visualization * /

         // create a separate action list for the layout
         ActionList layout = new ActionList (Activity.INFINITY);
         layout.add (new ForceDirectedLayout ("socialnet"));
         / * use a force-directed graph layout with default parameters * /

         layout.add (new RepaintAction ());
         / * repaint after each movement of the graph nodes * /

         vis.putAction ("layout", layout);
         / * add the laout actions to the visualization * /

         // 5. add interactive controls for visualization

         Display display = new Display (vis);
         display.setSize (700, 700);
         display.pan (350, 350);  // pan to the middle
         display.addControlListener (new DragControl ());
         / * allow items to be dragged around * /

         display.addControlListener (new PanControl ());
         / * allow the display to be panned (moved left / right, up / down) (left-drag) * /

         display.addControlListener (new ZoomControl ());
         / * allow the display to be zoomed (right-drag) * /

         // 6. launch the visualizer in a JFrame

         JFrame frame = new JFrame ("prefuse tutorial: socialnet");
         / * frame is the main window * /

         frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

         frame.add (display);
         / * add the display (which holds the visualization) to the window * /

         frame.pack ();
         frame.setVisible (true);

         / * start the visualization working * /
         vis.run ("color");
         vis.run ("layout");

     }
 }


+6
java prefuse
source share
2 answers

I am not sure about your comments if you are satisfied with the answer given on the prefuse forums. Therefore, I played with the code and with the following changes I was able to get the desired behavior.

I changed the input xml file so that the edgedefault element is directed.

... <graph edgedefault="directed"> ... 

Then in the code, I played with different EdgeRenderer edgetypes and arrows to make sure that I can turn the arrows on and off, or make them display forward or backward. I also tried curved lines. For example:

 edgeRenderer = new EdgeRenderer(prefuse.Constants.EDGE_TYPE_CURVE, prefuse.Constants.EDGE_ARROW_FORWARD); 

Again, you may have already received an answer to this in other forums.

+2
source share

I came across the same question. For future users of the prefuse library who start work: If you want to add arrows for example RadialGraphView, you need to make the changes mentioned by ditkin and add the line:

 ColorAction arrowColor = new ColorAction("tree.edges", VisualItem.FILLCOLOR, ColorLib.gray(200)); 

and below:

 // create the filtering and layout: [...] filter.add(arrowColor); // add this one 

Basically, the answer is in the sourceforge stream, but I would like to offer a solution here. The code from merve contains these instructions.

0
source share

All Articles