Skip to content

Commit

Permalink
focus the simulation's chart on the range of interest
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Aug 22, 2024
1 parent 598b7b9 commit 02ce975
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ junit-testng = "1.0.5"
junit4 = "4.13.2"
junit5 = "5.11.0"
jvm-dependency-conflict-resolution = "2.1.2"
kotlin = "2.0.10"
kotlin = "2.0.20"
lincheck = "2.33"
mockito = "5.12.0"
nexus-publish = "2.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.DefaultDrawingSupplier;
import org.jfree.chart.ui.RectangleInsets;
import org.jfree.data.Range;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;

Expand Down Expand Up @@ -109,11 +110,30 @@ private void configurePlot(JFreeChart chart) {
configureAxis(plot.getRangeAxis());
configureGrid(plot);

plot.getRangeAxis().setAutoRange(false);
plot.getRangeAxis().setRange(calculateRange(plot));

for (int i = 0; i < plot.getCategories().size(); i++) {
plot.getRenderer().setSeriesStroke(i, new BasicStroke(3.0f));
}
}

private Range calculateRange(CategoryPlot plot) {
double upperBound = 0;
double lowerBound = 100;
for (int series = 0; series < plot.getDataset().getRowCount(); series++) {
for (int item = 0; item < plot.getDataset().getColumnCount(); item++) {
var value = plot.getDataset().getValue(series, item);
if (value != null) {
lowerBound = Math.min(lowerBound, value.doubleValue());
upperBound = Math.max(upperBound, value.doubleValue());
}
}
}
double margin = 0.1 * (upperBound - lowerBound);
return new Range(Math.max(0, lowerBound - margin), Math.min(100, upperBound + margin));
}

private void applyTheme(JFreeChart chart) {
var theme = (StandardChartTheme) StandardChartTheme.createJFreeTheme();
theme.setDrawingSupplier(new DefaultDrawingSupplier(getWheelColors(),
Expand Down

0 comments on commit 02ce975

Please sign in to comment.