@Override public void render(Item item, RenderTarget target, PreviewProperties properties) { //Retrieve clicked node for the label: LabelItem label = (LabelItem) item; Node node = label.node; //Finally draw your graphics for the node label in each target if (target instanceof G2DTarget) { Graphics2D g = ((G2DTarget) target).getGraphics(); g.setColor(Color.BLACK); g.fillOval((int) node.x(), (int) -node.y(), 5, 5);//Note that y axis is inverse for node coordinates } else if (target instanceof PDFTarget) { } else if (target instanceof SVGTarget) { } }
@Override public ForceVector calculateForce(Node node1, Node node2, float distance) { ForceVector f = new ForceVector(node2.x() - node1.x(), node2.y() - node1.y()); float scale = -relativeStrength * optimalDistance * optimalDistance / (distance * distance); if (Float.isNaN(scale) || Float.isInfinite(scale)) { scale = -1; } f.multiply(scale); return f; } }
public static void fcUniRepulsor(Node N1, Node N2, double c) { double xDist = N1.x() - N2.x(); // distance en x entre les deux noeuds double yDist = N1.y() - N2.y(); double dist = (float) Math.sqrt(xDist * xDist + yDist * yDist); // distance tout court if (dist > 0) { double f = repulsion(c, dist); ForceVectorNodeLayoutData N2L = N2.getLayoutData(); N2L.dx -= xDist / dist * f; N2L.dy -= yDist / dist * f; } }
public static void fcUniAttractor(Node N1, Node N2, float c) { double xDist = N1.x() - N2.x(); // distance en x entre les deux noeuds double yDist = N1.y() - N2.y(); double dist = (float) Math.sqrt(xDist * xDist + yDist * yDist); // distance tout court if (dist > 0) { double f = attraction(c, dist); ForceVectorNodeLayoutData N2L = N2.getLayoutData(); N2L.dx -= xDist / dist * f; N2L.dy -= yDist / dist * f; } }
@Override public void apply(Node n, double g) { ForceAtlas2LayoutData nLayout = n.getLayoutData(); // Get the distance double xDist = n.x(); double yDist = n.y(); double distance = (float) Math.sqrt(xDist * xDist + yDist * yDist); if (distance > 0) { // NB: factor = force / distance double factor = coefficient * nLayout.mass * g / distance; nLayout.dx -= xDist * factor; nLayout.dy -= yDist * factor; } } }
private boolean clickingInNode(Node node, PreviewMouseEvent event) { float xdiff = node.x() - event.x; float ydiff = -node.y() - event.y;//Note that y axis is inverse for node coordinates float radius = node.size(); return xdiff * xdiff + ydiff * ydiff < radius * radius; } }
public static void fcBiRepulsor_y(Node N1, Node N2, double c, double verticalization) { double xDist = N1.x() - N2.x(); // distance en x entre les deux noeuds double yDist = N1.y() - N2.y(); double dist = (float) Math.sqrt(xDist * xDist + yDist * yDist); // distance tout court if (dist > 0) { double f = repulsion(c, dist); ForceVectorNodeLayoutData N1L = N1.getLayoutData(); ForceVectorNodeLayoutData N2L = N2.getLayoutData(); N1L.dx += xDist / dist * f; N1L.dy += verticalization * yDist / dist * f; N2L.dx -= xDist / dist * f; N2L.dy -= verticalization * yDist / dist * f; } }
public static void fcBiRepulsor(Node N1, Node N2, double c) { double xDist = N1.x() - N2.x(); // distance en x entre les deux noeuds double yDist = N1.y() - N2.y(); double dist = (float) Math.sqrt(xDist * xDist + yDist * yDist); // distance tout court if (dist > 0) { double f = repulsion(c, dist); ForceVectorNodeLayoutData N1L = N1.getLayoutData(); ForceVectorNodeLayoutData N2L = N2.getLayoutData(); N1L.dx += xDist / dist * f; N1L.dy += yDist / dist * f; N2L.dx -= xDist / dist * f; N2L.dy -= yDist / dist * f; } }
protected float cameraDistance(NodeModel object) { float[] cameraLocation = drawable.getCameraLocation(); double distance = Math.sqrt(Math.pow((double) object.getNode().x() - cameraLocation[0], 2d) + Math.pow((double) object.getNode().y() - cameraLocation[1], 2d) + Math.pow((double) object.getNode().z() - cameraLocation[2], 2d)); object.setCameraDistance((float) distance); return (float) distance; }
public static void fcBiAttractor_noCollide(Node N1, Node N2, double c) { double xDist = N1.x() - N2.x(); // distance en x entre les deux noeuds double yDist = N1.y() - N2.y(); double dist = (float) Math.sqrt(xDist * xDist + yDist * yDist) - N1.size() - N2.size(); // distance (from the border of each node) if (dist > 0) { double f = attraction(c, dist); ForceVectorNodeLayoutData N1L = N1.getLayoutData(); ForceVectorNodeLayoutData N2L = N2.getLayoutData(); N1L.dx += xDist / dist * f; N1L.dy += yDist / dist * f; N2L.dx -= xDist / dist * f; N2L.dy -= yDist / dist * f; } }
public boolean isInOctreeLeaf(Octant leaf) { // float radius = node.size() / 2f; if (Math.abs(node.x() - leaf.getPosX()) > (leaf.getSize() / 2) || Math.abs(node.y() - leaf.getPosY()) > (leaf.getSize() / 2) || Math.abs(node.z() - leaf.getPosZ()) > (leaf.getSize() / 2)) { return false; } return true; }
@Override public void apply(Node n, Region r) { ForceAtlas2LayoutData nLayout = n.getLayoutData(); // Get the distance double xDist = n.x() - r.getMassCenterX(); double yDist = n.y() - r.getMassCenterY(); double distance = (float) Math.sqrt(xDist * xDist + yDist * yDist); if (distance > 0) { // NB: factor = force / distance double factor = coefficient * nLayout.mass * r.getMass() / distance / distance; nLayout.dx += xDist * factor; nLayout.dy += yDist * factor; } }
@Override public void startDrag() { float x = graphIO.getMouseDrag3d()[0]; float y = graphIO.getMouseDrag3d()[1]; dragSelected = getSelectedNodes(); for (NodeModel selected : dragSelected) { float[] tab = selected.getDragDistanceFromMouse(); tab[0] = selected.getNode().x() - x; tab[1] = selected.getNode().y() - y; } }
public void centerOnNode(Node node) { if (node != null) { VizController.getInstance().getGraphIO().centerOnCoordinate(node.x(), node.y(), node.z() + node.size() * 8); engine.getScheduler().requireUpdateVisible(); } }
@Override public void moveNode(Node node, ForceVector forceData) { ForceVector displacement = forceData.normalize(); displacement.multiply(step); float x = node.x() + displacement.x(); float y = node.y() + displacement.y(); if (assertValue(x)) { node.setX(x); } if (assertValue(y)) { node.setY(y); } }
@Override public void moveNode(Node node, ForceVector forceData) { ForceVector displacement = new ForceVector(forceData); displacement.multiply(step); float x = node.x() + displacement.x(); float y = node.y() + displacement.y(); if (assertValue(x)) { node.setX(x); } if (assertValue(y)) { node.setY(y); } } }
private void copyNodeProperties(Node node, Node nodeCopy) { nodeCopy.setPosition(node.x(), node.y(), node.z()); nodeCopy.setColor(node.getColor()); nodeCopy.setFixed(node.isFixed()); nodeCopy.setLabel(node.getLabel()); nodeCopy.setSize(node.size()); }
private void copyNodeProperties(Node node, Node nodeCopy) { nodeCopy.setPosition(node.x(), node.y(), node.z()); nodeCopy.setColor(node.getColor()); nodeCopy.setFixed(node.isFixed()); nodeCopy.setLabel(node.getLabel()); nodeCopy.setSize(node.size()); }