diff --git a/src/main/java/ee/ut/dendroloj/Dendrologist.java b/src/main/java/ee/ut/dendroloj/Dendrologist.java index 0ebcde3..99d2104 100644 --- a/src/main/java/ee/ut/dendroloj/Dendrologist.java +++ b/src/main/java/ee/ut/dendroloj/Dendrologist.java @@ -141,119 +141,6 @@ public static void drawGraph(GraphCanvas graphCanvas) { GraphGUI.initGenericGUI(uiScale, graph, GenericGraphLayout.autoLayout()); } - /** - * EXPERIMENTAL API - *

- * Draws a graph based on the provided adjacency matrix. - * Negative values in the adjacency matrix are treated as missing edges. - * - * @param adjacencyMatrix graph adjacency matrix; value at [i][j] is treated as the weight of the edge from vertex i to vertex j - * @param labels string labels for vertices; pass null to use vertex indices as labels - * @deprecated THIS API IS EXPERIMENTAL AND MAY EVENTUALLY BE REMOVED - */ - @Deprecated - public static void drawGraph(int[][] adjacencyMatrix, String[] labels) { - if (isHeadless()) { - System.err.println("Dendrologist: Running in headless environment. Ignoring call to drawGraph."); - return; - } - for (var row : adjacencyMatrix) { - if (row.length != adjacencyMatrix.length) { - throw new IllegalArgumentException("Adjacency matrix is not square"); - } - } - - drawAdjacencyMatrixGraph(adjacencyMatrix.length, (from, to) -> { - int value = adjacencyMatrix[from][to]; - return value >= 0 ? value : null; - }, labels); - } - - /** - * EXPERIMENTAL API - *

- * Draws a graph based on the provided adjacency matrix. - * Infinite and NaN values in the adjacency matrix are treated as missing edges. - * - * @param adjacencyMatrix graph adjacency matrix; value at [i][j] is treated as the weight of the edge from vertex i to vertex j - * @param labels string labels for vertices; pass null to use vertex indices as labels - * @deprecated THIS API IS EXPERIMENTAL AND MAY EVENTUALLY BE REMOVED - */ - @Deprecated - public static void drawGraph(double[][] adjacencyMatrix, String[] labels) { - if (isHeadless()) { - System.err.println("Dendrologist: Running in headless environment. Ignoring call to drawGraph."); - return; - } - for (var row : adjacencyMatrix) { - if (row.length != adjacencyMatrix.length) { - throw new IllegalArgumentException("Adjacency matrix is not square"); - } - } - - drawAdjacencyMatrixGraph(adjacencyMatrix.length, (from, to) -> { - double value = adjacencyMatrix[from][to]; - return Double.isFinite(value) ? value : null; - }, labels); - } - - /** - * EXPERIMENTAL API - *

- * Draws a graph based on the provided adjacency matrix. - * Infinite and NaN values in the adjacency matrix are treated as missing edges. - * - * @param adjacencyMatrix graph adjacency matrix; value at [i][j] is treated as the weight of the edge from vertex i to vertex j - * @param labels string labels for vertices; pass null to use vertex indices as labels - * @deprecated THIS API IS EXPERIMENTAL AND MAY EVENTUALLY BE REMOVED - */ - @Deprecated - public static void drawGraph(float[][] adjacencyMatrix, String[] labels) { - if (isHeadless()) { - System.err.println("Dendrologist: Running in headless environment. Ignoring call to drawGraph."); - return; - } - for (var row : adjacencyMatrix) { - if (row.length != adjacencyMatrix.length) { - throw new IllegalArgumentException("Adjacency matrix is not square"); - } - } - - drawAdjacencyMatrixGraph(adjacencyMatrix.length, (from, to) -> { - float value = adjacencyMatrix[from][to]; - return Float.isFinite(value) ? value : null; - }, labels); - } - - private static void drawAdjacencyMatrixGraph(int vertexCount, WeightProvider weights, String[] labels) { - GraphCanvas graphCanvas = new GraphCanvas<>(); - for (int i = 0; i < vertexCount; i++) { - graphCanvas.drawVertex(i, labels == null ? String.valueOf(i) : labels[i]); - Number selfWeight = weights.getWeight(i, i); - if (selfWeight != null && selfWeight.doubleValue() != 0.0) { - graphCanvas.drawEdge(i, i, selfWeight.toString()); - } - for (int j = i + 1; j < vertexCount; j++) { - Number weight = weights.getWeight(i, j); - Number backwardsWeight = weights.getWeight(j, i); - if (Objects.equals(weight, backwardsWeight)) { - if (weight != null) graphCanvas.drawEdge(i, j, weight.toString()); - } else { - if (weight != null) graphCanvas.drawDirectedEdge(i, j, weight.toString()); - if (backwardsWeight != null) graphCanvas.drawDirectedEdge(j, i, backwardsWeight.toString()); - } - - } - } - Graph graph = GenericGraphLayout.assembleGraph(graphCanvas); - GraphGUI.initGenericGUI(uiScale, graph, GenericGraphLayout.autoLayout()); - } - - @FunctionalInterface - private interface WeightProvider { - Number getWeight(int from, int to); - } - private static boolean isHeadless() { return GraphGUI.isHeadless(); }