Skip to content

redesign the help statistics plot - #560

Open
Neil-Tomar wants to merge 1 commit into
Java-Discord:mainfrom
Neil-Tomar:feat/plotter-redesign
Open

redesign the help statistics plot#560
Neil-Tomar wants to merge 1 commit into
Java-Discord:mainfrom
Neil-Tomar:feat/plotter-redesign

Conversation

@Neil-Tomar

Copy link
Copy Markdown
Contributor

redesign the help statistics plot.

@Neil-Tomar
Neil-Tomar requested a review from a team as a code owner September 6, 2026 12:13

@danthe1st danthe1st left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry too much about updating the test graph while it is still in review, I will give you one once we are at a point where the PR is otherwise ok.
The differences between Windows and Linux may be caused by differences in antialiasing.

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid the wildcard import.

this.transactionRepository = transactionRepository;
setCommandData(new SubcommandData("stats", "Shows an general plot about help activity in this server"));
setCommandData(new SubcommandData("stats", "Shows an general plot about help activity in this server")
.addOption(OptionType.BOOLEAN, "darkmode", "generate a plot in dark mode.", false)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should start with an uppercase letter. I would suggest

Generates the plot with a dark background.

public void ImageDifferenceTest(){
List<Pair<String, Plotter.Bar>> testData = testData();
BufferedImage img1 = new Plotter(testData, "General helper statistics","subtitle").plot();
BufferedImage img2 = readImage("src/test/resources/PlotterTest.png");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't assume resources are files. Instead, load them as resources using getClass().getClassLoader().getResource("/PlotterTest.png"); or similar.

throw new IOException("Image is null.");
}
return image;
} catch (IOException e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please just throw the exception instead. In a test, it's ok if an exception is thrown in an error case.


public static boolean compareImage(BufferedImage img1, BufferedImage img2) {
if (img1 == null || img2 == null) {
return false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of just returning boolean and asserting it being true, please use proper assertions when they happen, e.g. assertNonNull(actual) and assertEquals(expected.getWidth(), actual.getWidth(), "image width does not match")

for (Pair<Color, Double> element : bar.elements()) {
double value = element.second();
int segmentHeight = (int) (height * (value / axisMax));
if (segmentHeight <= 0) continue;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use continue to exit out of a loop. Instead, either create a method where you can return or use a segmentHeight > 0 condition where you perform the drawing.


String label = formatMonth(entry.first());
int labelWidth = graphics2D.getFontMetrics().stringWidth(label);
graphics2D.drawString(label, centerX - labelWidth / 2, startY + height + 65);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple occurences where you draw a String centered around an x-coordinate. Please create a method for centered texts.


String label = formatMonth(entry.first());
int labelWidth = graphics2D.getFontMetrics().stringWidth(label);
graphics2D.drawString(label, centerX - labelWidth / 2, startY + height + 65);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a constant instead of a magic number here.

return String.format("%.2f", value);
}

private String formatMonth(String month) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class shouldn't be specific to months. If you want to display month names differently, please adapt the callers to pass the month names in the format that works well for them.

if (normalized <= 1) {
nice = 1;
} else if (normalized <= 2) {
nice = 2;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to, you can change the 2 to 2.5 here to have "nice" steps of 25.

};

@Test
public void ImageDifferenceTest(){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to add a second test for dark mode but that's up to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants