Skip to content

Commit

Permalink
Release 0.0.6, add go arounds
Browse files Browse the repository at this point in the history
  • Loading branch information
binokkio committed Aug 28, 2022
1 parent 4d629af commit a5b094c
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
32 changes: 15 additions & 17 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is a low quality codebase written specifically to render plain text visualizations of flows in Gingester.
This is a pathfinder codebase written specifically to render plain text visualizations of flows in Gingester.

Example code:

Expand All @@ -16,20 +16,18 @@ new GraphTxt(List.of(

Will produce:

┌───────┐ ┌───┐
│ AAAAA │ │ D │
└───┬───┘ └─┬─┘
┌───┴───┐ │
│ ├──────┬──┴───┬──────┐
┌─┴─┐ ┌───┴──┐ ┌─┴─┐ ┌──┴──┐ ┌─┴─┐
│ C │ │ BBBB │ │ E │ │ ZZZ │ │ H │
└───┘ └───┬──┘ └───┘ └─────┘ └─┬─┘
│ ┌┘
┌─┴─┐ ┌───┴──┐
│ F │ │ IIII │
└───┘ └──────┘
┌───────┐ ┌───┐
│ AAAAA │ │ D │
└───┬───┘ └─┬─┘
┌───┬───┴───┐ │
│ │ ├──────┬──┴───┬──────┐
│ ┌─┴─┐ ┌───┴──┐ ┌─┴─┐ ┌──┴──┐ ┌─┴─┐
│ │ C │ │ BBBB │ │ E │ │ ZZZ │ │ H │
│ └───┘ └───┬──┘ └───┘ └─────┘ └─┬─┘
│ │ ┌┘
└───────────┤ │
┌─┴─┐ ┌───┴──┐
│ F │ │ IIII │
└───┘ └──────┘

The layout algorithm keeps the nodes within the horizontal space used by the widest row.

Edges that skip a row, e.g. AAAAA-F in the example, currently draw behind other edges and nodes which needs to
be improved.
The layout algorithm keeps the nodes within the horizontal space used by the widest row.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<groupId>b.nana.technology.graphtxt</groupId>
<artifactId>graphtxt</artifactId>
<version>0.0.5</version>
<version>0.0.6</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
24 changes: 10 additions & 14 deletions src/main/java/b/nana/technology/graphtxt/GoAround.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@

public class GoAround {

private final NodeTxt to;
private final Set<NodeTxt> from = new HashSet<>();
private final NodeTxt from;
private final Set<NodeTxt> to = new HashSet<>();
final int x;
private final int height;
final int incomingGoAroundOffset;

public GoAround(Row row, NodeTxt to, int x, int height) {
this.to = to;
public GoAround(NodeTxt from, int x) {
this.from = from;
this.x = x;
this.height = height;
this.incomingGoAroundOffset = row.claimIncomingGoAroundOffset();
}

public NodeTxt getTo() {
return to;
public NodeTxt getFrom() {
return from;
}

public Set<NodeTxt> getFrom() {
return from;
public Set<NodeTxt> getTo() {
return to;
}

public void addFrom(NodeTxt from) {
this.from.add(from);
public void addTo(NodeTxt to) {
this.to.add(to);
}
}
12 changes: 6 additions & 6 deletions src/main/java/b/nana/technology/graphtxt/GoArounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public GoArounds(Nodes nodes, Rows rows) {
int toRowIndex = rows.getRowIndex(to);
int rowDistance = toRowIndex - fromRowIndex;
if (rowDistance > 1) {
GoAround goAround = goArounds.get(to);
GoAround goAround = goArounds.get(from);
if (goAround == null) {
goAround = new GoAround(rows.get(toRowIndex), to, x++, rowDistance);
goArounds.put(to, goAround);
goAround = new GoAround(from, x++);
goArounds.put(from, goAround);
}
goAround.addFrom(from);
goAround.addTo(to);
}
}
}
Expand All @@ -41,10 +41,10 @@ public GoAround get(NodeTxt to) {
}

public boolean isAtStartOfGoAround(NodeTxt node) {
return goArounds.values().stream().anyMatch(goAround -> goAround.getFrom().contains(node));
return goArounds.containsKey(node);
}

public boolean isAtEndOfGoAround(NodeTxt node) {
return goArounds.containsKey(node);
return goArounds.values().stream().anyMatch(goAround -> goAround.getTo().contains(node));
}
}
2 changes: 1 addition & 1 deletion src/main/java/b/nana/technology/graphtxt/GraphTxt.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String getText() {
for (Edge edge : node.getNode().getEdges()) {
NodeTxt to = nodes.get(edge.getTo());
if (rows.getRowIndex(node) + 1 != rows.getRowIndex(to)) {
node.renderEdge(canvas, coast, goArounds.get(to), to);
node.renderEdge(canvas, coast, goArounds.get(node), to, rows.get(rows.getRowIndex(to)));
incrementCoast = true;
} else {
node.renderEdge(canvas, coast, to);
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/b/nana/technology/graphtxt/NodeTxt.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class NodeTxt {

private int x;
private int y;
private int incomingGoAroundOffset = -1;

public NodeTxt(Node node) {
this.node = node;
Expand Down Expand Up @@ -96,9 +97,7 @@ public void renderNode(Canvas canvas) {
canvas.getPixel(x, y).setContent(RIGHT_DOWN);
canvas.getPixel(x + getWidth() - 1, y).setContent(DOWN_LEFT);
canvas.getPixel(x, y + 1).setContent(UP_DOWN);
canvas.getPixel(x + 1, y + 1).setContent(' ');
canvas.getPixel(x + getWidth() - 1, y + 1).setContent(UP_DOWN);
canvas.getPixel(x + getWidth() - 2, y + 1).setContent(' ');
canvas.getPixel(x, y + 2).setContent(UP_RIGHT);
canvas.getPixel(x + getWidth() - 1, y + 2).setContent(UP_LEFT);
for (int i = 1; i < getWidth() - 1; i++) {
Expand Down Expand Up @@ -137,7 +136,7 @@ public void renderEdge(Canvas canvas, int coast, NodeTxt nodeTxt) {
addEdgeSegment(canvas.getPixel(x, ++y), UP_DOWN_MASK);
}

public void renderEdge(Canvas canvas, int coast, GoAround goAround, NodeTxt to) {
public void renderEdge(Canvas canvas, int coast, GoAround goAround, NodeTxt to, Row toRow) {
int x = this.x + (getWidth() / 2);
int y = this.y + 3;

Expand All @@ -149,7 +148,7 @@ public void renderEdge(Canvas canvas, int coast, GoAround goAround, NodeTxt to)
addEdgeSegment(canvas.getPixel(--x, y), RIGHT_LEFT_MASK);

addEdgeSegment(canvas.getPixel(--x, y), RIGHT_DOWN_MASK);
while (y < to.y - goAround.incomingGoAroundOffset - 1)
while (y < to.y - to.getIncomingGoAroundOffset(toRow) - 1)
addEdgeSegment(canvas.getPixel(x, ++y), UP_DOWN_MASK);

addEdgeSegment(canvas.getPixel(x, ++y), UP_RIGHT_MASK);
Expand All @@ -160,6 +159,13 @@ public void renderEdge(Canvas canvas, int coast, GoAround goAround, NodeTxt to)

}

private int getIncomingGoAroundOffset(Row toRow) {
if (incomingGoAroundOffset == -1) {
incomingGoAroundOffset = toRow.claimIncomingGoAroundOffset();
}
return incomingGoAroundOffset;
}

private void addEdgeSegment(Pixel pixel, int edgeSegmentMask) {
pixel.setContent(EDGE_SEGMENTS[getEdgeSegmentMask(pixel.getContent()) | edgeSegmentMask]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/b/nana/technology/graphtxt/GraphTxtTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void testGoArounds2() {
List.of(
SimpleNode.of("A", "B", "D", "E"),
SimpleNode.of("B", "C", "D"),
SimpleNode.of("C", "D"),
SimpleNode.of("C", "D", "E"),
SimpleNode.of("D", "E"),
SimpleNode.of("E")
)
Expand Down

0 comments on commit a5b094c

Please sign in to comment.