Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitmapEncoder saveBitmap no response when XYChart setyAxisTickLabelsFormattingFunction is called before. #799

Open
hegemon33 opened this issue Nov 30, 2023 · 2 comments
Labels

Comments

@hegemon33
Copy link

Now we're using XYChart to draw scatter chart with modified Y-Axis which is the real value of Y-Axis is different from the one shown on label.

For example: real y value = 10, on y-axis label should show 0.01.

// The label should show as y-label
final Map<Double, Double> yLabelMap = getyLabelMap();
chart.setyAxisTickLabelsFormattingFunction(yValue -> {
    final Double yLabel = yLabelMap.get(yValue);
    return yLabel == null ? "" : yLabel.toString();
});

BitmapEncoder.saveBitmap(chart, "output.png", BitmapEncoder.BitmapFormat.PNG);

When running, the program will stuck at the saveBitmap.

java: Java 11
knowm XChart version: 3.8.5

@hegemon33
Copy link
Author

Ok...found the problem, if the return values of the format function get duplicate value, the saveBitmap method will never stop. Maybe need to handle this case? Even throw an Exception will be nice.

@mccartney mccartney added the Bug label Feb 13, 2024
@mccartney
Copy link
Collaborator

Good bug report, thanks.

While surely an infinite loop is not a proper behavior of handling input, just making a remark that ensuring the labels are unique seem to be intended functionality:

boolean areAllTickLabelsUnique(List<?> tickLabels) {

The code seems to assume this is the only desired situation.

So I guess the intended behavior here is to actually throw error.

mccartney added a commit to mccartney/XChart that referenced this issue Feb 13, 2024
mccartney added a commit to mccartney/XChart that referenced this issue Feb 13, 2024
mccartney added a commit that referenced this issue Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants