rotem - 2014-12-12

I'm trying to add a plugin to an existing application which displays a graph that is built from scratch. I've run the example code without a problem, even modified it. However, when using the new graph, it is not displayed and I repeatedly get the following warning:

WARNING: Union with invalid clip region: java.awt.geom.Rectangle2D$Double[x=NaN,y=NaN,w=NaN,h=NaN] <<<< Clip.union(..) [Thread 19]

Sometimes instead of "NaN" there is "INFINITY".

At first I thought it was because I'm using a JPanel and not a JFrame like in the example, but changing to JFrame did not help.

What does this warning mean? What am I doing wrong?

This is my code:

static Visualization graph_visualization;

private Visualization getGraphVisualization(Graph graph){
Visualization vis = new Visualization();
    vis.add("graph", graph);
    vis.setInteractive("graph.edges", null, false);
    return vis;
}

private Visualization setGraphVisualizationParams(Visualization vis){
// draw the "name" label for NodeItems
    LabelRenderer r = new LabelRenderer(UnderlyingGraph.AUTHOR);
    r.setRoundedCorner(8, 8); // round the corners

    //draw edges
    EdgeRenderer er = new EdgeRenderer(Constants.EDGE_TYPE_CURVE);

    // create a new default renderer factory
    DefaultRendererFactory rf = new DefaultRendererFactory();
    rf.setDefaultRenderer(r);
    rf.setDefaultEdgeRenderer(er);
    vis.setRendererFactory(rf);

    //adding colors
    ColorAction fill = new ColorAction("graph.nodes", VisualItem.FILLCOLOR,         ColorLib.rgb(190,190,255));
    ColorAction text = new ColorAction("graph.nodes", VisualItem.TEXTCOLOR, ColorLib.gray(0));
    ColorAction edges = new ColorAction("graph.edges", VisualItem.STROKECOLOR, ColorLib.gray(200));

    // create an action list containing all color assignments
    ActionList color = new ActionList();
    color.add(fill);
    color.add(text);
    color.add(edges);

    // create an action list with an animated layout
    ActionList layout = new ActionList(Activity.INFINITY);
    layout.add(new MyForceDirectedLayout("graph"));
    layout.add(new RepaintAction());

    //create size actions
    ActionList size = new ActionList();
    size.add(new DataSizeAction("graph.nodes", UnderlyingGraph.DEGREE));
    size.add(new SizeAction("graph.edges", 3));

    //creating a fixed action to fix lone nodes
    ActionList fixNodes = new ActionList();
    fixNodes.add(new MyItemAction());

    // add the actions to the visualization
    vis.putAction(COLOR, color);
    vis.putAction(LAYOUT, layout);
    vis.putAction(SIZE, size);
    vis.putAction(FIX_NODES, fixNodes);

    return vis;
}

private Display getGraphDisplay(Visualization vis){
Display d = new Display(vis);
    d.setSize(720, 500); // set display size
    d.setBounds(0, 0, 720, 500);
    // drag individual items around
    d.addControlListener(new DragControl());
    // pan with left-click drag on background
    d.addControlListener(new PanControl()); 
    // zoom with right-click drag
    d.addControlListener(new ZoomControl());
    // changing item colors when mouse over
    d.addControlListener(new MyControlAdapter(vis));

    return d;
}

//fixing all nodes without visible edges
private static void setFixedNodes(Graph graph, Visualization vis){
    Iterator nodes = graph.nodes();
    while(nodes.hasNext()){
        Node node = (Node) nodes.next();
        VisualItem visualNode = vis.getVisualItem("graph.nodes", node);
        boolean isFixed = true;

        //checking if an adjacent edge is visible
        Iterator edges = node.edges();
        while(edges.hasNext()){
            Edge edge = (Edge) edges.next();
            VisualItem visualEdge = vis.getVisualItem("graph.edges", edge);
            if(visualEdge.isVisible()){
                isFixed = false;
                break;
            }
        }

        visualNode.setFixed(isFixed);
    }
}

private void showGraph(){
graph_visualization = getGraphVisualization(graph);
graph_visualization = setGraphVisualizationParams(graph_visualization);
Display gd = getGraphDisplay(graph_visualization);

this.add(gd, BorderLayout.CENTER);
this.setVisible(true);
this.updateUI();

graph_visualization.run(COLOR);
    graph_visualization.run(LAYOUT);
    graph_visualization.run(SIZE);
    graph_visualization.run(FIX_NODES);

}