Search in sources :

Example 1 with EdgeItem

use of org.gephi.preview.plugin.items.EdgeItem in project gephi by gephi.

the class EdgeLabelRenderer method preProcess.

@Override
public void preProcess(PreviewModel previewModel) {
    PreviewProperties properties = previewModel.getProperties();
    if (properties.getBooleanValue(PreviewProperty.EDGE_LABEL_SHORTEN)) {
        //Shorten labels
        Item[] EdgeLabelsItems = previewModel.getItems(Item.EDGE_LABEL);
        int maxChars = properties.getIntValue(PreviewProperty.EDGE_LABEL_MAX_CHAR);
        for (Item item : EdgeLabelsItems) {
            String label = item.getData(EdgeLabelItem.LABEL);
            if (label.length() >= maxChars + 3) {
                label = label.substring(0, maxChars) + "...";
                item.setData(EdgeLabelItem.LABEL, label);
            }
        }
    }
    //Put parent color, and calculate position
    for (Item item : previewModel.getItems(Item.EDGE_LABEL)) {
        Edge edge = (Edge) item.getSource();
        Item edgeItem = previewModel.getItem(Item.EDGE, edge);
        EdgeColor edgeColor = (EdgeColor) properties.getValue(PreviewProperty.EDGE_COLOR);
        NodeItem sourceItem = (NodeItem) edgeItem.getData(EdgeRenderer.SOURCE);
        NodeItem targetItem = (NodeItem) edgeItem.getData(EdgeRenderer.TARGET);
        Color color = edgeColor.getColor((Color) item.getData(EdgeItem.COLOR), (Color) sourceItem.getData(NodeItem.COLOR), (Color) targetItem.getData(NodeItem.COLOR));
        item.setData(EDGE_COLOR, color);
        if (edge.isSelfLoop()) {
            //Middle
            Float x = sourceItem.getData(NodeItem.X);
            Float y = sourceItem.getData(NodeItem.Y);
            Float size = sourceItem.getData(NodeItem.SIZE);
            Vector v1 = new Vector(x, y);
            v1.add(size, -size);
            Vector v2 = new Vector(x, y);
            v2.add(size, size);
            Vector middle = bezierPoint(x, y, v1.x, v1.y, v2.x, v2.y, x, y, 0.5f);
            item.setData(LABEL_X, middle.x);
            item.setData(LABEL_Y, middle.y);
        } else if (properties.getBooleanValue(PreviewProperty.EDGE_CURVED)) {
            //Middle of the curve
            Float x1 = sourceItem.getData(NodeItem.X);
            Float x2 = targetItem.getData(NodeItem.X);
            Float y1 = sourceItem.getData(NodeItem.Y);
            Float y2 = targetItem.getData(NodeItem.Y);
            //Curved edgs
            Vector direction = new Vector(x2, y2);
            direction.sub(new Vector(x1, y1));
            float length = direction.mag();
            direction.normalize();
            float factor = properties.getFloatValue(EdgeRenderer.BEZIER_CURVENESS) * length;
            // normal vector to the edge
            Vector n = new Vector(direction.y, -direction.x);
            n.mult(factor);
            // first control point
            Vector v1 = new Vector(direction.x, direction.y);
            v1.mult(factor);
            v1.add(new Vector(x1, y1));
            v1.add(n);
            // second control point
            Vector v2 = new Vector(direction.x, direction.y);
            v2.mult(-factor);
            v2.add(new Vector(x2, y2));
            v2.add(n);
            Vector middle = bezierPoint(x1, y1, v1.x, v1.y, v2.x, v2.y, x2, y2, 0.5f);
            item.setData(LABEL_X, middle.x);
            item.setData(LABEL_Y, middle.y);
        } else {
            Float x = ((Float) sourceItem.getData(NodeItem.X) + (Float) targetItem.getData(NodeItem.X)) / 2f;
            Float y = ((Float) sourceItem.getData(NodeItem.Y) + (Float) targetItem.getData(NodeItem.Y)) / 2f;
            item.setData(LABEL_X, x);
            item.setData(LABEL_Y, y);
        }
    }
    //Property font
    font = properties.getFontValue(PreviewProperty.EDGE_LABEL_FONT);
}
Also used : EdgeColor(org.gephi.preview.types.EdgeColor) EdgeLabelItem(org.gephi.preview.plugin.items.EdgeLabelItem) EdgeItem(org.gephi.preview.plugin.items.EdgeItem) NodeItem(org.gephi.preview.plugin.items.NodeItem) NodeItem(org.gephi.preview.plugin.items.NodeItem) Color(java.awt.Color) EdgeColor(org.gephi.preview.types.EdgeColor) DependantColor(org.gephi.preview.types.DependantColor) DependantOriginalColor(org.gephi.preview.types.DependantOriginalColor) Edge(org.gephi.graph.api.Edge) GlyphVector(java.awt.font.GlyphVector)

Example 2 with EdgeItem

use of org.gephi.preview.plugin.items.EdgeItem in project gephi by gephi.

the class EdgeRenderer method isSelfLoopEdge.

private static boolean isSelfLoopEdge(final Item item) {
    final Item sourceItem = item.getData(SOURCE);
    final Item targetItem = item.getData(TARGET);
    return item instanceof EdgeItem && sourceItem == targetItem;
}
Also used : EdgeItem(org.gephi.preview.plugin.items.EdgeItem) NodeItem(org.gephi.preview.plugin.items.NodeItem) EdgeItem(org.gephi.preview.plugin.items.EdgeItem)

Example 3 with EdgeItem

use of org.gephi.preview.plugin.items.EdgeItem in project gephi by gephi.

the class EdgeBuilder method getItems.

@Override
public Item[] getItems(Graph graph) {
    EdgeItem[] items = new EdgeItem[graph.getEdgeCount()];
    int i = 0;
    for (Edge e : graph.getEdges()) {
        EdgeItem item = new EdgeItem(e);
        item.setData(EdgeItem.WEIGHT, e.getWeight(graph.getView()));
        item.setData(EdgeItem.DIRECTED, e.isDirected());
        if (graph.isDirected(e)) {
            item.setData(EdgeItem.MUTUAL, ((DirectedGraph) graph).getMutualEdge(e) != null);
        }
        item.setData(EdgeItem.SELF_LOOP, e.isSelfLoop());
        item.setData(EdgeItem.COLOR, e.alpha() == 0 ? null : e.getColor());
        items[i++] = item;
    }
    return items;
}
Also used : EdgeItem(org.gephi.preview.plugin.items.EdgeItem)

Example 4 with EdgeItem

use of org.gephi.preview.plugin.items.EdgeItem in project gephi-plugins-bootcamp by gephi.

the class HighlighMutualEdges method preProcess.

@Override
public void preProcess(PreviewModel previewModel) {
    PreviewProperties properties = previewModel.getProperties();
    //Check if the boolean property is set
    if (properties.getBooleanValue(MUTUALEGDE_HIGHLIGHT)) {
        Color color = properties.getColorValue(MUTUALEGDE_HIGHLIGHT_COLOR);
        // Retrieve all edge items in the model
        // As this renderer is called after the EdgeRenderer (which has a position=100, 
        // and this renderer has no specific position) we know these edge
        // items are well defined and already posses a color
        Item[] edgeItems = previewModel.getItems(Item.EDGE);
        for (Item item : edgeItems) {
            EdgeItem edgeItem = (EdgeItem) item;
            Boolean mutual = edgeItem.getData(EdgeItem.MUTUAL);
            if (mutual) {
                //If mutual edge, change the color
                edgeItem.setData(EdgeItem.COLOR, color);
            }
        }
    }
}
Also used : EdgeItem(org.gephi.preview.plugin.items.EdgeItem) EdgeItem(org.gephi.preview.plugin.items.EdgeItem) Color(java.awt.Color)

Aggregations

EdgeItem (org.gephi.preview.plugin.items.EdgeItem)4 Color (java.awt.Color)2 NodeItem (org.gephi.preview.plugin.items.NodeItem)2 GlyphVector (java.awt.font.GlyphVector)1 Edge (org.gephi.graph.api.Edge)1 EdgeLabelItem (org.gephi.preview.plugin.items.EdgeLabelItem)1 DependantColor (org.gephi.preview.types.DependantColor)1 DependantOriginalColor (org.gephi.preview.types.DependantOriginalColor)1 EdgeColor (org.gephi.preview.types.EdgeColor)1