Hide series
This commit is contained in:
parent
e3f579f38c
commit
a148502cf5
@ -126,9 +126,9 @@ public class AWTGraphRenderer implements IGraphRenderer<AWTDrawer> {
|
||||
legendSizeW = getLegendSizeW(graph, seriesNameFontMetrics);
|
||||
legendSizeH = getLegendSizeH(graph, seriesNameFontMetrics);
|
||||
|
||||
if (legendSizeW > graphWidth / 3d || legendSizeH > graphHeight / 2.5d) {
|
||||
var newFontSizeW = (float) (seriesNameFont.getSize() * ((graphWidth / 3d) / legendSizeW));
|
||||
var newFontSizeH = (float) (seriesNameFont.getSize() * ((graphHeight / 2.5d) / legendSizeH));
|
||||
if (legendSizeW > graphWidth / 1.2d || legendSizeH > graphHeight / 1.5d) {
|
||||
var newFontSizeW = (float) (seriesNameFont.getSize() * ((graphWidth / 1.2d) / legendSizeW));
|
||||
var newFontSizeH = (float) (seriesNameFont.getSize() * ((graphHeight / 1.5d) / legendSizeH));
|
||||
seriesNameFont = seriesNameFont.deriveFont(Math.min(newFontSizeW, newFontSizeH));
|
||||
seriesNameFontMetrics = graphics2D.getFontMetrics(seriesNameFont);
|
||||
}
|
||||
@ -352,6 +352,7 @@ public class AWTGraphRenderer implements IGraphRenderer<AWTDrawer> {
|
||||
|
||||
int i = 0;
|
||||
for (SeriesData series : graph.data().series()) {
|
||||
if (series.showInLegend()) {
|
||||
var seriesStyleSize = graph.style().seriesStyles().size();
|
||||
if (graph.style().seriesStyles().isEmpty()) {
|
||||
throw new IllegalArgumentException("No styles found");
|
||||
@ -376,6 +377,7 @@ public class AWTGraphRenderer implements IGraphRenderer<AWTDrawer> {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double getSeriesMargin(FontMetrics seriesNameFontMetrics) {
|
||||
return seriesNameFontMetrics.getHeight() * 2d / 3d;
|
||||
@ -397,7 +399,12 @@ public class AWTGraphRenderer implements IGraphRenderer<AWTDrawer> {
|
||||
}
|
||||
|
||||
private static double getLegendSizeH(Graph graph, FontMetrics seriesNameFontMetrics) {
|
||||
int seriesCount = graph.data().series().size();
|
||||
int seriesCount = 0;
|
||||
for (SeriesData series : graph.data().series()) {
|
||||
if (series.showInLegend()) {
|
||||
seriesCount++;
|
||||
}
|
||||
}
|
||||
double seriesPadding = getSeriesPadding(seriesNameFontMetrics);
|
||||
double singleSeriesHeight = seriesNameFontMetrics.getHeight();
|
||||
return seriesPadding / 2d
|
||||
@ -408,12 +415,14 @@ public class AWTGraphRenderer implements IGraphRenderer<AWTDrawer> {
|
||||
private static double getSeriesTextMaxWidth(Graph graph, FontMetrics seriesNameFontMetrics) {
|
||||
double seriesTextMaxWidth = 0;
|
||||
for (SeriesData series : graph.data().series()) {
|
||||
if (series.showInLegend()) {
|
||||
var seriesName = series.name();
|
||||
var seriesNameRasterWidth = seriesNameFontMetrics.stringWidth(seriesName);
|
||||
if (seriesTextMaxWidth < seriesNameRasterWidth) {
|
||||
seriesTextMaxWidth = seriesNameRasterWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
return seriesTextMaxWidth;
|
||||
}
|
||||
|
||||
|
@ -2,4 +2,13 @@ package it.cavallium.jlinegraph;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record SeriesData(List<Vertex> vertices, boolean isFunction, String name) {}
|
||||
public record SeriesData(List<Vertex> vertices, boolean isFunction, String name, boolean showInLegend) {
|
||||
|
||||
public SeriesData(List<Vertex> vertices, boolean isFunction, String name) {
|
||||
this(vertices, isFunction, name, true);
|
||||
}
|
||||
|
||||
public SeriesData {
|
||||
showInLegend = showInLegend && !name.isBlank();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user