private void updateEdges(HierarchicalGraph graph) { Modeler edgeInit = engine.getModelClasses()[AbstractEngine.CLASS_EDGE].getCurrentModeler(); Modeler arrowInit = engine.getModelClasses()[AbstractEngine.CLASS_ARROW].getCurrentModeler(); EdgeIterable edgeIterable; edgeIterable = graph.getEdges(); float minWeight = Float.POSITIVE_INFINITY; float maxWeight = Float.NEGATIVE_INFINITY; TimeInterval timeInterval = DynamicUtilities.getVisibleInterval(dynamicModel); for (Edge edge : edgeIterable) { if (edge.getSource().getNodeData().getModel() == null || edge.getTarget().getNodeData().getModel() == null) { continue; } float weight = 1f; if (timeInterval == null) { weight = edge.getWeight(); } else { weight = edge.getWeight(timeInterval.getLow(), timeInterval.getHigh()); } minWeight = Math.min(minWeight, weight); maxWeight = Math.max(maxWeight, weight); Edge2dModel obj = (Edge2dModel) edge.getEdgeData().getModel(); if (obj == null) { // Model is null, ADD obj = (Edge2dModel) edgeInit.initModel(edge.getEdgeData()); engine.addObject(AbstractEngine.CLASS_EDGE, obj); if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop()) { Arrow2dModel arrowObj = (Arrow2dModel) arrowInit.initModel(edge.getEdgeData()); engine.addObject(AbstractEngine.CLASS_ARROW, arrowObj); arrowObj.setCacheMarker(cacheMarker); arrowObj.setWeight(weight); obj.setArrow(arrowObj); } } else if (!obj.isValid()) { engine.addObject(AbstractEngine.CLASS_EDGE, obj); if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop()) { Arrow2dModel arrowObj = obj.getArrow(); engine.addObject(AbstractEngine.CLASS_ARROW, arrowObj); arrowObj.setCacheMarker(cacheMarker); arrowObj.setWeight(weight); } } else { if (!undirected && vizConfig.isShowArrows() && !edge.isSelfLoop() && edge.isDirected()) { Arrow2dModel arrowObj = obj.getArrow(); arrowObj.setCacheMarker(cacheMarker); arrowObj.setWeight(weight); } } obj.setWeight(weight); obj.setCacheMarker(cacheMarker); } limits.setMinWeight(minWeight); limits.setMaxWeight(maxWeight); }
@Override public Object getValueFor(Edge edge) { if (edge.isDirected()) { return NbBundle.getMessage(EdgesDataTable.class, "EdgeDataTable.type.column.directed"); } else { return NbBundle.getMessage( EdgesDataTable.class, "EdgeDataTable.type.column.undirected"); } }
private void writeEdges(XMLStreamWriter xmlWriter, HierarchicalGraph graph) throws Exception { if (cancel) { return; } xmlWriter.writeStartElement(EDGES); AttributeColumn dynamicCol = dynamicCol = attributeModel.getEdgeTable().getColumn(DynamicModel.TIMEINTERVAL_COLUMN); EdgeIterable edgeIterable = exportHierarchy ? graph.getEdgesTree() : graph.getEdgesAndMetaEdges(); for (Edge edge : edgeIterable) { xmlWriter.writeStartElement(EDGE); if (edge.getEdgeData().getId() != null && !edge.getEdgeData().getId().equals(Integer.toString(edge.getId()))) { xmlWriter.writeAttribute(EDGE_ID, edge.getEdgeData().getId()); } xmlWriter.writeAttribute(EDGE_SOURCE, edge.getSource().getNodeData().getId()); xmlWriter.writeAttribute(EDGE_TARGET, edge.getTarget().getNodeData().getId()); if (edge.isDirected() && graphModel.isMixed()) { xmlWriter.writeAttribute(EDGE_TYPE, "directed"); } else if (!edge.isDirected() && graphModel.isMixed()) { xmlWriter.writeAttribute(EDGE_TYPE, "undirected"); } String label = edge.getEdgeData().getLabel(); if (label != null && !label.isEmpty()) { xmlWriter.writeAttribute(EDGE_LABEL, label); } float weight = edge.getWeight(); if (weight != 1f) { xmlWriter.writeAttribute(EDGE_WEIGHT, "" + weight); } if (exportDynamic && dynamicCol != null && visibleInterval != null) { TimeInterval timeInterval = (TimeInterval) edge.getEdgeData().getAttributes().getValue(dynamicCol.getIndex()); if (timeInterval != null) { writeTimeInterval(xmlWriter, timeInterval); } } if (exportColors) { writeEdgeColor(xmlWriter, edge); } if (exportAttributes && edge.getEdgeData().getAttributes() != null) { AttributeRow attributeRow = (AttributeRow) edge.getEdgeData().getAttributes(); writeAttValues(xmlWriter, attributeRow, visibleInterval); } xmlWriter.writeEndElement(); Progress.progress(progress); if (cancel) { break; } } xmlWriter.writeEndElement(); }
private void exportData(Graph graph) throws Exception { int max = graph.getNodeCount(); Progress.start(progressTicket, max); if (!list) { if (header) { writer.append(SEPARATOR); Node[] nodes = graph.getNodes().toArray(); for (int i = 0; i < nodes.length; i++) { writeMatrixNode(nodes[i], i < nodes.length - 1); } writer.append(EOL); } } if (list) { Node[] nodes = graph.getNodes().toArray(); for (int i = 0; i < nodes.length; i++) { Node n = nodes[i]; List<Node> neighbours = new ArrayList<Node>(); for (Edge e : graph.getEdges(n)) { if (!e.isDirected() || (e.isDirected() && n == e.getSource())) { Node m = graph.getOpposite(n, e); neighbours.add(m); } } for (Edge e : ((HierarchicalGraph) graph).getMetaEdges(n)) { if (!e.isDirected() || (e.isDirected() && n == e.getSource())) { Node m = graph.getOpposite(n, e); neighbours.add(m); } } writeListNode(n, !neighbours.isEmpty()); for (int j = 0; j < neighbours.size(); j++) { writeListNode(neighbours.get(j), j < neighbours.size() - 1); } writer.append(EOL); } } else { if (graph instanceof DirectedGraph) { DirectedGraph directedGraph = (DirectedGraph) graph; Node[] nodes = graph.getNodes().toArray(); for (Node n : nodes) { if (cancel) { break; } writeMatrixNode(n, true); for (int j = 0; j < nodes.length; j++) { Node m = nodes[j]; Edge e = directedGraph.getEdge(n, m); e = e == null ? ((HierarchicalDirectedGraph) directedGraph).getMetaEdge(n, m) : e; writeEdge(e, j < nodes.length - 1); } Progress.progress(progressTicket); writer.append(EOL); } } else if (graph instanceof UndirectedGraph) { UndirectedGraph undirectedGraph = (UndirectedGraph) graph; Node[] nodes = graph.getNodes().toArray(); for (Node n : nodes) { if (cancel) { break; } writeMatrixNode(n, true); for (int j = 0; j < nodes.length; j++) { Node m = nodes[j]; Edge e = undirectedGraph.getEdge(n, m); e = e == null ? ((HierarchicalUndirectedGraph) undirectedGraph).getMetaEdge(n, m) : e; writeEdge(e, j < nodes.length - 1); } Progress.progress(progressTicket); writer.append(EOL); } } else { MixedGraph mixedGraph = (MixedGraph) graph; Node[] nodes = graph.getNodes().toArray(); for (Node n : graph.getNodes()) { if (cancel) { break; } writeMatrixNode(n, true); for (int j = 0; j < nodes.length; j++) { Node m = nodes[j]; Edge e = mixedGraph.getEdge(n, m); e = e == null ? ((HierarchicalMixedGraph) mixedGraph).getMetaEdge(n, m) : e; writeEdge(e, j < nodes.length - 1); } Progress.progress(progressTicket); writer.append(EOL); } } } graph.readUnlockAll(); Progress.finish(progressTicket); }