GraphStream have an image as a background

566 Views Asked by At

I am working in my Java project and I am using GraphStream library to visually represent graphs. My question is how to put an image behind a graph? I want an image as a background to my graph.

2

There are 2 best solutions below

3
On

I think this can be achieved using LayerRenderer interface with View.setBackLayerRenderer() / View.setFrontLayerRenderer() methods. You can find more here.

0
On

The method setBackLayerRenderer() is implemented in the class DefaultView, here's what worked for me:

Graph graph = new SingleGraph("graph");`
Viewer viewer = graph.display();
DefaultView view = (DefaultView) viewer.getDefaultView();
view.setBackLayerRenderer(new LayerRenderer() {
    @Override
    public void render(Graphics2D graphics2D, GraphicGraph  graphicGraph, double v, int i, int i1, double v1, double v2, double v3, double v4) {
        graphics2D.setColor(Color.green);
        graphics2D.drawString("hello", 10, 30);
    }
});