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);
}
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;
}
}
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());
}
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;
}
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());
}
}
}
Aggregations