繁体   English   中英

需要像箭头一样预先填充图形边缘

[英]need prefuse graph edges like arrows

我完成了我的作业,并在谷歌搜索了一个样本和一个在stackoverflow之前回答的主题。 但是没有找到任何东西。

我的问题是没有箭头视图的普通边缘。

以下是我希望从目标到目的地的前进箭头:

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

这是我看到的边缘颜色,希望这些不一定是透明的:

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

因此,我想知道我错在哪里? 为什么我的边缘看起来不像箭头?

谢谢你的想法。

有关更多详细信息,我想粘贴所有代码:

/*
 * 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");

    }
}

如果您对prefuse论坛中给出的答案感到满意,我不确定您的评论。 因此,我玩了代码并通过以下更改能够获得您想要的行为。

我更改了输入xml,以便定向图元素的edgedefault。

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

然后在代码中我使用不同的EdgeRenderer边缘类型和箭头类型来确保我可以打开和关闭箭头,或让它们向前或向后显示。 我也试过弯曲的线条。 例如:

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

同样,您可能已经在其他论坛中得到了答案。

我偶然发现了同样的问题。 对于刚开始使用的prefuse库的未来用户:如果要向RadialGraphView示例添加箭头,则需要进行ditkin提到的更改并添加以下行:

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

以及下面:

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

基本上,答案是在sourceforge线程中,但我想在这里提供一个解决方案。 merve的代码包含这些指令。

暂无
暂无

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

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