package fortiss.results.widgets;

import java.util.List;

import javax.swing.UIManager;

import org.knowm.xchart.CategoryChart;
import org.knowm.xchart.CategoryChartBuilder;
import org.knowm.xchart.CategorySeries;
import org.knowm.xchart.CategorySeries.CategorySeriesRenderStyle;
import org.knowm.xchart.XChartPanel;
import org.knowm.xchart.style.Styler.LegendPosition;

import fortiss.gui.style.Colors;
import fortiss.gui.style.FontSize;
import fortiss.gui.style.Fonts;

public class CategoryPlotWidget extends XChartPanel<CategoryChart> {

	private static final long serialVersionUID = 1L;
	private List<CategorySeries> series;
	/**
	 * @param title plot title
	 * @param xAxisTitle title of the x axis
	 * @param yAxisTitle title of the y axis
	 * @param width widget width
	 * @param height widget height
	 * @param series list of CategorySeries
	 * @param style Options: Area, Bar, Line, Scatter, SteppedBar, Stick
	 */
	public CategoryPlotWidget(String title, String xAxisTitle, String yAxisTitle, int width, int height,
			List<CategorySeries> series, CategorySeriesRenderStyle style) {

		super(new CategoryChartBuilder().width(width).height(height).title(title.toUpperCase()).xAxisTitle(xAxisTitle)
				.yAxisTitle(yAxisTitle).build());

		this.series = series;
		getChart().getStyler().setDefaultSeriesRenderStyle(style);
		// getChart().getStyler().setChartBackgroundColor(Colors.background);
		getChart().getStyler().setChartBackgroundColor(UIManager.getColor("Panel.background"));
		getChart().getStyler().setChartFontColor(Colors.accent1);
		getChart().getStyler().setChartPadding(10);
		getChart().getStyler().setChartTitleFont(Fonts.getOswald(FontSize.NORMAL));
		getChart().getStyler().setChartTitlePadding(15);
		getChart().getStyler().setLegendFont(Fonts.getOpenSans(FontSize.TINY));
		getChart().getStyler().setLegendPosition(LegendPosition.OutsideS);
		getChart().getStyler().setLegendSeriesLineLength(20);
		getChart().getStyler().setAxisTitleFont(Fonts.getOpenSans(FontSize.TINY));
		getChart().getStyler().setAxisTickLabelsFont(Fonts.getOpenSans(FontSize.TINY));

		series.forEach((serie) -> getChart().addSeries(serie.getName(), (List<?>) serie.getXData(),
				(List<? extends Number>) serie.getYData()));
	}
	
	public boolean isEmpty() {
		double sum = 0;
		for (CategorySeries item : series) {
			sum = item.getYMax() + item.getYMin();
		}
		return sum == 0;
	}
}

@@ -2263,23 +2263,76 @@
 %7B%0A%09%09
-double sum = 0;
+// If at least one series has non-zero values, the plot is not empty
 %0A%09%09f
@@ -2374,14 +2374,11 @@
 %0A%09%09%09
-sum = 
+if(
 item
@@ -2392,9 +2392,15 @@
 x() 
-+
+!= 0 &&
  ite
@@ -2410,17 +2410,48 @@
 etYMin()
-;
+ != 0 ) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D
 %0A%09%09%7D%0A%09%09r
@@ -2460,16 +2460,12 @@
 urn 
-sum == 0
+true
 ;%0A%09%7D

Fix algorithm to hide empty bar plots