Skip to content

Commit

Permalink
Proceeding to V3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftian14 committed Jan 22, 2021
1 parent 5da8e01 commit 51be9fe
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 210 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# MyLOGGER

![Collage](images/collage.png)

A simple _logging_ tool to make **console outputs** look prettier...

For instructions on using the logger, writing a "Formatting Code"
Expand Down
Binary file added images/collage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/main/java/com/mcxiv/logger/boxUtilities/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public class Box {
public static final String L_DC = "\u2560";
public static final String A_DC = "\u256C";


// Blocks
public static final String B_F = "\u2588";
public static final String B_H = "\u258B";
public static final String B_T = "\u258E";


}
29 changes: 29 additions & 0 deletions src/main/java/com/mcxiv/logger/plotting/Plot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.mcxiv.logger.plotting;

import com.mcxiv.logger.util.Iterator;

public class Plot {
public static interface BarGraph {
static BarGraph simple() {
return new SimpleBarGraph();
}

BarGraph title(String title);

BarGraph XLabel(String... names);

BarGraph XLabel(int a, int b, Iterator its);

BarGraph YLabel(String... names);

BarGraph YLabel(int a, int b, Iterator its);

BarGraph bar(int... values);

BarGraph W(int w);

BarGraph H(int h);

String create();
}
}
114 changes: 114 additions & 0 deletions src/main/java/com/mcxiv/logger/plotting/SimpleBarGraph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package com.mcxiv.logger.plotting;

import com.mcxiv.logger.boxUtilities.Box;
import com.mcxiv.logger.tools.C;
import com.mcxiv.logger.tools.RandomColor;
import com.mcxiv.logger.util.Iterator;

class SimpleBarGraph implements Plot.BarGraph {

String title = null;
String[] xLabels = null;
String[] yLabels = null;
int[] values = null;

double scale = 0.1;

@Override
public Plot.BarGraph title(String title) {
this.title = title;
return this;
}

@Override
public Plot.BarGraph XLabel(String... names) {
xLabels = names;
return this;
}

@Override
public Plot.BarGraph XLabel(int a, int b, Iterator its) {
xLabels = (String[]) Iterator.toArray(a, b, 1, its);
return this;
}

@Override
public Plot.BarGraph YLabel(String... names) {
yLabels = names;
return this;
}

@Override
public Plot.BarGraph YLabel(int a, int b, Iterator its) {
yLabels = Iterator.toArray(a, b, 1, its);
return this;
}

@Override
public Plot.BarGraph bar(int... values) {
this.values = values;
return this;
}

@Override
public Plot.BarGraph W(int w) {
return this;
}

@Override
public Plot.BarGraph H(int h) {
return this;
}

@Override
public String create() {

int highestBar = Integer.MIN_VALUE;
for (int i : values) if (highestBar < i) highestBar = i;

int longestName = Integer.MIN_VALUE;
if (yLabels == null) yLabels = defaultYLables(highestBar);
for (String s : yLabels) if (longestName < s.length()) longestName = s.length();


StringBuilder builder = new StringBuilder("\n");


String form = " %" + longestName + "s \u2528 ";

for (int dh = 0, lim = (int) (highestBar * scale); dh < lim; dh++) {

if (dh >= lim - yLabels.length)
builder.append(String.format(form, yLabels[lim - dh - 1]));
else builder.append(String.format(form, ""));

for (int dw = 0; dw < values.length; dw++) { // +3 of pads and border

if (values[dw] * scale >= lim - dh)
builder.append(RandomColor.getRandomAt(dw)).append(Box.B_F);
else builder.append(" ");

}

if (xLabels != null && dh < xLabels.length)
builder.append(" ").append(RandomColor.getRandomAt(dh)).append(Box.B_F).append(C.RS).append(" ").append(xLabels[dh]);

builder.append("\n").append(C.RS);
}

for (int i = 0; i < longestName + 2; i++)
builder.append(" ");
builder.append("\u2517");
for (int i = 0; i < values.length + 2; i++)
builder.append("\u2501");

return builder.toString();
}

private static String[] defaultYLables(int highestBar) {
String[] sts = new String[highestBar];
for (int i = 0; i < highestBar; i++)
sts[i] = "" + i;
return sts;
}
}
62 changes: 2 additions & 60 deletions src/main/java/com/mcxiv/logger/tables/BoxTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.mcxiv.logger.boxUtilities.Box;
import com.mcxiv.logger.decorations.Decoration;
import com.mcxiv.logger.util.GroupIterator;
import com.mcxiv.logger.util.Iterator;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -79,66 +81,6 @@ public Table row(String... msg) {
return this;
}

@Override
public Table iter(int a, int b, Iterator... its) {

for (int i = a; i < b; i++) { // for each row

String[] msg = new String[its.length]; // every cell

for (int j = 0; j < msg.length; j++)
msg[j] = its[j].consume(i).toString(); // for each cell; jth cell on ith row

rows.add(msg);

for (int j = 0; j < its.length; j++) // for each cell/column updating row width
if (rowWidth.get(j) < msg[j].length())
rowWidth.set(j, msg[j].length());

}
return this;
}

@Override
public Table iter(int a, int b, int c, Iterator... its) {

for (int i = a; i < b; i += c) { // for each row

String[] msg = new String[its.length]; // every cell

for (int j = 0; j < msg.length; j++)
msg[j] = its[j].consume(i).toString(); // for each cell; jth cell on ith row

rows.add(msg);

for (int j = 0; j < its.length; j++) // for each cell/column updating row width
if (rowWidth.get(j) < msg[j].length())
rowWidth.set(j, msg[j].length());

}
return this;
}

@Override
public <T> Table bunch(T[] main, int groupSize, GroupIterator<T>... its) {
for (int i = 0; i < main.length; i += groupSize) { // For every bunch <-> For each row

String[] msg = new String[its.length]; // every cell

for (int j = 0; j < its.length; j++) // for each cell
msg[j] = its[j].consume(i / groupSize, Arrays.copyOfRange(main, i, i + groupSize)).toString();

rows.add(msg);

for (int j = 0; j < its.length; j++) // for each cell/column updating row width
if (rowWidth.get(j) < msg[j].length())
rowWidth.set(j, msg[j].length());

}

return this;
}

@Override
public String create() {
// Initialising all formats, if not specified, the default is used.
Expand Down
61 changes: 0 additions & 61 deletions src/main/java/com/mcxiv/logger/tables/EmptyTable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mcxiv.logger.tables;

import java.util.ArrayList;
import java.util.Arrays;

class EmptyTable extends TableAdaptor {

Expand Down Expand Up @@ -58,66 +57,6 @@ public Table row(String... msg) {
return this;
}

@Override
public Table iter(int a, int b, Iterator... its) {

for (int i = a; i < b; i++) { // for each row

String[] msg = new String[its.length]; // every cell

for (int j = 0; j < msg.length; j++)
msg[j] = its[j].consume(i).toString(); // for each cell; jth cell on ith row

rows.add(msg);

for (int j = 0; j < its.length; j++) // for each cell/column updating row width
if (rowWidth.get(j) < msg[j].length())
rowWidth.set(j, msg[j].length());

}
return this;
}

@Override
public Table iter(int a, int b, int c, Iterator... its) {

for (int i = a; i < b; i += c) { // for each row

String[] msg = new String[its.length]; // every cell

for (int j = 0; j < msg.length; j++)
msg[j] = its[j].consume(i).toString(); // for each cell; jth cell on ith row

rows.add(msg);

for (int j = 0; j < its.length; j++) // for each cell/column updating row width
if (rowWidth.get(j) < msg[j].length())
rowWidth.set(j, msg[j].length());

}
return this;
}

@Override
public <T> Table bunch(T[] main, int groupSize, GroupIterator<T>... its) {
for (int i = 0; i < main.length; i += groupSize) { // For every bunch <-> For each row

String[] msg = new String[its.length]; // every cell

for (int j = 0; j < its.length; j++) // for each cell
msg[j] = its[j].consume(i / groupSize, Arrays.copyOfRange(main, i, i + groupSize)).toString();

rows.add(msg);

for (int j = 0; j < its.length; j++) // for each cell/column updating row width
if (rowWidth.get(j) < msg[j].length())
rowWidth.set(j, msg[j].length());

}

return this;
}

@Override
public String create() {

Expand Down
Loading

0 comments on commit 51be9fe

Please sign in to comment.