2011-01-04 16 views
6

Hice mi tarea y busqué en google una muestra y un tema que se contestó anteriormente en stackoverflow. Pero nada ha sido encontrado.necesito prefigurar los bordes del gráfico como flechas

Mi problema son los bordes comunes que no tienen una vista como flechas.

Aquí es lo que hago a la esperanza que hay hacia adelante flechas de destino a destino:

 
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); 


Esto es lo que veo sobre el color de los bordes, con la esperanza éstas no deben ser transparentes:

 
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 colour = new ActionList(); 
     colour.add(fill); 
     colour.add(text); 
     colour.add(edges); 
     colour.add(arrow); 
     vis.putAction("colour", colour); 

Por lo tanto, me pregunto dónde estoy equivocado? ¿Por qué mis bordes no parecen flechas?

Gracias por cualquier idea.

Para más detalles, quiero pegar todo el código:

 
/* 
* 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 

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


     // map data to colours in the palette 
     DataColorAction fill = new DataColorAction("socialnet.nodes", "gender", Constants.NOMINAL, VisualItem.FILLCOLOR, palette); 
     /* fill describes what colour 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 colour 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 colour to draw the edges */ 

     // combine the colour assignments into an action list 
     ActionList colour = new ActionList(); 
     colour.add(fill); 
     colour.add(text); 
     colour.add(edges); 
     colour.add(arrow); 
     vis.putAction("colour", colour); 
     /* add the colour 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("colour"); 
     vis.run("layout"); 

    } 
} 


+0

hola, mi pregunta se responde aquí: https://sourceforge.net/projects/prefuse/forums/forum/343013/topic/4035245/index/page/1 También he encontrado una ejecución ejemplo en la página siguiente, pero es un poco complicado complicado para un buscador básico de gráficos: http://goosebumps4all.net/34all/bb/showthread.php?tid=17 si debo dar alguna línea de código, las líneas clave están aquí:

... graph = new GraphMLReader().readGraph("socialnet.xml"); ... Table n = graph.getNodeTable(); Table e = graph.getEdgeTable(); Graph g_new = new Graph(n, e, true); 
Gracias de antemano por la atención. – merve

Respuesta

2

No estoy seguro de por sus comentarios si está satisfecho con la respuesta dada en los foros Prefuse. Por lo tanto, jugué con el código y con los siguientes cambios pude obtener el comportamiento que desea.

Cambié la entrada xml para que se ordene el edgedefault del elemento gráfico.

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

Luego, en el código que juega con diferentes edgetypes EdgeRenderer y arrowtypes sólo para asegurarse de que podía encender y apagar las flechas, o hacer que la pantalla hacia delante o hacia atrás. También probé líneas curvas. Por ejemplo:

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

De nuevo, es posible que ya haya obtenido una respuesta a esto en los demás foros.

0

Me encontré con la misma pregunta. Para el futuro usuario de la biblioteca prefuse que se están iniciando: Si desea añadir flechas para el ejemplo RadialGraphView, es necesario realizar los cambios mencionados por ditkin y añadir la línea:

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

y más adelante:

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

Básicamente, la respuesta está en el hilo de sourceforge, pero quería proporcionar una solución aquí. El código de merve contiene estas instrucciones.

Cuestiones relacionadas