Search in sources :

Example 16 with NodeDraft

use of org.gephi.io.importer.api.NodeDraft in project gephi-plugins-bootcamp by gephi.

the class SimpleGenerator method generate.

@Override
public void generate(ContainerLoader container) {
    // create nodes
    NodeDraft n1 = container.factory().newNodeDraft();
    NodeDraft n2 = container.factory().newNodeDraft();
    // set node labels
    n1.setLabel("Hello");
    n2.setLabel("World");
    // create edge
    EdgeDraft e = container.factory().newEdgeDraft();
    e.setSource(n1);
    e.setTarget(n2);
    // fill in the graph
    container.addNode(n1);
    container.addNode(n2);
    container.addEdge(e);
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 17 with NodeDraft

use of org.gephi.io.importer.api.NodeDraft in project gephi-plugins-bootcamp by gephi.

the class MatrixFileImporter method importData.

private void importData(LineNumberReader reader) throws Exception {
    // read type code initial line
    String line = reader.readLine();
    String typecode = line;
    report.log("Typecode is " + typecode);
    // read comment lines if any
    boolean comment = true;
    while (comment) {
        line = reader.readLine();
        comment = line.startsWith("%");
    }
    String[] str = line.split("( )+");
    int nRows = (Integer.valueOf(str[0].trim()));
    int nColumns = (Integer.valueOf(str[1].trim()));
    int nNonZeros = (Integer.valueOf(str[2].trim()));
    report.log("Number of rows: " + nRows);
    report.log("Number of cols: " + nColumns);
    report.log("Number of non zeros: " + nNonZeros);
    while ((line = reader.readLine()) != null) {
        //Read coordinates and value
        str = line.split("( )+");
        int node1Index = (Integer.valueOf(str[0].trim()));
        int node2Index = (Integer.valueOf(str[1].trim()));
        float weight = 1f;
        if (str.length > 2) {
            weight = (Double.valueOf(str[2].trim())).floatValue();
        }
        //Get or create node
        NodeDraft node1;
        if (container.nodeExists(String.valueOf(node1Index))) {
            node1 = container.getNode(String.valueOf(node1Index));
        } else {
            node1 = container.factory().newNodeDraft(String.valueOf(node1Index));
            //Don't forget to add the node
            container.addNode(node1);
        }
        NodeDraft node2;
        if (container.nodeExists(String.valueOf(node2Index))) {
            node2 = container.getNode(String.valueOf(node2Index));
        } else {
            node2 = container.factory().newNodeDraft(String.valueOf(node2Index));
            //Don't forget to add the node
            container.addNode(node2);
        }
        //Create edge
        EdgeDraft edgeDraft = container.factory().newEdgeDraft();
        edgeDraft.setSource(node1);
        edgeDraft.setTarget(node2);
        edgeDraft.setWeight(weight);
        container.addEdge(edgeDraft);
    }
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 18 with NodeDraft

use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.

the class DefaultScaler method doScale.

@Override
public void doScale(Container container) {
    setDefaults();
    float sizeMin = Float.POSITIVE_INFINITY;
    float sizeMax = Float.NEGATIVE_INFINITY;
    float xMin = Float.POSITIVE_INFINITY;
    float xMax = Float.NEGATIVE_INFINITY;
    float yMin = Float.POSITIVE_INFINITY;
    float yMax = Float.NEGATIVE_INFINITY;
    float zMin = Float.POSITIVE_INFINITY;
    float zMax = Float.NEGATIVE_INFINITY;
    float sizeRatio = 0f;
    float averageSize = 2.5f;
    //Recenter
    double centroidX = 0;
    double centroidY = 0;
    int nodeSize = 0;
    for (NodeDraft node : container.getUnloader().getNodes()) {
        centroidX += node.getX();
        centroidY += node.getY();
        nodeSize++;
    }
    centroidX /= nodeSize;
    centroidY /= nodeSize;
    for (NodeDraft node : container.getUnloader().getNodes()) {
        node.setX((float) (node.getX() - centroidX));
        node.setY((float) (node.getY() - centroidY));
    }
    //Measure
    for (NodeDraft node : container.getUnloader().getNodes()) {
        sizeMin = Math.min(node.getSize(), sizeMin);
        sizeMax = Math.max(node.getSize(), sizeMax);
        xMin = Math.min(node.getX(), xMin);
        xMax = Math.max(node.getX(), xMax);
        yMin = Math.min(node.getY(), yMin);
        yMax = Math.max(node.getY(), yMax);
        zMin = Math.min(node.getZ(), zMin);
        zMax = Math.max(node.getZ(), zMax);
    }
    if (sizeMin != 0 && sizeMax != 0) {
        if (sizeMin == sizeMax) {
            sizeRatio = sizeMinimum / sizeMin;
        } else {
            sizeRatio = (sizeMaximum - sizeMinimum) / (sizeMax - sizeMin);
        }
        //Watch octree limit
        if (xMin * sizeRatio < -octreeLimit) {
            sizeRatio = Math.abs(octreeLimit / xMin);
        }
        if (xMax * sizeRatio > octreeLimit) {
            sizeRatio = Math.abs(octreeLimit / xMax);
        }
        if (yMin * sizeRatio < -octreeLimit) {
            sizeRatio = Math.abs(octreeLimit / yMin);
        }
        if (yMax * sizeRatio > octreeLimit) {
            sizeRatio = Math.abs(octreeLimit / yMax);
        }
        if (zMin * sizeRatio < -octreeLimit) {
            sizeRatio = Math.abs(octreeLimit / zMin);
        }
        if (zMax * sizeRatio > octreeLimit) {
            sizeRatio = Math.abs(octreeLimit / zMax);
        }
        averageSize = 0f;
        //Scale node size
        for (NodeDraft node : container.getUnloader().getNodes()) {
            float size = (node.getSize() - sizeMin) * sizeRatio + sizeMinimum;
            node.setSize(size);
            node.setX(node.getX() * sizeRatio);
            node.setY(node.getY() * sizeRatio);
            node.setZ(node.getZ() * sizeRatio);
            averageSize += size;
        }
        averageSize /= nodeSize;
    }
/*
         float weightMin = Float.POSITIVE_INFINITY;
         float weightMax = Float.NEGATIVE_INFINITY;
         float weightRatio = 0f;

         //Measure
         weightMaximum = averageSize * 0.8f;
         for (EdgeDraftGetter edge : container.getUnloader().getEdges()) {
         weightMin = Math.min(edge.getWeight(), weightMin);
         weightMax = Math.max(edge.getWeight(), weightMax);
         }
         if (weightMin == weightMax) {
         weightRatio = weightMinimum / weightMin;
         } else {
         weightRatio = Math.abs((weightMaximum - weightMinimum) / (weightMax - weightMin));
         }

         //Scale edge weight
         for (EdgeDraftGetter edge : container.getUnloader().getEdges()) {
         float weight = (edge.getWeight() - weightMin) * weightRatio + weightMinimum;
         assert !Float.isNaN(weight);
         edge.setWeight(weight);
         }*/
}
Also used : NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 19 with NodeDraft

use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.

the class MultiGraph method generate.

@Override
public void generate(ContainerLoader container) {
    NodeDraft[] nodeArray = new NodeDraft[numberOfNodes];
    for (int i = 0; i < numberOfNodes; i++) {
        NodeDraft nodeDraft = container.factory().newNodeDraft("n" + i);
        container.addNode(nodeDraft);
        nodeArray[i] = nodeDraft;
    }
    String[] edgeTypes = new String[numberOfEdgeTypes];
    for (int i = 0; i < edgeTypes.length; i++) {
        edgeTypes[i] = "Type " + i;
    }
    Random random = new Random();
    if (wiringProbability > 0) {
        for (int i = 0; i < numberOfNodes - 1; i++) {
            NodeDraft node1 = nodeArray[i];
            for (int j = i + 1; j < numberOfNodes; j++) {
                NodeDraft node2 = nodeArray[j];
                if (random.nextDouble() < wiringProbability) {
                    if (random.nextDouble() < 0.3) {
                        //Double
                        EdgeDraft edgeDraft1 = container.factory().newEdgeDraft();
                        edgeDraft1.setSource(node1);
                        edgeDraft1.setTarget(node2);
                        edgeDraft1.setType(edgeTypes[0]);
                        edgeDraft1.setLabel((String) edgeDraft1.getType());
                        container.addEdge(edgeDraft1);
                        EdgeDraft edgeDraft2 = container.factory().newEdgeDraft();
                        edgeDraft2.setSource(node1);
                        edgeDraft2.setTarget(node2);
                        edgeDraft2.setType(edgeTypes[1]);
                        edgeDraft2.setLabel((String) edgeDraft2.getType());
                        container.addEdge(edgeDraft2);
                    } else {
                        //Single
                        EdgeDraft edgeDraft = container.factory().newEdgeDraft();
                        edgeDraft.setSource(node1);
                        edgeDraft.setTarget(node2);
                        edgeDraft.setType(edgeTypes[random.nextInt(edgeTypes.length)]);
                        edgeDraft.setLabel((String) edgeDraft.getType());
                        container.addEdge(edgeDraft);
                    }
                }
            }
        }
    }
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Random(java.util.Random) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Example 20 with NodeDraft

use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.

the class RandomGraph method generate.

@Override
public void generate(ContainerLoader container) {
    int max = numberOfNodes;
    if (wiringProbability > 0) {
        max += numberOfNodes - 1;
    }
    Progress.start(progress, max);
    int progressUnit = 0;
    Random random = new Random();
    NodeDraft[] nodeArray = new NodeDraft[numberOfNodes];
    for (int i = 0; i < numberOfNodes && !cancel; i++) {
        NodeDraft nodeDraft = container.factory().newNodeDraft();
        container.addNode(nodeDraft);
        nodeArray[i] = nodeDraft;
        Progress.progress(progress, ++progressUnit);
    }
    if (wiringProbability > 0) {
        for (int i = 0; i < numberOfNodes - 1 && !cancel; i++) {
            NodeDraft node1 = nodeArray[i];
            for (int j = i + 1; j < numberOfNodes && !cancel; j++) {
                NodeDraft node2 = nodeArray[j];
                if (random.nextDouble() < wiringProbability) {
                    EdgeDraft edgeDraft = container.factory().newEdgeDraft();
                    edgeDraft.setSource(node1);
                    edgeDraft.setTarget(node2);
                    container.addEdge(edgeDraft);
                }
            }
            Progress.progress(progress, ++progressUnit);
        }
    }
    Progress.finish(progress);
    progress = null;
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Random(java.util.Random) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Aggregations

NodeDraft (org.gephi.io.importer.api.NodeDraft)31 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)15 Issue (org.gephi.io.importer.api.Issue)14 IOException (java.io.IOException)5 StringTokenizer (java.util.StringTokenizer)5 Random (java.util.Random)4 SQLException (java.sql.SQLException)2 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)2 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Edge (org.gephi.graph.api.Edge)1 Graph (org.gephi.graph.api.Graph)1 GraphController (org.gephi.graph.api.GraphController)1 GraphFactory (org.gephi.graph.api.GraphFactory)1 Node (org.gephi.graph.api.Node)1 ContainerUnloader (org.gephi.io.importer.api.ContainerUnloader)1 ElementDraft (org.gephi.io.importer.api.ElementDraft)1