Search in sources :

Example 66 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class LegacyGraphPersistenceProvider method readTreeStructure.

public void readTreeStructure(XMLStreamReader reader, GraphModel graphModel, GraphFactory factory, LegacyMapHelper mapHelper) throws XMLStreamException {
    Graph graph = graphModel.getGraph();
    boolean end = false;
    while (reader.hasNext() && !end) {
        int type = reader.next();
        switch(type) {
            case XMLStreamReader.START_ELEMENT:
                String name = reader.getLocalName();
                if (ELEMENT_TREESTRUCTURE_NODE.equalsIgnoreCase(name)) {
                    String id = reader.getAttributeValue(null, "id");
                    String pre = reader.getAttributeValue(null, "pre");
                    mapHelper.preToIdMap.put(pre, id);
                    Node node = factory.newNode(id);
                    graph.addNode(node);
                }
                break;
            case XMLStreamReader.END_ELEMENT:
                if (ELEMENT_TREESTRUCTURE.equalsIgnoreCase(reader.getLocalName())) {
                    end = true;
                }
                break;
        }
    }
}
Also used : Graph(org.gephi.graph.api.Graph) Node(org.gephi.graph.api.Node)

Example 67 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ExporterPajek method execute.

@Override
public boolean execute() {
    GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
    Graph graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
    graph.readLock();
    try {
        exportData(graph);
    } catch (Exception e) {
        Logger.getLogger(ExporterPajek.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        graph.readUnlock();
        Progress.finish(progressTicket);
    }
    return !cancel;
}
Also used : Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel)

Example 68 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class ExporterVNA method execute.

@Override
public boolean execute() {
    GraphModel graphModel = workspace.getLookup().lookup(GraphModel.class);
    Graph graph = exportVisible ? graphModel.getGraphVisible() : graphModel.getGraph();
    graph.readLock();
    //nodes are counted twice, because they are printed in exportNodeData and exportNodeProperties
    Progress.start(progressTicket, graph.getNodeCount() * 2 + graph.getEdgeCount());
    try {
        exportData(graph);
    } catch (Exception e) {
        Logger.getLogger(ExporterVNA.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        graph.readUnlock();
        Progress.finish(progressTicket);
    }
    return !cancel;
}
Also used : Graph(org.gephi.graph.api.Graph) GraphModel(org.gephi.graph.api.GraphModel) IOException(java.io.IOException)

Example 69 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class HeatMap method getListeners.

@Override
public ToolEventListener[] getListeners() {
    listeners = new ToolEventListener[1];
    listeners[0] = new NodeClickEventListener() {

        @Override
        public void clickNodes(Node[] nodes) {
            try {
                Node n = nodes[0];
                Color[] colors;
                float[] positions;
                if (heatMapPanel.isUsePalette()) {
                    colors = heatMapPanel.getSelectedPalette().getColors();
                    positions = heatMapPanel.getSelectedPalette().getPositions();
                    dontPaintUnreachable = true;
                } else {
                    gradientColors = colors = heatMapPanel.getGradientColors();
                    gradientPositions = positions = heatMapPanel.getGradientPositions();
                    dontPaintUnreachable = heatMapPanel.isDontPaintUnreachable();
                }
                GraphController gc = Lookup.getDefault().lookup(GraphController.class);
                AbstractShortestPathAlgorithm algorithm;
                if (gc.getGraphModel().isDirected()) {
                    DirectedGraph graph = gc.getGraphModel().getDirectedGraphVisible();
                    algorithm = new BellmanFordShortestPathAlgorithm(graph, n);
                    algorithm.compute();
                } else {
                    Graph graph = gc.getGraphModel().getGraphVisible();
                    algorithm = new DijkstraShortestPathAlgorithm(graph, n);
                    algorithm.compute();
                }
                //Color
                LinearGradient linearGradient = new LinearGradient(colors, positions);
                //Algorithm
                double maxDistance = algorithm.getMaxDistance();
                if (!dontPaintUnreachable) {
                    //+1 to have the maxdistance nodes a ratio<1
                    maxDistance++;
                }
                if (maxDistance > 0) {
                    for (Entry<Node, Double> entry : algorithm.getDistances().entrySet()) {
                        Node node = entry.getKey();
                        if (!Double.isInfinite(entry.getValue())) {
                            float ratio = (float) (entry.getValue() / maxDistance);
                            Color c = linearGradient.getValue(ratio);
                            node.setColor(c);
                        } else if (!dontPaintUnreachable) {
                            Color c = colors[colors.length - 1];
                            node.setColor(c);
                        }
                    }
                }
                Color c = colors[0];
                n.setColor(c);
                heatMapPanel.setStatus(NbBundle.getMessage(HeatMap.class, "HeatMap.status.maxdistance") + new DecimalFormat("#.##").format(algorithm.getMaxDistance()));
            } catch (Exception e) {
                Logger.getLogger("").log(Level.SEVERE, "", e);
            }
        }
    };
    return listeners;
}
Also used : Node(org.gephi.graph.api.Node) Color(java.awt.Color) DecimalFormat(java.text.DecimalFormat) DijkstraShortestPathAlgorithm(org.gephi.algorithms.shortestpath.DijkstraShortestPathAlgorithm) AbstractShortestPathAlgorithm(org.gephi.algorithms.shortestpath.AbstractShortestPathAlgorithm) BellmanFordShortestPathAlgorithm(org.gephi.algorithms.shortestpath.BellmanFordShortestPathAlgorithm) LinearGradient(org.gephi.ui.utils.GradientUtils.LinearGradient) Entry(java.util.Map.Entry) DirectedGraph(org.gephi.graph.api.DirectedGraph) Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) NodeClickEventListener(org.gephi.tools.spi.NodeClickEventListener) GraphController(org.gephi.graph.api.GraphController)

Example 70 with Graph

use of org.gephi.graph.api.Graph in project gephi by gephi.

the class WeightedDegreeNGTest method testCyclicGraphDegree.

@Test
public void testCyclicGraphDegree() {
    GraphModel graphModel = GraphGenerator.generateCyclicUndirectedGraph(5);
    Graph graph = graphModel.getGraph();
    Node n = graph.getNode("3");
    WeightedDegree d = new WeightedDegree();
    d.execute(graph);
    double degree = (Double) n.getAttribute(WeightedDegree.WDEGREE);
    double avDegree = d.getAverageDegree();
    assertEquals(degree, 2.0);
    assertEquals(avDegree, 2.0);
}
Also used : Graph(org.gephi.graph.api.Graph) DirectedGraph(org.gephi.graph.api.DirectedGraph) GraphModel(org.gephi.graph.api.GraphModel) Node(org.gephi.graph.api.Node) Test(org.testng.annotations.Test)

Aggregations

Graph (org.gephi.graph.api.Graph)104 GraphModel (org.gephi.graph.api.GraphModel)57 Node (org.gephi.graph.api.Node)50 DirectedGraph (org.gephi.graph.api.DirectedGraph)43 Test (org.testng.annotations.Test)36 GraphController (org.gephi.graph.api.GraphController)27 UndirectedGraph (org.gephi.graph.api.UndirectedGraph)24 Edge (org.gephi.graph.api.Edge)21 Column (org.gephi.graph.api.Column)9 ArrayList (java.util.ArrayList)8 Function (org.gephi.appearance.api.Function)6 GraphView (org.gephi.graph.api.GraphView)6 AttributeFunction (org.gephi.appearance.api.AttributeFunction)5 AppearanceController (org.gephi.appearance.api.AppearanceController)4 AppearanceModel (org.gephi.appearance.api.AppearanceModel)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 TransformerUI (org.gephi.appearance.spi.TransformerUI)3 GraphElementsController (org.gephi.datalab.api.GraphElementsController)3 DataTablesController (org.gephi.datalab.api.datatables.DataTablesController)3