Graph graphic presentation

This commit is contained in:
L3o15 2025-05-15 11:42:34 +02:00
parent 8f2a27d552
commit 73f3f08b5d

View file

@ -27,18 +27,36 @@ public class ElementGraph {
}
public void printGraph() {
for (GraphElement from : elements) {
Element fromElement = from.getElement();
System.out.println("[" + fromElement + "] →");
for (ElementLink link : from.getLinks()) {
Element toElement = link.getElement();
int value = link.getValue();
System.out.printf(" -> %s : %d\n", toElement, value);
System.out.println("From element is the row name, to element is the column name");
List<Element> elements = getElementsNames(); // lista ordinata degli elementi
int maxNameLen = 0;
for (Element element : elements) {
if (element.name().length() > maxNameLen) {
maxNameLen = element.name().length();
}
}
maxNameLen = maxNameLen + 2;
// Stampa intestazione colonna
System.out.print(String.format("%" + maxNameLen + "s", ""));
for (Element to : elements) {
System.out.print(String.format("%" + maxNameLen + "s", to));
}
System.out.println();
System.out.println("-".repeat(10 + maxNameLen * elements.size()));
// Stampa ogni riga
for (Element from : elements) {
System.out.print(String.format("%" + maxNameLen + "s", from));
for (Element to : elements) {
int value = getInteractionBetween(from, to);
System.out.print(String.format("%" + maxNameLen + "s", value));
}
System.out.println();
}
}
public int getTotalStrength(){