Search in sources :

Example 1 with GraphicEdge

use of org.graphstream.ui.graphicGraph.GraphicEdge in project gs-ui-javafx by graphstream.

the class HasSkel method positionMultiEdge.

private void positionMultiEdge(ConnectorSkeleton skel, double x1, double y1, double x2, double y2, int multi, EdgeGroup group) {
    double vx = (x2 - x1);
    double vy = (y2 - y1);
    double vx2 = (vy) * 0.6;
    double vy2 = (-vx) * 0.6;
    double gap = 0.2;
    double ox = 0.0;
    double oy = 0.0;
    // (1+multi)/2 must be done on integers.
    double f = ((1 + multi) / 2) * gap;
    vx *= 0.2;
    vy *= 0.2;
    GraphicEdge main = group.getEdge(0);
    GraphicEdge edge = group.getEdge(multi);
    if (group.getCount() % 2 == 0) {
        ox = vx2 * (gap / 2);
        oy = vy2 * (gap / 2);
        if (!edge.from.equals(main.from)) {
            // Edges are in the same direction.
            ox = -ox;
            oy = -oy;
        }
    }
    vx2 *= f;
    vy2 *= f;
    double xx1 = x1 + vx;
    double yy1 = y1 + vy;
    double xx2 = x2 - vx;
    double yy2 = y2 - vy;
    double m = multi;
    if (edge.from.equals(main.from))
        m += 0;
    else
        m += 1;
    if (m % 2 == 0) {
        xx1 += (vx2 + ox);
        yy1 += (vy2 + oy);
        xx2 += (vx2 + ox);
        yy2 += (vy2 + oy);
    } else {
        xx1 -= (vx2 - ox);
        yy1 -= (vy2 - oy);
        xx2 -= (vx2 - ox);
        yy2 -= (vy2 - oy);
    }
    skel.setCurve(x1, y1, 0, xx1, yy1, 0, xx2, yy2, 0, x2, y2, 0);
}
Also used : GraphicEdge(org.graphstream.ui.graphicGraph.GraphicEdge)

Example 2 with GraphicEdge

use of org.graphstream.ui.graphicGraph.GraphicEdge in project gs-ui-javafx by graphstream.

the class SpriteFlowShape method configureForElement.

@Override
public void configureForElement(Backend bck, GraphicElement element, Skeleton skel, DefaultCamera2D camera) {
    GraphicSprite sprite = (GraphicSprite) element;
    if (sprite.isAttachedToEdge()) {
        GraphicEdge edge = sprite.getEdgeAttachment();
        fillableLine.configureFillableLineForElement(element.getStyle(), camera, element);
        decorable.configureDecorableForElement(bck, camera, element, skel);
        if (element.hasAttribute("ui.size"))
            theSize = camera.getMetrics().lengthToGu(StyleConstants.convertValue(element.getAttribute("ui.size")));
        along = element.getX();
        offset = camera.getMetrics().lengthToGu(element.getY(), sprite.getUnits());
        connectorSkel = (ConnectorSkeleton) edge.getAttribute(Skeleton.attributeName);
    } else {
        connectorSkel = null;
    }
}
Also used : GraphicSprite(org.graphstream.ui.graphicGraph.GraphicSprite) GraphicEdge(org.graphstream.ui.graphicGraph.GraphicEdge)

Example 3 with GraphicEdge

use of org.graphstream.ui.graphicGraph.GraphicEdge in project gs-ui-javafx by graphstream.

the class DefaultCamera method allGraphicElementsIn.

@Override
public Collection<GraphicElement> allGraphicElementsIn(GraphicGraph graph, EnumSet<InteractiveElement> types, double x1, double y1, double x2, double y2) {
    List<GraphicElement> elts = new ArrayList<GraphicElement>();
    Stream nodeStream = null;
    Stream edgeStream = null;
    Stream spriteStream = null;
    if (types.contains(InteractiveElement.NODE)) {
        nodeStream = graph.nodes().filter(n -> isNodeIn((GraphicNode) n, x1, y1, x2, y2));
    } else {
        nodeStream = Stream.empty();
    }
    if (types.contains(InteractiveElement.EDGE)) {
        edgeStream = graph.edges().filter(e -> isEdgeIn((GraphicEdge) e, x1, y1, x2, y2));
    } else {
        edgeStream = Stream.empty();
    }
    if (types.contains(InteractiveElement.SPRITE)) {
        spriteStream = graph.sprites().filter(e -> isSpriteIn((GraphicSprite) e, x1, y1, x2, y2));
    } else {
        spriteStream = Stream.empty();
    }
    Stream<GraphicElement> s = Stream.concat(nodeStream, Stream.concat(edgeStream, spriteStream));
    return s.collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) Affine(javafx.scene.transform.Affine) Point2(org.graphstream.ui.geom.Point2) Point3(org.graphstream.ui.geom.Point3) GraphicElement(org.graphstream.ui.graphicGraph.GraphicElement) Camera(org.graphstream.ui.view.camera.Camera) NonInvertibleTransformException(javafx.scene.transform.NonInvertibleTransformException) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) GraphMetrics(org.graphstream.ui.view.util.GraphMetrics) InteractiveElement(org.graphstream.ui.view.util.InteractiveElement) Point2D(javafx.geometry.Point2D) EnumSet(java.util.EnumSet) GraphicGraph(org.graphstream.ui.graphicGraph.GraphicGraph) GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode) Units(org.graphstream.ui.graphicGraph.stylesheet.StyleConstants.Units) GraphicEdge(org.graphstream.ui.graphicGraph.GraphicEdge) Edge(org.graphstream.graph.Edge) Node(org.graphstream.graph.Node) GraphicsContext(javafx.scene.canvas.GraphicsContext) Collection(java.util.Collection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) StyleConstants(org.graphstream.ui.graphicGraph.stylesheet.StyleConstants) List(java.util.List) GraphicSprite(org.graphstream.ui.graphicGraph.GraphicSprite) Values(org.graphstream.ui.graphicGraph.stylesheet.Values) Stream(java.util.stream.Stream) Vector2(org.graphstream.ui.geom.Vector2) Optional(java.util.Optional) Selector(org.graphstream.ui.graphicGraph.stylesheet.Selector) Style(org.graphstream.ui.graphicGraph.stylesheet.Style) GraphicElement(org.graphstream.ui.graphicGraph.GraphicElement) ArrayList(java.util.ArrayList) Stream(java.util.stream.Stream)

Example 4 with GraphicEdge

use of org.graphstream.ui.graphicGraph.GraphicEdge in project gs-ui-javafx by graphstream.

the class DefaultCamera method getSpritePositionEdge.

/**
 * Compute the position of a sprite if attached to an edge.
 *
 * @param sprite
 *            The sprite.
 * @param pos
 *            Where to stored the computed position, if null, the position
 *            is created.
 * @param units
 *            The units the computed position must be given into.
 * @return The same instance as pos, or a new one if pos was null.
 */
protected Point2D getSpritePositionEdge(GraphicSprite sprite, Point2D pos, Units units) {
    GraphicEdge edge = sprite.getEdgeAttachment();
    if (edge.isCurve()) {
        double[] ctrl = edge.getControlPoints();
        Point2 p0 = new Point2(edge.from.getX(), edge.from.getY());
        Point2 p1 = new Point2(ctrl[0], ctrl[1]);
        Point2 p2 = new Point2(ctrl[1], ctrl[2]);
        Point2 p3 = new Point2(edge.to.getX(), edge.to.getY());
        Vector2 perp = CubicCurve.perpendicular(p0, p1, p2, p3, sprite.getX());
        double y = metrics.lengthToGu(sprite.getY(), sprite.getUnits());
        perp.normalize();
        perp.scalarMult(y);
        double X = CubicCurve.eval(p0.x, p1.x, p2.x, p3.x, sprite.getX()) - perp.data[0];
        double Y = CubicCurve.eval(p0.y, p1.y, p2.y, p3.y, sprite.getX()) - perp.data[1];
        pos = new Point2D(X, Y);
    } else {
        double x = ((GraphicNode) edge.getSourceNode()).x;
        double y = ((GraphicNode) edge.getSourceNode()).y;
        double dx = ((GraphicNode) edge.getTargetNode()).x - x;
        double dy = ((GraphicNode) edge.getTargetNode()).y - y;
        // Percent on the edge.
        double d = sprite.getX();
        double o = metrics.lengthToGu(sprite.getY(), sprite.getUnits());
        // Offset from the position given by percent, perpendicular to the
        // edge.
        d = d > 1 ? 1 : d;
        d = d < 0 ? 0 : d;
        x += dx * d;
        y += dy * d;
        d = (double) Math.sqrt(dx * dx + dy * dy);
        dx /= d;
        dy /= d;
        x += -dy * o;
        y += dx * o;
        pos = new Point2D(x, y);
        if (units == Units.PX) {
            pos = Tx.transform(pos.getX(), pos.getY());
        }
    }
    return pos;
}
Also used : Point2(org.graphstream.ui.geom.Point2) Vector2(org.graphstream.ui.geom.Vector2) Point2D(javafx.geometry.Point2D) GraphicEdge(org.graphstream.ui.graphicGraph.GraphicEdge) GraphicNode(org.graphstream.ui.graphicGraph.GraphicNode)

Example 5 with GraphicEdge

use of org.graphstream.ui.graphicGraph.GraphicEdge in project gs-ui-javafx by graphstream.

the class Decorable method decorConnector.

public void decorConnector(Backend backend, DefaultCamera2D camera, IconAndText iconAndText, GraphicElement element, Form shape) {
    boolean visible = true;
    if (element != null)
        visible = camera.isTextVisible(element);
    if (theDecor != null && visible) {
        if (element instanceof GraphicEdge) {
            GraphicEdge edge = (GraphicEdge) element;
            if ((skel != null) && (skel.isCurve())) {
                theDecor.renderAlong(backend, camera, iconAndText, skel);
            } else {
                theDecor.renderAlong(backend, camera, iconAndText, edge.from.x, edge.from.y, edge.to.x, edge.to.y);
            }
        } else {
            Bounds bounds = shape.getBounds();
            theDecor.renderAlong(backend, camera, iconAndText, bounds.getMinX(), bounds.getMinY(), bounds.getMaxX(), bounds.getMaxY());
        }
    }
}
Also used : Bounds(javafx.geometry.Bounds) GraphicEdge(org.graphstream.ui.graphicGraph.GraphicEdge)

Aggregations

GraphicEdge (org.graphstream.ui.graphicGraph.GraphicEdge)7 Point2D (javafx.geometry.Point2D)2 Point2 (org.graphstream.ui.geom.Point2)2 Vector2 (org.graphstream.ui.geom.Vector2)2 GraphicNode (org.graphstream.ui.graphicGraph.GraphicNode)2 GraphicSprite (org.graphstream.ui.graphicGraph.GraphicSprite)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Bounds (javafx.geometry.Bounds)1 GraphicsContext (javafx.scene.canvas.GraphicsContext)1 Affine (javafx.scene.transform.Affine)1