public void setNodesX(Float x) { nodesX = x; for (Node node : nodes) { node.setX(x); } }
public void readNodeData(XMLStreamReader reader, Node node) throws XMLStreamException { boolean end = false; while (reader.hasNext() && !end) { Integer eventType = reader.next(); if (eventType.equals(XMLEvent.START_ELEMENT)) { String name = reader.getLocalName(); if (ELEMENT_NODEDATA_POSITION.equalsIgnoreCase(name)) { node.setX(Float.parseFloat(reader.getAttributeValue(null, "x"))); node.setY(Float.parseFloat(reader.getAttributeValue(null, "y"))); node.setZ(Float.parseFloat(reader.getAttributeValue(null, "z"))); } else if (ELEMENT_NODEDATA_COLOR.equalsIgnoreCase(name)) { node.setR(Float.parseFloat(reader.getAttributeValue(null, "r"))); node.setG(Float.parseFloat(reader.getAttributeValue(null, "g"))); node.setB(Float.parseFloat(reader.getAttributeValue(null, "b"))); node.setAlpha(Float.parseFloat(reader.getAttributeValue(null, "a"))); } else if (ELEMENT_NODEDATA_SIZE.equalsIgnoreCase(name)) { node.setSize(Float.parseFloat(reader.getAttributeValue(0))); } } else if (eventType.equals(XMLStreamReader.END_ELEMENT)) { if (ELEMENT_NODEDATA.equalsIgnoreCase(reader.getLocalName())) { end = true; } } } }
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { for (Node n : graph.getNodes()) { n.setX((float) (-size / 2 + size * random.nextDouble())); n.setY((float) (-size / 2 + size * random.nextDouble())); } converged = true; } finally { graph.readUnlockAll(); } }
n.setX(random.nextInt(2000) - 1000); n.setY(random.nextInt(2000) - 1000);
@Override public void mouseClick(int[] positionViewport, float[] position3d) { //Get current graph GraphController gc = Lookup.getDefault().lookup(GraphController.class); Graph graph = gc.getGraphModel().getGraph(); GraphFactory factory = gc.getGraphModel().factory(); //Add node Node node = factory.newNode(); node.setX(position3d[0]); node.setY(position3d[1]); node.setSize(10f); graph.addNode(node); } },
@Override public void goAlgo() { Graph graph = graphModel.getGraphVisible(); graph.readLock(); int nodeCount = graph.getNodeCount(); Node[] nodes = graph.getNodes().toArray(); int rows = (int) Math.round(Math.sqrt(nodeCount)) + 1; int cols = (int) Math.round(Math.sqrt(nodeCount)) + 1; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols && (i * rows + j) < nodes.length; j++) { Node node = nodes[i * rows + j]; float x = (-areaSize / 2f) + ((float) j / cols) * areaSize; float y = (areaSize / 2f) - ((float) i / rows) * areaSize; float px = node.x(); float py = node.y(); node.setX(px + (x - px) * (speed / 10000f)); node.setY(py + (y - py) * (speed / 10000f)); } } graph.readUnlock(); }
/** * See https://github.com/gephi/gephi/issues/603 Nodes position to NaN on applied layout * * @param graphModel */ public static void ensureSafeLayoutNodePositions(GraphModel graphModel) { Graph graph = graphModel.getGraph(); NodeIterable nodesIterable = graph.getNodes(); for (Node node : nodesIterable) { if (node.x() != 0 || node.y() != 0) { nodesIterable.doBreak(); return; } } //All at 0.0, init some random positions nodesIterable = graph.getNodes(); for (Node node : nodesIterable) { node.setX((float) ((0.01 + Math.random()) * 1000) - 500); node.setY((float) ((0.01 + Math.random()) * 1000) - 500); } } }
private Node buildNode(Graph graph, String label, String id) { Node newNode; if (id != null) { newNode = graph.getModel().factory().newNode(id); } else { newNode = graph.getModel().factory().newNode(); } newNode.setSize(DEFAULT_NODE_SIZE); newNode.setLabel(label); //Set random position to the node: newNode.setX((float) ((0.01 + Math.random()) * 1000) - 500); newNode.setY((float) ((0.01 + Math.random()) * 1000) - 500); return newNode; }
private void clampPosition(NodeModel nodeModel) { //Clamp Hack to avoid nodes to be outside octree float quantum = size / 2; Node node = nodeModel.getNode(); float x = node.x(); float y = node.y(); float z = node.z(); if (x > root.posX + quantum) { node.setX(root.posX + quantum); } else if (x < root.posX - quantum) { node.setX(root.posX - quantum); } if (y > root.posY + quantum) { node.setY(root.posY + quantum); } else if (y < root.posY - quantum) { node.setY(root.posY - quantum); } if (z > root.posZ + quantum) { node.setZ(root.posZ + quantum); } else if (z < root.posZ - quantum) { node.setZ(root.posZ - quantum); } }
float px = node.x(); float py = node.y(); node.setX(px + (x - px) * (speed / 10000f)); node.setY(py + (y - py) * (speed / 10000f));
@Override public void mouseClick(int[] positionViewport, float[] position3d) { color = nodePencilPanel.getColor(); size = nodePencilPanel.getNodeSize(); GraphController gc = Lookup.getDefault().lookup(GraphController.class); GraphModel gm = gc.getGraphModel(); Graph graph = gm.getGraph(); Node node = gm.factory().newNode(); node.setX(position3d[0]); node.setY(position3d[1]); node.setSize(size); node.setColor(color); graph.addNode(node); } };
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { double sin = Math.sin(-getAngle() * Math.PI / 180); double cos = Math.cos(-getAngle() * Math.PI / 180); double px = 0f; double py = 0f; for (Node n : graph.getNodes()) { double dx = n.x() - px; double dy = n.y() - py; n.setX((float) (px + dx * cos - dy * sin)); n.setY((float) (py + dy * cos + dx * sin)); } setConverged(true); } finally { graph.readUnlockAll(); } }
@Override public void mouseDrag() { if (vizConfig.isMouseSelectionUpdateWhileDragging()) { mouseMove(); } else { float[] drag = graphIO.getMouseDrag3d(); if (dragSelected != null) { for (NodeModel obj : dragSelected) { float[] mouseDistance = obj.getDragDistanceFromMouse(); obj.getNode().setX(drag[0] + mouseDistance[0]); obj.getNode().setY(drag[1] + mouseDistance[1]); } } } }
@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 clickNodes(Node[] nodes) { //Get mouse position float[] position3d = VizController.getInstance().getGraphIO().getMousePosition3d(); //Get current graph GraphController gc = Lookup.getDefault().lookup(GraphController.class); Graph graph = gc.getGraphModel().getGraph(); GraphFactory factory = gc.getGraphModel().factory(); //Add node Node node = factory.newNode(); node.setX(position3d[0]); node.setY(position3d[1]); node.setSize(10f); graph.addNode(node); //Add edges with the clicked nodes for (Node n : nodes) { Edge edge = factory.newEdge(node, n); graph.addEdge(edge); } } }};
@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); } } }
newNode.setX(selectedNode.x()); newNode.setY(selectedNode.y()); newNode.setZ(selectedNode.z());
@Override public void goAlgo() { graph = graphModel.getGraphVisible(); graph.readLock(); try { double xMean = 0, yMean = 0; for (Node n : graph.getNodes()) { xMean += n.x(); yMean += n.y(); } xMean /= graph.getNodeCount(); yMean /= graph.getNodeCount(); for (Node n : graph.getNodes()) { double dx = (n.x() - xMean) * getScale(); double dy = (n.y() - yMean) * getScale(); n.setX((float) (xMean + dx)); n.setY((float) (yMean + dy)); } setConverged(true); } finally { graph.readUnlockAll(); } }
private Node copyNode(Node node, Graph graph) { Node copy = buildNode(graph, node.getLabel()); //Copy properties (position, size and color): copy.setX(node.x()); copy.setY(node.y()); copy.setZ(node.z()); copy.setSize(node.size()); copy.setR(node.r()); copy.setG(node.g()); copy.setB(node.b()); copy.setAlpha(node.alpha()); Table nodeTable = graph.getModel().getNodeTable(); //Copy attributes: for (Column column : nodeTable) { if (!column.isReadOnly()) { copy.setAttribute(column, node.getAttribute(column)); } } graph.addNode(copy); return copy; }
OpenOrdLayoutData layoutData = n.getLayoutData(); Node node = positions[layoutData.nodeId]; n.setX(node.x * 10f); n.setY(node.y * 10f);