如何在 prefuse 中自定义渲染。 prefuse 布局中自定义图像的问题

发布于 2024-08-30 20:18:12 字数 4457 浏览 8 评论 0原文

大家好,

我编写了一个java应用程序来以不同的布局显示图像。我能够正确地显示不同的布局,但有时图像会重叠。在我的应用程序中,有超过 20/30 个节点和几个具有 6 到 10 个边的节点。图片尺寸为50*50。由于有 10 条边,节点将重叠,即图像将重叠在另一个图像上。我该如何解决这个问题?

任何帮助将不胜感激。

我的代码如下

 
import javax.swing.JFrame;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO; 
import java.util.;
import java.io.;
import java.awt.Font;

导入 prefuse.常量; 导入预保险丝。显示; 导入 prefuse.可视化; 导入 prefuse.action.ActionList; 导入 prefuse.action.RepaintAction; 导入 prefuse.action.assignment.ColorAction; 导入 prefuse.action.assignment.FontAction; 导入 prefuse.action.assignment.DataColorAction; 导入 prefuse.action.layout.graph.ForceDirectedLayout; 导入 prefuse.action.layout.graph.; 导入 prefuse.action.layout.; 导入 prefuse.activity.Activity; 导入 prefuse.controls.DragControl; 导入 prefuse.controls.PanControl; 导入 prefuse.controls.ZoomControl; 导入 prefuse.data.Graph; 导入 prefuse.data.io.DataIOException; 导入 prefuse.data.io.GraphMLReader; 导入 prefuse.render.DefaultRendererFactory; 导入 prefuse.render.LabelRenderer; 导入 prefuse.util.ColorLib; 导入 prefuse.visual.VisualItem; 导入 prefuse.visual.*; 导入 prefuse.util.FontLib; 导入 prefuse.action.assignment.DataSizeAction;

导入 prefuse.data.*; 导入 prefuse.render.ImageFactory;

公共类布局示例{

public static void main(String[] argv) throws Exception {

    Graph graph = null;
    try {

        graph = new GraphMLReader().readGraph("/graphs.xml");
    } catch ( DataIOException e ) {
        e.printStackTrace();
        System.err.println("Error loading graph. Exiting...");
        System.exit(1);
    }

ImageFactory imageFactory = new ImageFactory(100,100);

try
{
    //load images and construct imageFactory.
    String images[] = new String[3];
    images[0] = "data/images/switch.png";
    images[1] = "data/images/ip_network.png";
    images[2] = "data/images/router.png";

    String[] names = new String[] {"Switch","Network","Router"};
    BufferedImage img = null;

    for(int i=0; i < images.length ; i++)
    {
        try {
            img = ImageIO.read(new File(images[i]));
            imageFactory.addImage(names[i],img);
        }
        catch (IOException e){
        }
    }


}
catch(Exception exp)
{

}


    Visualization vis = new Visualization();
    vis.add("graph", graph);

LabelRenderer nodeRenderer = new LabelRenderer("name", "type");
    nodeRenderer.setVerticalAlignment(Constants.BOTTOM);
    nodeRenderer.setHorizontalPadding(0);
    nodeRenderer.setVerticalPadding(0);
    nodeRenderer.setImagePosition(Constants.TOP);
    nodeRenderer.setMaxImageDimensions(100,100); 

    DefaultRendererFactory drf = new DefaultRendererFactory();
    drf.setDefaultRenderer(nodeRenderer);
    vis.setRendererFactory(drf); 

    ColorAction nText = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR);
    nText.setDefaultColor(ColorLib.gray(100));


    ColorAction nEdges = new ColorAction("graph.edges", VisualItem.STROKECOLOR);
    nEdges.setDefaultColor(ColorLib.gray(100));

    // bundle the color actions
    ActionList draw = new ActionList();

     //MAD - changing the size of the nodes dependent on the weight of the people
    final DataSizeAction dsa = new DataSizeAction("graph.nodes","size");        
    draw.add(dsa);

    draw.add(nText);
    draw.add(new FontAction("graph.nodes", FontLib.getFont("Tahoma",Font.BOLD, 12)));
    draw.add(nEdges);

    vis.putAction("draw", draw);



  ActionList layout = new ActionList(Activity.DEFAULT_STEP_TIME);


  BalloonTreeLayout balloonlayout = new BalloonTreeLayout("graph",50);
  layout.add(balloonlayout); 


    Display d = new Display(vis);

    vis.putAction("layout", layout);


// start up the animated layout
    vis.run("draw");
vis.run("layout");


    d.addControlListener(new DragControl());
    // pan with left-click drag on background
    d.addControlListener(new PanControl()); 
    // zoom with right-click drag
    d.addControlListener(new ZoomControl()); 

    // -- 6. launch the visualization -------------------------------------






    // create a new window to hold the visualization
    JFrame frame = new JFrame("prefuse example");
    // ensure application exits when window is closed
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(d);
    frame.pack();           // layout components in window
    frame.setVisible(true); // show the window

}

}

谢谢 拉维库玛尔

HI all,

I have written a java application to show the images in different layouts. I am able to show it different layout correctly but some times the images are overlapped. In my application having more than 20/30 nodes and couple of nodes having 6 to 10 edges. The images size are 50*50. Because of the 10 edges, the nodes will overlapped i.e images will overlapped on another images. How can I solve the problem?

Any help will be highly appreciated.

My code is given below

 
import javax.swing.JFrame;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO; 
import java.util.;
import java.io.;
import java.awt.Font;

import prefuse.Constants; import prefuse.Display; import prefuse.Visualization; import prefuse.action.ActionList; import prefuse.action.RepaintAction; import prefuse.action.assignment.ColorAction; import prefuse.action.assignment.FontAction; import prefuse.action.assignment.DataColorAction; import prefuse.action.layout.graph.ForceDirectedLayout; import prefuse.action.layout.graph.; import prefuse.action.layout.; import prefuse.activity.Activity; import prefuse.controls.DragControl; import prefuse.controls.PanControl; import prefuse.controls.ZoomControl; import prefuse.data.Graph; import prefuse.data.io.DataIOException; import prefuse.data.io.GraphMLReader; import prefuse.render.DefaultRendererFactory; import prefuse.render.LabelRenderer; import prefuse.util.ColorLib; import prefuse.visual.VisualItem; import prefuse.visual.*; import prefuse.util.FontLib; import prefuse.action.assignment.DataSizeAction;

import prefuse.data.*; import prefuse.render.ImageFactory;

public class LayoutExample {

public static void main(String[] argv) throws Exception {

    Graph graph = null;
    try {

        graph = new GraphMLReader().readGraph("/graphs.xml");
    } catch ( DataIOException e ) {
        e.printStackTrace();
        System.err.println("Error loading graph. Exiting...");
        System.exit(1);
    }

ImageFactory imageFactory = new ImageFactory(100,100);

try
{
    //load images and construct imageFactory.
    String images[] = new String[3];
    images[0] = "data/images/switch.png";
    images[1] = "data/images/ip_network.png";
    images[2] = "data/images/router.png";

    String[] names = new String[] {"Switch","Network","Router"};
    BufferedImage img = null;

    for(int i=0; i < images.length ; i++)
    {
        try {
            img = ImageIO.read(new File(images[i]));
            imageFactory.addImage(names[i],img);
        }
        catch (IOException e){
        }
    }


}
catch(Exception exp)
{

}


    Visualization vis = new Visualization();
    vis.add("graph", graph);

LabelRenderer nodeRenderer = new LabelRenderer("name", "type");
    nodeRenderer.setVerticalAlignment(Constants.BOTTOM);
    nodeRenderer.setHorizontalPadding(0);
    nodeRenderer.setVerticalPadding(0);
    nodeRenderer.setImagePosition(Constants.TOP);
    nodeRenderer.setMaxImageDimensions(100,100); 

    DefaultRendererFactory drf = new DefaultRendererFactory();
    drf.setDefaultRenderer(nodeRenderer);
    vis.setRendererFactory(drf); 

    ColorAction nText = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR);
    nText.setDefaultColor(ColorLib.gray(100));


    ColorAction nEdges = new ColorAction("graph.edges", VisualItem.STROKECOLOR);
    nEdges.setDefaultColor(ColorLib.gray(100));

    // bundle the color actions
    ActionList draw = new ActionList();

     //MAD - changing the size of the nodes dependent on the weight of the people
    final DataSizeAction dsa = new DataSizeAction("graph.nodes","size");        
    draw.add(dsa);

    draw.add(nText);
    draw.add(new FontAction("graph.nodes", FontLib.getFont("Tahoma",Font.BOLD, 12)));
    draw.add(nEdges);

    vis.putAction("draw", draw);



  ActionList layout = new ActionList(Activity.DEFAULT_STEP_TIME);


  BalloonTreeLayout balloonlayout = new BalloonTreeLayout("graph",50);
  layout.add(balloonlayout); 


    Display d = new Display(vis);

    vis.putAction("layout", layout);


// start up the animated layout
    vis.run("draw");
vis.run("layout");


    d.addControlListener(new DragControl());
    // pan with left-click drag on background
    d.addControlListener(new PanControl()); 
    // zoom with right-click drag
    d.addControlListener(new ZoomControl()); 

    // -- 6. launch the visualization -------------------------------------






    // create a new window to hold the visualization
    JFrame frame = new JFrame("prefuse example");
    // ensure application exits when window is closed
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(d);
    frame.pack();           // layout components in window
    frame.setVisible(true); // show the window

}

}

Thanks
R.Ravikumar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文